Merge pull request 'Add notification feature when a device is renamed' (#18) from arshana790/device-mgt-core-fork:android-feature into master

Reviewed-on: community/device-mgt-core#18
improvement/fix-task-deletion
Pahansith Gunathilake 2 years ago
commit a05007b835

@ -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);

@ -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";
}

@ -1030,4 +1030,6 @@ public interface DeviceManagementProviderService {
*/
PaginationResult getDevicesDetails(PaginationRequest request, List<Integer> devicesIds, String groupName)
throws DeviceManagementException;
Boolean SendDeviceNameChangedNotification(Device device) throws DeviceManagementException;
}

@ -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<DeviceIdentifier> 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);
}
}
}

Loading…
Cancel
Save