From 4943635a61a6bf2f9d2b6ce1fa0cf3586791d2c7 Mon Sep 17 00:00:00 2001 From: charitha Date: Sat, 12 Dec 2020 03:01:19 +0530 Subject: [PATCH] Fetch enrollment Id if it is not already in the device --- .../DeviceManagementProviderServiceImpl.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index bd91dbccf9..fe35fd51d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1973,16 +1973,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void updateOperation(Device device, Operation operation) throws OperationManagementException { - EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo(); - if (enrolmentInfo == null) { - throw new OperationManagementException( - "Device not found for device id:" + device.getDeviceIdentifier() + " " + "type:" + - device.getType()); - } try { - pluginRepository.getOperationManager(device.getType(), this.getTenantId()) - .updateOperation(device.getEnrolmentInfo().getId(), operation, - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo(); + if (enrolmentInfo == null || device.getEnrolmentInfo().getId() <= 0) { + pluginRepository.getOperationManager(device.getType(), this.getTenantId()) + .updateOperation(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()), + operation); + } else { + pluginRepository.getOperationManager(device.getType(), this.getTenantId()) + .updateOperation(device.getEnrolmentInfo().getId(), operation, + new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + } if (DeviceManagerUtil.isPublishOperationResponseEnabled()) { List permittedOperations = DeviceManagerUtil.getEnabledOperationsForResponsePublish(); if (permittedOperations.contains(operation.getCode())