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