Merge branch 'release-2.0.x' of https://github.com/wso2/carbon-device-mgt into release-2.0.x

revert-70aa11f8
charitha 8 years ago
commit 3b97b3296e

@ -66,9 +66,35 @@ public class DeviceTypeConfiguration {
protected License license; protected License license;
@XmlElement(name = "DataSource", required = true) @XmlElement(name = "DataSource", required = true)
protected DataSource dataSource; protected DataSource dataSource;
@XmlElement(name = "TaskConfiguration", required = true)
private TaskConfiguration taskConfiguration;
@XmlAttribute(name = "name") @XmlAttribute(name = "name")
protected String name; protected String name;
/**
* Gets the value of the taskConfiguration property.
*
* @return
* possible object is
* {@link TaskConfiguration }
*
*/
public TaskConfiguration getTaskConfiguration() {
return taskConfiguration;
}
/**
* Sets the value of the taskConfiguration property.
*
* @param taskConfiguration
* allowed object is
* {@link TaskConfiguration }
*
*/
public void setTaskConfiguration(TaskConfiguration taskConfiguration) {
this.taskConfiguration = taskConfiguration;
}
/** /**
* Gets the value of the deviceDetails property. * Gets the value of the deviceDetails property.
* *

@ -0,0 +1,102 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
/**
*
*/
@XmlRootElement(name = "TaskConfiguration")
public class TaskConfiguration {
private boolean enabled;
private int frequency;
private String taskClazz;
private List<Operation> operations;
@XmlElement(name = "Enable", required = true)
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@XmlElement(name = "Frequency", required = true)
public int getFrequency() {
return frequency;
}
public void setFrequency(int frequency) {
this.frequency = frequency;
}
@XmlElement(name = "TaskClass", required = true)
public String getTaskClazz() {
return taskClazz;
}
public void setTaskClazz(String taskClazz) {
this.taskClazz = taskClazz;
}
@XmlElementWrapper(name="Operations")
@XmlElement(name = "Operation", required = true)
public List<Operation> getOperations() {
return operations;
}
public void setOperations(List<Operation> operations) {
this.operations = operations;
}
@XmlRootElement(name = "Operation")
public static class Operation {
private String operationName;
private int recurrency;
@XmlElement(name = "Name", required = true)
public String getOperationName() {
return operationName;
}
public void setOperationName(String operationName) {
this.operationName = operationName;
}
@XmlElement(name = "RecurrentTimes", required = true)
public int getRecurrency() {
return recurrency;
}
public void setRecurrency(int recurrency) {
this.recurrency = recurrency;
}
}
}

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.TaskOperation;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
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;
@ -31,7 +32,9 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceTypeConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceTypeConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Property; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Property;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationProvider; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationProvider;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.TaskConfiguration;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -48,6 +51,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private PushNotificationConfig pushNotificationConfig; private PushNotificationConfig pushNotificationConfig;
private ProvisioningConfig provisioningConfig; private ProvisioningConfig provisioningConfig;
private String type; private String type;
private List<TaskOperation> taskOperations;
public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
DeviceTypeConfiguration deviceTypeConfiguration) { DeviceTypeConfiguration deviceTypeConfiguration) {
@ -55,6 +59,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceTypeConfiguration); this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceTypeConfiguration);
this.setType(deviceTypeConfiguration.getName()); this.setType(deviceTypeConfiguration.getName());
this.populatePushNotificationConfig(deviceTypeConfiguration.getPushNotificationProvider()); this.populatePushNotificationConfig(deviceTypeConfiguration.getPushNotificationProvider());
this.setTask(deviceTypeConfiguration);
} }
@Override @Override
@ -62,6 +67,28 @@ public class DeviceTypeManagerService implements DeviceManagementService {
return type; return type;
} }
@Override
public List<TaskOperation> getTasksForPlatform(){
return taskOperations;
}
private void setTask(DeviceTypeConfiguration deviceTypeConfiguration) {
//Read the config file and take the list of operations there in the config
TaskConfiguration taskConfiguration = deviceTypeConfiguration.getTaskConfiguration();
if (taskConfiguration != null) {
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations();
if (ops != null && !ops.isEmpty()) {
taskOperations = new ArrayList<>();
for (TaskConfiguration.Operation op : ops) {
TaskOperation taskOperation = new TaskOperation();
taskOperation.setTaskName(op.getOperationName());
taskOperation.setRecurrentTimes(op.getRecurrency());
taskOperations.add(taskOperation);
}
}
}
}
@Override @Override
public void init() throws DeviceManagementException { public void init() throws DeviceManagementException {
} }

