From 6e09caf953174ed604bd22e985bc126611085176 Mon Sep 17 00:00:00 2001 From: Shabirmean Date: Sat, 28 Nov 2015 20:14:51 +0530 Subject: [PATCH] Added VirtualFireAlarm deviceType Plugin/Service components --- .../pom.xml | 124 +++ .../constants/VirtualFireAlarmConstants.java | 34 + .../plugin/impl/VirtualFireAlarmManager.java | 282 ++++++ .../impl/VirtualFireAlarmManagerService.java | 112 +++ .../plugin/impl/dao/VirtualFireAlarmDAO.java | 123 +++ .../impl/VirtualFireAlarmDeviceDAOImpl.java | 238 +++++ .../impl/util/VirtualFireAlarmUtils.java | 45 + ...alFirealarmManagementServiceComponent.java | 105 +++ .../pom.xml | 241 +++++ .../service/VirtualFireAlarmService.java | 833 ++++++++++++++++++ .../service/dto/DeviceJSON.java | 36 + .../exception/VirtualFireAlarmException.java | 31 + .../VirtualFireAlarmMQTTSubscriber.java | 154 ++++ .../VirtualFireAlarmXMPPConnector.java | 137 +++ .../service/util/VerificationManager.java | 254 ++++++ .../util/VirtualFireAlarmServiceUtils.java | 357 ++++++++ .../service/util/scep/ContentType.java | 26 + .../service/util/scep/SCEPOperation.java | 39 + .../src/main/webapp/META-INF/resources.xml | 105 +++ .../webapp/META-INF/webapp-classloading.xml | 33 + .../src/main/webapp/WEB-INF/cxf-servlet.xml | 66 ++ .../src/main/webapp/WEB-INF/web.xml | 81 ++ .../device-mgt-iot-virtualfirealarm/pom.xml | 63 ++ .../org.wso2.carbon.device.mgt.iot/pom.xml | 2 +- .../IotDeviceManagementServiceComponent.java | 2 +- .../mgt/iot/service/DeviceTypeService.java | 1 + .../pom.xml | 0 .../src/main/resources/build.properties | 0 .../src/main/resources/conf/mobile-config.xml | 0 .../main/resources/dbscripts/plugins/h2.sql | 0 .../resources/dbscripts/plugins/mssql.sql | 0 .../resources/dbscripts/plugins/mysql.sql | 0 .../resources/dbscripts/plugins/oracle.sql | 0 .../dbscripts/plugins/postgresql.sql | 0 .../templates/hidden-operations-android.hbs | 0 .../src/main/resources/p2.inf | 0 .../pom.xml | 0 .../pom.xml | 2 +- .../src/main/resources/build.properties | 0 .../src/main/resources/conf/mobile-config.xml | 0 .../resources/dbscripts/plugins/ios/h2.sql | 0 .../resources/dbscripts/plugins/ios/mssql.sql | 0 .../resources/dbscripts/plugins/ios/mysql.sql | 0 .../dbscripts/plugins/ios/oracle.sql | 0 .../dbscripts/plugins/ios/postgresql.sql | 0 .../configuration.hbs | 0 .../configuration.json | 0 .../operation-bar.hbs | 0 .../operation-bar.js | 0 .../operation-bar.json | 0 .../public/js/operation-bar.js | 0 .../templates/hidden-operations-ios.hbs | 0 .../public/templates/operations.hbs | 0 .../operation-mod.hbs | 0 .../operation-mod.json | 0 .../public/js/operation-mod.js | 0 .../configuration.hbs | 0 .../configuration.json | 0 .../public/js/platform-configuration.js | 0 .../units/mdm.unit.ui.header.logo/logo.hbs | 0 .../units/mdm.unit.ui.header.logo/logo.json | 0 .../src/main/resources/p2.inf | 0 .../pom.xml | 2 +- .../pom.xml | 0 .../src/main/resources/build.properties | 0 .../main/resources/dbscripts/plugins/h2.sql | 0 .../resources/dbscripts/plugins/mssql.sql | 0 .../resources/dbscripts/plugins/mysql.sql | 0 .../resources/dbscripts/plugins/oracle.sql | 0 .../dbscripts/plugins/postgresql.sql | 0 .../src/main/resources/p2.inf | 0 .../pom.xml | 0 pom.xml | 31 +- 73 files changed, 3551 insertions(+), 8 deletions(-) create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManagerService.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAO.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/impl/VirtualFireAlarmDeviceDAOImpl.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/VirtualFirealarmManagementServiceComponent.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/dto/DeviceJSON.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/exception/VirtualFireAlarmException.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTSubscriber.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VerificationManager.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/ContentType.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/resources.xml create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml create mode 100644 components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/web.xml create mode 100644 components/device-mgt-iot-virtualfirealarm/pom.xml rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/build.properties (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf/mobile-config.xml (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/h2.sql (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mssql.sql (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mysql.sql (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/oracle.sql (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/postgresql.sql (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-android.hbs (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf (100%) rename features/{device-mgt-mdm-android => device-mgt-mdm-android-feature}/pom.xml (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/pom.xml (99%) rename features/{device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature => device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature}/src/main/resources/build.properties (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.json (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.json (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.json (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf (100%) rename features/{device-mgt-mdm => device-mgt-mdm-feature}/pom.xml (96%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/org.wso2.carbon.device.mgt.mobile.windows.feature/pom.xml (100%) rename features/{device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature => device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature}/src/main/resources/build.properties (100%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/h2.sql (100%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mssql.sql (100%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mysql.sql (100%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/oracle.sql (100%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/postgresql.sql (100%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/p2.inf (100%) rename features/{device-mgt-mdm-windows => device-mgt-mdm-windows-feature}/pom.xml (100%) diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml new file mode 100644 index 0000000000..e8ea39ae9c --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml @@ -0,0 +1,124 @@ + + + + + + + device-mgt-iot-virtualfirealarm + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl + 1.9.2-SNAPSHOT + bundle + WSO2 Carbon - Virtual FireAlarm Management Plugin Impl + WSO2 Carbon - Virtual FireAlarm Management/Control Plugin Implementation + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + maven-compiler-plugin + + 1.7 + 1.7 + + 2.3.2 + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.iot.device.mgt.version} + IoT Server Impl Bundle + org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal + + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + javax.xml.bind.*, + javax.naming, + javax.sql, + javax.xml.bind.annotation.*, + javax.xml.parsers, + javax.net, + javax.net.ssl, + org.w3c.dom, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.common, + org.wso2.carbon.context.*, + org.wso2.carbon.ndatasource.core, + org.wso2.carbon.device.mgt.iot.*, + + + + !org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal, + org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.* + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + + org.wso2.carbon + org.wso2.carbon.logging + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot + + + + + \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java new file mode 100644 index 0000000000..0190b20013 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java @@ -0,0 +1,34 @@ +/* + * 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.iot.virtualfirealarm.plugin.constants; + +public class VirtualFireAlarmConstants { + public final static String DEVICE_TYPE = "virtual_firealarm"; + public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME"; + public final static String DEVICE_PLUGIN_DEVICE_ID = "VIRTUAL_FIREALARM_DEVICE_ID"; + public final static String STATE_ON = "ON"; + public final static String STATE_OFF = "OFF"; + + public static final String URL_PREFIX = "http://"; + public static final String BULB_CONTEXT = "/BULB/"; + public static final String SONAR_CONTEXT = "/HUMIDITY/"; + public static final String TEMPERATURE_CONTEXT = "/TEMPERATURE/"; + + public static final String SENSOR_TEMPERATURE = "temperature"; +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java new file mode 100644 index 0000000000..c0d2e75106 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java @@ -0,0 +1,282 @@ +/* + * 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.iot.virtualfirealarm.plugin.impl; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +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.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao.VirtualFireAlarmDAO; + +import java.util.ArrayList; +import java.util.List; + + +/** + * This represents the FireAlarm implementation of DeviceManagerService. + */ +public class VirtualFireAlarmManager implements DeviceManager { + + private static final IotDeviceManagementDAOFactory iotDeviceManagementDAOFactory = new VirtualFireAlarmDAO(); + private static final Log log = LogFactory.getLog(VirtualFireAlarmManager.class); + + + @Override + public FeatureManager getFeatureManager() { + return null; + } + + @Override + public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + throws DeviceManagementException { + //TODO implement this + return false; + } + + @Override + public TenantConfiguration getConfiguration() throws DeviceManagementException { + //TODO implement this + return null; + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Enrolling a new Virtual Firealarm device : " + device.getDeviceIdentifier()); + } + VirtualFireAlarmDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO().addIotDevice( + iotDevice); + VirtualFireAlarmDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + VirtualFireAlarmDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while enrolling the Virtual Firealarm device : " + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Modifying the Virtual Firealarm device enrollment data"); + } + VirtualFireAlarmDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .updateIotDevice(iotDevice); + VirtualFireAlarmDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + VirtualFireAlarmDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the update device transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while updating the enrollment of the Virtual Firealarm device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling Virtual Firealarm device : " + deviceId); + } + VirtualFireAlarmDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .deleteIotDevice(deviceId.getId()); + VirtualFireAlarmDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + VirtualFireAlarmDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while removing the Virtual Firealarm device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean isEnrolled = false; + try { + if (log.isDebugEnabled()) { + log.debug("Checking the enrollment of Virtual Firealarm device : " + deviceId.getId()); + } + IotDevice iotDevice = + iotDeviceManagementDAOFactory.getIotDeviceDAO().getIotDevice( + deviceId.getId()); + if (iotDevice != null) { + isEnrolled = true; + } + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while checking the enrollment status of Virtual Firealarm device : " + + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return isEnrolled; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + Device device; + try { + if (log.isDebugEnabled()) { + log.debug("Getting the details of Virtual Firealarm device : " + deviceId.getId()); + } + IotDevice iotDevice = iotDeviceManagementDAOFactory.getIotDeviceDAO(). + getIotDevice(deviceId.getId()); + device = IotDeviceManagementUtil.convertToDevice(iotDevice); + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while fetching the Virtual Firealarm device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return device; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; + } + + public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + + @Override + public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, + EnrolmentInfo.Status status) throws DeviceManagementException { + return false; + } + + @Override + public License getLicense(String s) throws LicenseManagementException { + return null; + } + + @Override + public void addLicense(License license) throws LicenseManagementException { + + } + + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug( + "updating the details of Virtual Firealarm device : " + deviceIdentifier); + } + VirtualFireAlarmDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .updateIotDevice(iotDevice); + VirtualFireAlarmDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + VirtualFireAlarmDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the update device info transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = + "Error while updating the Virtual Firealarm device : " + deviceIdentifier; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + List devices = null; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all Virtual Firealarm devices"); + } + List iotDevices = + iotDeviceManagementDAOFactory.getIotDeviceDAO().getAllIotDevices(); + if (iotDevices != null) { + devices = new ArrayList(); + for (IotDevice iotDevice : iotDevices) { + devices.add(IotDeviceManagementUtil.convertToDevice(iotDevice)); + } + } + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while fetching all Virtual Firealarm devices."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return devices; + } + + + @Override + public boolean requireDeviceAuthorization() { + return true; + } + +} \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManagerService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManagerService.java new file mode 100644 index 0000000000..ae39c7364c --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManagerService.java @@ -0,0 +1,112 @@ +/* + * 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.iot.virtualfirealarm.plugin.impl; + +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.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; + +import java.util.List; + +public class VirtualFireAlarmManagerService implements DeviceManagementService{ + private DeviceManager deviceManager; + @Override + public String getType() { + return VirtualFireAlarmConstants.DEVICE_TYPE; + } + + + @Override + public String getProviderTenantDomain() { + return "carbon.super"; + } + + @Override + public boolean isSharedWithAllTenants() { + return true; + } + + @Override + public String[] getSharedTenantsDomain() { + return new String[0]; + } + + @Override + public void init() throws DeviceManagementException { + this.deviceManager=new VirtualFireAlarmManager(); + } + + @Override + public DeviceManager getDeviceManager() { + return deviceManager; + } + + @Override + public ApplicationManager getApplicationManager() { + return null; + } + + @Override + public void notifyOperationToDevices(Operation operation, List deviceIds) + throws DeviceManagementException { + + } + + @Override + public Application[] getApplications(String domain, int pageNumber, int size) + throws ApplicationManagementException { + return new Application[0]; + } + + @Override + public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, + String status) throws ApplicationManagementException { + + } + + @Override + public String getApplicationStatus(DeviceIdentifier deviceId, Application application) + throws ApplicationManagementException { + return null; + } + + @Override + public void installApplicationForDevices(Operation operation, List deviceIdentifiers) + throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUsers(Operation operation, List userNameList) + throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUserRoles(Operation operation, List userRoleList) + throws ApplicationManagementException { + + } +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAO.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAO.java new file mode 100644 index 0000000000..d517dc5210 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAO.java @@ -0,0 +1,123 @@ +/* + * 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.iot.virtualfirealarm.plugin.impl.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao + .IotDeviceManagementDAOFactoryInterface; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao.impl.VirtualFireAlarmDeviceDAOImpl; + + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + +public class VirtualFireAlarmDAO extends IotDeviceManagementDAOFactory implements IotDeviceManagementDAOFactoryInterface { + + private static final Log log = LogFactory.getLog(VirtualFireAlarmDAO.class); + static DataSource dataSource; + private static ThreadLocal currentConnection = new ThreadLocal(); + + public VirtualFireAlarmDAO() { + initFireAlarmDAO(); + } + + public static void initFireAlarmDAO() { + dataSource = getDataSourceMap().get(VirtualFireAlarmConstants.DEVICE_TYPE); + } + + @Override public IotDeviceDAO getIotDeviceDAO() { + return new VirtualFireAlarmDeviceDAOImpl(); + } + + public static void beginTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = dataSource.getConnection(); + conn.setAutoCommit(false); + currentConnection.set(conn); + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); + } + } + + public static Connection getConnection() throws IotDeviceManagementDAOException { + if (currentConnection.get() == null) { + try { + currentConnection.set(dataSource.getConnection()); + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while retrieving data source connection", e); + } + } + return currentConnection.get(); + } + + public static void commitTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.commit(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence commit " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while committing the transaction", e); + } finally { + closeConnection(); + } + } + + public static void closeConnection() throws IotDeviceManagementDAOException { + + Connection con = currentConnection.get(); + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + log.error("Error occurred while close the connection"); + } + } + currentConnection.remove(); + } + + public static void rollbackTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.rollback(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence rollback " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while rollback the transaction", e); + } finally { + closeConnection(); + } + } +} \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/impl/VirtualFireAlarmDeviceDAOImpl.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/impl/VirtualFireAlarmDeviceDAOImpl.java new file mode 100644 index 0000000000..12d54a60ea --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/impl/VirtualFireAlarmDeviceDAOImpl.java @@ -0,0 +1,238 @@ +/* + * 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.iot.virtualfirealarm.plugin.impl.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.util.IotDeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao.VirtualFireAlarmDAO; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Implements IotDeviceDAO for virtual firealarm Devices. + */ +public class VirtualFireAlarmDeviceDAOImpl implements IotDeviceDAO{ + + + private static final Log log = LogFactory.getLog(VirtualFireAlarmDeviceDAOImpl.class); + + @Override + public IotDevice getIotDevice(String iotDeviceId) + throws IotDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + IotDevice iotDevice = null; + ResultSet resultSet = null; + try { + conn = VirtualFireAlarmDAO.getConnection(); + String selectDBQuery = + "SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME" + + " FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?"; + stmt = conn.prepareStatement(selectDBQuery); + stmt.setString(1, iotDeviceId); + resultSet = stmt.executeQuery(); + + if (resultSet.next()) { + iotDevice = new IotDevice(); + iotDevice.setIotDeviceName(resultSet.getString( + VirtualFireAlarmConstants.DEVICE_PLUGIN_DEVICE_NAME)); + Map propertyMap = new HashMap(); + + + + iotDevice.setDeviceProperties(propertyMap); + + if (log.isDebugEnabled()) { + log.debug("Virtual Firealarm device " + iotDeviceId + " data has been fetched from " + + "Virtual Firealarm database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while fetching Virtual Firealarm device : '" + iotDeviceId + "'"; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); + VirtualFireAlarmDAO.closeConnection(); + } + + return iotDevice; + } + + @Override + public boolean addIotDevice(IotDevice iotDevice) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = VirtualFireAlarmDAO.getConnection(); + String createDBQuery = + "INSERT INTO VIRTUAL_FIREALARM_DEVICE(VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)"; + + stmt = conn.prepareStatement(createDBQuery); + stmt.setString(1, iotDevice.getIotDeviceId()); + stmt.setString(2,iotDevice.getIotDeviceName()); + if (iotDevice.getDeviceProperties() == null) { + iotDevice.setDeviceProperties(new HashMap()); + } + + + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Virtual Firealarm device " + iotDevice.getIotDeviceId() + " data has been" + + " added to the Virtual Firealarm database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while adding the Virtual Firealarm device '" + + iotDevice.getIotDeviceId() + "' to the Virtual Firealarm db."; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean updateIotDevice(IotDevice iotDevice) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = VirtualFireAlarmDAO.getConnection(); + String updateDBQuery = + "UPDATE VIRTUAL_FIREALARM_DEVICE SET DEVICE_NAME = ? WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?"; + + stmt = conn.prepareStatement(updateDBQuery); + + if (iotDevice.getDeviceProperties() == null) { + iotDevice.setDeviceProperties(new HashMap()); + } + stmt.setString(1, iotDevice.getIotDeviceName()); + + stmt.setString(2, iotDevice.getIotDeviceId()); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Virtualm Firealarm device " + iotDevice.getIotDeviceId() + " data has been" + + " modified."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while modifying the Virtual Firealarm device '" + + iotDevice.getIotDeviceId() + "' data."; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean deleteIotDevice(String iotDeviceId) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = VirtualFireAlarmDAO.getConnection(); + String deleteDBQuery = + "DELETE FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?"; + stmt = conn.prepareStatement(deleteDBQuery); + stmt.setString(1, iotDeviceId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Virtual Firealarm device " + iotDeviceId + " data has deleted" + + " from the Virtual Firealarm database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while deleting Virtual Firealarm device " + iotDeviceId; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public List getAllIotDevices() + throws IotDeviceManagementDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + IotDevice iotDevice; + List iotDevices = new ArrayList(); + + try { + conn = VirtualFireAlarmDAO.getConnection(); + String selectDBQuery = + "SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME " + + "FROM VIRTUAL_FIREALARM_DEVICE"; + stmt = conn.prepareStatement(selectDBQuery); + resultSet = stmt.executeQuery(); + while (resultSet.next()) { + iotDevice = new IotDevice(); + iotDevice.setIotDeviceId(resultSet.getString(VirtualFireAlarmConstants.DEVICE_PLUGIN_DEVICE_ID)); + iotDevice.setIotDeviceName(resultSet.getString(VirtualFireAlarmConstants.DEVICE_PLUGIN_DEVICE_NAME)); + + Map propertyMap = new HashMap(); + + iotDevice.setDeviceProperties(propertyMap); + iotDevices.add(iotDevice); + } + if (log.isDebugEnabled()) { + log.debug("All Virtual Firealarm device details have fetched from Firealarm database."); + } + return iotDevices; + } catch (SQLException e) { + String msg = "Error occurred while fetching all Virtual Firealarm device data'"; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); + VirtualFireAlarmDAO.closeConnection(); + } + + } + + } \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java new file mode 100644 index 0000000000..ffd644ec8b --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.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.iot.virtualfirealarm.plugin.impl.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Map; + +/** + * Contains utility methods used by FireAlarm plugin. + */ +public class VirtualFireAlarmUtils { + + private static Log log = LogFactory.getLog(VirtualFireAlarmUtils.class); + + public static String getDeviceProperty(Map deviceProperties, String property) { + + String deviceProperty = deviceProperties.get(property); + + if (deviceProperty == null) { + return ""; + } + + return deviceProperty; + } + + +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/VirtualFirealarmManagementServiceComponent.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/VirtualFirealarmManagementServiceComponent.java new file mode 100644 index 0000000000..8aa5d5cff0 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/internal/VirtualFirealarmManagementServiceComponent.java @@ -0,0 +1,105 @@ +/* + * 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.iot.virtualfirealarm.plugin.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.VirtualFireAlarmManagerService; + + +/** + * @scr.component name="org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal + * .VirtualFirealarmManagementServiceComponent" + * immediate="true" + * @scr.reference name="org.wso2.carbon.device.mgt.iot.service.DeviceTypeServiceImpl" + * interface="org.wso2.carbon.device.mgt.iot.service.DeviceTypeService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDeviceTypeService" + * unbind="unsetDeviceTypeService" + */ +public class VirtualFirealarmManagementServiceComponent { + private ServiceRegistration firealarmServiceRegRef; + + private static final Log log = LogFactory.getLog( + VirtualFirealarmManagementServiceComponent.class); + + protected void activate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("Activating Virtual Firealarm Device Management Service Component"); + } + try { + BundleContext bundleContext = ctx.getBundleContext(); + firealarmServiceRegRef = + bundleContext.registerService(DeviceManagementService.class.getName(), + new VirtualFireAlarmManagerService(), null); + + if (log.isDebugEnabled()) { + log.debug( + "Virtual Firealarm Device Management Service Component has been " + + "successfully activated"); + } + } catch (Throwable e) { + log.error( + "Error occurred while activating Virtual Firealarm Device Management Service " + + "Component", + e); + } + } + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("De-activating Virtual Firealarm Device Management Service Component"); + } + try { + if (firealarmServiceRegRef != null) { + firealarmServiceRegRef.unregister(); + } + + if (log.isDebugEnabled()) { + log.debug( + "Virtual Firealarm Device Management Service Component has been " + + "successfully de-activated"); + } + } catch (Throwable e) { + log.error( + "Error occurred while de-activating Virtual Firealarm Device Management " + + "bundle", + e); + } + } + + protected void setDeviceTypeService(DeviceTypeService deviceTypeService) { + /* This is to avoid this component getting initialized before the common registered */ + if (log.isDebugEnabled()) { + log.debug("Data source service set to mobile service component"); + } + } + + protected void unsetDeviceTypeService(DeviceTypeService deviceTypeService) { + //do nothing + } + + +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml new file mode 100644 index 0000000000..0bb46c1a2b --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml @@ -0,0 +1,241 @@ + + + + + + device-mgt-iot-virtualfirealarm + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl + 1.9.2-SNAPSHOT + war + WSO2 Carbon - IoT Server APIs : Virtual FireAlarm API + WSO2 Carbon - Virtual FireAlarm Service API 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.apache.axis2.wso2 + axis2-client + + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics + + + org.apache.axis2.wso2 + axis2-client + + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.certificate.mgt.core + + + commons-codec.wso2 + commons-codec + + + + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + provided + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-transports-http + provided + + + + org.eclipse.paho + mqtt-client + + + + + org.apache.httpcomponents + httpasyncclient + 4.1 + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl + provided + + + + + org.codehaus.jackson + jackson-core-asl + + + org.codehaus.jackson + jackson-jaxrs + + + javax + javaee-web-api + provided + + + javax.ws.rs + jsr311-api + provided + + + commons-httpclient.wso2 + commons-httpclient + + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.bouncycastle.wso2 + bcprov-jdk15on + + + org.wso2.carbon + org.wso2.carbon.user.api + + + org.wso2.carbon + org.wso2.carbon.queuing + + + org.wso2.carbon + org.wso2.carbon.base + + + org.apache.axis2.wso2 + axis2 + + + org.igniterealtime.smack.wso2 + smack + + + org.igniterealtime.smack.wso2 + smackx + + + jaxen + jaxen + + + commons-fileupload.wso2 + commons-fileupload + + + org.apache.ant.wso2 + ant + + + org.apache.ant.wso2 + ant + + + commons-httpclient.wso2 + commons-httpclient + + + org.eclipse.equinox + javax.servlet + + + org.wso2.carbon + org.wso2.carbon.registry.api + + + + + + commons-codec + commons-codec + + + + org.igniterealtime.smack.wso2 + smack + provided + + + org.igniterealtime.smack.wso2 + smackx + provided + + + + + + + + + maven-compiler-plugin + + UTF-8 + ${wso2.maven.compiler.source} + ${wso2.maven.compiler.target} + + + + maven-war-plugin + + virtual_firealarm + + + + + + \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java new file mode 100644 index 0000000000..eb968772c7 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -0,0 +1,833 @@ +/* + * 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.iot.virtualfirealarm.service; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; +import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; +import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; +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.iot.DeviceManagement; +import org.wso2.carbon.device.mgt.iot.DeviceValidator; +import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo; +import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; +import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; +import org.wso2.carbon.device.mgt.iot.util.ZipArchive; +import org.wso2.carbon.device.mgt.iot.util.ZipUtil; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.dto.DeviceJSON; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmMQTTSubscriber; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmXMPPConnector; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.ContentType; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.scep.SCEPOperation; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +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.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.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + + +public class VirtualFireAlarmService { + + private static Log log = LogFactory.getLog(VirtualFireAlarmService.class); + + //TODO; replace this tenant domain + private static final String SUPER_TENANT = "carbon.super"; + + @Context //injected response proxy supporting multiple thread + private HttpServletResponse response; + + public static final String XMPP_PROTOCOL = "XMPP"; + public static final String HTTP_PROTOCOL = "HTTP"; + public static final String MQTT_PROTOCOL = "MQTT"; + + private VerificationManager verificationManager; + private VirtualFireAlarmMQTTSubscriber virtualFireAlarmMQTTSubscriber; + private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector; + private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); + + + public void setVerificationManager( + VerificationManager verificationManager) { + this.verificationManager = verificationManager; + verificationManager.initVerificationManager(); + } + + public void setVirtualFireAlarmXMPPConnector( + final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) { + this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector; + + Runnable mqttStarter = new Runnable() { + @Override + public void run() { + virtualFireAlarmXMPPConnector.initConnector(); + virtualFireAlarmXMPPConnector.connectAndLogin(); + } + }; + + Thread mqttStarterThread = new Thread(mqttStarter); + mqttStarterThread.setDaemon(true); + mqttStarterThread.start(); + } + + public void setVirtualFireAlarmMQTTSubscriber( + final VirtualFireAlarmMQTTSubscriber virtualFireAlarmMQTTSubscriber) { + this.virtualFireAlarmMQTTSubscriber = virtualFireAlarmMQTTSubscriber; + + Runnable xmppStarter = new Runnable() { + @Override + public void run() { + virtualFireAlarmMQTTSubscriber.initConnector(); + virtualFireAlarmMQTTSubscriber.connectAndSubscribe(); + } + }; + + Thread xmppStarterThread = new Thread(xmppStarter); + xmppStarterThread.setDaemon(true); + xmppStarterThread.start(); + } + + public VerificationManager getVerificationManager() { + return verificationManager; + } + + public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() { + return virtualFireAlarmXMPPConnector; + } + + public VirtualFireAlarmMQTTSubscriber getVirtualFireAlarmMQTTSubscriber() { + return virtualFireAlarmMQTTSubscriber; + } + + /* --------------------------------------------------------------------------------------- + Device management specific APIs + Also contains utility methods required for the execution of these APIs + --------------------------------------------------------------------------------------- */ + @Path("manager/device/register") + @PUT + public boolean register(@QueryParam("deviceId") String deviceId, + @QueryParam("name") String name, @QueryParam("owner") String owner) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + try { + if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) { + response.setStatus(Response.Status.CONFLICT.getStatusCode()); + return false; + } + Device device = new Device(); + device.setDeviceIdentifier(deviceId); + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); + + enrolmentInfo.setDateOfEnrolment(new Date().getTime()); + enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); + enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); + enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); + + device.setName(name); + device.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + enrolmentInfo.setOwner(owner); + device.setEnrolmentInfo(enrolmentInfo); + boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device); + + if (added) { + response.setStatus(Response.Status.OK.getStatusCode()); + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + } + + return added; + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return false; + } finally { + deviceManagement.endTenantFlow(); + } + } + + @Path("manager/device/remove/{device_id}") + @DELETE + public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + try { + boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice( + deviceIdentifier); + if (removed) { + response.setStatus(Response.Status.OK.getStatusCode()); + + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + + } + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("manager/device/update/{device_id}") + @POST + public boolean updateDevice(@PathParam("device_id") String deviceId, + @QueryParam("name") String name, + @Context HttpServletResponse response) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + try { + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); + device.setDeviceIdentifier(deviceId); + + // device.setDeviceTypeId(deviceTypeId); + device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); + + device.setName(name); + device.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + + boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( + device); + + if (updated) { + response.setStatus(Response.Status.OK.getStatusCode()); + + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + + } + return updated; + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return false; + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("manager/device/{device_id}") + @GET + @Consumes("application/json") + @Produces("application/json") + public Device getDevice(@PathParam("device_id") String deviceId) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + + try { + return deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return null; + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("manager/devices/{username}") + @GET + @Consumes("application/json") + @Produces("application/json") + public Device[] getFirealarmDevices(@PathParam("username") String username) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + + try { + List userDevices = + deviceManagement.getDeviceManagementService().getDevicesOfUser( + username); + ArrayList userDevicesforFirealarm = new ArrayList<>(); + for (Device device : userDevices) { + + if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) && + device.getEnrolmentInfo().getStatus().equals( + EnrolmentInfo.Status.ACTIVE)) { + userDevicesforFirealarm.add(device); + + } + } + + return userDevicesforFirealarm.toArray(new Device[]{}); + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return null; + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("manager/device/{sketch_type}/download") + @GET + @Produces("application/octet-stream") + public Response downloadSketch(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String sketchType) { + //TODO:: null check customDeviceName at UI level + try { + ZipArchive zipFile = createDownloadFile(owner, customDeviceName, sketchType); + Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); + rb.header("Content-Disposition", + "attachment; filename=\"" + zipFile.getFileName() + "\""); + return rb.build(); + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (AccessTokenException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + + } + + @Path("manager/device/{sketch_type}/generate_link") + @GET + public Response generateSketchLink(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String sketchType) { + + try { + ZipArchive zipFile = createDownloadFile(owner, customDeviceName, sketchType); + Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); + return rb.build(); + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (AccessTokenException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + + } + + private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType) + throws DeviceManagementException, AccessTokenException, DeviceControllerException { + if (owner == null) { + throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); + } + + //create new device id + String deviceId = shortUUID(); + + TokenClient accessTokenClient = new TokenClient(VirtualFireAlarmConstants.DEVICE_TYPE); + AccessTokenInfo accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); + + //create token + String accessToken = accessTokenInfo.getAccess_token(); + String refreshToken = accessTokenInfo.getRefresh_token(); + //adding registering data + + XmppAccount newXmppAccount = new XmppAccount(); + newXmppAccount.setAccountName(owner + "_" + deviceId); + newXmppAccount.setUsername(deviceId); + newXmppAccount.setPassword(accessToken); + newXmppAccount.setEmail(deviceId + "@wso2.com"); + + XmppServerClient xmppServerClient = new XmppServerClient(); + xmppServerClient.initControlQueue(); + boolean status; + + if (XmppConfig.getInstance().isEnabled()) { + status = xmppServerClient.createXMPPAccount(newXmppAccount); + if (!status) { + String msg = + "XMPP Account was not created for device - " + deviceId + " of owner - " + + owner + + ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot" + + ".common.config.server.configs"; + log.warn(msg); + throw new DeviceManagementException(msg); + } + } + + //Register the device with CDMF + String deviceName = customDeviceName + "_" + deviceId; + status = register(deviceId, deviceName, owner); + + if (!status) { + String msg = "Error occurred while registering the device with " + "id: " + deviceId + + " owner:" + owner; + throw new DeviceManagementException(msg); + } + + + ZipUtil ziputil = new ZipUtil(); + ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, + accessToken, refreshToken); + zipFile.setDeviceId(deviceId); + return zipFile; + } + + private static String shortUUID() { + UUID uuid = UUID.randomUUID(); + long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); + return Long.toString(l, Character.MAX_RADIX); + } + + /* --------------------------------------------------------------------------------------- + Device specific APIs - Control APIs + Data-Publishing APIs + Also contains utility methods required for the execution of these APIs + --------------------------------------------------------------------------------------- */ + @Path("controller/register/{owner}/{deviceId}/{ip}/{port}") + @POST + public String registerDeviceIP(@PathParam("owner") String owner, + @PathParam("deviceId") String deviceId, + @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort, + @Context HttpServletResponse response, + @Context HttpServletRequest request) { + + //TODO:: Need to get IP from the request itself + String result; + + log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + + " of owner: " + owner); + + String deviceHttpEndpoint = deviceIP + ":" + devicePort; + deviceToIpMap.put(deviceId, deviceHttpEndpoint); + + result = "Device-IP Registered"; + response.setStatus(Response.Status.OK.getStatusCode()); + + if (log.isDebugEnabled()) { + log.debug(result); + } + + return result; + } + + /* Service to switch "ON" and "OFF" the Virtual FireAlarm bulb + Called by an external client intended to control the Virtual FireAlarm bulb */ + @Path("controller/bulb/{state}") + @POST + public void switchBulb(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @HeaderParam("protocol") String protocol, + @PathParam("state") String state, + @Context HttpServletResponse response) { + + try { + DeviceValidator deviceValidator = new DeviceValidator(); + if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId, + VirtualFireAlarmConstants + .DEVICE_TYPE))) { + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + return; + } + } catch (DeviceManagementException e) { + log.error("DeviceValidation Failed for deviceId: " + deviceId + " of user: " + owner); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return; + } + + String switchToState = state.toUpperCase(); + + if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals( + VirtualFireAlarmConstants.STATE_OFF)) { + log.error("The requested state change shoud be either - 'ON' or 'OFF'"); + response.setStatus(Response.Status.BAD_REQUEST.getStatusCode()); + return; + } + + String protocolString = protocol.toUpperCase(); + String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState; + + if (log.isDebugEnabled()) { + log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " + + protocolString); + } + + try { + switch (protocolString) { + case HTTP_PROTOCOL: + String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); + if (deviceHTTPEndpoint == null) { + response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); + return; + } + + VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true); + break; + case MQTT_PROTOCOL: + String mqttMessage = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); + VirtualFireAlarmServiceUtils.sendCommandViaMQTT(owner, deviceId, mqttMessage, switchToState); + break; + case XMPP_PROTOCOL: + VirtualFireAlarmServiceUtils.sendCommandViaXMPP(owner, deviceId, + VirtualFireAlarmConstants.BULB_CONTEXT, + switchToState, virtualFireAlarmXMPPConnector); + break; + default: + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return; + } + } catch (DeviceManagementException e) { + log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return; + } + + response.setStatus(Response.Status.OK.getStatusCode()); + } + + + @Path("controller/readsonar") + @GET + public String requestSonarReading(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @HeaderParam("protocol") String protocol, + @Context HttpServletResponse response) { + String replyMsg = ""; + + DeviceValidator deviceValidator = new DeviceValidator(); + try { + if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId, + VirtualFireAlarmConstants + .DEVICE_TYPE))) { + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + return "Unauthorized Access"; + } + } catch (DeviceManagementException e) { + replyMsg = e.getErrorMessage(); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return replyMsg; + } + + String protocolString = protocol.toUpperCase(); + + if (log.isDebugEnabled()) { + log.debug("Sending request to read sonar value of device [" + deviceId + "] via " + + protocolString); + } + + try { + switch (protocolString) { + case HTTP_PROTOCOL: + String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); + if (deviceHTTPEndpoint == null) { + replyMsg = + "IP not registered for device: " + deviceId + " of owner: " + owner; + response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); + return replyMsg; + } + + replyMsg = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, + VirtualFireAlarmConstants.SONAR_CONTEXT, + false); + break; + + case MQTT_PROTOCOL: + String mqttMessage = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); + VirtualFireAlarmServiceUtils.sendCommandViaMQTT(owner, deviceId, mqttMessage, ""); + break; + + case XMPP_PROTOCOL: + VirtualFireAlarmServiceUtils.sendCommandViaXMPP(owner, deviceId, + VirtualFireAlarmConstants.SONAR_CONTEXT, "", + virtualFireAlarmXMPPConnector); + break; + + default: + replyMsg = "Requested protocol '" + protocolString + "' is not supported"; + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return replyMsg; + } + } catch (DeviceManagementException e) { + replyMsg = e.getErrorMessage(); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return replyMsg; + } + + response.setStatus(Response.Status.OK.getStatusCode()); + replyMsg = "The current sonar reading of the device is " + replyMsg; + return replyMsg; + } + + + @Path("controller/readtemperature") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord requestTemperature(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @HeaderParam("protocol") String protocol, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + DeviceValidator deviceValidator = new DeviceValidator(); + try { + if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId, + VirtualFireAlarmConstants + .DEVICE_TYPE))) { + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + } + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + String protocolString = protocol.toUpperCase(); + + if (log.isDebugEnabled()) { + log.debug( + "Sending request to read virtual-firealarm-temperature of device [" + deviceId + + "] via " + protocolString); + } + + try { + switch (protocolString) { + case HTTP_PROTOCOL: + String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); + if (deviceHTTPEndpoint == null) { + response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); + } + + String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, + VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, + false); + + SensorDataManager.getInstance().setSensorRecord(deviceId, + VirtualFireAlarmConstants.SENSOR_TEMPERATURE, + temperatureValue, + Calendar.getInstance().getTimeInMillis()); + break; + + case MQTT_PROTOCOL: + String mqttMessage = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); + VirtualFireAlarmServiceUtils.sendCommandViaMQTT(owner, deviceId, mqttMessage, ""); + break; + + case XMPP_PROTOCOL: + VirtualFireAlarmServiceUtils.sendCommandViaXMPP(owner, deviceId, + VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, "", + virtualFireAlarmXMPPConnector); + break; + + default: + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + } + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + VirtualFireAlarmConstants + .SENSOR_TEMPERATURE); + } catch (DeviceManagementException | DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + @Path("controller/push_temperature") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public void pushTemperatureData(final DeviceJSON dataMsg, + @Context HttpServletResponse response) { + String deviceId = dataMsg.deviceId; + String deviceIp = dataMsg.reply; + float temperature = dataMsg.value; + + String registeredIp = deviceToIpMap.get(deviceId); + + if (registeredIp == null) { + log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " + + deviceIp + " for device ID - " + deviceId); + response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); + return; + } else if (!registeredIp.equals(deviceIp)) { + log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + + deviceId + + " is already registered under some other IP. Re-registration " + + "required"); + response.setStatus(Response.Status.CONFLICT.getStatusCode()); + return; + } + SensorDataManager.getInstance().setSensorRecord(deviceId, + VirtualFireAlarmConstants + .SENSOR_TEMPERATURE, + String.valueOf(temperature), + Calendar.getInstance().getTimeInMillis()); + + if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.owner, dataMsg.deviceId, dataMsg.value)) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + + @GET + @Path("controller/scep") + public Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message) { + + if (log.isDebugEnabled()) { + log.debug("Invoking SCEP operation " + operation); + } + + if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) { + + if (log.isDebugEnabled()) { + log.debug("Invoking GetCACert"); + } + + try { + CertificateManagementService certificateManagementService = + VirtualFireAlarmServiceUtils.getCertificateManagementService(); + SCEPResponse scepResponse = certificateManagementService.getCACertSCEP(); + Response.ResponseBuilder responseBuilder; + + switch (scepResponse.getResultCriteria()) { + case CA_CERT_FAILED: + log.error("CA cert failed"); + responseBuilder = Response.serverError(); + break; + case CA_CERT_RECEIVED: + + if (log.isDebugEnabled()) { + log.debug("CA certificate received in GetCACert"); + } + + responseBuilder = Response.ok(scepResponse.getEncodedResponse(), + ContentType.X_X509_CA_CERT); + break; + case CA_RA_CERT_RECEIVED: + + if (log.isDebugEnabled()) { + log.debug("CA and RA certificates received in GetCACert"); + } + + responseBuilder = Response.ok(scepResponse.getEncodedResponse(), + ContentType.X_X509_CA_RA_CERT); + break; + default: + log.error("Invalid SCEP request"); + responseBuilder = Response.serverError(); + break; + } + + return responseBuilder.build(); + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the iOS device", e); + } catch (KeystoreException e) { + log.error("Keystore error occurred while enrolling the iOS device", e); + } + + } else if (SCEPOperation.GET_CA_CAPS.getValue().equals(operation)) { + + if (log.isDebugEnabled()) { + log.debug("Invoking GetCACaps"); + } + + try { + CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. + getCertificateManagementService(); + byte caCaps[] = certificateManagementService.getCACapsSCEP(); + + return Response.ok(caCaps, MediaType.TEXT_PLAIN).build(); + + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the device", e); + } + + } else { + log.error("Invalid SCEP operation " + operation); + } + + return Response.serverError().build(); + } + + @POST + @Path("controller/scep") + public Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream) { + + if (log.isDebugEnabled()) { + log.debug("Invoking SCEP operation " + operation); + } + + if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) { + + if (log.isDebugEnabled()) { + log.debug("Invoking PKIOperation"); + } + + try { + CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. + getCertificateManagementService(); + byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream); + + return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build(); + + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the device", e); + } catch (KeystoreException e) { + log.error("Keystore error occurred while enrolling the device", e); + } + } + return Response.serverError().build(); + } +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/dto/DeviceJSON.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/dto/DeviceJSON.java new file mode 100644 index 0000000000..3d86d79bb1 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/dto/DeviceJSON.java @@ -0,0 +1,36 @@ +/* + * 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.iot.virtualfirealarm.service.dto; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement + +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeviceJSON { + @XmlElement(required = true) public String owner; + @XmlElement(required = true) public String deviceId; + @XmlElement(required = true) public String reply; + @XmlElement public Long time; + @XmlElement public String key; + @XmlElement public float value; +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/exception/VirtualFireAlarmException.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/exception/VirtualFireAlarmException.java new file mode 100644 index 0000000000..9f9ca0253f --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/exception/VirtualFireAlarmException.java @@ -0,0 +1,31 @@ +/* + * 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.iot.virtualfirealarm.service.exception; + +public class VirtualFireAlarmException extends Exception { + private static final long serialVersionUID = 118512086957330189L; + + public VirtualFireAlarmException(String errorMessage) { + super(errorMessage); + } + + public VirtualFireAlarmException(String errorMessage, Throwable throwable) { + super(errorMessage, throwable); + } +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTSubscriber.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTSubscriber.java new file mode 100644 index 0000000000..5e563164a4 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmMQTTSubscriber.java @@ -0,0 +1,154 @@ +/* + * 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.iot.virtualfirealarm.service.transport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttSubscriber; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils; + +import java.io.File; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.Calendar; +import java.util.UUID; + +public class VirtualFireAlarmMQTTSubscriber extends MqttSubscriber { + private static Log log = LogFactory.getLog(VirtualFireAlarmMQTTSubscriber.class); + + private static final String subscribeTopic = + "wso22" + File.separator + "iot" + File.separator + "+" + File.separator + + VirtualFireAlarmConstants.DEVICE_TYPE + File.separator + "+" + File.separator + + "publisher"; + + private static final String iotServerSubscriber = UUID.randomUUID().toString().substring(0, 5); + private static String mqttEndpoint; + + private VirtualFireAlarmMQTTSubscriber() { + super(iotServerSubscriber, VirtualFireAlarmConstants.DEVICE_TYPE, + MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic); + } + + public void initConnector() { + mqttEndpoint = MqttConfig.getInstance().getMqttQueueEndpoint(); + } + + public void connectAndSubscribe() { + try { + super.connectAndSubscribe(); + } catch (DeviceManagementException e) { + log.error("Subscription to MQTT Broker at: " + mqttEndpoint + " failed"); + retryMQTTSubscription(); + } + } + + @Override + protected void postMessageArrived(String topic, MqttMessage mqttMessage) { + String ownerAndId = topic.replace("wso2" + File.separator + "iot" + File.separator, ""); + ownerAndId = ownerAndId.replace(File.separator + VirtualFireAlarmConstants.DEVICE_TYPE + File.separator, ":"); + ownerAndId = ownerAndId.replace(File.separator + "publisher", ""); + + String owner = ownerAndId.split(":")[0]; + String deviceId = ownerAndId.split(":")[1]; + + if (log.isDebugEnabled()) { + log.debug("Received MQTT message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}"); + } + + String actualMessage = ""; + + try { + PublicKey clientPublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId); + PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey(); + actualMessage = VirtualFireAlarmServiceUtils.extractMessageFromPayload(mqttMessage.toString(), + serverPrivateKey, clientPublicKey); + + if (log.isDebugEnabled()) { + log.debug("MQTT: Received Message [" + actualMessage + "] topic: [" + topic + "]"); + } + + if (actualMessage.contains("PUBLISHER")) { + float temperature = Float.parseFloat(actualMessage.split(":")[2]); + + if (!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) { + log.error("MQTT Subscriber: Publishing data to DAS failed."); + } + + if (log.isDebugEnabled()) { + log.debug("MQTT Subscriber: Published data to DAS successfully."); + } + + } else if (actualMessage.contains("TEMPERATURE")) { + String temperatureValue = actualMessage.split(":")[1]; + SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMPERATURE, + temperatureValue, + Calendar.getInstance().getTimeInMillis()); + } else { + if (log.isDebugEnabled()) { + log.debug("MQTT: Random Message [" + actualMessage + "] topic: [" + topic + "]"); + } + } + } catch (VirtualFireAlarmException e) { + String errorMsg = + "CertificateManagementService failure oo Signature-Verification/Decryption was unsuccessful."; + log.error(errorMsg, e); + } + } + + private void retryMQTTSubscription() { + Thread retryToSubscribe = new Thread() { + @Override + public void run() { + while (true) { + if (!isConnected()) { + if (log.isDebugEnabled()) { + log.debug("Subscriber re-trying to reach MQTT queue...."); + } + + try { + VirtualFireAlarmMQTTSubscriber.super.connectAndSubscribe(); + } catch (DeviceManagementException e1) { + if (log.isDebugEnabled()) { + log.debug("Attempt to re-connect to MQTT-Queue failed"); + } + } + } else { + break; + } + + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + log.error("MQTT: Thread S;eep Interrupt Exception"); + } + } + } + }; + + retryToSubscribe.setDaemon(true); + retryToSubscribe.start(); + } +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java new file mode 100644 index 0000000000..f4eccbb54f --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java @@ -0,0 +1,137 @@ +/* + * 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.iot.virtualfirealarm.service.transport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jivesoftware.smack.packet.Message; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConnector; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils; + +import java.util.Calendar; + +public class VirtualFireAlarmXMPPConnector extends XmppConnector { + private static Log log = LogFactory.getLog(VirtualFireAlarmXMPPConnector.class); + + private static String xmppServerIP; + // private static int xmppServerPort; + private static String xmppAdminUsername; + private static String xmppAdminPassword; + private static String xmppAdminAccountJID; + + private VirtualFireAlarmXMPPConnector() { + super(XmppConfig.getInstance().getXmppServerIP(), + XmppConfig.getInstance().getSERVER_CONNECTION_PORT()); + } + + public void initConnector() { + xmppServerIP = XmppConfig.getInstance().getXmppServerIP(); + xmppAdminUsername = XmppConfig.getInstance().getXmppUsername(); + xmppAdminPassword = XmppConfig.getInstance().getXmppPassword(); + xmppAdminAccountJID = xmppAdminUsername + "@" + xmppServerIP; + } + + public void connectAndLogin() { + try { + super.connectAndLogin(xmppAdminUsername, xmppAdminPassword, null); + super.setMessageFilterOnReceiver(xmppAdminAccountJID); + } catch (DeviceManagementException e) { + log.error("Connect/Login attempt to XMPP Server at: " + xmppServerIP + " failed"); + retryXMPPConnection(); + } + } + + @Override + protected void processXMPPMessage(Message xmppMessage) { + String from = xmppMessage.getFrom(); + String subject = xmppMessage.getSubject(); + String message = xmppMessage.getBody(); + + int indexOfAt = from.indexOf("@"); + int indexOfSlash = from.indexOf("/"); + + String deviceId = from.substring(0, indexOfAt); + String owner = from.substring(indexOfSlash + 1, from.length()); + + log.info("Received XMPP message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}"); + + if (subject.equals("PUBLISHER")) { + log.info("XMPP: Publisher Message [" + message + "] from [" + from + "]"); + + float temperature = Float.parseFloat(message.split(":")[1]); + if(!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) { + log.error("XMPP Connector: Publishing data to DAS failed."); + } + + if(log.isDebugEnabled()) { + log.debug("XMPP Connector: Published data to DAS successfully."); + } + } else if(subject.equals("CONTROL-REPLY")) { + log.info("XMPP: Reply Message [" + message + "] from [" + from + "]"); + String temperature = message.split(":")[1]; + SensorDataManager.getInstance().setSensorRecord(deviceId,VirtualFireAlarmConstants.SENSOR_TEMPERATURE, temperature, Calendar.getInstance().getTimeInMillis()); + } else { + log.info("SOME XMPP Message [" + message + "] from " + from + "]"); + } + + } + + private void retryXMPPConnection() { + Thread retryToConnect = new Thread() { + @Override + public void run() { + + while (true) { + if (!isConnected()) { + if (log.isDebugEnabled()) { + log.debug("Re-trying to reach XMPP Server...."); + } + + try { + VirtualFireAlarmXMPPConnector.super.connectAndLogin(xmppAdminUsername, + xmppAdminPassword, + null); + VirtualFireAlarmXMPPConnector.super.setMessageFilterOnReceiver( + xmppAdminAccountJID); + } catch (DeviceManagementException e1) { + if (log.isDebugEnabled()) { + log.debug("Attempt to re-connect to XMPP-Server failed"); + } + } + } else { + break; + } + + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + log.error("XMPP: Thread Sleep Interrupt Exception"); + } + } + } + }; + + retryToConnect.setDaemon(true); + retryToConnect.start(); + } +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VerificationManager.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VerificationManager.java new file mode 100644 index 0000000000..07bd72ffb1 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VerificationManager.java @@ -0,0 +1,254 @@ +/* + * 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.iot.virtualfirealarm.service.util; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; +import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.security.SignatureException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; + + +public class VerificationManager { + private static final Log log = LogFactory.getLog(VerificationManager.class); + + private static PrivateKey serverPrivateKey; + private static final String SIGNATURE_ALG = "SHA1withRSA"; + private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding"; + + private VerificationManager() { + + } + + public void initVerificationManager() { + serverPrivateKey = retrievePrivateKey(ConfigurationUtil.CA_CERT_ALIAS, + ConfigurationUtil.KEYSTORE_CA_CERT_PRIV_PASSWORD); + } + + public static PrivateKey retrievePrivateKey(String alias, String password){ + PrivateKey privateKey = null; + InputStream inputStream = null; + KeyStore keyStore; + + try { + keyStore = KeyStore.getInstance(ConfigurationUtil.getConfigEntry(ConfigurationUtil.CERTIFICATE_KEYSTORE)); + inputStream = new FileInputStream(ConfigurationUtil.getConfigEntry( + ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE)); + + keyStore.load(inputStream, ConfigurationUtil.getConfigEntry(ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD) + .toCharArray()); + + privateKey = (PrivateKey) (keyStore.getKey(ConfigurationUtil.getConfigEntry(alias), + ConfigurationUtil.getConfigEntry(password).toCharArray())); + + } catch (KeyStoreException e) { + String errorMsg = "Could not load KeyStore of given type in [certificate-config.xml] file." ; + log.error(errorMsg, e); + } catch (FileNotFoundException e) { + String errorMsg = "KeyStore file could not be loaded from path given in [certificate-config.xml] file."; + log.error(errorMsg, e); + } catch (NoSuchAlgorithmException e) { + String errorMsg = "Algorithm not found when loading KeyStore"; + log.error(errorMsg, e); + } catch (CertificateException e) { + String errorMsg = "CertificateException when loading KeyStore"; + log.error(errorMsg, e); + } catch (IOException e) { + String errorMsg = "Input output issue occurred when loading KeyStore"; + log.error(errorMsg, e); + } catch (KeystoreException e) { + String errorMsg = "An error occurred whilst trying load Configs for KeyStoreReader"; + log.error(errorMsg, e); + } catch (UnrecoverableKeyException e) { + String errorMsg = "Key is unrecoverable when retrieving CA private key"; + log.error(errorMsg, e); + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (IOException e) { + log.error("Error closing KeyStore input stream", e); + } + } + + return privateKey; + } + + public static PrivateKey getServerPrivateKey() { + return serverPrivateKey; + } + + public static String encryptMessage(String message, Key encryptionKey) throws VirtualFireAlarmException { + Cipher encrypter; + byte[] cipherData; + + try { + encrypter = Cipher.getInstance(CIPHER_PADDING); + encrypter.init(Cipher.ENCRYPT_MODE, encryptionKey); + cipherData = encrypter.doFinal(message.getBytes(StandardCharsets.UTF_8)); + + } catch (NoSuchAlgorithmException e) { + String errorMsg = "Algorithm not found exception occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (NoSuchPaddingException e) { + String errorMsg = "No Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (InvalidKeyException e) { + String errorMsg = "InvalidKey exception occurred for encryptionKey \n[\n" + encryptionKey + "\n]\n"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (BadPaddingException e) { + String errorMsg = "Bad Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (IllegalBlockSizeException e) { + String errorMsg = "Illegal blockSize error occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } + + return Base64.encodeBase64String(cipherData); + } + + + public static String signMessage(String encryptedData, PrivateKey signatureKey) throws VirtualFireAlarmException { + + Signature signature; + String signedEncodedString; + + try { + signature = Signature.getInstance(SIGNATURE_ALG); + signature.initSign(signatureKey); + signature.update(Base64.decodeBase64(encryptedData)); + + byte[] signatureBytes = signature.sign(); + signedEncodedString = Base64.encodeBase64String(signatureBytes); + + } catch (NoSuchAlgorithmException e) { + String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (SignatureException e) { + String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (InvalidKeyException e) { + String errorMsg = "InvalidKey exception occurred for signatureKey \n[\n" + signatureKey + "\n]\n"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } + + return signedEncodedString; + } + + + public static boolean verifySignature(String data, String signedData, PublicKey verificationKey) + throws VirtualFireAlarmException { + + Signature signature; + boolean verified; + + try { + signature = Signature.getInstance(SIGNATURE_ALG); + signature.initVerify(verificationKey); + signature.update(Base64.decodeBase64(data)); + + verified = signature.verify(Base64.decodeBase64(signedData)); + + } catch (NoSuchAlgorithmException e) { + String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (SignatureException e) { + String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (InvalidKeyException e) { + String errorMsg = "InvalidKey exception occurred for signatureKey \n[\n" + verificationKey + "\n]\n"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } + + return verified; + } + + + public static String decryptMessage(String encryptedMessage, Key decryptKey) throws VirtualFireAlarmException { + + Cipher decrypter; + String decryptedMessage; + + try { + + decrypter = Cipher.getInstance(CIPHER_PADDING); + decrypter.init(Cipher.DECRYPT_MODE, decryptKey); + decryptedMessage = new String(decrypter.doFinal(Base64.decodeBase64(encryptedMessage)), StandardCharsets.UTF_8); + + } catch (NoSuchAlgorithmException e) { + String errorMsg = "Algorithm not found exception occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (NoSuchPaddingException e) { + String errorMsg = "No Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (InvalidKeyException e) { + String errorMsg = "InvalidKey exception occurred for encryptionKey \n[\n" + decryptKey + "\n]\n"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (BadPaddingException e) { + String errorMsg = "Bad Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (IllegalBlockSizeException e) { + String errorMsg = "Illegal blockSize error occurred for Cipher instance of [" + CIPHER_PADDING + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } + + return decryptedMessage; + } + + +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java new file mode 100644 index 0000000000..a8476f3a45 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/VirtualFireAlarmServiceUtils.java @@ -0,0 +1,357 @@ +/* + * 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.iot.virtualfirealarm.service.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.concurrent.FutureCallback; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClients; +import org.json.JSONObject; +import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; +import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.iot.DeviceController; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmXMPPConnector; + +import javax.ws.rs.HttpMethod; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.security.Key; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.cert.X509Certificate; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; + +public class VirtualFireAlarmServiceUtils { + private static final Log log = LogFactory.getLog(VirtualFireAlarmServiceUtils.class); + + //TODO; replace this tenant domain + private static final String SUPER_TENANT = "carbon.super"; + private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature"; + private static final String JSON_MESSAGE_KEY = "Msg"; + private static final String JSON_SIGNATURE_KEY = "Sig"; + + public static CertificateManagementService getCertificateManagementService() throws + VirtualFireAlarmException { + + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + CertificateManagementService certificateManagementService = (CertificateManagementService) + ctx.getOSGiService(CertificateManagementService.class, null); + + if (certificateManagementService == null) { + String msg = "EnrollmentService is not initialized"; + log.error(msg); + throw new VirtualFireAlarmException(msg); + } + + return certificateManagementService; + } + + + public static String sendCommandViaHTTP(final String deviceHTTPEndpoint, String urlContext, + boolean fireAndForgot) throws DeviceManagementException { + + String responseMsg = ""; + String urlString = VirtualFireAlarmConstants.URL_PREFIX + deviceHTTPEndpoint + urlContext; + + if (log.isDebugEnabled()) { + log.debug(urlString); + } + + if (!fireAndForgot) { + HttpURLConnection httpConnection = getHttpConnection(urlString); + + try { + httpConnection.setRequestMethod(HttpMethod.GET); + } catch (ProtocolException e) { + String errorMsg = + "Protocol specific error occurred when trying to set method to GET" + + " for:" + urlString; + log.error(errorMsg); + throw new DeviceManagementException(errorMsg, e); + } + + responseMsg = readResponseFromGetRequest(httpConnection); + + } else { + CloseableHttpAsyncClient httpclient = null; + try { + + httpclient = HttpAsyncClients.createDefault(); + httpclient.start(); + HttpGet request = new HttpGet(urlString); + final CountDownLatch latch = new CountDownLatch(1); + Future future = httpclient.execute( + request, new FutureCallback() { + @Override + public void completed(HttpResponse httpResponse) { + latch.countDown(); + } + + @Override + public void failed(Exception e) { + latch.countDown(); + } + + @Override + public void cancelled() { + latch.countDown(); + } + }); + + latch.await(); + + } catch (InterruptedException e) { + if (log.isDebugEnabled()) { + log.debug("Sync Interrupted"); + } + } finally { + try { + if (httpclient != null) { + httpclient.close(); + + } + } catch (IOException e) { + if (log.isDebugEnabled()) { + log.debug("Failed on close"); + } + } + } + } + + return responseMsg; + } + + + public static boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource, + String state) throws DeviceManagementException { + + boolean result; + DeviceController deviceController = new DeviceController(); + + try { + PublicKey devicePublicKey = getDevicePublicKey(deviceId); + PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey(); + String message = prepareSecurePayLoad(resource, devicePublicKey, serverPrivateKey); + + result = deviceController.publishMqttControl(deviceOwner, + VirtualFireAlarmConstants.DEVICE_TYPE, + deviceId, message, state); + } catch (DeviceControllerException e) { + String errorMsg = "Error whilst trying to publish to MQTT Queue"; + log.error(errorMsg); + throw new DeviceManagementException(errorMsg, e); + } catch (VirtualFireAlarmException e) { + throw new DeviceManagementException(e); + } + return result; + } + + public static void sendCommandViaXMPP(String deviceOwner, String deviceId, String resource, + String state, VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) + throws DeviceManagementException { + + String xmppServerDomain = XmppConfig.getInstance().getXmppEndpoint(); + int indexOfChar = xmppServerDomain.lastIndexOf(File.separator); + if (indexOfChar != -1) { + xmppServerDomain = xmppServerDomain.substring((indexOfChar + 1), + xmppServerDomain.length()); + } + + indexOfChar = xmppServerDomain.indexOf(":"); + if (indexOfChar != -1) { + xmppServerDomain = xmppServerDomain.substring(0, indexOfChar); + } + + String clientToConnect = deviceId + "@" + xmppServerDomain + File.separator + deviceOwner; + String message = resource.replace("/", "") + ":" + state; + + virtualFireAlarmXMPPConnector.sendXMPPMessage(clientToConnect, message, "CONTROL-REQUEST"); + } + + /* --------------------------------------------------------------------------------------- + Utility methods relevant to creating and sending http requests + --------------------------------------------------------------------------------------- */ + + /* This methods creates and returns a http connection object */ + + public static HttpURLConnection getHttpConnection(String urlString) throws + DeviceManagementException { + + URL connectionUrl = null; + HttpURLConnection httpConnection; + + try { + connectionUrl = new URL(urlString); + httpConnection = (HttpURLConnection) connectionUrl.openConnection(); + } catch (MalformedURLException e) { + String errorMsg = + "Error occured whilst trying to form HTTP-URL from string: " + urlString; + log.error(errorMsg); + throw new DeviceManagementException(errorMsg, e); + } catch (IOException e) { + String errorMsg = "Error occured whilst trying to open a connection to: " + + connectionUrl.toString(); + log.error(errorMsg); + throw new DeviceManagementException(errorMsg, e); + } + + return httpConnection; + } + + /* This methods reads and returns the response from the connection */ + + public static String readResponseFromGetRequest(HttpURLConnection httpConnection) + throws DeviceManagementException { + BufferedReader bufferedReader; + try { + bufferedReader = new BufferedReader(new InputStreamReader( + httpConnection.getInputStream())); + } catch (IOException e) { + String errorMsg = + "There is an issue with connecting the reader to the input stream at: " + + httpConnection.getURL(); + log.error(errorMsg); + throw new DeviceManagementException(errorMsg, e); + } + + String responseLine; + StringBuilder completeResponse = new StringBuilder(); + + try { + while ((responseLine = bufferedReader.readLine()) != null) { + completeResponse.append(responseLine); + } + } catch (IOException e) { + String errorMsg = + "Error occured whilst trying read from the connection stream at: " + + httpConnection.getURL(); + log.error(errorMsg); + throw new DeviceManagementException(errorMsg, e); + } + try { + bufferedReader.close(); + } catch (IOException e) { + log.error( + "Could not succesfully close the bufferedReader to the connection at: " + + httpConnection.getURL()); + } + + return completeResponse.toString(); + } + + public static boolean publishToDAS(String owner, String deviceId, float temperature) { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(SUPER_TENANT, true); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx.getOSGiService( + DeviceAnalyticsService.class, null); + Object metdaData[] = {owner, VirtualFireAlarmConstants.DEVICE_TYPE, deviceId, + System.currentTimeMillis()}; + Object payloadData[] = {temperature}; + + try { + deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", metdaData, + new Object[0], payloadData); + } catch (DataPublisherConfigurationException e) { + return false; + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + return true; + } + + + + public static String prepareSecurePayLoad(String message, Key encryptionKey, PrivateKey signatureKey) + throws VirtualFireAlarmException { + String encryptedMsg = VerificationManager.encryptMessage(message, encryptionKey); + String signedPayload = VerificationManager.signMessage(encryptedMsg, signatureKey); + + JSONObject jsonPayload = new JSONObject(); + jsonPayload.append(JSON_MESSAGE_KEY, encryptedMsg); + jsonPayload.append(JSON_SIGNATURE_KEY, signedPayload); + + return jsonPayload.toString(); + } + + + public static String extractMessageFromPayload(String message, Key decryptionKey, PublicKey verifySignatureKey) + throws VirtualFireAlarmException { + String actualMessage; + + JSONObject jsonPayload = new JSONObject(message); + String encryptedMessage = jsonPayload.getString(JSON_MESSAGE_KEY); + String signedPayload = jsonPayload.getString(JSON_SIGNATURE_KEY); + + if (VerificationManager.verifySignature(encryptedMessage, signedPayload, verifySignatureKey)) { + actualMessage = VerificationManager.decryptMessage(encryptedMessage, decryptionKey); + } else { + String errorMsg = "The message was not signed by a valid client. Could not verify signature on payload"; + throw new VirtualFireAlarmException(errorMsg); + } + + return actualMessage; + } + + + public static PublicKey getDevicePublicKey(String deviceId) throws VirtualFireAlarmException { + PublicKey clientPublicKey; + String alias = ""; + + try { + alias += deviceId.hashCode(); + + CertificateManagementService certificateManagementService = + VirtualFireAlarmServiceUtils.getCertificateManagementService(); + X509Certificate clientCertificate = (X509Certificate) certificateManagementService.getCertificateByAlias( + alias); + clientPublicKey = clientCertificate.getPublicKey(); + + } catch (VirtualFireAlarmException e) { + String errorMsg = "Could not retrieve CertificateManagementService from the runtime."; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } catch (KeystoreException e) { + String errorMsg = "An error occurred whilst trying to retrieve certificate for deviceId [" + deviceId + + "] with alias: [" + alias + "]"; + log.error(errorMsg); + throw new VirtualFireAlarmException(errorMsg, e); + } + return clientPublicKey; + } + +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/ContentType.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/ContentType.java new file mode 100644 index 0000000000..db84c48811 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/ContentType.java @@ -0,0 +1,26 @@ +/* + * 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.iot.virtualfirealarm.service.util.scep; + +public class ContentType { + public static final String X_PKI_MESSAGE = "application/x-pki-message"; + public static final String X_X509_CA_CERT = "application/x-x509-ca-cert"; + public static final String X_X509_CA_RA_CERT = "application/x-x509-ca-ra-cert"; +} + diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java new file mode 100644 index 0000000000..9ad390e5d8 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/util/scep/SCEPOperation.java @@ -0,0 +1,39 @@ +/* + * 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.iot.virtualfirealarm.service.util.scep; + +public enum SCEPOperation { + GET_CA_CERT("GetCACert"), + GET_CA_CAPS("GetCACaps"), + PKI_OPERATION("PKIOperation"); + + private String value; + + private SCEPOperation(String value) { + this.setValue(value); + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/resources.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/resources.xml new file mode 100644 index 0000000000..8f83e0507e --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/resources.xml @@ -0,0 +1,105 @@ + + + + + + + + Any + PUT + http://localhost:9763/virtual_firealarm/manager/device/register + /manager/device/register/* + + + Any + DELETE + http://localhost:9763/virtual_firealarm/manager/device/remove + /manager/device/remove/* + + + Any + POST + http://localhost:9763/virtual_firealarm/manager/device/update + /manager/device/update/* + + + Any + GET + http://localhost:9763/virtual_firealarm/manager/device + /manager/device/* + + + Any + GET + http://localhost:9763/virtual_firealarm/manager/devices + /manager/devices/* + + + Any + GET + http://localhost:9763/virtual_firealarm/manager/device/{sketch_type}/download + /manager/device/{sketch_type}/download + + + Any + GET + http://localhost:9763/virtual_firealarm/manager/device/{sketch_type}/generate_link + /manager/device/{sketch_type}/generate_link + + + + Any + POST + http://localhost:9763/virtual_firealarm/controller/register/{owner}/{deviceId}/{ip}/{port} + /controller/register/{owner}/{deviceId}/{ip}/{port} + + + Any + POST + http://localhost:9763/virtual_firealarm/controller/controller/bulb/{state} + /controller/bulb/{state} + + + Any + GET + http://localhost:9763/virtual_firealarm/controller/controller/readsonar + /controller/readsonar + + + Any + GET + http://localhost:9763/virtual_firealarm/controller/controller/readtemperature + /controller/readtemperature + + + Any + POST + http://localhost:9763/virtual_firealarm/controller/controller/push_temperature + /controller/push_temperature + + \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 0000000000..fa44619195 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,33 @@ + + + + + + + + + false + + + CXF,Carbon + diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 0000000000..2f54a57e36 --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..50447398be --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,81 @@ + + + WSO2 IoT Server + WSO2 IoT Server + + + CXFServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + + + CXFServlet + /* + + + + isAdminService + false + + + doAuthentication + false + + + + + managed-api-enabled + true + + + managed-api-owner + admin + + + managed-api-name + virtual_firealarm + + + managed-api-endpoint + http://localhost:9763/virtual_firealarm + + + managed-api-version + 1.0.0 + + + managed-api-context + /virtual_firealarm + + + managed-api-context-template + /virtual_firealarm/{version} + + + managed-api-application + virtual_firealarm + + + managed-api-isSecured + true + + + + + + + + + + + + + + + diff --git a/components/device-mgt-iot-virtualfirealarm/pom.xml b/components/device-mgt-iot-virtualfirealarm/pom.xml new file mode 100644 index 0000000000..025f29006d --- /dev/null +++ b/components/device-mgt-iot-virtualfirealarm/pom.xml @@ -0,0 +1,63 @@ + + + + + + + org.wso2.carbon.devicemgt-plugins + carbon-device-mgt-plugins-parent + 1.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + device-mgt-iot-virtualfirealarm + 1.9.2-SNAPSHOT + pom + WSO2 Carbon - IoT Device Management VirtualFireAlarm Component + http://wso2.org + + + org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl + org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl + + + + + + + + org.apache.felix + maven-scr-plugin + 1.7.2 + + + generate-scr-scrdescriptor + + scr + + + + + + + + \ No newline at end of file diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/pom.xml b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/pom.xml index 24cb0fa14c..19602bb76f 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/pom.xml +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/pom.xml @@ -96,7 +96,7 @@ !org.wso2.carbon.device.mgt.iot.internal, - org.wso2.carbon.device.mgt.iot.*;version="${pom.version}", + org.wso2.carbon.device.mgt.iot.*;version="${project.version}", org.eclipse.paho.client.mqttv3.*;version="${eclipse.paho.version}" diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java index 177efe3835..078f11cbc4 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java @@ -44,7 +44,7 @@ import org.wso2.carbon.utils.ConfigurationContextService; import java.util.Map; /** - * @scr.component name="org.wso2.carbon.device.mgt.iot.common.internal.IotDeviceManagementServiceComponent" + * @scr.component name="org.wso2.carbon.device.mgt.iot.internal.IotDeviceManagementServiceComponent" * immediate="true" * @scr.reference name="user.realmservice.default" * interface="org.wso2.carbon.user.core.service.RealmService" diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/DeviceTypeService.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/DeviceTypeService.java index 7d8fecf84e..c4253eac1b 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/DeviceTypeService.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/DeviceTypeService.java @@ -20,4 +20,5 @@ package org.wso2.carbon.device.mgt.iot.service; public interface DeviceTypeService { + } diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/build.properties b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/build.properties similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/build.properties rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/build.properties diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf/mobile-config.xml b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf/mobile-config.xml similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf/mobile-config.xml rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/conf/mobile-config.xml diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/h2.sql b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/h2.sql similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/h2.sql rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/h2.sql diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mssql.sql b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mssql.sql similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mssql.sql rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mssql.sql diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mysql.sql b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mysql.sql similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mysql.sql rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/mysql.sql diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/oracle.sql b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/oracle.sql similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/oracle.sql rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/oracle.sql diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/postgresql.sql b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/postgresql.sql similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/postgresql.sql rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/dbscripts/plugins/postgresql.sql diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-android.hbs b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-android.hbs similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-android.hbs rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-android.hbs diff --git a/features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf b/features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf similarity index 100% rename from features/device-mgt-mdm-android/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf rename to features/device-mgt-mdm-android-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf diff --git a/features/device-mgt-mdm-android/pom.xml b/features/device-mgt-mdm-android-feature/pom.xml similarity index 100% rename from features/device-mgt-mdm-android/pom.xml rename to features/device-mgt-mdm-android-feature/pom.xml diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/pom.xml b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/pom.xml similarity index 99% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/pom.xml rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/pom.xml index d94fddad4c..5c69731bf7 100644 --- a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/pom.xml +++ b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt-plugins - device-mgt-feature + device-mgt-mdm-feature 1.9.2-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/build.properties b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/build.properties similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/build.properties rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/build.properties diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.hbs diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.platform.configuration/configuration.json diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.js diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.json b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.json similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.json rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.json diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/hidden-operations-ios.hbs diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/templates/operations.hbs diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.json b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.json similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.json rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.json diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.json diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/public/js/platform-configuration.js diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.json b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.json similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.json rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.json diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf b/features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf rename to features/device-mgt-mdm-feature/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/p2.inf diff --git a/features/device-mgt-mdm/pom.xml b/features/device-mgt-mdm-feature/pom.xml similarity index 96% rename from features/device-mgt-mdm/pom.xml rename to features/device-mgt-mdm-feature/pom.xml index b2565634db..7c966344de 100644 --- a/features/device-mgt-mdm/pom.xml +++ b/features/device-mgt-mdm-feature/pom.xml @@ -28,7 +28,7 @@ 4.0.0 - device-mgt-feature + device-mgt-mdm-feature 1.9.2-SNAPSHOT pom WSO2 Carbon - Device Management Feature diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/pom.xml b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/pom.xml similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/pom.xml rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/pom.xml diff --git a/features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/build.properties b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/build.properties similarity index 100% rename from features/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/build.properties rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/build.properties diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/h2.sql b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/h2.sql similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/h2.sql rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/h2.sql diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mssql.sql b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mssql.sql similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mssql.sql rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mssql.sql diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mysql.sql b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mysql.sql similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mysql.sql rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/mysql.sql diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/oracle.sql b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/oracle.sql similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/oracle.sql rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/oracle.sql diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/postgresql.sql b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/postgresql.sql similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/postgresql.sql rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/dbscripts/plugins/postgresql.sql diff --git a/features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/p2.inf b/features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/p2.inf similarity index 100% rename from features/device-mgt-mdm-windows/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/p2.inf rename to features/device-mgt-mdm-windows-feature/org.wso2.carbon.device.mgt.mobile.windows.feature/src/main/resources/p2.inf diff --git a/features/device-mgt-mdm-windows/pom.xml b/features/device-mgt-mdm-windows-feature/pom.xml similarity index 100% rename from features/device-mgt-mdm-windows/pom.xml rename to features/device-mgt-mdm-windows-feature/pom.xml diff --git a/pom.xml b/pom.xml index f1b1f1ee18..6beec6cf3e 100644 --- a/pom.xml +++ b/pom.xml @@ -37,14 +37,26 @@ + components/device-mgt-iot components/device-mgt-mdm + + components/device-mgt-mdm-android components/device-mgt-mdm-windows + + + components/device-mgt-iot-virtualfirealarm + + features/device-mgt-iot-feature - features/device-mgt-mdm - features/device-mgt-mdm-android - features/device-mgt-mdm-windows + features/device-mgt-mdm-feature + + + features/device-mgt-mdm-android-feature + features/device-mgt-mdm-windows-feature + + @@ -297,6 +309,12 @@ war + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl + ${carbon.iot.device.mgt.version} + + org.json.wso2 json @@ -1049,7 +1067,7 @@ 2.3.1 2.2.4 1.0.2 - 2.0.0.wso2v1 + 3.0.0.wso2v1 3.2.1 1.8 4.3.1.wso2v2 @@ -1168,6 +1186,11 @@ build-helper-maven-plugin 1.8 + + org.apache.maven.plugins + maven-war-plugin + 2.2 +