();
- private static final String DEVICEMGT_JAGGERY_APP_PATH = CarbonUtils.getCarbonRepository() + File.separator
- + "jaggeryapps" + File.separator + "devicemgt" + File.separator + "app" + File.separator + "units"
- + File.separator;
-
- private static final String UNIT_PREFIX = "cdmf.unit.device.type";
-
- @Override
- public void init(ConfigurationContext configurationContext) {
- }
-
- @Override
- public void setDirectory(String s) {
-
- }
-
- @Override
- public void setExtension(String s) {
-
- }
-
- @Override
- public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
- if (!deploymentFileData.getFile().isDirectory()) {
- return;
- }
- String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
- if (tenantDomain != null && !tenantDomain.isEmpty()) {
- File jaggeryAppPath = new File(
- DEVICEMGT_JAGGERY_APP_PATH + tenantDomain + "." + deploymentFileData.getName());
- try {
- if (!jaggeryAppPath.exists()) {
- FileUtils.forceMkdir(jaggeryAppPath);
- FileUtils.copyDirectory(deploymentFileData.getFile(), jaggeryAppPath);
- File[] listOfFiles = jaggeryAppPath.listFiles();
-
- for (int i = 0; i < listOfFiles.length; i++) {
- if (listOfFiles[i].isFile()) {
- String content = FileUtils.readFileToString(listOfFiles[i]);
- FileUtils.writeStringToFile(listOfFiles[i], content.replaceAll(UNIT_PREFIX
- , tenantDomain + "." + UNIT_PREFIX));
- }
- }
- } else {
- log.debug("units already exists " + deploymentFileData.getName());
- }
- this.deviceTypeDeployedUIMap.put(deploymentFileData.getAbsolutePath(),
- jaggeryAppPath.getAbsolutePath());
- } catch (IOException e) {
- if (jaggeryAppPath.exists()) {
- try {
- FileUtils.deleteDirectory(jaggeryAppPath);
- } catch (IOException e1) {
- log.error("Failed to delete directory " + jaggeryAppPath.getAbsolutePath());
- }
- }
- log.error("Cannot deploy deviceType ui : " + deploymentFileData.getName(), e);
- throw new DeploymentException(
- "Device type ui file " + deploymentFileData.getName() + " is not deployed ", e);
- }
-
- } else {
- log.error("Cannot deploy deviceType ui: " + deploymentFileData.getName());
- }
-
-
- }
-
- @Override
- public void undeploy(String filePath) throws DeploymentException {
- try {
- String jaggeryUnitPath = this.deviceTypeDeployedUIMap.remove(filePath);
- FileUtils.deleteDirectory(new File(jaggeryUnitPath));
- log.info("Device Type units un deployed successfully.");
- } catch (IOException e) {
- throw new DeploymentException("Failed to remove the units: " + filePath);
- }
- }
-
-}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java
deleted file mode 100644
index be089a9ccc..0000000000
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
- *
- * WSO2 Inc. licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.annotation.XmlElementDecl;
-import javax.xml.bind.annotation.XmlRegistry;
-import javax.xml.namespace.QName;
-
-
-/**
- * This object contains factory methods for each
- * Java content interface and Java element interface
- * generated in the org.wso2.carbon package.
- * An ObjectFactory allows you to programatically
- * construct new instances of the Java representation
- * for XML content. The Java representation of XML
- * content can consist of schema derived interfaces
- * and classes representing the binding of schema
- * type definitions, element declarations and model
- * groups. Factory methods for each of these are
- * provided in this class.
- *
- */
-@XmlRegistry
-public class ObjectFactory {
-
- private final static QName _DeviceTypeConfiguration_QNAME = new QName("", "DeviceTypeConfiguration");
-
- /**
- * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.wso2.carbon
- *
- */
- public ObjectFactory() {
- }
-
- /**
- * Create an instance of {@link DeviceTypeConfiguration }
- *
- */
- public DeviceTypeConfiguration createDeviceTypeConfiguration() {
- return new DeviceTypeConfiguration();
- }
-
- /**
- * Create an instance of {@link Operation }
- *
- */
- public Operation createOperation() {
- return new Operation();
- }
-
- /**
- * Create an instance of {@link Attributes }
- *
- */
- public Attributes createAttributes() {
- return new Attributes();
- }
-
- /**
- * Create an instance of {@link ProvisioningConfig }
- *
- */
- public ProvisioningConfig createProvisioningConfig() {
- return new ProvisioningConfig();
- }
-
- /**
- * Create an instance of {@link TableConfig }
- *
- */
- public TableConfig createTableConfig() {
- return new TableConfig();
- }
-
- /**
- * Create an instance of {@link Table }
- *
- */
- public Table createTable() {
- return new Table();
- }
-
- /**
- * Create an instance of {@link Property }
- *
- */
- public Property createProperty() {
- return new Property();
- }
-
- /**
- * Create an instance of {@link JndiConfig }
- *
- */
- public JndiConfig createJndiConfig() {
- return new JndiConfig();
- }
-
- /**
- * Create an instance of {@link FormParameters }
- *
- */
- public FormParameters createFormParameters() {
- return new FormParameters();
- }
-
- /**
- * Create an instance of {@link Features }
- *
- */
- public Features createFeatures() {
- return new Features();
- }
-
- /**
- * Create an instance of {@link Feature }
- *
- */
- public Feature createFeature() {
- return new Feature();
- }
-
- /**
- * Create an instance of {@link PushNotificationProvider }
- *
- */
- public PushNotificationProvider createPushNotificationProvider() {
- return new PushNotificationProvider();
- }
-
- /**
- * Create an instance of {@link DataSource }
- *
- */
- public DataSource createDataSource() {
- return new DataSource();
- }
-
- /**
- * Create an instance of {@link ConfigProperties }
- *
- */
- public ConfigProperties createConfigProperties() {
- return new ConfigProperties();
- }
-
- /**
- * Create an instance of {@link License }
- *
- */
- public License createLicense() {
- return new License();
- }
-
- /**
- * Create an instance of {@link DeviceDetails }
- *
- */
- public DeviceDetails createDeviceDetails() {
- return new DeviceDetails();
- }
-
- /**
- * Create an instance of {@link QueryParameters }
- *
- */
- public QueryParameters createQueryParameters() {
- return new QueryParameters();
- }
-
- /**
- * Create an instance of {@link JAXBElement }{@code <}{@link DeviceTypeConfiguration }{@code >}}
- *
- */
- @XmlElementDecl(namespace = "", name = "DeviceTypeConfiguration")
- public JAXBElement createDeviceTypeConfiguration(DeviceTypeConfiguration value) {
- return new JAXBElement(_DeviceTypeConfiguration_QNAME, DeviceTypeConfiguration.class, null, value);
- }
-
-}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java
index 9c7d771c11..88761df2e1 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java
@@ -28,7 +28,7 @@ import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.utils.ConfigurationContextService;
/**
- * @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeManagementServiceComponent"
+ * @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeExtensionServiceComponent"
* immediate="true"
* @scr.reference name="config.context.service"
* interface="org.wso2.carbon.utils.ConfigurationContextService"
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java
index 495a72b48d..4611deb8f3 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java
@@ -19,7 +19,7 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
import org.w3c.dom.Document;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java
index 290fe93b7b..8b8ad98cf2 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java
@@ -22,9 +22,6 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
* This holds the constants used for this bundle.
*/
public class DeviceTypePluginConstants {
- public static final String MEDIA_TYPE_XML = "application/xml";
- public static final String CHARSET_UTF8 = "UTF8";
- public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
public static final String CDMF_UI_TYPE = "devicetype/ui";
public static final String CDMF_UI_TYPE_DIR = "devicetypes-ui";
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml
deleted file mode 100644
index a4a89876ae..0000000000
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml
+++ /dev/null
@@ -1,152 +0,0 @@
-
-
-
-
-
-
-
-
-
- abc
- this is a feature
-
-
- deviceId
-
-
- test
-
-
-
-
-
-
-
-
-
- temperature sensor fitted
- org.wso2.temperature.stream
- this is a sensor
-
- celcius
- atmeggga11234
-
-
-
- temperature sensor fitted
- org.wso2.temperature.stream
- this is a sensor
-
- celcius
-
-
-
-
-
-
-
-
- false
-
-
-
- true
-
-
-
- true
-
-
- sample.mqtt.adapter
- tcp://localhost:1883
- admin
- admin
- 0
-
- true
-
-
-
-
-
-
- en_US
- 1.0.0
- This is license text
-
-
-
- true
- 600000
-
-
- DEVICE_INFO
- 1
-
-
- APPLICATION_LIST
- 5
-
-
- DEVICE_LOCATION
- 1
-
-
-
-
-
-
- jdbc/SampleDM_DB
-
-
-
- SAMPLE_DEVICE_ID
-
- column1
- column2
-
-
-
-
-
-
-
- DEVICE_INFO
- APPLICATION_LIST
- DEVICE_LOCATION
-
-
-
-
-
- false
- 300
- 600
- 300
-
-
\ No newline at end of file
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml
new file mode 100644
index 0000000000..d8eb4557b7
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+ device-mgt-extensions
+ org.wso2.carbon.devicemgt
+ 3.0.9-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.pull.notification
+ bundle
+ WSO2 Carbon - Pull Notification Provider Implementation
+ WSO2 Carbon - Pull Notification Provider Implementation
+ http://wso2.org
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.policy.mgt.core
+
+
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ Pull Notification Provider Bundle
+
+ !org.wso2.carbon.device.mgt.extensions.pull.notification.internal,
+ org.wso2.carbon.device.mgt.extensions.pull.notification.*
+
+
+ org.osgi.framework,
+ org.osgi.service.component,
+ org.apache.commons.logging,
+ org.wso2.carbon.device.mgt.common.*,
+ org.wso2.carbon.device.mgt.core.service
+ org.wso2.carbon.policy.mgt.core.*,
+ org.wso2.carbon.policy.mgt.core,
+ com.google.gson,
+ org.wso2.carbon.device.mgt.core.service.*
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/PullNotificationSubscriberImpl.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/PullNotificationSubscriberImpl.java
new file mode 100644
index 0000000000..bcf8dece8a
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/PullNotificationSubscriberImpl.java
@@ -0,0 +1,102 @@
+/*
+ * 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.carbon.device.mgt.extensions.pull.notification;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+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.operation.mgt.Operation;
+import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
+import org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationDataHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class PullNotificationSubscriberImpl implements PullNotificationSubscriber {
+
+ public final class OperationCodes {
+ private OperationCodes() {
+ throw new AssertionError();
+ }
+ public static final String POLICY_MONITOR = "POLICY_MONITOR";
+ }
+
+
+ private static final Log log = LogFactory.getLog(PullNotificationSubscriberImpl.class);
+
+ public void init(Map properties) {
+
+ }
+
+ @Override
+ public void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException {
+ try {
+ if (!Operation.Status.ERROR.equals(operation.getStatus()) && operation.getCode() != null &&
+ OperationCodes.POLICY_MONITOR.equals(operation.getCode())) {
+ if (log.isDebugEnabled()) {
+ log.info("Received compliance status from POLICY_MONITOR operation ID: " + operation.getId());
+ }
+ List features = getComplianceFeatures(operation.getPayLoad());
+ PullNotificationDataHolder.getInstance().getPolicyManagerService()
+ .checkCompliance(deviceIdentifier, features);
+
+ } else {
+ PullNotificationDataHolder.getInstance().getDeviceManagementProviderService().updateOperation(
+ deviceIdentifier, operation);
+ }
+ } catch (OperationManagementException e) {
+ throw new PullNotificationExecutionFailedException(e);
+ } catch (PolicyComplianceException e) {
+ throw new PullNotificationExecutionFailedException("Invalid payload format compliant feature", e);
+ }
+ }
+
+ public void clean() {
+
+ }
+
+ private static List getComplianceFeatures(Object compliancePayload) throws
+ PolicyComplianceException {
+ String compliancePayloadString = new Gson().toJson(compliancePayload);
+ if (compliancePayload == null) {
+ return null;
+ }
+ // Parsing json string to get compliance features.
+ JsonElement jsonElement = new JsonParser().parse(compliancePayloadString);
+ JsonArray jsonArray = jsonElement.getAsJsonArray();
+ Gson gson = new Gson();
+ ComplianceFeature complianceFeature;
+ List complianceFeatures = new ArrayList(jsonArray.size());
+
+ for (JsonElement element : jsonArray) {
+ complianceFeature = gson.fromJson(element, ComplianceFeature.class);
+ complianceFeatures.add(complianceFeature);
+ }
+ return complianceFeatures;
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationDataHolder.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationDataHolder.java
new file mode 100644
index 0000000000..a9f7888c43
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationDataHolder.java
@@ -0,0 +1,50 @@
+/*
+ * 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.carbon.device.mgt.extensions.pull.notification.internal;
+
+import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
+import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
+
+public class PullNotificationDataHolder {
+
+ private DeviceManagementProviderService deviceManagementProviderService;
+ private PolicyManagerService policyManagerService;
+
+ private static PullNotificationDataHolder thisInstance = new PullNotificationDataHolder();
+
+ public static PullNotificationDataHolder getInstance() {
+ return thisInstance;
+ }
+
+ public DeviceManagementProviderService getDeviceManagementProviderService() {
+ return deviceManagementProviderService;
+ }
+
+ public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ this.deviceManagementProviderService = deviceManagementProviderService;
+ }
+
+ public PolicyManagerService getPolicyManagerService() {
+ return policyManagerService;
+ }
+
+ public void setPolicyManagerService(PolicyManagerService policyManagerService) {
+ this.policyManagerService = policyManagerService;
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationServiceComponent.java
new file mode 100644
index 0000000000..351e514706
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationServiceComponent.java
@@ -0,0 +1,80 @@
+/*
+ * 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.carbon.device.mgt.extensions.pull.notification.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
+import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
+
+/**
+ * @scr.component name="org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationServiceComponent" immediate="true"
+ * @scr.reference name="carbon.device.mgt.provider"
+ * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setDeviceManagementProviderService"
+ * unbind="unsetDeviceManagementProviderService"
+ * @scr.reference name="org.wso2.carbon.policy.mgt.core"
+ * interface="org.wso2.carbon.policy.mgt.core.PolicyManagerService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setPolicyManagerService"
+ * unbind="unsetPolicyManagerService"
+ */
+public class PullNotificationServiceComponent {
+
+ private static final Log log = LogFactory.getLog(PullNotificationServiceComponent.class);
+
+ @SuppressWarnings("unused")
+ protected void activate(ComponentContext componentContext) {
+ try {
+ //Do nothing
+ if (log.isDebugEnabled()) {
+ log.debug("pull notification provider implementation bundle has been successfully " +
+ "initialized");
+ }
+ } catch (Throwable e) {
+ log.error("Error occurred while initializing pull notification provider " +
+ "implementation bundle", e);
+ }
+ }
+
+ protected void deactivate(ComponentContext componentContext) {
+ //Do nothing
+ }
+
+ protected void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ PullNotificationDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
+ }
+
+ protected void unsetDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ PullNotificationDataHolder.getInstance().setDeviceManagementProviderService(null);
+ }
+
+ protected void setPolicyManagerService(PolicyManagerService policyManagerService) {
+ PullNotificationDataHolder.getInstance().setPolicyManagerService(policyManagerService);
+ }
+
+ protected void unsetPolicyManagerService(PolicyManagerService policyManagerService) {
+ PullNotificationDataHolder.getInstance().setPolicyManagerService(null);
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
index 5e08377cd7..73b0c3e456 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
new file mode 100644
index 0000000000..1fe5b6451e
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
@@ -0,0 +1,147 @@
+
+
+
+
+
+
+ device-mgt-extensions
+ org.wso2.carbon.devicemgt
+ 3.0.9-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
+ bundle
+ WSO2 Carbon - HTTP Based Push Notification Provider Implementation
+ WSO2 Carbon - HTTP Based Push Notification Provider Implementation
+ http://wso2.org
+
+
+
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.core
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
+
+ org.apache.ws.commons.axiom.wso2
+ axiom
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ org.wso2.orbit.org.scannotation
+ scannotation
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.tomcat
+ tomcat
+
+
+ org.wso2.tomcat
+ tomcat-servlet-api
+
+
+ javax.ws.rs
+ jsr311-api
+
+
+ org.apache.axis2.wso2
+ axis2
+
+
+ commons-lang.wso2
+ commons-lang
+
+
+ com.google.code.gson
+ gson
+
+
+ org.json.wso2
+ json
+
+
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ MQTT Based Push Notification Provider Bundle
+
+ !org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal,
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.*
+
+
+ org.apache.commons.logging,
+ org.osgi.service.component,
+ org.wso2.carbon.context,
+ org.wso2.carbon.device.mgt.common.operation.mgt,
+ org.wso2.carbon.device.mgt.common.push.notification,
+ org.wso2.carbon.device.mgt.common,
+ org.wso2.carbon.device.mgt.core.service,
+ org.osgi.framework,
+ org.wso2.carbon.device.mgt.core.operation.mgt,
+ org.wso2.carbon.core,
+ com.google.gson,
+ org.apache.commons.httpclient.*
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPBasedPushNotificationProvider.java
similarity index 50%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java
rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPBasedPushNotificationProvider.java
index 10a9b018b3..5f083400b1 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPBasedPushNotificationProvider.java
@@ -16,24 +16,22 @@
* under the License.
*
*/
+package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
-public class DeviceTypePluginDAOManager {
+public class HTTPBasedPushNotificationProvider implements PushNotificationProvider {
- private DeviceTypePluginDAO deviceTypePluginDAO;
- private DeviceTypeDAOHandler deviceTypeDAOHandler;
-
- public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
- deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName);
- deviceTypePluginDAO = new DeviceTypePluginDAO(deviceDAODefinition, deviceTypeDAOHandler);
+ @Override
+ public String getType() {
+ return "HTTP";
}
- public DeviceTypePluginDAO getDeviceDAO() {
- return deviceTypePluginDAO;
+ @Override
+ public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
+ return new HTTPNotificationStrategy(config);
}
- public DeviceTypeDAOHandler getDeviceTypeDAOHandler() {
- return deviceTypeDAOHandler;
- }
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java
new file mode 100644
index 0000000000..d833856883
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java
@@ -0,0 +1,94 @@
+package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
+
+import com.google.gson.Gson;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
+
+import java.net.UnknownHostException;
+
+public class HTTPMessageExecutor implements Runnable {
+
+ private String url;
+ private String authorizationHeader;
+ private String payload;
+ private HostConfiguration hostConfiguration;
+ private HttpClient httpClient;
+ private static final String APPLIATION_JSON = "application/json";
+ private static final String AUTHORIZATION_HEADER = "Authorization";
+ private static final Log log = LogFactory.getLog(HTTPMessageExecutor.class);
+
+ public HTTPMessageExecutor(NotificationContext notificationContext, String authorizationHeader, String url
+ , HostConfiguration hostConfiguration, HttpClient httpClient) {
+ this.url = url;
+ this.authorizationHeader = authorizationHeader;
+ Gson gson = new Gson();
+ this.payload = gson.toJson(notificationContext);
+ this.hostConfiguration = hostConfiguration;
+ this.httpClient = httpClient;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getAuthorizationHeader() {
+ return authorizationHeader;
+ }
+
+ public void setAuthorizationHeader(String authorizationHeader) {
+ this.authorizationHeader = authorizationHeader;
+ }
+
+ public String getPayload() {
+ return payload;
+ }
+
+ public void setPayload(String payload) {
+ this.payload = payload;
+ }
+
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public void setHttpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
+ @Override
+ public void run() {
+ EntityEnclosingMethod method = null;
+
+ try {
+ method = new PostMethod(this.getUrl());
+ method.setRequestEntity(new StringRequestEntity(this.getPayload(), APPLIATION_JSON, "UTF-8"));
+ if (authorizationHeader != null && authorizationHeader.isEmpty()) {
+ method.setRequestHeader(AUTHORIZATION_HEADER, authorizationHeader);
+ }
+
+ this.getHttpClient().executeMethod(hostConfiguration, method);
+
+ } catch (UnknownHostException e) {
+ log.error("Push Notification message dropped " + url, e);
+ throw new InvalidConfigurationException("invalid host: url", e);
+ } catch (Throwable e) {
+ log.error("Push Notification message dropped ", e);
+ throw new InvalidConfigurationException("Push Notification message dropped, " + e.getMessage(), e);
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java
new file mode 100644
index 0000000000..2e4e237c69
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
+
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
+
+public class HTTPNotificationStrategy implements NotificationStrategy {
+
+ private static final Log log = LogFactory.getLog(HTTPNotificationStrategy.class);
+ private final PushNotificationConfig config;
+ private static final String URL_PROPERTY = "url";
+ private static final String AUTHORIZATION_HEADER_PROPERTY = "authorization";
+ private String endpoint;
+ private static ExecutorService executorService;
+ private HttpClient httpClient = null;
+ private HostConfiguration hostConfiguration;
+ private String authorizationHeaderValue;
+ private String uri;
+
+ public HTTPNotificationStrategy(PushNotificationConfig config) {
+ this.config = config;
+ if (this.config == null) {
+ throw new InvalidConfigurationException("Properties Cannot be found");
+ }
+ endpoint = config.getProperties().get(URL_PROPERTY);
+ if (endpoint == null || endpoint.isEmpty()) {
+ throw new InvalidConfigurationException("Property - 'url' cannot be found");
+ }
+ try {
+ this.uri = endpoint;
+ URL url = new URL(endpoint);
+ hostConfiguration = new HostConfiguration();
+ hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());
+ this.authorizationHeaderValue = config.getProperties().get(AUTHORIZATION_HEADER_PROPERTY);
+ executorService = Executors.newFixedThreadPool(1);
+ httpClient = new HttpClient();
+ } catch (MalformedURLException e) {
+ throw new InvalidConfigurationException("Property - 'url' is malformed.", e);
+ }
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
+ try {
+ executorService.submit(new HTTPMessageExecutor(ctx, authorizationHeaderValue, uri, hostConfiguration
+ , httpClient));
+ } catch (RejectedExecutionException e) {
+ log.error("Failed to publish to external endpoint url: " + endpoint, e);
+ }
+ }
+
+ @Override
+ public NotificationContext buildContext() {
+ return null;
+ }
+
+ @Override
+ public void undeploy() {
+ executorService.shutdown();
+ }
+
+ @Override
+ public PushNotificationConfig getConfig() {
+ return config;
+ }
+
+}
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/internal/HTTPPushNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/internal/HTTPPushNotificationServiceComponent.java
new file mode 100644
index 0000000000..b16e1728d9
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/internal/HTTPPushNotificationServiceComponent.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal.HTTPPushNotificationServiceComponent" immediate="true"
+ */
+public class HTTPPushNotificationServiceComponent {
+
+ private static final Log log = LogFactory.getLog(HTTPPushNotificationServiceComponent.class);
+
+ @SuppressWarnings("unused")
+ protected void activate(ComponentContext componentContext) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing HTTP based push notification provider implementation bundle");
+ }
+ //Do nothing
+ if (log.isDebugEnabled()) {
+ log.debug("HTTP based push notification provider implementation bundle has been successfully " +
+ "initialized");
+ }
+ } catch (Throwable e) {
+ log.error("Error occurred while initializing HTTP based push notification provider " +
+ "implementation bundle", e);
+ }
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
index d1076f7f64..6c9f5fd325 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
index 121599324a..59653e7831 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
@@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
-import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@@ -147,7 +147,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
for (ProfileOperation profileOperation : profileOperations) {
Map dynamicProperties = new HashMap<>();
String topic = tenantDomain + "/"
- + deviceType + "/" + deviceId + "/" + profileOperation.getType()
+ + deviceType + "/" + deviceId + "/operation/" + profileOperation.getType()
.toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase();
dynamicProperties.put("topic", topic);
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
@@ -157,14 +157,17 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
} else {
Map dynamicProperties = new HashMap<>();
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/"
- + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType()
- .toString().toLowerCase() + "/" + operation.getCode();
+ + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/operation/"
+ + operation.getType().toString().toLowerCase() + "/" + operation.getCode() + "/" + operation.getId();
dynamicProperties.put("topic", topic);
- if (operation.getPayLoad() == null) {
- operation.setPayLoad("");
+ Object payload;
+ if ("command".equals(operation.getType().toString().toLowerCase())) {
+ payload = operation.getCode();
+ } else {
+ payload = operation.getPayLoad();
}
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
- operation.getPayLoad());
+ payload);
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
index ee9a1abd17..2a921c0014 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
index af3a1c6c4b..d091ecfd9d 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
@@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml
index 7c30ab6260..29aec93494 100644
--- a/components/device-mgt-extensions/pom.xml
+++ b/components/device-mgt-extensions/pom.xml
@@ -22,7 +22,7 @@
carbon-devicemgt
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../../pom.xml
@@ -34,10 +34,12 @@
http://wso2.org
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp
org.wso2.carbon.device.mgt.extensions.device.type.deployer
+ org.wso2.carbon.device.mgt.extensions.pull.notification
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
index f1bd359b92..e74d06d94d 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
@@ -3,7 +3,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
index 871ed94950..d6b7e0d520 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
@@ -125,7 +125,8 @@
javax.xml.*,
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
org.w3c.dom,
- org.wso2.carbon.base
+ org.wso2.carbon.base,
+ org.wso2.carbon.utils.multitenancy
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
index 32df9eb5ab..5d7342d414 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
@@ -22,7 +22,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
@@ -167,6 +167,16 @@
org.wso2.carbon.device.mgt.common
provided
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.analytics.data.publisher
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions
+ provided
+
org.wso2.carbon.devicemgt
org.wso2.carbon.device.mgt.core
@@ -280,16 +290,6 @@
javax.ws.rs
javax.ws.rs-api
-
-
- org.wso2.carbon.analytics-common
- org.wso2.carbon.event.receiver.stub
- provided
-
-
- org.wso2.carbon.analytics-common
- org.wso2.carbon.event.stream.stub
- provided
org.wso2.carbon.commons
@@ -311,13 +311,57 @@
org.wso2.carbon.identity.jwt.client.extension
provided
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.core
+ provided
+
+
+ org.wso2.carbon.registry
+ org.wso2.carbon.registry.resource
+ provided
+
org.wso2.carbon.identity.framework
org.wso2.carbon.identity.user.store.count
${carbon.identity.framework.version}
provided
-
+
+ org.wso2.carbon.analytics
+ org.wso2.carbon.analytics.datasource.commons
+ provided
+
+
+ org.wso2.carbon.analytics
+ org.wso2.carbon.analytics.api
+ provided
+
+
+ org.wso2.carbon.analytics
+ org.wso2.carbon.analytics.dataservice.commons
+ provided
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.receiver.stub
+ provided
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.stream.stub
+ provided
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.publisher.stub
+ provided
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.stream.persistence.stub
+ provided
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/OperationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/OperationRequest.java
new file mode 100644
index 0000000000..d8cd2ec769
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/OperationRequest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.jaxrs.beans;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
+
+import java.util.List;
+
+@ApiModel(value = "OperationRequest", description = "Operation details together with deviceIdentifier")
+public class OperationRequest {
+
+ @ApiModelProperty(name = "deviceIdentifiers", value = "list of devices that needs to be verified against the user", required = true)
+ List deviceIdentifiers;
+ @ApiModelProperty(name = "operation", value = "operation data", required = false)
+ Operation operation;
+
+ public List getDeviceIdentifiers() {
+ return deviceIdentifiers;
+ }
+
+ public void setDeviceIdentifiers(List deviceIdentifiers) {
+ this.deviceIdentifiers = deviceIdentifiers;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+
+ public void setOperation(Operation operation) {
+ this.operation = operation;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java
new file mode 100644
index 0000000000..276fea9ee4
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java
@@ -0,0 +1,60 @@
+/*
+ * 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.carbon.device.mgt.jaxrs.beans.analytics;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * This hold the attribute definition.
+ */
+public class Attribute {
+
+ @ApiModelProperty(value = "Event Attribute Name")
+ @JsonProperty("name")
+ private String name;
+ @ApiModelProperty(value = "Event Attribute Type")
+ @JsonProperty("type")
+ private AttributeType type;
+
+ public Attribute() {
+
+ }
+
+ public Attribute(String name, AttributeType attributeType) {
+ this.name = name;
+ this.type = attributeType;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public AttributeType getType() {
+ return type;
+ }
+
+ public void setType(AttributeType type) {
+ this.type = type;
+ }
+}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java
new file mode 100644
index 0000000000..23235612b9
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java
@@ -0,0 +1,32 @@
+/*
+ * 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.carbon.device.mgt.jaxrs.beans.analytics;
+
+/**
+ * This hold the definition of the attribute type for the attributes.
+ */
+public enum AttributeType {
+ STRING, LONG, BOOL, INT, FLOAT, DOUBLE;
+
+ @Override
+ public String toString() {
+ return super.toString().toLowerCase();
+ }
+}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/DeviceTypeEvent.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/DeviceTypeEvent.java
new file mode 100644
index 0000000000..7ff162b357
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/DeviceTypeEvent.java
@@ -0,0 +1,53 @@
+/*
+ * 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.carbon.device.mgt.jaxrs.beans.analytics;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * This hold stats data record
+ */
+public class DeviceTypeEvent {
+
+ private EventAttributeList eventAttributes;
+ private TransportType transport;
+
+ @ApiModelProperty(value = "Attributes related to device type event")
+ @JsonProperty("eventAttributes")
+ public EventAttributeList getEventAttributeList() {
+ return eventAttributes;
+ }
+
+ public void setEventAttributeList(
+ EventAttributeList eventAttributes) {
+ this.eventAttributes = eventAttributes;
+ }
+
+ @ApiModelProperty(value = "Transport to be used for device to server communication.")
+ @JsonProperty("transport")
+ public TransportType getTransportType() {
+ return transport;
+ }
+
+ public void setTransportType(TransportType transport) {
+ this.transport = transport;
+ }
+}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeList.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeList.java
new file mode 100644
index 0000000000..fe9bd39e03
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeList.java
@@ -0,0 +1,47 @@
+/*
+ * 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.carbon.device.mgt.jaxrs.beans.analytics;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModelProperty;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.jaxrs.beans.BasePaginatedResult;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This holds event attributes
+ */
+public class EventAttributeList {
+
+ private List attributes = new ArrayList<>();
+
+ @ApiModelProperty(value = "List of Event Attributes")
+ @JsonProperty("attributes")
+ public List getList() {
+ return attributes;
+ }
+
+ public void setList(List attributes) {
+ this.attributes = attributes;
+ }
+
+}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventRecords.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventRecords.java
new file mode 100644
index 0000000000..0dacde3833
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventRecords.java
@@ -0,0 +1,59 @@
+/*
+ * 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.carbon.device.mgt.jaxrs.beans.analytics;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModelProperty;
+import org.wso2.carbon.device.mgt.common.Device;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.wso2.carbon.analytics.datasource.commons.Record;
+import org.wso2.carbon.device.mgt.jaxrs.beans.BasePaginatedResult;
+
+/**
+ * This hold stats data record
+ */
+public class EventRecords extends BasePaginatedResult {
+
+ private List records = new ArrayList<>();
+
+ @ApiModelProperty(value = "List of records returned")
+ @JsonProperty("records")
+ public List getRecord() {
+ return records;
+ }
+
+ public void setList(List records) {
+ this.records = records;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{\n");
+
+ sb.append(" count: ").append(getCount()).append(",\n");
+ sb.append(" records: [").append(records).append("\n");
+ sb.append("]}\n");
+ return sb.toString();
+ }
+
+}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/TransportType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/TransportType.java
new file mode 100644
index 0000000000..58eae4e616
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/TransportType.java
@@ -0,0 +1,27 @@
+/*
+ * 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.carbon.device.mgt.jaxrs.beans.analytics;
+
+/**
+ * This hold the default transport types support by the server.
+ */
+public enum TransportType {
+ HTTP, MQTT;
+}
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceAgentService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceAgentService.java
new file mode 100644
index 0000000000..ce442701e1
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceAgentService.java
@@ -0,0 +1,608 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.jaxrs.service.api;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
+import io.swagger.annotations.Info;
+import io.swagger.annotations.ResponseHeader;
+import io.swagger.annotations.SwaggerDefinition;
+import io.swagger.annotations.Tag;
+import org.wso2.carbon.apimgt.annotations.api.Scope;
+import org.wso2.carbon.apimgt.annotations.api.Scopes;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
+import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+
+import javax.validation.Valid;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.Map;
+
+@SwaggerDefinition(
+ info = @Info(
+ version = "1.0.0",
+ title = "",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = "name", value = "DeviceAgent Service"),
+ @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/device/agent"),
+ })
+ }
+ ),
+ tags = {
+ @Tag(name = "device_agent, device_management", description = "")
+ }
+)
+@Api(value = "Device Agent", description = "Device Agent Service")
+@Path("/device/agent")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+@Scopes(
+ scopes = {
+ @Scope(
+ name = "Enroll Device",
+ description = "Register a device",
+ key = "perm:device:enroll",
+ permissions = {"/device-mgt/devices/owning-device/add"}
+ ),
+ @Scope(
+ name = "Modify Device",
+ description = "Modify a device",
+ key = "perm:device:modify",
+ permissions = {"/device-mgt/devices/owning-device/modify"}
+ ),
+ @Scope(
+ name = "Disenroll Device",
+ description = "Disenroll a device",
+ key = "perm:device:disenroll",
+ permissions = {"/device-mgt/devices/owning-device/remove"}
+ ),
+ @Scope(
+ name = "Publish Event",
+ description = "publish device event",
+ key = "perm:device:publish-event",
+ permissions = {"/device-mgt/devices/owning-device/event"}
+ ),
+ @Scope(
+ name = "Getting Device Operation Details",
+ description = "Getting Device Operation Details",
+ key = "perm:device:operations",
+ permissions = {"/device-mgt/devices/owning-device/view"}
+ )
+ }
+)
+public interface DeviceAgentService {
+
+ @POST
+ @Path("/enroll")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Create a device instance",
+ notes = "Create a device Instance",
+ tags = "Device Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:enroll")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully created a device instance.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest version" +
+ " of the requested resource.\n"),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n A deviceType with the specified device type was not found.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving the device details.",
+ response = ErrorResponse.class)
+ })
+ Response enrollDevice(@ApiParam(name = "device", value = "Device object with data.", required = true)
+ @Valid Device device);
+
+ @DELETE
+ @Path("/enroll/{type}/{id}")
+ @ApiOperation(
+ httpMethod = "DELETE",
+ value = "Unregistering a Device",
+ notes = "Use this REST API to unregister a device.",
+ tags = "Device Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:disenroll")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully disenrolled the device."),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n The specified resource does not exist."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while dis-enrolling the device.")
+ })
+ Response disEnrollDevice(
+ @ApiParam(name = "type", value = "The unique device identifier.") @PathParam("type") String type,
+ @ApiParam(name = "id", value = "The unique device identifier.") @PathParam("id") String id);
+
+ @PUT
+ @Path("/enroll/{type}/{id}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "PUT",
+ value = "modify device",
+ notes = "modify device",
+ tags = "Device Agent Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:modify")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully updated device instance.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest version" +
+ " of the requested resource.\n"),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n A deviceType with the specified device type was not found.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving the device details.",
+ response = ErrorResponse.class)
+ })
+ Response updateDevice(@ApiParam(name = "type", value = "The device type, such as ios, android or windows....etc", required = true)
+ @PathParam("type") String type,
+ @ApiParam(name = "id", value = "The device id.", required = true)
+ @PathParam("id") String deviceId,
+ @ApiParam(name = "device", value = "Device object with data.", required = true)
+ @Valid Device updateDevice);
+
+ @POST
+ @Path("/events/publish/{type}/{deviceId}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Publishing Events",
+ notes = "Publish events received by the device client to the WSO2 Data Analytics Server (DAS) using this API.",
+ tags = "Device Agent Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:publish-event")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = 200, message = "OK. \n Successfully published the event",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests.")
+ }),
+ @ApiResponse(
+ code = 303,
+ message = "See Other. \n The source can be retrieved from the URL specified in the location header.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Location",
+ description = "The Source URL of the document.")}),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error."),
+ @ApiResponse(
+ code = 415,
+ message = "Unsupported media type. \n The format of the requested entity was not supported."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while publishing events.")
+ })
+ Response publishEvents(
+ @ApiParam(
+ name = "payloadData",
+ value = "Information of the agent event to be published on DAS.")
+ @Valid
+ Map payloadData,
+ @ApiParam(
+ name = "type",
+ value = "name of the device type")
+ @PathParam("type") String type,
+ @ApiParam(
+ name = "deviceId",
+ value = "deviceId of the device")
+ @PathParam("deviceId") String deviceId);
+
+ @POST
+ @Path("/events/publish/data/{type}/{deviceId}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Publishing Events data only",
+ notes = "Publish events received by the device client to the WSO2 Data Analytics Server (DAS) using this API.",
+ tags = "Device Agent Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:publish-event")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = 200, message = "OK. \n Successfully published the event",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests.")
+ }),
+ @ApiResponse(
+ code = 303,
+ message = "See Other. \n The source can be retrieved from the URL specified in the location header.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Location",
+ description = "The Source URL of the document.")}),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error."),
+ @ApiResponse(
+ code = 415,
+ message = "Unsupported media type. \n The format of the requested entity was not supported."),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while publishing events.")
+ })
+ Response publishEvents(
+ @ApiParam(
+ name = "payloadData",
+ value = "Information of the agent event to be published on DAS.")
+ @Valid
+ List payloadData,
+ @ApiParam(
+ name = "type",
+ value = "name of the device type")
+ @PathParam("type") String type,
+ @ApiParam(
+ name = "deviceId",
+ value = "deviceId of the device")
+ @PathParam("deviceId") String deviceId);
+
+ @GET
+ @Path("/pending/operations/{type}/{id}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Get pending operation of the given device",
+ notes = "Returns the Operations.",
+ tags = "Device Agent Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully retrieved the operations.",
+ response = OperationList.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource has been modified the last time.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest " +
+ "version of the requested resource."),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n No device is found under the provided type and id.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving information requested device.",
+ response = ErrorResponse.class)
+ })
+ Response getPendingOperations(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true)
+ @PathParam("type") String type,
+ @ApiParam(name = "id", value = "The device id.", required = true)
+ @PathParam("id") String deviceId);
+
+ @GET
+ @Path("/next-pending/operation/{type}/{id}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Get pending operation of the given device",
+ notes = "Returns the Operation.",
+ tags = "Device Agent Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully retrieved the operation.",
+ response = Operation.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource has been modified the last time.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest " +
+ "version of the requested resource."),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n No device is found under the provided type and id.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving information requested device.",
+ response = ErrorResponse.class)
+ })
+ Response getNextPendingOperation(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true)
+ @PathParam("type") String type,
+ @ApiParam(name = "id", value = "The device id.", required = true)
+ @PathParam("id") String deviceId);
+
+ @PUT
+ @Path("/operations/{type}/{id}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "PUT",
+ value = "Update Operation",
+ notes = "Update the Operations.",
+ tags = "Device Agent Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully updated the operations.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource has been modified the last time.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest " +
+ "version of the requested resource."),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n No device is found under the provided type and id.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving information requested device.",
+ response = ErrorResponse.class)
+ })
+ Response updateOperation(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true)
+ @PathParam("type") String type,
+ @ApiParam(name = "id", value = "The device id.", required = true)
+ @PathParam("id") String deviceId,
+ @ApiParam(name = "operation", value = "Operation object with data.", required = true)
+ @Valid Operation operation);
+
+ @GET
+ @Path("/status/operations/{type}/{id}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Get pending operation of the given device",
+ notes = "Returns the Operations.",
+ tags = "Device Agent Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully retrieved the operations.",
+ response = OperationList.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource has been modified the last time.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest " +
+ "version of the requested resource."),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n No device is found under the provided type and id.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving information requested device.",
+ response = ErrorResponse.class)
+ })
+ Response getOperationsByDeviceAndStatus(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true)
+ @PathParam("type") String type,
+ @ApiParam(name = "id", value = "The device id.", required = true)
+ @PathParam("id") String deviceId,
+ @ApiParam(name = "status", value = "status of the operation.", required = true)
+ @QueryParam("status")Operation.Status status);
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java
new file mode 100644
index 0000000000..8b6d7ed030
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java
@@ -0,0 +1,347 @@
+package org.wso2.carbon.device.mgt.jaxrs.service.api;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
+import io.swagger.annotations.Info;
+import io.swagger.annotations.ResponseHeader;
+import io.swagger.annotations.SwaggerDefinition;
+import io.swagger.annotations.Tag;
+import org.wso2.carbon.apimgt.annotations.api.Scope;
+import org.wso2.carbon.apimgt.annotations.api.Scopes;
+import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
+import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.DeviceTypeEvent;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeList;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventRecords;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.TransportType;
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+
+import javax.validation.Valid;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@SwaggerDefinition(
+ info = @Info(
+ version = "1.0.0",
+ title = "",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = "name", value = "DeviceEventManagement"),
+ @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/events"),
+ })
+ }
+ ),
+ tags = {
+ @Tag(name = "device_management", description = "")
+ }
+)
+@Scopes(
+ scopes = {
+ @Scope(
+ name = "Add or Delete Event Definition for device type",
+ description = "Add or Delete Event Definition for device type",
+ key = "perm:device-types:events",
+ permissions = {"/device-mgt/device-type/add"}
+ ),
+ @Scope(
+ name = "Get Events Details of a Device Type",
+ description = "Get Events Details of a Device Type",
+ key = "perm:device-types:events:view",
+ permissions = {"/device-mgt/devices/owning-device/view"}
+ )
+ }
+)
+@Path("/events")
+@Api(value = "Device Event Management", description = "This API corresponds to all tasks related to device " +
+ "event management")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public interface DeviceEventManagementService {
+
+ @POST
+ @Path("/{type}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Add Event Type Defnition",
+ notes = "Add the event definition for the device.",
+ tags = "Device Event Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:events")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully added the event defintion.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description =
+ "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }
+ ),
+ @ApiResponse(
+ code = 400,
+ message =
+ "Bad Request. \n"),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the " +
+ "list of supported device types.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response deployDeviceTypeEventDefinition(@ApiParam(name = "type", value = "name of the device type", required = false)
+ @PathParam("type")String deviceType,
+ @ApiParam(name = "deviceTypeEvent", value = "DeviceTypeEvent object with data.", required = true)
+ @Valid DeviceTypeEvent deviceTypeEvent);
+
+ @DELETE
+ @Path("/{type}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "DELETE",
+ value = "Delete Event Type Defnition",
+ notes = "Delete the event definition for the device.",
+ tags = "Device Event Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:events")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully deleted the event definition.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description =
+ "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }
+ ),
+ @ApiResponse(
+ code = 400,
+ message =
+ "Bad Request. \n"),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the " +
+ "list of supported device types.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response deleteDeviceTypeEventDefinitions(@ApiParam(name = "type", value = "name of the device type", required = false)
+ @PathParam("type")String deviceType);
+
+ @GET
+ @Path("/{type}/{deviceId}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Getting Device Events",
+ notes = "Get the events for the device.",
+ tags = "Device Event Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:events:view")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully fetched the event definition.",
+ response = EventRecords.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description =
+ "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }
+ ),
+ @ApiResponse(
+ code = 400,
+ message =
+ "Bad Request. \n"),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the " +
+ "list of supported device types.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response getData(@ApiParam(name = "deviceId", value = "id of the device ", required = false)
+ @PathParam("deviceId") String deviceId,
+ @ApiParam(name = "from", value = "unix timestamp to retrieve", required = false)
+ @QueryParam("from") long from,
+ @ApiParam(name = "to", value = "unix time to retrieve", required = false)
+ @QueryParam("to") long to,
+ @ApiParam(name = "type", value = "name of the device type", required = false)
+ @PathParam("type") String deviceType,
+ @ApiParam(name = "offset", value = "offset of the records that needs to be picked up", required = false)
+ @QueryParam("offset") int offset,
+ @ApiParam(name = "limit", value = "limit of the records that needs to be picked up", required = false)
+ @QueryParam("limit") int limit);
+
+ @GET
+ @Path("last-known/{type}/{deviceId}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Getting Last Known Device Events",
+ notes = "Get the Last Known events for the device.",
+ tags = "Device Event Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:events:view")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully fetched the event.",
+ response = EventRecords.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description =
+ "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }
+ ),
+ @ApiResponse(
+ code = 400,
+ message =
+ "Bad Request. \n"),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the " +
+ "list of supported device types.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response getLastKnownData(@ApiParam(name = "deviceId", value = "id of the device ", required = false)
+ @PathParam("deviceId") String deviceId,
+ @ApiParam(name = "type", value = "name of the device type", required = false)
+ @PathParam("type") String deviceType);
+
+ @GET
+ @Path("/{type}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Getting Event Type Defnition",
+ notes = "Get the event definition for the device.",
+ tags = "Device Event Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:events:view")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully fetched the event defintion.",
+ response = DeviceTypeEvent.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description =
+ "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }
+ ),
+ @ApiResponse(
+ code = 400,
+ message =
+ "Bad Request. \n"),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the " +
+ "list of supported device types.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response getDeviceTypeEventDefinition(@ApiParam(name = "type", value = "name of the device type", required = false)
+ @PathParam("type")String deviceType) ;
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java
index dc1578fe10..53de86e45d 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java
@@ -32,17 +32,22 @@ import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
+import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+import javax.validation.Valid;
import javax.validation.constraints.Size;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -56,6 +61,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import java.util.List;
/**
* Device related REST-API. This can be used to manipulated device related details.
@@ -443,6 +449,60 @@ public interface DeviceManagementService {
@HeaderParam("If-Modified-Since")
String ifModifiedSince);
+ @PUT
+ @Path("/{type}/{id}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Get device enrollment status",
+ notes = "Get device enrollment status",
+ tags = "Device Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully created a device instance.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest version" +
+ " of the requested resource.\n"),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n A deviceType with the specified device type was not found.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving the device details.",
+ response = ErrorResponse.class)
+ })
+ Response isEnrolled(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true)
+ @PathParam("type") String type,
+ @ApiParam(name = "id", value = "The device id.", required = true)
+ @PathParam("id") String deviceId);
@GET
@Path("/{type}/{id}/location")
@@ -1253,4 +1313,62 @@ public interface DeviceManagementService {
@QueryParam("newStatus")
EnrolmentInfo.Status newStatus);
+ @POST
+ @Path("/{type}/operations")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Add operation to set of devices for a given device type",
+ notes = "Returns the Activity Related to the operation.",
+ tags = "Device Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:operations")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 201,
+ message = "OK. \n Successfully added the operation.",
+ response = Activity.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description = "Date and time the resource has been modified the last time.\n" +
+ "Used by caches, or in conditional requests."),
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest " +
+ "version of the requested resource."),
+ @ApiResponse(
+ code = 400,
+ message = "Bad Request. \n Invalid request or validation error.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found. \n No device is found under the provided type and id.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n " +
+ "Server error occurred while retrieving information requested device.",
+ response = ErrorResponse.class)
+ })
+ Response addOperation(@ApiParam(name = "type", value = "The device type, such as ios, android or windows... etc.", required = true)
+ @PathParam("type") String type,
+ @ApiParam(name = "deviceOperation", value = "Operation object with device ids.", required = true)
+ @Valid OperationRequest operationRequest);
+
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java
index b71c918fca..390bb2dca4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java
@@ -31,6 +31,7 @@ import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
+import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
@@ -206,4 +207,103 @@ public interface DeviceTypeManagementService {
@HeaderParam("If-Modified-Since")
String ifModifiedSince);
+ @GET
+ @Path("/all/{type}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Getting Details of a Device Type",
+ notes = "Get the details of a device by searching via the device type and the tenant domain.",
+ response = DeviceType.class,
+ tags = "Device Type Management Administrative Service",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:types")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.",
+ response = DeviceType.class,
+ responseContainer = "List",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body")
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest version of the " +
+ "requested resource.\n"),
+ @ApiResponse(
+ code = 401,
+ message = "Unauthorized.\n The unauthorized access to the requested resource.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found.\n The specified device does not exist",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the device list.",
+ response = ErrorResponse.class)
+ })
+ Response getDeviceTypeByName(
+ @ApiParam(
+ name = "type",
+ value = "The device type name, such as ios, android, windows or fire-alarm.",
+ required = true)
+ @PathParam("type")
+ @Size(min = 2, max = 45)
+ String type);
+
+ @GET
+ @Path("/all")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Retrieve device types information",
+ notes = "Retrieve device types information.",
+ response = DeviceType.class,
+ tags = "Device Type Management Administrative Service",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:types")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.",
+ response = DeviceType.class,
+ responseContainer = "List",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body")
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest version of the " +
+ "requested resource.\n"),
+ @ApiResponse(
+ code = 401,
+ message = "Unauthorized.\n The unauthorized access to the requested resource.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found.\n The specified device does not exist",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the device list.",
+ response = ErrorResponse.class)
+ })
+ Response getDeviceTypes();
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java
new file mode 100644
index 0000000000..aa90b5b304
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
+import io.swagger.annotations.Info;
+import io.swagger.annotations.ResponseHeader;
+import io.swagger.annotations.SwaggerDefinition;
+import io.swagger.annotations.Tag;
+import org.wso2.carbon.apimgt.annotations.api.Scope;
+import org.wso2.carbon.apimgt.annotations.api.Scopes;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.core.dto.DeviceType;
+import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
+import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+
+import javax.validation.constraints.Size;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@SwaggerDefinition(
+ info = @Info(
+ version = "1.0.0",
+ title = "",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = "name", value = "DeviceTypeManagementAdminService"),
+ @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/device-types"),
+ })
+ }
+ ),
+ tags = {
+ @Tag(name = "device_management", description = "")
+ }
+)
+@Path("/admin/device-types")
+@Api(value = "Device Type Management Administrative Service", description = "This an API intended to be used by " +
+ "'internal' components to log in as an admin user and do a selected number of operations. " +
+ "Further, this is strictly restricted to admin users only ")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+@Scopes(
+ scopes = {
+ @Scope(
+ name = "Getting Details of a Device",
+ description = "Getting Details of a Device",
+ key = "perm:admin:device-type",
+ permissions = {"/device-mgt/admin/device-type"}
+ )
+ }
+)
+public interface DeviceTypeManagementAdminService {
+
+ @GET
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Getting the Supported Device Type with Meta Definition",
+ notes = "Get the list of device types supported by WSO2 IoT.",
+ tags = "Device Type Management",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type")
+ })
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(
+ code = 200,
+ message = "OK. \n Successfully fetched the list of supported device types.",
+ response = DeviceTypeList.class,
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body"),
+ @ResponseHeader(
+ name = "ETag",
+ description = "Entity Tag of the response resource.\n" +
+ "Used by caches, or in conditional requests."),
+ @ResponseHeader(
+ name = "Last-Modified",
+ description =
+ "Date and time the resource was last modified.\n" +
+ "Used by caches, or in conditional requests."),
+ }
+ ),
+ @ApiResponse(
+ code = 304,
+ message =
+ "Not Modified. \n Empty body because the client already has the latest version " +
+ "of the requested resource.\n"),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the " +
+ "list of supported device types.",
+ response = ErrorResponse.class)
+ }
+ )
+ Response getDeviceTypes();
+
+ @POST
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Add a Device Type",
+ notes = "Add the details of a device type.",
+ tags = "Device Type Management Administrative Service",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK. \n Successfully added the device type.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body")
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest version of the " +
+ "requested resource.\n"),
+ @ApiResponse(
+ code = 401,
+ message = "Unauthorized.\n The unauthorized access to the requested resource.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found.\n The specified device does not exist",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the device list.",
+ response = ErrorResponse.class)
+ })
+ Response addDeviceType(@ApiParam(
+ name = "type",
+ value = "The device type such as ios, android, windows or fire-alarm.",
+ required = true)DeviceType deviceType);
+
+ @PUT
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "PUT",
+ value = "Update Device Type",
+ notes = "Update the details of a device type.",
+ response = DeviceType.class,
+ tags = "Device Type Management Administrative Service",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK. \n Successfully updated the device type.",
+ responseHeaders = {
+ @ResponseHeader(
+ name = "Content-Type",
+ description = "The content type of the body")
+ }),
+ @ApiResponse(
+ code = 304,
+ message = "Not Modified. Empty body because the client already has the latest version of the " +
+ "requested resource.\n"),
+ @ApiResponse(
+ code = 401,
+ message = "Unauthorized.\n The unauthorized access to the requested resource.",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 404,
+ message = "Not Found.\n The specified device does not exist",
+ response = ErrorResponse.class),
+ @ApiResponse(
+ code = 406,
+ message = "Not Acceptable.\n The requested media type is not supported"),
+ @ApiResponse(
+ code = 500,
+ message = "Internal Server Error. \n Server error occurred while fetching the device list.",
+ response = ErrorResponse.class)
+ })
+ Response updateDeviceType(@ApiParam(
+ name = "type",
+ value = "The device type such as ios, android, windows or fire-alarm.",
+ required = true) DeviceType deviceType);
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java
new file mode 100644
index 0000000000..c72dfd9197
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java
@@ -0,0 +1,574 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.jaxrs.service.impl;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
+import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
+import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
+import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
+import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
+import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
+import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AttributeType;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeList;
+import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceAgentService;
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
+import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub;
+import org.wso2.carbon.event.stream.stub.types.EventStreamAttributeDto;
+import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto;
+import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
+import org.wso2.carbon.user.api.UserStoreException;
+
+import javax.validation.Valid;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Path("/device/agent")
+public class DeviceAgentServiceImpl implements DeviceAgentService {
+ private static final Log log = LogFactory.getLog(DeviceAgentServiceImpl.class);
+ private static final String POLICY_MONITOR = "POLICY_MONITOR";
+ @POST
+ @Path("/enroll")
+ @Override
+ public Response enrollDevice(@Valid Device device) {
+ if (device == null) {
+ String errorMessage = "The payload of the device enrollment is incorrect.";
+ return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build();
+ }
+ try {
+ DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
+ if (device.getType() == null || device.getDeviceIdentifier() == null) {
+ String errorMessage = "The payload of the device enrollment is incorrect.";
+ return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build();
+ }
+ Device existingDevice = dms.getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
+ if (existingDevice != null && existingDevice.getEnrolmentInfo() != null && existingDevice
+ .getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
+ String errorMessage = "An active enrolment exists";
+ return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build();
+ }
+ device.getEnrolmentInfo().setOwner(DeviceMgtAPIUtils.getAuthenticatedUser());
+ device.getEnrolmentInfo().setDateOfEnrolment(System.currentTimeMillis());
+ device.getEnrolmentInfo().setDateOfLastUpdate(System.currentTimeMillis());
+ boolean status = dms.enrollDevice(device);
+ return Response.status(Response.Status.OK).entity(status).build();
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while enrolling the device, which carries the id '" +
+ device.getDeviceIdentifier() + "'";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (InvalidConfigurationException e) {
+ log.error("failed to add operation", e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
+ }
+
+ @DELETE
+ @Path("/enroll/{type}/{id}")
+ @Override
+ public Response disEnrollDevice(@PathParam("type") String type, @PathParam("id") String id) {
+ boolean result;
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type);
+ try {
+ result = DeviceMgtAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
+ if (result) {
+ return Response.status(Response.Status.OK).build();
+ } else {
+ return Response.status(Response.Status.NO_CONTENT).entity(type + " device that carries id '" + id +
+ "' has not been dis-enrolled").build();
+ }
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while enrolling the device, which carries the id '" + id + "'";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ @PUT
+ @Path("/enroll/{type}/{id}")
+ @Override
+ public Response updateDevice(@PathParam("type") String type, @PathParam("id") String id, @Valid Device updateDevice) {
+ Device device;
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(id);
+ deviceIdentifier.setType(type);
+ try {
+ device = DeviceMgtAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while getting enrollment details of the device that carries the id '" +
+ id + "'";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+
+ if (updateDevice == null) {
+ String errorMessage = "The payload of the device enrollment is incorrect.";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build();
+ }
+ if (device == null) {
+ String errorMessage = "The device to be modified doesn't exist.";
+ log.error(errorMessage);
+ return Response.status(Response.Status.NOT_FOUND).entity(errorMessage).build();
+ }
+ if (device.getEnrolmentInfo().getStatus() == EnrolmentInfo.Status.ACTIVE ) {
+ DeviceAccessAuthorizationService deviceAccessAuthorizationService =
+ DeviceMgtAPIUtils.getDeviceAccessAuthorizationService();
+ boolean status;
+ try {
+ status = deviceAccessAuthorizationService.isUserAuthorized(new DeviceIdentifier(id, type));
+ } catch (DeviceAccessAuthorizationException e) {
+ String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
+ id + "'";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ if (!status) {
+ return Response.status(Response.Status.UNAUTHORIZED).build();
+ }
+ }
+ if(updateDevice.getEnrolmentInfo() != null) {
+ device.getEnrolmentInfo().setDateOfLastUpdate(System.currentTimeMillis());
+ device.setEnrolmentInfo(device.getEnrolmentInfo());
+ }
+ device.getEnrolmentInfo().setOwner(DeviceMgtAPIUtils.getAuthenticatedUser());
+ if(updateDevice.getDeviceInfo() != null) {
+ device.setDeviceInfo(updateDevice.getDeviceInfo());
+ }
+ device.setDeviceIdentifier(id);
+ if(updateDevice.getDescription() != null) {
+ device.setDescription(updateDevice.getDescription());
+ }
+ if(updateDevice.getName() != null) {
+ device.setName(updateDevice.getName());
+ }
+ if(updateDevice.getFeatures() != null) {
+ device.setFeatures(updateDevice.getFeatures());
+ }
+ if(updateDevice.getProperties() != null) {
+ device.setProperties(updateDevice.getProperties());
+ }
+ boolean result;
+ try {
+ device.setType(type);
+ result = DeviceMgtAPIUtils.getDeviceManagementService().modifyEnrollment(device);
+ if (result) {
+ return Response.status(Response.Status.ACCEPTED).build();
+ } else {
+ return Response.status(Response.Status.NOT_MODIFIED).build();
+ }
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
+ id + "'";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
+
+ @POST
+ @Path("/events/publish/{type}/{deviceId}")
+ @Override
+ public Response publishEvents(@Valid Map payload, @PathParam("type") String type
+ , @PathParam("deviceId") String deviceId) {
+
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
+ try {
+ if (payload == null) {
+ String msg = "invalid payload structure";
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ } else {
+ boolean authorized = DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized
+ (new DeviceIdentifier(type, deviceId));
+ if (!authorized) {
+ String msg = "Does not have permission to access the device.";
+ return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();
+ }
+ }
+ Object metaData[] = new Object[1];
+ metaData[0] = deviceId;
+ EventAttributeList eventAttributeList = DeviceMgtAPIUtils.getDynamicEventCache().get(type);
+ if (eventAttributeList == null) {
+ String streamName = DeviceMgtAPIUtils.getStreamDefinition(type, tenantDomain);
+ eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
+ EventStreamDefinitionDto eventStreamDefinitionDto = eventStreamAdminServiceStub.getStreamDefinitionDto(
+ streamName + ":" + Constants.DEFAULT_STREAM_VERSION);
+ if (eventStreamDefinitionDto == null) {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ } else {
+ EventStreamAttributeDto[] eventStreamAttributeDtos = eventStreamDefinitionDto.getPayloadData();
+ List attributes = new ArrayList<>();
+ for (EventStreamAttributeDto eventStreamAttributeDto : eventStreamAttributeDtos) {
+ attributes.add(new Attribute(eventStreamAttributeDto.getAttributeName()
+ , AttributeType.valueOf(eventStreamAttributeDto.getAttributeType().toUpperCase())));
+
+ }
+ if (payload.size() != attributes.size()) {
+ String msg = "Payload does not match with the stream definition";
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ }
+ eventAttributeList = new EventAttributeList();
+ eventAttributeList.setList(attributes);
+ DeviceMgtAPIUtils.getDynamicEventCache().put(type, eventAttributeList);
+ }
+ }
+ int i = 0;
+ Object[] payloadData = new Object[eventAttributeList.getList().size()];
+ for (Attribute attribute : eventAttributeList.getList()) {
+ if (attribute.getType() == AttributeType.INT) {
+ payloadData[i] = ((Double) payload.get(attribute.getName())).intValue();
+ } else if (attribute.getType() == AttributeType.LONG) {
+ payloadData[i] = ((Double) payload.get(attribute.getName())).longValue();
+ } else {
+ payloadData[i] = payload.get(attribute.getName());
+ }
+ i++;
+ }
+
+ if (DeviceMgtAPIUtils.getEventPublisherService().publishEvent(DeviceMgtAPIUtils.getStreamDefinition(type
+ , PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain())
+ , Constants.DEFAULT_STREAM_VERSION, metaData
+ , null, payloadData)) {
+ return Response.status(Response.Status.OK).build();
+ } else {
+ String msg = "Error occurred while publishing the event.";
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ } catch (DataPublisherConfigurationException e) {
+ String msg = "Error occurred while publishing the event.";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (DeviceAccessAuthorizationException e) {
+ String msg = "Error occurred when checking for authorization";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (AxisFault e) {
+ log.error("Failed to retrieve event definitions for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (RemoteException e) {
+ log.error("Failed to connect with the remote services:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (JWTClientException e) {
+ log.error("Failed to generate jwt token for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (UserStoreException e) {
+ log.error("Failed to connect with the user store, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } finally {
+ if (eventStreamAdminServiceStub != null) {
+ try {
+ eventStreamAdminServiceStub.cleanup();
+ } catch (AxisFault axisFault) {
+ log.warn("Failed to clean eventStreamAdminServiceStub");
+ }
+ }
+ }
+ }
+
+ @POST
+ @Path("/events/publish/data/{type}/{deviceId}")
+ @Override
+ public Response publishEvents(@Valid List payload, @PathParam("type") String type
+ , @PathParam("deviceId") String deviceId) {
+
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
+ try {
+ if (payload == null) {
+ String msg = "Invalid payload structure";
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ } else {
+ boolean authorized = DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized
+ (new DeviceIdentifier(type, deviceId));
+ if (!authorized) {
+ String msg = "Does not have permission to access the device.";
+ return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();
+ }
+ }
+ Object metaData[] = new Object[1];
+ metaData[0] = deviceId;
+ EventAttributeList eventAttributeList = DeviceMgtAPIUtils.getDynamicEventCache().get(type);
+ if (eventAttributeList == null) {
+ String streamName = DeviceMgtAPIUtils.getStreamDefinition(type, tenantDomain);
+ eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
+ EventStreamDefinitionDto eventStreamDefinitionDto = eventStreamAdminServiceStub.getStreamDefinitionDto(
+ streamName + ":" + Constants.DEFAULT_STREAM_VERSION);
+ if (eventStreamDefinitionDto == null) {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ } else {
+ EventStreamAttributeDto[] eventStreamAttributeDtos = eventStreamDefinitionDto.getPayloadData();
+ List attributes = new ArrayList<>();
+ for (EventStreamAttributeDto eventStreamAttributeDto : eventStreamAttributeDtos) {
+ attributes.add(new Attribute(eventStreamAttributeDto.getAttributeName()
+ , AttributeType.valueOf(eventStreamAttributeDto.getAttributeType().toUpperCase())));
+
+ }
+ if (payload.size() != attributes.size()) {
+ String msg = "Payload does not match with the stream definition";
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ }
+ eventAttributeList = new EventAttributeList();
+ eventAttributeList.setList(attributes);
+ DeviceMgtAPIUtils.getDynamicEventCache().put(type, eventAttributeList);
+ }
+ }
+ int i = 0;
+ Object[] payloadData = new Object[eventAttributeList.getList().size()];
+ for (Attribute attribute : eventAttributeList.getList()) {
+ if (attribute.getType() == AttributeType.INT) {
+ payloadData[i] = ((Double) payload.get(i)).intValue();
+ } else if (attribute.getType() == AttributeType.LONG) {
+ payloadData[i] = ((Double) payload.get(i)).longValue();
+ } else {
+ payloadData[i] = payload.get(i);
+ }
+ i++;
+ }
+
+ if (DeviceMgtAPIUtils.getEventPublisherService().publishEvent(DeviceMgtAPIUtils.getStreamDefinition(type
+ , PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain())
+ , Constants.DEFAULT_STREAM_VERSION, metaData
+ , null, payloadData)) {
+ return Response.status(Response.Status.OK).build();
+ } else {
+ String msg = "Error occurred while publishing the event.";
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ } catch (DataPublisherConfigurationException e) {
+ String msg = "Error occurred while publishing the event.";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (DeviceAccessAuthorizationException e) {
+ String msg = "Error occurred when checking for authorization";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (AxisFault e) {
+ log.error("Failed to retrieve event definitions for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (RemoteException e) {
+ log.error("Failed to connect with the remote services:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (JWTClientException e) {
+ log.error("Failed to generate jwt token for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (UserStoreException e) {
+ log.error("Failed to connect with the user store, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } finally {
+ if (eventStreamAdminServiceStub != null) {
+ try {
+ eventStreamAdminServiceStub.cleanup();
+ } catch (AxisFault axisFault) {
+ log.warn("Failed to clean eventStreamAdminServiceStub");
+ }
+ }
+ }
+ }
+
+ @GET
+ @Path("/pending/operations/{type}/{id}")
+ public Response getPendingOperations(@PathParam("type") String type, @PathParam("id") String deviceId) {
+ try {
+ if (!DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(type)) {
+ String errorMessage = "Device identifier list is empty";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, type);
+ if (!DeviceMgtAPIUtils.isValidDeviceIdentifier(deviceIdentifier)) {
+ String msg = "Device not found for identifier '" + deviceId + "'";
+ log.error(msg);
+ return Response.status(Response.Status.NO_CONTENT).entity(msg).build();
+ }
+ List extends Operation> operations = DeviceMgtAPIUtils.getDeviceManagementService().getPendingOperations(
+ deviceIdentifier);
+ OperationList operationsList = new OperationList();
+ operationsList.setList(operations);
+ operationsList.setCount(operations.size());
+ return Response.status(Response.Status.OK).entity(operationsList).build();
+ } catch (OperationManagementException e) {
+ String errorMessage = "Issue in retrieving operation management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ } catch (DeviceManagementException e) {
+ String errorMessage = "Issue in retrieving deivce management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ }
+ }
+
+ @GET
+ @Path("/next-pending/operation/{type}/{id}")
+ public Response getNextPendingOperation(@PathParam("type") String type, @PathParam("id") String deviceId) {
+ try {
+ if (!DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(type)) {
+ String errorMessage = "Device type is invalid";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, type);
+ if (!DeviceMgtAPIUtils.isValidDeviceIdentifier(deviceIdentifier)) {
+ String msg = "Device not found for identifier '" + deviceId + "'";
+ log.error(msg);
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ }
+ Operation operation = DeviceMgtAPIUtils.getDeviceManagementService().getNextPendingOperation(
+ deviceIdentifier);
+ return Response.status(Response.Status.OK).entity(operation).build();
+ } catch (OperationManagementException e) {
+ String errorMessage = "Issue in retrieving operation management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ } catch (DeviceManagementException e) {
+ String errorMessage = "Issue in retrieving deivce management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ }
+ }
+
+ @PUT
+ @Path("/operations/{type}/{id}")
+ public Response updateOperation(@PathParam("type") String type, @PathParam("id") String deviceId, @Valid Operation operation) {
+ try {
+ if (!DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(type)) {
+ String errorMessage = "Device type is invalid";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ if (operation == null) {
+ String errorMessage = "Operation cannot empty";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, type);
+ if (!DeviceMgtAPIUtils.isValidDeviceIdentifier(deviceIdentifier)) {
+ String msg = "Device not found for identifier '" + deviceId + "'";
+ log.error(msg);
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ }
+ if (!Operation.Status.ERROR.equals(operation.getStatus()) && operation.getCode() != null &&
+ POLICY_MONITOR.equals(operation.getCode())) {
+ if (log.isDebugEnabled()) {
+ log.info("Received compliance status from POLICY_MONITOR operation ID: " + operation.getId());
+ }
+ List features = getComplianceFeatures(operation.getPayLoad());
+ DeviceMgtAPIUtils.getPolicyManagementService().checkCompliance(deviceIdentifier, features);
+
+ } else {
+ DeviceMgtAPIUtils.getDeviceManagementService().updateOperation(deviceIdentifier, operation);
+ }
+ return Response.status(Response.Status.OK).build();
+ } catch (OperationManagementException e) {
+ String errorMessage = "Issue in retrieving operation management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ } catch (DeviceManagementException e) {
+ String errorMessage = "Issue in retrieving deivce management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ } catch (PolicyComplianceException e) {
+ String errorMessage = "Issue in retrieving deivce management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ }
+ }
+
+ @GET
+ @Path("/status/operations/{type}/{id}")
+ public Response getOperationsByDeviceAndStatus(@PathParam("type") String type, @PathParam("id") String deviceId,
+ @QueryParam("status") Operation.Status status) {
+ if (status == null) {
+ String errorMessage = "Status is empty";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+
+ try {
+ if (!DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(type)) {
+ String errorMessage = "Invalid Device Type";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ List extends Operation> operations = DeviceMgtAPIUtils.getDeviceManagementService()
+ .getOperationsByDeviceAndStatus(new DeviceIdentifier(deviceId, type), status);
+ OperationList operationsList = new OperationList();
+ operationsList.setList(operations);
+ operationsList.setCount(operations.size());
+ return Response.status(Response.Status.OK).entity(operationsList).build();
+ } catch (OperationManagementException e) {
+ String errorMessage = "Issue in retrieving operation management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ } catch (DeviceManagementException e) {
+ String errorMessage = "Issue in retrieving device management service";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
+ }
+ }
+
+ private static List getComplianceFeatures(Object compliancePayload) throws
+ PolicyComplianceException {
+ String compliancePayloadString = new Gson().toJson(compliancePayload);
+ if (compliancePayload == null) {
+ return null;
+ }
+ // Parsing json string to get compliance features.
+ JsonElement jsonElement = new JsonParser().parse(compliancePayloadString);
+
+ JsonArray jsonArray = jsonElement.getAsJsonArray();
+ Gson gson = new Gson();
+ ComplianceFeature complianceFeature;
+ List complianceFeatures = new ArrayList(jsonArray.size());
+
+ for (JsonElement element : jsonArray) {
+ complianceFeature = gson.fromJson(element, ComplianceFeature.class);
+ complianceFeatures.add(complianceFeature);
+ }
+ return complianceFeatures;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java
new file mode 100644
index 0000000000..5a16fbccdb
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java
@@ -0,0 +1,590 @@
+package org.wso2.carbon.device.mgt.jaxrs.service.impl;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Stub;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
+import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
+import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
+import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
+import org.wso2.carbon.analytics.dataservice.commons.SortByField;
+import org.wso2.carbon.analytics.dataservice.commons.SortType;
+import org.wso2.carbon.analytics.stream.persistence.stub
+ .EventStreamPersistenceAdminServiceEventStreamPersistenceAdminServiceExceptionException;
+import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceAdminServiceStub;
+import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTable;
+import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTableRecord;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.CarbonContext;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.DeviceTypeEvent;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventRecords;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AttributeType;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeList;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.TransportType;
+import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceEventManagementService;
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
+import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceCallbackHandler;
+import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub;
+import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceCallbackHandler;
+import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub;
+import org.wso2.carbon.event.receiver.stub.types.BasicInputAdapterPropertyDto;
+import org.wso2.carbon.event.receiver.stub.types.EventReceiverConfigurationDto;
+import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub;
+import org.wso2.carbon.event.stream.stub.types.EventStreamAttributeDto;
+import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto;
+import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
+import org.wso2.carbon.user.api.UserStoreException;
+import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
+
+import javax.validation.Valid;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This is used for device type integration with DAS, to create streams and receiver dynamically and a common endpoint
+ * to retrieve data.
+ */
+@Path("/events")
+public class DeviceEventManagementServiceImpl implements DeviceEventManagementService {
+
+ private static final Log log = LogFactory.getLog(DeviceEventManagementServiceImpl.class);
+
+ private static final String DEFAULT_EVENT_STORE_NAME = "EVENT_STORE";
+ private static final String DEFAULT_WEBSOCKET_PUBLISHER_ADAPTER_TYPE = "secured-websocket";
+ private static final String OAUTH_MQTT_ADAPTER_TYPE = "oauth-mqtt";
+ private static final String THRIFT_ADAPTER_TYPE = "iot-event";
+ private static final String DEFAULT_DEVICE_ID_ATTRIBUTE = "deviceId";
+ private static final String DEFAULT_META_DEVICE_ID_ATTRIBUTE = "meta_deviceId";
+ private static final String MQTT_CONTENT_TRANSFORMER = "device-meta-transformer";
+ private static final String MQTT_CONTENT_TRANSFORMER_TYPE = "contentTransformer";
+ private static final String MQTT_CONTENT_VALIDATOR_TYPE = "contentValidator";
+ private static final String MQTT_CONTENT_VALIDATOR = "default";
+ private static final String TIMESTAMP_FIELD_NAME = "_timestamp";
+
+ /**
+ * Retrieves the stream definition from das for the given device type.
+ * @return dynamic event attribute list
+ */
+ @GET
+ @Path("/{type}")
+ @Override
+ public Response getDeviceTypeEventDefinition(@PathParam("type") String deviceType) {
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
+ EventReceiverAdminServiceStub eventReceiverAdminServiceStub = null;
+ try {
+ if (deviceType == null ||
+ !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) {
+ String errorMessage = "Invalid device type";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ String streamName = DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain);
+ eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
+ EventStreamDefinitionDto eventStreamDefinitionDto = eventStreamAdminServiceStub.getStreamDefinitionDto(
+ streamName + ":" + Constants.DEFAULT_STREAM_VERSION);
+ if (eventStreamDefinitionDto == null) {
+ return Response.status(Response.Status.NO_CONTENT).build();
+ }
+
+ EventStreamAttributeDto[] eventStreamAttributeDtos = eventStreamDefinitionDto.getPayloadData();
+ EventAttributeList eventAttributeList = new EventAttributeList();
+ List attributes = new ArrayList<>();
+ for (EventStreamAttributeDto eventStreamAttributeDto : eventStreamAttributeDtos) {
+ attributes.add(new Attribute(eventStreamAttributeDto.getAttributeName()
+ , AttributeType.valueOf(eventStreamAttributeDto.getAttributeType().toUpperCase())));
+ }
+ eventAttributeList.setList(attributes);
+
+ DeviceTypeEvent deviceTypeEvent = new DeviceTypeEvent();
+ deviceTypeEvent.setEventAttributeList(eventAttributeList);
+ deviceTypeEvent.setTransportType(TransportType.HTTP);
+ eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
+ EventReceiverConfigurationDto eventReceiverConfigurationDto = eventReceiverAdminServiceStub
+ .getActiveEventReceiverConfiguration(getReceiverName(deviceType, tenantDomain, TransportType.MQTT));
+ if (eventReceiverConfigurationDto != null) {
+ deviceTypeEvent.setTransportType(TransportType.MQTT);
+ }
+ return Response.ok().entity(deviceTypeEvent).build();
+ } catch (AxisFault e) {
+ log.error("Failed to retrieve event definitions for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (RemoteException e) {
+ log.error("Failed to connect with the remote services:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (JWTClientException e) {
+ log.error("Failed to generate jwt token for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (UserStoreException e) {
+ log.error("Failed to connect with the user store, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (DeviceManagementException e) {
+ log.error("Failed to access device management service, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } finally {
+ cleanup(eventStreamAdminServiceStub);
+ cleanup(eventReceiverAdminServiceStub);
+ }
+ }
+
+ /**
+ * Deploy Event Stream, Receiver, Publisher and Store Configuration.
+ */
+ @POST
+ @Path("/{type}")
+ @Override
+ public Response deployDeviceTypeEventDefinition(@PathParam("type") String deviceType,
+ @Valid DeviceTypeEvent deviceTypeEvent) {
+ TransportType transportType = deviceTypeEvent.getTransportType();
+ EventAttributeList eventAttributes = deviceTypeEvent.getEventAttributeList();
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ try {
+ if (eventAttributes == null || eventAttributes.getList() == null || eventAttributes.getList().size() == 0 ||
+ deviceType == null || transportType == null ||
+ !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) {
+ String errorMessage = "Invalid Payload";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ String streamName = DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain);
+ String streamNameWithVersion = streamName + ":" + Constants.DEFAULT_STREAM_VERSION;
+ publishStreamDefinitons(streamName, Constants.DEFAULT_STREAM_VERSION, deviceType, eventAttributes);
+ publishEventReceivers(streamNameWithVersion, transportType, tenantDomain, deviceType);
+ publishEventStore(streamName, Constants.DEFAULT_STREAM_VERSION, eventAttributes);
+ publishWebsocketPublisherDefinition(streamNameWithVersion, deviceType);
+ try {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
+ MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
+ if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
+ publishStreamDefinitons(streamName, Constants.DEFAULT_STREAM_VERSION, deviceType, eventAttributes);
+ publishEventReceivers(streamNameWithVersion, transportType, tenantDomain, deviceType);
+ }
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ return Response.ok().build();
+ } catch (AxisFault e) {
+ log.error("Failed to create event definitions for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (RemoteException e) {
+ log.error("Failed to connect with the remote services:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (JWTClientException e) {
+ log.error("Failed to generate jwt token for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (UserStoreException e) {
+ log.error("Failed to connect with the user store, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (DeviceManagementException e) {
+ log.error("Failed to access device management service, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (EventStreamPersistenceAdminServiceEventStreamPersistenceAdminServiceExceptionException e) {
+ log.error("Failed to create event store for, tenantDomain: " + tenantDomain + " deviceType" + deviceType,
+ e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
+ }
+
+ /**
+ * Delete device type specific artifacts from DAS.
+ */
+ @DELETE
+ @Path("/{type}")
+ @Override
+ public Response deleteDeviceTypeEventDefinitions(@PathParam("type") String deviceType) {
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ EventReceiverAdminServiceStub eventReceiverAdminServiceStub = null;
+ EventPublisherAdminServiceStub eventPublisherAdminServiceStub = null;
+ EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
+
+ EventReceiverAdminServiceStub tenantBasedEventReceiverAdminServiceStub = null;
+ EventStreamAdminServiceStub tenantBasedEventStreamAdminServiceStub = null;
+ try {
+ if (deviceType == null ||
+ !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) {
+ String errorMessage = "Invalid device type";
+ return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build();
+ }
+ String eventPublisherName = deviceType.trim().replace(" ", "_") + "_websocket_publisher";
+ String streamName = DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain);
+ eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
+ if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamName + ":" + Constants.DEFAULT_STREAM_VERSION) == null) {
+ return Response.status(Response.Status.NO_CONTENT).build();
+ }
+ eventStreamAdminServiceStub.removeEventStreamDefinition(streamName, Constants.DEFAULT_STREAM_VERSION);
+ EventReceiverAdminServiceCallbackHandler eventReceiverAdminServiceCallbackHandler =
+ new EventReceiverAdminServiceCallbackHandler() {};
+ EventPublisherAdminServiceCallbackHandler eventPublisherAdminServiceCallbackHandler =
+ new EventPublisherAdminServiceCallbackHandler() {};
+
+
+ String eventReceiverName = getReceiverName(deviceType, tenantDomain, TransportType.MQTT);
+ eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
+ if (eventReceiverAdminServiceStub.getInactiveEventReceiverConfigurationContent(eventReceiverName) == null) {
+ eventReceiverName = getReceiverName(deviceType, tenantDomain, TransportType.HTTP);
+ }
+ eventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration(eventReceiverName
+ , eventReceiverAdminServiceCallbackHandler);
+
+ eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub();
+ eventPublisherAdminServiceStub.startundeployInactiveEventPublisherConfiguration(eventPublisherName
+ , eventPublisherAdminServiceCallbackHandler);
+
+ try {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
+ MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
+ if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
+ tenantBasedEventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
+ tenantBasedEventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
+ tenantBasedEventStreamAdminServiceStub.removeEventStreamDefinition(streamName,
+ Constants.DEFAULT_STREAM_VERSION);
+
+ tenantBasedEventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration(
+ eventReceiverName, eventReceiverAdminServiceCallbackHandler);
+
+ }
+ } finally {
+ cleanup(tenantBasedEventReceiverAdminServiceStub);
+ cleanup(tenantBasedEventStreamAdminServiceStub);
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ return Response.ok().build();
+ } catch (AxisFault e) {
+ log.error("Failed to delete event definitions for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (RemoteException e) {
+ log.error("Failed to connect with the remote services:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (JWTClientException e) {
+ log.error("Failed to generate jwt token for tenantDomain:" + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (UserStoreException e) {
+ log.error("Failed to connect with the user store, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (DeviceManagementException e) {
+ log.error("Failed to access device management service, tenantDomain: " + tenantDomain, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } finally {
+ cleanup(eventStreamAdminServiceStub);
+ cleanup(eventPublisherAdminServiceStub);
+ cleanup(eventReceiverAdminServiceStub);
+ cleanup(eventReceiverAdminServiceStub);
+ cleanup(eventStreamAdminServiceStub);
+ }
+ }
+
+ /**
+ * Returns device specific data for the give period of time.
+ */
+ @GET
+ @Path("/{type}/{deviceId}")
+ @Override
+ public Response getData(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
+ @QueryParam("to") long to, @PathParam("type") String deviceType, @QueryParam("offset")
+ int offset, @QueryParam("limit") int limit) {
+ if (from == 0 || to == 0) {
+ String errorMessage = "Invalid values for from/to";
+ return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage).build();
+ }
+ String fromDate = String.valueOf(from);
+ String toDate = String.valueOf(to);
+ String query = DEFAULT_META_DEVICE_ID_ATTRIBUTE + ":" + deviceId
+ + " AND _timestamp : [" + fromDate + " TO " + toDate + "]";
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ String sensorTableName = getTableName(DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain));
+ try {
+ if (deviceType == null ||
+ !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) {
+ String errorMessage = "Invalid device type";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
+ new DeviceIdentifier(deviceId, deviceType))) {
+ return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
+ }
+ List sortByFields = new ArrayList<>();
+ SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC);
+ sortByFields.add(sortByField);
+ EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, offset, limit);
+ return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build();
+ } catch (AnalyticsException e) {
+ String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
+ log.error(errorMsg);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
+ } catch (DeviceAccessAuthorizationException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (DeviceManagementException e) {
+ String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
+ log.error(errorMsg);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
+ }
+ }
+
+ /**
+ * Returns the last know data point of the device type.
+ */
+ @GET
+ @Path("/last-known/{type}/{deviceId}")
+ @Override
+ public Response getLastKnownData(@PathParam("deviceId") String deviceId, @PathParam("type") String deviceType) {
+ String query = DEFAULT_META_DEVICE_ID_ATTRIBUTE + ":" + deviceId;
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ String sensorTableName = getTableName(DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain));
+ try {
+ if (deviceType == null ||
+ !DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(deviceType)) {
+ String errorMessage = "Invalid device type";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
+ new DeviceIdentifier(deviceId, deviceType))) {
+ return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
+ }
+ List sortByFields = new ArrayList<>();
+ SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC);
+ sortByFields.add(sortByField);
+ EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 1);
+ return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build();
+ } catch (AnalyticsException e) {
+ String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
+ log.error(errorMsg);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
+ } catch (DeviceAccessAuthorizationException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ } catch (DeviceManagementException e) {
+ String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
+ log.error(errorMsg);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
+ }
+ }
+
+ private void publishEventReceivers(String streamNameWithVersion, TransportType transportType
+ , String requestedTenantDomain, String deviceType)
+ throws RemoteException, UserStoreException, JWTClientException {
+ EventReceiverAdminServiceStub receiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
+ try {
+ TransportType transportTypeToBeRemoved = TransportType.HTTP;
+ if (transportType == TransportType.HTTP) {
+ transportTypeToBeRemoved = TransportType.MQTT;
+ }
+ String eventRecieverNameTobeRemoved = getReceiverName(deviceType, requestedTenantDomain, transportTypeToBeRemoved);
+ EventReceiverConfigurationDto eventReceiverConfigurationDto = receiverAdminServiceStub
+ .getActiveEventReceiverConfiguration(eventRecieverNameTobeRemoved);
+ if (eventReceiverConfigurationDto != null) {
+ EventReceiverAdminServiceCallbackHandler eventReceiverAdminServiceCallbackHandler =
+ new EventReceiverAdminServiceCallbackHandler() {};
+ receiverAdminServiceStub.startundeployActiveEventReceiverConfiguration(eventRecieverNameTobeRemoved
+ , eventReceiverAdminServiceCallbackHandler);
+ }
+
+ String adapterType = OAUTH_MQTT_ADAPTER_TYPE;
+ BasicInputAdapterPropertyDto basicInputAdapterPropertyDtos[];
+ if (transportType == TransportType.MQTT) {
+ basicInputAdapterPropertyDtos = new BasicInputAdapterPropertyDto[3];
+ basicInputAdapterPropertyDtos[0] = getBasicInputAdapterPropertyDto("topic", requestedTenantDomain
+ + "/" + deviceType + "/+/events");
+ basicInputAdapterPropertyDtos[1] = getBasicInputAdapterPropertyDto(MQTT_CONTENT_TRANSFORMER_TYPE
+ , MQTT_CONTENT_TRANSFORMER);
+ basicInputAdapterPropertyDtos[2] = getBasicInputAdapterPropertyDto(MQTT_CONTENT_VALIDATOR_TYPE
+ , MQTT_CONTENT_VALIDATOR);
+ } else {
+ adapterType = THRIFT_ADAPTER_TYPE;
+ basicInputAdapterPropertyDtos = new BasicInputAdapterPropertyDto[1];
+ basicInputAdapterPropertyDtos[0] = getBasicInputAdapterPropertyDto("events.duplicated.in.cluster", "false");
+ }
+ String eventRecieverName = getReceiverName(deviceType, requestedTenantDomain, transportType);
+ if (receiverAdminServiceStub.getActiveEventReceiverConfiguration(eventRecieverName) == null) {
+ if (transportType == TransportType.MQTT) {
+ receiverAdminServiceStub.deployJsonEventReceiverConfiguration(eventRecieverName, streamNameWithVersion
+ , adapterType, null, basicInputAdapterPropertyDtos, false);
+ } else {
+ receiverAdminServiceStub.deployWso2EventReceiverConfiguration(eventRecieverName, streamNameWithVersion
+ , adapterType, null, null, null, basicInputAdapterPropertyDtos, false, null);
+ }
+ }
+ } finally {
+ cleanup(receiverAdminServiceStub);
+ }
+ }
+
+ private void publishStreamDefinitons(String streamName, String version, String deviceType
+ , EventAttributeList eventAttributes)
+ throws RemoteException, UserStoreException, JWTClientException {
+ EventStreamAdminServiceStub eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
+ try {
+ EventStreamDefinitionDto eventStreamDefinitionDto = new EventStreamDefinitionDto();
+ eventStreamDefinitionDto.setName(streamName);
+ eventStreamDefinitionDto.setVersion(version);
+ EventStreamAttributeDto eventStreamAttributeDtos[] =
+ new EventStreamAttributeDto[eventAttributes.getList().size()];
+ EventStreamAttributeDto metaStreamAttributeDtos[] =
+ new EventStreamAttributeDto[1];
+ int i = 0;
+ for (Attribute attribute : eventAttributes.getList()) {
+ EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto();
+ eventStreamAttributeDto.setAttributeName(attribute.getName());
+ eventStreamAttributeDto.setAttributeType(attribute.getType().toString());
+ eventStreamAttributeDtos[i] = eventStreamAttributeDto;
+ i++;
+ }
+
+ EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto();
+ eventStreamAttributeDto.setAttributeName(DEFAULT_DEVICE_ID_ATTRIBUTE);
+ eventStreamAttributeDto.setAttributeType(AttributeType.STRING.toString());
+ metaStreamAttributeDtos[0] = eventStreamAttributeDto;
+ eventStreamDefinitionDto.setPayloadData(eventStreamAttributeDtos);
+ eventStreamDefinitionDto.setMetaData(metaStreamAttributeDtos);
+ String streamId = streamName + ":" + version;
+ if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) != null) {
+ eventStreamAdminServiceStub.editEventStreamDefinitionAsDto(eventStreamDefinitionDto, streamId);
+ } else {
+ eventStreamAdminServiceStub.addEventStreamDefinitionAsDto(eventStreamDefinitionDto);
+ }
+ } finally {
+ cleanup(eventStreamAdminServiceStub);
+ }
+ }
+
+ private void publishEventStore(String streamName, String version, EventAttributeList eventAttributes)
+ throws RemoteException, UserStoreException, JWTClientException,
+ EventStreamPersistenceAdminServiceEventStreamPersistenceAdminServiceExceptionException {
+ EventStreamPersistenceAdminServiceStub eventStreamPersistenceAdminServiceStub =
+ DeviceMgtAPIUtils.getEventStreamPersistenceAdminServiceStub();
+ try {
+ AnalyticsTable analyticsTable = new AnalyticsTable();
+ analyticsTable.setRecordStoreName(DEFAULT_EVENT_STORE_NAME);
+ analyticsTable.setStreamVersion(version);
+ analyticsTable.setTableName(streamName);
+ analyticsTable.setMergeSchema(false);
+ analyticsTable.setPersist(true);
+ AnalyticsTableRecord analyticsTableRecords[] = new AnalyticsTableRecord[eventAttributes.getList().size() + 1];
+ int i = 0;
+ for (Attribute attribute : eventAttributes.getList()) {
+ AnalyticsTableRecord analyticsTableRecord = new AnalyticsTableRecord();
+ analyticsTableRecord.setColumnName(attribute.getName());
+ analyticsTableRecord.setColumnType(attribute.getType().toString().toUpperCase());
+ analyticsTableRecord.setFacet(false);
+ analyticsTableRecord.setIndexed(false);
+ analyticsTableRecord.setPersist(true);
+ analyticsTableRecord.setPrimaryKey(false);
+ analyticsTableRecord.setScoreParam(false);
+ analyticsTableRecords[i] = analyticsTableRecord;
+ i++;
+ }
+ AnalyticsTableRecord analyticsTableRecord = new AnalyticsTableRecord();
+ analyticsTableRecord.setColumnName(DEFAULT_META_DEVICE_ID_ATTRIBUTE);
+ analyticsTableRecord.setColumnType(AttributeType.STRING.toString().toUpperCase());
+ analyticsTableRecord.setFacet(false);
+ analyticsTableRecord.setIndexed(true);
+ analyticsTableRecord.setPersist(true);
+ analyticsTableRecord.setPrimaryKey(false);
+ analyticsTableRecord.setScoreParam(false);
+ analyticsTableRecords[i] = analyticsTableRecord;
+ analyticsTable.setAnalyticsTableRecords(analyticsTableRecords);
+ eventStreamPersistenceAdminServiceStub.addAnalyticsTable(analyticsTable);
+ } finally {
+ cleanup(eventStreamPersistenceAdminServiceStub);
+ }
+ }
+
+ private void publishWebsocketPublisherDefinition(String streamNameWithVersion, String deviceType)
+ throws RemoteException, UserStoreException, JWTClientException {
+ EventPublisherAdminServiceStub eventPublisherAdminServiceStub = DeviceMgtAPIUtils
+ .getEventPublisherAdminServiceStub();
+ try {
+ String eventPublisherName = deviceType.trim().replace(" ", "_") + "_websocket_publisher";
+ if (eventPublisherAdminServiceStub.getActiveEventPublisherConfiguration(eventPublisherName) == null) {
+ eventPublisherAdminServiceStub.deployJsonEventPublisherConfiguration(eventPublisherName
+ , streamNameWithVersion, DEFAULT_WEBSOCKET_PUBLISHER_ADAPTER_TYPE, null, null
+ , null, false);
+ }
+ } finally {
+ cleanup(eventPublisherAdminServiceStub);
+ }
+ }
+
+ private BasicInputAdapterPropertyDto getBasicInputAdapterPropertyDto(String key, String value) {
+ BasicInputAdapterPropertyDto basicInputAdapterPropertyDto = new BasicInputAdapterPropertyDto();
+ basicInputAdapterPropertyDto.setKey(key);
+ basicInputAdapterPropertyDto.setValue(value);
+ return basicInputAdapterPropertyDto;
+ }
+
+ private String getTableName(String streamName) {
+ return streamName.toUpperCase().replace('.', '_');
+ }
+
+ private String getReceiverName(String deviceType, String tenantDomain, TransportType transportType) {
+ return deviceType.replace(" ", "_").trim() + "-" + tenantDomain + "-" + transportType.toString() + "-receiver";
+ }
+
+ private static AnalyticsDataAPI getAnalyticsDataAPI() {
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ AnalyticsDataAPI analyticsDataAPI =
+ (AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null);
+ if (analyticsDataAPI == null) {
+ String msg = "Analytics api service has not initialized.";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ return analyticsDataAPI;
+ }
+
+ private static EventRecords getAllEventsForDevice(String tableName, String query, List sortByFields
+ , int offset, int limit) throws AnalyticsException {
+ int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
+ AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();
+ EventRecords eventRecords = new EventRecords();
+ int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
+ if (eventCount == 0) {
+ eventRecords.setCount(0);
+ }
+ List resultEntries = analyticsDataAPI.search(tenantId, tableName, query, offset, limit,
+ sortByFields);
+ List recordIds = getRecordIds(resultEntries);
+ AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
+ eventRecords.setCount(eventCount);
+ eventRecords.setList(AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response));
+ return eventRecords;
+ }
+
+ private static List getRecordIds(List searchResults) {
+ List ids = new ArrayList<>();
+ for (SearchResultEntry searchResult : searchResults) {
+ ids.add(searchResult.getId());
+ }
+ return ids;
+ }
+
+ private void cleanup(Stub stub) {
+ if (stub != null) {
+ try {
+ stub.cleanup();
+ } catch (AxisFault axisFault) {
+ log.warn("Failed to clean the stub " + stub.getClass());
+ }
+ }
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java
index 2699c7c4b5..a269a67c21 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java
@@ -24,10 +24,13 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
+import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
@@ -35,6 +38,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
@@ -44,6 +48,8 @@ import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
+import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
+import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
@@ -51,6 +57,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceCompliance;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
+import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
@@ -58,6 +65,8 @@ import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
+import javax.security.auth.login.Configuration;
+import javax.validation.Valid;
import javax.validation.constraints.Size;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -83,6 +92,27 @@ import java.util.List;
public class DeviceManagementServiceImpl implements DeviceManagementService {
private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class);
+ public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
+
+ @GET
+ @Path("/{type}/{id}/status")
+ @Override
+ public Response isEnrolled(@PathParam("type") String type, @PathParam("id") String id) {
+ boolean result;
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type);
+ try {
+ result = DeviceMgtAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier);
+ if (result) {
+ return Response.status(Response.Status.OK).build();
+ } else {
+ return Response.status(Response.Status.NO_CONTENT).build();
+ }
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while checking enrollment status of the device.";
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ }
@GET
@Override
@@ -552,7 +582,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
RequestValidationUtil.validateDeviceIdentifier(type, id);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy;
- NonComplianceData complianceData = null;
+ NonComplianceData complianceData;
DeviceCompliance deviceCompliance = new DeviceCompliance();
try {
@@ -618,4 +648,78 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
+
+ @POST
+ @Path("/{type}/operations")
+ public Response addOperation(@PathParam("type") String type, @Valid OperationRequest operationRequest) {
+ try {
+ if (operationRequest == null || operationRequest.getDeviceIdentifiers() == null
+ || operationRequest.getOperation() == null) {
+ String errorMessage = "Operation cannot be empty";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ if (!DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes().contains(type)) {
+ String errorMessage = "Device Type is invalid";
+ log.error(errorMessage);
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ Operation.Type operationType = operationRequest.getOperation().getType();
+ if (operationType == Operation.Type.COMMAND || operationType == Operation.Type.CONFIG) {
+ DeviceIdentifier deviceIdentifier;
+ List deviceIdentifiers = new ArrayList<>();
+ for (String deviceId : operationRequest.getDeviceIdentifiers()) {
+ deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(type);
+ deviceIdentifiers.add(deviceIdentifier);
+ }
+ Operation operation;
+ if (operationType == Operation.Type.COMMAND) {
+ Operation commandOperation = operationRequest.getOperation();
+ operation = new CommandOperation();
+ operation.setType(Operation.Type.COMMAND);
+ operation.setCode(commandOperation.getCode());
+ operation.setEnabled(commandOperation.isEnabled());
+ operation.setStatus(commandOperation.getStatus());
+
+ } else {
+ Operation configOperation = operationRequest.getOperation();
+ operation = new ConfigOperation();
+ operation.setType(Operation.Type.CONFIG);
+ operation.setCode(configOperation.getCode());
+ operation.setEnabled(configOperation.isEnabled());
+ operation.setPayLoad(configOperation.getPayLoad());
+ operation.setStatus(configOperation.getStatus());
+ }
+ String date = new SimpleDateFormat(DATE_FORMAT_NOW).format(new Date());
+ operation.setCreatedTimeStamp(date);
+ Activity activity = DeviceMgtAPIUtils.getDeviceManagementService().addOperation(type, operation,
+ deviceIdentifiers);
+ return Response.status(Response.Status.CREATED).entity(activity).build();
+ } else {
+ String message = "Only Command and Config operation is supported through this api";
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(message).build();
+ }
+
+ } catch (InvalidDeviceException e) {
+ String errorMessage = "Invalid Device Identifiers found.";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
+ } catch (OperationManagementException e) {
+ String errorMessage = "Issue in retrieving operation management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
+ } catch (DeviceManagementException e) {
+ String errorMessage = "Issue in retrieving deivce management service instance";
+ log.error(errorMessage, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
+ } catch (InvalidConfigurationException e) {
+ log.error("failed to add operation", e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java
index 3bd43681e9..5fdc06a501 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java
@@ -23,6 +23,9 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
+import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
@@ -35,7 +38,9 @@ import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
+import java.util.ArrayList;
import java.util.List;
@Path("/device-types")
@@ -86,4 +91,62 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
return Response.status(Response.Status.OK).entity(features).build();
}
+ @Override
+ @GET
+ @Path("/config")
+ public Response getDeviceTypes() {
+ try {
+ List deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes();
+ List filteredDeviceTypes = new ArrayList<>();
+ for (DeviceType deviceType : deviceTypes) {
+ filteredDeviceTypes.add(clearMetaEntryInfo(deviceType));
+ }
+ return Response.status(Response.Status.OK).entity(filteredDeviceTypes).build();
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred at server side while fetching device type.";
+ log.error(msg, e);
+ return Response.serverError().entity(msg).build();
+ }
+ }
+
+ @Override
+ @GET
+ @Path("/config/{type}")
+ public Response getDeviceTypeByName(@PathParam("type") String type) {
+ if (type != null && type.length() > 0) {
+ try {
+ DeviceType deviceType = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(type);
+ if (deviceType == null) {
+ String msg = "Device type does not exist, " + type;
+ return Response.status(Response.Status.NO_CONTENT).entity(msg).build();
+ }
+ return Response.status(Response.Status.OK).entity(deviceType).build();
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred at server side while fetching device type.";
+ log.error(msg, e);
+ return Response.serverError().entity(msg).build();
+ }
+ } else {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ }
+
+ /**
+ * This cleans up the configs that should not be exposed to iot users.
+ * @param deviceType
+ * @return
+ */
+ private DeviceType clearMetaEntryInfo(DeviceType deviceType) {
+ DeviceTypeMetaDefinition metaDefinition = deviceType.getDeviceTypeMetaDefinition();
+ if (metaDefinition != null) {
+ metaDefinition.setInitialOperationConfig(null);
+ if (metaDefinition.getPushNotificationConfig() != null) {
+ metaDefinition.setPushNotificationConfig(new PushNotificationConfig(metaDefinition.
+ getPushNotificationConfig().getType(), false, null));
+ }
+ deviceType.setDeviceTypeMetaDefinition(metaDefinition);
+ }
+ return deviceType;
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java
index e947c258c0..d396237df4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java
@@ -22,6 +22,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.CarbonContext;
+import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
@@ -30,6 +32,9 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer;
+import org.wso2.carbon.registry.api.Registry;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.registry.resource.services.utils.ChangeRolePermissionsUtil;
import org.wso2.carbon.user.api.*;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
import org.wso2.carbon.user.mgt.UserRealmProxy;
@@ -296,6 +301,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
}
}
userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), permissions);
+ authorizeRoleForAppmgt(roleInfo.getRoleName(), roleInfo.getPermissions());
//TODO fix what's returned in the entity
return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleInfo.getRoleName(), "UTF-8"))).
@@ -450,6 +456,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
authorizationManager.authorizeRole(roleName, permission, CarbonConstants.UI_PERMISSION_ACTION);
}
}
+ authorizeRoleForAppmgt(roleName, roleInfo.getPermissions());
}
//TODO: Need to send the updated role information in the entity back to the client
return Response.status(Response.Status.OK).entity("Role '" + roleInfo.getRoleName() + "' has " +
@@ -467,6 +474,59 @@ public class RoleManagementServiceImpl implements RoleManagementService {
}
}
+ /**
+ * When presented with role and a set of permissions, if given role has permission to
+ * perform mobile app management, said role will be given rights mobile app collection in the
+ * governance registry.
+ *
+ * @param role
+ * @param permissions
+ * @return state of role update Operation
+ */
+ private boolean authorizeRoleForAppmgt(String role, String[] permissions) {
+ String permissionString =
+ "ra^true:rd^false:wa^true:wd^false:da^true:dd^false:aa^true:ad^false";
+ String resourcePath = "/_system/governance/mobileapps/";
+ boolean appmPermAvailable = false;
+
+ if (permissions != null) {
+ for (int i = 0; i < permissions.length; i++)
+ switch (permissions[i]) {
+ case "/permission/admin/manage/mobileapp":
+ appmPermAvailable = true;
+ break;
+ case "/permission/admin/manage/mobileapp/create":
+ appmPermAvailable = true;
+ break;
+ case "/permission/admin/manage/mobileapp/publish":
+ appmPermAvailable = true;
+ break;
+ }
+ }
+
+ if (appmPermAvailable) {
+ try {
+ Registry registry = CarbonContext.getThreadLocalCarbonContext().
+ getRegistry(RegistryType.SYSTEM_GOVERNANCE);
+ ChangeRolePermissionsUtil.changeRolePermissions((UserRegistry) registry,
+ resourcePath, role + ":" + permissionString);
+
+ return true;
+ } catch (Exception e) {
+ String msg = "Error while retrieving user registry in order to update permissions "
+ + "for resource : " + resourcePath;
+ log.error(msg, e);
+ return false;
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Mobile App Management permissions not selected, therefore role : " +
+ role + " not given permission for registry collection : " + resourcePath);
+ }
+ return false;
+ }
+ }
+
@DELETE
@Path("/{roleName}")
@Override
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java
index 9a968a3ac5..a6d98fc73c 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java
@@ -54,13 +54,13 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
RequestValidationUtil.validatePaginationParameters(offset, limit);
+ int currentTenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
+ if (MultitenantConstants.SUPER_TENANT_ID != currentTenantId) {
+ return Response.status(Response.Status.UNAUTHORIZED).entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage(
+ "Current logged in user is not authorized to perform this operation").build()).build();
+ }
try {
- int currentTenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
- if (MultitenantConstants.SUPER_TENANT_ID != currentTenantId) {
- return Response.status(Response.Status.UNAUTHORIZED).entity(
- new ErrorResponse.ErrorResponseBuilder().setMessage(
- "Current logged in user is not authorized to perform this operation").build()).build();
- }
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(DeviceMgtAPIUtils.getTenantId(tenantDomain));
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java
new file mode 100644
index 0000000000..3cc9401449
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
+import org.wso2.carbon.device.mgt.core.dto.DeviceType;
+import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementAdminService;
+import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+@Path("/admin/device-types")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagementAdminService {
+
+ private static final Log log = LogFactory.getLog(DeviceTypeManagementAdminServiceImpl.class);
+ private static final String DEVICETYPE_REGEX_PATTERN = "^[^ /]+$";
+ private static final Pattern patternMatcher = Pattern.compile(DEVICETYPE_REGEX_PATTERN);
+
+ @GET
+ @Override
+ public Response getDeviceTypes() {
+ try {
+ List deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes();
+ return Response.status(Response.Status.OK).entity(deviceTypes).build();
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while fetching the list of device types.";
+ log.error(msg, e);
+ return Response.serverError().entity(
+ new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
+ }
+ }
+
+ @Override
+ @POST
+ public Response addDeviceType(DeviceType deviceType) {
+ if (deviceType != null && deviceType.getDeviceTypeMetaDefinition() != null) {
+ try {
+ if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(deviceType.getName()) != null) {
+ String msg = "Device type already available, " + deviceType.getName();
+ return Response.status(Response.Status.CONFLICT).entity(msg).build();
+ }
+ Matcher matcher = patternMatcher.matcher(deviceType.getName());
+ if(matcher.find()) {
+ DeviceManagementService httpDeviceTypeManagerService =
+ DeviceMgtAPIUtils.getDeviceTypeGeneratorService()
+ .populateDeviceManagementService(deviceType.getName(),
+ deviceType.getDeviceTypeMetaDefinition());
+ DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
+ return Response.status(Response.Status.OK).build();
+ } else {
+ return Response.status(Response.Status.BAD_REQUEST).entity("Device type name does not match the pattern "
+ + DEVICETYPE_REGEX_PATTERN).build();
+ }
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred at server side while adding a device type.";
+ log.error(msg, e);
+ return Response.serverError().entity(msg).build();
+ } catch (InvalidConfigurationException e) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
+ }
+ } else {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ }
+
+ @Override
+ @PUT
+ public Response updateDeviceType(DeviceType deviceType) {
+ if (deviceType != null && deviceType.getDeviceTypeMetaDefinition() != null) {
+ try {
+ if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(deviceType.getName()) == null) {
+ String msg = "Device type does not exist, " + deviceType.getName();
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ }
+ DeviceManagementService httpDeviceTypeManagerService = DeviceMgtAPIUtils.getDeviceTypeGeneratorService()
+ .populateDeviceManagementService(deviceType.getName(), deviceType.getDeviceTypeMetaDefinition());
+ DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
+ return Response.status(Response.Status.OK).build();
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred at server side while updating the device type.";
+ log.error(msg, e);
+ return Response.serverError().entity(msg).build();
+ } catch (InvalidConfigurationException e) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
+ }
+ } else {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java
index c5fa21ae89..952f55fceb 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java
@@ -27,8 +27,10 @@ public class Constants {
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
public static final String PRIMARY_USER_STORE = "PRIMARY";
+ public static final String DEFAULT_STREAM_VERSION = "1.0.0";
public static final String SCOPE = "scope";
+
public final class ErrorMessages {
private ErrorMessages () { throw new AssertionError(); }
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
index d1e3ba234c..2df2daba39 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
@@ -18,26 +18,48 @@
package org.wso2.carbon.device.mgt.jaxrs.util;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.java.security.SSLProtocolSocketFactory;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceAdminServiceStub;
+import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.core.util.Utils;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
+import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.common.geo.service.GeoService;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeList;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
+import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub;
+import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub;
+import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub;
+import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
+import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.wso2.carbon.identity.user.store.count.AbstractCountRetrieverFactory;
import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever;
@@ -56,7 +78,22 @@ import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager;
import org.wso2.carbon.user.core.service.RealmService;
+import javax.cache.Cache;
+import javax.cache.Caching;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
import javax.ws.rs.core.MediaType;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -66,7 +103,51 @@ public class DeviceMgtAPIUtils {
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON_TYPE;
private static final String NOTIFIER_FREQUENCY = "notifierFrequency";
+ private static final String STREAM_DEFINITION_PREFIX = "iot.per.device.stream.";
+ private static final String DEFAULT_HTTP_PROTOCOL = "https";
+ private static final String EVENT_RECIEVER_CONTEXT = "EventReceiverAdminService/";
+ private static final String EVENT_PUBLISHER_CONTEXT = "EventPublisherAdminService/";
+ private static final String EVENT_STREAM_CONTEXT = "EventStreamAdminService/";
+ private static final String EVENT_PERSISTENCE_CONTEXT = "EventStreamPersistenceAdminService/";
+ private static final String AUTHORIZATION_HEADER = "Authorization";
+ private static final String AUTHORIZATION_HEADER_VALUE = "Bearer";
+ public static final String DAS_PORT = "${iot.analytics.https.port}";
+ public static final String DAS_HOST_NAME = "${iot.analytics.host}";
+ private static final String KEY_STORE_TYPE = "JKS";
+ private static final String TRUST_STORE_TYPE = "JKS";
+ private static final String KEY_MANAGER_TYPE = "SunX509"; //Default Key Manager Type
+ private static final String TRUST_MANAGER_TYPE = "SunX509"; //Default Trust Manager Type
+ private static final String SSLV3 = "SSLv3";
+ private static final String EVENT_CACHE_MANAGER_NAME = "mqttAuthorizationCacheManager";
+ private static final String EVENT_CACHE_NAME = "mqttAuthorizationCache";
+ public static final String DAS_ADMIN_SERVICE_EP = "https://" + DAS_HOST_NAME + ":" + DAS_PORT + "/services/";
+ private static SSLContext sslContext;
+
private static Log log = LogFactory.getLog(DeviceMgtAPIUtils.class);
+ private static KeyStore keyStore;
+ private static KeyStore trustStore;
+ private static char[] keyStorePassword;
+
+ static {
+ String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
+ String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty(
+ "Security.TrustStore.Password");
+ String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location");
+ String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty(
+ "Security.TrustStore.Location");
+
+ //Call to load the keystore.
+ try {
+ loadKeyStore(keyStoreLocation, keyStorePassword);
+ //Call to load the TrustStore.
+ loadTrustStore(trustStoreLocation, trustStorePassword);
+ //Create the SSL context with the loaded TrustStore/keystore.
+ initSSLConnection();
+ } catch (KeyStoreException | IOException | CertificateException | NoSuchAlgorithmException
+ | UnrecoverableKeyException | KeyManagementException e) {
+ log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
+ }
+ }
public static int getNotifierFrequency(PlatformConfiguration tenantConfiguration) {
List configEntryList = tenantConfiguration.getConfiguration();
@@ -115,6 +196,30 @@ public class DeviceMgtAPIUtils {
return deviceManagementProviderService;
}
+ public static DeviceTypeGeneratorService getDeviceTypeGeneratorService() {
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ DeviceTypeGeneratorService deviceTypeGeneratorService =
+ (DeviceTypeGeneratorService) ctx.getOSGiService(DeviceTypeGeneratorService.class, null);
+ if (deviceTypeGeneratorService == null) {
+ String msg = "DeviceTypeGeneratorService service has not initialized.";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ return deviceTypeGeneratorService;
+ }
+
+ public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
+ Device device = getDeviceManagementService().getDevice(deviceIdentifier);
+ if (device == null || device.getDeviceIdentifier() == null ||
+ device.getDeviceIdentifier().isEmpty() || device.getEnrolmentInfo() == null) {
+ return false;
+ } else if (EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())) {
+ return false;
+ }
+ return true;
+ }
+
+
public static UserStoreCountRetriever getUserStoreCountRetrieverService()
throws UserStoreCounterException {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@@ -367,4 +472,212 @@ public class DeviceMgtAPIUtils {
return username;
}
+ public static EventsPublisherService getEventPublisherService() {
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ EventsPublisherService eventsPublisherService =
+ (EventsPublisherService) ctx.getOSGiService(EventsPublisherService.class, null);
+ if (eventsPublisherService == null) {
+ String msg = "Event Publisher service has not initialized.";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ return eventsPublisherService;
+ }
+
+ public static String getStreamDefinition(String deviceType, String tenantDomain) {
+ return STREAM_DEFINITION_PREFIX + tenantDomain + "." + deviceType.replace(" ", ".");
+ }
+
+ public static EventStreamAdminServiceStub getEventStreamAdminServiceStub()
+ throws AxisFault, UserStoreException, JWTClientException {
+ EventStreamAdminServiceStub eventStreamAdminServiceStub = new EventStreamAdminServiceStub(
+ Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_STREAM_CONTEXT));
+ Options streamOptions = eventStreamAdminServiceStub._getServiceClient().getOptions();
+ if (streamOptions == null) {
+ streamOptions = new Options();
+ }
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
+ .getRealmConfiguration().getAdminUserName() + "@" + tenantDomain;
+ JWTClient jwtClient = DeviceMgtAPIUtils.getJWTClientManagerService().getJWTClient();
+
+ String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
+ jwtClient.getJwtToken(username).getBytes()));
+
+ List list = new ArrayList<>();
+ Header httpHeader = new Header();
+ httpHeader.setName(AUTHORIZATION_HEADER);
+ httpHeader.setValue(authValue);
+ list.add(httpHeader);//"https"
+ streamOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
+ streamOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
+ , new Protocol(DEFAULT_HTTP_PROTOCOL
+ , (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
+ , Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
+ eventStreamAdminServiceStub._getServiceClient().setOptions(streamOptions);
+ return eventStreamAdminServiceStub;
+ }
+
+ public static EventReceiverAdminServiceStub getEventReceiverAdminServiceStub()
+ throws AxisFault, UserStoreException, JWTClientException {
+ EventReceiverAdminServiceStub receiverAdminServiceStub = new EventReceiverAdminServiceStub(
+ Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_RECIEVER_CONTEXT));
+ Options eventReciverOptions = receiverAdminServiceStub._getServiceClient().getOptions();
+ if (eventReciverOptions == null) {
+ eventReciverOptions = new Options();
+ }
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
+ .getRealmConfiguration().getAdminUserName() + "@" + tenantDomain;
+ JWTClient jwtClient = DeviceMgtAPIUtils.getJWTClientManagerService().getJWTClient();
+
+ String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
+ jwtClient.getJwtToken(username).getBytes()));
+
+ List list = new ArrayList<>();
+ Header httpHeader = new Header();
+ httpHeader.setName(AUTHORIZATION_HEADER);
+ httpHeader.setValue(authValue);
+ list.add(httpHeader);
+
+ eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
+ eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
+ , new Protocol(DEFAULT_HTTP_PROTOCOL
+ , (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
+ , Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
+
+ receiverAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
+ return receiverAdminServiceStub;
+ }
+
+ public static EventPublisherAdminServiceStub getEventPublisherAdminServiceStub()
+ throws AxisFault, UserStoreException, JWTClientException {
+ EventPublisherAdminServiceStub eventPublisherAdminServiceStub = new EventPublisherAdminServiceStub(
+ Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_PUBLISHER_CONTEXT));
+ Options eventReciverOptions = eventPublisherAdminServiceStub._getServiceClient().getOptions();
+ if (eventReciverOptions == null) {
+ eventReciverOptions = new Options();
+ }
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
+ .getRealmConfiguration().getAdminUserName() + "@" + tenantDomain;
+ JWTClient jwtClient = DeviceMgtAPIUtils.getJWTClientManagerService().getJWTClient();
+
+ String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
+ jwtClient.getJwtToken(username).getBytes()));
+
+ List list = new ArrayList<>();
+ Header httpHeader = new Header();
+ httpHeader.setName(AUTHORIZATION_HEADER);
+ httpHeader.setValue(authValue);
+ list.add(httpHeader);
+
+ eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
+ eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
+ , new Protocol(DEFAULT_HTTP_PROTOCOL
+ , (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
+ , Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
+ eventPublisherAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
+ return eventPublisherAdminServiceStub;
+ }
+
+ public static EventStreamPersistenceAdminServiceStub getEventStreamPersistenceAdminServiceStub()
+ throws AxisFault, UserStoreException, JWTClientException {
+ EventStreamPersistenceAdminServiceStub eventStreamPersistenceAdminServiceStub
+ = new EventStreamPersistenceAdminServiceStub(
+ Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_PERSISTENCE_CONTEXT));
+ Options eventReciverOptions = eventStreamPersistenceAdminServiceStub._getServiceClient().getOptions();
+ if (eventReciverOptions == null) {
+ eventReciverOptions = new Options();
+ }
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
+ .getRealmConfiguration().getAdminUserName() + "@" + tenantDomain;
+ JWTClient jwtClient = DeviceMgtAPIUtils.getJWTClientManagerService().getJWTClient();
+
+ String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
+ jwtClient.getJwtToken(username).getBytes()));
+
+ List list = new ArrayList<>();
+ Header httpHeader = new Header();
+ httpHeader.setName(AUTHORIZATION_HEADER);
+ httpHeader.setValue(authValue);
+ list.add(httpHeader);
+
+ eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
+ eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
+ , new Protocol(DEFAULT_HTTP_PROTOCOL
+ , (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
+ , Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
+
+ eventStreamPersistenceAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
+ return eventStreamPersistenceAdminServiceStub;
+ }
+
+ /**
+ * This method is used to create the Cache that holds the event definition of the device type..
+ * @return Cachemanager
+ */
+ public static synchronized Cache getDynamicEventCache() {
+ return Caching.getCacheManagerFactory().getCacheManager(EVENT_CACHE_MANAGER_NAME).getCache(EVENT_CACHE_NAME);
+ }
+
+ /**
+ * Loads the keystore.
+ *
+ * @param keyStorePath - the path of the keystore
+ * @param ksPassword - the keystore password
+ */
+ private static void loadKeyStore(String keyStorePath, String ksPassword)
+ throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
+ InputStream fis = null;
+ try {
+ keyStorePassword = ksPassword.toCharArray();
+ keyStore = KeyStore.getInstance(KEY_STORE_TYPE);
+ fis = new FileInputStream(keyStorePath);
+ keyStore.load(fis, keyStorePassword);
+ } finally {
+ if (fis != null) {
+ fis.close();
+ }
+ }
+ }
+
+ /**
+ * Loads the trustore
+ *
+ * @param trustStorePath - the trustore path in the filesystem.
+ * @param tsPassword - the truststore password
+ */
+ private static void loadTrustStore(String trustStorePath, String tsPassword)
+ throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
+
+ InputStream fis = null;
+ try {
+ trustStore = KeyStore.getInstance(TRUST_STORE_TYPE);
+ fis = new FileInputStream(trustStorePath);
+ trustStore.load(fis, tsPassword.toCharArray());
+ } finally {
+ if (fis != null) {
+ fis.close();
+ }
+ }
+ }
+
+ /**
+ * Initializes the SSL Context
+ */
+ private static void initSSLConnection() throws NoSuchAlgorithmException, UnrecoverableKeyException,
+ KeyStoreException, KeyManagementException {
+ KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER_TYPE);
+ keyManagerFactory.init(keyStore, keyStorePassword);
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TRUST_MANAGER_TYPE);
+ trustManagerFactory.init(trustStore);
+
+ // Create and initialize SSLContext for HTTPS communication
+ sslContext = SSLContext.getInstance(SSLV3);
+ sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
+ SSLContext.setDefault(sslContext);
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
index 6e37d0256b..b59be7cf4f 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -29,6 +29,7 @@
+
@@ -40,8 +41,9 @@
-
-
+
+
+
@@ -70,7 +72,8 @@
-
+
+
@@ -82,10 +85,11 @@
-
+
-
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml
index abc284da3f..4579543f8f 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml
@@ -21,7 +21,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java
index 04df8c7dcd..d492ce22e1 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java
@@ -30,7 +30,7 @@ public class Device implements Serializable {
private static final long serialVersionUID = 1998101711L;
- @ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.",
+ @ApiModelProperty(name = "id", value = "ID of the device in the device information database.",
required = true)
private int id;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java
index f37e7e1d25..04504ccdc9 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java
@@ -56,7 +56,7 @@ public class DeviceIdentifier implements Serializable{
}
public void setType(String type) {
- this.type = type.toLowerCase();
+ this.type = type.trim();
}
public String getId() {
return id;
@@ -73,4 +73,4 @@ public class DeviceIdentifier implements Serializable{
", type='" + type + '\'' +
'}';
}
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/InvalidConfigurationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidConfigurationException.java
similarity index 88%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/InvalidConfigurationException.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidConfigurationException.java
index d0de9a178f..e6b291b605 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/InvalidConfigurationException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/InvalidConfigurationException.java
@@ -16,10 +16,10 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp;
+package org.wso2.carbon.device.mgt.common;
/**
- * This exception is thrown whether the xmpp configured with invalid configuration.
+ * This exception is thrown when configured with invalid configuration.
*/
public class InvalidConfigurationException extends RuntimeException {
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/InvalidConfigurationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationExecutionFailedException.java
similarity index 55%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/InvalidConfigurationException.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationExecutionFailedException.java
index e6f186f431..ecd3a84ab1 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/InvalidConfigurationException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationExecutionFailedException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ * 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
@@ -16,30 +16,29 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt;
+package org.wso2.carbon.device.mgt.common.pull.notification;
-/**
- * This exception is thrown whether the mqtt configured with invalid configuration.
- */
-public class InvalidConfigurationException extends RuntimeException {
+public class PullNotificationExecutionFailedException extends Exception {
+
+ private static final long serialVersionUID = -3151279311923070297L;
- public InvalidConfigurationException(String msg, Exception nestedEx) {
+ public PullNotificationExecutionFailedException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
- public InvalidConfigurationException(String message, Throwable cause) {
+ public PullNotificationExecutionFailedException(String message, Throwable cause) {
super(message, cause);
}
- public InvalidConfigurationException(String msg) {
+ public PullNotificationExecutionFailedException(String msg) {
super(msg);
}
- public InvalidConfigurationException() {
+ public PullNotificationExecutionFailedException() {
super();
}
- public InvalidConfigurationException(Throwable cause) {
+ public PullNotificationExecutionFailedException(Throwable cause) {
super(cause);
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationSubscriber.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationSubscriber.java
new file mode 100644
index 0000000000..8d59500ee0
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationSubscriber.java
@@ -0,0 +1,37 @@
+/*
+ * 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.carbon.device.mgt.common.pull.notification;
+
+
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
+
+import java.util.Map;
+
+/**
+ * This will handle the execution flow when a device sends a payload to IoT Server.
+ */
+public interface PullNotificationSubscriber {
+
+ void init(Map properties);
+
+ void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException;
+
+ void clean();
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java
index 7395b6f334..8cbe049245 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java
@@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
/**
@@ -47,6 +48,8 @@ public interface DeviceManagementService {
InitialOperationConfig getInitialOperationConfig();
+ PullNotificationSubscriber getPullNotificationSubscriber();
+
DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig();
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeGeneratorService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeGeneratorService.java
new file mode 100644
index 0000000000..f9c98e0f3a
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeGeneratorService.java
@@ -0,0 +1,13 @@
+package org.wso2.carbon.device.mgt.common.spi;
+
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
+
+/**
+ * This implementation populates device management service.
+ */
+public interface DeviceTypeGeneratorService {
+
+ DeviceManagementService populateDeviceManagementService(String deviceTypeName
+ , DeviceTypeMetaDefinition deviceTypeMetaDefinition);
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeDefinitionProvider.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeDefinitionProvider.java
new file mode 100644
index 0000000000..fab714fd5b
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeDefinitionProvider.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.common.type.mgt;
+
+public interface DeviceTypeDefinitionProvider {
+
+ DeviceTypeMetaDefinition getDeviceTypeMetaDefinition();
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java
new file mode 100644
index 0000000000..98b6c36e32
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java
@@ -0,0 +1,86 @@
+package org.wso2.carbon.device.mgt.common.type.mgt;
+
+import org.wso2.carbon.device.mgt.common.Feature;
+import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
+import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
+import org.wso2.carbon.device.mgt.common.license.mgt.License;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+
+import java.util.List;
+
+public class DeviceTypeMetaDefinition {
+
+ private List properties;
+ private List features;
+ private boolean claimable;
+ private PushNotificationConfig pushNotificationConfig;
+ private boolean policyMonitoringEnabled;
+ private InitialOperationConfig initialOperationConfig;
+ private License license;
+ private String description;
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public List getProperties() {
+ return properties;
+ }
+
+ public void setProperties(List properties) {
+ this.properties = properties;
+ }
+
+ public List getFeatures() {
+ return features;
+ }
+
+ public void setFeatures(List features) {
+ this.features = features;
+ }
+
+ public boolean isClaimable() {
+ return claimable;
+ }
+
+ public void setClaimable(boolean isClaimable) {
+ this.claimable = isClaimable;
+ }
+
+ public PushNotificationConfig getPushNotificationConfig() {
+ return pushNotificationConfig;
+ }
+
+ public void setPushNotificationConfig(
+ PushNotificationConfig pushNotificationConfig) {
+ this.pushNotificationConfig = pushNotificationConfig;
+ }
+
+ public boolean isPolicyMonitoringEnabled() {
+ return policyMonitoringEnabled;
+ }
+
+ public void setPolicyMonitoringEnabled(boolean policyMonitoringEnabled) {
+ this.policyMonitoringEnabled = policyMonitoringEnabled;
+ }
+
+ public InitialOperationConfig getInitialOperationConfig() {
+ return initialOperationConfig;
+ }
+
+ public void setInitialOperationConfig(InitialOperationConfig initialOperationConfig) {
+ this.initialOperationConfig = initialOperationConfig;
+ }
+
+ public License getLicense() {
+ return license;
+ }
+
+ public void setLicense(License license) {
+ this.license = license;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
index 8dc1d60e2e..941b876187 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java
index 3a4006cd7c..7a3b487121 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java
@@ -17,11 +17,14 @@
*/
package org.wso2.carbon.device.mgt.core;
+import com.google.gson.Gson;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
-import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
+import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder;
+import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
@@ -30,6 +33,8 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
@@ -52,19 +57,20 @@ import java.util.Map;
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
- private Map providers;
+ private Map providers;
private boolean isInitiated;
private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class);
private OperationManagerRepository operationManagerRepository;
+ private static final long DEFAULT_UPDATE_TIMESTAMP = 900000L;
public DeviceManagementPluginRepository() {
this.operationManagerRepository = new OperationManagerRepository();
- providers = Collections.synchronizedMap(new HashMap());
+ providers = Collections.synchronizedMap(new HashMap());
DeviceManagementServiceComponent.registerStartupListener(this);
}
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
- String deviceType = provider.getType().toLowerCase();
+ String deviceType = provider.getType();
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
String tenantDomain = provisioningConfig.getProviderTenantDomain();
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
@@ -77,10 +83,29 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
if (isInitiated) {
/* Initializing Device Management Service Provider */
provider.init();
- DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants);
+ DeviceTypeMetaDefinition deviceTypeDefinition = null;
+ if (provider instanceof DeviceTypeDefinitionProvider) {
+ DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(
+ provider.getType());
+ DeviceManagementServiceHolder existingProvider = providers.get(deviceTypeIdentifier);
+ deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMetaDefinition();
+ if (existingProvider != null && !(existingProvider.getDeviceManagementService()
+ instanceof DeviceTypeDefinitionProvider)) {
+ throw new DeviceManagementException("Definition of device type " + provider.getType()
+ + " is already available through sharing.");
+ }
+
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(provider.getType(), tenantId);
+ existingProvider = providers.get(deviceTypeIdentifier);
+ if (existingProvider != null) {
+ removeDeviceManagementProvider(provider);
+ }
+ }
+
+ DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants, deviceTypeDefinition);
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType,
- provider.getDeviceManager().
- requireDeviceAuthorization());
+ provider.getDeviceManager()
+ .requireDeviceAuthorization());
registerPushNotificationStrategy(provider);
registerMonitoringTask(provider);
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
@@ -88,40 +113,45 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
registerDeviceStatusMonitoringTask(deviceTypeObj, provider);
}
}
+ DeviceManagementServiceHolder deviceManagementServiceHolder = new DeviceManagementServiceHolder(provider);
if (isSharedWithAllTenants) {
- DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType);
- providers.put(deviceTypeIdentifier, provider);
+ DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType);
+ providers.put(deviceTypeIdentifier, deviceManagementServiceHolder);
} else {
- DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType, tenantId);
- providers.put(deviceTypeIdentifier, provider);
+ DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType, tenantId);
+ providers.put(deviceTypeIdentifier, deviceManagementServiceHolder);
}
}
}
public void removeDeviceManagementProvider(DeviceManagementService provider)
throws DeviceManagementException {
- String deviceTypeName = provider.getType().toLowerCase();
- DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
- DeviceTypeIdentifier deviceTypeIdentifier;
+ String deviceTypeName = provider.getType();
+ DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance()
+ .getDeviceManagementConfig();
+ DeviceTypeServiceIdentifier deviceTypeIdentifier;
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
if (provisioningConfig.isSharedWithAllTenants()) {
- deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName);
- providers.remove(deviceTypeIdentifier);
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName);
} else {
int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
- deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName, providerTenantId);
- providers.remove(deviceTypeIdentifier);
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName, providerTenantId);
}
+ PullNotificationSubscriber pullNotificationSubscriber = provider.getPullNotificationSubscriber();
+ if (pullNotificationSubscriber != null) {
+ pullNotificationSubscriber.clean();
+ }
+ providers.remove(deviceTypeIdentifier);
unregisterPushNotificationStrategy(deviceTypeIdentifier);
unregisterMonitoringTask(provider);
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
DeviceType deviceTypeObj = DeviceManagerUtil.getDeviceType(deviceTypeIdentifier.getDeviceType(),
- deviceTypeIdentifier.getTenantId());
+ deviceTypeIdentifier.getTenantId());
unregisterDeviceStatusMonitoringTask(deviceTypeObj, provider);
}
}
- private void unregisterPushNotificationStrategy(DeviceTypeIdentifier deviceTypeIdentifier) {
+ private void unregisterPushNotificationStrategy(DeviceTypeServiceIdentifier deviceTypeIdentifier) {
OperationManager operationManager = operationManagerRepository.getOperationManager(
deviceTypeIdentifier);
if (operationManager != null) {
@@ -135,20 +165,82 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
public DeviceManagementService getDeviceManagementService(String type, int tenantId) {
//Priority need to be given to the tenant before public.
- DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(type.toLowerCase(), tenantId);
- DeviceManagementService provider = providers.get(deviceTypeIdentifier);
+ DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId);
+ DeviceManagementServiceHolder provider = providers.get(deviceTypeIdentifier);
if (provider == null) {
- deviceTypeIdentifier = new DeviceTypeIdentifier(type.toLowerCase());
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type);
provider = providers.get(deviceTypeIdentifier);
+ if (provider == null) {
+ try {
+ DeviceType deviceType = DeviceManagerUtil.getDeviceType(type, tenantId);
+ if (deviceType == null) {
+ return null;
+ }
+ DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
+ if (deviceTypeMetaDefinition != null) {
+ DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder.getInstance()
+ .getDeviceTypeGeneratorService().populateDeviceManagementService(type, deviceTypeMetaDefinition);
+ if (deviceTypeManagerService == null) {
+ log.error("Failing to retrieve the device type service for " + type);
+ return null;
+ }
+ addDeviceManagementProvider(deviceTypeManagerService);
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId);
+ provider = providers.get(deviceTypeIdentifier);
+ }
+ } catch (DeviceManagementException e) {
+ log.error("Failing to retrieve the device type service for " + type, e);
+ return null;
+ }
+ }
+ if (provider == null) {
+ log.error("Device Type Definition not found for " + type);
+ return null;
+ }
+ } else {
+ // retrieves per tenant device type management service
+ if (provider.getDeviceManagementService() instanceof DeviceTypeDefinitionProvider) {
+ //handle updates.
+ long updatedTimestamp = provider.getTimestamp();
+ if (System.currentTimeMillis() - updatedTimestamp > DEFAULT_UPDATE_TIMESTAMP) {
+ try {
+ DeviceType deviceType = DeviceManagerUtil.getDeviceType(type,tenantId);
+ DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
+ if (deviceTypeMetaDefinition != null) {
+ Gson gson = new Gson();
+ String dbStoredDefinition = gson.toJson(deviceTypeMetaDefinition);
+ deviceTypeMetaDefinition = ((DeviceTypeDefinitionProvider)
+ provider.getDeviceManagementService()).getDeviceTypeMetaDefinition();
+ String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
+ if (!cachedDefinition.equals(dbStoredDefinition)) {
+ DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder.getInstance()
+ .getDeviceTypeGeneratorService().populateDeviceManagementService(type, deviceTypeMetaDefinition);
+ if (deviceTypeManagerService == null) {
+ log.error("Failing to retrieve the device type service for " + type);
+ return null;
+ }
+ addDeviceManagementProvider(deviceTypeManagerService);
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId);
+ provider = providers.get(deviceTypeIdentifier);
+ } else {
+ provider.setTimestamp(System.currentTimeMillis());
+ }
+ }
+ } catch (DeviceManagementException e) {
+ log.error("Failing to retrieve the device type service for " + type, e);
+ return null;
+ }
+ }
+ }
}
- return provider;
+ return provider.getDeviceManagementService();
}
- public Map getAllDeviceManagementServices(int tenantId) {
- Map tenantProviders = new HashMap<>();
- for (DeviceTypeIdentifier identifier : providers.keySet()) {
+ public Map getAllDeviceManagementServices(int tenantId) {
+ Map tenantProviders = new HashMap<>();
+ for (DeviceTypeServiceIdentifier identifier : providers.keySet()) {
if (identifier.getTenantId() == tenantId || identifier.isSharedWithAllTenant()) {
- tenantProviders.put(identifier, providers.get(identifier));
+ tenantProviders.put(identifier, providers.get(identifier).getDeviceManagementService());
}
}
return tenantProviders;
@@ -162,12 +254,12 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
try {
boolean isSharedWithAllTenants = deviceManagementService.getProvisioningConfig().isSharedWithAllTenants();
- DeviceTypeIdentifier deviceTypeIdentifier;
+ DeviceTypeServiceIdentifier deviceTypeIdentifier;
if (isSharedWithAllTenants) {
- deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType());
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType());
} else {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
- deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId);
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
}
if (pushNoteConfig != null) {
@@ -268,10 +360,13 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
public OperationManager getOperationManager(String deviceType, int tenantId) {
//Priority need to be given to the tenant before public.
- DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType.toLowerCase(), tenantId);
+ DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType, tenantId);
+ if (getDeviceManagementService(deviceType, tenantId) == null) {
+ return null;
+ }
OperationManager operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier);
if (operationManager == null) {
- deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType.toLowerCase());
+ deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType);
operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier);
}
return operationManager;
@@ -281,14 +376,26 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
public void notifyObserver() {
String deviceTypeName;
synchronized (providers) {
- for (DeviceManagementService provider : providers.values()) {
+ for (DeviceManagementServiceHolder deviceManagementServiceHolder : providers.values()) {
+ DeviceManagementService provider= deviceManagementServiceHolder.getDeviceManagementService();
try {
provider.init();
- deviceTypeName = provider.getType().toLowerCase();
+ deviceTypeName = provider.getType();
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
- DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId,
- provisioningConfig.isSharedWithAllTenants());
+ DeviceTypeMetaDefinition deviceTypeDefinition = null;
+ if (provider instanceof DeviceTypeDefinitionProvider) {
+ deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMetaDefinition();
+
+ DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(
+ provider.getType(), tenantId);
+ DeviceManagementServiceHolder existingProvider = providers.get(deviceTypeIdentifier);
+ if (existingProvider != null) {
+ removeDeviceManagementProvider(provider);
+ }
+ }
+ DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId
+ , provisioningConfig.isSharedWithAllTenants(), deviceTypeDefinition);
registerPushNotificationStrategy(provider);
registerMonitoringTask(provider);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
index 842b6bd967..e95fa19e51 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
@@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration;
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
+import org.wso2.carbon.device.mgt.core.config.pull.notification.PullNotificationConfiguration;
import org.wso2.carbon.device.mgt.core.config.push.notification.PushNotificationConfiguration;
import org.wso2.carbon.device.mgt.core.config.status.task.DeviceStatusTaskConfig;
import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration;
@@ -42,6 +43,7 @@ public final class DeviceManagementConfig {
private PolicyConfiguration policyConfiguration;
private PaginationConfiguration paginationConfiguration;
private PushNotificationConfiguration pushNotificationConfiguration;
+ private PullNotificationConfiguration pullNotificationConfiguration;
private DeviceStatusTaskConfig deviceStatusTaskConfig;
private DeviceCacheConfiguration deviceCacheConfiguration;
private GeoLocationConfiguration geoLocationConfiguration;
@@ -101,6 +103,15 @@ public final class DeviceManagementConfig {
this.pushNotificationConfiguration = pushNotificationConfiguration;
}
+ @XmlElement(name = "PullNotificationConfiguration", required = true)
+ public PullNotificationConfiguration getPullNotificationConfiguration() {
+ return pullNotificationConfiguration;
+ }
+
+ public void setPullNotificationConfiguration(PullNotificationConfiguration pullNotificationConfiguration) {
+ this.pullNotificationConfiguration = pullNotificationConfiguration;
+ }
+
@XmlElement(name = "DeviceStatusTaskConfig", required = true)
public DeviceStatusTaskConfig getDeviceStatusTaskConfig() {
return deviceStatusTaskConfig;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pull/notification/PullNotificationConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pull/notification/PullNotificationConfiguration.java
new file mode 100644
index 0000000000..4298987df7
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pull/notification/PullNotificationConfiguration.java
@@ -0,0 +1,40 @@
+/*
+* 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.carbon.device.mgt.core.config.pull.notification;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * This class is for Pull notification related Configurations
+ */
+@XmlRootElement(name = "PullNotificationConfiguration")
+public class PullNotificationConfiguration {
+
+ private boolean enabled;
+
+ @XmlElement(name = "Enabled", required = true)
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
index 14ac17dd95..f6a0a363b4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
@@ -420,5 +420,7 @@ public interface DeviceDAO {
*/
List getEnrolmentsByStatus(List deviceIds, Status status,
int tenantId) throws DeviceManagementDAOException;
+
+ List getDeviceEnrolledTenants() throws DeviceManagementDAOException;
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java
index 0e34fc1ab0..337a5af133 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java
@@ -55,7 +55,7 @@ public interface DeviceTypeDAO {
* @return return only the device types that are associated with the provider tenant.
* @throws DeviceManagementDAOException
*/
- List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException;
+ List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException;
/**
* @return sharedWithAllDeviceTypes This returns public shared device types.
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
index d62f2c1674..202d514b67 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
@@ -121,7 +121,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
- "t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
+ "t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ? ORDER BY e.DATE_OF_LAST_UPDATE DESC";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType());
@@ -154,7 +154,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
- "WHERE t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
+ "WHERE t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
"AND dt.UPDATE_TIMESTAMP > ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?" ;
stmt = conn.prepareStatement(sql);
int paramIdx = 1;
@@ -189,7 +189,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
- "t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
+ "t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ? AND e.STATUS = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType());
@@ -223,7 +223,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
- "t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? ) d1 WHERE d1.ID = e.DEVICE_ID ORDER BY e.DATE_OF_LAST_UPDATE DESC";
+ "t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? ) d1 WHERE d1.ID = e.DEVICE_ID ORDER BY e.DATE_OF_LAST_UPDATE DESC";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType());
stmt.setString(2, deviceIdentifier.getId());
@@ -253,7 +253,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
- "d.ID = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
+ "d.ID = ? AND t.ID = d.DEVICE_TYPE_ID AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ? ORDER BY e.DATE_OF_LAST_UPDATE DESC";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId);
@@ -317,7 +317,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " +
"d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
"DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
- "AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
+ "AND t.ID = d.DEVICE_TYPE_ID AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, type);
stmt.setInt(2, tenantId);
@@ -1071,4 +1071,27 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
return devices;
}
+
+ public List getDeviceEnrolledTenants() throws DeviceManagementDAOException {
+ Connection conn;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ List tenants = new ArrayList<>();
+ try {
+ conn = this.getConnection();
+ String sql = "SELECT distinct(TENANT_ID) FROM DM_DEVICE";
+ stmt = conn.prepareStatement(sql);
+ rs = stmt.executeQuery();
+ while (rs.next()) {
+ tenants.add(rs.getInt("TENANT_ID"));
+ }
+ } catch (SQLException e) {
+ throw new DeviceManagementDAOException("Error occurred while retrieving tenants which have " +
+ "device registered.", e);
+ } finally {
+ DeviceManagementDAOUtil.cleanupResources(stmt, rs);
+ }
+ return tenants;
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java
index c7e4952328..a4ecacfd3a 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java
@@ -17,6 +17,8 @@
*/
package org.wso2.carbon.device.mgt.core.dao.impl;
+import com.google.gson.Gson;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
@@ -27,7 +29,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
@@ -40,10 +44,18 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
try {
conn = this.getConnection();
stmt = conn.prepareStatement(
- "INSERT INTO DM_DEVICE_TYPE (NAME,PROVIDER_TENANT_ID,SHARED_WITH_ALL_TENANTS) VALUES (?,?,?)");
+ "INSERT INTO DM_DEVICE_TYPE (NAME,PROVIDER_TENANT_ID,SHARED_WITH_ALL_TENANTS,DEVICE_TYPE_META" +
+ ",LAST_UPDATED_TIMESTAMP) VALUES (?,?,?,?,?)");
stmt.setString(1, deviceType.getName());
stmt.setInt(2, providerTenantId);
stmt.setBoolean(3, isSharedWithAllTenants);
+ String deviceMeta = null;
+ if (deviceType.getDeviceTypeMetaDefinition() != null) {
+ Gson gson = new Gson();
+ deviceMeta = gson.toJson(deviceType.getDeviceTypeMetaDefinition());
+ }
+ stmt.setString(4, deviceMeta);
+ stmt.setTimestamp(5, new Timestamp(new Date().getTime()));
stmt.execute();
} catch (SQLException e) {
throw new DeviceManagementDAOException(
@@ -54,8 +66,29 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
}
@Override
- public void updateDeviceType(DeviceType deviceType, int tenantId)
- throws DeviceManagementDAOException {
+ public void updateDeviceType(DeviceType deviceType, int tenantId) throws DeviceManagementDAOException {
+ Connection conn;
+ PreparedStatement stmt = null;
+ try {
+ conn = this.getConnection();
+ stmt = conn.prepareStatement("UPDATE DM_DEVICE_TYPE SET DEVICE_TYPE_META = ?, LAST_UPDATED_TIMESTAMP = ? " +
+ "WHERE NAME = ? AND PROVIDER_TENANT_ID = ?");
+ String deviceMeta = null;
+ if (deviceType.getDeviceTypeMetaDefinition() != null) {
+ Gson gson = new Gson();
+ deviceMeta = gson.toJson(deviceType.getDeviceTypeMetaDefinition());
+ }
+ stmt.setString(1, deviceMeta);
+ stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
+ stmt.setString(3, deviceType.getName());
+ stmt.setInt(4, tenantId);
+ stmt.execute();
+ } catch (SQLException e) {
+ throw new DeviceManagementDAOException("Error occurred while updating device type'" +
+ deviceType.getName() + "'", e);
+ } finally {
+ DeviceManagementDAOUtil.cleanupResources(stmt, null);
+ }
}
@Override
@@ -67,8 +100,8 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
try {
conn = this.getConnection();
String sql =
- "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =" +
- "? OR SHARED_WITH_ALL_TENANTS = ?";
+ "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE, DEVICE_TYPE_META,LAST_UPDATED_TIMESTAMP " +
+ "FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =? OR SHARED_WITH_ALL_TENANTS = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setBoolean(2, true);
@@ -78,6 +111,12 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
DeviceType deviceType = new DeviceType();
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
deviceType.setName(rs.getString("DEVICE_TYPE"));
+ String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
+ if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
+ Gson gson = new Gson();
+ deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
+ , DeviceTypeMetaDefinition.class));
+ }
deviceTypes.add(deviceType);
}
return deviceTypes;
@@ -89,21 +128,30 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
}
@Override
- public List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException {
+ public List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
- List deviceTypes = new ArrayList<>();
+ List deviceTypes = new ArrayList<>();
try {
conn = this.getConnection();
String sql =
- "SELECT NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =?";
+ "SELECT NAME AS DEVICE_TYPE, DEVICE_TYPE_META FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
rs = stmt.executeQuery();
while (rs.next()) {
- deviceTypes.add(rs.getString("DEVICE_TYPE"));
+ DeviceType deviceType = new DeviceType();
+ deviceType.setName(rs.getString("DEVICE_TYPE"));
+ String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
+ if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
+ Gson gson = new Gson();
+ deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
+ , DeviceTypeMetaDefinition.class));
+ }
+ deviceTypes.add(deviceType);
+
}
return deviceTypes;
} catch (SQLException e) {
@@ -146,7 +194,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
ResultSet rs = null;
try {
conn = this.getConnection();
- String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?";
+ String sql = "SELECT ID AS DEVICE_TYPE_ID, DEVICE_TYPE_META, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, id);
rs = stmt.executeQuery();
@@ -155,6 +203,13 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
deviceType = new DeviceType();
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
deviceType.setName(rs.getString("DEVICE_TYPE"));
+ String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
+ if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
+ Gson gson = new Gson();
+ deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
+ , DeviceTypeMetaDefinition.class));
+ }
+
}
return deviceType;
} catch (SQLException e) {
@@ -174,7 +229,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
DeviceType deviceType = null;
try {
conn = this.getConnection();
- String sql = "SELECT ID AS DEVICE_TYPE_ID FROM DM_DEVICE_TYPE WHERE (PROVIDER_TENANT_ID =? OR " +
+ String sql = "SELECT ID AS DEVICE_TYPE_ID, DEVICE_TYPE_META FROM DM_DEVICE_TYPE WHERE (PROVIDER_TENANT_ID =? OR " +
"SHARED_WITH_ALL_TENANTS = ?) AND NAME =?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
@@ -185,6 +240,12 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
deviceType = new DeviceType();
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
deviceType.setName(type);
+ String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
+ if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
+ Gson gson = new Gson();
+ deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
+ , DeviceTypeMetaDefinition.class));
+ }
}
return deviceType;
} catch (SQLException e) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceManagementServiceHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceManagementServiceHolder.java
new file mode 100644
index 0000000000..d849120414
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceManagementServiceHolder.java
@@ -0,0 +1,47 @@
+/*
+ * 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.carbon.device.mgt.core.dto;
+
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+
+/**
+ * This holds the information of the registered device management service against the device type
+ * definition loaded timestamp. This is used to handle device type update scenario.
+ */
+public class DeviceManagementServiceHolder {
+
+ private DeviceManagementService deviceManagementService;
+ private long timestamp;
+
+ public DeviceManagementServiceHolder(DeviceManagementService deviceManagementService) {
+ this.deviceManagementService = deviceManagementService;
+ this.timestamp = System.currentTimeMillis();
+ }
+
+ public DeviceManagementService getDeviceManagementService() {
+ return deviceManagementService;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java
index eb363fff1c..c56257a363 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java
@@ -18,8 +18,11 @@
package org.wso2.carbon.device.mgt.core.dto;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
import java.io.Serializable;
@@ -33,6 +36,10 @@ public class DeviceType implements Serializable {
@ApiModelProperty(name = "name", value = "Device type name", required = true)
private String name;
+ @JsonProperty("metaDefinition")
+ @ApiModelProperty(name = "metaDefinition", value = "Device type definition", required = true)
+ private DeviceTypeMetaDefinition deviceTypeMetaDefinition;
+
public DeviceType() {
}
@@ -40,6 +47,7 @@ public class DeviceType implements Serializable {
this.name = name;
}
+ @JsonIgnore
public int getId() {
return id;
}
@@ -56,4 +64,13 @@ public class DeviceType implements Serializable {
this.name = name;
}
+ public DeviceTypeMetaDefinition getDeviceTypeMetaDefinition() {
+ return deviceTypeMetaDefinition;
+ }
+
+ public void setDeviceTypeMetaDefinition(
+ DeviceTypeMetaDefinition deviceTypeMetaDefinition) {
+ this.deviceTypeMetaDefinition = deviceTypeMetaDefinition;
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceTypeServiceIdentifier.java
similarity index 75%
rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceTypeServiceIdentifier.java
index 1849a97c0d..d6d48a8497 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceTypeServiceIdentifier.java
@@ -15,26 +15,26 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.wso2.carbon.device.mgt.common;
+package org.wso2.carbon.device.mgt.core.dto;
import java.io.Serializable;
/**
* This class holds the information of the device type and its provider tenant.
*/
-public class DeviceTypeIdentifier implements Serializable {
+public class DeviceTypeServiceIdentifier implements Serializable {
private String deviceType;
private int tenantId;
private static final int DEFAULT_SHARE_WITH_ALL_TENANTS_ID = -1;
- public DeviceTypeIdentifier(String deviceType, int tenantId) {
- this.deviceType = deviceType.toLowerCase();
+ public DeviceTypeServiceIdentifier(String deviceType, int tenantId) {
+ this.deviceType = deviceType;
this.tenantId = tenantId;
}
- public DeviceTypeIdentifier(String deviceType) {
- this.deviceType = deviceType.toLowerCase();
+ public DeviceTypeServiceIdentifier(String deviceType) {
+ this.deviceType = deviceType;
this.tenantId = DEFAULT_SHARE_WITH_ALL_TENANTS_ID;
}
@@ -59,8 +59,8 @@ public class DeviceTypeIdentifier implements Serializable {
@Override
public boolean equals(Object obj) {
- return (obj instanceof DeviceTypeIdentifier) && deviceType.equals(
- ((DeviceTypeIdentifier) obj).deviceType) && tenantId == ((DeviceTypeIdentifier) obj).tenantId;
+ return (obj instanceof DeviceTypeServiceIdentifier) && deviceType.equals(
+ ((DeviceTypeServiceIdentifier) obj).deviceType) && tenantId == ((DeviceTypeServiceIdentifier) obj).tenantId;
}
public boolean isSharedWithAllTenant() {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
index d043c509c1..f6a3a3fc83 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
@@ -19,15 +19,16 @@
package org.wso2.carbon.device.mgt.core.internal;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
-import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
+import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
import org.wso2.carbon.device.mgt.core.push.notification.mgt.PushNotificationProviderRepository;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
@@ -65,6 +66,7 @@ public class DeviceManagementDataHolder {
private PushNotificationProviderRepository pushNotificationProviderRepository;
private DeviceTaskManagerService deviceTaskManagerService;
private DeviceStatusTaskManagerService deviceStatusTaskManagerService;
+ private DeviceTypeGeneratorService deviceTypeGeneratorService;
private Map deviceStatusTaskPluginConfigs = Collections.synchronizedMap(
new HashMap());
@@ -244,7 +246,7 @@ public class DeviceManagementDataHolder {
this.deviceStatusTaskPluginConfigs.put(deviceType, deviceStatusTaskPluginConfig);
}
- public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig(DeviceTypeIdentifier deviceType) {
+ public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig(DeviceTypeServiceIdentifier deviceType) {
return this.deviceStatusTaskPluginConfigs.get(deviceType);
}
@@ -255,4 +257,13 @@ public class DeviceManagementDataHolder {
public void removeDeviceStatusTaskPluginConfig(DeviceType deviceType) {
this.deviceStatusTaskPluginConfigs.remove(deviceType);
}
+
+ public DeviceTypeGeneratorService getDeviceTypeGeneratorService() {
+ return deviceTypeGeneratorService;
+ }
+
+ public void setDeviceTypeGeneratorService(
+ DeviceTypeGeneratorService deviceTypeGeneratorService) {
+ this.deviceTypeGeneratorService = deviceTypeGeneratorService;
+ }
}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
index c42bb8acf8..3e08759405 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
@@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl;
@@ -108,6 +109,12 @@ import java.util.concurrent.TimeUnit;
* policy="dynamic"
* bind="setEmailSenderService"
* unbind="unsetEmailSenderService"
+ * @scr.reference name="device.type.generator.service"
+ * interface="org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService"
+ * cardinality="0..1"
+ * policy="dynamic"
+ * bind="setDeviceTypeGeneratorService"
+ * unbind="unsetDeviceTypeGeneratorService"
*/
public class DeviceManagementServiceComponent {
@@ -313,7 +320,7 @@ public class DeviceManagementServiceComponent {
try {
if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" +
- deviceManagementService.getType() + "'");
+ deviceManagementService.getType() + "'");
}
synchronized (LOCK) {
deviceManagers.add(deviceManagementService);
@@ -444,6 +451,30 @@ public class DeviceManagementServiceComponent {
}
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
}
+
+ /**
+ * sets DeviceTypeGeneratorService.
+ *
+ * @param deviceTypeGeneratorService An Instance of DeviceTypeGeneratorService
+ */
+ protected void setDeviceTypeGeneratorService(DeviceTypeGeneratorService deviceTypeGeneratorService) {
+ if (log.isDebugEnabled()) {
+ log.debug("Un setting Device DeviceTypeGeneratorService");
+ }
+ DeviceManagementDataHolder.getInstance().setDeviceTypeGeneratorService(deviceTypeGeneratorService);
+ }
+
+ /**
+ * sets DeviceTypeGeneratorService.
+ *
+ * @param deviceTypeGeneratorService An Instance of DeviceTypeGeneratorService
+ */
+ protected void unsetDeviceTypeGeneratorService(DeviceTypeGeneratorService deviceTypeGeneratorService) {
+ if (log.isDebugEnabled()) {
+ log.debug("Un setting Device DeviceTypeGeneratorService");
+ }
+ DeviceManagementDataHolder.getInstance().setDeviceTypeGeneratorService(null);
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
index 8a5d9aa6ce..c22f3de950 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
@@ -194,6 +194,8 @@ public class OperationManagerImpl implements OperationManager {
if (log.isDebugEnabled()) {
log.debug("Sending push notification to " + deviceId + " from add operation method.");
}
+ operation.setId(operationId);
+ operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
notificationStrategy.execute(new NotificationContext(deviceId, operation));
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED);
} catch (PushNotificationExecutionFailedException e) {
@@ -539,7 +541,7 @@ public class OperationManagerImpl implements OperationManager {
Operation.Status.valueOf(operation.getStatus().
toString()));
}
- if (isUpdated && operation.getOperationResponse() != null) {
+ if (operation.getOperationResponse() != null) {
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
}
OperationManagementDAOFactory.commitTransaction();
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java
index c9c863593c..8a44192f00 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java
@@ -18,7 +18,7 @@
*/
package org.wso2.carbon.device.mgt.core.operation.mgt;
-import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
+import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import java.util.Map;
@@ -26,21 +26,21 @@ import java.util.concurrent.ConcurrentHashMap;
public class OperationManagerRepository {
- private Map operationManagers;
+ private Map operationManagers;
public OperationManagerRepository() {
operationManagers = new ConcurrentHashMap<>();
}
- public void addOperationManager(DeviceTypeIdentifier type, OperationManager operationManager) {
+ public void addOperationManager(DeviceTypeServiceIdentifier type, OperationManager operationManager) {
operationManagers.put(type, operationManager);
}
- public OperationManager getOperationManager(DeviceTypeIdentifier type) {
+ public OperationManager getOperationManager(DeviceTypeServiceIdentifier type) {
return operationManagers.get(type);
}
- public void removeOperationManager(DeviceTypeIdentifier type) {
+ public void removeOperationManager(DeviceTypeServiceIdentifier type) {
operationManagers.remove(type);
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java
index c847c7652c..3020096972 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java
@@ -178,6 +178,7 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl {
ois = new ObjectInputStream(bais);
configOperation = (ConfigOperation) ois.readObject();
configOperation.setStatus(status);
+ configOperation.setId(rs.getInt("OPERATION_ID"));
operations.add(configOperation);
}
} catch (IOException e) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
index 09911f3cd6..a82e502257 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
@@ -32,7 +32,10 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.Date;
import java.util.HashMap;
@@ -558,4 +561,32 @@ public interface DeviceManagementProviderService {
*/
boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus)
throws DeviceManagementException;
+
+ /**
+ * This will handle add and update of device type services.
+ * @param deviceManagementService
+ */
+ void registerDeviceType(DeviceManagementService deviceManagementService) throws DeviceManagementException;
+
+ /**
+ * This retrieves the device type info for the given type
+ * @param deviceType name of the type.
+ * @throws DeviceManagementException
+ */
+ DeviceType getDeviceType(String deviceType) throws DeviceManagementException;
+
+ /**
+ * This retrieves the device type info for the given type
+ * @throws DeviceManagementException
+ */
+ List getDeviceTypes() throws DeviceManagementException;
+
+ /**
+ * This retrieves the device pull notification payload and passes to device type pull notification subscriber.
+ * @throws PullNotificationExecutionFailedException
+ */
+ void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation)
+ throws PullNotificationExecutionFailedException;
+
+ List getDeviceEnrolledTenants() throws DeviceManagementException;
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
index 77934202b2..a1e5d31e35 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
@@ -28,7 +28,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
-import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
+import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
@@ -776,7 +778,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public List getAvailableDeviceTypes() throws DeviceManagementException {
- List deviceTypesProvidedByTenant;
+ List deviceTypesProvidedByTenant;
List publicSharedDeviceTypesInDB;
List deviceTypesResponse = new ArrayList<>();
try {
@@ -784,17 +786,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
int tenantId = this.getTenantId();
deviceTypesProvidedByTenant = deviceTypeDAO.getDeviceTypesByProvider(tenantId);
publicSharedDeviceTypesInDB = deviceTypeDAO.getSharedDeviceTypes();
- Map registeredTypes =
+ Map registeredTypes =
pluginRepository.getAllDeviceManagementServices(tenantId);
Set deviceTypeSetForTenant = new HashSet<>();
if (registeredTypes != null) {
if (deviceTypesProvidedByTenant != null) {
- for (String deviceType : deviceTypesProvidedByTenant) {
- DeviceTypeIdentifier providerKey = new DeviceTypeIdentifier(deviceType, tenantId);
- if (registeredTypes.get(providerKey) != null) {
- deviceTypesResponse.add(deviceType);
- deviceTypeSetForTenant.add(deviceType);
+ for (DeviceType deviceType : deviceTypesProvidedByTenant) {
+ DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType.getName(), tenantId);
+ if (registeredTypes.get(providerKey) != null || deviceType.getDeviceTypeMetaDefinition() != null) {
+ deviceTypesResponse.add(deviceType.getName());
+ deviceTypeSetForTenant.add(deviceType.getName());
}
}
}
@@ -802,7 +804,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
// priority to that
if (publicSharedDeviceTypesInDB != null) {
for (String deviceType : publicSharedDeviceTypesInDB) {
- DeviceTypeIdentifier providerKey = new DeviceTypeIdentifier(deviceType);
+ DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType);
if (registeredTypes.get(providerKey) != null && !deviceTypeSetForTenant.contains(deviceType)) {
deviceTypesResponse.add(deviceType);
}
@@ -885,15 +887,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
+ @Deprecated
public void notifyOperationToDevices(Operation operation, List deviceIds)
throws DeviceManagementException {
- for (DeviceIdentifier deviceId : deviceIds) {
- DeviceManagementService dms =
- pluginRepository.getDeviceManagementService(deviceId.getType(), this.getTenantId());
- //TODO FIX THIS WITH PUSH NOTIFICATIONS
- //dms.notifyOperationToDevices(operation, deviceIds);
- }
+// for (DeviceIdentifier deviceId : deviceIds) {
+// DeviceManagementService dms =
+// pluginRepository.getDeviceManagementService(deviceId.getType(), this.getTenantId());
+// //TODO FIX THIS WITH PUSH NOTIFICATIONS
+// //dms.notifyOperationToDevices(operation, deviceIds);
+// }
}
@@ -1468,6 +1471,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return isDeviceUpdated;
}
+ @Override
+ public List getDeviceEnrolledTenants() throws DeviceManagementException {
+ try {
+ DeviceManagementDAOFactory.openConnection();
+ return deviceDAO.getDeviceEnrolledTenants();
+ } catch (DeviceManagementDAOException e) {
+ throw new DeviceManagementException("Error occurred while retrieving the tenants " +
+ "which have device enrolled.", e);
+ } catch (SQLException e) {
+ throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ }
+
private boolean updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId)
throws DeviceManagementException {
boolean isUpdatedEnrollment = false;
@@ -1600,6 +1618,65 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
}
+ @Override
+ public void registerDeviceType(DeviceManagementService deviceManagementService) throws DeviceManagementException {
+ if (deviceManagementService != null) {
+ pluginRepository.addDeviceManagementProvider(deviceManagementService);
+ }
+ }
+
+ @Override
+ public DeviceType getDeviceType(String deviceType) throws DeviceManagementException {
+ try {
+ DeviceManagementDAOFactory.openConnection();
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ return deviceTypeDAO.getDeviceType(deviceType, tenantId);
+ } catch (DeviceManagementDAOException e) {
+ throw new DeviceManagementException("Error occurred while obtaining the device type " + deviceType, e);
+ } catch (SQLException e) {
+ throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public List getDeviceTypes() throws DeviceManagementException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ DeviceManagementDAOFactory.openConnection();
+ return deviceTypeDAO.getDeviceTypes(tenantId);
+ } catch (DeviceManagementDAOException e) {
+ throw new DeviceManagementException("Error occurred while obtaining the device types for tenant "
+ + tenantId, e);
+ } catch (SQLException e) {
+ throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation)
+ throws PullNotificationExecutionFailedException {
+ DeviceManagementService dms =
+ pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId());
+ if (dms == null) {
+ String message = "Device type '" + deviceIdentifier.getType() + "' does not have an associated device management " +
+ "plugin registered within the framework";
+ if (log.isDebugEnabled()) {
+ log.debug(message);
+ }
+ throw new PullNotificationExecutionFailedException(message);
+ }
+ PullNotificationSubscriber pullNotificationSubscriber = dms.getPullNotificationSubscriber();
+ if (pullNotificationSubscriber == null) {
+ throw new PullNotificationExecutionFailedException("Pull Notification Subscriber is not configured " +
+ "for device type" + deviceIdentifier.getType());
+ }
+ pullNotificationSubscriber.execute(deviceIdentifier, operation);
+ }
+
/**
* Returns all the device-info including location of the given device.
*/
@@ -1712,4 +1789,4 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private void removeDeviceFromCache(DeviceIdentifier deviceIdentifier) {
DeviceCacheManagerImpl.getInstance().removeDeviceFromCache(deviceIdentifier, this.getTenantId());
}
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java
index 6d1228563c..7b65a3b6ee 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java
@@ -22,20 +22,26 @@ package org.wso2.carbon.device.mgt.core.task.impl;
import com.google.gson.Gson;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
+import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
import org.wso2.carbon.ntask.core.Task;
+import org.wso2.carbon.user.api.UserStoreException;
+import java.util.List;
import java.util.Map;
public class DeviceDetailsRetrieverTask implements Task {
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
-// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl();
private String deviceType;
private String oppConfig;
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
+ private boolean executeForTenants = false;
+ private final String IS_CLOUD = "is.cloud";
@Override
public void setProperties(Map map) {
@@ -54,21 +60,62 @@ public class DeviceDetailsRetrieverTask implements Task {
@Override
public void execute() {
- if (log.isDebugEnabled()) {
- log.debug("Device details retrieving task started to run.");
+
+ if(System.getProperty(IS_CLOUD) != null && Boolean.parseBoolean(System.getProperty(IS_CLOUD))){
+ executeForTenants = true;
}
+ if(executeForTenants){
+ this.executeForAllTenants();
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Device details retrieving task started to run.");
+ }
+ DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
+ operationMonitoringTaskConfig);
+ //pass the configurations also from here, monitoring tasks
+ try {
+ deviceTaskManager.addOperations();
+ } catch (DeviceMgtTaskException e) {
+ log.error(
+ "Error occurred while trying to add the operations to device to retrieve device details.", e);
+ }
+ }
+ }
- DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
- operationMonitoringTaskConfig);
- //pass the configurations also from here, monitoring tasks
+ private void executeForAllTenants() {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Device details retrieving task started to run for all tenants.");
+ }
try {
- deviceTaskManager.addOperations();
- } catch (DeviceMgtTaskException e) {
- log.error(
- "Error occurred while trying to add the operations to device to retrieve device details.",
- e);
+ List tenants = DeviceManagementDataHolder.getInstance().
+ getDeviceManagementProvider().getDeviceEnrolledTenants();
+ for (Integer tenant : tenants) {
+ String tenantDomain = DeviceManagementDataHolder.getInstance().
+ getRealmService().getTenantManager().getDomain(tenant);
+ try {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
+ DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
+ operationMonitoringTaskConfig);
+ //pass the configurations also from here, monitoring tasks
+ try {
+ deviceTaskManager.addOperations();
+ } catch (DeviceMgtTaskException e) {
+ log.error("Error occurred while trying to add the operations to " +
+ "device to retrieve device details.", e);
+ }
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+ } catch (UserStoreException e) {
+ log.error("Error occurred while trying to get the available tenants", e);
+ } catch (DeviceManagementException e) {
+ log.error("Error occurred while trying to get the available tenants " +
+ "from device manager provider service.", e);
}
-
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java
index ee972ef5bf..339567fc3c 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java
@@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.cache.DeviceCacheKey;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
@@ -130,7 +131,8 @@ public final class DeviceManagerUtil {
* @param isSharedWithAllTenants is this device type shared with all tenants.
* @return status of the operation
*/
- public static boolean registerDeviceType(String typeName, int tenantId, boolean isSharedWithAllTenants)
+ public static boolean registerDeviceType(String typeName, int tenantId, boolean isSharedWithAllTenants
+ , DeviceTypeMetaDefinition deviceTypeDefinition)
throws DeviceManagementException {
boolean status;
try {
@@ -140,7 +142,13 @@ public final class DeviceManagerUtil {
if (deviceType == null) {
deviceType = new DeviceType();
deviceType.setName(typeName);
+ deviceType.setDeviceTypeMetaDefinition(deviceTypeDefinition);
deviceTypeDAO.addDeviceType(deviceType, tenantId, isSharedWithAllTenants);
+ } else {
+ if (deviceTypeDefinition != null) {
+ deviceType.setDeviceTypeMetaDefinition(deviceTypeDefinition);
+ deviceTypeDAO.updateDeviceType(deviceType, tenantId);
+ }
}
DeviceManagementDAOFactory.commitTransaction();
status = true;
@@ -175,7 +183,7 @@ public final class DeviceManagerUtil {
throw new DeviceManagementException("Error occurred while fetching the device type '"
+ typeName + "'", e);
} catch (SQLException e) {
- throw new DeviceManagementException("Error occurred while fetching the device type '"
+ throw new DeviceManagementException("SQL Error occurred while fetching the device type '"
+ typeName + "'", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
@@ -528,4 +536,4 @@ public final class DeviceManagerUtil {
}
return deviceCache;
}
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java
index 8a7f71a66a..d555de0b41 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java
@@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@@ -77,7 +78,13 @@ public class TestDeviceManagementService implements DeviceManagementService {
return null;
}
+ @Override
+ public PullNotificationSubscriber getPullNotificationSubscriber() {
+ return null;
+ }
+
+ @Override
public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() {
return null;
}
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql
index eb06e9adcb..e71f55399d 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql
@@ -1,6 +1,8 @@
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID INT AUTO_INCREMENT NOT NULL,
NAME VARCHAR(300) NULL DEFAULT NULL,
+ DEVICE_TYPE_META VARCHAR(20000) NULL DEFAULT NULL,
+ LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (ID)
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
index cf06094b11..a526f050bb 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
@@ -22,7 +22,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
@@ -50,10 +50,6 @@
org.wso2.carbon.devicemgt
org.wso2.carbon.device.mgt.common
-
- org.wso2.carbon.devicemgt
- org.wso2.carbon.device.mgt.core
-
org.apache.ws.commons.axiom.wso2
axiom
@@ -62,10 +58,18 @@
org.wso2.carbon
org.wso2.carbon.utils
+
+ org.wso2.carbon
+ org.wso2.carbon.ndatasource.core
+
+
+ org.apache.felix
+ maven-scr-plugin
+
org.apache.felix
maven-bundle-plugin
@@ -77,14 +81,14 @@
${carbon.device.mgt.version}
Device Management Extensions Bundle
+ !org.wso2.carbon.device.mgt.extensions.internal,
org.wso2.carbon.device.mgt.extensions.*
org.wso2.carbon.governance.api.*,
javax.xml.namespace;resolution:=optional,
- org.wso2.carbon.device.mgt.core.*,
org.wso2.carbon.context,
- org.wso2.carbon.device.mgt.common,
+ org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.device.mgt.common.license.mgt,
org.wso2.carbon.registry.api,
org.wso2.carbon.registry.core,
@@ -93,8 +97,23 @@
org.wso2.carbon.base,
javax.xml.bind,
org.apache.commons.logging,
- org.wso2.carbon.utils
+ org.wso2.carbon.utils,
+ javax.naming,
+ javax.sql,
+ javax.xml,
+ javax.xml.bind.annotation,
+ javax.xml.parsers;resolution:=optional,
+ org.apache.commons.lang,
+ org.osgi.service.component,
+ org.w3c.dom,
+ org.wso2.carbon.ndatasource.core,
+ org.wso2.carbon.registry.core.service,
+ org.wso2.carbon.utils.dbcreator,
+ org.wso2.carbon.utils.multitenancy,
+ org.osgi.framework
+ org.wso2.carbon.device.mgt.extensions.pull.notification,
+ org.wso2.carbon.device.mgt.extensions.pull.notification.*
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeConfigIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeConfigIdentifier.java
similarity index 95%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeConfigIdentifier.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeConfigIdentifier.java
index a9288dd731..e2c2c02f1e 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeConfigIdentifier.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeConfigIdentifier.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template;
+package org.wso2.carbon.device.mgt.extensions.device.type.template;
import java.io.Serializable;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeGeneratorServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeGeneratorServiceImpl.java
new file mode 100644
index 0000000000..01bc313095
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeGeneratorServiceImpl.java
@@ -0,0 +1,14 @@
+package org.wso2.carbon.device.mgt.extensions.device.type.template;
+
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
+
+public class DeviceTypeGeneratorServiceImpl implements DeviceTypeGeneratorService {
+
+ @Override
+ public DeviceManagementService populateDeviceManagementService(String deviceTypeName
+ , DeviceTypeMetaDefinition deviceTypeMetaDefinition) {
+ return new HTTPDeviceTypeManagerService(deviceTypeName, deviceTypeMetaDefinition);
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
similarity index 92%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
index 602dc81b07..8bf15732a0 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template;
+package org.wso2.carbon.device.mgt.extensions.device.type.template;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -32,14 +32,14 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.*;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.util.DeviceTypePluginConstants;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeDeployerFileException;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao.DeviceDAODefinition;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao.DeviceTypePluginDAOManager;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.feature.ConfigurationBasedFeatureManager;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.DeviceTypeUtils;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.*;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinition;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.feature.ConfigurationBasedFeatureManager;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypePluginConstants;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils;
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.api.Resource;
@@ -108,7 +108,7 @@ public class DeviceTypeManager implements DeviceManager {
}
} catch (LicenseManagementException e) {
String msg = "Error occurred while adding default license for " + deviceType + " devices";
- throw new DeviceTypeDeployerFileException(msg, e);
+ throw new DeviceTypeDeployerPayloadException(msg, e);
}
claimable = false;
if (deviceTypeConfiguration.getClaimable() != null ) {
@@ -120,7 +120,7 @@ public class DeviceTypeManager implements DeviceManager {
defaultPlatformConfiguration = this.getDefaultConfiguration();
} catch (DeviceManagementException e) {
String msg = "Error occurred while default platform configuration";
- throw new DeviceTypeDeployerFileException(msg, e);
+ throw new DeviceTypeDeployerPayloadException(msg, e);
}
DeviceDetails deviceDetails = deviceTypeConfiguration.getDeviceDetails();
@@ -139,7 +139,7 @@ public class DeviceTypeManager implements DeviceManager {
}
}
if (deviceDefinitionTable == null) {
- throw new DeviceTypeDeployerFileException("Could not find definition for table: " + tableName);
+ throw new DeviceTypeDeployerPayloadException("Could not find definition for table: " + tableName);
}
propertiesExist = true;
@@ -166,11 +166,17 @@ public class DeviceTypeManager implements DeviceManager {
}
deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(datasourceName, deviceDAODefinition);
} else {
- throw new DeviceTypeDeployerFileException("Invalid datasource name.");
+ throw new DeviceTypeDeployerPayloadException("Invalid datasource name.");
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
+ } else {
+ if (deviceDetails.getProperties() != null && deviceDetails.getProperties().getProperty() != null
+ && deviceDetails.getProperties().getProperty().size() > 0 ) {
+ deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceType, deviceDetails);
+ propertiesExist = true;
+ }
}
}
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java
similarity index 74%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java
index 3fc29ccaa8..9ff760b4c9 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template;
+package org.wso2.carbon.device.mgt.extensions.device.type.template;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -31,15 +31,20 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.ConfigProperties;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceTypeConfiguration;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Property;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationProvider;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.TaskConfiguration;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceStatusTaskConfiguration;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.policy.mgt.DefaultPolicyMonitoringManager;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ConfigProperties;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceStatusTaskConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PolicyMonitoring;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PullNotificationSubscriberConfig;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.policy.mgt.DefaultPolicyMonitoringManager;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.pull.notification.PullNotificationSubscriberLoader;
import java.util.ArrayList;
import java.util.HashMap;
@@ -62,6 +67,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private List monitoringOperations;
private PolicyMonitoringManager policyMonitoringManager;
private InitialOperationConfig initialOperationConfig;
+ private PullNotificationSubscriber pullNotificationSubscriber;
private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig;
public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
@@ -76,9 +82,8 @@ public class DeviceTypeManagerService implements DeviceManagementService {
this.setInitialOperationConfig(deviceTypeConfiguration);
this.deviceStatusTaskPluginConfig = new DeviceStatusTaskPluginConfig();
this.setDeviceStatusTaskPluginConfig(deviceTypeConfiguration.getDeviceStatusTaskConfiguration());
- if (deviceTypeConfiguration.getPolicyMonitoring() != null ) {
- this.policyMonitoringManager = new DefaultPolicyMonitoringManager();
- }
+ this.setPolicyMonitoringManager(deviceTypeConfiguration.getPolicyMonitoring());
+ this.setPullNotificationSubscriber(deviceTypeConfiguration.getPullNotificationSubscriberConfig());
}
@Override
@@ -179,6 +184,11 @@ public class DeviceTypeManagerService implements DeviceManagementService {
return initialOperationConfig;
}
+ @Override
+ public PullNotificationSubscriber getPullNotificationSubscriber() {
+ return pullNotificationSubscriber;
+ }
+
public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() {
return deviceStatusTaskPluginConfig;
}
@@ -204,8 +214,24 @@ public class DeviceTypeManagerService implements DeviceManagementService {
protected void setInitialOperationConfig(DeviceTypeConfiguration deviceTypeConfiguration) {
if (deviceTypeConfiguration.getOperations() != null) {
List ops = deviceTypeConfiguration.getOperations();
- if (ops != null && !ops.isEmpty()) {
- initialOperationConfig.setOperations(ops);
+ if (!ops.isEmpty() && deviceTypeConfiguration.getFeatures() != null
+ && deviceTypeConfiguration.getFeatures().getFeature() != null) {
+ List validOps = new ArrayList<>();
+ for (String operation : ops) {
+ boolean isFeatureExist = false;
+ for (Feature feature : deviceTypeConfiguration.getFeatures().getFeature()) {
+ if (feature.getCode().equals(operation)) {
+ isFeatureExist = true;
+ break;
+ }
+ }
+ if (isFeatureExist) {
+ validOps.add(operation);
+ } else {
+ log.warn("Couldn't fine a valid feature for the operation : " + operation);
+ }
+ }
+ initialOperationConfig.setOperations(validOps);
}
}
}
@@ -221,4 +247,21 @@ public class DeviceTypeManagerService implements DeviceManagementService {
}
return propertMap;
}
+
+ private void setPolicyMonitoringManager(PolicyMonitoring policyMonitoring) {
+ if (policyMonitoring != null && policyMonitoring.isEnabled()) {
+ this.policyMonitoringManager = new DefaultPolicyMonitoringManager();
+ }
+ }
+
+ private void setPullNotificationSubscriber(PullNotificationSubscriberConfig pullNotificationSubscriberConfig) {
+ if (pullNotificationSubscriberConfig != null) {
+ String className = pullNotificationSubscriberConfig.getClassName();
+ if (className != null && !className.isEmpty()) {
+ PullNotificationSubscriberLoader pullNotificationSubscriberLoader = new PullNotificationSubscriberLoader
+ (className, pullNotificationSubscriberConfig.getConfigProperties());
+ this.pullNotificationSubscriber = pullNotificationSubscriberLoader.getPullNotificationSubscriber();
+ }
+ }
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java
new file mode 100644
index 0000000000..8f9f1f4e24
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.extensions.device.type.template;
+
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.Feature;
+import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Claimable;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ConfigProperties;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Features;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.License;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PolicyMonitoring;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ProvisioningConfig;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PullNotificationSubscriberConfig;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This inherits the capabiliy that is provided through the file based device type manager service.
+ * This will create and instance of device management service through a json payload.
+ */
+public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService implements DeviceTypeDefinitionProvider {
+
+ private DeviceTypeMetaDefinition deviceTypeMetaDefinition;
+ private static final String DEFAULT_PULL_NOTIFICATION_CLASS_NAME = "org.wso2.carbon.device.mgt.extensions.pull.notification.PullNotificationSubscriberImpl";
+
+ public HTTPDeviceTypeManagerService(String deviceTypeName, DeviceTypeMetaDefinition deviceTypeMetaDefinition) {
+ super(getDeviceTypeConfigIdentifier(deviceTypeName), getDeviceTypeConfiguration(
+ deviceTypeName, deviceTypeMetaDefinition));
+ this.deviceTypeMetaDefinition = deviceTypeMetaDefinition;
+ }
+
+ private static DeviceTypeConfiguration getDeviceTypeConfiguration(String deviceTypeName, DeviceTypeMetaDefinition
+ deviceTypeMetaDefinition) {
+ DeviceTypeConfiguration deviceTypeConfiguration = new DeviceTypeConfiguration();
+
+ if (deviceTypeMetaDefinition != null) {
+ Claimable claimable = new Claimable();
+ claimable.setEnabled(deviceTypeMetaDefinition.isClaimable());
+ deviceTypeConfiguration.setClaimable(claimable);
+
+ if (deviceTypeMetaDefinition.getProperties() != null &&
+ deviceTypeMetaDefinition.getProperties().size() > 0) {
+ DeviceDetails deviceDetails = new DeviceDetails();
+ Properties properties = new Properties();
+ properties.addProperties(deviceTypeMetaDefinition.getProperties());
+ deviceDetails.setProperties(properties);
+ deviceTypeConfiguration.setDeviceDetails(deviceDetails);
+ }
+ if (deviceTypeMetaDefinition.getFeatures() != null && deviceTypeMetaDefinition.getFeatures().size() > 0) {
+ Features features = new Features();
+ List featureList
+ = new ArrayList<>();
+ for (Feature feature : deviceTypeMetaDefinition.getFeatures()) {
+ org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature configFeature = new org
+ .wso2.carbon.device.mgt.extensions.device.type.template.config.Feature();
+ if (feature.getCode() != null && feature.getName() != null) {
+ configFeature.setCode(feature.getCode());
+ configFeature.setDescription(feature.getDescription());
+ configFeature.setName(feature.getName());
+ if (feature.getMetadataEntries() != null && feature.getMetadataEntries().size() > 0) {
+ List metaValues = new ArrayList<>();
+ for (Feature.MetadataEntry metadataEntry : feature.getMetadataEntries()) {
+ metaValues.add(metadataEntry.getValue().toString());
+ }
+ configFeature.setMetaData(metaValues);
+ }
+ featureList.add(configFeature);
+ }
+ }
+ features.addFeatures(featureList);
+ deviceTypeConfiguration.setFeatures(features);
+ }
+
+ deviceTypeConfiguration.setName(deviceTypeName);
+ //TODO: Add it to the license management service.
+// if (deviceTypeMetaDefinition.getLicense() != null) {
+// License license = new License();
+// license.setLanguage(deviceTypeMetaDefinition.getLicense().getLanguage());
+// license.setText(deviceTypeMetaDefinition.getLicense().getText());
+// license.setVersion(deviceTypeMetaDefinition.getLicense().getVersion());
+// deviceTypeConfiguration.setLicense(license);
+// }
+ PolicyMonitoring policyMonitoring = new PolicyMonitoring();
+ policyMonitoring.setEnabled(deviceTypeMetaDefinition.isPolicyMonitoringEnabled());
+ deviceTypeConfiguration.setPolicyMonitoring(policyMonitoring);
+
+ ProvisioningConfig provisioningConfig = new ProvisioningConfig();
+ provisioningConfig.setSharedWithAllTenants(false);
+ deviceTypeConfiguration.setProvisioningConfig(provisioningConfig);
+
+ PushNotificationConfig pushNotificationConfig = deviceTypeMetaDefinition.getPushNotificationConfig();
+ if (pushNotificationConfig != null) {
+ PushNotificationProvider pushNotificationProvider = new PushNotificationProvider();
+ pushNotificationProvider.setType(pushNotificationConfig.getType());
+ //default schedule value will be true.
+ pushNotificationProvider.setScheduled(true);
+ if (pushNotificationConfig.getProperties() != null &&
+ pushNotificationConfig.getProperties().size() > 0) {
+ ConfigProperties configProperties = new ConfigProperties();
+ List properties = new ArrayList<>();
+ for (Map.Entry entry : pushNotificationConfig.getProperties().entrySet()) {
+ Property property = new Property();
+ property.setName(entry.getKey());
+ property.setValue(entry.getValue());
+ properties.add(property);
+ }
+ configProperties.addProperties(properties);
+ pushNotificationProvider.setConfigProperties(configProperties);
+ }
+ pushNotificationProvider.setFileBasedProperties(true);
+ deviceTypeConfiguration.setPushNotificationProvider(pushNotificationProvider);
+ }
+
+// This is commented until the task registration handling issue is solved
+// OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceTypeMetaDefinition.getTaskConfig();
+// if (operationMonitoringTaskConfig != null) {
+// TaskConfiguration taskConfiguration = new TaskConfiguration();
+// taskConfiguration.setEnabled(operationMonitoringTaskConfig.isEnabled());
+// taskConfiguration.setFrequency(operationMonitoringTaskConfig.getFrequency());
+// if (operationMonitoringTaskConfig.getMonitoringOperation() != null) {
+// List operations = new ArrayList<>();
+// for (MonitoringOperation monitoringOperation : operationMonitoringTaskConfig
+// .getMonitoringOperation()) {
+// TaskConfiguration.Operation operation = new TaskConfiguration.Operation();
+// operation.setOperationName(monitoringOperation.getTaskName());
+// operation.setRecurrency(monitoringOperation.getRecurrentTimes());
+// operations.add(operation);
+// }
+// taskConfiguration.setOperations(operations);
+// }
+// deviceTypeConfiguration.setTaskConfiguration(taskConfiguration);
+// }
+
+ if (deviceTypeMetaDefinition.getInitialOperationConfig() != null) {
+ InitialOperationConfig initialOperationConfig = deviceTypeMetaDefinition.getInitialOperationConfig();
+ deviceTypeConfiguration.setOperations(initialOperationConfig.getOperations());
+ }
+ }
+ PullNotificationSubscriberConfig pullNotificationSubscriber = new PullNotificationSubscriberConfig();
+ pullNotificationSubscriber.setClassName(DEFAULT_PULL_NOTIFICATION_CLASS_NAME);
+ deviceTypeConfiguration.setPullNotificationSubscriberConfig(pullNotificationSubscriber);
+ return deviceTypeConfiguration;
+ }
+
+ private static DeviceTypeConfigIdentifier getDeviceTypeConfigIdentifier(String deviceType) {
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ return new DeviceTypeConfigIdentifier(deviceType, tenantDomain);
+ }
+
+ @Override
+ public DeviceTypeMetaDefinition getDeviceTypeMetaDefinition() {
+ return deviceTypeMetaDefinition;
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Attributes.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Attributes.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Attributes.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Attributes.java
index c52b1419de..43d84bfd3f 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Attributes.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Attributes.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import java.util.ArrayList;
import java.util.List;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Claimable.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Claimable.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Claimable.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Claimable.java
index 661778e62d..fdd3039597 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Claimable.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Claimable.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ConfigProperties.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/ConfigProperties.java
similarity index 93%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ConfigProperties.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/ConfigProperties.java
index 1280d8165c..8df38ca0e5 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ConfigProperties.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/ConfigProperties.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import java.util.ArrayList;
import java.util.List;
@@ -83,4 +83,8 @@ public class ConfigProperties {
return this.property;
}
+ public void addProperties(List property) {
+ this.property = property;
+ }
+
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DataSource.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DataSource.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DataSource.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DataSource.java
index f416facc4a..4e5cc80f81 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DataSource.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DataSource.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceAuthorizationConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceAuthorizationConfig.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceAuthorizationConfig.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceAuthorizationConfig.java
index 833719ba2a..9d8cf1162f 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceAuthorizationConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceAuthorizationConfig.java
@@ -17,7 +17,7 @@
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceDetails.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceDetails.java
similarity index 79%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceDetails.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceDetails.java
index 6428bf097f..b25c93f51a 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceDetails.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceDetails.java
@@ -16,13 +16,13 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.XmlValue;
/**
@@ -44,61 +44,61 @@ import javax.xml.bind.annotation.XmlValue;
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DeviceDetails", propOrder = {
- "value"
+ "properties"
})
public class DeviceDetails {
- @XmlValue
- protected String value;
@XmlAttribute(name = "table-id")
protected String tableId;
+ @XmlElement(name = "Properties", required = true)
+ protected Properties properties;
/**
- * Gets the value of the value property.
+ * Gets the value of the tableId property.
*
* @return
* possible object is
* {@link String }
*
*/
- public String getValue() {
- return value;
+ public String getTableId() {
+ return tableId;
}
/**
- * Sets the value of the value property.
+ * Sets the value of the tableId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
- public void setValue(String value) {
- this.value = value;
+ public void setTableId(String value) {
+ this.tableId = value;
}
/**
- * Gets the value of the tableId property.
- *
+ * Gets the value of the properties property.
+ *
* @return
* possible object is
- * {@link String }
- *
+ * {@link Properties }
+ *
*/
- public String getTableId() {
- return tableId;
+ public Properties getProperties() {
+ return properties;
}
/**
- * Sets the value of the tableId property.
- *
+ * Sets the value of the properties property.
+ *
* @param value
* allowed object is
- * {@link String }
- *
+ * {@link Properties }
+ *
*/
- public void setTableId(String value) {
- this.tableId = value;
+ public void setProperties(Properties value) {
+ this.properties = value;
}
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceStatusTaskConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceStatusTaskConfiguration.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceStatusTaskConfiguration.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceStatusTaskConfiguration.java
index be240c8402..588bd4a1ec 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceStatusTaskConfiguration.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceStatusTaskConfiguration.java
@@ -16,7 +16,7 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceTypeConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java
similarity index 89%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceTypeConfiguration.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java
index 8f90ffe6a0..46f442e89d 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/DeviceTypeConfiguration.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -40,7 +40,7 @@ import java.util.List;
* <element name="DeviceDetails" type="{}DeviceDetails"/>
* <element name="Features" type="{}Features"/>
* <element name="ProvisioningConfig" type="{}ProvisioningConfig"/>
- * <element name="PushNotificationProvider" type="{}PushNotificationProvider"/>
+ * <element name="PushNotificationProviderConfig" type="{}PushNotificationProviderConfig"/>
* <element name="License" type="{}License"/>
* <element name="DataSource" type="{}DataSource"/>
* <element name="PolicyMonitoring" type="{}PolicyMonitoring"/>
@@ -65,8 +65,10 @@ public class DeviceTypeConfiguration {
protected Features features;
@XmlElement(name = "ProvisioningConfig", required = true)
protected ProvisioningConfig provisioningConfig;
- @XmlElement(name = "PushNotificationProvider", required = true)
+ @XmlElement(name = "PushNotificationProviderConfig", required = true)
protected PushNotificationProvider pushNotificationProvider;
+ @XmlElement(name = "PullNotificationSubscriberConfig", required = true)
+ protected PullNotificationSubscriberConfig pullNotificationSubscriberConfig;
@XmlElement(name = "License", required = true)
protected License license;
@XmlElement(name = "DataSource", required = true)
@@ -198,7 +200,7 @@ public class DeviceTypeConfiguration {
* @param value allowed object is
* {@link DeviceDetails }
*/
- public void setDeviceDetails(PolicyMonitoring value) {
+ public void setPolicyMonitoring(PolicyMonitoring value) {
this.policyMonitoring = value;
}
@@ -262,6 +264,26 @@ public class DeviceTypeConfiguration {
this.pushNotificationProvider = value;
}
+ /**
+ * Gets the value of the PullNotificationSubscriberConfig property.
+ *
+ * @return possible object is
+ * {@link PullNotificationSubscriberConfig }
+ */
+ public PullNotificationSubscriberConfig getPullNotificationSubscriberConfig() {
+ return pullNotificationSubscriberConfig;
+ }
+
+ /**
+ * Sets the value of the PullNotificationSubscriberConfig property.
+ *
+ * @param value allowed object is
+ * {@link PullNotificationSubscriberConfig }
+ */
+ public void setPullNotificationSubscriberConfig(PullNotificationSubscriberConfig value) {
+ this.pullNotificationSubscriberConfig = value;
+ }
+
/**
* Gets the value of the license property.
*
@@ -341,4 +363,4 @@ public class DeviceTypeConfiguration {
public void setDeviceAuthorizationConfig(DeviceAuthorizationConfig value) {
this.deviceAuthorizationConfig = value;
}
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Feature.java
similarity index 89%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Feature.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Feature.java
index 0fd247cddc..800c4ff71f 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Feature.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Feature.java
@@ -16,13 +16,15 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType;
+import java.util.List;
/**
@@ -51,7 +53,7 @@ import javax.xml.bind.annotation.XmlType;
@XmlType(name = "Feature", propOrder = {
"name",
"description",
- "operation"
+ "operation", "metaData"
})
public class Feature {
@@ -63,6 +65,9 @@ public class Feature {
protected Operation operation;
@XmlAttribute(name = "code")
protected String code;
+ @XmlElementWrapper(name = "MetaData")
+ @XmlElement(name = "Property", required = true)
+ protected List metaData;
/**
* Gets the value of the name property.
@@ -160,4 +165,11 @@ public class Feature {
this.code = value;
}
+ public List getMetaData() {
+ return metaData;
+ }
+
+ public void setMetaData(List metaData) {
+ this.metaData = metaData;
+ }
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Features.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Features.java
similarity index 92%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Features.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Features.java
index 7e00b18688..1904cac3ed 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Features.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Features.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -69,4 +69,8 @@ public class Features {
return this.feature;
}
+ public void addFeatures(List features) {
+ this.feature = features;
+ }
+
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/FormParameters.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/FormParameters.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/FormParameters.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/FormParameters.java
index 6cdda89299..3cacabb3e4 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/FormParameters.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/FormParameters.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/InitialOperationConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/InitialOperationConfig.java
similarity index 93%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/InitialOperationConfig.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/InitialOperationConfig.java
index e172d7b009..cb45a1b212 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/InitialOperationConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/InitialOperationConfig.java
@@ -1,4 +1,4 @@
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.*;
import java.util.List;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/JndiConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/JndiConfig.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/JndiConfig.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/JndiConfig.java
index d28201d8a0..a07a3af080 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/JndiConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/JndiConfig.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/License.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/License.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/License.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/License.java
index 24d2feefc5..771f9f0574 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/License.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/License.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Operation.java
similarity index 98%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Operation.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Operation.java
index 0a954c242d..06fe5cf1be 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Operation.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Operation.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/PolicyMonitoring.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PolicyMonitoring.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/PolicyMonitoring.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PolicyMonitoring.java
index 12947c161e..251c598666 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/PolicyMonitoring.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PolicyMonitoring.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Properties.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Properties.java
new file mode 100644
index 0000000000..287ccf4352
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Properties.java
@@ -0,0 +1,80 @@
+
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * Java class for Properties complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType name="Properties">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="Property" maxOccurs="unbounded" minOccurs="0">
+ * <simpleType>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ * <enumeration value="attr1"/>
+ * <enumeration value="attr2"/>
+ * </restriction>
+ * </simpleType>
+ * </element>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Properties", propOrder = {
+ "property"
+})
+public class Properties {
+
+ @XmlElement(name = "Property")
+ protected List property;
+
+ /**
+ * Gets the value of the property property.
+ *
+ *
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a set
method for the property property.
+ *
+ *
+ * For example, to add a new item, do as follows:
+ *
+ * getProperty().add(newItem);
+ *
+ *
+ *
+ *
+ * Objects of the following type(s) are allowed in the list
+ * {@link String }
+ *
+ *
+ */
+ public List getProperty() {
+ if (property == null) {
+ property = new ArrayList();
+ }
+ return this.property;
+ }
+
+ public void addProperties(List property) {
+ this.property = property;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Property.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Property.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Property.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Property.java
index 82408f3d18..e79037451c 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Property.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Property.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ProvisioningConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/ProvisioningConfig.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ProvisioningConfig.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/ProvisioningConfig.java
index e6caf2f562..d54f698296 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ProvisioningConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/ProvisioningConfig.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PullNotificationSubscriberConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PullNotificationSubscriberConfig.java
new file mode 100644
index 0000000000..e18896f4e4
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PullNotificationSubscriberConfig.java
@@ -0,0 +1,106 @@
+/*
+ * 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.carbon.device.mgt.extensions.device.type.template.config;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * Java class for PullNotificationSubscriberConfig complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType name="PullNotificationSubscriberConfig">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="ConfigProperties" type="{}ConfigProperties"/>
+ * </sequence>
+ * <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "PullNotificationSubscriberConfig", propOrder = {
+ "configProperties"
+})
+public class PullNotificationSubscriberConfig {
+ @XmlElement(name = "ConfigProperties", required = true)
+ protected ConfigProperties configProperties;
+ @XmlAttribute(name = "className")
+ protected String className;
+
+ /**
+ * Gets the value of the configProperties property.
+ *
+ * @return
+ * possible object is
+ * {@link ConfigProperties }
+ *
+ */
+ public ConfigProperties getConfigProperties() {
+ return configProperties;
+ }
+
+ /**
+ * Sets the value of the configProperties property.
+ *
+ * @param value
+ * allowed object is
+ * {@link ConfigProperties }
+ *
+ */
+ public void setConfigProperties(ConfigProperties value) {
+ this.configProperties = value;
+ }
+
+ /**
+ * Gets the value of the type property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getClassName() {
+ return className;
+ }
+
+ /**
+ * Sets the value of the type property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setClassName(String value) {
+ this.className = value;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/PushNotificationProvider.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PushNotificationProvider.java
similarity index 98%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/PushNotificationProvider.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PushNotificationProvider.java
index 59e6e68b7b..2c6e4ca257 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/PushNotificationProvider.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PushNotificationProvider.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/QueryParameters.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/QueryParameters.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/QueryParameters.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/QueryParameters.java
index 0f37d49651..e79826134e 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/QueryParameters.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/QueryParameters.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Table.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Table.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Table.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Table.java
index 9cb5a926b3..6338f22142 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/Table.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/Table.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/TableConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/TableConfig.java
similarity index 97%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/TableConfig.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/TableConfig.java
index 4d912e2dd1..908046c649 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/TableConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/TableConfig.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import java.util.ArrayList;
import java.util.List;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/TaskConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/TaskConfiguration.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/TaskConfiguration.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/TaskConfiguration.java
index 6de303e557..fd31754a83 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/TaskConfiguration.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/TaskConfiguration.java
@@ -17,7 +17,7 @@
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/exception/DeviceTypeConfigurationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/exception/DeviceTypeConfigurationException.java
similarity index 94%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/exception/DeviceTypeConfigurationException.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/exception/DeviceTypeConfigurationException.java
index 70378fad0f..d044e7ebeb 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/exception/DeviceTypeConfigurationException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/exception/DeviceTypeConfigurationException.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception;
public class DeviceTypeConfigurationException extends Exception {
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/exception/InvalidConfigurationStateException.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/exception/InvalidConfigurationStateException.java
similarity index 94%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/exception/InvalidConfigurationStateException.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/exception/InvalidConfigurationStateException.java
index c3d7887b7d..3d39345327 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/exception/InvalidConfigurationStateException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/exception/InvalidConfigurationStateException.java
@@ -16,7 +16,7 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception;
public class InvalidConfigurationStateException extends RuntimeException {
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceDAODefinition.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceDAODefinition.java
similarity index 74%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceDAODefinition.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceDAODefinition.java
index 4df77a9a2c..d8f77a64a6 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceDAODefinition.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceDAODefinition.java
@@ -16,10 +16,10 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.dao;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Table;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeDeployerFileException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Table;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
import java.util.ArrayList;
import java.util.List;
@@ -45,19 +45,19 @@ public class DeviceDAODefinition {
primarykey = table.getPrimaryKey();
List attributes = table.getAttributes().getAttribute();
if (deviceTableName == null || deviceTableName.isEmpty()) {
- throw new DeviceTypeDeployerFileException("Missing deviceTableName");
+ throw new DeviceTypeDeployerPayloadException("Missing deviceTableName");
}
if (primarykey == null || primarykey.isEmpty()) {
- throw new DeviceTypeDeployerFileException("Missing primaryKey ");
+ throw new DeviceTypeDeployerPayloadException("Missing primaryKey ");
}
if (attributes == null || attributes.size() == 0) {
- throw new DeviceTypeDeployerFileException("Missing Attributes ");
+ throw new DeviceTypeDeployerPayloadException("Missing Attributes ");
}
for (String attribute : attributes) {
if (attribute.isEmpty()) {
- throw new DeviceTypeDeployerFileException("Unsupported attribute format for device definition");
+ throw new DeviceTypeDeployerPayloadException("Unsupported attribute format for device definition");
}
columnNames.add(attribute);
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypeDAOHandler.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypeDAOHandler.java
similarity index 89%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypeDAOHandler.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypeDAOHandler.java
index ce3f90c7ea..e31149fafe 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypeDAOHandler.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypeDAOHandler.java
@@ -1,9 +1,9 @@
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeDeployerFileException;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -31,7 +31,7 @@ public class DeviceTypeDAOHandler {
Context ctx = new InitialContext();
dataSource = (DataSource) ctx.lookup(datasourceName);
} catch (NamingException e) {
- throw new DeviceTypeDeployerFileException("Error while looking up the data source: " + datasourceName, e);
+ throw new DeviceTypeDeployerPayloadException("Error while looking up the data source: " + datasourceName, e);
}
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
similarity index 95%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAO.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
index 163ac64711..37331ec080 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
@@ -16,14 +16,14 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.dao;
import org.apache.commons.lang.StringUtils;
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.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.DeviceTypeUtils;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -36,9 +36,9 @@ import java.util.List;
* Implements CRUD for Devices. This holds the generic implementation. An instance of this will be created for
* each device type.
*/
-public class DeviceTypePluginDAO {
+public class DeviceTypePluginDAOImpl implements PluginDAO{
- private static final Log log = LogFactory.getLog(DeviceTypePluginDAO.class);
+ private static final Log log = LogFactory.getLog(DeviceTypePluginDAOImpl.class);
private DeviceTypeDAOHandler deviceTypeDAOHandler;
private DeviceDAODefinition deviceDAODefinition;
private String selectDBQueryForGetDevice;
@@ -47,8 +47,8 @@ public class DeviceTypePluginDAO {
private String deleteDBQueryToRemoveDevicd;
private String selectDBQueryToGetAllDevice;
- public DeviceTypePluginDAO(DeviceDAODefinition deviceDAODefinition,
- DeviceTypeDAOHandler deviceTypeDAOHandler) {
+ public DeviceTypePluginDAOImpl(DeviceDAODefinition deviceDAODefinition,
+ DeviceTypeDAOHandler deviceTypeDAOHandler) {
this.deviceTypeDAOHandler = deviceTypeDAOHandler;
this.deviceDAODefinition = deviceDAODefinition;
initializeDbQueries();
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOManager.java
new file mode 100644
index 0000000000..6a4f0e0126
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOManager.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.wso2.carbon.device.mgt.extensions.device.type.template.dao;
+
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+public class DeviceTypePluginDAOManager {
+
+ private PluginDAO deviceTypePluginDAO;
+ private DeviceTypeDAOHandler deviceTypeDAOHandler;
+ private static final String DEFAULT_DATASOURCE_NAME = "jdbc/DM_DS";
+
+ public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
+ deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName);
+ deviceTypePluginDAO = new DeviceTypePluginDAOImpl(deviceDAODefinition, deviceTypeDAOHandler);
+ }
+
+ public DeviceTypePluginDAOManager(String deviceType, DeviceDetails deviceDetails) {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext.getThreadLocalCarbonContext()
+ .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
+ try {
+ deviceTypeDAOHandler = new DeviceTypeDAOHandler(DEFAULT_DATASOURCE_NAME);
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ deviceTypePluginDAO = new PropertyBasedPluginDAOImpl(deviceDetails, deviceTypeDAOHandler, deviceType);
+ }
+
+ public PluginDAO getDeviceDAO() {
+ return deviceTypePluginDAO;
+ }
+
+ public DeviceTypeDAOHandler getDeviceTypeDAOHandler() {
+ return deviceTypeDAOHandler;
+ }
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PluginDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PluginDAO.java
new file mode 100644
index 0000000000..2ffd37f8f4
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PluginDAO.java
@@ -0,0 +1,36 @@
+/*
+ * 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.carbon.device.mgt.extensions.device.type.template.dao;
+
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
+import java.util.List;
+
+public interface PluginDAO {
+
+ Device getDevice(String deviceId) throws DeviceTypeMgtPluginException;
+
+ boolean addDevice(Device device) throws DeviceTypeMgtPluginException;
+
+ boolean updateDevice(Device device) throws DeviceTypeMgtPluginException;
+
+ boolean deleteDevice(String deviceId) throws DeviceTypeMgtPluginException;
+
+ List getAllDevices() throws DeviceTypeMgtPluginException;
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java
new file mode 100644
index 0000000000..227c352a82
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.extensions.device.type.template.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Implements CRUD for Devices. This holds the generic implementation. An instance of this will be created for
+ * each device type.
+ */
+public class PropertyBasedPluginDAOImpl implements PluginDAO {
+
+ private static final Log log = LogFactory.getLog(PropertyBasedPluginDAOImpl.class);
+ private DeviceTypeDAOHandler deviceTypeDAOHandler;
+ private List deviceProps;
+ private String deviceType;
+ private static final String PROPERTY_KEY_COLUMN_NAME = "PROPERTY_NAME";
+ private static final String PROPERTY_VALUE_COLUMN_NAME = "PROPERTY_VALUE";
+
+ public PropertyBasedPluginDAOImpl(DeviceDetails deviceDetails,
+ DeviceTypeDAOHandler deviceTypeDAOHandler, String deviceType) {
+ this.deviceTypeDAOHandler = deviceTypeDAOHandler;
+ this.deviceProps = deviceDetails.getProperties().getProperty();
+ this.deviceType = deviceType;
+ }
+
+ public Device getDevice(String deviceId) throws DeviceTypeMgtPluginException {
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ Device device = null;
+ ResultSet resultSet = null;
+ try {
+ conn = deviceTypeDAOHandler.getConnection();
+ stmt = conn.prepareStatement(
+ "SELECT * FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? AND DEVICE_IDENTIFICATION = ? " +
+ "AND TENANT_ID = ?");
+ stmt.setString(1, deviceType);
+ stmt.setString(2, deviceId);
+ stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
+ resultSet = stmt.executeQuery();
+ List properties = new ArrayList<>();
+ while (resultSet.next()) {
+ Device.Property property = new Device.Property();
+ property.setName(resultSet.getString(PROPERTY_KEY_COLUMN_NAME));
+ property.setValue(resultSet.getString(PROPERTY_VALUE_COLUMN_NAME));
+ properties.add(property);
+ }
+ if (properties.size() > 0) {
+ device = new Device();
+ device.setDeviceIdentifier(deviceId);
+ device.setType(deviceType);
+ device.setProperties(properties);
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while fetching device : '" + deviceId + "' type " + deviceType;
+ log.error(msg, e);
+ throw new DeviceTypeMgtPluginException(msg, e);
+ } finally {
+ DeviceTypeUtils.cleanupResources(stmt, resultSet);
+ deviceTypeDAOHandler.closeConnection();
+ }
+
+ return device;
+ }
+
+ public boolean addDevice(Device device) throws DeviceTypeMgtPluginException {
+ boolean status = false;
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = deviceTypeDAOHandler.getConnection();
+ stmt = conn.prepareStatement(
+ "INSERT INTO DM_DEVICE_PROPERTIES(DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, " +
+ "PROPERTY_VALUE, TENANT_ID) VALUES (?, ?, ?, ?, ?)");
+ for (String propertyKey : deviceProps) {
+ stmt.setString(1, deviceType);
+ stmt.setString(2, device.getDeviceIdentifier());
+ stmt.setString(3, propertyKey);
+ stmt.setString(4, getPropertyValue(device.getProperties(), propertyKey));
+ stmt.setInt(5, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
+ stmt.addBatch();
+ }
+ stmt.executeBatch();
+ status = true;
+ } catch (SQLException e) {
+ String msg = "Error occurred while adding the device '" +
+ device.getDeviceIdentifier() + "' to the type " + deviceType + " db.";
+ log.error(msg, e);
+ throw new DeviceTypeMgtPluginException(msg, e);
+ } finally {
+ DeviceTypeUtils.cleanupResources(stmt, null);
+ }
+ return status;
+ }
+
+ public boolean updateDevice(Device device) throws DeviceTypeMgtPluginException {
+ boolean status = false;
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = deviceTypeDAOHandler.getConnection();
+ stmt = conn.prepareStatement(
+ "UPDATE DM_DEVICE_PROPERTIES SET PROPERTY_VALUE = ? WHERE DEVICE_TYPE_NAME = ? AND " +
+ "DEVICE_IDENTIFICATION = ? AND PROPERTY_NAME = ? AND TENANT_ID= ?");
+
+ for (Device.Property property : device.getProperties()) {
+ if (!deviceProps.contains(property.getName())) {
+ continue;
+ }
+ stmt.setString(1, property.getValue());
+ stmt.setString(1, deviceType);
+ stmt.setString(2, device.getDeviceIdentifier());
+ stmt.setString(3, property.getName());
+ stmt.setInt(4, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
+ stmt.addBatch();
+ }
+ stmt.executeBatch();
+ return true;
+ } catch (SQLException e) {
+ String msg = "Error occurred while modifying the device '" +
+ device.getDeviceIdentifier() + "' data on" + deviceType;
+ log.error(msg, e);
+ throw new DeviceTypeMgtPluginException(msg, e);
+ } finally {
+ DeviceTypeUtils.cleanupResources(stmt, null);
+ }
+ }
+
+ public boolean deleteDevice(String deviceId) throws DeviceTypeMgtPluginException {
+ boolean status = false;
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = deviceTypeDAOHandler.getConnection();
+ stmt = conn.prepareStatement("DELETE FROM DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? " +
+ "AND DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?");
+ stmt.setString(1, deviceType);
+ stmt.setString(2, deviceId);
+ stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
+ int rows = stmt.executeUpdate();
+ if (rows > 0) {
+ status = true;
+ if (log.isDebugEnabled()) {
+ log.debug("device " + deviceId + " data has deleted from the " +
+ deviceType + " table.");
+ }
+ }
+ } catch (SQLException e) {
+ String msg =
+ "Error occurred while deleting " + deviceType + " device " + deviceId;
+ log.error(msg, e);
+ throw new DeviceTypeMgtPluginException(msg, e);
+ } finally {
+ DeviceTypeUtils.cleanupResources(stmt, null);
+ }
+ return status;
+ }
+
+ public List getAllDevices() throws DeviceTypeMgtPluginException {
+ Connection conn;
+ PreparedStatement stmt = null;
+ ResultSet resultSet = null;
+ Map deviceMap = new HashMap<>();
+ try {
+ conn = deviceTypeDAOHandler.getConnection();
+ stmt = conn.prepareStatement("SELECT DEVICE_IDENTIFICATION, PROPERTY_NAME, PROPERTY_VALUE FROM " +
+ "DM_DEVICE_PROPERTIES WHERE DEVICE_TYPE_NAME = ? AND TENANT_ID = ?");
+ stmt.setString(1, deviceType);
+ stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
+ resultSet = stmt.executeQuery();
+ while (resultSet.next()) {
+ String deviceId = resultSet.getString("DEVICE_IDENTIFICATION");
+ Device deviceInMap = deviceMap.get(deviceId);
+ if (deviceInMap == null) {
+ deviceInMap = new Device();
+ deviceInMap.setDeviceIdentifier(deviceId);
+ deviceInMap.setType(deviceType);
+ List properties = new ArrayList<>();
+ deviceInMap.setProperties(properties);
+ deviceMap.put(deviceId, deviceInMap);
+ }
+ Device.Property prop = new Device.Property();
+ prop.setName(resultSet.getString(PROPERTY_KEY_COLUMN_NAME));
+ prop.setName(resultSet.getString(PROPERTY_VALUE_COLUMN_NAME));
+ deviceInMap.getProperties().add(prop);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "All device details have fetched from " + deviceType + " table.");
+ }
+ return Arrays.asList((Device[])deviceMap.values().toArray());
+ } catch (SQLException e) {
+ String msg =
+ "Error occurred while fetching all " + deviceType + " device data'";
+ log.error(msg, e);
+ throw new DeviceTypeMgtPluginException(msg, e);
+ } finally {
+ DeviceTypeUtils.cleanupResources(stmt, resultSet);
+ deviceTypeDAOHandler.closeConnection();
+ }
+ }
+
+ private String getPropertyValue(List properties, String propertyName) {
+ for (Device.Property property : properties) {
+ if (property.getName() != null && property.getName().equals(propertyName)) {
+ return property.getValue();
+ }
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/exception/DeviceTypeDeployerFileException.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/exception/DeviceTypeDeployerPayloadException.java
similarity index 65%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/exception/DeviceTypeDeployerFileException.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/exception/DeviceTypeDeployerPayloadException.java
index 23b1f06c8b..b25547950e 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/exception/DeviceTypeDeployerFileException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/exception/DeviceTypeDeployerPayloadException.java
@@ -15,30 +15,30 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.exception;
/**
* This exception will be thrown if there are any issues with the content of the deployer.
*/
-public class DeviceTypeDeployerFileException extends RuntimeException {
+public class DeviceTypeDeployerPayloadException extends RuntimeException {
- public DeviceTypeDeployerFileException(String msg, Exception nestedEx) {
+ public DeviceTypeDeployerPayloadException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
- public DeviceTypeDeployerFileException(String message, Throwable cause) {
+ public DeviceTypeDeployerPayloadException(String message, Throwable cause) {
super(message, cause);
}
- public DeviceTypeDeployerFileException(String msg) {
+ public DeviceTypeDeployerPayloadException(String msg) {
super(msg);
}
- public DeviceTypeDeployerFileException() {
+ public DeviceTypeDeployerPayloadException() {
super();
}
- public DeviceTypeDeployerFileException(Throwable cause) {
+ public DeviceTypeDeployerPayloadException(Throwable cause) {
super(cause);
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/exception/DeviceTypeMgtPluginException.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/exception/DeviceTypeMgtPluginException.java
similarity index 94%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/exception/DeviceTypeMgtPluginException.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/exception/DeviceTypeMgtPluginException.java
index f5a73dafbb..b1548eb65f 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/exception/DeviceTypeMgtPluginException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/exception/DeviceTypeMgtPluginException.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.exception;
/**
* This exception will be thrown when there is an issues with the plugin generation.
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/feature/ConfigurationBasedFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java
similarity index 82%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/feature/ConfigurationBasedFeatureManager.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java
index 5d689fec5c..091123ab7d 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/feature/ConfigurationBasedFeatureManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/feature/ConfigurationBasedFeatureManager.java
@@ -16,14 +16,13 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.feature;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.feature;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Operation;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Operation;
-import javax.ws.rs.HttpMethod;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -45,13 +44,25 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
private static final Pattern PATH_PARAM_REGEX = Pattern.compile("\\{(.*?)\\}");
public ConfigurationBasedFeatureManager(
- List features) {
- for (org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature feature : features) {
+ List features) {
+ for (org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature feature : features) {
Feature deviceFeature = new Feature();
deviceFeature.setCode(feature.getCode());
deviceFeature.setName(feature.getName());
deviceFeature.setDescription(feature.getDescription());
Operation operation = feature.getOperation();
+ List metadataEntries = null;
+ if (feature.getMetaData() != null) {
+ metadataEntries = new ArrayList<>();
+ int id = 0;
+ for (String metaData : feature.getMetaData()) {
+ Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry();
+ metadataEntry.setId(id);
+ metadataEntry.setValue(metaData);
+ metadataEntries.add(metadataEntry);
+ id++;
+ }
+ }
if (operation != null) {
Map apiParams = new HashMap<>();
apiParams.put(METHOD, operation.getMethod().toUpperCase());
@@ -70,7 +81,9 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
formParams = operation.getFormParameters().getParameter();
}
apiParams.put(FORM_PARAMS, formParams);
- List metadataEntries = new ArrayList<>();
+ if (metadataEntries == null) {
+ metadataEntries = new ArrayList<>();
+ }
Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry();
metadataEntry.setId(-1);
metadataEntry.setValue(apiParams);
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/policy/mgt/DefaultPolicyMonitoringManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/policy/mgt/DefaultPolicyMonitoringManager.java
similarity index 84%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/policy/mgt/DefaultPolicyMonitoringManager.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/policy/mgt/DefaultPolicyMonitoringManager.java
index 634482db4e..3486446343 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/policy/mgt/DefaultPolicyMonitoringManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/policy/mgt/DefaultPolicyMonitoringManager.java
@@ -16,27 +16,19 @@
* under the License.
*
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.policy.mgt;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.policy.mgt;
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.Feature;
-import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Operation;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* This implementation policy monitoring manager.
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/pull/notification/PullNotificationSubscriberLoader.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/pull/notification/PullNotificationSubscriberLoader.java
new file mode 100644
index 0000000000..bdbe2d7d49
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/pull/notification/PullNotificationSubscriberLoader.java
@@ -0,0 +1,43 @@
+package org.wso2.carbon.device.mgt.extensions.device.type.template.pull.notification;
+
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ConfigProperties;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This creates an instance of the pull notification executor strategy with the given class name.
+ * makes sure the class name starts with the package prefix org.wso2.carbon.device.mgt.pull.notification.*
+ */
+public class PullNotificationSubscriberLoader {
+
+ private PullNotificationSubscriber pullNotificationSubscriber;
+
+ public PullNotificationSubscriberLoader(String className, ConfigProperties configProperties) {
+ try {
+ Class extends PullNotificationSubscriber> pullNotificationExecutorClass
+ = Class.forName(className).asSubclass(PullNotificationSubscriber.class);
+ Map properties = new HashMap<>();
+ if (configProperties != null) {
+ for (Property property : configProperties.getProperty()) {
+ properties.put(property.getName(), property.getValue());
+ }
+ }
+ pullNotificationSubscriber = pullNotificationExecutorClass.newInstance();
+ pullNotificationSubscriber.init(properties);
+ } catch (ClassNotFoundException e) {
+ throw new DeviceTypeDeployerPayloadException("Unable to find the class pull notification executor: " + className, e);
+ } catch (InstantiationException e) {
+ throw new DeviceTypeDeployerPayloadException("Unable to create an instance of :" + className, e);
+ } catch (IllegalAccessException e) {
+ throw new DeviceTypeDeployerPayloadException("Access of the instance in not allowed.", e);
+ }
+ }
+
+ public PullNotificationSubscriber getPullNotificationSubscriber() {
+ return pullNotificationSubscriber;
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceSchemaInitializer.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceSchemaInitializer.java
similarity index 96%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceSchemaInitializer.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceSchemaInitializer.java
index c436fd544b..daf5722da8 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceSchemaInitializer.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceSchemaInitializer.java
@@ -16,7 +16,7 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypePluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypePluginConstants.java
new file mode 100644
index 0000000000..4ac7c2292c
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypePluginConstants.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.extensions.device.type.template.util;
+
+/**
+ * This holds the constants used for this bundle.
+ */
+public class DeviceTypePluginConstants {
+ public static final String MEDIA_TYPE_XML = "application/xml";
+ public static final String CHARSET_UTF8 = "UTF8";
+ public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceTypeUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypeUtils.java
similarity index 93%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceTypeUtils.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypeUtils.java
index 20417fa4be..d409d22b38 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceTypeUtils.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypeUtils.java
@@ -16,14 +16,14 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util;
+package org.wso2.carbon.device.mgt.extensions.device.type.template.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.internal.DeviceTypeManagementDataHolder;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
+import org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionDataHolder;
import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.core.Registry;
@@ -101,7 +101,7 @@ public class DeviceTypeUtils {
public static Registry getConfigurationRegistry() throws DeviceTypeMgtPluginException {
try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
- return DeviceTypeManagementDataHolder.getInstance().getRegistryService()
+ return DeviceTypeExtensionDataHolder.getInstance().getRegistryService()
.getConfigSystemRegistry(tenantId);
} catch (RegistryException e) {
throw new DeviceTypeMgtPluginException("Error in retrieving conf registry instance: " + e.getMessage(), e);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionDataHolder.java
new file mode 100644
index 0000000000..69ac6b5d97
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionDataHolder.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.wso2.carbon.device.mgt.extensions.internal;
+
+import org.wso2.carbon.registry.core.service.RegistryService;
+
+/**
+ * This holds the necessary services required for the bundle.
+ */
+public class DeviceTypeExtensionDataHolder {
+
+ private RegistryService registryService;
+
+ private static DeviceTypeExtensionDataHolder thisInstance = new DeviceTypeExtensionDataHolder();
+
+ private DeviceTypeExtensionDataHolder() {}
+
+ public static DeviceTypeExtensionDataHolder getInstance() {
+ return thisInstance;
+ }
+
+ public RegistryService getRegistryService() {
+ return registryService;
+ }
+
+ public void setRegistryService(RegistryService registryService) {
+ this.registryService = registryService;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
new file mode 100644
index 0000000000..180e9717e3
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.extensions.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeGeneratorServiceImpl;
+import org.wso2.carbon.ndatasource.core.DataSourceService;
+import org.wso2.carbon.registry.core.service.RegistryService;
+
+/**
+ * @scr.component name="org.wso2.carbon.device.mgt.extensions.DeviceTypeExtensionServiceComponent"
+ * immediate="true"
+ * @scr.reference name="registry.service"
+ * interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="0..1"
+ * policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
+ * @scr.reference name="org.wso2.carbon.ndatasource"
+ * interface="org.wso2.carbon.ndatasource.core.DataSourceService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setDataSourceService"
+ * unbind="unsetDataSourceService"
+ */
+public class DeviceTypeExtensionServiceComponent {
+
+ private static final Log log = LogFactory.getLog(DeviceTypeExtensionServiceComponent.class);
+
+ protected void activate(ComponentContext ctx) {
+ if (log.isDebugEnabled()) {
+ log.debug("Activating DeviceType Deployer Service Component");
+ }
+ ctx.getBundleContext().registerService(DeviceTypeGeneratorService.class, new DeviceTypeGeneratorServiceImpl()
+ , null);
+ }
+
+ protected void deactivate(ComponentContext ctx) {
+ if (log.isDebugEnabled()) {
+ log.debug("De-activating DeviceType Deployer Service Component");
+ }
+ }
+
+ protected void setRegistryService(RegistryService registryService) {
+ if (log.isDebugEnabled()) {
+ log.debug("RegistryService acquired");
+ }
+ DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService);
+ }
+
+ protected void unsetRegistryService(RegistryService registryService) {
+ DeviceTypeExtensionDataHolder.getInstance().setRegistryService(null);
+ }
+
+ protected void setDataSourceService(DataSourceService dataSourceService) {
+ /* This is to avoid device management component getting initialized before the underlying datasources
+ are registered */
+ if (log.isDebugEnabled()) {
+ log.debug("Data source service set to android mobile service component");
+ }
+ }
+
+ protected void unsetDataSourceService(DataSourceService dataSourceService) {
+ //do nothing
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sample.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sample.xml
new file mode 100644
index 0000000000..c1d0cdadaa
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sample.xml
@@ -0,0 +1,168 @@
+
+
+
+
+
+
+
+
+
+
+ attr1
+ attr2
+
+
+
+
+
+
+ abc
+ this is a feature
+
+
+ deviceId
+
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+ true
+
+
+
+ true
+
+
+ sample.mqtt.adapter
+ tcp://localhost:1883
+ admin
+ admin
+ 0
+
+ true
+
+
+
+
+
+ admin
+
+
+
+
+
+
+ en_US
+ 1.0.0
+ This is license text
+
+
+
+ true
+ 600000
+
+
+ DEVICE_INFO
+ 1
+
+
+ APPLICATION_LIST
+ 5
+
+
+ DEVICE_LOCATION
+ 1
+
+
+
+
+
+
+ jdbc/SampleDM_DB
+
+
+
+ SAMPLE_DEVICE_ID
+
+ column1
+ column2
+
+
+
+
+
+
+
+ DEVICE_INFO
+ APPLICATION_LIST
+ DEVICE_LOCATION
+
+
+
+
+
+ false
+ 300
+ 600
+ 300
+
+
+
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml
index 27b13926de..ac860645a2 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml
@@ -22,7 +22,7 @@
device-mgt
org.wso2.carbon.devicemgt
- 3.0.8-SNAPSHOT
+ 3.0.9-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag
index 3e4c75a337..df5d11d01b 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag
@@ -167,6 +167,19 @@ if (!user) {
}else {
response.sendError(403);
}
+ } else if (uriMatcher.match("/{context}/api/devices/agent/{type}/{deviceId}/config")) {
+ elements = uriMatcher.elements();
+ deviceId = elements.deviceId;
+ type = elements.type;
+ operation = elements.operation;
+ if (userModule.isAuthorized("/permission/admin/device-mgt/devices/owning-device")) {
+ result = deviceModule.getDeviceAgentConfig(type, deviceId);
+ if (!result) {
+ response.sendError(500);
+ }
+ } else {
+ response.sendError(403);
+ }
} else if (uriMatcher.match("{context}/api/devices/{type}/{deviceId}/{operation}")) {
elements = uriMatcher.elements();
deviceId = elements.deviceId;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag
new file mode 100644
index 0000000000..6919a492a3
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag
@@ -0,0 +1,77 @@
+<%
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var uri = request.getRequestURI();
+var uriMatcher = new URIMatcher(String(uri));
+
+var log = new Log("api/stats-api.jag");
+
+var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
+var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+
+if (uriMatcher.match("/{context}/api/stats/paginate")) {
+ var deviceType = request.getParameter("deviceType");
+ var deviceId = request.getParameter("deviceId");
+ var from = request.getParameter("from");
+ var to = request.getParameter("to");
+ var index = request.getParameter("start");
+ var length = request.getParameter("length");
+ var keys = request.getParameter("attributes");
+ keys = JSON.parse(keys);
+ var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/events/"
+ + deviceType + "/" + deviceId + "?offset=" + index +"&limit=" + length + "&from="+ from + "&to=" + to;
+ serviceInvokers.XMLHttp.get(
+ restAPIEndpoint,
+ function (restAPIResponse) {
+ if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
+ var responsePayload = parse(restAPIResponse["responseText"]);
+
+ var paginatedResult = {};
+ paginatedResult["recordsTotal"] = responsePayload["count"];
+ paginatedResult["recordsFiltered"] = responsePayload["count"];
+ var records = responsePayload["records"];
+ var dataSet = [];
+ for (var i = 0; i < records.length; i++){
+ var record = records[i];
+ var timestamp = record["timestamp"];
+ var dataRow = [];
+ dataRow.push(timestamp);
+ for (var j = 0; j < keys.length; j++) {
+ var key = keys[j];
+ dataRow.push(record.values[key]);
+ }
+ //dataSet.push(dataRow);
+ dataSet.push(dataRow);
+ }
+ paginatedResult["data"] = dataSet;
+ response["status"] = restAPIResponse["status"];
+ response["content"] = paginatedResult;
+ } else {
+ response["status"] = 204;
+ var paginatedResult = {};
+ var dataSet = [];
+ paginatedResult["recordsTotal"] = 0;
+ paginatedResult["recordsFiltered"] = 0;
+ paginatedResult["data"] = dataSet;
+ response["content"] = paginatedResult;
+ }
+ }
+ );
+}
+%>
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json
index 36eda11c06..56ee92e863 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json
@@ -142,41 +142,12 @@
"perm:admin:certificates:view",
"perm:admin:certificates:add",
"perm:admin:certificates:verify",
- "perm:ios:enroll",
- "perm:ios:view-device",
- "perm:ios:apn",
- "perm:ios:ldap",
- "perm:ios:enterprise-app",
- "perm:ios:store-application",
- "perm:ios:remove-application",
- "perm:ios:app-list",
- "perm:ios:profile-list",
- "perm:ios:lock",
- "perm:ios:enterprise-wipe",
- "perm:ios:device-info",
- "perm:ios:restriction",
- "perm:ios:email",
- "perm:ios:cellular",
- "perm:ios:applications",
- "perm:ios:wifi",
- "perm:ios:ring",
- "perm:ios:location",
- "perm:ios:notification",
- "perm:ios:airplay",
- "perm:ios:caldav",
- "perm:ios:cal-subscription",
- "perm:ios:passcode-policy",
- "perm:ios:webclip",
- "perm:ios:vpn",
- "perm:ios:per-app-vpn",
- "perm:ios:app-to-per-app-vpn",
- "perm:ios:app-lock",
- "perm:ios:clear-passcode",
- "perm:ios:remove-profile",
- "perm:ios:get-restrictions",
- "perm:ios:wipe-data",
"perm:admin",
"perm:devicetype:deployment",
+ "perm:device-types:events",
+ "perm:device-types:events:view",
+ "perm:admin:device-type",
+ "perm:device:enroll",
"perm:geo-service:analytics"
],
"isOAuthEnabled": true,
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js
index 7aec083607..3181fc7a62 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js
@@ -25,7 +25,8 @@ deviceModule = function () {
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
var batchProvider = require("/app/modules/batch-provider-api.js")["batchProviders"];
-
+ var process = require("process");
+ var carbon = require("carbon");
var publicMethods = {};
var privateMethods = {};
@@ -271,6 +272,34 @@ deviceModule = function () {
}
};
+ publicMethods.getDeviceTypeCount = function () {
+ var carbonUser = session.get(constants.USER_SESSION_KEY);
+ if (carbonUser) {
+ var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
+ var uiPermissions = userModule.getUIPermissions();
+ var url;
+ if (uiPermissions.LIST_OWN_DEVICES) {
+ url = devicemgtProps["httpsURL"] +
+ devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types";
+ } else {
+ log.error("Access denied for user: " + carbonUser.username);
+ return -1;
+ }
+ return serviceInvokers.XMLHttp.get(
+ url, function (responsePayload) {
+ return parse(responsePayload["responseText"])["count"];
+ },
+ function (responsePayload) {
+ log.error(responsePayload["responseText"]);
+ return -1;
+ }
+ );
+ } else {
+ log.error("User object was not found in the session");
+ throw constants["ERRORS"]["USER_NOT_FOUND"];
+ }
+ };
+
publicMethods.getDeviceTypes = function () {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
@@ -280,6 +309,37 @@ deviceModule = function () {
return response;
};
+ publicMethods.getDeviceTypesConfig = function () {
+ var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types/config";
+ var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
+ if (response.status == "success") {
+ response.content = parse(response.content);
+ }
+ return response;
+ };
+
+ /*
+ @Updated
+ */
+ // publicMethods.getLicense = function (deviceType) {
+ // var url;
+ // var license;
+ // if (deviceType == "windows") {
+ // url = mdmProps["httpURL"] + "/mdm-windows-agent/services/device/license";
+ // } else if (deviceType == "ios") {
+ // url = mdmProps["httpsURL"] + "/ios-enrollment/license/";
+ // }
+
+ // if (url != null && url != undefined) {
+ // serviceInvokers.XMLHttp.get(url, function (responsePayload) {
+ // license = responsePayload.text;
+ // }, function (responsePayload) {
+ // return null;
+ // });
+ // }
+ // return license;
+ // };
+
publicMethods.getDevices = function (userName) {
var url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";
@@ -300,5 +360,64 @@ deviceModule = function () {
}
);
};
+
+ publicMethods.getDeviceAgentConfig = function (type, deviceId) {
+ var carbonUser = session.get(constants["USER_SESSION_KEY"]);
+ if (!carbonUser) {
+ log.error("User object was not found in the session");
+ throw constants["ERRORS"]["USER_NOT_FOUND"];
+ }
+ var userName = carbonUser.username + "@" + carbonUser.domain;
+ var config = {};
+ config.type = type;
+ config.deviceId = deviceId;
+ // register a tenant based app at API Manager
+ var applicationName = type.replace(" ", "") + "_" + carbonUser.domain;
+ var requestURL = (devicemgtProps["oauthProvider"]["appRegistration"]
+ ["apiManagerClientAppRegistrationServiceURL"]).replace("/tenants","");
+ var payload = {applicationName:applicationName, tags:["device_agent"],
+ isAllowedToAllDomains:false, validityPeriod: 3600};
+
+ serviceInvokers.XMLHttp.post(
+ requestURL, payload, function (responsePayload) {
+ var app = JSON.parse(responsePayload.responseText);
+
+ config.clientId = app["client_id"];
+ config.clientSecret = app["client_secret"];
+ if (config.clientId && config.clientSecret) {
+ var JWTClientManagerServicePackagePath =
+ "org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService";
+ //noinspection JSUnresolvedFunction, JSUnresolvedVariable
+ var JWTClientManagerService = carbon.server.osgiService(JWTClientManagerServicePackagePath);
+ //noinspection JSUnresolvedFunction
+ var jwtClient = JWTClientManagerService.getJWTClient();
+ // returning access token by JWT grant type
+ var deviceScope = "device_" + type.replace(" ", "") + "_" + deviceId + " perm:device:enroll " +
+ "perm:device:disenroll perm:device:modify perm:devices:operations perm:device:publish-event";
+ var tokenInfo = jwtClient.getAccessToken(config.clientId, config.clientSecret,
+ userName, deviceScope);
+ config.accessToken = tokenInfo.getAccessToken();
+ config.refreshToken = tokenInfo.getRefreshToken();
+ if (config.accessToken == null) {
+ return null;
+ }
+ config.mqttGateway = "tcp://" + process.getProperty("mqtt.broker.host") + ":" + process.getProperty("mqtt.broker.port");
+ config.httpsGateway = "https://" + process.getProperty("iot.gateway.host") + ":" + process.getProperty("iot.gateway.https.port");
+ config.httpGateway = "http://" + process.getProperty("iot.gateway.host") + ":" + process.getProperty("iot.gateway.http.port");
+ return config;
+ } else {
+ return null;
+ }
+ return config;
+ },
+ function (responsePayload) {
+ log.error(responsePayload);
+ return null;
+ }
+ );
+ return config;
+
+ };
+
return publicMethods;
}();
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js
index 40320806e9..7a0eeba191 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js
@@ -397,8 +397,6 @@ var utils = function () {
publicMethods["getUniqueBrowserScope"] = function () {
var deviceScope = "device_" + utility.md5(request.getHeader("User-Agent") + "::" + request.getRemoteAddr());
deviceScope = deviceScope + " ";
- log.debug("device scope");
- log.debug(deviceScope);
return deviceScope;
};
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js
index ff8fb6ea2d..cc8a20f552 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js
@@ -67,6 +67,9 @@ utility = function () {
publicMethods.getDeviceTypeConfig = function (deviceType) {
var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view");
+ if (!unitName) {
+ return null;
+ }
if (deviceType in deviceTypeConfigMap) {
return deviceTypeConfigMap[deviceType];
@@ -103,6 +106,9 @@ utility = function () {
publicMethods.getDeviceThumb = function (deviceType) {
var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view");
+ if (!unitName) {
+ unitName = "cdmf.unit.default.device.type.type-view";
+ }
var iconPath = "/app/units/" + unitName + "/public/images/thumb.png";
var icon = new File(iconPath);
if (icon.isExists()) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs
index f526cc03a3..689312a441 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs
@@ -191,6 +191,40 @@
+ {{#if permissions.IS_ADMIN}}
+
+ {{/if}}
+
{{else}}
Permitted None
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js
index 4e0c9aafa1..bc1460153c 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js
@@ -44,6 +44,7 @@ function onRequest(context) {
viewModel.groupCount = groupModule.getGroupCount();
viewModel.userCount = userModule.getUsersCount();
viewModel.policyCount = policyModule.getPoliciesCount();
+ viewModel.deviceTypeCount = deviceModule.getDeviceTypeCount();
viewModel.isCloud = devicemgtProps.isCloud;
if (devicemgtProps.isCloud) {
viewModel.roleCount = userModule.getFilteredRoles("devicemgt").content.count;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/analytics.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/analytics.js
index f77e3d14ce..54234b86db 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/analytics.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/analytics.js
@@ -21,8 +21,12 @@ function onRequest(context) {
var deviceType = context.uriParams.deviceType;
var deviceName = request.getParameter("deviceName");
var deviceId = request.getParameter("deviceId");
+ var unitName = utility.getTenantedDeviceUnitName(deviceType, "analytics-view");
+ if (!unitName) {
+ unitName = "cdmf.unit.default.device.type.analytics-view";
+ }
return {
- "deviceAnalyticsViewUnitName": utility.getTenantedDeviceUnitName(deviceType, "analytics-view"),
+ "deviceAnalyticsViewUnitName": unitName,
"deviceType": deviceType,
"deviceName": deviceName,
"deviceId": deviceId
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.type.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.type.view/view.js
index 693769dd11..6810da2496 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.type.view/view.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.type.view/view.js
@@ -32,15 +32,18 @@ function onRequest(context) {
var utility = require("/app/modules/utility.js").utility;
var deviceType = context.uriParams.deviceType;
-
var configs = utility.getDeviceTypeConfig(deviceType);
- if(!configs["deviceType"]){
- throw new Error("Invalid Device Type Configurations Found!","");
- }
-
+ var label = deviceType;
+ if (configs) {
+ label = configs["deviceType"]["label"];
+ }
+ var unitName = utility.getTenantedDeviceUnitName(deviceType, "type-view");
+ if (!unitName) {
+ unitName = "cdmf.unit.default.device.type.type-view";
+ }
return {
- "deviceTypeViewUnitName": utility.getTenantedDeviceUnitName(deviceType, "type-view"),
+ "deviceTypeViewUnitName": unitName,
"deviceType": deviceType,
- "label" : configs["deviceType"]["label"]
+ "label" : label
};
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.view/view.js
index 21ce993020..754cef4fa8 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.view/view.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.view/view.js
@@ -29,5 +29,9 @@ function onRequest(context){
});
var deviceType = context.uriParams.deviceType;
- return {"deviceViewUnitName": utility.getTenantedDeviceUnitName(deviceType, "device-view")};
+ var unitName = utility.getTenantedDeviceUnitName(deviceType, "device-view");
+ if (!unitName) {
+ unitName = "cdmf.unit.default.device.type.device-view";
+ }
+ return {"deviceViewUnitName": unitName};
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js
index 81f193ca9d..c973d07985 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js
@@ -60,20 +60,28 @@ function onRequest(context) {
if (data) {
for (var i = 0; i < data.length; i++) {
var config = utility.getDeviceTypeConfig(data[i]);
- var log = new Log("devices.js");
-
- if (!config) {
- continue;
+ var category = "iot";
+ var label = data[i];
+ var analyticsEnabled = "false";
+ var groupingEnabled = "true";
+ var analyticsView = null;
+ if (config) {
+ var deviceType = config.deviceType;
+ category = deviceType.category;
+ label = deviceType.label;
+ analyticsEnabled = deviceType.analyticsEnabled;
+ groupingEnabled = deviceType.groupingEnabled;
+ analyticsView = deviceType.analyticsView;
}
- var deviceType = config.deviceType;
+
deviceTypes.push({
"type": data[i],
- "category": deviceType.category,
- "label": deviceType.label,
+ "category": category,
+ "label": label,
"thumb": utility.getDeviceThumb(data[i]),
- "analyticsEnabled": deviceType.analyticsEnabled,
- "groupingEnabled": deviceType.groupingEnabled,
- "analyticsView" : deviceType.analyticsView
+ "analyticsEnabled": analyticsEnabled,
+ "groupingEnabled": groupingEnabled,
+ "analyticsView" : analyticsView
});
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js
index 007cb4e01c..c7518e5723 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js
@@ -404,7 +404,13 @@ function loadDevices(searchType, searchParam) {
];
var fnCreatedRow = function (row, data, dataIndex) {
- $(row).attr('data-type', 'selectable');
+
+ if(data.status != "REMOVED"){
+ $(row).attr('data-type', 'selectable');
+ }else{
+ $(row).attr('data-type', 'non-selectable');
+ }
+
$(row).attr('data-deviceid', htmlspecialchars(data.deviceIdentifier));
$(row).attr('data-devicetype', htmlspecialchars(data.deviceType));
$(row).attr('data-url', context + '/device/' + htmlspecialchars(data.deviceType) + '?id=' + htmlspecialchars(data.deviceIdentifier));
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.hbs
new file mode 100644
index 0000000000..9227e4e312
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.hbs
@@ -0,0 +1,264 @@
+{{!
+ 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.
+}}
+{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
+
+{{#zone "topCss"}}
+ {{css "css/devicetype.css"}}
+{{/zone}}
+
+{{#zone "breadcrumbs"}}
+
+
+
+
+
+
+
+
+ Device Types
+
+
+
+
+
+ Add
+
+
+{{/zone}}
+
+{{#zone "content"}}
+ {{#if canManage}}
+
+
+
+ {{else}}
+
+ Permission Denied
+
+
+ You not authorized to create device type.
+
+ {{/if}}
+{{/zone}}
+
+{{#zone "bottomJs"}}
+ {{js "js/bottomJs.js"}}
+{{/zone}}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.js
new file mode 100644
index 0000000000..f67504684b
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.js
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function onRequest(context) {
+ var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
+ var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+ var displayData = {};
+
+ if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
+ displayData.canManage = true;
+ }
+
+ return displayData;
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.json
new file mode 100644
index 0000000000..0de47dfc78
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/create.json
@@ -0,0 +1,5 @@
+{
+ "version": "1.0.0",
+ "uri": "/device-type/add",
+ "layout": "cdmf.layout.default"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/css/devicetype.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/css/devicetype.css
new file mode 100644
index 0000000000..28d691e6b0
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/css/devicetype.css
@@ -0,0 +1,19 @@
+.wr-btn-horizontal{
+ padding: 7px 10px;
+}
+
+.dontfloat {
+ clear:both;
+}
+
+.hidden-div {
+ display: none;
+}
+
+.feature-wrapper{
+ margin-top: 10px;
+}
+
+.wr-btn-secondary{
+ background-color: #617d8b;
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/js/bottomJs.js
new file mode 100644
index 0000000000..ca750b6907
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.create/public/js/bottomJs.js
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Checks if provided input is valid against RegEx input.
+ *
+ * @param regExp Regular expression
+ * @param inputString Input string to check
+ * @returns {boolean} Returns true if input matches RegEx
+ */
+function inputIsValid(regExp, inputString) {
+ regExp = new RegExp(regExp);
+ return regExp.test(inputString);
+}
+
+var validateInline = {};
+var clearInline = {};
+
+var apiBasePath = "/api/device-mgt/v1.0";
+
+
+var enableInlineError = function (inputField, errorMsg, errorSign) {
+ var fieldIdentifier = "#" + inputField;
+ var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
+ var errorSignIdentifier = "#" + inputField + " ." + errorSign;
+
+ if (inputField) {
+ $(fieldIdentifier).addClass(" has-error has-feedback");
+ }
+
+ if (errorMsg) {
+ $(errorMsgIdentifier).removeClass(" hidden");
+ }
+
+ if (errorSign) {
+ $(errorSignIdentifier).removeClass(" hidden");
+ }
+};
+
+var disableInlineError = function (inputField, errorMsg, errorSign) {
+ var fieldIdentifier = "#" + inputField;
+ var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
+ var errorSignIdentifier = "#" + inputField + " ." + errorSign;
+
+ if (inputField) {
+ $(fieldIdentifier).removeClass(" has-error has-feedback");
+ }
+
+ if (errorMsg) {
+ $(errorMsgIdentifier).addClass(" hidden");
+ }
+
+ if (errorSign) {
+ $(errorSignIdentifier).addClass(" hidden");
+ }
+};
+
+
+function formatRepo(user) {
+ if (user.loading) {
+ return user.text
+ }
+ if (!user.username) {
+ return;
+ }
+ var markup = '' +
+ '
' +
+ '
' +
+ '
' + user.username + '
';
+ if (user.name || user.name != undefined) {
+ markup += '
( ' + user.name + ' )
';
+ }
+ markup += '
';
+ return markup;
+}
+
+function formatRepoSelection(user) {
+ return user.username || user.text;
+}
+
+
+
+$(document).ready(function () {
+
+ $('[data-toggle="tooltip"]').tooltip();
+ var appContext = $("#app-context").data("app-context");
+
+ var maxField = 100; //Input fields increment limitation
+ var addButton = $('.add_button'); //Add button selector
+ var wrapper = $('.attribute_field_wrapper'); //Input field wrapper
+ var fieldHTML = $('#add-attribute-field').html(); //New input field html
+ $(addButton).click(function(){ //Once add button is clicked
+ $(wrapper).append(fieldHTML); // Add field html
+ });
+ $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
+ e.preventDefault();
+ $(this).parent('div').remove();
+ });
+
+ var addOperationButton = $('.add_operation_button'); //Add button selector
+ var operationWrapper = $('.operation_field_wrapper'); //Input field wrapper
+ var operationFieldHTML = $('#add-operation-field').html(); //New input field html
+ $(addOperationButton).click(function(){ //Once add button is clicked
+ $(operationWrapper).append(operationFieldHTML); // Add field html
+ });
+ $(operationWrapper).on('click', '.remove_operation_button', function(e){ //Once remove button is clicked
+ e.preventDefault();
+ $(this).parent('div').remove();
+ });
+
+
+ var addFeatureButton = $('.add_feature_button'); //Add button selector
+ var featureWrapper = $('.feature_field_wrapper'); //Input field wrapper
+ $(addFeatureButton).click(function(){ //Once add button is clicked
+ var featureFieldHtml = ''
+ $(featureWrapper).append(featureFieldHtml); // Add field html
+ });
+ $(featureWrapper).on('click', '.remove_feature_button', function(e){ //Once remove button is clicked
+ e.preventDefault();
+ $(this).parent('div').remove(); //Remove field html
+ });
+
+ /**
+ * Following click function would execute
+ * when a user clicks on "Add Device type" button.
+ */
+ $("button#add-devicetype-btn").click(function () {
+
+ var errorMsgWrapper = "#devicetype-create-error-msg";
+ var errorMsg = "#devicetype-create-error-msg span";
+ var deviceType = {};
+ var deviceTypeName = $("#deviceTypeName").val();
+ var deviceTypeDescription = $("#deviceTypeDescription").val();
+ if (!deviceTypeName || deviceTypeName.trim() == "" ) {
+ $(errorMsg).text("Device Type Name Cannot be empty.");
+ $(errorMsgWrapper).removeClass("hidden");
+ return;
+ }
+
+ if (!deviceTypeDescription || deviceTypeDescription.trim() == "" ) {
+ $(errorMsg).text("Device Type Description Cannot be empty.");
+ $(errorMsgWrapper).removeClass("hidden");
+ return
+ }
+
+ deviceType.name = deviceTypeName.trim();
+ deviceType.deviceTypeMetaDefinition = {}
+ deviceType.deviceTypeMetaDefinition.description = deviceTypeDescription.trim();
+
+ var pushNotification = $("#pushNotification").val();
+ if (pushNotification != "NONE") {
+ deviceType.deviceTypeMetaDefinition.pushNotificationConfig = {};
+ deviceType.deviceTypeMetaDefinition.pushNotificationConfig.scheduled = true;
+ deviceType.deviceTypeMetaDefinition.pushNotificationConfig.type = pushNotification;
+ }
+
+ var propertyValues = [];
+ $('input[name^="attribute"]').each(function() {
+ var propertyValue = $(this).val();
+ if (propertyValue.trim() != "") {
+ propertyValues.push(propertyValue.trim());
+ }
+ });
+ deviceType.deviceTypeMetaDefinition.properties = propertyValues;
+
+ var operationValues = [];
+ $('input[name^="operation"]').each(function() {
+ var operationValue = $(this).val();
+ if (operationValue.trim() != "") {
+ operationValues.push(operationValue.trim());
+ }
+ });
+ if (operationValues.length > 0) {
+ deviceType.deviceTypeMetaDefinition.initialOperationConfig = {};
+ deviceType.deviceTypeMetaDefinition.initialOperationConfig.operations = operationValues;
+ }
+
+ var features = [];
+ $('div[name^="deviceFeature"]').each(function() {
+ var featureName = $(this).find("#feature-name").val();
+ var featureCode = $(this).find("#feature-code").val();
+ var featureDescription = $(this).find("#feature-description").val();
+ if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") {
+ var feature = {};
+ feature.name = featureName.trim();
+ feature.code = featureCode.trim();
+ feature.description = featureDescription.trim();
+ features.push(feature);
+ }
+ });
+ deviceType.deviceTypeMetaDefinition.features = features;
+
+ var addRoleAPI = apiBasePath + "/admin/device-types";
+
+ invokerUtil.post(
+ addRoleAPI,
+ deviceType,
+ function (data, textStatus, jqXHR) {
+ if (jqXHR.status == 200) {
+ window.location.href = appContext + "/device-type/edit-event?type=" +
+ encodeURIComponent(deviceTypeName);
+ }
+ },
+ function (jqXHR) {
+ if (jqXHR.status == 500) {
+ $(errorMsg).text("Unexpected error.");
+ $(errorMsgWrapper).removeClass("hidden");
+ }
+ if (jqXHR.status == 400) {
+ $(errorMsg).text("Device type name should not contain whitespaces.");
+ $(errorMsgWrapper).removeClass("hidden");
+ }
+
+ if (jqXHR.status == 409) {
+ $(errorMsg).text("Device type already exists");
+ $(errorMsgWrapper).removeClass("hidden");
+ }
+ }
+ );
+ });
+
+});
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.hbs
new file mode 100644
index 0000000000..599ffcec4e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.hbs
@@ -0,0 +1,271 @@
+{{!
+ 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.
+}}
+{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
+
+{{#zone "topCss"}}
+ {{css "css/devicetype.css"}}
+{{/zone}}
+
+{{#zone "breadcrumbs"}}
+
+
+
+
+
+
+
+
+ Device Types
+
+
+
+
+
+ Edit
+
+
+{{/zone}}
+
+{{#zone "content"}}
+ {{#if canManage}}
+
+
+
+ {{else}}
+
+ Permission Denied
+
+
+ You not authorized to edit device type.
+
+ {{/if}}
+{{/zone}}
+
+{{#zone "bottomJs"}}
+ {{js "js/bottomJs.js"}}
+{{/zone}}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.js
new file mode 100644
index 0000000000..94284ac016
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.js
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function onRequest(context) {
+ var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
+ var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+ var displayData = {};
+
+
+ if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
+ displayData.canManage = true;
+ }
+ context.handlebars.registerHelper('if_eq', function(a, b, opts) {
+ if(a == b) // Or === depending on your needs
+ return opts.fn(this);
+ else
+ return opts.inverse(this);
+ });
+
+ var deviceType = request.getParameter("type");
+ var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
+ var restAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ + "/device-types/config/" + deviceType;
+ displayData.name = deviceType;
+ serviceInvokers.XMLHttp.get(
+ restAPIEndpoint,
+ function (restAPIResponse) {
+ if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
+ var typeData = parse(restAPIResponse["responseText"]);
+ displayData.type = typeData;
+
+ }
+ }
+ );
+
+ return displayData;
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.json
new file mode 100644
index 0000000000..26088b9d86
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/edit.json
@@ -0,0 +1,5 @@
+{
+ "version": "1.0.0",
+ "uri": "/device-type/edit",
+ "layout": "cdmf.layout.default"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/css/devicetype.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/css/devicetype.css
new file mode 100644
index 0000000000..19307c1c79
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/css/devicetype.css
@@ -0,0 +1,25 @@
+.wr-btn-horizontal{
+ padding: 7px 10px;
+}
+
+.dontfloat {
+ clear:both;
+}
+
+.hidden-div {
+ display: none;
+}
+
+.hidden-input {
+ display: none;
+}
+
+.feature-wrapper{
+ margin-top: 10px;
+}
+.wr-btn-secondary{
+ background-color: #617d8b;
+}
+.wr-btn-secondary{
+ background-color: #617d8b;
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js
new file mode 100644
index 0000000000..3fd2548a6f
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.edit/public/js/bottomJs.js
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Checks if provided input is valid against RegEx input.
+ *
+ * @param regExp Regular expression
+ * @param inputString Input string to check
+ * @returns {boolean} Returns true if input matches RegEx
+ */
+function inputIsValid(regExp, inputString) {
+ regExp = new RegExp(regExp);
+ return regExp.test(inputString);
+}
+
+var validateInline = {};
+var clearInline = {};
+
+var apiBasePath = "/api/device-mgt/v1.0";
+var domain = $("#domain").val();
+
+
+var enableInlineError = function (inputField, errorMsg, errorSign) {
+ var fieldIdentifier = "#" + inputField;
+ var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
+ var errorSignIdentifier = "#" + inputField + " ." + errorSign;
+
+ if (inputField) {
+ $(fieldIdentifier).addClass(" has-error has-feedback");
+ }
+
+ if (errorMsg) {
+ $(errorMsgIdentifier).removeClass(" hidden");
+ }
+
+ if (errorSign) {
+ $(errorSignIdentifier).removeClass(" hidden");
+ }
+};
+
+var disableInlineError = function (inputField, errorMsg, errorSign) {
+ var fieldIdentifier = "#" + inputField;
+ var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
+ var errorSignIdentifier = "#" + inputField + " ." + errorSign;
+
+ if (inputField) {
+ $(fieldIdentifier).removeClass(" has-error has-feedback");
+ }
+
+ if (errorMsg) {
+ $(errorMsgIdentifier).addClass(" hidden");
+ }
+
+ if (errorSign) {
+ $(errorSignIdentifier).addClass(" hidden");
+ }
+};
+
+function formatRepo(user) {
+ if (user.loading) {
+ return user.text
+ }
+ if (!user.username) {
+ return;
+ }
+ var markup = '' +
+ '
' +
+ '
' +
+ '
' + user.username + '
';
+ if (user.name || user.name != undefined) {
+ markup += '
( ' + user.name + ' )
';
+ }
+ markup += '
';
+ return markup;
+}
+
+function formatRepoSelection(user) {
+ return user.username || user.text;
+}
+
+$(document).ready(function () {
+
+ var appContext = $("#app-context").data("app-context");
+
+ var addButton = $('.add_button'); //Add button selector
+ var wrapper = $('.attribute_field_wrapper'); //Input field wrapper
+ var fieldHTML = $('#add-attribute-field').html(); //New input field html
+ $(addButton).click(function(){ //Once add button is clicked
+ $(wrapper).append(fieldHTML); // Add field html
+ });
+ $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
+ e.preventDefault();
+ $(this).parent('div').remove(); //Remove field html
+ });
+
+ var addOperationButton = $('.add_operation_button'); //Add button selector
+ var operationWrapper = $('.operation_field_wrapper'); //Input field wrapper
+ var operationFieldHTML = $('#add-operation-field').html(); //New input field html
+ $(addOperationButton).click(function(){ //Once add button is clicked
+ $(operationWrapper).append(operationFieldHTML); // Add field html
+ });
+ $(operationWrapper).on('click', '.remove_operation_button', function(e){ //Once remove button is clicked
+ e.preventDefault();
+ $(this).parent('div').remove();
+ });
+
+
+ var addFeatureButton = $('.add_feature_button'); //Add button selector
+ var featureWrapper = $('.feature_field_wrapper'); //Input field wrapper
+ $(addFeatureButton).click(function(){ //Once add button is clicked
+ var featureFieldHtml = ''
+ $(featureWrapper).append(featureFieldHtml); // Add field html
+
+ });
+ $(featureWrapper).on('click', '.remove_feature_button', function(e){ //Once remove button is clicked
+ e.preventDefault();
+ $(this).parent('div').remove(); //Remove field html
+ op--; //Decrement field counter
+ });
+
+ /**
+ * Following click function would execute
+ * when a user clicks on "Add Device type" button.
+ */
+ $("button#add-devicetype-btn").click(function () {
+
+ var errorMsgWrapper = "#devicetype-create-error-msg";
+ var errorMsg = "#devicetype-create-error-msg span";
+ var successMsgWrapper = "#devicetype-create-success-msg";
+ var successMsg = "#devicetype-create-success-msg span";
+ var deviceType = {};
+ var deviceTypeName = $("#deviceTypeName").val();
+ var deviceTypeDescription = $("#deviceTypeDescription").val();
+ if (!deviceTypeName || deviceTypeName.trim() == "" ) {
+ $(errorMsg).text("Device Type Name Cannot be empty.");
+ $(errorMsgWrapper).removeClass("hidden");
+ return;
+ }
+
+ if (!deviceTypeDescription || deviceTypeDescription.trim() == "" ) {
+ $(errorMsg).text("Device Type Description Cannot be empty.");
+ $(errorMsgWrapper).removeClass("hidden");
+ return
+ }
+
+ deviceType.name = deviceTypeName.trim();
+ deviceType.deviceTypeMetaDefinition = {}
+ deviceType.deviceTypeMetaDefinition.description = deviceTypeDescription.trim();
+
+ var pushNotification = $("#pushNotification").val();
+ if (pushNotification != "NONE") {
+ deviceType.deviceTypeMetaDefinition.pushNotificationConfig = {};
+ deviceType.deviceTypeMetaDefinition.pushNotificationConfig.scheduled = true;
+ deviceType.deviceTypeMetaDefinition.pushNotificationConfig.type = pushNotification;
+ }
+
+ var propertyValues = [];
+ $('input[name^="attribute"]').each(function() {
+ var propertyValue = $(this).val();
+ if (propertyValue.trim() != "") {
+ propertyValues.push(propertyValue.trim());
+ }
+ });
+ deviceType.deviceTypeMetaDefinition.properties = propertyValues;
+
+ var operationValues = [];
+ $('input[name^="operation"]').each(function() {
+ var operationValue = $(this).val();
+ if (operationValue.trim() != "") {
+ operationValues.push(operationValue.trim());
+ }
+ });
+ if (operationValues.length > 0) {
+ deviceType.deviceTypeMetaDefinition.initialOperationConfig = {};
+ deviceType.deviceTypeMetaDefinition.initialOperationConfig.operations = operationValues;
+ }
+
+ var features = [];
+ $('div[name^="deviceFeature"]').each(function() {
+ var featureName = $(this).find("#feature-name").val();
+ var featureCode = $(this).find("#feature-code").val();
+ if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") {
+ var feature = {};
+ feature.name = featureName.trim();
+ feature.code = featureCode.trim();
+ feature.description = $("#feature-description").val();
+ features.push(feature);
+ }
+ });
+ deviceType.deviceTypeMetaDefinition.features = features;
+
+ var addRoleAPI = apiBasePath + "/admin/device-types";
+
+ invokerUtil.put(
+ addRoleAPI,
+ deviceType,
+ function (data, textStatus, jqXHR) {
+ if (jqXHR.status == 200) {
+ $("#modalDevice").modal('show');
+ }
+ },
+ function (jqXHR) {
+ if (jqXHR.status == 500) {
+ $(errorMsg).text("Unexpected error.");
+ $(errorMsgWrapper).removeClass("hidden");
+ }
+
+ if (jqXHR.status == 409) {
+ $(errorMsg).text("Device type already exists");
+ $(errorMsgWrapper).removeClass("hidden");
+ }
+ }
+ );
+ });
+
+});
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.hbs
new file mode 100644
index 0000000000..f9707c27b8
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.hbs
@@ -0,0 +1,179 @@
+{{!
+ 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.
+}}
+{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
+
+{{#zone "topCss"}}
+ {{css "css/devicetype.css"}}
+{{/zone}}
+
+{{#zone "breadcrumbs"}}
+
+
+
+
+
+
+
+
+ Device Types
+
+
+
+
+
+ Event
+
+
+{{/zone}}
+
+{{#zone "content"}}
+ {{#if canManage}}
+
+
+
+
+
+
+
+
+ {{else}}
+
+ Permission Denied
+
+
+ You not authorized to edit device type.
+
+ {{/if}}
+{{/zone}}
+
+{{#zone "bottomJs"}}
+ {{js "js/bottomJs.js"}}
+{{/zone}}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.js
new file mode 100644
index 0000000000..d18ee388b1
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.js
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function onRequest(context) {
+ var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
+ var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+ var displayData = {};
+
+
+ if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
+ displayData.canManage = true;
+ }
+ context.handlebars.registerHelper('selected', function(a, b, opts) {
+ if(a == b) // Or === depending on your needs
+ return "selected";
+ else
+ return "";
+ });
+
+ var deviceType = request.getParameter("type");
+ var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
+ var restAPIEndpoint = deviceMgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ + "/events/" + deviceType;
+ displayData.name = deviceType;
+ serviceInvokers.XMLHttp.get(
+ restAPIEndpoint,
+ function (restAPIResponse) {
+ if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
+ var typeData = parse(restAPIResponse["responseText"]);
+ displayData.event = typeData;
+ }
+ }
+ );
+
+ return displayData;
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.json
new file mode 100644
index 0000000000..9e773121e5
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/edit.json
@@ -0,0 +1,5 @@
+{
+ "version": "1.0.0",
+ "uri": "/device-type/edit-event",
+ "layout": "cdmf.layout.default"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/css/devicetype.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/css/devicetype.css
new file mode 100644
index 0000000000..d915490351
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/css/devicetype.css
@@ -0,0 +1,29 @@
+
+
+.dontfloat {
+ clear:both;
+}
+
+.hidden-div {
+ display: none;
+}
+
+.hidden-input {
+ display: none;
+}
+
+.event-wrapper{
+ margin-top: 10px;
+}
+
+.wr-btn-horizontal{
+ padding: 7px 10px;
+}
+
+.wr-btn-secondary{
+ background-color: #617d8b;
+}
+
+.page-content-wrapper{
+ height: calc(100vh - 50px);
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/js/bottomJs.js
new file mode 100644
index 0000000000..25f94e8705
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetype.event.edit/public/js/bottomJs.js
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Checks if provided input is valid against RegEx input.
+ *
+ * @param regExp Regular expression
+ * @param inputString Input string to check
+ * @returns {boolean} Returns true if input matches RegEx
+ */
+function inputIsValid(regExp, inputString) {
+ regExp = new RegExp(regExp);
+ return regExp.test(inputString);
+}
+
+var validateInline = {};
+var clearInline = {};
+
+var apiBasePath = "/api/device-mgt/v1.0";
+var domain = $("#domain").val();
+
+
+var enableInlineError = function (inputField, errorMsg, errorSign) {
+ var fieldIdentifier = "#" + inputField;
+ var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
+ var errorSignIdentifier = "#" + inputField + " ." + errorSign;
+
+ if (inputField) {
+ $(fieldIdentifier).addClass(" has-error has-feedback");
+ }
+
+ if (errorMsg) {
+ $(errorMsgIdentifier).removeClass(" hidden");
+ }
+
+ if (errorSign) {
+ $(errorSignIdentifier).removeClass(" hidden");
+ }
+};
+
+var disableInlineError = function (inputField, errorMsg, errorSign) {
+ var fieldIdentifier = "#" + inputField;
+ var errorMsgIdentifier = "#" + inputField + " ." + errorMsg;
+ var errorSignIdentifier = "#" + inputField + " ." + errorSign;
+
+ if (inputField) {
+ $(fieldIdentifier).removeClass(" has-error has-feedback");
+ }
+
+ if (errorMsg) {
+ $(errorMsgIdentifier).addClass(" hidden");
+ }
+
+ if (errorSign) {
+ $(errorSignIdentifier).addClass(" hidden");
+ }
+};
+
+function formatRepo(user) {
+ if (user.loading) {
+ return user.text
+ }
+ if (!user.username) {
+ return;
+ }
+ var markup = '
' +
+ '
' +
+ '
' +
+ '
' + user.username + '
';
+ if (user.name || user.name != undefined) {
+ markup += '
( ' + user.name + ' )
';
+ }
+ markup += '
';
+ return markup;
+}
+
+function formatRepoSelection(user) {
+ return user.username || user.text;
+}
+
+
+
+$(document).ready(function () {
+
+ var appContext = $("#app-context").data("app-context");
+ var addEventButton = $('.add_event_button'); //Add button selector
+ var eventWrapper = $('.event_field_wrapper'); //Input field wrapper
+ $(addEventButton).click(function(){ //Once add button is clicked
+ var eventFieldHtml = '
' +
+ '
' +
+ '
' +
+ 'STRING LONG BOOL INT FLOAT ' +
+ 'DOUBLE
' +
+ '
'
+ $(eventWrapper).append(eventFieldHtml); // Add field html
+
+ });
+ $(eventWrapper).on('click', '.remove_event_button', function(e){ //Once remove button is clicked
+ e.preventDefault();
+ $(this).parent('div').remove();
+ });
+
+ /**
+ * Following click function would execute
+ * when a user clicks on "Add Device type" button.
+ */
+ $("button#add-event-btn").click(function () {
+
+ var errorMsgWrapper = "#devicetype-create-error-msg";
+ var errorMsg = "#devicetype-create-error-msg span";
+ var successMsgWrapper = "#devicetype-create-success-msg";
+ var successMsg = "#devicetype-create-success-msg span";
+ var deviceTypeEvent = {};
+ var deviceTypeName = $("#deviceTypeName").val();
+ var deviceTypeDescription = $("#deviceTypeDescription").val();
+ if (!deviceTypeName || deviceTypeName.trim() == "" ) {
+ $(errorMsg).text("Device Type Name Cannot be empty.");
+ $(errorMsgWrapper).removeClass("hidden");
+ return;
+ }
+
+
+ deviceTypeEvent.eventAttributes = {};
+
+ deviceTypeEvent.transport = $("#transport").val();
+
+ var attributes = [];
+ $('div[name^="deviceEvent"]').each(function() {
+ var eventName = $(this).find("#event-name").val();
+ var eventType = $(this).find("#event-type").val();
+ if (eventName && eventName.trim() != "" && eventType && eventType.trim() != "" && eventName != "deviceId") {
+ var attribute = {};
+ attribute.name = eventName.trim();
+ attribute.type = eventType.trim();
+ attributes.push(attribute);
+ }
+ });
+ deviceTypeEvent.eventAttributes.attributes = attributes;
+
+ var addEventsAPI = apiBasePath + "/events/" + deviceTypeName;
+
+ invokerUtil.post(
+ addEventsAPI,
+ deviceTypeEvent,
+ function (data, textStatus, jqXHR) {
+ if (jqXHR.status == 200) {
+ $("#modalDevice").modal('show');
+ }
+ },
+ function (jqXHR) {
+ if (jqXHR.status == 500) {
+ $(errorMsg).text("Failed to deploy event definition, Please Contact Administrator");
+ $(errorMsgWrapper).removeClass("hidden");
+ }
+
+ if (jqXHR.status == 409) {
+ $(errorMsg).text("Device type definition cannot be updated");
+ $(errorMsgWrapper).removeClass("hidden");
+ }
+ }
+ );
+ });
+
+
+
+});
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.hbs
new file mode 100644
index 0000000000..21dd6abb7d
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.hbs
@@ -0,0 +1,110 @@
+{{!
+ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+
+ WSO2 Inc. licenses this file to you under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except
+ in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+}}
+
+{{unit "cdmf.unit.ui.title" pageTitle="Device Type Management"}}
+{{unit "cdmf.unit.data-tables-extended"}}
+{{unit "cdmf.unit.ui.modal"}}
+
+{{#zone "breadcrumbs"}}
+
+
+
+
+
+
+
+
+ Device Types
+
+
+{{/zone}}
+
+{{#zone "navbarActions"}}
+ {{#unless isCloud}}
+
+
+
+
+
+
+
+ Create Device Type
+
+
+ {{/unless}}
+{{/zone}}
+
+{{#zone "content"}}
+ {{#if hasDeviceTypes}}
+
+
+
+ Loading device types . . .
+
+
+
+
+
+
+
+ By Device Type Name
+
+
+
+
+
+
+
+
+
+
+
Sort By
+
+
+
By Device Type name
+
+
+
+ {{else}}
+
+
+
+ {{/if}}
+{{/zone}}
+
+{{#zone "bottomJs"}}
+
+
+ {{js "js/devicetype-listing.js"}}
+{{/zone}}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.js
new file mode 100644
index 0000000000..4fb1980df5
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.js
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function onRequest(context) {
+ var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
+ var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+
+ context["permissions"] = userModule.getUIPermissions();
+ if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
+ context["editPermitted"] = true;
+ }
+ var deviceTypeCount = deviceModule.getDeviceTypeCount();
+
+ if (deviceTypeCount > 0) {
+ context["hasDeviceTypes"] = true;
+ } else {
+ context["hasDeviceTypes"] = false;
+ }
+
+ return context;
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.json
new file mode 100644
index 0000000000..4dfd684380
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/devicetypes.json
@@ -0,0 +1,5 @@
+{
+ "version": "1.0.0",
+ "uri": "/device-types",
+ "layout": "cdmf.layout.default"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/js/devicetype-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/js/devicetype-listing.js
new file mode 100644
index 0000000000..9cfe22481a
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/js/devicetype-listing.js
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var loadDeviceTypeBasedActionURL = function (action, deviceTypeName) {
+ href = $("#ast-container").data("app-context") + "device-type/" + action + "?type=" + encodeURIComponent(deviceTypeName);
+ $(location).attr('href', href);
+};
+
+$(function () {
+ var sortableElem = '.wr-sortable';
+ $(sortableElem).sortable({
+ beforeStop: function () {
+ $(this).sortable('toArray');
+ }
+ });
+ $(sortableElem).disableSelection();
+});
+
+var apiBasePath = "/api/device-mgt/v1.0";
+var modalPopup = ".modal";
+var modalPopupContainer = modalPopup + " .modal-content";
+var modalPopupContent = modalPopup + " .modal-content";
+var body = "body";
+var isInit = true;
+var isCloud = false;
+
+
+/**
+ *
+ * Fires the res_text when ever a data table redraw occurs making
+ * the font icons change the size to respective screen resolution.
+ *
+ */
+$(document).on('draw.dt', function () {
+ $(".icon .text").res_text(0.2);
+});
+
+
+/*
+ * set popup maximum height function.
+ */
+function setPopupMaxHeight() {
+ $(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30)));
+ $(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2)));
+}
+
+/*
+ * show popup function.
+ */
+function showPopup() {
+ $(modalPopup).modal('show');
+ //setPopupMaxHeight();
+}
+
+/*
+ * hide popup function.
+ */
+function hidePopup() {
+ $(modalPopupContent).html('');
+ $(modalPopup).modal('hide');
+ $('body').removeClass('modal-open').css('padding-right', '0px');
+ $('.modal-backdrop').remove();
+}
+
+
+/**
+ * Following function would execute
+ * when a user clicks on the list item
+ * initial mode and with out select mode.
+ */
+function InitiateViewOption() {
+ // $(location).attr('href', $(this).data("url"));
+}
+
+function htmlspecialchars(text) {
+ return jQuery('
').text(text).html();
+}
+
+function loadDeviceTypes() {
+ var loadingContent = $("#loading-content");
+ loadingContent.show();
+
+ var dataFilter = function (data) {
+ data = JSON.parse(data);
+ var objects = [];
+ $(data).each(function (index) {
+ objects.push(
+ {
+ name: htmlspecialchars(data[index].name),
+ DT_RowId: "devicetype-" + htmlspecialchars(data[index].name),
+ metaDefinition: (data[index].deviceTypeMetaDefinition ? true : false)
+ }
+ )
+ });
+
+ var json = {
+ "recordsTotal": data.length,
+ "recordsFiltered": data.length,
+ "data": objects
+ };
+
+ return JSON.stringify(json);
+ };
+
+ //noinspection JSUnusedLocalSymbols
+ var fnCreatedRow = function (nRow, aData, iDataIndex) {
+ $(nRow).attr('data-type', 'selectable');
+ };
+
+ //noinspection JSUnusedLocalSymbols
+ var columns = [
+ {
+ class: "remove-padding icon-only content-fill",
+ data: null,
+ defaultContent: "
" +
+ " " +
+ "
"
+ },
+ {
+ class: "",
+ data: "name",
+ render: function (name, type, row, meta) {
+ return '
' + name.replace("devicemgt", "") + ' ';
+ }
+ },
+ {
+ class: "text-right content-fill text-left-on-grid-view no-wrap",
+ data: null,
+ render: function (data, type, row, meta) {
+ var isCloud = false;
+ if ($('#is-cloud').length > 0) {
+ isCloud = true;
+ }
+
+ var innerhtml = '';
+ if (data.metaDefinition) {
+
+ var editLink = '
' +
+ '' +
+ ' ' +
+ ' ' +
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ 'Edit ' +
+ ' ';
+
+ var editEventLink = '
' +
+ '' +
+ ' ' +
+ ' ' +
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ 'Edit Event ' +
+ ' ';
+
+ innerhtml = editLink + editEventLink;
+ }
+ return innerhtml;
+ }
+ }
+ ];
+
+ var options = {
+ "placeholder": "Search By Device Type Name",
+ "searchKey": "filter",
+ "searching": false
+ };
+ var settings = {
+ "sorting": false
+ };
+ var deviceTypeApiUrl = '/api/device-mgt/v1.0/admin/device-types';
+
+ $('#devicetype-grid').datatables_extended_serverside_paging(settings, deviceTypeApiUrl, dataFilter, columns, fnCreatedRow, null, options);
+ loadingContent.hide();
+
+}
+
+$(document).ready(function () {
+ loadDeviceTypes();
+});
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/templates/devicetype-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/templates/devicetype-listing.hbs
new file mode 100644
index 0000000000..6835f28e9c
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devicetypes/public/templates/devicetype-listing.hbs
@@ -0,0 +1,44 @@
+{{#each deviceTypes}}
+
+
+
+
+
+
+ {{deviceTypeName}}
+
+
+ {{#if canEdit}}
+
+
+
+
+
+
+
+
+
+
+ Edit
+
+
+
+
+
+
+
+
+
+
+
+ Edit Event
+
+ {{/if}}
+
+
+{{/each}}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/date-picker.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/date-picker.js
index 3f89797692..5a8ac270be 100755
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/date-picker.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/date-picker.js
@@ -103,7 +103,14 @@ function setDateTime(from, to) {
// Implement drawGraph_
method in your UI unit for analytics.
var deviceTypes = $("#device-type-details").data("devicetypes");
for (var i = 0; i < deviceTypes.length; i++){
- window["drawGraph_" + deviceTypes](parseInt(from / 1000), parseInt(to / 1000));
+ try{
+ window["drawGraph_" + deviceTypes](parseInt(from / 1000), parseInt(to / 1000));
+ }catch(e){
+ }
+ try{
+ window["drawTable"](parseInt(from / 1000), parseInt(to / 1000));
+ }catch(e){
+ }
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js
index 84582854a0..d461776f24 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js
@@ -50,6 +50,12 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
var deviceType;
var ownership;
+ var searching = true;
+ if (options) {
+ if (typeof options.searching !== 'undefined') {
+ searching = options.searching;
+ }
+ }
//--- End of EMM related codes
@@ -57,7 +63,7 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
$.extend({}, {
serverSide: true,
processing: false,
- searching: true,
+ searching: searching,
ordering: false,
filter: false,
bSortCellsTop: true,
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.hbs
new file mode 100644
index 0000000000..0dd0c6a174
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.hbs
@@ -0,0 +1,114 @@
+{{!
+ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+
+ WSO2 Inc. licenses this file to you under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except
+ in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+}}
+
+{{#if control_operations}}
+
+
+ {{#each control_operations}}
+
+
+ {{name}}
+
+
+
+
+
+
+
+
+
+
+
+ {{name}}
+
+
+
+ {{description}}
+
+
+
+
+
+
+
+
+ {{/each}}
+
+{{else}}
+
+
+ Operations Loading Failed!
+
+{{/if}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{{#zone "bottomJs"}}
+ {{js "js/operation-bar.js"}}
+{{/zone}}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.js
new file mode 100644
index 0000000000..1f9ef9fc07
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.js
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function onRequest(context) {
+ var log = new Log("operation.js");
+ var deviceType = context.uriParams.deviceType;
+ var operationModule = require("/app/modules/business-controllers/operation.js")["operationModule"];
+ var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+ var restAPIEndpoint = devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ + "/devices/" + deviceType + "/operations";
+ var device = context.unit.params.device;
+ var features = context.unit.params.features;
+ return {"control_operations": features, "device": device, "operationEndpoint": restAPIEndpoint};
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.json
new file mode 100644
index 0000000000..688e939808
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/operation-bar.json
@@ -0,0 +1,3 @@
+{
+ "version": "1.0.0"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/public/js/operation-bar.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/public/js/operation-bar.js
new file mode 100644
index 0000000000..5707f092d1
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.operation-bar/public/js/operation-bar.js
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * On operation click function.
+ * @param selection: Selected operation
+ */
+function operationSelect(selection) {
+ $(modalPopupContent).addClass("operation-data");
+ $(modalPopupContent).html($(" .operation[data-operation-code=" + selection + "]").html());
+ $(modalPopupContent).data("operation-code", selection);
+ showPopup();
+}
+
+function submitForm(formId) {
+ var form = $("#" + formId);
+ var operationDetails = $("#operation-details");
+ var deviceId = operationDetails.data("deviceid");
+ var operationEndpoint = operationDetails.data("endpoint");
+ var contentType = "application/json";
+
+ var payload = {};
+ var devices=[];
+ devices.push(deviceId);
+ payload["deviceIdentifiers"] = devices;
+ var operation = {};
+ operation["code"] = form.find("#operation-code").val();
+ operation["type"]= form.find("#operation-type").val();
+ operation["status"] = "PENDING";
+ operation["control"] = "REPEAT";
+ operation["payLoad"] = form.find("#operation-payload").val();
+ operation["enabled"] = true;
+ payload["operation"] = operation;
+
+ //setting responses callbacks
+ var defaultStatusClasses = "fw fw-stack-1x";
+ var content = $("#operation-response-template").find(".content");
+ var title = content.find("#title");
+ var statusIcon = content.find("#status-icon");
+ var description = content.find("#description");
+ var successCallBack = function (response) {
+ var res = response;
+ try {
+ res = JSON.parse(response).messageFromServer;
+ } catch (err) {
+ //do nothing
+ }
+ title.html("Operation Triggered!");
+ statusIcon.attr("class", defaultStatusClasses + " fw-check");
+ description.html(res);
+ $(modalPopupContent).html(content.html());
+ };
+ var errorCallBack = function (response) {
+ console.log(response);
+ title.html("An Error Occurred!");
+ statusIcon.attr("class", defaultStatusClasses + " fw-error");
+ var reason = (response.responseText == "null")?response.statusText:response.responseText;
+ description.html(reason);
+ $(modalPopupContent).html(content.html());
+ };
+ invokerUtil.post(operationEndpoint, payload, successCallBack, errorCallBack, contentType);
+}
+
+$(document).on('submit', 'form', function (e) {
+ e.preventDefault();
+ var postOperationRequest = $.ajax({
+ url: $(this).attr("action") + '&' + $(this).serialize(),
+ method: "post"
+ });
+
+ var btnSubmit = $('#btnSend', this);
+ btnSubmit.addClass('hidden');
+
+ var lblSending = $('#lblSending', this);
+ lblSending.removeClass('hidden');
+
+ var lblSent = $('#lblSent', this);
+ postOperationRequest.done(function (data) {
+ lblSending.addClass('hidden');
+ lblSent.removeClass('hidden');
+ setTimeout(function () {
+ hidePopup();
+ }, 3000);
+ });
+
+ postOperationRequest.fail(function (jqXHR, textStatus) {
+ lblSending.addClass('hidden');
+ lblSent.addClass('hidden');
+ });
+});
+
+function operationTypeChage(selectElement) {
+ if (selectElement.value == "COMMAND") {
+ $("#operation-payload").hide();
+ } else {
+ $("#operation-payload").show();
+ }
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.hbs
new file mode 100644
index 0000000000..e122c8539f
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.hbs
@@ -0,0 +1,27 @@
+{{!
+ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+
+ WSO2 Inc. licenses this file to you under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except
+ in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+}}
+
+
+ {{#each device.initialDeviceInfo}}
+
+ {{@key}}
+ {{this}}
+
+ {{/each}}
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.js
new file mode 100644
index 0000000000..4638be4277
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.js
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function onRequest (context) {
+ var log = new Log("overview-section.js");
+ var device = context.unit.params.device;
+ return {"device" : device};
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.json
new file mode 100644
index 0000000000..688e939808
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.overview-section/overview-section.json
@@ -0,0 +1,3 @@
+{
+ "version": "1.0.0"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.hbs
new file mode 100644
index 0000000000..456b895631
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.hbs
@@ -0,0 +1,47 @@
+{{!
+ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+
+ WSO2 Inc. licenses this file to you under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except
+ in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+}}
+
+{{unit "cdmf.unit.data-tables-extended"}}
+
+
+
+{{#if attributes}}
+
+{{else}}
+
Analytics Not Configured
+{{/if}}
+
+
+{{#zone "bottomJs"}}
+ {{js "js/device.js"}}
+{{/zone}}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.js
new file mode 100644
index 0000000000..6a16f8eb5d
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.js
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function onRequest(context) {
+
+ var deviceType = context.uriParams.deviceType;
+ var deviceId = request.getParameter("deviceId");
+ var keys = [];
+ var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
+ var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+
+ if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
+ var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
+ var device = deviceModule.viewDevice(deviceType, deviceId);
+
+ var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ + "/events/" + deviceType;
+ serviceInvokers.XMLHttp.get(
+ restAPIEndpoint,
+ function (restAPIResponse) {
+ if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
+ var data = parse(restAPIResponse["responseText"]);
+ if (data.eventAttributes.attributes.length > 0) {
+ for (var i = 0; i < data.eventAttributes.attributes.length; i++) {
+ var attribute = data.eventAttributes.attributes[i];
+ if (attribute['name'] == "deviceId") {
+ continue;
+ }
+ keys.push(attribute['name']);
+ }
+ }
+
+ }
+ }
+ );
+
+ if (device && device.status != "error") {
+ if (keys.length === 0 || keys.length === undefined) {
+ return {
+ "device": device.content,
+ "backendApiUri": "/api/device-mgt/v1.0/events/" + deviceType
+ };
+ } else {
+
+ return {
+ "device": device.content,
+ "backendApiUri": "/api/device-mgt/v1.0/events/" + deviceType,
+ "attributes": keys
+ };
+ }
+ } else {
+ response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
+ exit();
+ }
+ }
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.json
new file mode 100644
index 0000000000..688e939808
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/analytics-view.json
@@ -0,0 +1,3 @@
+{
+ "version": "1.0.0"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/public/js/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/public/js/device.js
new file mode 100644
index 0000000000..e7a216dd3e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/public/js/device.js
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var InitiateViewOption = null;
+var deviceId = null;
+var deviceType = null;
+var fromTime = null;
+var toTime = null;
+var keys = null;
+
+function drawTable(from, to) {
+ var device = $("#device-details");
+ deviceId = device.data("deviceid");
+ deviceType = device.data("devicetype");
+ keys = device.data("attributes").split(",");
+ fromTime = from * 1000;
+ toTime = to * 1000;
+ if ( $.fn.dataTable.isDataTable( '#stats-table' ) ) {
+ var table = $('#stats-table').DataTable();
+ table.clear().draw();
+ table.ajax.reload();
+ }
+ else {
+ $("#stats-table").datatables_extended({
+ serverSide: true,
+ processing: false,
+ searching: false,
+ ordering: false,
+ pageLength: 100,
+ order: [],
+ ajax: {
+ url: "/devicemgt/api/stats/paginate",
+ data: buildAjaxData
+ }
+ });
+ }
+}
+
+function buildAjaxData (){
+ var settings = $("#stats-table").dataTable().fnSettings();
+
+ var obj = {
+ //default params
+ "draw" : settings.iDraw,
+ "start" : settings._iDisplayStart,
+ "length" : settings._iDisplayLength,
+ "columns" : "",
+ "order": "",
+ "deviceType" : deviceType,
+ "deviceId" : deviceId,
+ "from": fromTime,
+ "to" : toTime,
+ "attributes" : JSON.stringify(keys)
+ };
+
+ return obj;
+
+
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.hbs
new file mode 100644
index 0000000000..d4491a3f33
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.hbs
@@ -0,0 +1,188 @@
+{{!
+ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+
+ WSO2 Inc. licenses this file to you under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except
+ in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+}}
+{{#zone "topCss"}}
+
+{{/zone}}
+
+{{#zone "device-thumbnail"}}
+
+{{/zone}}
+
+{{#zone "device-details"}}
+ {{unit "cdmf.unit.default.device.overview-section" device=device}}
+{{/zone}}
+
+{{#zone "device-opetations"}}
+ {{#if features}}
+
+
+
Device Operations
+
+ {{unit "cdmf.unit.default.device.operation-bar" device=device features=features}}
+
+ {{/if}}
+{{/zone}}
+
+{{#zone "device-view-tabs"}}
+ {{#if attributes}}
+ Device
+ Statistics
+
+ {{/if}}
+ {{#if features}}
+ Operations Log
+ {{/if}}
+{{/zone}}
+
+{{#zone "device-view-tab-contents"}}
+ {{#if attributes}}
+
+
Device Event
+ {{unit "cdmf.unit.default.device.type.realtime.analytics-view" device=device attributes=attributes}}
+
+ {{/if}}
+ {{#if features}}
+
+
+
+
+
+
+
+
+ Loading Operations Log . . .
+
+
+
+
+
+ Not available yet
+
+
+
+
+
+ {{/if}}
+
+
Device Communication
+
+ {{#if event}}
+
publish device events :
+ {{#if_eq event.transport "MQTT"}}
+
+ MQTT Topic :
+ {{tenantDomain}}/{{device.type}}/<device_id>/events
+
+ {{#if eventSample}}
+
+ Device Event Payload :
+ {{eventSample}}
+
+ {{/if}}
+ {{/if_eq}}
+ {{#if_eq event.transport "HTTP"}}
+
+ curl -k -X POST {{httpsGateway}}/api/device-mgt/v1.0/device/agent/events/publish/{{device.type}}/{{device.deviceIdentifier}}
+ -H 'authorization: Bearer %accessToken%'
+ -H 'content-type: application/json'
+ -d '{{eventSample}}'
+
+
+ {{/if_eq}}
+ {{/if}}
+
+
Retrieve operations
+ {{#if type.deviceTypeMetaDefinition.pushNotificationConfig}}
+ {{#if_eq type.deviceTypeMetaDefinition.pushNotificationConfig.type "MQTT"}}
+
+
MQTT Topic :
+
{{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/#
+
+
+
Topic Structure :
+
+
+ {{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/command/<feature_code>/<operation_id>
+
+
+ {{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/config/<feature_code>/<operation_id>
+
+
+ {{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/profile/<feature_code>/<operation_id>
+
+
+ {{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/policy/policy_bundle
+
+
+ {{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/operation/policy/policy_revoke
+
+
+
+
+
+ Operation Response :
+ {{tenantDomain}}/{{device.type}}/{{device.deviceIdentifier}}/update/operation
+
+
+ Payload :
+ {"id": 1,"status": "COMPLETED", "operationResponse": "this is my response"}
+
+
+
+ {{/if_eq}}
+ {{else}}
+
+ Retrieve pending operation :
+ curl -k -X GET {{httpsGateway}}/api/device-mgt/v1.0/device/agent/pending/operations/{{device.type}}/{{device.deviceIdentifier}} -H 'authorization: Bearer %accessToken%' -H 'content-type: application/json'
+
+
+ Retrieve next pending operation :
+ curl -k -X GET {{httpsGateway}}/api/device-mgt/v1.0/device/agent/next-pending/{{device.type}}/{{device.deviceIdentifier}} -H 'authorization: Bearer %accessToken%' -H 'content-type: application/json'
+
+
+ Update operation :
+ curl -k -X PUT {{httpsGateway}}/api/device-mgt/v1.0/device/agent/operations/{{device.type}}/{{device.deviceIdentifier}} -H 'authorization: Bearer %accessToken%' -H 'content-type: application/json' -d '{"id": 1,"status": "COMPLETED", "payload": "this is my response"}'
+
+
+ {{/if}}
+
+
+
+
+{{/zone}}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.js
new file mode 100644
index 0000000000..445106e6d0
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.js
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
+var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+var process = require("process");
+var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
+function onRequest(context) {
+ var log = new Log("device-view.js");
+ var deviceType = context.uriParams.deviceType;
+ var deviceId = request.getParameter("id");
+ var attributes = [];
+ var featureList = [];
+ var user = userModule.getCarbonUser();
+ var tenantDomain = user.domain;
+
+ var autoCompleteParams = [
+ {"name" : "deviceId", "value" : deviceId}
+ ];
+ context.handlebars.registerHelper('if_eq', function(a, b, opts) {
+ if(a == b) // Or === depending on your needs
+ return opts.fn(this);
+ else
+ return opts.inverse(this);
+ });
+
+ var displayData = {};
+
+ var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ + "/device-types/config/" + deviceType;
+ displayData.deviceType = deviceType;
+ displayData.tenantDomain = tenantDomain;
+ serviceInvokers.XMLHttp.get(
+ restAPIEndpoint,
+ function (restAPIResponse) {
+ if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
+ var typeData = parse(restAPIResponse["responseText"]);
+ displayData.type = typeData;
+ if (typeData.deviceTypeMetaDefinition) {
+ var features = typeData.deviceTypeMetaDefinition.features;
+ if (features) {
+ var feature;
+ for (var i = 0; i < features.length; i++) {
+ feature = {};
+ feature["operation"] = features[i].code;
+ feature["name"] = features[i].name;
+ feature["description"] = features[i].description;
+ featureList.push(feature);
+ }
+ }
+ }
+ }
+ }
+ );
+
+ var eventRestAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ + "/events/" + deviceType;
+ serviceInvokers.XMLHttp.get(
+ eventRestAPIEndpoint,
+ function (restAPIResponse) {
+ if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
+ var typeData = parse(restAPIResponse["responseText"]);
+ displayData.event = typeData;
+ var sampleValue = "";
+ if (typeData.eventAttributes && typeData.eventAttributes.attributes) {
+ var eventExample = {};
+ for (var i = 0; i < typeData.eventAttributes.attributes.length; i++) {
+ var attribute = typeData.eventAttributes.attributes[i];
+ if (attribute['name'] == "deviceId") {
+ continue;
+ }
+ attributes.push(attribute['name']);
+
+ switch (attribute.type) {
+ case "STRING":
+ eventExample[attribute.name] = "string";
+ sampleValue = sampleValue + "\"string\", ";
+ break;
+ case "LONG":
+ eventExample[attribute.name] = 0;
+ sampleValue = sampleValue + 0 +", ";
+ break;
+ case "INT":
+ eventExample[attribute.name] = 0;
+ sampleValue = sampleValue + 0 +", ";
+ break;
+ case "FLOAT":
+ eventExample[attribute.name] = 0.0;
+ sampleValue = sampleValue + 0.0 +", ";
+ break;
+ case "DOUBLE":
+ eventExample[attribute.name] = 0.0;
+ sampleValue = sampleValue + 0.0 +", ";
+ break;
+ case "BOOL":
+ eventExample[attribute.name] = false;
+ sampleValue = sampleValue + false + ", ";
+ break;
+
+ }
+
+ }
+ var sample = eventExample;
+ if (sampleValue && sampleValue.length > 2) {
+ displayData.sampleValue = sampleValue.substring(0, sampleValue.length - 2);
+ }
+ displayData.eventSample = JSON.stringify(sample);
+ displayData.mqttGateway = "tcp://" + process.getProperty("mqtt.broker.host") + ":" + process.getProperty("mqtt.broker.port");
+ displayData.httpsGateway = "https://" + process.getProperty("iot.gateway.host") + ":" + process.getProperty("iot.gateway.https.port");
+
+ }
+ }
+ }
+ );
+
+ displayData.tenantDomain = tenantDomain;
+
+ if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
+ var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
+ var device = deviceModule.viewDevice(deviceType, deviceId);
+ if (device && device.status != "error") {
+ displayData.device = device.content;
+ displayData.autoCompleteParams = autoCompleteParams;
+ displayData.encodedFeaturePayloads = "";
+ displayData.features = featureList;
+ if (attributes.length === 0 || attributes.length === undefined) {
+ return displayData;
+ } else {
+ displayData.attributes = attributes;
+ return displayData;
+ }
+ } else {
+ response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
+ exit();
+ }
+ }
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.json
new file mode 100644
index 0000000000..9eecd8f5bf
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/device-view.json
@@ -0,0 +1,3 @@
+{
+ "version": "1.0.0"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/public/images/deviceType.png b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/public/images/deviceType.png
new file mode 100644
index 0000000000..71e5c0c28b
Binary files /dev/null and b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.device-view/public/images/deviceType.png differ
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.hbs
new file mode 100644
index 0000000000..6911c698fc
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.hbs
@@ -0,0 +1,45 @@
+{{!
+ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+
+ WSO2 Inc. licenses this file to you under the Apache License,
+ Version 2.0 (the "License"); you may not use this file except
+ in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+}}
+{{unit "cdmf.unit.lib.rickshaw-graph"}}
+
+
+
{{#if timestamp}}Last Known:{{timestamp}}{{/if}}
+
+
+ {{#each events}}
+
+ {{this.key}}
+ {{this.value}}
+
+ {{/each}}
+
+
+
+
+
+
+
+ View Device Analytics
+
+
+{{#zone "bottomJs"}}
+ {{js "js/moment.min.js"}}
+ {{js "js/socket.io.min.js"}}
+ {{js "js/device-stats.js"}}
+{{/zone}}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.js
new file mode 100644
index 0000000000..cfefa850e0
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.js
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
+var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+
+function onRequest(context) {
+ var log = new Log("stats.js");
+ var carbonServer = require("carbon").server;
+ var device = context.unit.params.device;
+ var attributes = context.unit.params.attributes;
+ var events = [];
+ var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
+ var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
+ var constants = require("/app/modules/constants.js");
+ var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss");
+ var jwtService = carbonServer.osgiService(
+ 'org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService');
+ var jwtClient = jwtService.getJWTClient();
+ var encodedClientKeys = session.get(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"]);
+ var token = "";
+ var user = userModule.getCarbonUser();
+ var tenantDomain = user.domain;
+ if (encodedClientKeys) {
+ var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"];
+ var resp = tokenUtil.decode(encodedClientKeys).split(":");
+ if (tenantDomain == "carbon.super") {
+ var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {});
+ if (tokenPair) {
+ token = tokenPair.accessToken;
+ }
+ websocketEndpoint = websocketEndpoint + "/secured-websocket/iot.per.device.stream." + tenantDomain + "." + device.type + "/1.0.0?"
+ + "deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token;
+ } else {
+ var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username + "@" + tenantDomain,"default", {});
+ if (tokenPair) {
+ token = tokenPair.accessToken;
+ }
+ websocketEndpoint = websocketEndpoint + "/secured-websocket" + "/t/" + tenantDomain + "/iot.per.device.stream." + tenantDomain
+ + "." + device.type + "/1.0.0?" + "deviceId=" + device.deviceIdentifier + "&deviceType="
+ + device.type + "&websocketToken=" + token;
+ }
+
+ }
+ var events = [];
+ var viewModel = {};
+ viewModel.device = device;
+ viewModel.websocketEndpoint = websocketEndpoint;
+
+ var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
+ + "/events/last-known/" + device.type + "/" + device.deviceIdentifier;
+ serviceInvokers.XMLHttp.get(
+ restAPIEndpoint,
+ function (restAPIResponse) {
+ if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
+ var responsePayload = parse(restAPIResponse["responseText"]);
+ var records = responsePayload["records"];
+ if (records && records[0] && records[0].values) {
+ var record = records[0].values;
+ viewModel.timestamp = new Date(records[0].timestamp);
+ for (var eventAttribute in attributes){
+ var event = {};
+ event.key = attributes[eventAttribute];
+ event.value = record["" + attributes[eventAttribute]];
+ events.push(event);
+ }
+ } else {
+ for (var eventAttribute in attributes){
+ var event = {};
+ event.key = attributes[eventAttribute];
+ event.value = "-";
+ events.push(event);
+ }
+ }
+
+ }
+ }
+ );
+ viewModel.attributes = attributes;
+ viewModel.events = events;
+ return viewModel;
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.json
new file mode 100644
index 0000000000..688e939808
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.json
@@ -0,0 +1,3 @@
+{
+ "version": "1.0.0"
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/device-stats.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/device-stats.js
new file mode 100644
index 0000000000..48bc419600
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/device-stats.js
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var ws;
+var attributes = null;
+$(window).load(function () {
+ var div = $("#div-chart");
+ var websocketUrl = div.data("websocketurl");
+ attributes = div.data("attributes").split(",");
+ connect(websocketUrl)
+});
+
+$(window).unload(function () {
+ disconnect();
+});
+
+//websocket connection
+function connect(target) {
+ if ('WebSocket' in window) {
+ ws = new WebSocket(target);
+ } else if ('MozWebSocket' in window) {
+ ws = new MozWebSocket(target);
+ } else {
+ console.log('WebSocket is not supported by this browser.');
+ }
+ if (ws) {
+ ws.onmessage = function (webSocketData) {
+ var data = JSON.parse(webSocketData.data);
+ console.log(data);
+ var payloadData = data["event"]["payloadData"];
+ for (var i = 0; i < attributes.length; i++){
+ $("#" + attributes[i] +"-value").text(payloadData[attributes[i]]);
+ }
+ $("#time-mode").text("Real Time Mode");
+ };
+ }
+}
+
+function disconnect() {
+ if (ws != null) {
+ ws.close();
+ ws = null;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/moment.min.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/moment.min.js
new file mode 100644
index 0000000000..d0b48f73e9
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/moment.min.js
@@ -0,0 +1,7 @@
+//! moment.js
+//! version : 2.10.2
+//! authors : Tim Wood, Iskren Chernev, Moment.js contributors
+//! license : MIT
+//! momentjs.com
+!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.moment=b()}(this,function(){"use strict";function a(){return Ac.apply(null,arguments)}function b(a){Ac=a}function c(){return{empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1}}function d(a){return"[object Array]"===Object.prototype.toString.call(a)}function e(a){return"[object Date]"===Object.prototype.toString.call(a)||a instanceof Date}function f(a,b){var c,d=[];for(c=0;c0)for(c in Cc)d=Cc[c],e=b[d],"undefined"!=typeof e&&(a[d]=e);return a}function m(b){l(this,b),this._d=new Date(+b._d),Dc===!1&&(Dc=!0,a.updateOffset(this),Dc=!1)}function n(a){return a instanceof m||null!=a&&g(a,"_isAMomentObject")}function o(a){var b=+a,c=0;return 0!==b&&isFinite(b)&&(c=b>=0?Math.floor(b):Math.ceil(b)),c}function p(a,b,c){var d,e=Math.min(a.length,b.length),f=Math.abs(a.length-b.length),g=0;for(d=0;e>d;d++)(c&&a[d]!==b[d]||!c&&o(a[d])!==o(b[d]))&&g++;return g+f}function q(){}function r(a){return a?a.toLowerCase().replace("_","-"):a}function s(a){for(var b,c,d,e,f=0;f0;){if(d=t(e.slice(0,b).join("-")))return d;if(c&&c.length>=b&&p(e,c,!0)>=b-1)break;b--}f++}return null}function t(a){var b=null;if(!Ec[a]&&"undefined"!=typeof module&&module&&module.exports)try{b=Bc._abbr,require("./locale/"+a),u(b)}catch(c){}return Ec[a]}function u(a,b){var c;return a&&(c="undefined"==typeof b?w(a):v(a,b),c&&(Bc=c)),Bc._abbr}function v(a,b){return null!==b?(b.abbr=a,Ec[a]||(Ec[a]=new q),Ec[a].set(b),u(a),Ec[a]):(delete Ec[a],null)}function w(a){var b;if(a&&a._locale&&a._locale._abbr&&(a=a._locale._abbr),!a)return Bc;if(!d(a)){if(b=t(a))return b;a=[a]}return s(a)}function x(a,b){var c=a.toLowerCase();Fc[c]=Fc[c+"s"]=Fc[b]=a}function y(a){return"string"==typeof a?Fc[a]||Fc[a.toLowerCase()]:void 0}function z(a){var b,c,d={};for(c in a)g(a,c)&&(b=y(c),b&&(d[b]=a[c]));return d}function A(b,c){return function(d){return null!=d?(C(this,b,d),a.updateOffset(this,c),this):B(this,b)}}function B(a,b){return a._d["get"+(a._isUTC?"UTC":"")+b]()}function C(a,b,c){return a._d["set"+(a._isUTC?"UTC":"")+b](c)}function D(a,b){var c;if("object"==typeof a)for(c in a)this.set(c,a[c]);else if(a=y(a),"function"==typeof this[a])return this[a](b);return this}function E(a,b,c){for(var d=""+Math.abs(a),e=a>=0;d.lengthb;b++)d[b]=Jc[d[b]]?Jc[d[b]]:G(d[b]);return function(e){var f="";for(b=0;c>b;b++)f+=d[b]instanceof Function?d[b].call(e,a):d[b];return f}}function I(a,b){return a.isValid()?(b=J(b,a.localeData()),Ic[b]||(Ic[b]=H(b)),Ic[b](a)):a.localeData().invalidDate()}function J(a,b){function c(a){return b.longDateFormat(a)||a}var d=5;for(Hc.lastIndex=0;d>=0&&Hc.test(a);)a=a.replace(Hc,c),Hc.lastIndex=0,d-=1;return a}function K(a,b,c){Yc[a]="function"==typeof b?b:function(a){return a&&c?c:b}}function L(a,b){return g(Yc,a)?Yc[a](b._strict,b._locale):new RegExp(M(a))}function M(a){return a.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(a,b,c,d,e){return b||c||d||e}).replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function N(a,b){var c,d=b;for("string"==typeof a&&(a=[a]),"number"==typeof b&&(d=function(a,c){c[b]=o(a)}),c=0;cd;d++){if(e=i([2e3,d]),c&&!this._longMonthsParse[d]&&(this._longMonthsParse[d]=new RegExp("^"+this.months(e,"").replace(".","")+"$","i"),this._shortMonthsParse[d]=new RegExp("^"+this.monthsShort(e,"").replace(".","")+"$","i")),c||this._monthsParse[d]||(f="^"+this.months(e,"")+"|^"+this.monthsShort(e,""),this._monthsParse[d]=new RegExp(f.replace(".",""),"i")),c&&"MMMM"===b&&this._longMonthsParse[d].test(a))return d;if(c&&"MMM"===b&&this._shortMonthsParse[d].test(a))return d;if(!c&&this._monthsParse[d].test(a))return d}}function U(a,b){var c;return"string"==typeof b&&(b=a.localeData().monthsParse(b),"number"!=typeof b)?a:(c=Math.min(a.date(),Q(a.year(),b)),a._d["set"+(a._isUTC?"UTC":"")+"Month"](b,c),a)}function V(b){return null!=b?(U(this,b),a.updateOffset(this,!0),this):B(this,"Month")}function W(){return Q(this.year(),this.month())}function X(a){var b,c=a._a;return c&&-2===a._pf.overflow&&(b=c[_c]<0||c[_c]>11?_c:c[ad]<1||c[ad]>Q(c[$c],c[_c])?ad:c[bd]<0||c[bd]>24||24===c[bd]&&(0!==c[cd]||0!==c[dd]||0!==c[ed])?bd:c[cd]<0||c[cd]>59?cd:c[dd]<0||c[dd]>59?dd:c[ed]<0||c[ed]>999?ed:-1,a._pf._overflowDayOfYear&&($c>b||b>ad)&&(b=ad),a._pf.overflow=b),a}function Y(b){a.suppressDeprecationWarnings===!1&&"undefined"!=typeof console&&console.warn&&console.warn("Deprecation warning: "+b)}function Z(a,b){var c=!0;return h(function(){return c&&(Y(a),c=!1),b.apply(this,arguments)},b)}function $(a,b){hd[a]||(Y(b),hd[a]=!0)}function _(a){var b,c,d=a._i,e=id.exec(d);if(e){for(a._pf.iso=!0,b=0,c=jd.length;c>b;b++)if(jd[b][1].exec(d)){a._f=jd[b][0]+(e[6]||" ");break}for(b=0,c=kd.length;c>b;b++)if(kd[b][1].exec(d)){a._f+=kd[b][0];break}d.match(Vc)&&(a._f+="Z"),sa(a)}else a._isValid=!1}function aa(b){var c=ld.exec(b._i);return null!==c?void(b._d=new Date(+c[1])):(_(b),void(b._isValid===!1&&(delete b._isValid,a.createFromInputFallback(b))))}function ba(a,b,c,d,e,f,g){var h=new Date(a,b,c,d,e,f,g);return 1970>a&&h.setFullYear(a),h}function ca(a){var b=new Date(Date.UTC.apply(null,arguments));return 1970>a&&b.setUTCFullYear(a),b}function da(a){return ea(a)?366:365}function ea(a){return a%4===0&&a%100!==0||a%400===0}function fa(){return ea(this.year())}function ga(a,b,c){var d,e=c-b,f=c-a.day();return f>e&&(f-=7),e-7>f&&(f+=7),d=za(a).add(f,"d"),{week:Math.ceil(d.dayOfYear()/7),year:d.year()}}function ha(a){return ga(a,this._week.dow,this._week.doy).week}function ia(){return this._week.dow}function ja(){return this._week.doy}function ka(a){var b=this.localeData().week(this);return null==a?b:this.add(7*(a-b),"d")}function la(a){var b=ga(this,1,4).week;return null==a?b:this.add(7*(a-b),"d")}function ma(a,b,c,d,e){var f,g,h=ca(a,0,1).getUTCDay();return h=0===h?7:h,c=null!=c?c:e,f=e-h+(h>d?7:0)-(e>h?7:0),g=7*(b-1)+(c-e)+f+1,{year:g>0?a:a-1,dayOfYear:g>0?g:da(a-1)+g}}function na(a){var b=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==a?b:this.add(a-b,"d")}function oa(a,b,c){return null!=a?a:null!=b?b:c}function pa(a){var b=new Date;return a._useUTC?[b.getUTCFullYear(),b.getUTCMonth(),b.getUTCDate()]:[b.getFullYear(),b.getMonth(),b.getDate()]}function qa(a){var b,c,d,e,f=[];if(!a._d){for(d=pa(a),a._w&&null==a._a[ad]&&null==a._a[_c]&&ra(a),a._dayOfYear&&(e=oa(a._a[$c],d[$c]),a._dayOfYear>da(e)&&(a._pf._overflowDayOfYear=!0),c=ca(e,0,a._dayOfYear),a._a[_c]=c.getUTCMonth(),a._a[ad]=c.getUTCDate()),b=0;3>b&&null==a._a[b];++b)a._a[b]=f[b]=d[b];for(;7>b;b++)a._a[b]=f[b]=null==a._a[b]?2===b?1:0:a._a[b];24===a._a[bd]&&0===a._a[cd]&&0===a._a[dd]&&0===a._a[ed]&&(a._nextDay=!0,a._a[bd]=0),a._d=(a._useUTC?ca:ba).apply(null,f),null!=a._tzm&&a._d.setUTCMinutes(a._d.getUTCMinutes()-a._tzm),a._nextDay&&(a._a[bd]=24)}}function ra(a){var b,c,d,e,f,g,h;b=a._w,null!=b.GG||null!=b.W||null!=b.E?(f=1,g=4,c=oa(b.GG,a._a[$c],ga(za(),1,4).year),d=oa(b.W,1),e=oa(b.E,1)):(f=a._locale._week.dow,g=a._locale._week.doy,c=oa(b.gg,a._a[$c],ga(za(),f,g).year),d=oa(b.w,1),null!=b.d?(e=b.d,f>e&&++d):e=null!=b.e?b.e+f:f),h=ma(c,d,e,g,f),a._a[$c]=h.year,a._dayOfYear=h.dayOfYear}function sa(b){if(b._f===a.ISO_8601)return void _(b);b._a=[],b._pf.empty=!0;var c,d,e,f,g,h=""+b._i,i=h.length,j=0;for(e=J(b._f,b._locale).match(Gc)||[],c=0;c0&&b._pf.unusedInput.push(g),h=h.slice(h.indexOf(d)+d.length),j+=d.length),Jc[f]?(d?b._pf.empty=!1:b._pf.unusedTokens.push(f),P(f,d,b)):b._strict&&!d&&b._pf.unusedTokens.push(f);b._pf.charsLeftOver=i-j,h.length>0&&b._pf.unusedInput.push(h),b._pf.bigHour===!0&&b._a[bd]<=12&&(b._pf.bigHour=void 0),b._a[bd]=ta(b._locale,b._a[bd],b._meridiem),qa(b),X(b)}function ta(a,b,c){var d;return null==c?b:null!=a.meridiemHour?a.meridiemHour(b,c):null!=a.isPM?(d=a.isPM(c),d&&12>b&&(b+=12),d||12!==b||(b=0),b):b}function ua(a){var b,d,e,f,g;if(0===a._f.length)return a._pf.invalidFormat=!0,void(a._d=new Date(0/0));for(f=0;fg)&&(e=g,d=b));h(a,d||b)}function va(a){if(!a._d){var b=z(a._i);a._a=[b.year,b.month,b.day||b.date,b.hour,b.minute,b.second,b.millisecond],qa(a)}}function wa(a){var b,c=a._i,e=a._f;return a._locale=a._locale||w(a._l),null===c||void 0===e&&""===c?k({nullInput:!0}):("string"==typeof c&&(a._i=c=a._locale.preparse(c)),n(c)?new m(X(c)):(d(e)?ua(a):e?sa(a):xa(a),b=new m(X(a)),b._nextDay&&(b.add(1,"d"),b._nextDay=void 0),b))}function xa(b){var c=b._i;void 0===c?b._d=new Date:e(c)?b._d=new Date(+c):"string"==typeof c?aa(b):d(c)?(b._a=f(c.slice(0),function(a){return parseInt(a,10)}),qa(b)):"object"==typeof c?va(b):"number"==typeof c?b._d=new Date(c):a.createFromInputFallback(b)}function ya(a,b,d,e,f){var g={};return"boolean"==typeof d&&(e=d,d=void 0),g._isAMomentObject=!0,g._useUTC=g._isUTC=f,g._l=d,g._i=a,g._f=b,g._strict=e,g._pf=c(),wa(g)}function za(a,b,c,d){return ya(a,b,c,d,!1)}function Aa(a,b){var c,e;if(1===b.length&&d(b[0])&&(b=b[0]),!b.length)return za();for(c=b[0],e=1;ea&&(a=-a,c="-"),c+E(~~(a/60),2)+b+E(~~a%60,2)})}function Ga(a){var b=(a||"").match(Vc)||[],c=b[b.length-1]||[],d=(c+"").match(qd)||["-",0,0],e=+(60*d[1])+o(d[2]);return"+"===d[0]?e:-e}function Ha(b,c){var d,f;return c._isUTC?(d=c.clone(),f=(n(b)||e(b)?+b:+za(b))-+d,d._d.setTime(+d._d+f),a.updateOffset(d,!1),d):za(b).local();return c._isUTC?za(b).zone(c._offset||0):za(b).local()}function Ia(a){return 15*-Math.round(a._d.getTimezoneOffset()/15)}function Ja(b,c){var d,e=this._offset||0;return null!=b?("string"==typeof b&&(b=Ga(b)),Math.abs(b)<16&&(b=60*b),!this._isUTC&&c&&(d=Ia(this)),this._offset=b,this._isUTC=!0,null!=d&&this.add(d,"m"),e!==b&&(!c||this._changeInProgress?Za(this,Ua(b-e,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,a.updateOffset(this,!0),this._changeInProgress=null)),this):this._isUTC?e:Ia(this)}function Ka(a,b){return null!=a?("string"!=typeof a&&(a=-a),this.utcOffset(a,b),this):-this.utcOffset()}function La(a){return this.utcOffset(0,a)}function Ma(a){return this._isUTC&&(this.utcOffset(0,a),this._isUTC=!1,a&&this.subtract(Ia(this),"m")),this}function Na(){return this._tzm?this.utcOffset(this._tzm):"string"==typeof this._i&&this.utcOffset(Ga(this._i)),this}function Oa(a){return a=a?za(a).utcOffset():0,(this.utcOffset()-a)%60===0}function Pa(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Qa(){if(this._a){var a=this._isUTC?i(this._a):za(this._a);return this.isValid()&&p(this._a,a.toArray())>0}return!1}function Ra(){return!this._isUTC}function Sa(){return this._isUTC}function Ta(){return this._isUTC&&0===this._offset}function Ua(a,b){var c,d,e,f=a,h=null;return Ea(a)?f={ms:a._milliseconds,d:a._days,M:a._months}:"number"==typeof a?(f={},b?f[b]=a:f.milliseconds=a):(h=rd.exec(a))?(c="-"===h[1]?-1:1,f={y:0,d:o(h[ad])*c,h:o(h[bd])*c,m:o(h[cd])*c,s:o(h[dd])*c,ms:o(h[ed])*c}):(h=sd.exec(a))?(c="-"===h[1]?-1:1,f={y:Va(h[2],c),M:Va(h[3],c),d:Va(h[4],c),h:Va(h[5],c),m:Va(h[6],c),s:Va(h[7],c),w:Va(h[8],c)}):null==f?f={}:"object"==typeof f&&("from"in f||"to"in f)&&(e=Xa(za(f.from),za(f.to)),f={},f.ms=e.milliseconds,f.M=e.months),d=new Da(f),Ea(a)&&g(a,"_locale")&&(d._locale=a._locale),d}function Va(a,b){var c=a&&parseFloat(a.replace(",","."));return(isNaN(c)?0:c)*b}function Wa(a,b){var c={milliseconds:0,months:0};return c.months=b.month()-a.month()+12*(b.year()-a.year()),a.clone().add(c.months,"M").isAfter(b)&&--c.months,c.milliseconds=+b-+a.clone().add(c.months,"M"),c}function Xa(a,b){var c;return b=Ha(b,a),a.isBefore(b)?c=Wa(a,b):(c=Wa(b,a),c.milliseconds=-c.milliseconds,c.months=-c.months),c}function Ya(a,b){return function(c,d){var e,f;return null===d||isNaN(+d)||($(b,"moment()."+b+"(period, number) is deprecated. Please use moment()."+b+"(number, period)."),f=c,c=d,d=f),c="string"==typeof c?+c:c,e=Ua(c,d),Za(this,e,a),this}}function Za(b,c,d,e){var f=c._milliseconds,g=c._days,h=c._months;e=null==e?!0:e,f&&b._d.setTime(+b._d+f*d),g&&C(b,"Date",B(b,"Date")+g*d),h&&U(b,B(b,"Month")+h*d),e&&a.updateOffset(b,g||h)}function $a(a){var b=a||za(),c=Ha(b,this).startOf("day"),d=this.diff(c,"days",!0),e=-6>d?"sameElse":-1>d?"lastWeek":0>d?"lastDay":1>d?"sameDay":2>d?"nextDay":7>d?"nextWeek":"sameElse";return this.format(this.localeData().calendar(e,this,za(b)))}function _a(){return new m(this)}function ab(a,b){var c;return b=y("undefined"!=typeof b?b:"millisecond"),"millisecond"===b?(a=n(a)?a:za(a),+this>+a):(c=n(a)?+a:+za(a),c<+this.clone().startOf(b))}function bb(a,b){var c;return b=y("undefined"!=typeof b?b:"millisecond"),"millisecond"===b?(a=n(a)?a:za(a),+a>+this):(c=n(a)?+a:+za(a),+this.clone().endOf(b)a?Math.ceil(a):Math.floor(a)}function fb(a,b,c){var d,e,f=Ha(a,this),g=6e4*(f.utcOffset()-this.utcOffset());return b=y(b),"year"===b||"month"===b||"quarter"===b?(e=gb(this,f),"quarter"===b?e/=3:"year"===b&&(e/=12)):(d=this-f,e="second"===b?d/1e3:"minute"===b?d/6e4:"hour"===b?d/36e5:"day"===b?(d-g)/864e5:"week"===b?(d-g)/6048e5:d),c?e:eb(e)}function gb(a,b){var c,d,e=12*(b.year()-a.year())+(b.month()-a.month()),f=a.clone().add(e,"months");return 0>b-f?(c=a.clone().add(e-1,"months"),d=(b-f)/(f-c)):(c=a.clone().add(e+1,"months"),d=(b-f)/(c-f)),-(e+d)}function hb(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")}function ib(){var a=this.clone().utc();return 0b;b++)if(this._weekdaysParse[b]||(c=za([2e3,1]).day(b),d="^"+this.weekdays(c,"")+"|^"+this.weekdaysShort(c,"")+"|^"+this.weekdaysMin(c,""),this._weekdaysParse[b]=new RegExp(d.replace(".",""),"i")),this._weekdaysParse[b].test(a))return b}function Jb(a){var b=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=a?(a=Eb(a,this.localeData()),this.add(a-b,"d")):b}function Kb(a){var b=(this.day()+7-this.localeData()._week.dow)%7;return null==a?b:this.add(a-b,"d")}function Lb(a){return null==a?this.day()||7:this.day(this.day()%7?a:a-7)}function Mb(a,b){F(a,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),b)})}function Nb(a,b){return b._meridiemParse}function Ob(a){return"p"===(a+"").toLowerCase().charAt(0)}function Pb(a,b,c){return a>11?c?"pm":"PM":c?"am":"AM"}function Qb(a){F(0,[a,3],0,"millisecond")}function Rb(){return this._isUTC?"UTC":""}function Sb(){return this._isUTC?"Coordinated Universal Time":""}function Tb(a){return za(1e3*a)}function Ub(){return za.apply(null,arguments).parseZone()}function Vb(a,b,c){var d=this._calendar[a];return"function"==typeof d?d.call(b,c):d}function Wb(a){var b=this._longDateFormat[a];return!b&&this._longDateFormat[a.toUpperCase()]&&(b=this._longDateFormat[a.toUpperCase()].replace(/MMMM|MM|DD|dddd/g,function(a){return a.slice(1)}),this._longDateFormat[a]=b),b}function Xb(){return this._invalidDate}function Yb(a){return this._ordinal.replace("%d",a)}function Zb(a){return a}function $b(a,b,c,d){var e=this._relativeTime[c];return"function"==typeof e?e(a,b,c,d):e.replace(/%d/i,a)}function _b(a,b){var c=this._relativeTime[a>0?"future":"past"];return"function"==typeof c?c(b):c.replace(/%s/i,b)}function ac(a){var b,c;for(c in a)b=a[c],"function"==typeof b?this[c]=b:this["_"+c]=b;this._ordinalParseLenient=new RegExp(this._ordinalParse.source+"|"+/\d{1,2}/.source)}function bc(a,b,c,d){var e=w(),f=i().set(d,b);return e[c](f,a)}function cc(a,b,c,d,e){if("number"==typeof a&&(b=a,a=void 0),a=a||"",null!=b)return bc(a,b,c,e);var f,g=[];for(f=0;d>f;f++)g[f]=bc(a,f,c,e);return g}function dc(a,b){return cc(a,b,"months",12,"month")}function ec(a,b){return cc(a,b,"monthsShort",12,"month")}function fc(a,b){return cc(a,b,"weekdays",7,"day")}function gc(a,b){return cc(a,b,"weekdaysShort",7,"day")}function hc(a,b){return cc(a,b,"weekdaysMin",7,"day")}function ic(){var a=this._data;return this._milliseconds=Od(this._milliseconds),this._days=Od(this._days),this._months=Od(this._months),a.milliseconds=Od(a.milliseconds),a.seconds=Od(a.seconds),a.minutes=Od(a.minutes),a.hours=Od(a.hours),a.months=Od(a.months),a.years=Od(a.years),this}function jc(a,b,c,d){var e=Ua(b,c);return a._milliseconds+=d*e._milliseconds,a._days+=d*e._days,a._months+=d*e._months,a._bubble()}function kc(a,b){return jc(this,a,b,1)}function lc(a,b){return jc(this,a,b,-1)}function mc(){var a,b,c,d=this._milliseconds,e=this._days,f=this._months,g=this._data,h=0;return g.milliseconds=d%1e3,a=eb(d/1e3),g.seconds=a%60,b=eb(a/60),g.minutes=b%60,c=eb(b/60),g.hours=c%24,e+=eb(c/24),h=eb(nc(e)),e-=eb(oc(h)),f+=eb(e/30),e%=30,h+=eb(f/12),f%=12,g.days=e,g.months=f,g.years=h,this}function nc(a){return 400*a/146097}function oc(a){return 146097*a/400}function pc(a){var b,c,d=this._milliseconds;if(a=y(a),"month"===a||"year"===a)return b=this._days+d/864e5,c=this._months+12*nc(b),"month"===a?c:c/12;switch(b=this._days+Math.round(oc(this._months/12)),a){case"week":return b/7+d/6048e5;case"day":return b+d/864e5;case"hour":return 24*b+d/36e5;case"minute":return 24*b*60+d/6e4;case"second":return 24*b*60*60+d/1e3;case"millisecond":return Math.floor(24*b*60*60*1e3)+d;default:throw new Error("Unknown unit "+a)}}function qc(){return this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*o(this._months/12)}function rc(a){return function(){return this.as(a)}}function sc(a){return a=y(a),this[a+"s"]()}function tc(a){return function(){return this._data[a]}}function uc(){return eb(this.days()/7)}function vc(a,b,c,d,e){return e.relativeTime(b||1,!!c,a,d)}function wc(a,b,c){var d=Ua(a).abs(),e=ce(d.as("s")),f=ce(d.as("m")),g=ce(d.as("h")),h=ce(d.as("d")),i=ce(d.as("M")),j=ce(d.as("y")),k=e0,k[4]=c,vc.apply(null,k)}function xc(a,b){return void 0===de[a]?!1:void 0===b?de[a]:(de[a]=b,!0)}function yc(a){var b=this.localeData(),c=wc(this,!a,b);return a&&(c=b.pastFuture(+this,c)),b.postformat(c)}function zc(){var a=ee(this.years()),b=ee(this.months()),c=ee(this.days()),d=ee(this.hours()),e=ee(this.minutes()),f=ee(this.seconds()+this.milliseconds()/1e3),g=this.asSeconds();return g?(0>g?"-":"")+"P"+(a?a+"Y":"")+(b?b+"M":"")+(c?c+"D":"")+(d||e||f?"T":"")+(d?d+"H":"")+(e?e+"M":"")+(f?f+"S":""):"P0D"}var Ac,Bc,Cc=a.momentProperties=[],Dc=!1,Ec={},Fc={},Gc=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|x|X|zz?|ZZ?|.)/g,Hc=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,Ic={},Jc={},Kc=/\d/,Lc=/\d\d/,Mc=/\d{3}/,Nc=/\d{4}/,Oc=/[+-]?\d{6}/,Pc=/\d\d?/,Qc=/\d{1,3}/,Rc=/\d{1,4}/,Sc=/[+-]?\d{1,6}/,Tc=/\d+/,Uc=/[+-]?\d+/,Vc=/Z|[+-]\d\d:?\d\d/gi,Wc=/[+-]?\d+(\.\d{1,3})?/,Xc=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,Yc={},Zc={},$c=0,_c=1,ad=2,bd=3,cd=4,dd=5,ed=6;F("M",["MM",2],"Mo",function(){return this.month()+1}),F("MMM",0,0,function(a){return this.localeData().monthsShort(this,a)}),F("MMMM",0,0,function(a){return this.localeData().months(this,a)}),x("month","M"),K("M",Pc),K("MM",Pc,Lc),K("MMM",Xc),K("MMMM",Xc),N(["M","MM"],function(a,b){b[_c]=o(a)-1}),N(["MMM","MMMM"],function(a,b,c,d){var e=c._locale.monthsParse(a,d,c._strict);null!=e?b[_c]=e:c._pf.invalidMonth=a});var fd="January_February_March_April_May_June_July_August_September_October_November_December".split("_"),gd="Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),hd={};a.suppressDeprecationWarnings=!1;var id=/^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,jd=[["YYYYYY-MM-DD",/[+-]\d{6}-\d{2}-\d{2}/],["YYYY-MM-DD",/\d{4}-\d{2}-\d{2}/],["GGGG-[W]WW-E",/\d{4}-W\d{2}-\d/],["GGGG-[W]WW",/\d{4}-W\d{2}/],["YYYY-DDD",/\d{4}-\d{3}/]],kd=[["HH:mm:ss.SSSS",/(T| )\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss",/(T| )\d\d:\d\d:\d\d/],["HH:mm",/(T| )\d\d:\d\d/],["HH",/(T| )\d\d/]],ld=/^\/?Date\((\-?\d+)/i;a.createFromInputFallback=Z("moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.",function(a){a._d=new Date(a._i+(a._useUTC?" UTC":""))}),F(0,["YY",2],0,function(){return this.year()%100}),F(0,["YYYY",4],0,"year"),F(0,["YYYYY",5],0,"year"),F(0,["YYYYYY",6,!0],0,"year"),x("year","y"),K("Y",Uc),K("YY",Pc,Lc),K("YYYY",Rc,Nc),K("YYYYY",Sc,Oc),K("YYYYYY",Sc,Oc),N(["YYYY","YYYYY","YYYYYY"],$c),N("YY",function(b,c){c[$c]=a.parseTwoDigitYear(b)}),a.parseTwoDigitYear=function(a){return o(a)+(o(a)>68?1900:2e3)};var md=A("FullYear",!1);F("w",["ww",2],"wo","week"),F("W",["WW",2],"Wo","isoWeek"),x("week","w"),x("isoWeek","W"),K("w",Pc),K("ww",Pc,Lc),K("W",Pc),K("WW",Pc,Lc),O(["w","ww","W","WW"],function(a,b,c,d){b[d.substr(0,1)]=o(a)});var nd={dow:0,doy:6};F("DDD",["DDDD",3],"DDDo","dayOfYear"),x("dayOfYear","DDD"),K("DDD",Qc),K("DDDD",Mc),N(["DDD","DDDD"],function(a,b,c){c._dayOfYear=o(a)}),a.ISO_8601=function(){};var od=Z("moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548",function(){var a=za.apply(null,arguments);return this>a?this:a}),pd=Z("moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548",function(){var a=za.apply(null,arguments);return a>this?this:a});Fa("Z",":"),Fa("ZZ",""),K("Z",Vc),K("ZZ",Vc),N(["Z","ZZ"],function(a,b,c){c._useUTC=!0,c._tzm=Ga(a)});var qd=/([\+\-]|\d\d)/gi;a.updateOffset=function(){};var rd=/(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,sd=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;Ua.fn=Da.prototype;var td=Ya(1,"add"),ud=Ya(-1,"subtract");a.defaultFormat="YYYY-MM-DDTHH:mm:ssZ";var vd=Z("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(a){return void 0===a?this.localeData():this.locale(a)});F(0,["gg",2],0,function(){return this.weekYear()%100}),F(0,["GG",2],0,function(){return this.isoWeekYear()%100}),xb("gggg","weekYear"),xb("ggggg","weekYear"),xb("GGGG","isoWeekYear"),xb("GGGGG","isoWeekYear"),x("weekYear","gg"),x("isoWeekYear","GG"),K("G",Uc),K("g",Uc),K("GG",Pc,Lc),K("gg",Pc,Lc),K("GGGG",Rc,Nc),K("gggg",Rc,Nc),K("GGGGG",Sc,Oc),K("ggggg",Sc,Oc),O(["gggg","ggggg","GGGG","GGGGG"],function(a,b,c,d){b[d.substr(0,2)]=o(a)}),O(["gg","GG"],function(b,c,d,e){c[e]=a.parseTwoDigitYear(b)}),F("Q",0,0,"quarter"),x("quarter","Q"),K("Q",Kc),N("Q",function(a,b){b[_c]=3*(o(a)-1)}),F("D",["DD",2],"Do","date"),x("date","D"),K("D",Pc),K("DD",Pc,Lc),K("Do",function(a,b){return a?b._ordinalParse:b._ordinalParseLenient}),N(["D","DD"],ad),N("Do",function(a,b){b[ad]=o(a.match(Pc)[0],10)});var wd=A("Date",!0);F("d",0,"do","day"),F("dd",0,0,function(a){return this.localeData().weekdaysMin(this,a)}),F("ddd",0,0,function(a){return this.localeData().weekdaysShort(this,a)}),F("dddd",0,0,function(a){return this.localeData().weekdays(this,a)}),F("e",0,0,"weekday"),F("E",0,0,"isoWeekday"),x("day","d"),x("weekday","e"),x("isoWeekday","E"),K("d",Pc),K("e",Pc),K("E",Pc),K("dd",Xc),K("ddd",Xc),K("dddd",Xc),O(["dd","ddd","dddd"],function(a,b,c){var d=c._locale.weekdaysParse(a);null!=d?b.d=d:c._pf.invalidWeekday=a}),O(["d","e","E"],function(a,b,c,d){b[d]=o(a)});var xd="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),yd="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),zd="Su_Mo_Tu_We_Th_Fr_Sa".split("_");F("H",["HH",2],0,"hour"),F("h",["hh",2],0,function(){return this.hours()%12||12}),Mb("a",!0),Mb("A",!1),x("hour","h"),K("a",Nb),K("A",Nb),K("H",Pc),K("h",Pc),K("HH",Pc,Lc),K("hh",Pc,Lc),N(["H","HH"],bd),N(["a","A"],function(a,b,c){c._isPm=c._locale.isPM(a),c._meridiem=a}),N(["h","hh"],function(a,b,c){b[bd]=o(a),c._pf.bigHour=!0});var Ad=/[ap]\.?m?\.?/i,Bd=A("Hours",!0);F("m",["mm",2],0,"minute"),x("minute","m"),K("m",Pc),K("mm",Pc,Lc),N(["m","mm"],cd);var Cd=A("Minutes",!1);F("s",["ss",2],0,"second"),x("second","s"),K("s",Pc),K("ss",Pc,Lc),N(["s","ss"],dd);var Dd=A("Seconds",!1);F("S",0,0,function(){return~~(this.millisecond()/100)}),F(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),Qb("SSS"),Qb("SSSS"),x("millisecond","ms"),K("S",Qc,Kc),K("SS",Qc,Lc),K("SSS",Qc,Mc),K("SSSS",Tc),N(["S","SS","SSS","SSSS"],function(a,b){b[ed]=o(1e3*("0."+a))});var Ed=A("Milliseconds",!1);F("z",0,0,"zoneAbbr"),F("zz",0,0,"zoneName");var Fd=m.prototype;Fd.add=td,Fd.calendar=$a,Fd.clone=_a,Fd.diff=fb,Fd.endOf=pb,Fd.format=jb,Fd.from=kb,Fd.fromNow=lb,Fd.get=D,Fd.invalidAt=wb,Fd.isAfter=ab,Fd.isBefore=bb,Fd.isBetween=cb,Fd.isSame=db,Fd.isValid=ub,Fd.lang=vd,Fd.locale=mb,Fd.localeData=nb,Fd.max=pd,Fd.min=od,Fd.parsingFlags=vb,Fd.set=D,Fd.startOf=ob,Fd.subtract=ud,Fd.toArray=tb,Fd.toDate=sb,Fd.toISOString=ib,Fd.toJSON=ib,Fd.toString=hb,Fd.unix=rb,Fd.valueOf=qb,Fd.year=md,Fd.isLeapYear=fa,Fd.weekYear=zb,Fd.isoWeekYear=Ab,Fd.quarter=Fd.quarters=Db,Fd.month=V,Fd.daysInMonth=W,Fd.week=Fd.weeks=ka,Fd.isoWeek=Fd.isoWeeks=la,Fd.weeksInYear=Cb,Fd.isoWeeksInYear=Bb,Fd.date=wd,Fd.day=Fd.days=Jb,Fd.weekday=Kb,Fd.isoWeekday=Lb,Fd.dayOfYear=na,Fd.hour=Fd.hours=Bd,Fd.minute=Fd.minutes=Cd,Fd.second=Fd.seconds=Dd,Fd.millisecond=Fd.milliseconds=Ed,Fd.utcOffset=Ja,Fd.utc=La,Fd.local=Ma,Fd.parseZone=Na,Fd.hasAlignedHourOffset=Oa,Fd.isDST=Pa,Fd.isDSTShifted=Qa,Fd.isLocal=Ra,Fd.isUtcOffset=Sa,Fd.isUtc=Ta,Fd.isUTC=Ta,Fd.zoneAbbr=Rb,Fd.zoneName=Sb,Fd.dates=Z("dates accessor is deprecated. Use date instead.",wd),Fd.months=Z("months accessor is deprecated. Use month instead",V),Fd.years=Z("years accessor is deprecated. Use year instead",md),Fd.zone=Z("moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779",Ka);var Gd=Fd,Hd={sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},Id={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY LT",LLLL:"dddd, MMMM D, YYYY LT"},Jd="Invalid date",Kd="%d",Ld=/\d{1,2}/,Md={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},Nd=q.prototype;Nd._calendar=Hd,Nd.calendar=Vb,Nd._longDateFormat=Id,Nd.longDateFormat=Wb,Nd._invalidDate=Jd,Nd.invalidDate=Xb,Nd._ordinal=Kd,Nd.ordinal=Yb,Nd._ordinalParse=Ld,
+Nd.preparse=Zb,Nd.postformat=Zb,Nd._relativeTime=Md,Nd.relativeTime=$b,Nd.pastFuture=_b,Nd.set=ac,Nd.months=R,Nd._months=fd,Nd.monthsShort=S,Nd._monthsShort=gd,Nd.monthsParse=T,Nd.week=ha,Nd._week=nd,Nd.firstDayOfYear=ja,Nd.firstDayOfWeek=ia,Nd.weekdays=Fb,Nd._weekdays=xd,Nd.weekdaysMin=Hb,Nd._weekdaysMin=zd,Nd.weekdaysShort=Gb,Nd._weekdaysShort=yd,Nd.weekdaysParse=Ib,Nd.isPM=Ob,Nd._meridiemParse=Ad,Nd.meridiem=Pb,u("en",{ordinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(a){var b=a%10,c=1===o(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th";return a+c}}),a.lang=Z("moment.lang is deprecated. Use moment.locale instead.",u),a.langData=Z("moment.langData is deprecated. Use moment.localeData instead.",w);var Od=Math.abs,Pd=rc("ms"),Qd=rc("s"),Rd=rc("m"),Sd=rc("h"),Td=rc("d"),Ud=rc("w"),Vd=rc("M"),Wd=rc("y"),Xd=tc("milliseconds"),Yd=tc("seconds"),Zd=tc("minutes"),$d=tc("hours"),_d=tc("days"),ae=tc("months"),be=tc("years"),ce=Math.round,de={s:45,m:45,h:22,d:26,M:11},ee=Math.abs,fe=Da.prototype;fe.abs=ic,fe.add=kc,fe.subtract=lc,fe.as=pc,fe.asMilliseconds=Pd,fe.asSeconds=Qd,fe.asMinutes=Rd,fe.asHours=Sd,fe.asDays=Td,fe.asWeeks=Ud,fe.asMonths=Vd,fe.asYears=Wd,fe.valueOf=qc,fe._bubble=mc,fe.get=sc,fe.milliseconds=Xd,fe.seconds=Yd,fe.minutes=Zd,fe.hours=$d,fe.days=_d,fe.weeks=uc,fe.months=ae,fe.years=be,fe.humanize=yc,fe.toISOString=zc,fe.toString=zc,fe.toJSON=zc,fe.locale=mb,fe.localeData=nb,fe.toIsoString=Z("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",zc),fe.lang=vd,F("X",0,0,"unix"),F("x",0,0,"valueOf"),K("x",Uc),K("X",Wc),N("X",function(a,b,c){c._d=new Date(1e3*parseFloat(a,10))}),N("x",function(a,b,c){c._d=new Date(o(a))}),a.version="2.10.2",b(za),a.fn=Gd,a.min=Ba,a.max=Ca,a.utc=i,a.unix=Tb,a.months=dc,a.isDate=e,a.locale=u,a.invalid=k,a.duration=Ua,a.isMoment=n,a.weekdays=fc,a.parseZone=Ub,a.localeData=w,a.isDuration=Ea,a.monthsShort=ec,a.weekdaysMin=hc,a.defineLocale=v,a.weekdaysShort=gc,a.normalizeUnits=y,a.relativeTimeThreshold=xc;var ge=a;return ge});
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/socket.io.min.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/socket.io.min.js
new file mode 100644
index 0000000000..7e870c9864
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/socket.io.min.js
@@ -0,0 +1,2 @@
+/*! Socket.IO.min.js build:0.9.16, production. Copyright(c) 2011 LearnBoost MIT Licensed */
+var io="undefined"==typeof module?{}:module.exports;(function(){(function(a,b){var c=a;c.version="0.9.16",c.protocol=1,c.transports=[],c.j=[],c.sockets={},c.connect=function(a,d){var e=c.util.parseUri(a),f,g;b&&b.location&&(e.protocol=e.protocol||b.location.protocol.slice(0,-1),e.host=e.host||(b.document?b.document.domain:b.location.hostname),e.port=e.port||b.location.port),f=c.util.uniqueUri(e);var h={host:e.host,secure:"https"==e.protocol,port:e.port||("https"==e.protocol?443:80),query:e.query||""};c.util.merge(h,d);if(h["force new connection"]||!c.sockets[f])g=new c.Socket(h);return!h["force new connection"]&&g&&(c.sockets[f]=g),g=g||c.sockets[f],g.of(e.path.length>1?e.path:"")}})("object"==typeof module?module.exports:this.io={},this),function(a,b){var c=a.util={},d=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,e=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];c.parseUri=function(a){var b=d.exec(a||""),c={},f=14;while(f--)c[e[f]]=b[f]||"";return c},c.uniqueUri=function(a){var c=a.protocol,d=a.host,e=a.port;return"document"in b?(d=d||document.domain,e=e||(c=="https"&&document.location.protocol!=="https:"?443:document.location.port)):(d=d||"localhost",!e&&c=="https"&&(e=443)),(c||"http")+"://"+d+":"+(e||80)},c.query=function(a,b){var d=c.chunkQuery(a||""),e=[];c.merge(d,c.chunkQuery(b||""));for(var f in d)d.hasOwnProperty(f)&&e.push(f+"="+d[f]);return e.length?"?"+e.join("&"):""},c.chunkQuery=function(a){var b={},c=a.split("&"),d=0,e=c.length,f;for(;db.length?a:b,f=a.length>b.length?b:a;for(var g=0,h=f.length;g0&&a.splice(0,1)[0]!=c.transport.name);a.length?h(a):c.publish("connect_failed")}}},c.options["connect timeout"]))})}c.sessionid=d,c.closeTimeout=f*1e3,c.heartbeatTimeout=e*1e3,c.transports||(c.transports=c.origTransports=g?b.util.intersect(g.split(","),c.options.transports):c.options.transports),c.setHeartbeatTimeout(),h(c.transports),c.once("connect",function(){clearTimeout(c.connectTimeoutTimer),a&&typeof a=="function"&&a()})}),this},d.prototype.setHeartbeatTimeout=function(){clearTimeout(this.heartbeatTimeoutTimer);if(this.transport&&!this.transport.heartbeats())return;var a=this;this.heartbeatTimeoutTimer=setTimeout(function(){a.transport.onClose()},this.heartbeatTimeout)},d.prototype.packet=function(a){return this.connected&&!this.doBuffer?this.transport.packet(a):this.buffer.push(a),this},d.prototype.setBuffer=function(a){this.doBuffer=a,!a&&this.connected&&this.buffer.length&&(this.options.manualFlush||this.flushBuffer())},d.prototype.flushBuffer=function(){this.transport.payload(this.buffer),this.buffer=[]},d.prototype.disconnect=function(){if(this.connected||this.connecting)this.open&&this.of("").packet({type:"disconnect"}),this.onDisconnect("booted");return this},d.prototype.disconnectSync=function(){var a=b.util.request(),c=["http"+(this.options.secure?"s":"")+":/",this.options.host+":"+this.options.port,this.options.resource,b.protocol,"",this.sessionid].join("/")+"/?disconnect=1";a.open("GET",c,!1),a.send(null),this.onDisconnect("booted")},d.prototype.isXDomain=function(){var a=c.location.port||("https:"==c.location.protocol?443:80);return this.options.host!==c.location.hostname||this.options.port!=a},d.prototype.onConnect=function(){this.connected||(this.connected=!0,this.connecting=!1,this.doBuffer||this.setBuffer(!1),this.emit("connect"))},d.prototype.onOpen=function(){this.open=!0},d.prototype.onClose=function(){this.open=!1,clearTimeout(this.heartbeatTimeoutTimer)},d.prototype.onPacket=function(a){this.of(a.endpoint).onPacket(a)},d.prototype.onError=function(a){a&&a.advice&&a.advice==="reconnect"&&(this.connected||this.connecting)&&(this.disconnect(),this.options.reconnect&&this.reconnect()),this.publish("error",a&&a.reason?a.reason:a)},d.prototype.onDisconnect=function(a){var b=this.connected,c=this.connecting;this.connected=!1,this.connecting=!1,this.open=!1;if(b||c)this.transport.close(),this.transport.clearTimeouts(),b&&(this.publish("disconnect",a),"booted"!=a&&this.options.reconnect&&!this.reconnecting&&this.reconnect())},d.prototype.reconnect=function(){function e(){if(a.connected){for(var b in a.namespaces)a.namespaces.hasOwnProperty(b)&&""!==b&&a.namespaces[b].packet({type:"connect"});a.publish("reconnect",a.transport.name,a.reconnectionAttempts)}clearTimeout(a.reconnectionTimer),a.removeListener("connect_failed",f),a.removeListener("connect",f),a.reconnecting=!1,delete a.reconnectionAttempts,delete a.reconnectionDelay,delete a.reconnectionTimer,delete a.redoTransports,a.options["try multiple transports"]=c}function f(){if(!a.reconnecting)return;if(a.connected)return e();if(a.connecting&&a.reconnecting)return a.reconnectionTimer=setTimeout(f,1e3);a.reconnectionAttempts++>=b?a.redoTransports?(a.publish("reconnect_failed"),e()):(a.on("connect_failed",f),a.options["try multiple transports"]=!0,a.transports=a.origTransports,a.transport=a.getTransport(),a.redoTransports=!0,a.connect()):(a.reconnectionDelay=10:!1},c.xdomainCheck=function(){return!0},typeof window!="undefined"&&(WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0),b.transports.push("flashsocket")}("undefined"!=typeof io?io.Transport:module.exports,"undefined"!=typeof io?io:module.parent.exports);if("undefined"!=typeof window)var swfobject=function(){function A(){if(t)return;try{var a=i.getElementsByTagName("body")[0].appendChild(Q("span"));a.parentNode.removeChild(a)}catch(b){return}t=!0;var c=l.length;for(var d=0;d0)for(var c=0;c0){var g=P(d);if(g)if(S(m[c].swfVersion)&&!(y.wk&&y.wk<312))U(d,!0),e&&(f.success=!0,f.ref=G(d),e(f));else if(m[c].expressInstall&&H()){var h={};h.data=m[c].expressInstall,h.width=g.getAttribute("width")||"0",h.height=g.getAttribute("height")||"0",g.getAttribute("class")&&(h.styleclass=g.getAttribute("class")),g.getAttribute("align")&&(h.align=g.getAttribute("align"));var i={},j=g.getElementsByTagName("param"),k=j.length;for(var l=0;l ');h.outerHTML='"+k+" ",n[n.length]=c.id,g=P(c.id)}else{var m=Q(b);m.setAttribute("type",e);for(var o in c)c[o]!=Object.prototype[o]&&(o.toLowerCase()=="styleclass"?m.setAttribute("class",c[o]):o.toLowerCase()!="classid"&&m.setAttribute(o,c[o]));for(var p in d)d[p]!=Object.prototype[p]&&p.toLowerCase()!="movie"&&M(m,p,d[p]);h.parentNode.replaceChild(m,h),g=m}}return g}function M(a,b,c){var d=Q("param");d.setAttribute("name",b),d.setAttribute("value",c),a.appendChild(d)}function N(a){var b=P(a);b&&b.nodeName=="OBJECT"&&(y.ie&&y.win?(b.style.display="none",function(){b.readyState==4?O(a):setTimeout(arguments.callee,10)}()):b.parentNode.removeChild(b))}function O(a){var b=P(a);if(b){for(var c in b)typeof b[c]=="function"&&(b[c]=null);b.parentNode.removeChild(b)}}function P(a){var b=null;try{b=i.getElementById(a)}catch(c){}return b}function Q(a){return i.createElement(a)}function R(a,b,c){a.attachEvent(b,c),o[o.length]=[a,b,c]}function S(a){var b=y.pv,c=a.split(".");return c[0]=parseInt(c[0],10),c[1]=parseInt(c[1],10)||0,c[2]=parseInt(c[2],10)||0,b[0]>c[0]||b[0]==c[0]&&b[1]>c[1]||b[0]==c[0]&&b[1]==c[1]&&b[2]>=c[2]?!0:!1}function T(c,d,e,f){if(y.ie&&y.mac)return;var g=i.getElementsByTagName("head")[0];if(!g)return;var h=e&&typeof e=="string"?e:"screen";f&&(v=null,w=null);if(!v||w!=h){var j=Q("style");j.setAttribute("type","text/css"),j.setAttribute("media",h),v=g.appendChild(j),y.ie&&y.win&&typeof i.styleSheets!=a&&i.styleSheets.length>0&&(v=i.styleSheets[i.styleSheets.length-1]),w=h}y.ie&&y.win?v&&typeof v.addRule==b&&v.addRule(c,d):v&&typeof i.createTextNode!=a&&v.appendChild(i.createTextNode(c+" {"+d+"}"))}function U(a,b){if(!x)return;var c=b?"visible":"hidden";t&&P(a)?P(a).style.visibility=c:T("#"+a,"visibility:"+c)}function V(b){var c=/[\\\"<>\.;]/,d=c.exec(b)!=null;return d&&typeof encodeURIComponent!=a?encodeURIComponent(b):b}var a="undefined",b="object",c="Shockwave Flash",d="ShockwaveFlash.ShockwaveFlash",e="application/x-shockwave-flash",f="SWFObjectExprInst",g="onreadystatechange",h=window,i=document,j=navigator,k=!1,l=[D],m=[],n=[],o=[],p,q,r,s,t=!1,u=!1,v,w,x=!0,y=function(){var f=typeof i.getElementById!=a&&typeof i.getElementsByTagName!=a&&typeof i.createElement!=a,g=j.userAgent.toLowerCase(),l=j.platform.toLowerCase(),m=l?/win/.test(l):/win/.test(g),n=l?/mac/.test(l):/mac/.test(g),o=/webkit/.test(g)?parseFloat(g.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):!1,p=!1,q=[0,0,0],r=null;if(typeof j.plugins!=a&&typeof j.plugins[c]==b)r=j.plugins[c].description,r&&(typeof j.mimeTypes==a||!j.mimeTypes[e]||!!j.mimeTypes[e].enabledPlugin)&&(k=!0,p=!1,r=r.replace(/^.*\s+(\S+\s+\S+$)/,"$1"),q[0]=parseInt(r.replace(/^(.*)\..*$/,"$1"),10),q[1]=parseInt(r.replace(/^.*\.(.*)\s.*$/,"$1"),10),q[2]=/[a-zA-Z]/.test(r)?parseInt(r.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0);else if(typeof h[["Active"].concat("Object").join("X")]!=a)try{var s=new(window[["Active"].concat("Object").join("X")])(d);s&&(r=s.GetVariable("$version"),r&&(p=!0,r=r.split(" ")[1].split(","),q=[parseInt(r[0],10),parseInt(r[1],10),parseInt(r[2],10)]))}catch(t){}return{w3:f,pv:q,wk:o,ie:p,win:m,mac:n}}(),z=function(){if(!y.w3)return;(typeof i.readyState!=a&&i.readyState=="complete"||typeof i.readyState==a&&(i.getElementsByTagName("body")[0]||i.body))&&A(),t||(typeof i.addEventListener!=a&&i.addEventListener("DOMContentLoaded",A,!1),y.ie&&y.win&&(i.attachEvent(g,function(){i.readyState=="complete"&&(i.detachEvent(g,arguments.callee),A())}),h==top&&function(){if(t)return;try{i.documentElement.doScroll("left")}catch(a){setTimeout(arguments.callee,0);return}A()}()),y.wk&&function(){if(t)return;if(!/loaded|complete/.test(i.readyState)){setTimeout(arguments.callee,0);return}A()}(),C(A))}(),W=function(){y.ie&&y.win&&window.attachEvent("onunload",function(){var a=o.length;for(var b=0;b= 10.0.0 is required.");return}location.protocol=="file:"&&a.error("WARNING: web-socket-js doesn't work in file:///... URL unless you set Flash Security Settings properly. Open the page via Web server i.e. http://..."),WebSocket=function(a,b,c,d,e){var f=this;f.__id=WebSocket.__nextId++,WebSocket.__instances[f.__id]=f,f.readyState=WebSocket.CONNECTING,f.bufferedAmount=0,f.__events={},b?typeof b=="string"&&(b=[b]):b=[],setTimeout(function(){WebSocket.__addTask(function(){WebSocket.__flash.create(f.__id,a,b,c||null,d||0,e||null)})},0)},WebSocket.prototype.send=function(a){if(this.readyState==WebSocket.CONNECTING)throw"INVALID_STATE_ERR: Web Socket connection has not been established";var b=WebSocket.__flash.send(this.__id,encodeURIComponent(a));return b<0?!0:(this.bufferedAmount+=b,!1)},WebSocket.prototype.close=function(){if(this.readyState==WebSocket.CLOSED||this.readyState==WebSocket.CLOSING)return;this.readyState=WebSocket.CLOSING,WebSocket.__flash.close(this.__id)},WebSocket.prototype.addEventListener=function(a,b,c){a in this.__events||(this.__events[a]=[]),this.__events[a].push(b)},WebSocket.prototype.removeEventListener=function(a,b,c){if(!(a in this.__events))return;var d=this.__events[a];for(var e=d.length-1;e>=0;--e)if(d[e]===b){d.splice(e,1);break}},WebSocket.prototype.dispatchEvent=function(a){var b=this.__events[a.type]||[];for(var c=0;c