Merge pull request #406 from sameeragunarathne/IoTS-1.0.0

fixed share groups and group analytics in device grouping
revert-70aa11f8
Charitha Goonetilleke 8 years ago committed by GitHub
commit e1a1f710a0

@ -467,6 +467,58 @@ public interface GroupManagementService {
required = true) required = true)
@PathParam("groupId") int groupId); @PathParam("groupId") int groupId);
@Path("/id/{groupId}/roles")
@GET
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "View list of roles of a device group.",
notes = "Returns details of roles which particular group has been shared with.",
tags = "Device Group Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the users.",
response = DeviceGroupUsersList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the roles.",
response = ErrorResponse.class)
})
@Permission(name = "View roles", permission = "/device-mgt/groups/roles/view")
Response getRolesOfGroup(@ApiParam(
name = "groupId",
value = "ID of the group.",
required = true)
@PathParam("groupId") int groupId,
@ApiParam(
name = "userName",
value = "User name of the current user.",
required = false)
@QueryParam("userName") String userName);
@Path("/id/{groupId}/devices") @Path("/id/{groupId}/devices")
@GET @GET
@ApiOperation( @ApiOperation(

@ -34,13 +34,11 @@ 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.common.group.mgt.GroupUser;
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.*;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupShare;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupUsersList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException; import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -54,6 +52,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
private static final String DEFAULT_ADMIN_ROLE = "admin"; private static final String DEFAULT_ADMIN_ROLE = "admin";
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups", private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
"/permission/device-mgt/user/groups"}; "/permission/device-mgt/user/groups"};
private static final String EMPTY_RESULT = "EMPTY";
@Override @Override
public Response getGroups(String name, String owner, int offset, int limit) { public Response getGroups(String name, String owner, int offset, int limit) {
@ -201,6 +200,35 @@ public class GroupManagementServiceImpl implements GroupManagementService {
} }
} }
@Override
public Response getRolesOfGroup(int groupId, String userName) {
try {
List<String> groupRoles;
if(userName != null) {
groupRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(userName, groupId);
} else {
groupRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupId);
}
if(groupRoles != null && groupRoles.size() > 0) {
RoleList deviceGroupRolesList = new RoleList();
deviceGroupRolesList.setList(groupRoles);
deviceGroupRolesList.setCount(groupRoles.size());
return Response.status(Response.Status.OK).entity(deviceGroupRolesList).build();
} else {
return Response.status(Response.Status.OK).entity(EMPTY_RESULT).build();
}
} catch (GroupManagementException e) {
String msg = "Error occurred while getting roles of the group.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UserStoreException e) {
String msg = "Error while retrieving the user.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override @Override
public Response getDevicesOfGroup(int groupId, int offset, int limit) { public Response getDevicesOfGroup(int groupId, int offset, int limit) {
try { try {

@ -66,8 +66,8 @@ var groupModule = {};
); );
}; };
groupModule.getGroupDevices = function (groupName, owner) { groupModule.getGroupDevices = function (groupId) {
endPoint = deviceServiceEndpoint + "/groups/owner/" + owner + "/name/" + groupName + "/devices"; endPoint = deviceServiceEndpoint + "/groups/id/" + groupId + "/devices?limit=10";
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
endPoint, function (responsePayload) { endPoint, function (responsePayload) {
return responsePayload; return responsePayload;

@ -20,11 +20,16 @@ function onRequest(context) {
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
var groupName = context.uriParams.name; var groupName = context.uriParams.name;
var groupOwner = context.uriParams.owner; var groupId = context.uriParams.id;
var devices = groupModule.getGroupDevices(groupName, groupOwner).data; var devices = [];
var deviceResponse = groupModule.getGroupDevices(groupId).responseText;
if(deviceResponse != null) {
var deviceResponseObj = parse(deviceResponse);
devices = deviceResponseObj.devices;
}
var page = { var page = {
"groupName": groupName, "groupName": groupName,
"groupOwner": groupOwner,
"title": groupName + " Analytics" "title": groupName + " Analytics"
}; };
if (devices) { if (devices) {

@ -1,5 +1,5 @@
{ {
"version": "1.0.0", "version": "1.0.0",
"uri": "/group/{owner}/{name}/analytics", "uri": "/group/{name}/{id}/analytics",
"layout": "cdmf.layout.default" "layout": "cdmf.layout.default"
} }

@ -151,21 +151,31 @@ function loadGroups() {
data: 'name', data: 'name',
class: 'fade-edge' class: 'fade-edge'
}, },
{
targets: 2,
data: 'owner',
class: 'fade-edge remove-padding-top',
},
{ {
targets: 3, targets: 3,
data: 'description',
class: 'fade-edge remove-padding-top',
},
{
targets: 4,
data: 'id', data: 'id',
class: 'text-right content-fill text-left-on-grid-view no-wrap', class: 'text-right content-fill text-left-on-grid-view no-wrap',
render: function (id, type, row, meta) { render: function (id, type, row, meta) {
var html; var html;
html = '<a href="devices?groupId=' + row.groupId + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' + html = '<a href="devices?groupId=' + row.groupId + '&groupName=' + row.name + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' + '<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>'; '<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>';
html += '<a href="group/' + row.owner + '/' + row.name + '/analytics" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' + html += '<a href="group/' + row.name + '/' + row.groupId + '/analytics" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' + '<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>'; '<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-name="' + row.name + '" ' + html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-id="' + row.groupId + '" ' +
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>' + 'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>'; '<span class="hidden-xs hidden-on-grid-view">Share</span></a>';
@ -198,6 +208,11 @@ function loadGroups() {
$(this).attr('data-search', data.owner); $(this).attr('data-search', data.owner);
$(this).attr('data-display', data.owner); $(this).attr('data-display', data.owner);
break; break;
case 3:
$(this).attr('data-grid-label', "Description");
$(this).attr('data-search', data.description);
$(this).attr('data-display', data.description);
break;
} }
}); });
}; };
@ -326,7 +341,7 @@ function attachEvents() {
* on Group Management page in WSO2 Device Management Server Console. * on Group Management page in WSO2 Device Management Server Console.
*/ */
$("a.share-group-link").click(function () { $("a.share-group-link").click(function () {
var groupName = $(this).data("group-name"); var groupId = $(this).data("group-id");
var groupOwner = $(this).data("group-owner"); var groupOwner = $(this).data("group-owner");
$(modalPopupContent).html($('#share-group-w1-modal-content').html()); $(modalPopupContent).html($('#share-group-w1-modal-content').html());
$("a#share-group-next-link").show(); $("a#share-group-next-link").show();
@ -337,7 +352,7 @@ function attachEvents() {
$("#user-names").html("Please specify a user other than current user."); $("#user-names").html("Please specify a user other than current user.");
$("a#share-group-next-link").hide(); $("a#share-group-next-link").hide();
} else { } else {
getAllRoles(groupName, groupOwner, selectedUser); getAllRoles(groupId, selectedUser);
} }
}); });
$("a#share-group-w1-cancel-link").click(function () { $("a#share-group-w1-cancel-link").click(function () {
@ -352,6 +367,7 @@ function attachEvents() {
*/ */
$("a.remove-group-link").click(function () { $("a.remove-group-link").click(function () {
var groupId = $(this).data("group-id"); var groupId = $(this).data("group-id");
var groupOwner = $(this).data("group-owner");
$(modalPopupContent).html($('#remove-group-modal-content').html()); $(modalPopupContent).html($('#remove-group-modal-content').html());
showPopup(); showPopup();
@ -426,15 +442,15 @@ function attachEvents() {
}); });
} }
function getAllRoles(groupName, groupOwner, selectedUser) { function getAllRoles(groupId, selectedUser) {
$(modalPopupContent).html($('#share-group-w2-modal-content').html()); $(modalPopupContent).html($('#share-group-w2-modal-content').html());
$('#user-roles').html('<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>'); $('#user-roles').html('<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>');
$("a#share-group-yes-link").hide(); $("a#share-group-yes-link").hide();
var successCallback = function (data, textStatus, xhr) { var successCallback = function (data, textStatus, xhr) {
data = JSON.parse(data); data = JSON.parse(data);
if (xhr.status == 200) { if (xhr.status == 200) {
if (data.length > 0) { if (data.roles.length > 0) {
generateRoleMap(groupName, groupOwner, selectedUser, data); generateRoleMap(groupId, selectedUser, data.roles);
} else { } else {
$('#user-roles').html("There is no any roles for this group."); $('#user-roles').html("There is no any roles for this group.");
} }
@ -443,7 +459,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) {
} }
}; };
invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles", invokerUtil.get("/api/device-mgt/v1.0/groups/id/" + groupId + "/roles",
successCallback, function (message) { successCallback, function (message) {
displayErrors(message); displayErrors(message);
}); });
@ -453,11 +469,14 @@ function getAllRoles(groupName, groupOwner, selectedUser) {
}); });
} }
function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { function generateRoleMap(groupId, selectedUser, allRoles) {
var successCallback = function (data, textStatus, xhr) { var successCallback = function (data, textStatus, xhr) {
data = JSON.parse(data); data = JSON.parse(data);
if (xhr.status == 200) { if (xhr.status == 200) {
var userRoles = data; var userRoles = [];
if(data != "EMPTY") {
userRoles = data.roles;
}
var str = ''; var str = '';
for (var i = 0; i < allRoles.length; i++) { for (var i = 0; i < allRoles.length; i++) {
@ -482,14 +501,14 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
roles.push(allRoles[i]); roles.push(allRoles[i]);
} }
} }
updateGroupShare(groupName, groupOwner, selectedUser, roles); updateGroupShare(groupId, selectedUser, roles);
}); });
} else { } else {
displayErrors(xhr); displayErrors(xhr);
} }
}; };
invokerUtil.get("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/share/roles?userName=" + selectedUser, invokerUtil.get("/api/device-mgt/v1.0/groups/id/" + groupId + "/roles?userName=" + selectedUser,
successCallback, function (message) { successCallback, function (message) {
displayErrors(message); displayErrors(message);
}); });
@ -499,7 +518,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
}); });
} }
function updateGroupShare(groupName, groupOwner, selectedUser, roles) { function updateGroupShare(groupId, selectedUser, roles) {
var successCallback = function (data) { var successCallback = function (data) {
$(modalPopupContent).html($('#share-group-200-content').html()); $(modalPopupContent).html($('#share-group-200-content').html());
setTimeout(function () { setTimeout(function () {
@ -508,8 +527,9 @@ function updateGroupShare(groupName, groupOwner, selectedUser, roles) {
}, 2000); }, 2000);
}; };
invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/user/" + selectedUser + "/share/roles", var deviceGroupShare = {"username": selectedUser, "groupRoles": roles };
roles, successCallback, function (message) { invokerUtil.post("/api/device-mgt/v1.0/groups/id/" + groupId + "/share",
deviceGroupShare, successCallback, function (message) {
displayErrors(message); displayErrors(message);
}); });
} }

Loading…
Cancel
Save