From 20343d93497d15020e2781d6266c074d05438875 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Mon, 30 May 2016 13:03:21 +0530 Subject: [PATCH 1/3] fixed swagger message issue --- .../wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java | 2 +- .../device/mgt/jaxrs/api/impl/DeviceNotificationImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java index c2c5c99f81..5a02dc0837 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java @@ -112,7 +112,7 @@ public interface DeviceNotification { value = "Sending a Device Notification", notes = "Notify users on device operation failures and other information using this REST API") @ApiResponses(value = { - @ApiResponse(code = 201, message = "NNotification has added successfully"), + @ApiResponse(code = 201, message = "Notification has been added successfully"), @ApiResponse(code = 500, message = "Error occurred while updating notification status") }) @Permission(scope = "device-notification-modify", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceNotificationImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceNotificationImpl.java index 3a4ece1a17..ea2da30f29 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceNotificationImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceNotificationImpl.java @@ -97,7 +97,7 @@ public class DeviceNotificationImpl implements DeviceNotification{ ResponsePayload responseMsg = new ResponsePayload(); try { DeviceMgtAPIUtils.getNotificationManagementService().addNotification(notification); - responseMsg.setMessageFromServer("Notification has added successfully."); + responseMsg.setMessageFromServer("Notification has been added successfully."); responseMsg.setStatusCode(HttpStatus.SC_CREATED); return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } catch (NotificationManagementException e) { From e2c03adec478612116e8c7ba76fed23bf14d1e22 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 31 May 2016 11:14:37 +0530 Subject: [PATCH 2/3] FIx for https://wso2.org/jira/browse/IOTS-169 --- .../device/mgt/jaxrs/api/impl/GroupImpl.java | 19 ++++++++--- ...n.java => GroupAlreadyExistException.java} | 12 +++---- .../GroupManagementProviderService.java | 4 +-- .../GroupManagementProviderServiceImpl.java | 6 ++-- .../devicemgt/app/conf/config.json | 5 +++ .../pages/cdmf.page.group.create/create.hbs | 24 +++----------- .../pages/cdmf.page.group.create/create.js | 32 +++++++++++++++++++ .../public/js/group-add.js | 16 ++++++++++ .../app/pages/cdmf.page.groups/groups.hbs | 3 +- .../cdmf.page.groups/public/js/listing.js | 3 ++ 10 files changed, 86 insertions(+), 38 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/{GroupAlreadyEixistException.java => GroupAlreadyExistException.java} (78%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java index 14c6323818..2f0b1d111d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java @@ -25,7 +25,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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.DeviceGroupConstants; -import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyEixistException; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; 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; @@ -58,7 +58,11 @@ public class GroupImpl implements Group { public Response createGroup(DeviceGroup group) { String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); if (group == null) { - return Response.status(Response.Status.BAD_REQUEST).build(); + return Response.status(Response.Status.BAD_REQUEST).entity("Group cannot be null").build(); + } else if (group.getName() == null || !group.getName().matches("^[\\S]{3,30}$")) { + String msg = "Provided group name is invalid. Should be in minimum 3 characters long " + + "and should not include any whitespaces."; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } group.setOwner(owner); group.setDateOfCreation(new Date().getTime()); @@ -78,7 +82,7 @@ public class GroupImpl implements Group { groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DeviceGroupConstants.Roles.DEFAULT_VIEW_EVENTS, DeviceGroupConstants.Permissions.DEFAULT_VIEW_EVENTS_PERMISSIONS); return Response.status(Response.Status.CREATED).build(); - } catch (GroupAlreadyEixistException e) { + } catch (GroupAlreadyExistException e) { return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build(); } catch (GroupManagementException e) { log.error(e.getErrorMessage(), e); @@ -92,9 +96,14 @@ public class GroupImpl implements Group { @Consumes("application/json") @Produces("application/json") public Response updateGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner, - DeviceGroup deviceGroup) { + DeviceGroup group) { + if (group.getName() == null || !group.getName().matches("^[\\S]{3,30}$")) { + String msg = "Provided group name is invalid. Should be in minimum 3 characters long " + + "and should not include any whitespaces."; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } try { - DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupName, owner); + DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(group, groupName, owner); return Response.status(Response.Status.OK).build(); } catch (GroupManagementException e) { log.error(e.getErrorMessage(), e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/GroupAlreadyEixistException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/GroupAlreadyExistException.java similarity index 78% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/GroupAlreadyEixistException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/GroupAlreadyExistException.java index 0ee0960b20..f849d0952b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/GroupAlreadyEixistException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/group/mgt/GroupAlreadyExistException.java @@ -21,31 +21,31 @@ package org.wso2.carbon.device.mgt.common.group.mgt; /** * This class represents a custom exception specified for group management */ -public class GroupAlreadyEixistException extends Exception { +public class GroupAlreadyExistException extends Exception { private static final long serialVersionUID = -312678379574816874L; private String errorMessage; - public GroupAlreadyEixistException(String msg, Exception nestedEx) { + public GroupAlreadyExistException(String msg, Exception nestedEx) { super(msg, nestedEx); setErrorMessage(msg); } - public GroupAlreadyEixistException(String message, Throwable cause) { + public GroupAlreadyExistException(String message, Throwable cause) { super(message, cause); setErrorMessage(message); } - public GroupAlreadyEixistException(String msg) { + public GroupAlreadyExistException(String msg) { super(msg); setErrorMessage(msg); } - public GroupAlreadyEixistException() { + public GroupAlreadyExistException() { super(); } - public GroupAlreadyEixistException(Throwable cause) { + public GroupAlreadyExistException(Throwable cause) { super(cause); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java index 82564aec36..1b16cc0507 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java @@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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.GroupAlreadyExistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser; import org.wso2.carbon.user.core.multiplecredentials.UserDoesNotExistException; @@ -43,7 +43,7 @@ public interface GroupManagementProviderService { * @throws GroupManagementException */ void createGroup(DeviceGroup deviceGroup, String defaultRole, - String[] defaultPermissions) throws GroupManagementException, GroupAlreadyEixistException; + String[] defaultPermissions) throws GroupManagementException, GroupAlreadyExistException; /** * Update existing device group. 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 6cecc185e0..dc01ddf5d6 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 @@ -29,7 +29,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.TransactionManagementException; 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.GroupAlreadyExistException; 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.group.mgt.DeviceGroupBuilder; @@ -69,7 +69,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public void createGroup(DeviceGroup deviceGroup, String defaultRole, String[] defaultPermissions) - throws GroupManagementException, GroupAlreadyEixistException { + throws GroupManagementException, GroupAlreadyExistException { if (deviceGroup == null) { throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); } @@ -83,7 +83,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid groupId = this.groupDAO.addGroup(groupBroker, tenantId); GroupManagementDAOFactory.commitTransaction(); } else { - throw new GroupAlreadyEixistException("Group exist with name " + deviceGroup.getName()); + throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName()); } } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); 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 bef0d5884f..8d8f82d08b 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 @@ -37,6 +37,11 @@ "emailJSRegEx" : "/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/", "emailRegExViolationErrorMsg" : "Provided email is invalid." }, + "groupValidationConfig": { + "groupNameJSRegEx": "^[\\S]{3,30}$", + "groupNameRegExViolationErrorMsg": "Provided group name is invalid.", + "groupNameHelpMsg": "Should be in minimum 3 characters long and should not include any whitespaces." + }, "roleValidationConfig" : { "rolenameJSRegEx" : "^[\\S]{3,30}$", "rolenameRegExViolationErrorMsg" : "Provided role name is invalid.", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs index cc7aeaeb40..bcf105493b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs @@ -1,20 +1,3 @@ -{{! - 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. -}} {{unit "cdmf.unit.ui.title" pageTitle="Group Management"}} {{#zone "breadcrumbs"}} @@ -49,11 +32,12 @@
- + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js new file mode 100644 index 0000000000..5c646f33f9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js @@ -0,0 +1,32 @@ +/* + * 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-group 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 devicemgtProps = require('/app/conf/devicemgt-props.js').config(); + var page = {}; + page["groupNameJSRegEx"] = devicemgtProps.groupValidationConfig.groupNameJSRegEx; + page["groupNameRegExViolationErrorMsg"] = devicemgtProps.groupValidationConfig.groupNameRegExViolationErrorMsg; + page["groupNameHelpMsg"] = devicemgtProps.groupValidationConfig.groupNameHelpMsg; + return page; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js index 9e0bc2de9a..ae6870abd3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js @@ -16,6 +16,18 @@ * under the License. */ +/** + * Checks if provided input is valid against RegEx input. + * + * @param regExp Regular expression + * @param inputString Input string to check + * @returns {boolean} Returns true if input matches RegEx + */ +function inputIsValid(regExp, inputString) { + regExp = new RegExp(regExp); + return regExp.test(inputString); +} + $(function () { $("button#add-group-btn").click(function () { @@ -26,6 +38,10 @@ $(function () { $('.wr-validation-summary strong').text("Group Name is a required field. It cannot be empty."); $('.wr-validation-summary').removeClass("hidden"); return false; + } else if (!inputIsValid($("input#name").data("regex"), name)) { + $('.wr-validation-summary strong').text($("input#name").data("errormsg")); + $('.wr-validation-summary').removeClass("hidden"); + return false; } else { var group = {"name": name, "description": description}; 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 cb93094c76..263f47d411 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 @@ -226,8 +226,7 @@
-

Exception at backend. Try Later.

- +

Bad Request. Please contact your administrator.

    Ok     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 bd44775759..1c16e3dfd1 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 @@ -484,6 +484,9 @@ function displayErrors(jqXHR) { showPopup(); if (jqXHR.status == 400) { $(modalPopupContent).html($('#group-400-content').html()); + if (jqXHR.responseText) { + $('#error-msg').html(jqXHR.responseText.replace(new RegExp("\"", 'g'), "")); + } $("a#group-400-link").click(function () { hidePopup(); }); From 92a732cd411a5930c13926681ff190d55af5193b Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 31 May 2016 11:30:36 +0530 Subject: [PATCH 3/3] Moved redundant texts to constants --- .../carbon/device/mgt/jaxrs/api/impl/GroupImpl.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java index 2f0b1d111d..97c086bf14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/GroupImpl.java @@ -50,6 +50,9 @@ import java.util.List; @SuppressWarnings("NonJaxWsWebServices") public class GroupImpl implements Group { + private static final String GROUP_CANNOT_NULL_MSG = "Group cannot be null."; + private static final String GROUP_NAME_INVALID_MSG = "Provided group name is invalid. Should be in minimum 3 " + + "characters long and should not include any whitespaces."; private static Log log = LogFactory.getLog(GroupImpl.class); @Override @@ -58,11 +61,9 @@ public class GroupImpl implements Group { public Response createGroup(DeviceGroup group) { String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); if (group == null) { - return Response.status(Response.Status.BAD_REQUEST).entity("Group cannot be null").build(); + return Response.status(Response.Status.BAD_REQUEST).entity(GROUP_CANNOT_NULL_MSG).build(); } else if (group.getName() == null || !group.getName().matches("^[\\S]{3,30}$")) { - String msg = "Provided group name is invalid. Should be in minimum 3 characters long " + - "and should not include any whitespaces."; - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(GROUP_NAME_INVALID_MSG).build(); } group.setOwner(owner); group.setDateOfCreation(new Date().getTime()); @@ -98,9 +99,7 @@ public class GroupImpl implements Group { public Response updateGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner, DeviceGroup group) { if (group.getName() == null || !group.getName().matches("^[\\S]{3,30}$")) { - String msg = "Provided group name is invalid. Should be in minimum 3 characters long " + - "and should not include any whitespaces."; - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(GROUP_NAME_INVALID_MSG).build(); } try { DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(group, groupName, owner);