Fixed issue in device type config operation

- Device type config operation throws invalid device identifieres exception when changing configurations without having active devices
revert-dabc3590
Charitha Goonetilleke 6 years ago
parent 750dcc71c6
commit 211391fb02

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
@ -124,25 +125,28 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati
} else if (AndroidConstants.TenantConfigProperties.NOTIFIER_FREQUENCY.equals(entry.getName())) { } else if (AndroidConstants.TenantConfigProperties.NOTIFIER_FREQUENCY.equals(entry.getName())) {
List<Device> deviceList = AndroidAPIUtils. List<Device> deviceList = AndroidAPIUtils.
getDeviceManagementService(). getDeviceManagementService().
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false);
List<DeviceIdentifier> deviceIdList = new ArrayList<>(); List<DeviceIdentifier> deviceIdList = new ArrayList<>();
for (Device device : deviceList) { for (Device device : deviceList) {
deviceIdList.add(new DeviceIdentifier(device.getDeviceIdentifier(),device.getType())); if (EnrolmentInfo.Status.REMOVED != device.getEnrolmentInfo().getStatus()) {
deviceIdList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
}
} }
if (entry.getValue() != null) { if (!deviceIdList.isEmpty()) {
NotifierFrequency notifierFrequency = new NotifierFrequency(); if (entry.getValue() != null) {
notifierFrequency.setValue(Integer.parseInt(entry.getValue().toString())); NotifierFrequency notifierFrequency = new NotifierFrequency();
ProfileOperation operation = new ProfileOperation(); notifierFrequency.setValue(Integer.parseInt(entry.getValue().toString()));
operation.setCode(AndroidConstants.OperationCodes.NOTIFIER_FREQUENCY); ProfileOperation operation = new ProfileOperation();
operation.setPayLoad(notifierFrequency.toJSON()); operation.setCode(AndroidConstants.OperationCodes.NOTIFIER_FREQUENCY);
operation.setType(Operation.Type.CONFIG); operation.setPayLoad(notifierFrequency.toJSON());
operation.setEnabled(true); operation.setEnabled(true);
AndroidAPIUtils.getDeviceManagementService().addOperation( AndroidAPIUtils.getDeviceManagementService().addOperation(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
operation, deviceIdList); operation, deviceIdList);
} else { } else {
return Response.status(Response.Status.BAD_REQUEST) return Response.status(Response.Status.BAD_REQUEST)
.entity("No value specified for notifierFrequency.").build(); .entity("No value specified for notifierFrequency.").build();
}
} }
} }
} }

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
@ -125,25 +126,28 @@ public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurati
} else if (AndroidConstants.TenantConfigProperties.NOTIFIER_FREQUENCY.equals(entry.getName())) { } else if (AndroidConstants.TenantConfigProperties.NOTIFIER_FREQUENCY.equals(entry.getName())) {
List<Device> deviceList = AndroidAPIUtils. List<Device> deviceList = AndroidAPIUtils.
getDeviceManagementService(). getDeviceManagementService().
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false);
List<DeviceIdentifier> deviceIdList = new ArrayList<>(); List<DeviceIdentifier> deviceIdList = new ArrayList<>();
for (Device device : deviceList) { for (Device device : deviceList) {
deviceIdList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); if (EnrolmentInfo.Status.REMOVED != device.getEnrolmentInfo().getStatus()) {
deviceIdList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
}
} }
if (entry.getValue() != null) { if (!deviceIdList.isEmpty()) {
NotifierFrequency notifierFrequency = new NotifierFrequency(); if (entry.getValue() != null) {
notifierFrequency.setValue(Integer.parseInt(entry.getValue().toString())); NotifierFrequency notifierFrequency = new NotifierFrequency();
ProfileOperation operation = new ProfileOperation(); notifierFrequency.setValue(Integer.parseInt(entry.getValue().toString()));
operation.setCode(AndroidConstants.OperationCodes.NOTIFIER_FREQUENCY); ProfileOperation operation = new ProfileOperation();
operation.setPayLoad(notifierFrequency.toJSON()); operation.setCode(AndroidConstants.OperationCodes.NOTIFIER_FREQUENCY);
operation.setType(Operation.Type.CONFIG); operation.setPayLoad(notifierFrequency.toJSON());
operation.setEnabled(true); operation.setEnabled(true);
AndroidAPIUtils.getDeviceManagementService().addOperation( AndroidAPIUtils.getDeviceManagementService().addOperation(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
operation, deviceIdList); operation, deviceIdList);
} else { } else {
return Response.status(Response.Status.BAD_REQUEST) return Response.status(Response.Status.BAD_REQUEST)
.entity("No value specified for notifierFrequency.").build(); .entity("No value specified for notifierFrequency.").build();
}
} }
} }
} }

Loading…
Cancel
Save