|
|
@ -40,10 +40,12 @@ import org.wso2.carbon.policy.mgt.common.Policy;
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@Path("/policies")
|
|
|
|
@Path("/policies")
|
|
|
@ -301,4 +303,37 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
|
|
|
|
@Path("/priorities")
|
|
|
|
|
|
|
|
public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies) {
|
|
|
|
|
|
|
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
|
|
|
|
|
|
|
List<Policy> policiesToUpdate = new ArrayList<>(priorityUpdatedPolicies.size());
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < priorityUpdatedPolicies.size(); i++) {
|
|
|
|
|
|
|
|
Policy policyObj = new Policy();
|
|
|
|
|
|
|
|
policyObj.setId(priorityUpdatedPolicies.get(i).getId());
|
|
|
|
|
|
|
|
policyObj.setPriorityId(priorityUpdatedPolicies.get(i).getPriority());
|
|
|
|
|
|
|
|
policiesToUpdate.add(policyObj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean policiesUpdated;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
|
|
|
|
|
|
policiesUpdated = pap.updatePolicyPriorities(policiesToUpdate);
|
|
|
|
|
|
|
|
} 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());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (policiesUpdated) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity("Policy Priorities successfully "
|
|
|
|
|
|
|
|
+ "updated.").build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Policy priorities did "
|
|
|
|
|
|
|
|
+ "not update. Bad Request.").build());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|