|
|
|
@ -221,14 +221,22 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|
|
|
|
RequestValidationUtil.validatePolicyIds(policyIds);
|
|
|
|
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
|
|
|
boolean policyDeleted = true;
|
|
|
|
|
String invalidPolicyIds = "";
|
|
|
|
|
try {
|
|
|
|
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
|
|
|
for (int i : policyIds) {
|
|
|
|
|
Policy policy = pap.getPolicy(i);
|
|
|
|
|
if (policy == null || !pap.deletePolicy(policy)) {
|
|
|
|
|
if (policy == null) {
|
|
|
|
|
invalidPolicyIds += i + ",";
|
|
|
|
|
policyDeleted = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(policyDeleted) {
|
|
|
|
|
for(int i : policyIds) {
|
|
|
|
|
Policy policy = pap.getPolicy(i);
|
|
|
|
|
pap.deletePolicy(policy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (PolicyManagementException e) {
|
|
|
|
|
String msg = "ErrorResponse occurred while removing policies";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
@ -239,8 +247,10 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|
|
|
|
return Response.status(Response.Status.OK).entity("Policies have been successfully deleted").build();
|
|
|
|
|
} else {
|
|
|
|
|
//TODO:Check of this logic is correct
|
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Policy doesn't exist").build()).build();
|
|
|
|
|
String ModifiedInvalidPolicyIds = invalidPolicyIds.substring(0, invalidPolicyIds.length()-1);
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Policies with the policy ID " +
|
|
|
|
|
ModifiedInvalidPolicyIds + " doesn't exist").build()).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|