|
|
|
@ -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);
|
|
|
|
|