@ -97,5 +97,20 @@
</Table> </Table>
</tableConfig> </tableConfig>
</DataSource> </DataSource>
<TaskConfiguration>
<Operations>
<Operation>
<Name>DEVICE_INFO</Name>
<RecurrentTimes>1</RecurrentTimes>
</Operation>
<Operation>
<Name>APPLICATION_LIST</Name>
<RecurrentTimes>5</RecurrentTimes>
</Operation>
<Operation>
<Name>DEVICE_LOCATION</Name>
<RecurrentTimes>1</RecurrentTimes>
</Operation>
</Operations>
</TaskConfiguration>
</DeviceTypeConfiguration> </DeviceTypeConfiguration>

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.common;
/**
*
*/
public class TaskOperation {
private String taskName;
private int recurrentTimes;
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public int getRecurrentTimes() {
return recurrentTimes;
}
public void setRecurrentTimes(int recurrentTimes) {
this.recurrentTimes = recurrentTimes;
}
}

@ -21,9 +21,12 @@ package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.TaskOperation;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import java.util.List;
/** /**
* Composite interface that acts as the SPI exposing all device management as well as application management * Composite interface that acts as the SPI exposing all device management as well as application management
* functionalities. * functionalities.
@ -34,6 +37,8 @@ public interface DeviceManagementService {
String getType(); String getType();
List<TaskOperation> getTasksForPlatform();//getTasksConfiguraitons
DeviceManager getDeviceManager(); DeviceManager getDeviceManager();
ApplicationManager getApplicationManager(); ApplicationManager getApplicationManager();

@ -21,16 +21,25 @@ package org.wso2.carbon.device.mgt.core.operation.mgt;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.TaskOperation;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.*; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -43,6 +52,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
import org.wso2.carbon.device.mgt.core.operation.mgt.util.DeviceIDHolder; import org.wso2.carbon.device.mgt.core.operation.mgt.util.DeviceIDHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationCreateTimeComparator; import org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationCreateTimeComparator;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl; import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
@ -51,7 +61,9 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated * This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated
@ -127,7 +139,7 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
OperationDAOUtil.convertOperation(operation); OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
boolean isScheduledOperation = this.isTaskScheduledOperation(operation); boolean isScheduledOperation = this.isTaskScheduledOperation(operation, deviceIds);
boolean isNotRepeated = false; boolean isNotRepeated = false;
boolean hasExistingTaskOperation; boolean hasExistingTaskOperation;
int enrolmentId; int enrolmentId;
@ -231,7 +243,7 @@ public class OperationManagerImpl implements OperationManager {
List<String> unAuthorizedDeviceList = new ArrayList<>(); List<String> unAuthorizedDeviceList = new ArrayList<>();
DeviceIDHolder deviceIDHolder = new DeviceIDHolder(); DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
try { try {
if (operation != null && isAuthenticationSkippedOperation(operation)) { if (operation != null && isAuthenticationSkippedOperation(operation, deviceIds)) {
authorizedDeviceList = deviceIds; authorizedDeviceList = deviceIds;
} else { } else {
boolean isAuthorized; boolean isAuthorized;
@ -873,11 +885,11 @@ public class OperationManagerImpl implements OperationManager {
return CarbonContext.getThreadLocalCarbonContext().getUsername(); return CarbonContext.getThreadLocalCarbonContext().getUsername();
} }
private boolean isAuthenticationSkippedOperation(Operation operation) { private boolean isAuthenticationSkippedOperation(Operation operation, List<DeviceIdentifier> deviceIds) {
//This is to check weather operations are coming from the task related to retrieving device information. //This is to check weather operations are coming from the task related to retrieving device information.
DeviceTaskManager taskManager = new DeviceTaskManagerImpl(); DeviceTaskManager taskManager = new DeviceTaskManagerImpl();
if (taskManager.isTaskOperation(operation.getCode())) { if (taskManager.isTaskOperation(operation.getCode(), deviceIds)) {
return true; return true;
} }
@ -1021,14 +1033,37 @@ public class OperationManagerImpl implements OperationManager {
return resetStatus; return resetStatus;
} }
private boolean isTaskScheduledOperation(Operation operation) { private boolean isTaskScheduledOperation(Operation operation, List<DeviceIdentifier> deviceIds) {
TaskConfiguration taskConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). List<TaskOperation> taskOperations = new ArrayList<>();
getTaskConfiguration(); Map<String, List<TaskOperation>> deviceTypeSpecificTasks = new HashMap<>();
for (TaskConfiguration.Operation op : taskConfiguration.getOperations()) { DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
if (operation.getCode().equals(op.getOperationName())) { getDeviceManagementProvider();
return true;
deviceTypeSpecificTasks = deviceManagementProviderService.getTaskList();//Get task list from each device type
for(DeviceIdentifier deviceIdentifier : deviceIds){
String deviceType = deviceIdentifier.getType();
for(String dti : deviceTypeSpecificTasks.keySet()){
if (dti.equals(deviceType)) {
taskOperations = deviceTypeSpecificTasks.get(dti);
for(TaskOperation op : taskOperations){
if (operation.getCode().equals(op.getTaskName())) {
return true;
}
}
}
} }
} }
// TaskConfiguration taskConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
// getTaskConfiguration();
// for (TaskConfiguration.Operation op : taskConfiguration.getOperations()) {
// if (operation.getCode().equals(op.getOperationName())) {
// return true;
// }
// }
return false; return false;
} }

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import java.util.HashMap; import java.util.HashMap;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Proxy class for all Device Management related operations that take the corresponding plugin type in * Proxy class for all Device Management related operations that take the corresponding plugin type in
@ -275,4 +276,6 @@ public interface DeviceManagementProviderService {
int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException; int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException;
Map<String, List<TaskOperation>> getTaskList();
} }

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; 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.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
@ -32,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.TaskOperation;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
@ -1213,6 +1215,27 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return DeviceManagementDataHolder.getInstance().getOperationManager().getActivityCountUpdatedAfter(timestamp); return DeviceManagementDataHolder.getInstance().getOperationManager().getActivityCountUpdatedAfter(timestamp);
} }
@Override
public Map<String, List<TaskOperation>> getTaskList() {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Map<DeviceTypeIdentifier, DeviceManagementService> deviceManagementServiceMap =
pluginRepository.getAllDeviceManagementServices(tenantId);
DeviceManagementService dms;
String deviceType;
List<TaskOperation> taskOperations;
Map<String, List<TaskOperation>> deviceTypeSpecificTasks = new HashMap<>();
for(DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()){
dms = deviceManagementServiceMap.get(dti);
taskOperations = dms.getTasksForPlatform();
if (taskOperations != null) {
deviceType = dms.getType();
deviceTypeSpecificTasks.put(deviceType, taskOperations);
}
}
return deviceTypeSpecificTasks;
}
@Override @Override
public List<Device> getDevicesOfUser(String username) throws DeviceManagementException { public List<Device> getDevicesOfUser(String username) throws DeviceManagementException {
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();

@ -19,6 +19,8 @@
package org.wso2.carbon.device.mgt.core.task; package org.wso2.carbon.device.mgt.core.task;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.util.List; import java.util.List;
public interface DeviceTaskManager { public interface DeviceTaskManager {
@ -29,8 +31,8 @@ public interface DeviceTaskManager {
* @return - list of Task Operations. * @return - list of Task Operations.
* @throws DeviceMgtTaskException * @throws DeviceMgtTaskException
*/ */
List<TaskOperation> getOperationList() throws DeviceMgtTaskException; List<org.wso2.carbon.device.mgt.common.TaskOperation> getOperationList(String deviceType)
throws DeviceMgtTaskException;
/** /**
* This method will take the monitoring frequency. * This method will take the monitoring frequency.
@ -66,7 +68,7 @@ public interface DeviceTaskManager {
* @return * @return
* @throws DeviceMgtTaskException * @throws DeviceMgtTaskException
*/ */
List<String> getValidOperationNames() throws DeviceMgtTaskException; List<String> getValidOperationNames(String deviceType) throws DeviceMgtTaskException;
/** /**
* This method will check wheather give operation is added by the task. * This method will check wheather give operation is added by the task.
@ -74,6 +76,6 @@ public interface DeviceTaskManager {
* @return - true or false * @return - true or false
* @throws DeviceMgtTaskException * @throws DeviceMgtTaskException
*/ */
boolean isTaskOperation(String opName); boolean isTaskOperation(String opName, List<DeviceIdentifier> deviceIds);
} }

