From 92a732cd411a5930c13926681ff190d55af5193b Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 31 May 2016 11:30:36 +0530 Subject: [PATCH] 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 2f0b1d111d6..97c086bf141 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);