diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/StartupOperationConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/StartupOperationConfig.java new file mode 100644 index 00000000000..e8be3713f04 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/StartupOperationConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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; + +import java.util.List; + +public class StartupOperationConfig { + + private List startupOperations; + + public List getStartupOperations() { + return startupOperations; + } + + public void setStartupOperations(List startupOperations) { + this.startupOperations = startupOperations; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index b14a5ab920a..a8c73e1c43d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -15,6 +15,22 @@ * specific language governing permissions and limitations * under the License. * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.spi; @@ -49,6 +65,8 @@ public interface DeviceManagementService { InitialOperationConfig getInitialOperationConfig(); + StartupOperationConfig getStartupOperationConfig(); + PullNotificationSubscriber getPullNotificationSubscriber(); DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 186b253de40..c2c7ef4813f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -46,6 +46,7 @@ import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.StartupOperationConfig; import org.wso2.carbon.device.mgt.common.UserNotFoundException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; @@ -654,10 +655,14 @@ public interface DeviceManagementProviderService { List getMonitoringOperationList(String deviceType); + List getStartupOperations(String deviceType); + int getDeviceMonitoringFrequency(String deviceType); OperationMonitoringTaskConfig getDeviceMonitoringConfig(String deviceType); + StartupOperationConfig getStartupOperationConfig(String deviceType); + boolean isDeviceMonitoringEnabled(String deviceType); PolicyMonitoringManager getPolicyMonitoringManager(String deviceType); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index b65b75d2ea1..151352c7b1d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -65,6 +65,7 @@ import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.StartupOperationConfig; import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.UserNotFoundException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; @@ -1733,6 +1734,19 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return operationMonitoringTaskConfig.getMonitoringOperation(); } + @Override + public List getStartupOperations(String deviceType) { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + + DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceType, tenantId); + + StartupOperationConfig startupOperationConfig = dms.getStartupOperationConfig(); + if (startupOperationConfig != null) { + return startupOperationConfig.getStartupOperations(); + } + return null; + } + @Override public int getDeviceMonitoringFrequency(String deviceType) { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -1748,6 +1762,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return dms.getOperationMonitoringConfig(); } + @Override + public StartupOperationConfig getStartupOperationConfig(String deviceType) { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceType, tenantId); + return dms.getStartupOperationConfig(); + } + @Override public boolean isDeviceMonitoringEnabled(String deviceType) { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/Utils.java index 36b43b12c68..bf3db9c6b3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/Utils.java @@ -14,6 +14,23 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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. */ @@ -21,7 +38,9 @@ package org.wso2.carbon.device.mgt.core.task; import org.wso2.carbon.context.PrivilegedCarbonContext; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public class Utils { @@ -46,5 +65,25 @@ public class Utils { } } + public static boolean getIsTenantedStartupConfig(Map> map, String deviceType) { + List deviceTypes; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + if (map.containsKey(tenantId)) { + if (map.get(tenantId).contains(deviceType)) { + return false; + } else { + deviceTypes = map.get(tenantId); + deviceTypes.add(deviceType); + map.put(tenantId, deviceTypes); + return true; + } + } else { + deviceTypes = new ArrayList<>(); + deviceTypes.add(deviceType); + map.put(tenantId, deviceTypes); + return true; + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index f411c3d9f84..a9fee811251 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -14,6 +14,23 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.core.task.impl; @@ -23,6 +40,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; +import org.wso2.carbon.device.mgt.common.StartupOperationConfig; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; @@ -56,17 +74,20 @@ public class DeviceDetailsRetrieverTask implements Task { .getDeviceManagementProvider(); OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceManagementProviderService .getDeviceMonitoringConfig(deviceType); + StartupOperationConfig startupOperationConfig = deviceManagementProviderService + .getStartupOperationConfig(deviceType); if (System.getProperty(IS_CLOUD) != null && Boolean.parseBoolean(System.getProperty(IS_CLOUD))) { executeForTenants = true; } if (executeForTenants) { - this.executeForAllTenants(operationMonitoringTaskConfig); + this.executeForAllTenants(operationMonitoringTaskConfig, startupOperationConfig); } else { if (log.isDebugEnabled()) { log.debug("Device details retrieving task started to run."); } - DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, operationMonitoringTaskConfig); + DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, operationMonitoringTaskConfig, + startupOperationConfig); //pass the configurations also from here, monitoring tasks try { if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) { @@ -78,7 +99,8 @@ public class DeviceDetailsRetrieverTask implements Task { } } - private void executeForAllTenants(OperationMonitoringTaskConfig operationMonitoringTaskConfig) { + private void executeForAllTenants(OperationMonitoringTaskConfig operationMonitoringTaskConfig, + StartupOperationConfig startupOperationConfig) { if (log.isDebugEnabled()) { log.debug("Device details retrieving task started to run for all tenants."); @@ -98,7 +120,8 @@ public class DeviceDetailsRetrieverTask implements Task { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, - operationMonitoringTaskConfig); + operationMonitoringTaskConfig, + startupOperationConfig); //pass the configurations also from here, monitoring tasks try { if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) { 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 c4acc9c82e1..c677b309158 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 @@ -17,7 +17,7 @@ * * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, + * Entgra (Pvt) Ltd. 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 @@ -44,6 +44,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; +import org.wso2.carbon.device.mgt.common.StartupOperationConfig; 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.internal.DeviceManagementDataHolder; @@ -62,7 +63,17 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class); private String deviceType; static volatile Map>> map = new HashMap<>(); + private static volatile Map> startupConfigMap = new HashMap<>(); private OperationMonitoringTaskConfig operationMonitoringTaskConfig; + private StartupOperationConfig startupOperationConfig; + + public DeviceTaskManagerImpl(String deviceType, + OperationMonitoringTaskConfig operationMonitoringTaskConfig, + StartupOperationConfig startupOperationConfig) { + this.deviceType = deviceType; + this.operationMonitoringTaskConfig = operationMonitoringTaskConfig; + this.startupOperationConfig = startupOperationConfig; + } public DeviceTaskManagerImpl(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) { @@ -79,6 +90,13 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { return operationMonitoringTaskConfig.getMonitoringOperation(); } + private List getStartupOperations() { + if (startupOperationConfig != null) { + return startupOperationConfig.getStartupOperations(); + } + return null; + } + @Override public int getTaskFrequency() throws DeviceMgtTaskException { return operationMonitoringTaskConfig.getFrequency(); @@ -104,6 +122,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { List devices; List operations; List validDeviceIdentifiers; + List startupOperations; operations = this.getValidOperationNames(); //list operations for each device type devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type @@ -118,18 +137,17 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { .size()); } for (String str : operations) { - Operation operation; - if ("SERVER_VERSION".equals(str)) { - operation = new ProfileOperation(); - operation.setPayLoad(ServerConfiguration.getInstance().getFirstProperty("Version")); - } else { - operation = new CommandOperation(); - } - operation.setType(Operation.Type.COMMAND); + CommandOperation operation = new CommandOperation(); operation.setEnabled(true); + operation.setType(Operation.Type.COMMAND); operation.setCode(str); deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers); } + startupOperations = getStartupOperations(); + if (startupOperations != null && !startupOperations.isEmpty()) { + addStartupOperations(startupOperations, validDeviceIdentifiers, + deviceManagementProviderService); + } } else { if (log.isDebugEnabled()) { log.debug("No operations are available."); @@ -177,6 +195,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { return opNames; } + private void addStartupOperations(List startupOperations, List validDeviceIdentifiers + , DeviceManagementProviderService deviceManagementProviderService) throws DeviceMgtTaskException { + boolean isStartupConfig = Utils.getIsTenantedStartupConfig(startupConfigMap, deviceType); + if (isStartupConfig) { + try { + Operation operation; + for (String startupOp : startupOperations) { + if ("SERVER_VERSION".equals(startupOp)) { + operation = new ProfileOperation(); + operation.setPayLoad(ServerConfiguration.getInstance().getFirstProperty("Version")); + } else { + operation = new CommandOperation(); + } + operation.setType(Operation.Type.COMMAND); + operation.setEnabled(true); + operation.setCode(startupOp); + deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers); + } + } catch (InvalidDeviceException e) { + throw new DeviceMgtTaskException("Invalid DeviceIdentifiers found.", e); + } catch (OperationManagementException e) { + throw new DeviceMgtTaskException("Error occurred while adding the operations to devices", e); + } + } + } + private List getOperationListforTask() throws DeviceMgtTaskException { DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder @@ -187,17 +231,31 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { deviceType);//Get task list from each device type } + private List getStartupOperationListForTask() { + DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance() + .getDeviceManagementProvider(); + return deviceManagementProviderService.getStartupOperations(deviceType); + } + @Override public boolean isTaskOperation(String opName) { try { List monitoringOperations = this.getOperationListforTask(); + List startupOperations = this.getStartupOperationListForTask(); for (MonitoringOperation taop : monitoringOperations) { if (taop.getTaskName().equalsIgnoreCase(opName)) { return true; } } + if (startupOperations != null && !startupOperations.isEmpty()) { + for (String operation : startupOperations) { + if (opName.equalsIgnoreCase(operation)) { + return true; + } + } + } } catch (DeviceMgtTaskException e) { // ignoring the error, no need to throw, If error occurs, return value will be false. } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index d9449f6a498..9154afd0e34 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -14,6 +14,22 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.core; @@ -100,6 +116,11 @@ public class TestDeviceManagementService implements DeviceManagementService { return null; } + @Override + public StartupOperationConfig getStartupOperationConfig() { + return null; + } + @Override public PullNotificationSubscriber getPullNotificationSubscriber() { return null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java index ca245a1d001..755895a862b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java @@ -15,6 +15,22 @@ * specific language governing permissions and limitations * under the License. * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.template; @@ -27,6 +43,7 @@ import org.wso2.carbon.device.mgt.common.InitialOperationConfig; import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; +import org.wso2.carbon.device.mgt.common.StartupOperationConfig; 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; @@ -70,6 +87,7 @@ public class DeviceTypeManagerService implements DeviceManagementService { private List monitoringOperations; private PolicyMonitoringManager policyMonitoringManager; private InitialOperationConfig initialOperationConfig; + private StartupOperationConfig startupOperationConfig; private PullNotificationSubscriber pullNotificationSubscriber; private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig; private GeneralConfig generalConfig; @@ -87,6 +105,8 @@ public class DeviceTypeManagerService implements DeviceManagementService { this.setOperationMonitoringConfig(deviceTypeConfiguration); this.initialOperationConfig = new InitialOperationConfig(); this.setInitialOperationConfig(deviceTypeConfiguration); + this.startupOperationConfig = new StartupOperationConfig(); + this.setStartupOperationConfig(deviceTypeConfiguration); this.deviceStatusTaskPluginConfig = new DeviceStatusTaskPluginConfig(); this.setDeviceStatusTaskPluginConfig(deviceTypeConfiguration.getDeviceStatusTaskConfiguration()); this.setPolicyMonitoringManager(deviceTypeConfiguration.getPolicyMonitoring()); @@ -210,6 +230,11 @@ public class DeviceTypeManagerService implements DeviceManagementService { return initialOperationConfig; } + @Override + public StartupOperationConfig getStartupOperationConfig() { + return startupOperationConfig; + } + @Override public PullNotificationSubscriber getPullNotificationSubscriber() { return pullNotificationSubscriber; @@ -267,6 +292,15 @@ public class DeviceTypeManagerService implements DeviceManagementService { } } + private void setStartupOperationConfig(DeviceTypeConfiguration deviceTypeConfiguration) { + if (deviceTypeConfiguration.getOperations() != null) { + List startupOperations = deviceTypeConfiguration.getStartupOperations(); + if (startupOperations != null && !startupOperations.isEmpty()) { + startupOperationConfig.setStartupOperations(startupOperations); + } + } + } + private void setType(String type) { this.type = type; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java index 46f442e89d8..b1ba2d8fe8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java @@ -15,6 +15,22 @@ * specific language governing permissions and limitations * under the License. * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.template.config; @@ -86,6 +102,9 @@ public class DeviceTypeConfiguration { @XmlElementWrapper(name = "InitialOperationConfig") @XmlElement(name = "Operation", required = true) protected List operations; + @XmlElementWrapper(name = "StartupOperationConfig") + @XmlElement(name = "Operation", required = true) + protected List startupOperations; public List getOperations() { return operations; @@ -363,4 +382,24 @@ public class DeviceTypeConfiguration { public void setDeviceAuthorizationConfig(DeviceAuthorizationConfig value) { this.deviceAuthorizationConfig = value; } + + /** + * Gets the value of startup operation config + * + * @return possible object is + * {@link List} + */ + public List getStartupOperations() { + return startupOperations; + } + + /** + * Sets the value for startup operation config + * + * @param startupOperations possible object is + * {@link List} + */ + public void setStartupOperations(List startupOperations) { + this.startupOperations = startupOperations; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java index 0f76246da64..c0297bff753 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java @@ -14,6 +14,23 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. + * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.policy.mgt.core.mock; @@ -24,6 +41,7 @@ import org.wso2.carbon.device.mgt.common.InitialOperationConfig; import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; +import org.wso2.carbon.device.mgt.common.StartupOperationConfig; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; @@ -88,6 +106,11 @@ public class TypeXDeviceManagementService implements DeviceManagementService { return null; } + @Override + public StartupOperationConfig getStartupOperationConfig() { + return null; + } + @Override public PullNotificationSubscriber getPullNotificationSubscriber() { return null;