add error log

avn-pack
Thilina Sandaruwan 1 year ago
parent 00b107ee99
commit e66c3dc6f6

@ -152,21 +152,22 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ
@Path("/roles/share") @Path("/roles/share")
@Override @Override
public Response createGroupWithRoles(DeviceGroupRoleWrapper group) { public Response createGroupWithRoles(DeviceGroupRoleWrapper group) {
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).build();
} }
group.setOwner(owner); group.setOwner(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE);
try { try {
DeviceMgtAPIUtils.getGroupManagementProviderService().createGroupWithRoles(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); DeviceMgtAPIUtils.getGroupManagementProviderService().createGroupWithRoles(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
DeviceMgtAPIUtils.getGroupManagementProviderService().manageGroupSharing(group.getGroupId(), group.getUserRoles()); DeviceMgtAPIUtils.getGroupManagementProviderService().manageGroupSharing(group.getGroupId(), group.getUserRoles());
return Response.status(Response.Status.CREATED).build(); return Response.status(Response.Status.CREATED).build();
} catch (GroupManagementException e) { } catch (GroupManagementException e) {
String msg = "Error occurred while adding new group."; String msg = "Error occurred while adding " + group.getName() + " group";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupAlreadyExistException e) { } catch (GroupAlreadyExistException e) {
String msg = "Group already exists with name : " + group.getName() + "."; String msg = "Group already exists with name : " + group.getName() + ".";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build(); return Response.status(Response.Status.CONFLICT).entity(msg).build();
} catch (RoleDoesNotExistException e) { } catch (RoleDoesNotExistException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();

Loading…
Cancel
Save