From a72b47f6f7df81182c64937ba7378e64bb620b81 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Wed, 24 Aug 2016 19:18:35 +0530 Subject: [PATCH 1/2] Fixing incorrect response for remove policy --- .../impl/PolicyManagementServiceImpl.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index f2aeae680d..109bb189d4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -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(); } } From 16e6e124369ebd05ed9aee224bfe86c57fc8b1a5 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Perera Date: Thu, 25 Aug 2016 11:53:29 +0530 Subject: [PATCH 2/2] Fixed issue in Activity API returning one activity --- .../core/operation/mgt/dao/impl/GenericOperationDAOImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 36bdfd738a..afd6c774b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -420,7 +420,8 @@ public class GenericOperationDAOImpl implements OperationDAO { "ON feom.OPERATION_ID = o.ID LEFT OUTER JOIN (SELECT ID, ENROLMENT_ID, OPERATION_ID, " + "OPERATION_RESPONSE, MAX(RECEIVED_TIMESTAMP) LATEST_RECEIVED_TIMESTAMP " + "FROM DM_DEVICE_OPERATION_RESPONSE GROUP BY ENROLMENT_ID , OPERATION_ID) orsp " + - "ON o.ID = orsp.OPERATION_ID AND feom.ENROLMENT_ID = orsp.ENROLMENT_ID GROUP BY feom.ENROLMENT_ID"; + "ON o.ID = orsp.OPERATION_ID AND feom.ENROLMENT_ID = orsp.ENROLMENT_ID GROUP BY feom.ENROLMENT_ID, " + + "feom.OPERATION_ID"; stmt = conn.prepareStatement(sql);