From b1683c1ccbf8b56192d884fbe77246495951ba5e Mon Sep 17 00:00:00 2001 From: charithag Date: Thu, 28 Apr 2016 08:01:46 +0530 Subject: [PATCH 1/5] Add capability to assign device in to a group and bug fixes --- .../carbon/device/mgt/jaxrs/api/Group.java | 51 ++++--- .../src/main/webapp/META-INF/permissions.xml | 15 +- .../mgt/core/group/mgt/dao/GroupDAOImpl.java | 4 +- .../jaggeryapps/devicemgt/api/group-api.jag | 83 +++++++++++ .../jaggeryapps/devicemgt/api/stats-api.jag | 124 ---------------- .../devicemgt/app/modules/group.js | 2 +- .../app/pages/cdmf.page.devices/devices.hbs | 2 +- .../app/pages/cdmf.page.devices/devices.js | 1 - .../cdmf.page.devices/public/js/listing.js | 132 ++++++++---------- .../jaggeryapps/devicemgt/jaggery.conf | 4 - 10 files changed, 189 insertions(+), 229 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java index 4e1b9b68b7..acd9e98714 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java @@ -21,15 +21,15 @@ package org.wso2.carbon.device.mgt.jaxrs.api; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; -import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyEixistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; +import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -141,6 +141,26 @@ public class Group { } } + @Path("/all") + @GET + @Produces("application/json") + public Response getAllGroups() { + try { + GroupManagementProviderService groupManagementProviderService = DeviceMgtAPIUtils + .getGroupManagementProviderService(); + PaginationResult paginationResult = groupManagementProviderService + .getGroups(0, groupManagementProviderService.getGroupCount()); + if (paginationResult.getRecordsTotal() > 0) { + return Response.status(Response.Status.OK).entity(paginationResult.getData()).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).build(); + } + } catch (GroupManagementException e) { + log.error(e.getMessage(), e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + } + @Path("/user/{user}") @GET @Produces("application/json") @@ -364,16 +384,18 @@ public class Group { } @GET - @Path("/owner/{owner}/name/{groupName}/devices/all") + @Path("/owner/{owner}/name/{groupName}/devices") @Produces("application/json") - public Response getDevices(@PathParam("groupName") String groupName, - @PathParam("owner") String owner) { + public Response getDevices(@PathParam("groupName") String groupName, @PathParam("owner") String owner, + @QueryParam("start") int startIdx, @QueryParam("length") int length) { try { - List devices = DeviceMgtAPIUtils.getGroupManagementProviderService().getDevices( - groupName, owner); - Device[] deviceArray = new Device[devices.size()]; - devices.toArray(deviceArray); - return Response.status(Response.Status.OK).entity(deviceArray).build(); + PaginationResult paginationResult = DeviceMgtAPIUtils + .getGroupManagementProviderService().getDevices(groupName, owner, startIdx, length); + if (paginationResult.getRecordsTotal() > 0) { + return Response.status(Response.Status.OK).entity(paginationResult).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).build(); + } } catch (GroupManagementException e) { log.error(e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); @@ -394,15 +416,12 @@ public class Group { } } - @PUT - @Path("/owner/{owner}/name/{groupName}/devices/{deviceType}/{deviceId}") + @POST + @Path("/owner/{owner}/name/{groupName}/devices") @Produces("application/json") public Response addDevice(@PathParam("groupName") String groupName, - @PathParam("owner") String owner, @PathParam("deviceId") String deviceId, - @PathParam("deviceType") String deviceType, - @FormParam("userName") String userName) { + @PathParam("owner") String owner, DeviceIdentifier deviceIdentifier) { try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType); boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addDevice( deviceIdentifier, groupName, owner); if (isAdded) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml index 1768fa9160..e00d1a93ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml @@ -959,12 +959,19 @@ - List All Groups + List All Groups with Pagination /device-mgt/admin/groups/list /groups GET + + List All Groups + /device-mgt/admin/groups/list + /groups/all + GET + + List Groups /device-mgt/user/groups/list @@ -1080,7 +1087,7 @@ List Group Devices /device-mgt/user/groups/devices/list - /groups/owner/*/name/*/devices/all + /groups/owner/*/name/*/devices GET @@ -1094,8 +1101,8 @@ Add Device to Group /device-mgt/user/groups/devices/add - /groups/owner/*/name/*/devices/*/* - PUT + /groups/owner/*/name/*/devices + POST diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java index 819d676dc7..afb8cca055 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java @@ -356,9 +356,9 @@ public class GroupDAOImpl implements GroupDAO { ResultSet resultSet = null; try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT COUNT(gm.ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP gm, (SELECT ID as GROUP_ID " + + String sql = "SELECT COUNT(gm.ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP gm, (SELECT ID " + "FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?) dg " + - "WHERE dm.GROUP_ID = dg.GROUP_ID AND dm.TENANT_ID = ?"; + "WHERE gm.GROUP_ID = dg.ID AND dm.TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, groupName); stmt.setString(2, owner); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag new file mode 100644 index 0000000000..e64ad14d16 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag @@ -0,0 +1,83 @@ +<% +/* + * 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 uri = request.getRequestURI(); +var uriMatcher = new URIMatcher(String(uri)); + +var log = new Log("api/device-api.jag"); +var constants = require("/app/modules/constants.js"); +var utility = require("/app/modules/utility.js").utility; +var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); +var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; + +var user = session.get(constants.USER_SESSION_KEY); +var result; + +response.contentType = 'application/json'; + +if (!user) { + response.sendRedirect("/devicemgt/login?#login-required"); + exit(); +} else { + if (uriMatcher.match("/{context}/api/groups")) { + var url = request.getParameter("url"); + var draw = request.getParameter("draw"); + var length = request.getParameter("length"); + var start = request.getParameter("start"); + var search = request.getParameter("search[value]"); + var groupName = request.getParameter("columns[1][search][value]"); + var owner = request.getParameter("columns[2][search][value]"); + var targetURL; + + function appendQueryParam(url, queryParam, value) { + if (url.indexOf("?") > 0) { + return url + "&" + queryParam + "=" + value; + } + return url + "?" + queryParam + "=" + value; + } + + targetURL = devicemgtProps.httpsURL + request.getParameter("url"); + targetURL = appendQueryParam(targetURL, "start", start); + targetURL = appendQueryParam(targetURL, "length", length); + + if (search && search !== "") { + targetURL = appendQueryParam(targetURL, "search", search); + } + + if (groupName && groupName !== "") { + targetURL = appendQueryParam(targetURL, "group-name", groupName); + } + + if (owner && owner !== "") { + targetURL = appendQueryParam(targetURL, "user", owner); + } + + serviceInvokers.XMLHttp.get( + targetURL, function (responsePayload) { + response.status = 200; + result = responsePayload; + }, + function (responsePayload) { + response.status = responsePayload.status; + result = responsePayload.responseText; + }); + } +} + +%> \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag deleted file mode 100644 index 5c8fd94355..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag +++ /dev/null @@ -1,124 +0,0 @@ -<% -/* - * Copyright (c) 2015, 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 uri = request.getRequestURI(); -var uriMatcher = new URIMatcher(String(uri)); - -var log = new Log("api/stats-api.jag"); - -var from = request.getParameter("from"); -var to = request.getParameter("to"); - -var constants = require("/app/modules/constants.js"); -var utility = require("/app/modules/utility.js").utility; -var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); - -var deviceCloudGroupService = devicemgtProps["httpsURL"] + "/common/group_manager"; -var deviceCloudDeviceService = devicemgtProps["httpsURL"] + "/common/device_manager"; -var deviceCloudStatsService = devicemgtProps["httpsURL"] + "/common/stats_manager"; - -var stats = {}; -var deviceId; -var deviceType; - -var responseProcessor = require('utils').response; -response.contentType = 'application/json'; - -var user = session.get(constants.USER_SESSION_KEY); - -if (!user) { - response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized"); -} else { - if (uriMatcher.match("/{context}/api/stats")) { - deviceId = request.getParameter("deviceId"); - deviceType = request.getParameter("deviceType"); - - getDeviceData(deviceType, deviceId); - - } else if (uriMatcher.match("/{context}/api/stats/group")) { - var groupId = request.getParameter("groupId"); - - //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all - var endPoint = deviceCloudGroupService + "/group/id/" + groupId + "/device/all"; - var data = {"username": user}; - var devices = get(endPoint, data, "json").data; - - for (var device in devices) { - deviceId = devices[device].deviceIdentifier; - deviceType = devices[device].type; - getDeviceData(deviceType, deviceId); - } - } - log.info(stats); - // returning the result. - if (stats) { - print(stats); - } -} - -function getDeviceData(deviceType, deviceId) { - //URL: GET https://localhost:9443/devicecloud/device_manager/device/type/{type}/identifier/{identifier} - var endPoint = deviceCloudDeviceService + "/device/type/" + deviceType + "/identifier/" + deviceId; - var data = {"username": user}; - var device = get(endPoint, data, "json").data; - log.info(device); - if (!device) { - return; - } - var uname = device.enrolmentInfo.owner; - - var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; - - if (analyticStreams) { - var streamTableName; - for (var stream in analyticStreams) { - streamTableName = analyticStreams[stream]["table"]; - if (stats[streamTableName] == null) { - stats[streamTableName] = []; - } - stats[streamTableName].push({ - "device": device.name, - "stats": getSensorData(streamTableName, analyticStreams[stream]["ui_unit"]["data"][1]["column"]["name"], uname, device.type, device.deviceIdentifier, from, to), - "stream": analyticStreams[stream] - }); - } - } -} - -function getSensorData(table, column, user, type, deviceIdentifier, from, to) { - - var fetchedData = []; - - try { - ///stats/device/type/{type}/identifier/{identifier} - var endPoint = deviceCloudStatsService + "/stats/device/type/" + type + "/identifier/" + deviceIdentifier; - var query = "?table=" + encodeURIComponent(table) - + "&column=" + encodeURIComponent(column) - + "&username=" + encodeURIComponent(user) - + "&from=" + from - + "&to=" + to; - endPoint = endPoint + query; - fetchedData = get(endPoint, {}, "json").data; - return fetchedData; - } catch (error) { - log.error(error); - } -} - -%> diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js index 3d050b38a1..31fac7176d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js @@ -54,7 +54,7 @@ var groupModule = {}; }; groupModule.getGroupDeviceCount = function (groupName, owner) { - endPoint = groupServiceEndpoint + "/" + owner + "/" + groupName + "/devices/count"; + endPoint = groupServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices/count"; return serviceInvokers.XMLHttp.get( endPoint, function (responsePayload) { return responsePayload; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index 2966fa09a2..1122acfc29 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -1,4 +1,4 @@ -{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}} +{{unit "cdmf.unit.ui.title" pageTitle=title}} {{unit "cdmf.unit.data-tables-extended"}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index 851fec3688..e56c529cc9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -44,7 +44,6 @@ function onRequest(context) { if (groupName && groupOwner) { var groupModule = require("/app/modules/group.js").groupModule; deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner); - page.groupOwner = groupOwner; } else { deviceCount = deviceModule.getDevicesCount(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index ae7a5fcaa5..e8b20bd5c8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -61,10 +61,18 @@ function InitiateViewOption(url) { var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var assetContainer = "#ast-container"; +var deviceListing, currentUser, groupName, groupOwner; + /* * DOM ready functions. */ $(document).ready(function () { + deviceListing = $("#device-listing"); + deviceListing.data("current-user"); + + groupName = getParameterByName("groupName"); + groupOwner = getParameterByName("groupOwner"); + /* Adding selected class for selected devices */ $(deviceCheckbox).each(function () { addDeviceSelectedClass(this); @@ -88,8 +96,6 @@ $(document).ready(function () { $(".ast-container").on("click", ".claim-btn", function(e){ e.stopPropagation(); var deviceId = $(this).data("deviceid"); - var deviceListing = $("#device-listing"); - var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; invokerUtil.put(serviceURL, deviceIdentifier, function(message){ @@ -161,10 +167,6 @@ function toTitleCase(str) { } function loadDevices(searchType, searchParam){ - var deviceListing = $("#device-listing"); - var imageResource = deviceListing.data("image-resource"); - var currentUser = deviceListing.data("currentUser"); - var serviceURL; if ($.hasPermission("LIST_DEVICES")) { serviceURL = "/devicemgt_admin/devices"; @@ -304,6 +306,15 @@ function loadDevices(searchType, searchParam){ 'data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' + '' + ''; + + if (!groupName || !groupOwner) { + html += '' + + '' + + ''; + } + html += '' + '' + @@ -370,12 +381,6 @@ function loadDevices(searchType, searchParam){ }); } -/* - * Setting-up global variables. - */ -var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; -var assetContainer = "#ast-container"; - function openCollapsedNav() { $('.wr-hidden-nav-toggle-btn').addClass('active'); $('#hiddenNav').slideToggle('slideDown', function () { @@ -386,14 +391,12 @@ function openCollapsedNav() { } function initPage() { - var deviceListing = $("#device-listing"); - var currentUser = deviceListing.data("currentUser"); var serviceURL; if ($.hasPermission("LIST_DEVICES")) { serviceURL = "/devicemgt_admin/devices/count"; } else if ($.hasPermission("LIST_OWN_DEVICES")) { //Get authenticated users devices - serviceURL = "/devicemgt_admin/devices/user/"+currentUser+"/count"; + serviceURL = "/devicemgt_admin/devices/user/" + currentUser + "/count"; } invokerUtil.get(serviceURL, function (data) { @@ -442,8 +445,6 @@ $(document).ready(function () { $(".ast-container").on("click", ".claim-btn", function(e) { e.stopPropagation(); var deviceId = $(this).data("deviceid"); - var deviceListing = $("#device-listing"); - var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; invokerUtil.put(serviceURL, deviceIdentifier, function(message) { @@ -516,72 +517,51 @@ function attachDeviceEvents() { $("a.group-device-link").click(function () { var deviceId = $(this).data("deviceid"); var deviceType = $(this).data("devicetype"); - var endPoint = "api/group/all"; - $(modalPopupContent).html($('#group-device-modal-content').html()); $('#user-groups').html('
'); $("a#group-device-yes-link").hide(); showPopup(); - var getGroupsRequest = $.ajax({ - url: endPoint, - method: "GET", - contentType: "application/json", - accept: "application/json" - }); - - getGroupsRequest.done(function (data, txtStatus, jqxhr) { - var groups = JSON.parse(data); - var status = jqxhr.status; - if (status == 200) { - groups = groups.data; - if (groups.length <= 0) { - $('#user-groups').html("There is no any groups available"); - return; - } - var str = '
'; - $('#user-groups').html(str); - $("a#group-device-yes-link").show(); - $("a#group-device-yes-link").click(function () { - var selectedGroupId = $('#assign-group-selector').val(); - endPoint = "api/group/id/" + selectedGroupId + "/assign"; - var device = {"deviceId": deviceId, "deviceType": deviceType}; - - var assignRequest = $.ajax({ - url: endPoint, - method: "POST", - contentType: "application/json", - accept: "application/json", - data: JSON.stringify(device) - }); - - assignRequest.done(function (data, txtStatus, jqxhr) { - var status = jqxhr.status; - if (status == 200) { - $(modalPopupContent).html($('#group-associate-device-200-content').html()); - setTimeout(function () { - hidePopup(); - location.reload(false); - }, 2000); - } else { - displayDeviceErrors(jqXHR); - } - } - ); - assignRequest.fail(function (jqXHR) { - displayDeviceErrors(jqXHR); - }); - }); - } - } - ); - getGroupsRequest.fail(function (jqXHR) { + var serviceURL; + if ($.hasPermission("LIST_ALL_GROUPS")) { + serviceURL = "/devicemgt_admin/groups/all"; + } else if ($.hasPermission("LIST_GROUPS")) { + //Get authenticated users groups + serviceURL = "/devicemgt_admin/groups/user/" + currentUser; + } + + invokerUtil.get(serviceURL, function (data) { + var groups = JSON.parse(data); + if (groups.length <= 0) { + $('#user-groups').html("There is no any groups available"); + return; + } + var str = '
'; + $('#user-groups').html(str); + $("a#group-device-yes-link").show(); + $("a#group-device-yes-link").click(function () { + var selectedGroup = $('#assign-group-selector').val(); + serviceURL = "/devicemgt_admin/groups/owner/" + selectedGroup + "/devices"; + var device = {"id": deviceId, "type": deviceType}; + invokerUtil.post(serviceURL, device, function (data) { + $(modalPopupContent).html($('#group-associate-device-200-content').html()); + setTimeout(function () { + hidePopup(); + location.reload(false); + }, 2000); + }, function (message) { + displayDeviceErrors(jqXHR); + }); + }); + }, function (message) { displayDeviceErrors(jqXHR); }); + $("a#group-device-cancel-link").click(function () { hidePopup(); }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf index 1ee17c2028..d18daaa172 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf @@ -11,10 +11,6 @@ "url": "/api/group/*", "path": "/api/group-api.jag" }, - { - "url": "/api/stats/*", - "path": "/api/stats-api.jag" - }, { "url": "/api/operations/*", "path": "/api/operation-api.jag" From 46117b4e84dc87614a9af9ac10fa3a48cf3b35b3 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 28 Apr 2016 18:10:52 +0530 Subject: [PATCH 2/5] Adding temporary development code bits for dashboard analytics feature --- .../analytics/dashboard/dao/GadgetDataServiceDAOImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java index e56e241ec5..fabd43ec8e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java @@ -411,7 +411,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceWithDetails = new HashMap<>(); List> filteredDevicesWithDetails = new ArrayList<>(); int totalRecordsCount = 0; try { @@ -448,7 +447,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + Map filteredDeviceWithDetails; while (rs.next()) { + filteredDeviceWithDetails = new HashMap<>(); filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); @@ -559,7 +560,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceWithDetails = new HashMap<>(); List> filteredDevicesWithDetails = new ArrayList<>(); try { con = this.getConnection(); @@ -589,7 +589,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + Map filteredDeviceWithDetails; while (rs.next()) { + filteredDeviceWithDetails = new HashMap<>(); filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); From b8972c90198e11bcdeec1aecddbf1ee271825344 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 29 Apr 2016 05:40:34 +0530 Subject: [PATCH 3/5] Adding temporary development code bits for dashboard analytics feature --- .../dashboard/dao/GadgetDataServiceDAO.java | 32 ++++++++++--------- .../internal/GadgetDataServiceImpl.java | 26 +++++++++++++-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java index f54701c716..6cbdba08bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java @@ -33,65 +33,67 @@ public interface GadgetDataServiceDAO { */ int getTotalDeviceCount() throws GadgetDataServiceDAOException; + /** + * Method to get active device count from a particular tenant. + * + * @return active device count. + */ int getActiveDeviceCount() throws GadgetDataServiceDAOException; + /** + * Method to get inactive device count from a particular tenant. + * + * @return inactive device count. + */ int getInactiveDeviceCount() throws GadgetDataServiceDAOException; + /** + * Method to get removed device count from a particular tenant. + * + * @return removed device count. + */ int getRemovedDeviceCount() throws GadgetDataServiceDAOException; /** - * Method to get non-compliant device count. + * Method to get non-compliant device count from a particular tenant. * * @return Non-compliant device count. */ - @SuppressWarnings("unused") int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException; /** - * Method to get unmonitored device count. + * Method to get unmonitored device count from a particular tenant. * * @return Unmonitored device count. */ - @SuppressWarnings("unused") int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") int getDeviceCount(Map filters) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") Map getDeviceCountsByPlatforms(Map filters) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, Map filters) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") Map getDeviceCountsByOwnershipTypes(Map filters) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, Map filters) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") PaginationResult getDevicesWithDetails(Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") List> getDevicesWithDetails(Map filters) throws GadgetDataServiceDAOException; - @SuppressWarnings("unused") List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, Map filters) throws GadgetDataServiceDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java index c0df361d9f..2f31b84f40 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java @@ -270,12 +270,32 @@ class GadgetDataServiceImpl implements GadgetDataService { @Override public List> getDevicesWithDetails(Map filters) { - return null; + List> devicesWithDetails = null; + try { + GadgetDataServiceDAOFactory.openConnection(); + devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters); + } catch (GadgetDataServiceDAOException | SQLException e) { + return null; + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return devicesWithDetails; } @Override - public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, Map filters) { - return null; + public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, + Map filters) { + List> featureNonCompliantDevicesWithDetails = null; + try { + GadgetDataServiceDAOFactory.openConnection(); + featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters); + } catch (GadgetDataServiceDAOException | SQLException e) { + return null; + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return featureNonCompliantDevicesWithDetails; } } From a2cb6937c132ceea56aea62497423953209e4389 Mon Sep 17 00:00:00 2001 From: charithag Date: Fri, 29 Apr 2016 12:46:53 +0530 Subject: [PATCH 4/5] Fix device listing page title --- .../devicemgt/app/pages/cdmf.page.devices/devices.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index 1122acfc29..2966fa09a2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -1,4 +1,4 @@ -{{unit "cdmf.unit.ui.title" pageTitle=title}} +{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}} {{unit "cdmf.unit.data-tables-extended"}} From fd531555a3f1e41e73c963de623da85ddb6eb33a Mon Sep 17 00:00:00 2001 From: charithag Date: Fri, 29 Apr 2016 13:34:46 +0530 Subject: [PATCH 5/5] Fix bugs --- .../mgt/core/group/mgt/dao/GroupDAOImpl.java | 2 +- .../app/pages/cdmf.page.devices/devices.hbs | 31 +++++++++++-- .../cdmf.page.devices/public/js/listing.js | 45 ++++++++----------- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java index ffa7fe65c7..1dc62b8046 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java @@ -384,7 +384,7 @@ public class GroupDAOImpl implements GroupDAO { Connection conn = GroupManagementDAOFactory.getConnection(); String sql = "SELECT COUNT(gm.ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP gm, (SELECT ID " + "FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?) dg " + - "WHERE gm.GROUP_ID = dg.ID AND dm.TENANT_ID = ?"; + "WHERE gm.GROUP_ID = dg.ID AND gm.TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, groupName); stmt.setString(2, owner); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index 2966fa09a2..b800c8777e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -55,6 +55,11 @@ {{/zone}} {{#zone "content"}} +
+
+ {{title}} +
+
@@ -275,7 +280,7 @@