@ -22,22 +22,27 @@ package org.wso2.carbon.device.mgt.core.task.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.TaskOperation;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
import org.wso2.carbon.device.mgt.core.task.TaskOperation;
import org.wso2.carbon.device.mgt.core.task.Utils; import org.wso2.carbon.device.mgt.core.task.Utils;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DeviceTaskManagerImpl implements DeviceTaskManager { public class DeviceTaskManagerImpl implements DeviceTaskManager {
@ -47,34 +52,35 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override @Override
public List<TaskOperation> getOperationList() throws DeviceMgtTaskException { //get device type specific operations
TaskConfiguration taskConfiguration = public List<TaskOperation> getOperationList(String deviceType) throws DeviceMgtTaskException {
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration();
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations();
List<TaskOperation> taskOperations = new ArrayList<>(); List<TaskOperation> taskOperations = new ArrayList<>();
for (TaskConfiguration.Operation op : ops) { Map<String, List<TaskOperation>> deviceTypeSpecificTasks;
TaskOperation taskOperation = new TaskOperation(); //This Map contains task list against device type
taskOperation.setTaskName(op.getOperationName()); DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
taskOperation.setRecurrentTimes(op.getRecurrency()); getDeviceManagementProvider();
taskOperation.setTaskPlatforms(op.getPlatforms());
taskOperations.add(taskOperation); deviceTypeSpecificTasks = deviceManagementProviderService.getTaskList();//Get task list from each device type
for(String dti : deviceTypeSpecificTasks.keySet()){
if (dti.equals(deviceType)) {
taskOperations = deviceTypeSpecificTasks.get(dti);
}
} }
return taskOperations; return taskOperations;
} }
public List<String> getPlatformsForOperations(String opName) { private List<String> getDeviceTypes() {
List<String> operationPlatforms = new ArrayList<>(); List<String> operationPlatforms = new ArrayList<>();
TaskConfiguration taskConfiguration = Map<String, List<TaskOperation>> deviceTypeSpecificTasks;
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration();
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations(); DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
for (TaskConfiguration.Operation op : ops) { getDeviceManagementProvider();
if (op.getOperationName().equals(opName)) { deviceTypeSpecificTasks = deviceManagementProviderService.getTaskList();
List<String> platform = op.getPlatforms();
for (String operationPlatform : platform) { Set<String> platformTypes = deviceTypeSpecificTasks.keySet();
operationPlatforms.add(operationPlatform); for(String platformType : platformTypes ){
} operationPlatforms.add(platformType);
}
} }
return operationPlatforms; return operationPlatforms;
} }
@ -100,32 +106,31 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override @Override
public void addOperations() throws DeviceMgtTaskException { public void addOperations() throws DeviceMgtTaskException {
List<String> deviceTypes;
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance(). DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider(); getDeviceManagementProvider();
try { try {
List<Device> devices; List<Device> devices;
List<String> operations = this.getValidOperationNames(); List<String> operations;
for (String taskOperation : operations) { List<String> deviceTypes = this.getDeviceTypes();//list available device types
deviceTypes = getPlatformsForOperations(taskOperation);
for (String deviceType : deviceTypes) { for(String deviceType : deviceTypes){
devices = deviceManagementProviderService.getAllDevices(deviceType); operations = this.getValidOperationNames(deviceType); //list operations for each device type
if (!devices.isEmpty()) { devices = deviceManagementProviderService.getAllDevices(deviceType);//list devices for each type
for (String str : operations) { if (!devices.isEmpty()) {
CommandOperation operation = new CommandOperation(); for (String str : operations) {
operation.setEnabled(true); CommandOperation operation = new CommandOperation();
operation.setType(Operation.Type.COMMAND); operation.setEnabled(true);
operation.setCode(str); operation.setType(Operation.Type.COMMAND);
deviceManagementProviderService.addOperation(deviceType, operation, operation.setCode(str);
DeviceManagerUtil.getValidDeviceIdentifiers(devices)); deviceManagementProviderService.addOperation(deviceType, operation,
} DeviceManagerUtil.getValidDeviceIdentifiers(devices));
} else { }
if (log.isDebugEnabled()) { } else {
log.debug("No devices are available to perform the operations."); if (log.isDebugEnabled()) {
} log.debug("No devices are available to perform the operations.");
} }
}
}
} }
} catch (InvalidDeviceException e) { } catch (InvalidDeviceException e) {
throw new DeviceMgtTaskException("Invalid DeviceIdentifiers found.", e); throw new DeviceMgtTaskException("Invalid DeviceIdentifiers found.", e);
@ -137,8 +142,9 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
} }
@Override @Override
public List<String> getValidOperationNames() throws DeviceMgtTaskException { public List<String> getValidOperationNames(String deviceType) throws DeviceMgtTaskException {
List<TaskOperation> taskOperations = this.getOperationList();
List<TaskOperation> taskOperations = this.getOperationList(deviceType);
List<String> opNames = new ArrayList<>(); List<String> opNames = new ArrayList<>();
Long milliseconds = System.currentTimeMillis(); Long milliseconds = System.currentTimeMillis();
int frequency = this.getTaskFrequency(); int frequency = this.getTaskFrequency();
@ -167,17 +173,22 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override @Override
public boolean isTaskOperation(String opName) { public boolean isTaskOperation(String opName, List<DeviceIdentifier> deviceIds) {
try {
List<TaskOperation> taskOperations = this.getOperationList(); for(DeviceIdentifier deviceIdentifier : deviceIds){
for (TaskOperation taop : taskOperations) { String deviceType = deviceIdentifier.getType();
if (taop.getTaskName().equalsIgnoreCase(opName)) { try {
return true; List<TaskOperation> taskOperations = this.getOperationList(deviceType);
for (TaskOperation taop : taskOperations) {
if (taop.getTaskName().equalsIgnoreCase(opName)) {
return true;
}
} }
} catch (DeviceMgtTaskException e) {
// ignoring the error, no need to throw, If error occurs, return value will be false.
} }
} catch (DeviceMgtTaskException e) {
// ignoring the error, no need to throw, If error occurs, return value will be false.
} }
return false; return false;
} }

@ -39,6 +39,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
public static final String TASK_TYPE = "DEVICE_DETAILS"; public static final String TASK_TYPE = "DEVICE_DETAILS";
public static final String TASK_NAME = "DEVICE_DETAILS_TASK"; public static final String TASK_NAME = "DEVICE_DETAILS_TASK";
public static final String TENANT_ID = "TENANT_ID"; public static final String TENANT_ID = "TENANT_ID";
private static String TASK_CLASS = "org.wso2.carbon.device.mgt.core.task.impl.DeviceDetailsRetrieverTask";
private DeviceTaskManager deviceTaskManager; private DeviceTaskManager deviceTaskManager;
@ -75,7 +77,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
if (!taskManager.isTaskScheduled(TASK_NAME)) { if (!taskManager.isTaskScheduled(TASK_NAME)) {
TaskInfo taskInfo = new TaskInfo(TASK_NAME, deviceTaskManager.getTaskImplementedClazz(), TaskInfo taskInfo = new TaskInfo(TASK_NAME, TASK_CLASS,
properties, triggerInfo); properties, triggerInfo);
taskManager.registerTask(taskInfo); taskManager.registerTask(taskInfo);
@ -130,7 +132,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
properties.put(TENANT_ID, String.valueOf(tenantId)); properties.put(TENANT_ID, String.valueOf(tenantId));
TaskInfo taskInfo = new TaskInfo(TASK_NAME, deviceTaskManager.getTaskImplementedClazz(), properties, TaskInfo taskInfo = new TaskInfo(TASK_NAME, TASK_CLASS, properties,
triggerInfo); triggerInfo);
taskManager.registerTask(taskInfo); taskManager.registerTask(taskInfo);

@ -17,12 +17,11 @@
*/ */
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.TaskOperation;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@ -42,6 +41,11 @@ public class TestDeviceManagementService implements DeviceManagementService {
return providerType; return providerType;
} }
@Override
public List<TaskOperation> getTasksForPlatform(){
return null;
}
@Override @Override
public void init() throws DeviceManagementException { public void init() throws DeviceManagementException {

@ -76,7 +76,7 @@ public class PolicyFilterImpl implements PolicyFilter {
continue; continue;
} else { } else {
for (DeviceGroupWrapper deviceGroupWrapper : wrappers) { for (DeviceGroupWrapper deviceGroupWrapper : wrappers) {
if (groupMap.containsKey(deviceGroupWrapper.getId()) && policyMap.containsKey(policy.getId())) { if (groupMap.containsKey(deviceGroupWrapper.getId()) && !policyMap.containsKey(policy.getId())) {
temp.add(policy); temp.add(policy);
policyMap.put(policy.getId(), policy); policyMap.put(policy.getId(), policy);
} }
@ -140,6 +140,9 @@ public class PolicyFilterImpl implements PolicyFilter {
@Override @Override
public List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) { public List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) {
if (ownershipType == null) {
return policies;
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("No of policies went in to filterOwnershipTypeBasedPolicies : " + policies.size()); log.debug("No of policies went in to filterOwnershipTypeBasedPolicies : " + policies.size());
log.debug("Ownership type : " + ownershipType); log.debug("Ownership type : " + ownershipType);
@ -150,7 +153,7 @@ public class PolicyFilterImpl implements PolicyFilter {
List<Policy> temp = new ArrayList<Policy>(); List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) { for (Policy policy : policies) {
if (ownershipType.equalsIgnoreCase(policy.getOwnershipType()) || if (policy.getOwnershipType() == null || ownershipType.equalsIgnoreCase(policy.getOwnershipType()) ||
PolicyManagementConstants.ANY.equalsIgnoreCase(policy.getOwnershipType())) { PolicyManagementConstants.ANY.equalsIgnoreCase(policy.getOwnershipType())) {
temp.add(policy); temp.add(policy);
} }

@ -128,6 +128,12 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
} }
if (pipDevice.getDeviceGroups() != null && !pipDevice.getDeviceGroups().isEmpty()) { if (pipDevice.getDeviceGroups() != null && !pipDevice.getDeviceGroups().isEmpty()) {
Map<Integer, DeviceGroup> groupMap = new HashMap<>();
List<DeviceGroup> groups = pipDevice.getDeviceGroups();
for(DeviceGroup gr: groups){
groupMap.put(gr.getGroupId(), gr);
}
policies = policyFilter.filterDeviceGroupsPolicies(groupMap, policies);
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -51,33 +51,6 @@
<TaskConfiguration> <TaskConfiguration>
<Enable>true</Enable> <Enable>true</Enable>
<Frequency>600000</Frequency> <Frequency>600000</Frequency>
<TaskClass>org.wso2.carbon.device.mgt.core.task.impl.DeviceDetailsRetrieverTask</TaskClass>
<Operations>
<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> </TaskConfiguration>
<!-- Default Page size configuration for paginated DM APIs--> <!-- Default Page size configuration for paginated DM APIs-->
<PaginationConfiguration> <PaginationConfiguration>

Loading…
Cancel
Save