diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java index cc5fa3ddac6..8bab08463b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -173,7 +173,10 @@ public class GroupManagementServiceImpl implements GroupManagementService { .manageGroupSharing(groupId, userRoles); return Response.status(Response.Status.OK).build(); } catch (GroupManagementException e) { - String msg = "Error occurred while managing group share."; + String msg = "Error occurred while managing group share. "; + if (e.getErrorMessage() != null){ + msg += e.getErrorMessage(); + } log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RoleDoesNotExistException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 94b480978e7..fa169c58a98 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -367,39 +367,43 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void manageGroupSharing(int groupId, List newRoles) throws GroupManagementException, RoleDoesNotExistException { - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - UserStoreManager userStoreManager; - try { - userStoreManager = - DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm( - tenantId).getUserStoreManager(); - List currentUserRoles = getRoles(groupId); - GroupManagementDAOFactory.beginTransaction(); - for (String role : newRoles) { - if (!userStoreManager.isExistingRole(role)) { - throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store."); + if (newRoles != null) { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + UserStoreManager userStoreManager; + try { + userStoreManager = + DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm( + tenantId).getUserStoreManager(); + List currentUserRoles = getRoles(groupId); + GroupManagementDAOFactory.beginTransaction(); + for (String role : newRoles) { + if (!userStoreManager.isExistingRole(role)) { + throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store."); + } + // Removing role from current user roles of the group will return true if role exist. + // So we don't need to add it to the db again. + if (!currentUserRoles.remove(role)) { + // If group doesn't have the role, it is adding to the db. + groupDAO.addRole(groupId, role, tenantId); + } } - // Removing role from current user roles of the group will return true if role exist. - // So we don't need to add it to the db again. - if (!currentUserRoles.remove(role)) { - // If group doesn't have the role, it is adding to the db. - groupDAO.addRole(groupId, role, tenantId); + for (String role : currentUserRoles) { + // Removing old roles from db which are not available in the new roles list. + groupDAO.removeRole(groupId, role, tenantId); } + GroupManagementDAOFactory.commitTransaction(); + } catch (GroupManagementDAOException e) { + GroupManagementDAOFactory.rollbackTransaction(); + throw new GroupManagementException(e); + } catch (UserStoreException e) { + throw new GroupManagementException("User store error in updating sharing roles.", e); + } catch (TransactionManagementException e) { + throw new GroupManagementException(e); + } finally { + GroupManagementDAOFactory.closeConnection(); } - for (String role : currentUserRoles) { - // Removing old roles from db which are not available in the new roles list. - groupDAO.removeRole(groupId, role, tenantId); - } - GroupManagementDAOFactory.commitTransaction(); - } catch (GroupManagementDAOException e) { - GroupManagementDAOFactory.rollbackTransaction(); - throw new GroupManagementException(e); - } catch (UserStoreException e) { - throw new GroupManagementException("User store error in updating sharing roles.", e); - } catch (TransactionManagementException e) { - throw new GroupManagementException(e); - } finally { - GroupManagementDAOFactory.closeConnection(); + } else { + throw new GroupManagementException("No roles provided to complete the operation."); } } @@ -469,12 +473,12 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.beginTransaction(); - for (DeviceIdentifier deviceIdentifier : deviceIdentifiers){ + for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier); if (device == null) { throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'"); } - if (!this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId)){ + if (!this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId)) { this.groupDAO.addDevice(groupId, device.getId(), tenantId); } } @@ -501,7 +505,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.beginTransaction(); - for (DeviceIdentifier deviceIdentifier : deviceIdentifiers){ + for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceIdentifier); if (device == null) { throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'"); @@ -554,7 +558,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid Device device = managementProviderService.getDevice(deviceIdentifier); GroupManagementDAOFactory.openConnection(); return groupDAO.getGroups(device.getId(), - PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (DeviceManagementException e) { throw new GroupManagementException("Error occurred while retrieving the device details.", e); } catch (GroupManagementDAOException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index 5caf20f31fa..f6120a5c146 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -2,7 +2,7 @@ "appContext": "/devicemgt/", "isCloud": false, "httpsURL": "https://%iot.gateway.host%:%iot.gateway.https.port%", - "httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port", + "httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port%", "wssURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", "portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", "dashboardServerURL": "%https.ip%", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs index 74d866758ba..645d05b0ed7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs @@ -381,7 +381,7 @@
-

Unexpected error occurred!

+

Unexpected error occurred!

diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 7dfacfb41f2..1fc2eec829e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -112,7 +112,7 @@ function toTitleCase(str) { }); } -function htmlspecialchars(text){ +function htmlspecialchars(text) { return jQuery('
').text(text).html(); } @@ -138,11 +138,11 @@ function loadGroups() { var objects = []; $(data.deviceGroups).each(function (index) { objects.push({ - groupId: htmlspecialchars(data.deviceGroups[index].id), - name: htmlspecialchars(data.deviceGroups[index].name), - description: htmlspecialchars(data.deviceGroups[index].description), - owner: htmlspecialchars(data.deviceGroups[index].owner) - }) + groupId: htmlspecialchars(data.deviceGroups[index].id), + name: htmlspecialchars(data.deviceGroups[index].name), + description: htmlspecialchars(data.deviceGroups[index].description), + owner: htmlspecialchars(data.deviceGroups[index].owner) + }) }); var json = { "recordsTotal": data.count, @@ -159,7 +159,7 @@ function loadGroups() { class: 'remove-padding icon-only content-fill viewEnabledIcon', render: function (data, type, row, meta) { return '
'; + 'src="public/cdmf.page.groups/images/group-icon.png"/>
'; } }, { @@ -185,38 +185,38 @@ function loadGroups() { var html = ''; if ($.hasPermission("VIEW_GROUP_DEVICES")) { /*html += '
' + - '' - + - '';*/ + + '/analytics" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' + + '' + + + '';*/ } if (row.owner != "wso2.system.user") { if ($.hasPermission("SHARE_GROUP")) { html += - ''; + ''; } if ($.hasPermission("UPDATE_GROUP")) { html += - '' + - ''; + '' + + ''; } if ($.hasPermission("REMOVE_GROUP")) { html += - '' - + - ''; + '' + + + ''; } } return html; @@ -251,21 +251,21 @@ function loadGroups() { }; $('#group-grid').datatables_extended_serverside_paging( - null, - serviceURL, - dataFilter, - columns, - fnCreatedRow, - function (oSettings) { - $(".icon .text").res_text(0.2); - attachEvents(); - var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); - thisTable.removeClass("table-selectable"); - }, - { - "placeholder": "Search By Group Name", - "searchKey": "name" - } + null, + serviceURL, + dataFilter, + columns, + fnCreatedRow, + function (oSettings) { + $(".icon .text").res_text(0.2); + attachEvents(); + var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + thisTable.removeClass("table-selectable"); + }, + { + "placeholder": "Search By Group Name", + "searchKey": "name" + } ); $(groupCheckbox).click(function () { addGroupSelectedClass(this); @@ -442,7 +442,7 @@ function attachEvents() { }; invokerUtil.delete("/api/device-mgt/v1.0/groups/id/" + groupId, - successCallback, function (message) { + successCallback, function (message) { displayErrors(message); }); }); @@ -487,7 +487,7 @@ function attachEvents() { }; invokerUtil.put("/api/device-mgt/v1.0/groups/id/" + groupId, group, - successCallback, function (message) { + successCallback, function (message) { displayErrors(message); }); }); @@ -517,7 +517,7 @@ function markAlreadySavedUsersRoles(groupId) { }; invokerUtil.get("/api/device-mgt/v1.0/groups/id/" + groupId + "/roles", - successCallback, function (message) { + successCallback, function (message) { displayErrors(message); }); } @@ -535,8 +535,8 @@ function listAllRoles(groupId) { $("#rolesListing").html(html); markAlreadySavedUsersRoles(groupId); $("select.select2[multiple=multiple]").select2({ - tags: false - }); + tags: false + }); } else { $("#rolesListing").html("No roles available"); } @@ -546,7 +546,7 @@ function listAllRoles(groupId) { }; invokerUtil.get("/api/device-mgt/v1.0/roles?offset=0&limit=100&user-store=all", - successCallback, function (message) { + successCallback, function (message) { displayErrors(message); }); } @@ -589,7 +589,7 @@ function updateGroupShare(groupId, roles) { }; invokerUtil.post("/api/device-mgt/v1.0/groups/id/" + groupId + "/share", - roles, successCallback, function (message) { + roles, successCallback, function (message) { displayErrors(message); }); } @@ -600,7 +600,7 @@ function createNewCombinedRole(roleName, roleList) { showPopup(); }; invokerUtil.post("/api/device-mgt/v1.0/roles/create-combined-role/" + roleName, roleList, - successCallback, function (message) { + successCallback, function (message) { displayErrors(message); }); } @@ -633,6 +633,9 @@ function displayErrors(jqXHR) { }); } else { $(modalPopupContent).html($('#group-unexpected-error-content').html()); + if (jqXHR.responseText) { + $('#unexp-error-msg').html(jqXHR.responseText.replace(new RegExp("\"", 'g'), "")); + } $("a#group-unexpected-error-link").click(function () { hidePopup(); });