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

merge-requests/7/head
charitha 8 years ago
commit 3b97b3296e

@ -66,9 +66,35 @@ public class DeviceTypeConfiguration {
protected License license;
@XmlElement(name = "DataSource", required = true)
protected DataSource dataSource;
@XmlElement(name = "TaskConfiguration", required = true)
private TaskConfiguration taskConfiguration;
@XmlAttribute(name = "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.
*

@ -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.DeviceManager;
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.configuration.mgt.ConfigurationEntry;
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.Property;
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.List;
import java.util.Map;
@ -48,6 +51,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private PushNotificationConfig pushNotificationConfig;
private ProvisioningConfig provisioningConfig;
private String type;
private List<TaskOperation> taskOperations;
public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
DeviceTypeConfiguration deviceTypeConfiguration) {
@ -55,6 +59,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceTypeConfiguration);
this.setType(deviceTypeConfiguration.getName());
this.populatePushNotificationConfig(deviceTypeConfiguration.getPushNotificationProvider());
this.setTask(deviceTypeConfiguration);
}
@Override
@ -62,6 +67,28 @@ public class DeviceTypeManagerService implements DeviceManagementService {
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
public void init() throws DeviceManagementException {
}

@ -97,5 +97,20 @@
</Table>
</tableConfig>
</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>

@ -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.DeviceManager;
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.push.notification.PushNotificationConfig;
import java.util.List;
/**
* Composite interface that acts as the SPI exposing all device management as well as application management
* functionalities.
@ -34,6 +37,8 @@ public interface DeviceManagementService {
String getType();
List<TaskOperation> getTasksForPlatform();//getTasksConfiguraitons
DeviceManager getDeviceManager();
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.LogFactory;
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.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.NotificationStrategy;
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.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.DeviceManagementDAOException;
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.util.DeviceIDHolder;
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.impl.DeviceTaskManagerImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
@ -51,7 +61,9 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 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 =
OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
boolean isScheduledOperation = this.isTaskScheduledOperation(operation, deviceIds);
boolean isNotRepeated = false;
boolean hasExistingTaskOperation;
int enrolmentId;
@ -231,7 +243,7 @@ public class OperationManagerImpl implements OperationManager {
List<String> unAuthorizedDeviceList = new ArrayList<>();
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
try {
if (operation != null && isAuthenticationSkippedOperation(operation)) {
if (operation != null && isAuthenticationSkippedOperation(operation, deviceIds)) {
authorizedDeviceList = deviceIds;
} else {
boolean isAuthorized;
@ -873,11 +885,11 @@ public class OperationManagerImpl implements OperationManager {
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.
DeviceTaskManager taskManager = new DeviceTaskManagerImpl();
if (taskManager.isTaskOperation(operation.getCode())) {
if (taskManager.isTaskOperation(operation.getCode(), deviceIds)) {
return true;
}
@ -1021,14 +1033,37 @@ public class OperationManagerImpl implements OperationManager {
return resetStatus;
}
private boolean isTaskScheduledOperation(Operation operation) {
TaskConfiguration taskConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getTaskConfiguration();
for (TaskConfiguration.Operation op : taskConfiguration.getOperations()) {
if (operation.getCode().equals(op.getOperationName())) {
return true;
private boolean isTaskScheduledOperation(Operation operation, List<DeviceIdentifier> deviceIds) {
List<TaskOperation> taskOperations = new ArrayList<>();
Map<String, List<TaskOperation>> deviceTypeSpecificTasks = new HashMap<>();
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
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;
}

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import java.util.HashMap;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 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;
Map<String, List<TaskOperation>> getTaskList();
}

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
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.DeviceIdentifier;
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.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.app.mgt.Application;
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);
}
@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
public List<Device> getDevicesOfUser(String username) throws DeviceManagementException {
List<Device> devices = new ArrayList<>();

@ -19,6 +19,8 @@
package org.wso2.carbon.device.mgt.core.task;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.util.List;
public interface DeviceTaskManager {
@ -29,8 +31,8 @@ public interface DeviceTaskManager {
* @return - list of Task Operations.
* @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.
@ -66,7 +68,7 @@ public interface DeviceTaskManager {
* @return
* @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.
@ -74,6 +76,6 @@ public interface DeviceTaskManager {
* @return - true or false
* @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.LogFactory;
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.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.OperationManagementException;
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.operation.mgt.CommandOperation;
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.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.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 {
@ -47,34 +52,35 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override
public List<TaskOperation> getOperationList() throws DeviceMgtTaskException {
TaskConfiguration taskConfiguration =
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration();
//get device type specific operations
public List<TaskOperation> getOperationList(String deviceType) throws DeviceMgtTaskException {
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);
Map<String, List<TaskOperation>> deviceTypeSpecificTasks;
//This Map contains task list against device type
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
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;
}
public List<String> getPlatformsForOperations(String opName) {
private List<String> getDeviceTypes() {
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);
}
}
Map<String, List<TaskOperation>> deviceTypeSpecificTasks;
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
deviceTypeSpecificTasks = deviceManagementProviderService.getTaskList();
Set<String> platformTypes = deviceTypeSpecificTasks.keySet();
for(String platformType : platformTypes ){
operationPlatforms.add(platformType);
}
return operationPlatforms;
}
@ -100,32 +106,31 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override
public void addOperations() throws DeviceMgtTaskException {
List<String> deviceTypes;
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
try {
List<Device> devices;
List<String> operations = this.getValidOperationNames();
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.");
}
}
}
List<String> operations;
List<String> deviceTypes = this.getDeviceTypes();//list available device types
for(String deviceType : deviceTypes){
operations = this.getValidOperationNames(deviceType); //list operations for each device type
devices = deviceManagementProviderService.getAllDevices(deviceType);//list devices for each type
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);
@ -137,8 +142,9 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
}
@Override
public List<String> getValidOperationNames() throws DeviceMgtTaskException {
List<TaskOperation> taskOperations = this.getOperationList();
public List<String> getValidOperationNames(String deviceType) throws DeviceMgtTaskException {
List<TaskOperation> taskOperations = this.getOperationList(deviceType);
List<String> opNames = new ArrayList<>();
Long milliseconds = System.currentTimeMillis();
int frequency = this.getTaskFrequency();
@ -167,17 +173,22 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override
public boolean isTaskOperation(String opName) {
try {
List<TaskOperation> taskOperations = this.getOperationList();
for (TaskOperation taop : taskOperations) {
if (taop.getTaskName().equalsIgnoreCase(opName)) {
return true;
public boolean isTaskOperation(String opName, List<DeviceIdentifier> deviceIds) {
for(DeviceIdentifier deviceIdentifier : deviceIds){
String deviceType = deviceIdentifier.getType();
try {
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;
}

@ -39,6 +39,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
public static final String TASK_TYPE = "DEVICE_DETAILS";
public static final String TASK_NAME = "DEVICE_DETAILS_TASK";
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;
@ -75,7 +77,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
if (!taskManager.isTaskScheduled(TASK_NAME)) {
TaskInfo taskInfo = new TaskInfo(TASK_NAME, deviceTaskManager.getTaskImplementedClazz(),
TaskInfo taskInfo = new TaskInfo(TASK_NAME, TASK_CLASS,
properties, triggerInfo);
taskManager.registerTask(taskInfo);
@ -130,7 +132,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
Map<String, String> properties = new HashMap<>();
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);
taskManager.registerTask(taskInfo);

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

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

@ -128,6 +128,12 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
}
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()) {

@ -51,33 +51,6 @@
<TaskConfiguration>
<Enable>true</Enable>
<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>
<!-- Default Page size configuration for paginated DM APIs-->
<PaginationConfiguration>

Loading…
Cancel
Save