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 9ffece7230..d8c6371315 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 @@ -616,9 +616,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier (deviceId, deviceType), true); persistedDevice.setName(device.getName()); - boolean response = deviceManagementProviderService.modifyEnrollment(persistedDevice); - return Response.status(Response.Status.CREATED).entity(response).build(); + System.out.println("This is rename device"); + boolean responseOfmodifyEnrollment = deviceManagementProviderService.modifyEnrollment(persistedDevice); + boolean responseOfDeviceNameChanged = deviceManagementProviderService.SendDeviceNameChangedNotification( + persistedDevice); + boolean response = responseOfmodifyEnrollment && responseOfDeviceNameChanged; + return Response.status(Response.Status.CREATED).entity(response).build(); } catch (DeviceManagementException e) { log.error("Error encountered while updating device of type : " + deviceType + " and " + "ID : " + deviceId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/common/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/common/Constants.java index 0db16ff451..7d7c3ba853 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/common/Constants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/common/Constants.java @@ -24,4 +24,6 @@ public class Constants { public static final String URI_SEPARATOR = "/"; public static final String BASIC_AUTH_HEADER_PREFIX = "Basic "; public static final String BEARER = "Bearer "; + public static final String SEND_USERNAME = "SEND_USERNAME"; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index adfb67f003..f781fd3d75 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -1030,4 +1030,6 @@ public interface DeviceManagementProviderService { */ PaginationResult getDevicesDetails(PaginationRequest request, List devicesIds, String groupName) throws DeviceManagementException; + + Boolean SendDeviceNameChangedNotification(Device device) throws DeviceManagementException; } 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 cfbe8a3480..77c8c38f83 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 @@ -123,6 +123,7 @@ import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.cache.DeviceCacheKey; import org.wso2.carbon.device.mgt.core.cache.impl.BillingCacheManagerImpl; import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl; +import org.wso2.carbon.device.mgt.core.common.Constants; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO; @@ -146,6 +147,7 @@ import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataDAO; import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOException; import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil; import org.wso2.carbon.email.sender.core.ContentProviderInfo; @@ -4877,4 +4879,34 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv paginationResult.setData(populateAllDeviceInfo(subscribedDeviceDetails)); return paginationResult; } + + @Override + public Boolean SendDeviceNameChangedNotification(Device device) throws DeviceManagementException { + + try { + ProfileOperation operation = new ProfileOperation(); + operation.setCode(Constants.SEND_USERNAME); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(device.getName()); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(device.getDeviceIdentifier()); + deviceIdentifier.setType(device.getType()); + + List deviceIdentifiers = new ArrayList<>(); + deviceIdentifiers.add(deviceIdentifier); + Activity activity; + activity = addOperation(device.getType(), operation, deviceIdentifiers); + + return activity != null; + } catch (OperationManagementException e) { + String msg = "Error occurred while sending operation"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (InvalidDeviceException e) { + String msg = "Invalid Device exception occurred"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + } }