From a2a46a3439702bebf22b75b34a7856ddea257aa8 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 16 Nov 2017 21:10:28 +0530 Subject: [PATCH 1/4] Add siddhi extensions to reflect get methods in device management core service --- .../pom.xml | 23 +-- .../GetDevicesOfStatusFunctionExecutor.java | 132 ++++++++++++++ .../GetDevicesOfUserFunctionExecutor.java | 143 +++++++++++++++ .../HasDevicesOfStatusFunctionExecutor.java | 134 ++++++++++++++ .../HasDevicesOfUserFunctionExecutor.java | 147 +++++++++++++++ .../device/IsEnrolledFunctionExecutor.java | 122 +++++++++++++ .../device/IsInGroupFunctionExecutor.java} | 32 ++-- .../siddhi/device/utils/DeviceUtils.java} | 45 ++--- .../src/main/resources/device.siddhiext} | 9 +- .../device}/BaseDeviceManagementTest.java | 6 +- .../siddhi/device/ExtensionTestCase.java} | 168 ++++++++++++++---- .../device}/test/util/DataSourceConfig.java | 2 +- .../device}/test/util/SiddhiTestHelper.java | 2 +- .../device}/test/util/TestDataHolder.java | 4 +- .../util/TestDeviceManagementService.java | 2 +- .../device}/test/util/TestDeviceManager.java | 2 +- .../siddhi/device}/test/util/TestUtils.java | 2 +- .../resources/carbon-home/dbscripts/h2.sql | 0 .../repository/conf/axis2/axis2.xml | 0 .../repository/conf/axis2/axis2_client.xml | 0 .../repository/conf/axis2/tenant-axis2.xml | 0 .../carbon-home/repository/conf/carbon.xml | 0 .../repository/conf/cdm-config.xml | 0 .../conf/datasources/master-datasources.xml | 0 .../conf/etc/bundle-config/README.txt | 0 .../carboncontext-osgi-services.properties | 0 .../repository/conf/etc/config-validation.xml | 0 .../carbon-home/repository/conf/etc/jmx.xml | 0 .../repository/conf/etc/launch.ini | 0 .../conf/etc/logging-bridge.properties | 0 .../repository/conf/etc/mime.mappings | 0 .../repository/conf/etc/mime.types | 0 .../repository/conf/etc/osgi-debug.options | 0 .../repository/conf/log4j.properties | 0 .../carbon-home/repository/conf/registry.xml | 0 .../conf/security/authenticators.xml | 0 .../conf/tomcat/carbon/META-INF/context.xml | 0 .../conf/tomcat/carbon/WEB-INF/web.xml | 0 .../conf/tomcat/catalina-server.xml | 0 .../repository/conf/tomcat/tomcat-users.xml | 0 .../repository/conf/tomcat/web.xml | 0 .../carbon-home/repository/conf/user-mgt.xml | 0 .../config/datasource/data-source-config.xml | 0 .../src/test/resources/log4j.properties | 0 .../src/test/resources/sql/h2.sql | 0 .../src/test/resources/testng.xml | 4 +- .../user-test/user-mgt-registry-test.xml | 0 .../extensions/siddhi-extensions/pom.xml | 2 +- 48 files changed, 884 insertions(+), 97 deletions(-) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/pom.xml (89%) create mode 100644 components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfStatusFunctionExecutor.java create mode 100644 components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfUserFunctionExecutor.java create mode 100644 components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfStatusFunctionExecutor.java create mode 100644 components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfUserFunctionExecutor.java create mode 100644 components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsEnrolledFunctionExecutor.java rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/IsDeviceInGroupFunctionExecutor.java => org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsInGroupFunctionExecutor.java} (83%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/utils/DeviceGroupUtils.java => org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/utils/DeviceUtils.java} (54%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/main/resources/devicegroup.siddhiext => org.wso2.extension.siddhi.device/src/main/resources/device.siddhiext} (53%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device}/BaseDeviceManagementTest.java (96%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/CheckDeviceInGroupExtensionTestCase.java => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/ExtensionTestCase.java} (50%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device}/test/util/DataSourceConfig.java (97%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device}/test/util/SiddhiTestHelper.java (95%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device}/test/util/TestDataHolder.java (97%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device}/test/util/TestDeviceManagementService.java (98%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device}/test/util/TestDeviceManager.java (98%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup => org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device}/test/util/TestUtils.java (98%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/dbscripts/h2.sql (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/carbon.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/cdm-config.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/datasources/master-datasources.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/jmx.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/launch.ini (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/mime.mappings (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/mime.types (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/log4j.properties (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/registry.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/security/authenticators.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/tomcat/web.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/carbon-home/repository/conf/user-mgt.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/config/datasource/data-source-config.xml (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/log4j.properties (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/sql/h2.sql (100%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/testng.xml (83%) rename components/extensions/siddhi-extensions/{org.wso2.extension.siddhi.devicegroup => org.wso2.extension.siddhi.device}/src/test/resources/user-test/user-mgt-registry-test.xml (100%) diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/pom.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/pom.xml similarity index 89% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/pom.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/pom.xml index ba4de2247c..996094ec12 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/pom.xml +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/pom.xml @@ -25,9 +25,9 @@ 4.0.0 - org.wso2.extension.siddhi.devicegroup + org.wso2.extension.siddhi.device bundle - WSO2 Siddhi Execution Extension - Check device belongs to a group + WSO2 Siddhi Execution Extension - Device management Core functionality as Siddhi extension http://wso2.org @@ -51,6 +51,10 @@ log4j log4j + + org.json.wso2 + json + com.h2database.wso2 h2-database-engine @@ -91,16 +95,6 @@ commons-logging-api RELEASE - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.appmgt.mdm.restconnector - 4.0.91-SNAPSHOT - - - asm - asm - RELEASE - asm asm @@ -127,10 +121,11 @@ ${project.artifactId} ${project.artifactId} - org.wso2.extension.siddhi.devicegroup, - org.wso2.extension.siddhi.devicegroup.* + org.wso2.extension.siddhi.device, + org.wso2.extension.siddhi.device.* + org.json;version="${orbit.version.json.range}", org.wso2.siddhi.core.*, org.wso2.siddhi.query.api.*, org.wso2.carbon.device.mgt.core.*, diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfStatusFunctionExecutor.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfStatusFunctionExecutor.java new file mode 100644 index 0000000000..032021890a --- /dev/null +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfStatusFunctionExecutor.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2017, 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.extension.siddhi.device; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONArray; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.extension.siddhi.device.utils.DeviceUtils; +import org.wso2.siddhi.core.config.ExecutionPlanContext; +import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException; +import org.wso2.siddhi.core.executor.ExpressionExecutor; +import org.wso2.siddhi.core.executor.function.FunctionExecutor; +import org.wso2.siddhi.query.api.definition.Attribute; +import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; + +import java.util.List; + +/** + * getDevicesOfStatus(status [, deviceType]) + * Returns devices with specified status + * Accept Type(s): (STRING, STRING) + * Return Type(s): (STRING) + */ +public class GetDevicesOfStatusFunctionExecutor extends FunctionExecutor { + + private static Log log = LogFactory.getLog(GetDevicesOfStatusFunctionExecutor.class); + private Attribute.Type returnType = Attribute.Type.STRING; + + @Override + protected void init(ExpressionExecutor[] attributeExpressionExecutors, + ExecutionPlanContext executionPlanContext) { + if (attributeExpressionExecutors.length != 1 && attributeExpressionExecutors.length != 2) { + throw new ExecutionPlanValidationException( + "Invalid no of arguments passed to device:getDevicesOfStatus() function, required 2 but found " + + attributeExpressionExecutors.length); + } + if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the first argument (status) of device:getDevicesOfStatus() " + + "function, required " + Attribute.Type.STRING + " as status, but found " + + attributeExpressionExecutors[0].getReturnType().toString()); + } + if (attributeExpressionExecutors.length == 2 + && attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the second argument (device type) of device:getDevicesOfStatus() " + + "function, required " + Attribute.Type.STRING + " as device type, but found " + + attributeExpressionExecutors[1].getReturnType().toString()); + } + } + + @Override + protected Object execute(Object[] data) { + if (data[0] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfStatus() function. " + + "First argument cannot be null"); + } + if (data.length == 2 && data[1] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfStatus() function. " + + "Second argument cannot be null"); + } + String status = (String) data[0]; + String deviceType = null; + if (data.length == 2) { + deviceType = (String) data[1]; + } + + JSONArray deviceIds = new JSONArray(); + try { + DeviceManagementProviderService deviceManagementProviderService = DeviceUtils.getDeviceManagementProviderService(); + List devices = deviceManagementProviderService.getDevicesByStatus(EnrolmentInfo.Status.valueOf(status), false); + for (Device device : devices) { + if (deviceType == null || deviceType.equalsIgnoreCase(device.getType())) { + deviceIds.put(device.getDeviceIdentifier()); + } + } + } catch (DeviceManagementException e) { + log.error("Error occurred while getting devices with status " + status, e); + } + return deviceIds.toString(); + } + + @Override + protected Object execute(Object data) { + return execute(new Object[]{data}); + } + + @Override + public void start() { + //Nothing to start + } + + @Override + public void stop() { + //Nothing to stop + } + + @Override + public Attribute.Type getReturnType() { + return returnType; + } + + @Override + public Object[] currentState() { + return null; //No need to maintain a state. + } + + @Override + public void restoreState(Object[] state) { + //Since there's no need to maintain a state, nothing needs to be done here. + } +} diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfUserFunctionExecutor.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfUserFunctionExecutor.java new file mode 100644 index 0000000000..27a82530eb --- /dev/null +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/GetDevicesOfUserFunctionExecutor.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2017, 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.extension.siddhi.device; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONArray; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.extension.siddhi.device.utils.DeviceUtils; +import org.wso2.siddhi.core.config.ExecutionPlanContext; +import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException; +import org.wso2.siddhi.core.executor.ExpressionExecutor; +import org.wso2.siddhi.core.executor.function.FunctionExecutor; +import org.wso2.siddhi.query.api.definition.Attribute; +import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; + +import java.util.List; + +/** + * getDevicesOfUser(user , deviceType [, status]) + * Returns list of ids of devices belongs to a user + * Accept Type(s): (STRING, STRING, STRING) + * Return Type(s): (STRING) + */ +public class GetDevicesOfUserFunctionExecutor extends FunctionExecutor { + + private static Log log = LogFactory.getLog(GetDevicesOfUserFunctionExecutor.class); + private Attribute.Type returnType = Attribute.Type.STRING; + + @Override + protected void init(ExpressionExecutor[] attributeExpressionExecutors, + ExecutionPlanContext executionPlanContext) { + if (attributeExpressionExecutors.length != 2 && attributeExpressionExecutors.length != 3) { + throw new ExecutionPlanValidationException( + "Invalid no of arguments passed to device:getDevicesOfUser() function, minimum 2, or 3 with " + + "optional. but found " + attributeExpressionExecutors.length); + } + if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the first argument (user) of device:getDevicesOfUser() " + + "function, required " + Attribute.Type.STRING + " as user, but found " + + attributeExpressionExecutors[0].getReturnType().toString()); + } + if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the second argument (device type) of device:getDevicesOfUser() " + + "function, required " + Attribute.Type.STRING + " as device type, but found " + + attributeExpressionExecutors[1].getReturnType().toString()); + } + if (attributeExpressionExecutors.length == 3 + && attributeExpressionExecutors[2].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid optional parameter type found for the third argument (status) of " + + "device:getDevicesOfUser() function, required " + Attribute.Type.STRING + " as status, but found " + + attributeExpressionExecutors[2].getReturnType().toString()); + } + } + + @Override + protected Object execute(Object[] data) { + if (data[0] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfUser() function. " + + "First argument cannot be null"); + } + if (data[1] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfUser() function. " + + "Second argument cannot be null"); + } + if (data.length == 3 && data[2] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfUser() function. " + + "Third argument cannot be null"); + } + String user = (String) data[0]; + String deviceType = (String) data[1]; + String status = null; + if (data.length == 3) { + status = (String) data[2]; + } + + JSONArray deviceIds = new JSONArray(); + try { + DeviceManagementProviderService deviceManagementProviderService = DeviceUtils.getDeviceManagementProviderService(); + List devices = deviceManagementProviderService.getDevicesOfUser(user, deviceType, false); + for (Device device : devices) { + if (status == null || status.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) { + deviceIds.put(device.getDeviceIdentifier()); + } + } + } catch (DeviceManagementException e) { + log.error("Error occurred while getting " + deviceType + " devices of user " + user + + ", with status " + status, e); + } + return deviceIds.toString(); + } + + @Override + protected Object execute(Object data) { + return null; //Since the getDevicesOfUser function takes in 2 or 3 parameters, this method does not get called. Hence,not implemented. + } + + @Override + public void start() { + //Nothing to start + } + + @Override + public void stop() { + //Nothing to stop + } + + @Override + public Attribute.Type getReturnType() { + return returnType; + } + + @Override + public Object[] currentState() { + return null; //No need to maintain a state. + } + + @Override + public void restoreState(Object[] state) { + //Since there's no need to maintain a state, nothing needs to be done here. + } +} diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfStatusFunctionExecutor.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfStatusFunctionExecutor.java new file mode 100644 index 0000000000..944394a1b9 --- /dev/null +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfStatusFunctionExecutor.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2017, 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.extension.siddhi.device; + +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.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.extension.siddhi.device.utils.DeviceUtils; +import org.wso2.siddhi.core.config.ExecutionPlanContext; +import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException; +import org.wso2.siddhi.core.executor.ExpressionExecutor; +import org.wso2.siddhi.core.executor.function.FunctionExecutor; +import org.wso2.siddhi.query.api.definition.Attribute; +import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; + +import java.util.List; + +/** + * hasDevicesOfStatus(status [, deviceType]) + * Returns true if there are devices with specified status + * Accept Type(s): (STRING, STRING) + * Return Type(s): (BOOL) + */ +public class HasDevicesOfStatusFunctionExecutor extends FunctionExecutor { + + private static Log log = LogFactory.getLog(HasDevicesOfStatusFunctionExecutor.class); + private Attribute.Type returnType = Attribute.Type.BOOL; + + @Override + protected void init(ExpressionExecutor[] attributeExpressionExecutors, + ExecutionPlanContext executionPlanContext) { + if (attributeExpressionExecutors.length != 1 && attributeExpressionExecutors.length != 2) { + throw new ExecutionPlanValidationException( + "Invalid no of arguments passed to device:hasDevicesOfStatus() function, required 2 but found " + + attributeExpressionExecutors.length); + } + if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the first argument (status) of device:hasDevicesOfStatus() " + + "function, required " + Attribute.Type.STRING + " as status, but found " + + attributeExpressionExecutors[0].getReturnType().toString()); + } + if (attributeExpressionExecutors.length == 2 + && attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the second argument (device type) of device:hasDevicesOfStatus() " + + "function, required " + Attribute.Type.STRING + " as device type, but found " + + attributeExpressionExecutors[1].getReturnType().toString()); + } + } + + @Override + protected Object execute(Object[] data) { + if (data[0] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:hasDevicesOfStatus() function. " + + "First argument cannot be null"); + } + if (data.length == 2 && data[1] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:hasDevicesOfStatus() function. " + + "Second argument cannot be null"); + } + String status = (String) data[0]; + String deviceType = null; + if (data.length == 2) { + deviceType = (String) data[1]; + } + try { + DeviceManagementProviderService deviceManagementProviderService = DeviceUtils.getDeviceManagementProviderService(); + List devices = deviceManagementProviderService.getDevicesByStatus(EnrolmentInfo.Status.valueOf(status), false); + if (deviceType == null) { + return !devices.isEmpty(); + } else { + for (Device device : devices) { + if (deviceType.equalsIgnoreCase(device.getType())) { + return true; + } + } + return false; + } + } catch (DeviceManagementException e) { + log.error("Error occurred while getting devices with status " + status, e); + } + return false; + } + + @Override + protected Object execute(Object data) { + return execute(new Object[]{data}); + } + + @Override + public void start() { + //Nothing to start + } + + @Override + public void stop() { + //Nothing to stop + } + + @Override + public Attribute.Type getReturnType() { + return returnType; + } + + @Override + public Object[] currentState() { + return null; //No need to maintain a state. + } + + @Override + public void restoreState(Object[] state) { + //Since there's no need to maintain a state, nothing needs to be done here. + } +} diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfUserFunctionExecutor.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfUserFunctionExecutor.java new file mode 100644 index 0000000000..ffb72c7f67 --- /dev/null +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/HasDevicesOfUserFunctionExecutor.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2017, 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.extension.siddhi.device; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONArray; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.extension.siddhi.device.utils.DeviceUtils; +import org.wso2.siddhi.core.config.ExecutionPlanContext; +import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException; +import org.wso2.siddhi.core.executor.ExpressionExecutor; +import org.wso2.siddhi.core.executor.function.FunctionExecutor; +import org.wso2.siddhi.query.api.definition.Attribute; +import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; + +import java.util.List; + +/** + * hasDevicesOfUser(user , deviceType [, status]) + * Returns true if there are devices belonging to user + * Accept Type(s): (STRING, STRING, STRING) + * Return Type(s): (BOOL) + */ +public class HasDevicesOfUserFunctionExecutor extends FunctionExecutor { + + private static Log log = LogFactory.getLog(HasDevicesOfUserFunctionExecutor.class); + private Attribute.Type returnType = Attribute.Type.BOOL; + + @Override + protected void init(ExpressionExecutor[] attributeExpressionExecutors, + ExecutionPlanContext executionPlanContext) { + if (attributeExpressionExecutors.length != 2 && attributeExpressionExecutors.length != 3) { + throw new ExecutionPlanValidationException( + "Invalid no of arguments passed to device:getDevicesOfUser() function, minimum 2, or 3 with " + + "optional. but found " + attributeExpressionExecutors.length); + } + if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the first argument (user) of device:getDevicesOfUser() " + + "function, required " + Attribute.Type.STRING + " as user, but found " + + attributeExpressionExecutors[0].getReturnType().toString()); + } + if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the second argument (device type) of device:getDevicesOfUser() " + + "function, required " + Attribute.Type.STRING + " as device type, but found " + + attributeExpressionExecutors[1].getReturnType().toString()); + } + if (attributeExpressionExecutors.length == 3 + && attributeExpressionExecutors[2].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid optional parameter type found for the third argument (status) of " + + "device:getDevicesOfUser() function, required " + Attribute.Type.STRING + " as status, but found " + + attributeExpressionExecutors[2].getReturnType().toString()); + } + } + + @Override + protected Object execute(Object[] data) { + if (data[0] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfUser() function. " + + "First argument cannot be null"); + } + if (data[1] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfUser() function. " + + "Second argument cannot be null"); + } + if (data.length == 3 && data[2] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:getDevicesOfUser() function. " + + "Third argument cannot be null"); + } + String user = (String) data[0]; + String deviceType = (String) data[1]; + String status = null; + if (data.length == 3) { + status = (String) data[2]; + } + + try { + DeviceManagementProviderService deviceManagementProviderService = DeviceUtils.getDeviceManagementProviderService(); + List devices = deviceManagementProviderService.getDevicesOfUser(user, deviceType, false); + if (status == null) { + return !devices.isEmpty(); + } else { + for (Device device : devices) { + if (status.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) { + return true; + } + } + return false; + } + } catch (DeviceManagementException e) { + log.error("Error occurred while getting " + deviceType + " devices of user " + user + + ", with status " + status, e); + } + return false; + } + + @Override + protected Object execute(Object data) { + return null; //Since the getDevicesOfUser function takes in 2 or 3 parameters, this method does not get called. Hence,not implemented. + } + + @Override + public void start() { + //Nothing to start + } + + @Override + public void stop() { + //Nothing to stop + } + + @Override + public Attribute.Type getReturnType() { + return returnType; + } + + @Override + public Object[] currentState() { + return null; //No need to maintain a state. + } + + @Override + public void restoreState(Object[] state) { + //Since there's no need to maintain a state, nothing needs to be done here. + } +} diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsEnrolledFunctionExecutor.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsEnrolledFunctionExecutor.java new file mode 100644 index 0000000000..f1893e33a3 --- /dev/null +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsEnrolledFunctionExecutor.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017, 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.extension.siddhi.device; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; +import org.wso2.extension.siddhi.device.utils.DeviceUtils; +import org.wso2.siddhi.core.config.ExecutionPlanContext; +import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException; +import org.wso2.siddhi.core.executor.ExpressionExecutor; +import org.wso2.siddhi.core.executor.function.FunctionExecutor; +import org.wso2.siddhi.query.api.definition.Attribute; +import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; + +/** + * isEnrolled(deviceId, deviceType) + * Returns true if device enrolled. + * Accept Type(s): (STRING, STRING) + * Return Type(s): (BOOL) + */ +public class IsEnrolledFunctionExecutor extends FunctionExecutor { + + private static Log log = LogFactory.getLog(IsEnrolledFunctionExecutor.class); + private Attribute.Type returnType = Attribute.Type.BOOL; + + @Override + protected void init(ExpressionExecutor[] attributeExpressionExecutors, + ExecutionPlanContext executionPlanContext) { + if (attributeExpressionExecutors.length != 2) { + throw new ExecutionPlanValidationException( + "Invalid no of arguments passed to device:isEnrolled() function, required 2, but found " + + attributeExpressionExecutors.length); + } + if (attributeExpressionExecutors[0].getReturnType()!= Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the first argument (deviceId) of device:isEnrolled() " + + "function, required " + Attribute.Type.STRING + ", but found " + + attributeExpressionExecutors[0].getReturnType().toString()); + } + if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException( + "Invalid parameter type found for the second argument (deviceType) of device:isEnrolled() " + + "function, required " + Attribute.Type.STRING + ", but found " + + attributeExpressionExecutors[1].getReturnType().toString()); + } + } + + @Override + protected Object execute(Object[] data) { + if (data[0] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:isEnrolled() function. " + + "First argument cannot be null"); + } + if (data[1] == null) { + throw new ExecutionPlanRuntimeException("Invalid input given to device:isEnrolled() function. " + + "Second argument cannot be null"); + } + + String deviceId = (String) data[0]; + String deviceType = (String) data[1]; + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType); + try { + DeviceManagementProviderService deviceManagementService = DeviceUtils.getDeviceManagementProviderService(); + return deviceManagementService.isEnrolled(deviceIdentifier); + } catch (DeviceManagementException e) { + log.error("Error occurred while checking device is enrolled.", e); + } + return false; + } + + @Override + protected Object execute(Object data) { + return null; //Since the getDevicesOfUser function takes in 2 parameters, this method does not get called. Hence,not implemented. + } + + @Override + public void start() { + //Nothing to start + } + + @Override + public void stop() { + //Nothing to stop + } + + @Override + public Attribute.Type getReturnType() { + return returnType; + } + + @Override + public Object[] currentState() { + return null; //No need to maintain a state. + } + + @Override + public void restoreState(Object[] state) { + //Since there's no need to maintain a state, nothing needs to be done here. + } +} diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/IsDeviceInGroupFunctionExecutor.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsInGroupFunctionExecutor.java similarity index 83% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/IsDeviceInGroupFunctionExecutor.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsInGroupFunctionExecutor.java index 5072b6385c..56b52ef952 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/IsDeviceInGroupFunctionExecutor.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/IsInGroupFunctionExecutor.java @@ -16,14 +16,14 @@ * under the License. */ -package org.wso2.extension.siddhi.devicegroup; +package org.wso2.extension.siddhi.device; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; -import org.wso2.extension.siddhi.devicegroup.utils.DeviceGroupUtils; +import org.wso2.extension.siddhi.device.utils.DeviceUtils; import org.wso2.siddhi.core.config.ExecutionPlanContext; import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException; import org.wso2.siddhi.core.executor.ExpressionExecutor; @@ -33,14 +33,14 @@ import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; /** - * isDeviceInGroup(deviceId , groupId) + * isInGroup(groupId, deviceId, deviceType) * Returns true if device belongs to group, otherwise false. - * Accept Type(s): (STRING, INTEGER) + * Accept Type(s): (INTEGER, STRING, STRING) * Return Type(s): (BOOL) */ -public class IsDeviceInGroupFunctionExecutor extends FunctionExecutor { +public class IsInGroupFunctionExecutor extends FunctionExecutor { - private static Log log = LogFactory.getLog(IsDeviceInGroupFunctionExecutor.class); + private static Log log = LogFactory.getLog(IsInGroupFunctionExecutor.class); private Attribute.Type returnType = Attribute.Type.BOOL; @Override @@ -48,24 +48,24 @@ public class IsDeviceInGroupFunctionExecutor extends FunctionExecutor { ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 3) { throw new ExecutionPlanValidationException( - "Invalid no of arguments passed to group:isDeviceInGroup() function, required 3, but found " + "Invalid no of arguments passed to device:isInGroup() function, required 3, but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType()!= Attribute.Type.INT) { throw new ExecutionPlanValidationException( - "Invalid parameter type found for the first argument (group id) of group:isDeviceInGroup() " + + "Invalid parameter type found for the first argument (group id) of device:isInGroup() " + "function, required " + Attribute.Type.INT + ", but found " + attributeExpressionExecutors[0].getReturnType().toString()); } if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException( - "Invalid parameter type found for the second argument (device id) of group:isDeviceInGroup() " + + "Invalid parameter type found for the second argument (device id) of device:isInGroup() " + "function, required " + Attribute.Type.STRING + ", but found " + attributeExpressionExecutors[1].getReturnType().toString()); } if (attributeExpressionExecutors[2].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException( - "Invalid parameter type found for the third argument (device type) of group:isDeviceInGroup() " + + "Invalid parameter type found for the third argument (device type) of device:isInGroup() " + "function, required " + Attribute.Type.STRING + ", but found " + attributeExpressionExecutors[2].getReturnType().toString()); } @@ -74,15 +74,15 @@ public class IsDeviceInGroupFunctionExecutor extends FunctionExecutor { @Override protected Object execute(Object[] data) { if (data[0] == null) { - throw new ExecutionPlanRuntimeException("Invalid input given to group:isDeviceInGroup() function. " + + throw new ExecutionPlanRuntimeException("Invalid input given to device:isInGroup() function. " + "First argument cannot be null"); } if (data[1] == null) { - throw new ExecutionPlanRuntimeException("Invalid input given to group:isDeviceInGroup() function. " + + throw new ExecutionPlanRuntimeException("Invalid input given to device:isInGroup() function. " + "Second argument cannot be null"); } if (data[2] == null) { - throw new ExecutionPlanRuntimeException("Invalid input given to group:isDeviceInGroup() function. " + + throw new ExecutionPlanRuntimeException("Invalid input given to device:isInGroup() function. " + "Third argument cannot be null"); } Integer groupId = (Integer) data[0]; @@ -90,7 +90,7 @@ public class IsDeviceInGroupFunctionExecutor extends FunctionExecutor { String deviceType = (String) data[2]; DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType); - GroupManagementProviderService groupManagementService = DeviceGroupUtils.getGroupManagementProviderService(); + GroupManagementProviderService groupManagementService = DeviceUtils.getGroupManagementProviderService(); try { return groupManagementService.isDeviceMappedToGroup(groupId, deviceIdentifier); } catch (GroupManagementException e) { @@ -101,7 +101,7 @@ public class IsDeviceInGroupFunctionExecutor extends FunctionExecutor { @Override protected Object execute(Object data) { - return null; //Since the getProperty function takes in 2 parameters, this method does not get called. Hence,not implemented. + return null; //Since the isInGroup function takes in 3 parameters, this method does not get called. Hence,not implemented. } @Override @@ -129,5 +129,3 @@ public class IsDeviceInGroupFunctionExecutor extends FunctionExecutor { //Since there's no need to maintain a state, nothing needs to be done here. } } - - diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/utils/DeviceGroupUtils.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/utils/DeviceUtils.java similarity index 54% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/utils/DeviceGroupUtils.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/utils/DeviceUtils.java index 700d5fa025..897e026c67 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/java/org/wso2/extension/siddhi/devicegroup/utils/DeviceGroupUtils.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/java/org/wso2/extension/siddhi/device/utils/DeviceUtils.java @@ -15,48 +15,53 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.extension.siddhi.devicegroup.utils; +package org.wso2.extension.siddhi.device.utils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; /** * This class holds utility methods to retrieve data. */ -public class DeviceGroupUtils { +public class DeviceUtils { - private static Log log = LogFactory.getLog(DeviceGroupUtils.class); - private static GroupManagementProviderService groupManagementProviderServiceForTest; + private static Log log = LogFactory.getLog(DeviceUtils.class); + private static DeviceManagementProviderService deviceManagementProviderService; + private static GroupManagementProviderService groupManagementProviderService; - private DeviceGroupUtils(){ + private DeviceUtils(){ + } + public static DeviceManagementProviderService getDeviceManagementProviderService() { + if (deviceManagementProviderService != null) { + return deviceManagementProviderService; + } + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + deviceManagementProviderService = + (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null); + if (deviceManagementProviderService == null) { + String msg = "Device Management service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return deviceManagementProviderService; } public static GroupManagementProviderService getGroupManagementProviderService() { - if (groupManagementProviderServiceForTest != null) { - return groupManagementProviderServiceForTest; + if (groupManagementProviderService != null) { + return groupManagementProviderService; } PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - GroupManagementProviderService groupManagementProviderService = + groupManagementProviderService = (GroupManagementProviderService) ctx.getOSGiService(GroupManagementProviderService.class, null); if (groupManagementProviderService == null) { - String msg = "GroupImpl Management service has not initialized."; + String msg = "Group Management service has not initialized."; log.error(msg); throw new IllegalStateException(msg); } return groupManagementProviderService; } - - /** - * This method is only to set groupManagementProviderService locally for testing as OSGi framework cannot start - * with testng to register the groupManagementProviderService. Hence setting groupManagementProviderService from - * CheckDeviceInGroupExtensionTestCase - * @param groupManagementProviderServiceForTest to be set. - */ - public static void setGroupManagementProviderServiceForTest( - GroupManagementProviderService groupManagementProviderServiceForTest) { - DeviceGroupUtils.groupManagementProviderServiceForTest = groupManagementProviderServiceForTest; - } } diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/resources/devicegroup.siddhiext b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/resources/device.siddhiext similarity index 53% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/resources/devicegroup.siddhiext rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/resources/device.siddhiext index 41eed5053e..84dd50b95f 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/main/resources/devicegroup.siddhiext +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/main/resources/device.siddhiext @@ -6,7 +6,7 @@ # in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# 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 @@ -16,4 +16,9 @@ # under the License. # -isDeviceInGroup=org.wso2.extension.siddhi.devicegroup.IsDeviceInGroupFunctionExecutor +isInGroup=org.wso2.extension.siddhi.device.IsInGroupFunctionExecutor +getDevicesOfUser=org.wso2.extension.siddhi.device.GetDevicesOfUserFunctionExecutor +hasDevicesOfUser=org.wso2.extension.siddhi.device.HasDevicesOfUserFunctionExecutor +getDevicesOfStatus=org.wso2.extension.siddhi.device.GetDevicesOfStatusFunctionExecutor +hasDevicesOfStatus=org.wso2.extension.siddhi.device.HasDevicesOfStatusFunctionExecutor +isEnrolled=org.wso2.extension.siddhi.device.IsEnrolledFunctionExecutor diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/BaseDeviceManagementTest.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/BaseDeviceManagementTest.java similarity index 96% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/BaseDeviceManagementTest.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/BaseDeviceManagementTest.java index 93aac646b5..ce6130c06d 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/BaseDeviceManagementTest.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/BaseDeviceManagementTest.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.extension.siddhi.devicegroup; +package org.wso2.extension.siddhi.device; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,8 +32,8 @@ import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; -import org.wso2.extension.siddhi.devicegroup.test.util.DataSourceConfig; -import org.wso2.extension.siddhi.devicegroup.test.util.TestUtils; +import org.wso2.extension.siddhi.device.test.util.DataSourceConfig; +import org.wso2.extension.siddhi.device.test.util.TestUtils; import javax.sql.DataSource; import javax.xml.bind.JAXBContext; diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/CheckDeviceInGroupExtensionTestCase.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/ExtensionTestCase.java similarity index 50% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/CheckDeviceInGroupExtensionTestCase.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/ExtensionTestCase.java index adb76beb37..801b9e93ab 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/CheckDeviceInGroupExtensionTestCase.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/ExtensionTestCase.java @@ -16,13 +16,12 @@ * under the License. */ -package org.wso2.extension.siddhi.devicegroup; +package org.wso2.extension.siddhi.device; import org.apache.log4j.Logger; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -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; @@ -47,11 +46,11 @@ import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import org.wso2.extension.siddhi.devicegroup.test.util.SiddhiTestHelper; -import org.wso2.extension.siddhi.devicegroup.test.util.TestDataHolder; -import org.wso2.extension.siddhi.devicegroup.test.util.TestDeviceManagementService; -import org.wso2.extension.siddhi.devicegroup.test.util.TestUtils; -import org.wso2.extension.siddhi.devicegroup.utils.DeviceGroupUtils; +import org.wso2.extension.siddhi.device.test.util.SiddhiTestHelper; +import org.wso2.extension.siddhi.device.test.util.TestDataHolder; +import org.wso2.extension.siddhi.device.test.util.TestDeviceManagementService; +import org.wso2.extension.siddhi.device.test.util.TestUtils; +import org.wso2.extension.siddhi.device.utils.DeviceUtils; import org.wso2.siddhi.core.ExecutionPlanRuntime; import org.wso2.siddhi.core.SiddhiManager; import org.wso2.siddhi.core.event.Event; @@ -60,39 +59,56 @@ import org.wso2.siddhi.core.stream.input.InputHandler; import org.wso2.siddhi.core.util.EventPrinter; import java.io.InputStream; +import java.lang.reflect.Field; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import static org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS; import static org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE; -public class CheckDeviceInGroupExtensionTestCase extends BaseDeviceManagementTest { - private static final Logger log = Logger.getLogger(CheckDeviceInGroupExtensionTestCase.class); +public class ExtensionTestCase extends BaseDeviceManagementTest { + private static final Logger log = Logger.getLogger(ExtensionTestCase.class); private AtomicInteger count = new AtomicInteger(0); private volatile boolean eventArrived; private GroupManagementProviderService groupManagementProviderService; - private DeviceManagementProviderService deviceMgtService; + private DeviceManagementProviderService deviceManagementProviderService; private static String DEVICE_TYPE = "Test"; + private QueryCallback queryCallback = new QueryCallback() { + @Override + public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { + EventPrinter.print(timeStamp, inEvents, removeEvents); + for (Event event : inEvents) { + count.incrementAndGet(); + eventArrived = true; + } + } + }; + @BeforeClass @Override public void init() throws Exception { log.info("Initializing"); - count.set(0); - eventArrived = false; groupManagementProviderService = new GroupManagementProviderServiceImpl(); - deviceMgtService = new DeviceManagementProviderServiceImpl(); - DeviceGroupUtils.setGroupManagementProviderServiceForTest(groupManagementProviderService); + deviceManagementProviderService = new DeviceManagementProviderServiceImpl(); DeviceManagementServiceComponent.notifyStartupListeners(); - DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); + DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProviderService); DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService()); DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl()); DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(groupManagementProviderService); DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); - deviceMgtService.registerDeviceType( + deviceManagementProviderService.registerDeviceType( new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); + + Field deviceManagementProviderServiceField = DeviceUtils.class.getDeclaredField("deviceManagementProviderService"); + deviceManagementProviderServiceField.setAccessible(true); + deviceManagementProviderServiceField.set(null, deviceManagementProviderService); + + Field groupManagementProviderServiceField = DeviceUtils.class.getDeclaredField("groupManagementProviderService"); + groupManagementProviderServiceField.setAccessible(true); + groupManagementProviderServiceField.set(null, groupManagementProviderService); } private RegistryService getRegistryService() throws RegistryException, UserStoreException, @@ -119,7 +135,7 @@ public class CheckDeviceInGroupExtensionTestCase extends BaseDeviceManagementTes public void enrollDevice() { Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE); try { - boolean enrollmentStatus = deviceMgtService.enrollDevice(device); + boolean enrollmentStatus = deviceManagementProviderService.enrollDevice(device); Assert.assertTrue(enrollmentStatus); } catch (DeviceManagementException e) { String msg = "Error Occurred while enrolling device"; @@ -140,25 +156,18 @@ public class CheckDeviceInGroupExtensionTestCase extends BaseDeviceManagementTes } @Test(dependsOnMethods = {"addDevices"}) - public void testIsDeviceInGroupExtension() throws InterruptedException, GroupManagementException { - log.info("IsDeviceInGroup TestCase"); + public void testIsInGroupExtension() throws InterruptedException, GroupManagementException { + log.info("IsInGroup TestCase"); SiddhiManager siddhiManager = new SiddhiManager(); + count.set(0); + eventArrived = false; + String inStreamDefinition = "define stream inputStream (groupId int, deviceId string, deviceType string);"; - String query = ("@info(name = 'query1') from inputStream[devicegroup:isDeviceInGroup(groupId, deviceId, deviceType) == true] " + + String query = ("@info(name = 'query1') from inputStream[device:isInGroup(groupId, deviceId, deviceType)] " + "select deviceId insert into outputStream;"); ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(inStreamDefinition + query); - - executionPlanRuntime.addCallback("query1", new QueryCallback() { - @Override - public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { - EventPrinter.print(timeStamp, inEvents, removeEvents); - for (Event event : inEvents) { - count.incrementAndGet(); - eventArrived = true; - } - } - }); + executionPlanRuntime.addCallback("query1", queryCallback); InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream"); executionPlanRuntime.start(); @@ -172,4 +181,101 @@ public class CheckDeviceInGroupExtensionTestCase extends BaseDeviceManagementTes Assert.assertEquals(1, count.get()); executionPlanRuntime.shutdown(); } + + @Test(dependsOnMethods = {"testIsInGroupExtension"}) + public void testGetDevicesOfUserFunctionExecutor() throws InterruptedException, GroupManagementException { + log.info("GetDevicesOfUser without status TestCase"); + SiddhiManager siddhiManager = new SiddhiManager(); + + count.set(0); + eventArrived = false; + + String inStreamDefinition = "define stream inputStream (user string, deviceType string);"; + String query = ("@info(name = 'query1') from inputStream[device:hasDevicesOfUser(user, deviceType)] " + + "select device:getDevicesOfUser(user, deviceType) as devices insert into outputStream;"); + ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(inStreamDefinition + query); + executionPlanRuntime.addCallback("query1", queryCallback); + + InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream"); + executionPlanRuntime.start(); + Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE); + inputHandler.send(new Object[]{device.getEnrolmentInfo().getOwner(), device.getType()}); + SiddhiTestHelper.waitForEvents(100, 1, count, 10000); + Assert.assertTrue(eventArrived); + Assert.assertEquals(1, count.get()); + executionPlanRuntime.shutdown(); + } + + @Test(dependsOnMethods = {"testGetDevicesOfUserFunctionExecutor"}) + public void testGetDevicesOfUserWithStatusFunctionExecutor() throws InterruptedException, GroupManagementException { + log.info("GetDevicesOfUser with status TestCase"); + SiddhiManager siddhiManager = new SiddhiManager(); + + count.set(0); + eventArrived = false; + + String inStreamDefinition = "define stream inputStream (user string, deviceType string, status string);"; + String query = ("@info(name = 'query1') from inputStream[device:hasDevicesOfUser(user, deviceType, status)] " + + "select device:getDevicesOfUser(user, deviceType, status) as devices insert into outputStream;"); + ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(inStreamDefinition + query); + executionPlanRuntime.addCallback("query1", queryCallback); + + InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream"); + executionPlanRuntime.start(); + Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE); + inputHandler.send(new Object[]{device.getEnrolmentInfo().getOwner(), device.getType(), + device.getEnrolmentInfo().getStatus().toString()}); + SiddhiTestHelper.waitForEvents(100, 1, count, 10000); + Assert.assertTrue(eventArrived); + Assert.assertEquals(1, count.get()); + executionPlanRuntime.shutdown(); + } + + @Test(dependsOnMethods = {"testGetDevicesOfUserWithStatusFunctionExecutor"}) + public void testGetDevicesOfStatusFunctionExecutor() throws InterruptedException, GroupManagementException { + log.info("GetDevicesOfStatus without deviceType TestCase"); + SiddhiManager siddhiManager = new SiddhiManager(); + + count.set(0); + eventArrived = false; + + String inStreamDefinition = "define stream inputStream (status string);"; + String query = ("@info(name = 'query1') from inputStream[device:hasDevicesOfStatus(status)] " + + "select device:getDevicesOfStatus(status) as devices insert into outputStream;"); + ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(inStreamDefinition + query); + executionPlanRuntime.addCallback("query1", queryCallback); + + InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream"); + executionPlanRuntime.start(); + Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE); + inputHandler.send(new Object[]{device.getEnrolmentInfo().getStatus().toString()}); + SiddhiTestHelper.waitForEvents(100, 1, count, 10000); + Assert.assertTrue(eventArrived); + Assert.assertEquals(1, count.get()); + executionPlanRuntime.shutdown(); + } + + @Test(dependsOnMethods = {"testGetDevicesOfStatusFunctionExecutor"}) + public void testGetDevicesOfStatusWithTypeFunctionExecutor() throws InterruptedException, GroupManagementException { + log.info("GetDevicesOfStatus with deviceType TestCase"); + SiddhiManager siddhiManager = new SiddhiManager(); + + count.set(0); + eventArrived = false; + + String inStreamDefinition = "define stream inputStream (status string, deviceType string);"; + String query = ("@info(name = 'query1') from inputStream[device:hasDevicesOfStatus(status, deviceType)] " + + "select device:getDevicesOfStatus(status, deviceType) as devices insert into outputStream;"); + ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(inStreamDefinition + query); + executionPlanRuntime.addCallback("query1", queryCallback); + + InputHandler inputHandler = executionPlanRuntime.getInputHandler("inputStream"); + executionPlanRuntime.start(); + Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE); + inputHandler.send(new Object[]{device.getEnrolmentInfo().getStatus().toString(), device.getType()}); + SiddhiTestHelper.waitForEvents(100, 1, count, 10000); + Assert.assertTrue(eventArrived); + Assert.assertEquals(1, count.get()); + executionPlanRuntime.shutdown(); + } } diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/DataSourceConfig.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/DataSourceConfig.java similarity index 97% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/DataSourceConfig.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/DataSourceConfig.java index 74cc58aefb..f787d9b221 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/DataSourceConfig.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/DataSourceConfig.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.extension.siddhi.devicegroup.test.util; +package org.wso2.extension.siddhi.device.test.util; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/SiddhiTestHelper.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/SiddhiTestHelper.java similarity index 95% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/SiddhiTestHelper.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/SiddhiTestHelper.java index 7b0801d57e..820cbf1545 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/SiddhiTestHelper.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/SiddhiTestHelper.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.extension.siddhi.devicegroup.test.util; +package org.wso2.extension.siddhi.device.test.util; import java.util.concurrent.atomic.AtomicInteger; diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDataHolder.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDataHolder.java similarity index 97% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDataHolder.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDataHolder.java index 67c2f774eb..6c2fe832ff 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDataHolder.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDataHolder.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.wso2.extension.siddhi.devicegroup.test.util; +package org.wso2.extension.siddhi.device.test.util; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -45,7 +45,7 @@ public class TestDataHolder { enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); enrolmentInfo.setOwner(OWNER); enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); - enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED); + enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); device.setEnrolmentInfo(enrolmentInfo); device.setDescription("Test Description"); device.setDeviceIdentifier(initialDeviceIdentifier); diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDeviceManagementService.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManagementService.java similarity index 98% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDeviceManagementService.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManagementService.java index 758facbb46..f1631b747f 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDeviceManagementService.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManagementService.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.extension.siddhi.devicegroup.test.util; +package org.wso2.extension.siddhi.device.test.util; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDeviceManager.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java similarity index 98% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDeviceManager.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java index eb6871ba82..7a152b9a37 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestDeviceManager.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.wso2.extension.siddhi.devicegroup.test.util; +package org.wso2.extension.siddhi.device.test.util; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestUtils.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestUtils.java similarity index 98% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestUtils.java rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestUtils.java index 29a46fe16c..20ed04dae6 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/java/org/wso2/extension/siddhi/devicegroup/test/util/TestUtils.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestUtils.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.extension.siddhi.devicegroup.test.util; +package org.wso2.extension.siddhi.device.test.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/dbscripts/h2.sql b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/dbscripts/h2.sql similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/dbscripts/h2.sql rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/dbscripts/h2.sql diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/carbon.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/carbon.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/carbon.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/cdm-config.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/cdm-config.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/cdm-config.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/datasources/master-datasources.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/datasources/master-datasources.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/datasources/master-datasources.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/datasources/master-datasources.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/jmx.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/jmx.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/jmx.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/jmx.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/launch.ini b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/launch.ini similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/launch.ini rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/launch.ini diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/mime.mappings b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/mime.mappings similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/mime.mappings rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/mime.mappings diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/mime.types b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/mime.types similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/mime.types rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/mime.types diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/log4j.properties b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/log4j.properties similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/log4j.properties rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/log4j.properties diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/registry.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/registry.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/registry.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/registry.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/security/authenticators.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/security/authenticators.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/security/authenticators.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/security/authenticators.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/web.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/web.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/tomcat/web.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/tomcat/web.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/user-mgt.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/user-mgt.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/carbon-home/repository/conf/user-mgt.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/carbon-home/repository/conf/user-mgt.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/config/datasource/data-source-config.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/config/datasource/data-source-config.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/config/datasource/data-source-config.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/config/datasource/data-source-config.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/log4j.properties b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/log4j.properties similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/log4j.properties rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/log4j.properties diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/sql/h2.sql b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/sql/h2.sql similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/sql/h2.sql rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/sql/h2.sql diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/testng.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/testng.xml similarity index 83% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/testng.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/testng.xml index 01419c74c5..a2e39e52ee 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/testng.xml +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/testng.xml @@ -24,8 +24,8 @@ - - + + diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/user-test/user-mgt-registry-test.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/user-test/user-mgt-registry-test.xml similarity index 100% rename from components/extensions/siddhi-extensions/org.wso2.extension.siddhi.devicegroup/src/test/resources/user-test/user-mgt-registry-test.xml rename to components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/user-test/user-mgt-registry-test.xml diff --git a/components/extensions/siddhi-extensions/pom.xml b/components/extensions/siddhi-extensions/pom.xml index efa6a77776..c29d825b99 100644 --- a/components/extensions/siddhi-extensions/pom.xml +++ b/components/extensions/siddhi-extensions/pom.xml @@ -33,7 +33,7 @@ http://wso2.org - org.wso2.extension.siddhi.devicegroup + org.wso2.extension.siddhi.device org.wso2.extension.siddhi.execution.json org.wso2.gpl.siddhi.extension.geo.script From 69b1102ee2f11b3d0a7c3b350c9805ed4ac23800 Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 17 Nov 2017 12:55:14 +0530 Subject: [PATCH 2/4] Add siddhi extensions to reflect get methods in device management core service --- .../pom.xml | 8 ++++---- features/extensions-feature/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename features/extensions-feature/{org.wso2.extension.siddhi.devicegroup.feature => org.wso2.extension.siddhi.device.feature}/pom.xml (92%) diff --git a/features/extensions-feature/org.wso2.extension.siddhi.devicegroup.feature/pom.xml b/features/extensions-feature/org.wso2.extension.siddhi.device.feature/pom.xml similarity index 92% rename from features/extensions-feature/org.wso2.extension.siddhi.devicegroup.feature/pom.xml rename to features/extensions-feature/org.wso2.extension.siddhi.device.feature/pom.xml index 5f5d31507c..50aeb0941b 100644 --- a/features/extensions-feature/org.wso2.extension.siddhi.devicegroup.feature/pom.xml +++ b/features/extensions-feature/org.wso2.extension.siddhi.device.feature/pom.xml @@ -24,7 +24,7 @@ ../pom.xml - org.wso2.extension.siddhi.devicegroup.feature + org.wso2.extension.siddhi.device.feature pom WSO2 Siddhi Execution Extension - Device Group Feature http://wso2.org @@ -33,7 +33,7 @@ org.wso2.carbon.devicemgt-plugins - org.wso2.extension.siddhi.devicegroup + org.wso2.extension.siddhi.device @@ -51,7 +51,7 @@ p2-feature-gen - org.wso2.extension.siddhi.devicegroup + org.wso2.extension.siddhi.device ../../etc/feature.properties @@ -61,7 +61,7 @@ - org.wso2.carbon.devicemgt-plugins:org.wso2.extension.siddhi.devicegroup:${carbon.devicemgt.plugins.version} + org.wso2.carbon.devicemgt-plugins:org.wso2.extension.siddhi.device:${carbon.devicemgt.plugins.version} diff --git a/features/extensions-feature/pom.xml b/features/extensions-feature/pom.xml index f919f23f76..970b76db8a 100644 --- a/features/extensions-feature/pom.xml +++ b/features/extensions-feature/pom.xml @@ -39,7 +39,7 @@ org.wso2.carbon.device.mgt.adapter.feature org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature org.wso2.carbon.andes.extensions.device.mgt.api.feature - org.wso2.extension.siddhi.devicegroup.feature + org.wso2.extension.siddhi.device.feature org.wso2.extension.siddhi.execution.json.feature org.wso2.carbon.device.mgt.notification.listener.feature org.wso2.gpl.siddhi.extension.geo.script.feature diff --git a/pom.xml b/pom.xml index fff364f81e..792a61d4fe 100644 --- a/pom.xml +++ b/pom.xml @@ -412,7 +412,7 @@ org.wso2.carbon.devicemgt-plugins - org.wso2.extension.siddhi.devicegroup + org.wso2.extension.siddhi.device ${carbon.devicemgt.plugins.version} From 5f4bada92a36fe21729ff9a7e8769075b58eb5a0 Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 17 Nov 2017 12:56:27 +0530 Subject: [PATCH 3/4] Add improvments to oauth-http publisher to work with url templates --- ...SO2IoT-DeviceOperation-Publisher_1.0.0.xml | 20 ++++++------- .../org.wso2.iot.operation_1.0.0.json | 8 +++-- .../output/adapter/http/HTTPEventAdapter.java | 30 +++++++++++++++++++ .../adapter/http/HTTPEventAdapterFactory.java | 7 +++++ .../http/util/HTTPEventAdapterConstants.java | 2 ++ .../adapter/http/i18n/Resources.properties | 2 ++ 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/WSO2IoT-DeviceOperation-Publisher_1.0.0/WSO2IoT-DeviceOperation-Publisher_1.0.0.xml b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/WSO2IoT-DeviceOperation-Publisher_1.0.0/WSO2IoT-DeviceOperation-Publisher_1.0.0.xml index 326925a9b0..7d52806b57 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/WSO2IoT-DeviceOperation-Publisher_1.0.0/WSO2IoT-DeviceOperation-Publisher_1.0.0.xml +++ b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/WSO2IoT-DeviceOperation-Publisher_1.0.0/WSO2IoT-DeviceOperation-Publisher_1.0.0.xml @@ -19,24 +19,24 @@ - + { - "deviceIdentifiers": [ - {{meta_deviceIdentifier}} - ], + "deviceIdentifiers": {{meta_deviceIdentifiers}}, + "deviceType": "{{meta_deviceType}}", "operation": { - "code": {{code}}, - "type": {{type}}, + "code": "{{code}}", + "type": "{{type}}", "status": "PENDING", - "isEnabled": {{isEnabled}}, - "payLoad": {{payLoad}} + "isEnabled": "{{isEnabled}}", + "payLoad": "{{payLoad}}" } } HttpPost - https://localhost:9443/api/device-mgt/v1.0/devices/android/operations + https://localhost:9443/api/device-mgt/v1.0/devices/{deviceType}/operations + true - \ No newline at end of file + diff --git a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/org.wso2.iot.operation_1.0.0/org.wso2.iot.operation_1.0.0.json b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/org.wso2.iot.operation_1.0.0/org.wso2.iot.operation_1.0.0.json index 44a0b0a453..c5786c0daa 100755 --- a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/org.wso2.iot.operation_1.0.0/org.wso2.iot.operation_1.0.0.json +++ b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/device_analytics/org.wso2.iot.operation_1.0.0/org.wso2.iot.operation_1.0.0.json @@ -1,11 +1,15 @@ { "name": "org.wso2.iot.operation", "version": "1.0.0", - "nickName": "", + "nickName": "Operation Stream", "description": "Operation stream for WSO2 IoT Devices", "metaData": [ { - "name": "deviceIdentifier", + "name": "deviceIdentifiers", + "type": "STRING" + }, + { + "name": "deviceType", "type": "STRING" } ], diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java index a37f49b71b..b93074c722 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java @@ -59,13 +59,17 @@ import java.net.UnknownHostException; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class HTTPEventAdapter implements OutputEventAdapter { @@ -181,6 +185,32 @@ public class HTTPEventAdapter implements OutputEventAdapter { .extractHeaders(dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_HEADERS)); String payload = message.toString(); + if ("true".equals(dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED))) { + try { + JSONParser jsonParser = new JSONParser(); + JSONObject jsonPayload = (JSONObject) jsonParser.parse(payload); + + List matchList = new ArrayList<>(); + Pattern regex = Pattern.compile("\\{(.*?)\\}"); + Matcher regexMatcher = regex.matcher(url); + + while (regexMatcher.find()) {//Finds Matching Pattern in String + matchList.add(regexMatcher.group(1));//Fetching Group from String + } + + for(String str:matchList) { + if (jsonPayload.containsKey(str)) { + url = url.replace("{" + str + "}", jsonPayload.get(str).toString()); + } + } + if (log.isDebugEnabled()) { + log.debug("Modified url: " + url); + } + } catch (ParseException e) { + log.error("Unable to parse request body to Json.", e); + } + } + try { executorService.submit(new HTTPSender(url, payload, headers, httpClient)); } catch (RejectedExecutionException e) { diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapterFactory.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapterFactory.java index 0aad85489a..e5450ebfc0 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapterFactory.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapterFactory.java @@ -76,6 +76,12 @@ public class HTTPEventAdapterFactory extends OutputEventAdapterFactory { urlProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_HINT)); urlProp.setRequired(true); + Property urlTemplateProp = new Property(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED); + urlTemplateProp.setDisplayName(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED)); + urlTemplateProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED_HINT)); + urlTemplateProp.setRequired(true); + urlTemplateProp.setOptions(new String[]{"true", "false"}); + Property usernameProp = new Property(HTTPEventAdapterConstants.ADAPTER_USERNAME); usernameProp.setDisplayName(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_USERNAME)); usernameProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_USERNAME_HINT)); @@ -94,6 +100,7 @@ public class HTTPEventAdapterFactory extends OutputEventAdapterFactory { headersProp.setRequired(false); dynamicPropertyList.add(urlProp); + dynamicPropertyList.add(urlTemplateProp); dynamicPropertyList.add(usernameProp); dynamicPropertyList.add(passwordProp); dynamicPropertyList.add(headersProp); diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/util/HTTPEventAdapterConstants.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/util/HTTPEventAdapterConstants.java index 212afe7367..296f51aa28 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/util/HTTPEventAdapterConstants.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/util/HTTPEventAdapterConstants.java @@ -21,6 +21,8 @@ public class HTTPEventAdapterConstants { public static final String ADAPTER_TYPE_HTTP = "oauth-http"; public static final String ADAPTER_MESSAGE_URL = "http.url"; + public static final String ADAPTER_MESSAGE_URL_TEMPLATED = "http.url.templated"; + public static final String ADAPTER_MESSAGE_URL_TEMPLATED_HINT = "http.url.templated.hint"; public static final String ADAPTER_MESSAGE_URL_HINT = "http.url.hint"; public static final String ADAPTER_CONF_DCR_URL = "dcrUrl"; public static final String ADAPTER_CONF_TOKEN_URL = "tokenUrl"; diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/resources/org/wso2/carbon/device/mgt/output/adapter/http/i18n/Resources.properties b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/resources/org/wso2/carbon/device/mgt/output/adapter/http/i18n/Resources.properties index 0ceb2d520a..a31fefd0ec 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/resources/org/wso2/carbon/device/mgt/output/adapter/http/i18n/Resources.properties +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/resources/org/wso2/carbon/device/mgt/output/adapter/http/i18n/Resources.properties @@ -18,6 +18,8 @@ http.url=URL http.url.hint=The target HTTP/HTTPS URL, e.g. "http://yourhost:8080/service (URL will auto format for tenants)" +http.url.templated=URL Templated +http.url.templated.hint=The target HTTP/HTTPS URL has template value(s) to fill from event. e.g. "http://yourhost:8080/service/{variable1}/{variable2}" variable1 & variable2 should be available in the event and event should be in json format username=Username http.username.hint=Username to obtain oauth token. Leave empty to use default. password=Password From f790b13baad6edae2422b6f938653d2af2c5f69f Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 17 Nov 2017 13:39:33 +0530 Subject: [PATCH 4/4] Bump device mgt version latest --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8f1a88ad00..a158e7f2ad 100644 --- a/pom.xml +++ b/pom.xml @@ -1210,7 +1210,7 @@ 1.1.1 - 3.0.172 + 3.0.175 [3.0.0, 4.0.0)