From 870ff031bb44156cb1ee53d6672596e30aba8824 Mon Sep 17 00:00:00 2001 From: abhishekdesilva Date: Mon, 13 Aug 2018 11:15:06 +0530 Subject: [PATCH 1/4] Checking for pending operations before adding an operation --- .../operation/mgt/OperationManagerImpl.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index d45fb2deadb..a3f06b59eb0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -174,6 +174,35 @@ public class OperationManagerImpl implements OperationManager { OperationManagementDAOFactory.beginTransaction(); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil.convertOperation(operation); + int enrolmentId; + boolean hasExistingTaskOperation; + List pendingDeviceList = new ArrayList<>(); + String operationCode = operationDto.getCode(); + + for (DeviceIdentifier deviceId : authorizedDeviceList) { + Device device = getDevice(deviceId); + enrolmentId = device.getEnrolmentInfo().getId(); + hasExistingTaskOperation = operationDAO.updateTaskOperation(enrolmentId, operationCode); + if (hasExistingTaskOperation) { + pendingDeviceList.add(deviceId); + } + + } + + if(pendingDeviceList.size()>0){ + if (authorizedDeviceList.size() == pendingDeviceList.size()) { + log.info("All the devices contain a pending operation for the Operation Code: "+operationCode); + Activity activity = new Activity(); + //Send the operation statuses only for admin triggered operations + String deviceType = validDeviceIds.get(0).getType(); + activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult, + deviceType)); + return activity; + }else{ + authorizedDeviceList.removeAll(pendingDeviceList); + } + } + int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); boolean isScheduledOperation = this.isTaskScheduledOperation(operation); boolean isNotRepeated = false; @@ -188,8 +217,6 @@ public class OperationManagerImpl implements OperationManager { isScheduled = notificationStrategy.getConfig().isScheduled(); } - boolean hasExistingTaskOperation; - int enrolmentId; List devices = new ArrayList<>(); if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT == operationDto. getControl()) { @@ -197,7 +224,6 @@ public class OperationManagerImpl implements OperationManager { } //TODO have to create a sql to load device details from deviceDAO using single query. - String operationCode = operationDto.getCode(); for (DeviceIdentifier deviceId : authorizedDeviceList) { Device device = getDevice(deviceId); devices.add(device); From a0bc1cdd20cc8def1eb2cafe5cd871babbd551a3 Mon Sep 17 00:00:00 2001 From: abhishekdesilva Date: Tue, 21 Aug 2018 09:53:23 +0530 Subject: [PATCH 2/4] Reformatted the code block as necessary --- .../mgt/core/operation/mgt/OperationManagerImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index a3f06b59eb0..8af419bc740 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -186,19 +186,19 @@ public class OperationManagerImpl implements OperationManager { if (hasExistingTaskOperation) { pendingDeviceList.add(deviceId); } - } - if(pendingDeviceList.size()>0){ + if (pendingDeviceList.size() > 0) { if (authorizedDeviceList.size() == pendingDeviceList.size()) { - log.info("All the devices contain a pending operation for the Operation Code: "+operationCode); + log.info("All the devices contain a pending operation for the Operation Code: " + + operationCode); Activity activity = new Activity(); //Send the operation statuses only for admin triggered operations String deviceType = validDeviceIds.get(0).getType(); activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult, deviceType)); return activity; - }else{ + } else { authorizedDeviceList.removeAll(pendingDeviceList); } } From 4aad82437bd99b087eef5b1f99ee95038b3b79fd Mon Sep 17 00:00:00 2001 From: abhishekdesilva Date: Tue, 21 Aug 2018 14:46:18 +0530 Subject: [PATCH 3/4] Log info has changed into debug --- .../device/mgt/core/operation/mgt/OperationManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 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/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 8af419bc740..71d657d2e86 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -190,7 +190,7 @@ public class OperationManagerImpl implements OperationManager { if (pendingDeviceList.size() > 0) { if (authorizedDeviceList.size() == pendingDeviceList.size()) { - log.info("All the devices contain a pending operation for the Operation Code: " + log.debug("All the devices contain a pending operation for the Operation Code: " + operationCode); Activity activity = new Activity(); //Send the operation statuses only for admin triggered operations From 85040f0c68a1e78a14b07c95eb0ae53043d9c2a0 Mon Sep 17 00:00:00 2001 From: abhishekdesilva Date: Tue, 21 Aug 2018 15:00:14 +0530 Subject: [PATCH 4/4] Log debug process completion --- .../device/mgt/core/operation/mgt/OperationManagerImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 71d657d2e86..9b6914f605a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -190,8 +190,10 @@ public class OperationManagerImpl implements OperationManager { if (pendingDeviceList.size() > 0) { if (authorizedDeviceList.size() == pendingDeviceList.size()) { - log.debug("All the devices contain a pending operation for the Operation Code: " - + operationCode); + if (log.isDebugEnabled()) { + log.debug("All the devices contain a pending operation for the Operation Code: " + + operationCode); + } Activity activity = new Activity(); //Send the operation statuses only for admin triggered operations String deviceType = validDeviceIds.get(0).getType();