From 4bc04b7923d985e8c394fab6290c46711b7dc42b Mon Sep 17 00:00:00 2001 From: charitha Date: Sat, 1 Jun 2019 13:22:21 +0530 Subject: [PATCH] Add notifier type details --- .../android/bean/NotifierFrequency.java | 11 ++++ .../DeviceTypeConfigurationServiceImpl.java | 57 +++++++++++-------- .../android/util/AndroidConstants.java | 1 + 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/NotifierFrequency.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/NotifierFrequency.java index e7061ae915..b38a8b802a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/NotifierFrequency.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/NotifierFrequency.java @@ -27,9 +27,20 @@ import java.io.Serializable; description = "This class represents notification frequency configuration.") public class NotifierFrequency extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "type", value = "Notification type", required = true) + private int type; + @ApiModelProperty(name = "value", value = "Notification polling frequency", required = true) private int value; + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + public int getValue() { return value; } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java index bc6e8b2f7e..e799a67e73 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java @@ -134,6 +134,7 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati try { configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); List configs = configuration.getConfiguration(); + NotifierFrequency notifierFrequency = new NotifierFrequency(); for (ConfigurationEntry entry : configs) { if (AndroidConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { License license = new License(); @@ -145,30 +146,18 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, license); licenseEntry = entry; } else if (AndroidConstants.TenantConfigProperties.NOTIFIER_FREQUENCY.equals(entry.getName())) { - List deviceList = AndroidAPIUtils. - getDeviceManagementService(). - getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false); - List deviceIdList = new ArrayList<>(); - for (Device device : deviceList) { - if (EnrolmentInfo.Status.REMOVED != device.getEnrolmentInfo().getStatus()) { - deviceIdList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - } + if (entry.getValue() != null) { + notifierFrequency.setValue(Integer.parseInt(entry.getValue().toString())); + } else { + return Response.status(Response.Status.BAD_REQUEST) + .entity("No value specified for notifierFrequency.").build(); } - if (!deviceIdList.isEmpty()) { - if (entry.getValue() != null) { - NotifierFrequency notifierFrequency = new NotifierFrequency(); - notifierFrequency.setValue(Integer.parseInt(entry.getValue().toString())); - ProfileOperation operation = new ProfileOperation(); - operation.setCode(AndroidConstants.OperationCodes.NOTIFIER_FREQUENCY); - operation.setPayLoad(notifierFrequency.toJSON()); - operation.setEnabled(true); - AndroidAPIUtils.getDeviceManagementService().addOperation( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, - operation, deviceIdList); - } else { - return Response.status(Response.Status.BAD_REQUEST) - .entity("No value specified for notifierFrequency.").build(); - } + } else if (AndroidConstants.TenantConfigProperties.NOTIFIER_TYPE.equals(entry.getName())) { + if (entry.getValue() != null) { + notifierFrequency.setType(Integer.parseInt(entry.getValue().toString())); + } else { + return Response.status(Response.Status.BAD_REQUEST) + .entity("No value specified for notifierType.").build(); } } } @@ -178,6 +167,7 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati } configuration.setConfiguration(configs); AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + notifyDevices(notifierFrequency); } catch (DeviceManagementException e) { msg = "Error occurred while modifying configuration settings of Android platform"; log.error(msg, e); @@ -203,6 +193,27 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati .entity("Android platform configuration has been updated successfully.").build(); } + private void notifyDevices(NotifierFrequency notifierFrequency) throws DeviceManagementException, + OperationManagementException, InvalidDeviceException { + List deviceList = AndroidAPIUtils. + getDeviceManagementService(). + getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false); + List deviceIdList = new ArrayList<>(); + for (Device device : deviceList) { + if (EnrolmentInfo.Status.REMOVED != device.getEnrolmentInfo().getStatus()) { + deviceIdList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + } + } + if (!deviceIdList.isEmpty()) { + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.NOTIFIER_FREQUENCY); + operation.setPayLoad(notifierFrequency.toJSON()); + operation.setEnabled(true); + AndroidAPIUtils.getDeviceManagementService().addOperation( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, + operation, deviceIdList); + } + } @GET @Path("/license") diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java index 9db77c7f4f..42712d9875 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java @@ -160,6 +160,7 @@ public final class AndroidConstants { public static final String LANGUAGE_US = "en_US"; public static final String CONTENT_TYPE_TEXT = "text"; public static final String NOTIFIER_FREQUENCY = "notifierFrequency"; + public static final String NOTIFIER_TYPE = "notifierType"; public static final String SERVER_VERSION = "serverVersion"; }