fix the EMM-1702

4.x.x
hasuniea 8 years ago
parent 8740eae61a
commit 05e95e2675

@ -79,6 +79,8 @@ public class TaskConfiguration {
private String operationName;
private int recurrency;
private List<String> 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<String> getPlatforms() {
return platforms;
}
public void setPlatforms(List<String> platforms) {
this.platforms = platforms;
}
}
}

@ -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<String> taskPlatforms;
public List<String> getTaskPlatforms() {
return taskPlatforms;
}
public void setTaskPlatforms(List<String> taskPlatforms) {
this.taskPlatforms = taskPlatforms;
}
public String getTaskName() {
return taskName;
@ -43,5 +54,6 @@ public class TaskOperation {
public void setRecurrentTimes(int recurrentTimes) {
this.recurrentTimes = recurrentTimes;
}
}

@ -53,16 +53,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations();
List<TaskOperation> 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<String> getPlatformsForOperations(String opName) {
List<String> operationPlatforms = new ArrayList<>();
TaskConfiguration taskConfiguration =
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration();
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations();
for (TaskConfiguration.Operation op : ops) {
if (op.getOperationName().equals(opName)) {
List<String> 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<String> deviceTypes;
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
try {
List<String> deviceTypes = deviceManagementProviderService.getAvailableDeviceTypes();
List<Device> devices;
List<String> 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 {

@ -51,14 +51,26 @@
<Operation>
<Name>DEVICE_INFO</Name>
<RecurrentTimes>1</RecurrentTimes>
<Platforms>
<platform>android</platform>
<platform>ios</platform>
</Platforms>
</Operation>
<Operation>
<Name>APPLICATION_LIST</Name>
<RecurrentTimes>5</RecurrentTimes>
<Platforms>
<platform>android</platform>
<platform>ios</platform>
</Platforms>
</Operation>
<Operation>
<Name>DEVICE_LOCATION</Name>
<RecurrentTimes>1</RecurrentTimes>
<Platforms>
<platform>android</platform>
<platform>ios</platform>
</Platforms>
</Operation>
</Operations>
</TaskConfiguration>

Loading…
Cancel
Save