hasuniea 8 years ago
commit 1ba598a93e

@ -264,10 +264,14 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information"); log.debug("Getting the list of users with all user-related information");
} }
List<BasicUserInfo> userList, offsetList;
RequestValidationUtil.validatePaginationParameters(offset, limit); RequestValidationUtil.validatePaginationParameters(offset, limit);
List<BasicUserInfo> userList, offsetList;
String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter); String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter);
int appliedLimit = (limit <= 0) ? -1 : (limit + offset); // to get whole set of users, appliedLimit is set to -1
// by default, this whole set is limited to 100 - MaxUserNameListLength of user-mgt.xml
int appliedLimit = -1;
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
@ -285,14 +289,23 @@ public class UserManagementServiceImpl implements UserManagementService {
userList.add(user); userList.add(user);
} }
if (offset <= userList.size()) { int toIndex = offset + limit;
offsetList = userList.subList(offset, userList.size()); int listSize = userList.size();
int lastIndex = listSize - 1;
if (offset <= lastIndex) {
if (toIndex <= listSize) {
offsetList = userList.subList(offset, toIndex);
} else {
offsetList = userList.subList(offset, listSize);
}
} else { } else {
offsetList = new ArrayList<>(); offsetList = new ArrayList<>();
} }
BasicUserInfoList result = new BasicUserInfoList(); BasicUserInfoList result = new BasicUserInfoList();
result.setList(offsetList); result.setList(offsetList);
result.setCount(offsetList.size()); result.setCount(users.length);
return Response.status(Response.Status.OK).entity(result).build(); return Response.status(Response.Status.OK).entity(result).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {

@ -0,0 +1,175 @@
/*
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var removeCustomParam = function () {
$(this).parent().parent().remove();
};
/**
* Following function would execute
* when a user clicks on the list item
* initial mode and with out select mode.
*/
function InitiateViewOption() {
$(location).attr('href', $(this).data("url"));
}
$("#back-to-search").click(function () {
$('#advance-search-result').addClass('hidden');
$("#advance-search-form").removeClass('hidden');
$("#view-search-param").addClass('hidden');
$("#back-to-search").addClass('hidden');
});
$("#view-search-param").click(function () {
$("#advance-search-form").removeClass('hidden');
$(".title-result").addClass('hidden');
$("#view-search-param").addClass('hidden');
});
var dynamicForm = '<div class="dynamic-search-param row"><div class="row"><a class="close-button-div icon fw fw-error">' +
'</a></div><div class="form-group wr-input-control col-md-2"><label class="wr-input-label ">State</label>' +
'<select class="state no-tag form-control select2-custom"><option>AND</option><option>OR</option></select></div><div ' +
'class="form-group wr-input-control col-md-4"><label class="wr-input-label ">Key</label><select class=' +
'"txt-key form-control select2-custom"><option>deviceModel</option><option>vendor</option><option>osVersion' +
'</option><option>batteryLevel</option><option>internalTotalMemory</option> <option>' +
'internalAvailableMemory</option> <option>externalTotalMemory</option> <option>externalAvailableMemory' +
'</option> <option>connectionType</option> <option>ssid</option> <option>cpuUsage</option> <option>' +
'totalRAMMemory</option> <option>availableRAMMemory</option> <option>pluggedIn</option></select></div>' +
'<div class="form-group wr-input-control col-md-2">' +
'<label class="wr-input-label ">Operator</label><select class="form-control select2-custom no-tag operator">' +
'<option>=</option><option> !=</option><option> <</option>' +
'<option> =<</option><option> ></option><option> >=</option></select></div><div class="form-group ' +
'wr-input-control col-md-4"><label class="wr-input-label' +
' ">Value</label><input type="text" class="form-control txt-value"/></div></div>';
$(document).ready(function () {
var isInit = true;
$("#add-custom-param").click(function () {
$("#customSearchParam").prepend(dynamicForm);
$(".close-button-div").unbind("click");
$(".close-button-div").bind("click", removeCustomParam);
$(".txt-key").select2({tags: true});
$(".no-tag").select2({tags: false});
});
$("#device-search-btn").click(function () {
var location = $("#location").val();
var payload_obj = {};
var conditions = [];
if (location) {
var conditionObject = {};
conditionObject.key = "LOCATION";
conditionObject.value = location;
conditionObject.operator = "=";
conditionObject.state = "OR";
conditions.push(conditionObject)
}
$("#customSearchParam .dynamic-search-param").each(function () {
var value = $(this).find(".txt-value").val();
var key = $(this).find(".txt-key").val()
if (value && key) {
var conditionObject = {};
conditionObject.key = key;
conditionObject.value = value;
conditionObject.operator = $(this).find(".operator").val();
conditionObject.state = $(this).find(".state").val();
conditions.push(conditionObject)
}
});
payload_obj.conditions = conditions;
var deviceSearchAPI = "/api/device-mgt/v1.0/devices/search-devices";
$("#advance-search-form").addClass(" hidden");
$("#loading-content").removeClass('hidden');
var deviceListing = $("#device-listing");
var deviceListingSrc = deviceListing.attr("src");
$.template("device-listing", deviceListingSrc, function (template) {
var successCallback = function (data) {
if (!data) {
$("#loading-content").addClass('hidden');
$("#advance-search-result").addClass("hidden");
$("#advance-search-form").removeClass(" hidden");
$('#device-listing-status').removeClass('hidden');
$('#device-listing-status-msg').text('No Device are available to be displayed.');
return;
}
data = JSON.parse(data);
if (data.devices.length == 0) {
$("#loading-content").addClass('hidden');
$("#advance-search-result").addClass("hidden");
$("#advance-search-form").removeClass(" hidden");
$('#device-listing-status').removeClass('hidden');
$('#device-listing-status-msg').text('No Device are available to be displayed.');
return;
}
var viewModel = {};
var devices = [];
if (data.devices.length > 0) {
for (i = 0; i < data.devices.length; i++) {
var tempDevice = data.devices[i];
var device = {};
device.type = tempDevice.type;
device.name = tempDevice.name;
device.deviceIdentifier = tempDevice.deviceIdentifier;
var properties = {} ;
var enrolmentInfo = {};
properties.VENDOR = tempDevice.deviceInfo.vendor;
properties.DEVICE_MODEL = tempDevice.deviceInfo.deviceModel;
enrolmentInfo.status = "ACTIVE";
enrolmentInfo.owner = "N/A";
enrolmentInfo.ownership = "N/A";
device.enrolmentInfo = enrolmentInfo;
device.properties = properties;
devices.push(device);
}
viewModel.devices = devices;
$('#advance-search-result').removeClass('hidden');
$("#view-search-param").removeClass('hidden');
$("#back-to-search").removeClass('hidden');
$('#device-grid').removeClass('hidden');
$('#ast-container').removeClass('hidden');
$('#user-listing-status-msg').text("");
var content = template(viewModel);
$("#ast-container").html(content);
} else {
$('#device-listing-status').removeClass('hidden');
$('#device-listing-status-msg').text('No Device are available to be displayed.');
}
$("#loading-content").addClass('hidden');
if (isInit) {
$('#device-grid').datatables_extended();
isInit = false;
}
$(".icon .text").res_text(0.2);
};
invokerUtil.post(deviceSearchAPI,
payload_obj,
successCallback,
function (message) {
$("#loading-content").addClass('hidden');
$("#advance-search-result").addClass("hidden");
$("#advance-search-form").removeClass(" hidden");
$('#device-listing-status').removeClass('hidden');
$('#device-listing-status-msg').text('Server is unable to perform the search please enroll at least one device or check the search query');
}
);
});
});
});

@ -0,0 +1,44 @@
{{#each devices}}
<tr data-type="selectable" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}">
<td class="remove-padding icon-only content-fill viewEnabledIcon"
{{#unequal enrolmentInfo.status "REMOVED"}}
data-url="view?type={{type}}&id={{deviceIdentifier}}"
{{/unequal}}
>
<div class="thumbnail icon">
<i class="square-element text fw fw-mobile"></i>
</div>
</td>
<td class="fade-edge" data-search="{{properties.DEVICE_MODEL}},{{properties.VENDOR}}" data-display="{{properties.DEVICE_MODEL}}">
<h4>Device {{name}}</h4>
{{#if properties.DEVICE_MODEL}}
<div>({{properties.VENDOR}} - {{properties.DEVICE_MODEL}})</div>
{{/if}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.owner}}" data-display="{{enrolmentInfo.owner}}" data-grid-label="Owner">{{enrolmentInfo.owner}}</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.status}}" data-display="{{enrolmentInfo.status}}" data-grid-label="Status">
{{#equal enrolmentInfo.status "ACTIVE"}}<span><i class="fw fw-ok icon-success"></i> Active</span>{{/equal}}
{{#equal enrolmentInfo.status "INACTIVE"}}<span><i class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
{{#equal enrolmentInfo.status "BLOCKED"}}<span><i class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
{{#equal enrolmentInfo.status "REMOVED"}}<span><i class="fw fw-delete icon-danger"></i> Removed</span>{{/equal}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{type}}" data-display="{{type}}" data-grid-label="Type">{{type}}</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.ownership}}" data-display="{{enrolmentInfo.ownership}}" data-grid-label="Ownership">{{enrolmentInfo.ownership}}</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
<!--{{#equal type "TemperatureController"}}
{{#equal status "INACTIVE"}}
<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view claim-btn" data-deviceid="{{deviceIdentifier}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-edit fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Claim</span>
</a>
{{/equal}}
{{/equal}}-->
</td>
</tr>
{{/each}}

@ -0,0 +1,125 @@
<!--
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
{{#zone "content"}}
<!-- content/body -->
<div class="row">
<div class="col-md-12">
<!-- content -->
<div class="row">
<div class="col-md-10 col-centered">
<button id="back-to-search" class="wr-btn col-fixed-right hidden">Back to Search Query</button>
<button id="view-search-param" class="wr-btn col-fixed-right hidden">View Search Query</button>
</div>
</div>
<div id="advance-search-form" class="container col-centered wr-content">
<div class="wr-form">
<p class="page-sub-title">Advanced Device Search</p>
<hr/>
<div id="device-listing-status" class="raw hidden">
<div class="col-lg-12 col-md-12">
<ul style="list-style-type: none;">
<li class="message message-info">
<h4>
<i class="icon fw fw-info"></i>
<a id="device-listing-status-msg"></a>
</h4>
</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12">
<div id="device-search-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<label class="wr-input-label ">
Location
</label>
<br>
<div class="row" >
<div id="locationInputField" class=" col-md-10 form-group wr-input-control">
<input type="text" id="location" class="form-control"/>
<br>
<span class=" locationError hidden glyphicon glyphicon-remove form-control-feedback"></span>
<label class="error usernameEmpty hidden" for="summary">This field is required.</label>
</div>
<div class= "col-md-2 form-group wr-input-control col-fixed-right">
<button id="device-search-btn" class="wr-btn-search ">Search</button>
</div>
</div>
<button id="add-custom-param" class="wr-btn">Add a custom search parameter</button>
<br>
</div>
<br>
<div id="customSearchParam" class="col-lg-10 col-md-10">
</div>
</div>
</div>
</div>
<!-- /content -->
<!-- loading -->
<div id="loading-content" class="col-centered hidden">
<i class="fw fw-settings fw-spin fw-2x"></i>
Searching for Devices . . .
<br>
</div>
<!--/loading-->
<!-- result content -->
<div id="advance-search-result" class="col-centered hidden">
<div class="wr-form">
<b class="page-sub-title title-result">Advanced Search Results</b>
<hr/>
<div id="device-table">
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
id="device-grid">
<thead class="hidden">
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody id="ast-container">
<br class="c-both"/>
</tbody>
</table>
</div>
</div>
</div>
<!-- / result content -->
</div>
</div>
<!-- /content/body -->
{{/zone}}
{{#zone "bottomJs"}}
{{js "/js/bottomJs.js"}}
<script id="device-listing" src="{{@page.publicUri}}/templates/device-listing.hbs"
type="text/x-handlebars-template"></script>
{{/zone}}

@ -0,0 +1,44 @@
/*
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/**
* Returns the dynamic state to be populated by add-user page.
*
* @param context Object that gets updated with the dynamic state of this page to be presented
* @returns {*} A context object that returns the dynamic state of this page to be presented
*/
function onRequest(context) {
var log = new Log("units/user-create/certificate-create.js");
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var response = userModule.getRolesByUserStore();
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
if (response["status"] == "success") {
context["roles"] = response["content"];
}
context["charLimit"] = mdmProps["usernameLength"];
context["usernameJSRegEx"] = mdmProps["userValidationConfig"]["usernameJSRegEx"];
context["usernameHelpText"] = mdmProps["userValidationConfig"]["usernameHelpMsg"];
context["usernameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["usernameRegExViolationErrorMsg"];
context["firstnameJSRegEx"] = mdmProps["userValidationConfig"]["firstnameJSRegEx"];
context["firstnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"];
context["lastnameJSRegEx"] = mdmProps["userValidationConfig"]["lastnameJSRegEx"];
context["lastnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"];
return context;
}

@ -1,26 +1,22 @@
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* KIND, either express or implied. See the License for the * either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
var responseCodes = { var deviceMgtAPIBaseURI = "/api/device-mgt/v1.0";
"CREATED": "Created",
"ACCEPTED": "202",
"INTERNAL_SERVER_ERROR": "Internal Server Error"
};
/** /**
* Following function would execute * Following function would execute
@ -31,6 +27,48 @@ function InitiateViewOption() {
$(location).attr('href', $(this).data("url")); $(location).attr('href', $(this).data("url"));
} }
function loadNotifications() {
var deviceListing = $("#notification-listing");
var deviceListingSrc = deviceListing.attr("src");
var currentUser = deviceListing.data("currentUser");
$.template(
"notification-listing",
deviceListingSrc,
function (template) {
invokerUtil.get(
deviceMgtAPIBaseURI + "/notifications",
// on success
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) {
data = JSON.parse(data);
if (data["notifications"] && data["notifications"].length > 0) {
var viewModel = {};
viewModel["notifications"] = data["notifications"];
var content = template(viewModel);
$("#ast-container").html(content);
$("#unread-notifications").datatables_extended();
$("#all-notifications").datatables_extended();
}
}
},
// on error
function (jqXHR) {
console.log(jqXHR.status);
}
);
}
);
}
// Start of HTML embedded invoke methods
function showAdvanceOperation(operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
}
$(document).ready(function () { $(document).ready(function () {
var permissionSet = {}; var permissionSet = {};
$.setPermission = function (permission) { $.setPermission = function (permission) {
@ -43,76 +81,31 @@ $(document).ready(function () {
loadNotifications(); loadNotifications();
$("#ast-container").on("click", ".new-notification", function(e){ $("#ast-container").on("click", ".new-notification", function(e) {
var notificationId = $(this).data("id"); var notificationId = $(this).data("id");
var redirectUrl = $(this).data("url"); // var redirectUrl = $(this).data("url");
var getNotificationsAPI = "/api/device-mgt/v1.0/notifications/"+notificationId+"/CHECKED"; var query = deviceMgtAPIBaseURI + "/notifications" + "/" + notificationId + "/mark-checked";
var errorMsgWrapper = "#error-msg"; var errorMsgWrapper = "#error-msg";
var errorMsg = "#error-msg span"; var errorMsg = "#error-msg span";
invokerUtil.put( invokerUtil.put(
getNotificationsAPI, query,
null, null,
function (data) { // on success
data = JSON.parse(data); function (data, textStatus, jqXHR) {
if (data.status == responseCodes["ACCEPTED"]) { if (jqXHR.status == 200) {
$("#config-save-form").addClass("hidden"); $("#config-save-form").addClass("hidden");
location.href = redirectUrl; // location.href = redirectUrl;
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
} }
},
$(errorMsgWrapper).removeClass("hidden"); // on error
}, function (data) { function (jqXHR) {
data = data.status; if (jqXHR.status == 403) {
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted."); $(errorMsg).text("Action was not permitted.");
} else { } else if (jqXHR.status == 500) {
$(errorMsg).text("An unexpected error occurred."); $(errorMsg).text("An unexpected error occurred. Please try refreshing the page in a while.");
} }
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
} }
); );
}); });
}); });
function loadNotifications(){
var deviceListing = $("#notification-listing");
var deviceListingSrc = deviceListing.attr("src");
var currentUser = deviceListing.data("currentUser");
$.template("notification-listing", deviceListingSrc, function (template) {
var serviceURL = "/api/device-mgt/v1.0/notifications";
var successCallback = function (data) {
var viewModel = {};
data = JSON.parse(data);
viewModel.notifications = data.notifications;
if(data.count > 0){
var content = template(viewModel);
$("#ast-container").html(content);
$('#unread-notifications').datatables_extended();
$('#all-notifications').datatables_extended();
}
};
invokerUtil.get(serviceURL,
successCallback, function(message){
console.log(message.content);
});
});
}
// Start of HTML embedded invoke methods
var showAdvanceOperation = function (operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
};

@ -19,7 +19,7 @@
<tr data-type="selectable" data-id="{{id}}"> <tr data-type="selectable" data-id="{{id}}">
<td data-display="{{description}}" data-grid-label="Description">{{description}}</td> <td data-display="{{description}}" data-grid-label="Description">{{description}}</td>
<td style="text-align: center;"> <td style="text-align: center;">
<a href="device?type={{deviceIdentifier.type}}&id={{deviceIdentifier.id}}" data-id="{{id}}" data-url="device?type={{deviceIdentifier.type}}&id={{deviceIdentifier.id}}" class="new-notification" data-click-event="remove-form"> <a href="device?type={{deviceIdentifier.type}}&id={{deviceIdentifier.id}}" data-id="{{id}}" data-url="device/{{deviceIdentifier.type}}?id={{deviceIdentifier.id}}" class="new-notification" data-click-event="remove-form">
<span class="fw-stack"> <span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i> <i class="fw fw-view fw-stack-1x"></i>

Loading…
Cancel
Save