|
|
@ -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.PaginationResult;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
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.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.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.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
@ -50,6 +50,9 @@ import java.util.List;
|
|
|
|
@SuppressWarnings("NonJaxWsWebServices")
|
|
|
|
@SuppressWarnings("NonJaxWsWebServices")
|
|
|
|
public class GroupImpl implements Group {
|
|
|
|
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);
|
|
|
|
private static Log log = LogFactory.getLog(GroupImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -58,7 +61,9 @@ public class GroupImpl implements Group {
|
|
|
|
public Response createGroup(DeviceGroup group) {
|
|
|
|
public Response createGroup(DeviceGroup group) {
|
|
|
|
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
if (group == null) {
|
|
|
|
if (group == null) {
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).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}$")) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(GROUP_NAME_INVALID_MSG).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
group.setOwner(owner);
|
|
|
|
group.setOwner(owner);
|
|
|
|
group.setDateOfCreation(new Date().getTime());
|
|
|
|
group.setDateOfCreation(new Date().getTime());
|
|
|
@ -78,7 +83,7 @@ public class GroupImpl implements Group {
|
|
|
|
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DeviceGroupConstants.Roles.DEFAULT_VIEW_EVENTS,
|
|
|
|
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DeviceGroupConstants.Roles.DEFAULT_VIEW_EVENTS,
|
|
|
|
DeviceGroupConstants.Permissions.DEFAULT_VIEW_EVENTS_PERMISSIONS);
|
|
|
|
DeviceGroupConstants.Permissions.DEFAULT_VIEW_EVENTS_PERMISSIONS);
|
|
|
|
return Response.status(Response.Status.CREATED).build();
|
|
|
|
return Response.status(Response.Status.CREATED).build();
|
|
|
|
} catch (GroupAlreadyEixistException e) {
|
|
|
|
} catch (GroupAlreadyExistException e) {
|
|
|
|
return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
|
|
|
|
return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
log.error(e.getErrorMessage(), e);
|
|
|
|
log.error(e.getErrorMessage(), e);
|
|
|
@ -92,9 +97,12 @@ public class GroupImpl implements Group {
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public Response updateGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner,
|
|
|
|
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}$")) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(GROUP_NAME_INVALID_MSG).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupName, owner);
|
|
|
|
DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(group, groupName, owner);
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
log.error(e.getErrorMessage(), e);
|
|
|
|
log.error(e.getErrorMessage(), e);
|
|
|
|