From 4092254b191f1c2f9366c25cf0d6930a5f23cc2b Mon Sep 17 00:00:00 2001 From: Chathura Ekanayake Date: Wed, 26 Jul 2017 12:39:25 +0530 Subject: [PATCH] backend fix for the issue with getting next pending operation of custom devices. --- .../service/impl/DeviceManagementServiceImpl.java | 14 ++++++++++++-- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 2 +- 2 files 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/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index a269a67c21..5118221ac3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -50,6 +50,7 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtExcept import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; 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; @@ -665,7 +666,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.BAD_REQUEST).build(); } Operation.Type operationType = operationRequest.getOperation().getType(); - if (operationType == Operation.Type.COMMAND || operationType == Operation.Type.CONFIG) { + if (operationType == Operation.Type.COMMAND || operationType == Operation.Type.CONFIG || operationType == Operation.Type.PROFILE) { DeviceIdentifier deviceIdentifier; List deviceIdentifiers = new ArrayList<>(); for (String deviceId : operationRequest.getDeviceIdentifiers()) { @@ -683,7 +684,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { operation.setEnabled(commandOperation.isEnabled()); operation.setStatus(commandOperation.getStatus()); - } else { + } else if (operationType == Operation.Type.CONFIG) { Operation configOperation = operationRequest.getOperation(); operation = new ConfigOperation(); operation.setType(Operation.Type.CONFIG); @@ -691,6 +692,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { operation.setEnabled(configOperation.isEnabled()); operation.setPayLoad(configOperation.getPayLoad()); operation.setStatus(configOperation.getStatus()); + + } else { + Operation profileOperation = operationRequest.getOperation(); + operation = new ProfileOperation(); + operation.setType(Operation.Type.PROFILE); + operation.setCode(profileOperation.getCode()); + operation.setEnabled(profileOperation.isEnabled()); + operation.setPayLoad(profileOperation.getPayLoad()); + operation.setStatus(profileOperation.getStatus()); } String date = new SimpleDateFormat(DATE_FORMAT_NOW).format(new Date()); operation.setCreatedTimeStamp(date); 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/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 3020096972..82beb1b5f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -130,7 +130,7 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl { rs = stmt.executeQuery(); if (rs.next()) { - byte[] operationDetails = rs.getBytes("OPERATION_DETAILS"); + byte[] operationDetails = rs.getBytes("OPERATION_CONFIG"); bais = new ByteArrayInputStream(operationDetails); ois = new ObjectInputStream(bais); configOperation = (ConfigOperation) ois.readObject();