From 05e95e26752b5f160ae431fa578b0a76e6f0d171 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 7 Oct 2016 15:48:43 +0530 Subject: [PATCH] fix the EMM-1702 --- .../core/config/task/TaskConfiguration.java | 13 ++++ .../device/mgt/core/task/TaskOperation.java | 12 ++++ .../core/task/impl/DeviceTaskManagerImpl.java | 59 +++++++++++++------ .../src/main/resources/conf/cdm-config.xml | 12 ++++ 4 files changed, 77 insertions(+), 19 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/task/TaskConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/task/TaskConfiguration.java index 8b099b1b24e..14efb787f26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/task/TaskConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/task/TaskConfiguration.java @@ -79,6 +79,8 @@ public class TaskConfiguration { private String operationName; private int recurrency; + private List platforms; + @XmlElement(name = "Name", required = true) public String getOperationName() { @@ -97,5 +99,16 @@ public class TaskConfiguration { public void setRecurrency(int recurrency) { this.recurrency = recurrency; } + + @XmlElementWrapper(name = "Platforms") + @XmlElement(name = "platform", required = true) + public List getPlatforms() { + return platforms; + } + + public void setPlatforms(List platforms) { + this.platforms = platforms; + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/TaskOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/TaskOperation.java index e7dc35b1bd2..6777841ed35 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/TaskOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/TaskOperation.java @@ -20,6 +20,8 @@ package org.wso2.carbon.device.mgt.core.task; +import java.util.List; + /** * This is the bean for the operations added by the task. */ @@ -27,6 +29,15 @@ public class TaskOperation { private String taskName; private int recurrentTimes; + private List taskPlatforms; + + public List getTaskPlatforms() { + return taskPlatforms; + } + + public void setTaskPlatforms(List taskPlatforms) { + this.taskPlatforms = taskPlatforms; + } public String getTaskName() { return taskName; @@ -43,5 +54,6 @@ public class TaskOperation { public void setRecurrentTimes(int recurrentTimes) { this.recurrentTimes = recurrentTimes; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java index 5041f71a6c2..dafd763e61b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java @@ -53,16 +53,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { List ops = taskConfiguration.getOperations(); List taskOperations = new ArrayList<>(); - for (TaskConfiguration.Operation op : ops) { TaskOperation taskOperation = new TaskOperation(); taskOperation.setTaskName(op.getOperationName()); taskOperation.setRecurrentTimes(op.getRecurrency()); + taskOperation.setTaskPlatforms(op.getPlatforms()); taskOperations.add(taskOperation); } return taskOperations; } + public List getPlatformsForOperations(String opName) { + List operationPlatforms = new ArrayList<>(); + TaskConfiguration taskConfiguration = + DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration(); + List ops = taskConfiguration.getOperations(); + for (TaskConfiguration.Operation op : ops) { + if (op.getOperationName().equals(opName)) { + List platform = op.getPlatforms(); + for (String operationPlatform : platform) { + operationPlatforms.add(operationPlatform); + } + } + } + return operationPlatforms; + } + @Override public int getTaskFrequency() throws DeviceMgtTaskException { return DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration(). @@ -84,29 +100,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { @Override public void addOperations() throws DeviceMgtTaskException { + List deviceTypes; DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance(). getDeviceManagementProvider(); try { - List deviceTypes = deviceManagementProviderService.getAvailableDeviceTypes(); List devices; List operations = this.getValidOperationNames(); - - for (String deviceType : deviceTypes) { - devices = deviceManagementProviderService.getAllDevices(deviceType); - if (!devices.isEmpty()) { - for (String str : operations) { - CommandOperation operation = new CommandOperation(); - operation.setEnabled(true); - operation.setType(Operation.Type.COMMAND); - operation.setCode(str); - deviceManagementProviderService.addOperation(deviceType, operation, - DeviceManagerUtil.getValidDeviceIdentifiers(devices)); - } - } else { - if (log.isDebugEnabled()) { - log.debug("No devices are available to perform the operations."); - } - } + for (String taskOperation : operations) { + deviceTypes = getPlatformsForOperations(taskOperation); + for (String deviceType : deviceTypes) { + devices = deviceManagementProviderService.getAllDevices(deviceType); + if (!devices.isEmpty()) { + for (String str : operations) { + CommandOperation operation = new CommandOperation(); + operation.setEnabled(true); + operation.setType(Operation.Type.COMMAND); + operation.setCode(str); + deviceManagementProviderService.addOperation(deviceType, operation, + DeviceManagerUtil.getValidDeviceIdentifiers(devices)); + } + } else { + if (log.isDebugEnabled()) { + log.debug("No devices are available to perform the operations."); + } + } + + } } } catch (InvalidDeviceException e) { throw new DeviceMgtTaskException("Invalid DeviceIdentifiers found.", e); @@ -145,6 +164,8 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { return opNames; } + + @Override public boolean isTaskOperation(String opName) { try { diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 84af9068726..fdd4a427103 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -51,14 +51,26 @@ DEVICE_INFO 1 + + android + ios + APPLICATION_LIST 5 + + android + ios + DEVICE_LOCATION 1 + + android + ios +