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 bd91dbccf96..fe35fd51d53 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())