mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Improving Device and Policy Management APIs and cleaning up code of Role and User Management APIs
This commit is contained in:
parent
624e7df688
commit
37852051ff
@ -27,7 +27,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
@ -35,10 +34,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
@ -100,9 +96,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
try {
|
||||
sinceDate = format.parse(ifModifiedSince);
|
||||
} catch (ParseException e) {
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid date " +
|
||||
"string is provided in 'If-Modified-Since' header").build());
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
|
||||
"string is provided in 'If-Modified-Since' header").build()).build();
|
||||
}
|
||||
request.setSince(sinceDate);
|
||||
result = dms.getAllDevices(request);
|
||||
@ -116,9 +112,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
try {
|
||||
sinceDate = format.parse(since);
|
||||
} catch (ParseException e) {
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid date " +
|
||||
"string is provided in 'since' filter").build());
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
|
||||
"string is provided in 'since' filter").build()).build();
|
||||
}
|
||||
request.setSince(sinceDate);
|
||||
result = dms.getAllDevices(request);
|
||||
@ -140,8 +136,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while fetching all enrolled devices";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,13 +157,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while fetching the device information.";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
if (device == null) {
|
||||
throw new NotFoundException(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Requested device of type '" +
|
||||
type + "', which carries id '" + id + "' does not exist").build());
|
||||
type + "', which carries id '" + id + "' does not exist").build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(device).build();
|
||||
}
|
||||
@ -187,17 +183,17 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||
FeatureManager fm = dms.getFeatureManager(type);
|
||||
if (fm == null) {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No feature manager is " +
|
||||
"registered with the given type '" + type + "'").build());
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
||||
"registered with the given type '" + type + "'").build()).build();
|
||||
}
|
||||
features = fm.getFeatures();
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while retrieving the list of features of '" + type + "' device, which " +
|
||||
"carries the id '" + id + "'";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(features).build();
|
||||
}
|
||||
@ -216,13 +212,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
} catch (SearchMgtException e) {
|
||||
String msg = "Error occurred while searching for devices that matches the provided selection criteria";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
if (devices == null || devices.size() == 0) {
|
||||
Response.status(Response.Status.OK).entity(deviceList);
|
||||
}
|
||||
|
||||
deviceList.setList(devices);
|
||||
return Response.status(Response.Status.OK).entity(deviceList).build();
|
||||
}
|
||||
@ -237,23 +229,21 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit) {
|
||||
List<Application> applications;
|
||||
//ApplicationList appList;
|
||||
ApplicationManagementProviderService amc;
|
||||
try {
|
||||
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
||||
|
||||
amc = DeviceMgtAPIUtils.getAppManagementService();
|
||||
applications = amc.getApplicationListForDevice(new DeviceIdentifier(id, type));
|
||||
if (applications == null) {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that " +
|
||||
"no applications is found upon the provided type and id").build());
|
||||
}
|
||||
|
||||
//TODO: return app list
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while fetching the apps of the '" + type + "' device, which carries " +
|
||||
"the id '" + id + "'";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(applications).build();
|
||||
}
|
||||
@ -276,23 +266,17 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
|
||||
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||
result = dms.getOperations(new DeviceIdentifier(id, type),request);
|
||||
int resultCount = result.getRecordsTotal();
|
||||
|
||||
if (resultCount == 0) {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that" +
|
||||
" no operation is found upon the provided type and id").build());
|
||||
}
|
||||
operationsList.setList((List<? extends Operation>) result.getData());
|
||||
operationsList.setCount(result.getRecordsTotal());
|
||||
return Response.status(Response.Status.OK).entity(operationsList).build();
|
||||
} catch (OperationManagementException e) {
|
||||
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
|
||||
"carries the id '" + id + "'";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
operationsList.setList((List<? extends Operation>) result.getData());
|
||||
operationsList.setCount(result.getRecordsTotal());
|
||||
return Response.status(Response.Status.OK).entity(operationsList).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -306,18 +290,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
|
||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||
Policy policy = policyManagementService.getAppliedPolicyToDevice(new DeviceIdentifier(id, type));
|
||||
if (policy == null) {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No policy has " +
|
||||
"been found for the '" + type + "' device, which carries the id '" + id + "'").build());
|
||||
}
|
||||
|
||||
return Response.status(Response.Status.OK).entity(policy).build();
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Error occurred while retrieving the current policy associated with the '" + type +
|
||||
"' device, which carries the id '" + id + "'";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,6 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.PolicyManagementService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
@ -45,6 +44,8 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -53,6 +54,7 @@ import java.util.List;
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
|
||||
private static final String API_BASE_PATH = "/policies";
|
||||
private static final Log log = LogFactory.getLog(PolicyManagementServiceImpl.class);
|
||||
|
||||
@POST
|
||||
@ -74,31 +76,38 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
String username = threadLocalCarbonContext.getUsername();
|
||||
try {
|
||||
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, username)) {
|
||||
throw new UnauthorizedAccessException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(401l).setMessage
|
||||
("Current logged in user is not authorized to add policies").build());
|
||||
return Response.status(Response.Status.UNAUTHORIZED).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage
|
||||
("Current logged in user is not authorized to add policies").build()).build();
|
||||
}
|
||||
} catch (DeviceAccessAuthorizationException e) {
|
||||
String msg = "ErrorResponse occurred while checking if the current user is authorized to add a policy";
|
||||
String msg = "Error occurred while checking if the current user is authorized to add a policy";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||
pap.addPolicy(policy);
|
||||
return Response.status(Response.Status.CREATED).entity("Policy has been added successfully").build();
|
||||
Policy createdPolicy = pap.addPolicy(policy);
|
||||
|
||||
return Response.created(new URI(API_BASE_PATH + "/" + createdPolicy.getId())).entity(createdPolicy).build();
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "ErrorResponse occurred while adding policy";
|
||||
String msg = "Error occurred while adding policy";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()).build();
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving device list.";
|
||||
String msg = "Error occurred while retrieving device list.";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()).build();
|
||||
} catch (URISyntaxException e) {
|
||||
String msg = "Error occurred while composing the location URI, which represents information of the " +
|
||||
"newly created policy";
|
||||
log.error(msg, e);
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,21 +147,14 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
try {
|
||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||
policies = policyAdministratorPoint.getPolicies();
|
||||
if (policies == null || policies.size() == 0) {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No policies found.").build());
|
||||
}
|
||||
targetPolicies.setCount(policies.size());
|
||||
filteredPolicies = FilteringUtil.getFilteredList(policies, offset, limit);
|
||||
if (filteredPolicies.size() == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
|
||||
}
|
||||
targetPolicies.setList(filteredPolicies);
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving all available policies";
|
||||
String msg = "Error occurred while retrieving all available policies";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
|
||||
return Response.status(Response.Status.OK).entity(targetPolicies).build();
|
||||
@ -168,14 +170,15 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||
policy = policyAdministratorPoint.getPolicy(id);
|
||||
if (policy == null) {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No policy found.").build());
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
"No policy found with the id '" + id + "'").build()).build();
|
||||
}
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving policy corresponding to the id '" + id + "'";
|
||||
String msg = "Error occurred while retrieving policy corresponding to the id '" + id + "'";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(policy).build();
|
||||
}
|
||||
@ -190,22 +193,22 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
Policy policy = this.getPolicyFromWrapper(policyWrapper);
|
||||
policy.setId(id);
|
||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||
Policy exisitingPolicy = pap.getPolicy(id);
|
||||
if (exisitingPolicy == null) {
|
||||
Policy existingPolicy = pap.getPolicy(id);
|
||||
if (existingPolicy == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Policy not found.").build();
|
||||
}
|
||||
pap.updatePolicy(policy);
|
||||
return Response.status(Response.Status.OK).entity("Policy has successfully been updated.").build();
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "ErrorResponse occurred while updating the policy";
|
||||
String msg = "Error occurred while updating the policy";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving the device list.";
|
||||
String msg = "Error occurred while retrieving the device list.";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,15 +230,15 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "ErrorResponse occurred while removing policies";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
if (policyDeleted) {
|
||||
return Response.status(Response.Status.OK).entity("Policies have been successfully deleted").build();
|
||||
} else {
|
||||
//TODO:Check of this logic is correct
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Policy doesn't exist").build());
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("Policy doesn't exist").build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,18 +259,18 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
}
|
||||
}
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "ErrorResponse occurred while activating policies";
|
||||
String msg = "Error occurred while activating policies";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()).build();
|
||||
}
|
||||
if (isPolicyActivated) {
|
||||
return Response.status(Response.Status.OK).entity("Selected policies have been successfully activated")
|
||||
.build();
|
||||
} else {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Selected policies have " +
|
||||
"not been activated").build());
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("Selected policies have " +
|
||||
"not been activated").build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,16 +293,16 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Exception in inactivating policies.";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
if (isPolicyDeActivated) {
|
||||
return Response.status(Response.Status.OK).entity("Selected policies have been successfully " +
|
||||
"deactivated").build();
|
||||
} else {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Selected policies have " +
|
||||
"not been deactivated").build());
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("Selected policies have " +
|
||||
"not been deactivated").build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,8 +318,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "Exception in applying changes.";
|
||||
log.error(msg, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity("Changes have been successfully updated.").build();
|
||||
}
|
||||
@ -340,17 +343,17 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
} catch (PolicyManagementException e) {
|
||||
String error = "Exception in updating policy priorities.";
|
||||
log.error(error, e);
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(error).build());
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(error).build()).build();
|
||||
}
|
||||
if (policiesUpdated) {
|
||||
return Response.status(Response.Status.OK).entity("Policy Priorities successfully "
|
||||
+ "updated.").build();
|
||||
|
||||
} else {
|
||||
throw new NotFoundException(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Policy priorities did "
|
||||
+ "not update. Bad Request.").build());
|
||||
+ "not update. Bad Request.").build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
try {
|
||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
||||
if (!userRealm.getUserStoreManager().isExistingRole(roleName)) {
|
||||
return Response.status(404).entity(new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
"No role exists with the name '" + roleName + "'").build()).build();
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
||||
if (!userStoreManager.isExistingRole(roleName)) {
|
||||
return Response.status(404).entity(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
|
||||
roleName + "'").build()).build();
|
||||
}
|
||||
@ -234,7 +234,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
||||
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
|
||||
if (!userStoreManager.isExistingRole(roleName)) {
|
||||
return Response.status(404).entity(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
|
||||
roleName + "'").build()).build();
|
||||
}
|
||||
@ -290,7 +290,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
||||
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
|
||||
if (!userStoreManager.isExistingRole(roleName)) {
|
||||
return Response.status(404).entity(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" +
|
||||
roleName + "'").build()).build();
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
" already exists. Therefore, request made to add user was refused.");
|
||||
}
|
||||
// returning response with bad request state
|
||||
return Response.status(409).entity(
|
||||
return Response.status(Response.Status.CONFLICT).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " +
|
||||
userInfo.getUsername() + " already exists. Therefore, request made to add user " +
|
||||
"was refused.").build()).build();
|
||||
@ -108,7 +108,8 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User by username: " + username + " does not exist.");
|
||||
}
|
||||
return Response.status(404).entity(new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
||||
"User doesn't exist.").build()).build();
|
||||
}
|
||||
|
||||
@ -133,7 +134,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
log.debug("User by username: " + userInfo.getUsername() +
|
||||
" doesn't exists. Therefore, request made to update user was refused.");
|
||||
}
|
||||
return Response.status(404).entity(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " +
|
||||
userInfo.getUsername() + " doesn't exist.").build()).build();
|
||||
}
|
||||
@ -206,7 +207,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User by username: " + username + " does not exist for removal.");
|
||||
}
|
||||
return Response.status(404).entity(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("User '" +
|
||||
username + "' does not exist for removal.").build()).build();
|
||||
}
|
||||
@ -234,7 +235,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User by username: " + username + " does not exist for role retrieval.");
|
||||
}
|
||||
return Response.status(404).entity(
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + username +
|
||||
" does not exist for role retrieval.").build()).build();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user