diff --git a/README.md b/README.md index 1fbe5606e..4cd3ea5a5 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,5 @@ WSO2 MOBILE DEVICE MANAGER WSO2 Mobile Device Manager (WSO2 MDM) is a comprehensive platform that helps solve mobile computing challenges enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program. Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 MDM offers a single enterprise-grade platform. + + diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml index 176413cff..dd175a867 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml @@ -16,14 +16,12 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -34,19 +32,6 @@ - - maven-clean-plugin - 2.4.1 - - - auto-clean - initialize - - clean - - - - maven-antrun-plugin 1.7 @@ -55,7 +40,7 @@ process-resources - + diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_execution/android_sense_execution.siddhiql b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_execution/android_sense_execution.siddhiql index 2304e2eca..fcd13aa5d 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_execution/android_sense_execution.siddhiql +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_execution/android_sense_execution.siddhiql @@ -39,8 +39,22 @@ define stream battery (meta_owner string, meta_deviceType string, meta_deviceId @Export('org.wso2.iot.devices.accelerometer:1.0.0') define stream accelerometer (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, x float, y float, z float); +@Export("org.wso2.iot.devices.speed:1.0.0") +define stream speed (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, limit float); + +@Export("org.wso2.iot.devices.turn:1.0.0") +define stream turn (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, turn string); + @Import('org.wso2.iot.android.sense:1.0.0') -define stream androidsense (meta_owner string, meta_deviceId string, meta_type string, meta_timestamp long, battery int, gps_lat double, gps_long double, accelerometer_x float, accelerometer_y float, accelerometer_z float, magnetic_x float, magnetic_y float, magnetic_z float, gyroscope_x float, gyroscope_y float, gyroscope_z float, light float, pressure float, proximity float, gravity_x float, gravity_y float, gravity_z float, rotation_x float, rotation_y float, rotation_z float, word string, word_sessionId string, word_status string); +define stream androidsense (meta_owner string, meta_deviceId string, meta_type string, meta_timestamp long, battery int, gps_lat double, gps_long double, accelerometer_x float, accelerometer_y float, accelerometer_z float,speed_limit float,turn_way string, magnetic_x float, magnetic_y float, magnetic_z float, gyroscope_x float, gyroscope_y float, gyroscope_z float, light float, pressure float, proximity float, gravity_x float, gravity_y float, gravity_z float, rotation_x float, rotation_y float, rotation_z float, word string, word_sessionId string, word_status string); + +from androidsense[meta_type == 'speed'] +select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, speed_limit as limit +insert into speed; + +from androidsense[meta_type == 'turn'] +select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, turn_way as turn +insert into turn; from androidsense[meta_type == 'accelerometer'] select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, accelerometer_x as x, accelerometer_y as y, accelerometer_z as z @@ -84,4 +98,4 @@ insert into rotation; from androidsense[meta_type == 'word'] select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, word_sessionId as sessionId, word as word, word_status as status -insert into words; \ No newline at end of file +insert into words; diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_stream/org.wso2.iot.android.sense_1.0.0.json b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_stream/org.wso2.iot.android.sense_1.0.0.json index f9048dd33..a42d308c4 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_stream/org.wso2.iot.android.sense_1.0.0.json +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_stream/org.wso2.iot.android.sense_1.0.0.json @@ -16,6 +16,8 @@ {"name": "accelerometer_x", "type": "FLOAT"}, {"name": "accelerometer_y", "type": "FLOAT"}, {"name": "accelerometer_z", "type": "FLOAT"}, + {"name": "speed_limit", "type": "FLOAT"}, + {"name": "turn_way", "type": "STRING"}, {"name": "magnetic_x", "type": "FLOAT"}, {"name": "magnetic_y", "type": "FLOAT"}, {"name": "magnetic_z", "type": "FLOAT"}, @@ -35,4 +37,4 @@ {"name": "word_sessionId", "type": "STRING"}, {"name": "word_status", "type": "STRING"} ] -} \ No newline at end of file +} diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml index 3a2404ddf..642525ea2 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml @@ -1,11 +1,9 @@ - + androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml index 61c64749f..2985b3292 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/pom.xml @@ -10,12 +10,11 @@ License for the ~ specific language governing permissions and limitations ~ under the License. --> - + androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -68,7 +67,8 @@ org.wso2.carbon.core, org.wso2.carbon.core.util, org.wso2.carbon.event.output.adapter.core, - org.wso2.carbon.event.output.adapter.core.exception + org.wso2.carbon.event.output.adapter.core.exception, + org.wso2.carbon.ndatasource.core !org.wso2.carbon.device.mgt.iot.androidsense.plugin.internal, diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManager.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManager.java index f5bd7e61e..fff692b37 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManager.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManager.java @@ -25,7 +25,7 @@ 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.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException; @@ -49,14 +49,14 @@ public class AndroidSenseManager implements DeviceManager { } @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + public boolean saveConfiguration(PlatformConfiguration PlatformConfiguration) throws DeviceManagementException { //TODO implement this return false; } @Override - public TenantConfiguration getConfiguration() throws DeviceManagementException { + public PlatformConfiguration getConfiguration() throws DeviceManagementException { //TODO implement this return null; } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/AndroidSenseDAOUtil.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/AndroidSenseDAOUtil.java index b879f24ae..c847e16c4 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/AndroidSenseDAOUtil.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/AndroidSenseDAOUtil.java @@ -43,7 +43,7 @@ public class AndroidSenseDAOUtil { Context ctx = new InitialContext(); dataSource = (DataSource) ctx.lookup(AndroidSenseConstants.DATA_SOURCE_NAME); } catch (NamingException e) { - log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME); + log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME, e); } } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java index cba547d56..bb6120f5e 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java @@ -85,13 +85,12 @@ public class AndroidSenseUtils { try { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(AndroidSenseConstants.DATA_SOURCE_NAME); - DeviceSchemaInitializer initializer = - new DeviceSchemaInitializer(dataSource); + DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); log.info("Initializing device management repository database schema"); initializer.createRegistryDatabase(); } catch (NamingException e) { - log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME); + log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME, e); } catch (Exception e) { throw new AndroidSenseDeviceMgtPluginException("Error occurred while initializing Iot Device " + "Management database schema", e); diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/DeviceSchemaInitializer.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/DeviceSchemaInitializer.java index eabc7f44b..7b02de7e8 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/DeviceSchemaInitializer.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/DeviceSchemaInitializer.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.dbcreator.DatabaseCreator; @@ -33,7 +34,8 @@ public class DeviceSchemaInitializer extends DatabaseCreator{ private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class); private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts" - + File.separator + "cdm" + File.separator + "plugins" + File.separator; + + File.separator + "cdm" + File.separator + "plugins" + File.separator + AndroidSenseConstants.DEVICE_TYPE + + File.separator; public DeviceSchemaInitializer(DataSource dataSource) { super(dataSource); diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/internal/AndroidSenseManagementServiceComponent.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/internal/AndroidSenseManagementServiceComponent.java index f287650ec..981b4e04b 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/internal/AndroidSenseManagementServiceComponent.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/internal/AndroidSenseManagementServiceComponent.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.AndroidSenseManag import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.util.AndroidSenseStartupListener; import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.util.AndroidSenseUtils; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; +import org.wso2.carbon.ndatasource.core.DataSourceService; /** * @scr.component name="org.wso2.carbon.device.mgt.iot.android.internal.AndroidSenseManagementServiceComponent" @@ -38,6 +39,12 @@ import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; * policy="dynamic" * bind="setOutputEventAdapterService" * unbind="unsetOutputEventAdapterService" + * @scr.reference name="org.wso2.carbon.ndatasource" + * interface="org.wso2.carbon.ndatasource.core.DataSourceService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDataSourceService" + * unbind="unsetDataSourceService" */ public class AndroidSenseManagementServiceComponent { @@ -57,8 +64,7 @@ public class AndroidSenseManagementServiceComponent { String setupOption = System.getProperty("setup"); if (setupOption != null) { if (log.isDebugEnabled()) { - log.debug( - "-Dsetup is enabled. Iot Device management repository schema initialization is about " + + log.debug("-Dsetup is enabled. Iot Device management repository schema initialization is about " + "to begin"); } try { @@ -108,4 +114,16 @@ public class AndroidSenseManagementServiceComponent { protected void unsetOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService) { AndroidSenseManagementDataHolder.getInstance().setOutputEventAdapterService(null); } + + protected void setDataSourceService(DataSourceService dataSourceService) { + /* This is to avoid mobile device management component getting initialized before the underlying datasources + are registered */ + if (log.isDebugEnabled()) { + log.debug("Data source service set to service component"); + } + } + + protected void unsetDataSourceService(DataSourceService dataSourceService) { + //do nothing + } } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml index 00aeef2e0..b3ec594b7 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml @@ -17,14 +17,12 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + androidsense-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.hbs b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.hbs index 9580c8524..c8e8b2a29 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.hbs +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.analytics-view/analytics-view.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs index 2ee7289d4..89059bcd6 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#zone "topCss"}} +{{#zone "topCss"}} + {{css "css/styles.css"}} +{{/zone}} {{#zone "bottomJs"}} {{js "/js/download.js"}} @@ -325,4 +290,4 @@ } {{js "/js/jquery.validate.js"}} -{{/zone}} +{{/zone}} \ No newline at end of file diff --git a/components/iot-plugins/androidsense-plugin/pom.xml b/components/iot-plugins/androidsense-plugin/pom.xml index 3d310a1e2..96e2afc95 100644 --- a/components/iot-plugins/androidsense-plugin/pom.xml +++ b/components/iot-plugins/androidsense-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml index 1f313170a..457aec2d2 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml @@ -16,14 +16,12 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -34,19 +32,6 @@ - - maven-clean-plugin - 2.4.1 - - - auto-clean - initialize - - clean - - - - maven-antrun-plugin 1.7 @@ -55,7 +40,7 @@ process-resources - + diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml index 77142701b..90d723f94 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml @@ -17,13 +17,11 @@ ~ under the License. --> - + arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml index f32a29f81..5b900b936 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/pom.xml @@ -18,12 +18,11 @@ ~ under the License. --> - + arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -70,7 +69,8 @@ org.wso2.carbon.device.mgt.common, org.wso2.carbon.device.mgt.iot.*, org.wso2.carbon.device.mgt.extensions.feature.mgt.*, - org.wso2.carbon.utils.* + org.wso2.carbon.utils.*, + org.wso2.carbon.ndatasource.core diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java index 35dbdb4ea..c3d80d8d6 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java @@ -27,7 +27,7 @@ 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.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException; @@ -51,14 +51,14 @@ public class ArduinoManager implements DeviceManager { } @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + public boolean saveConfiguration(PlatformConfiguration PlatformConfiguration) throws DeviceManagementException { //TODO implement this return false; } @Override - public TenantConfiguration getConfiguration() throws DeviceManagementException { + public PlatformConfiguration getConfiguration() throws DeviceManagementException { //TODO implement this return null; } diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAOUtil.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAOUtil.java index 6e8895f4a..4a7cb00ec 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAOUtil.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAOUtil.java @@ -45,7 +45,7 @@ public class ArduinoDAOUtil { Context ctx = new InitialContext(); dataSource = (DataSource) ctx.lookup(ArduinoConstants.DATA_SOURCE_NAME); } catch (NamingException e) { - log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME); + log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME, e); } } diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java index f5e364274..1bc62d74d 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java @@ -97,13 +97,12 @@ public class ArduinoUtils { try { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(ArduinoConstants.DATA_SOURCE_NAME); - DeviceSchemaInitializer initializer = - new DeviceSchemaInitializer(dataSource); + DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); log.info("Initializing device management repository database schema"); initializer.createRegistryDatabase(); } catch (NamingException e) { - log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME); + log.error("Error while looking up the data source: " + ArduinoConstants.DATA_SOURCE_NAME, e); } catch (Exception e) { throw new ArduinoDeviceMgtPluginException("Error occurred while initializing Iot Device " + "Management database schema", e); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/DeviceSchemaInitializer.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/DeviceSchemaInitializer.java index 3567e776f..eff15d20f 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/DeviceSchemaInitializer.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/DeviceSchemaInitializer.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.dbcreator.DatabaseCreator; @@ -33,7 +34,8 @@ public class DeviceSchemaInitializer extends DatabaseCreator{ private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class); private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts" - + File.separator + "cdm" + File.separator + "plugins" + File.separator; + + File.separator + "cdm" + File.separator + "plugins" + File.separator + ArduinoConstants.DEVICE_TYPE + + File.separator; public DeviceSchemaInitializer(DataSource dataSource) { super(dataSource); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/internal/ArduinoManagementServiceComponent.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/internal/ArduinoManagementServiceComponent.java index fc5fe40a3..719378575 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/internal/ArduinoManagementServiceComponent.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/internal/ArduinoManagementServiceComponent.java @@ -27,9 +27,17 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException; import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.ArduinoManagerService; import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util.ArduinoUtils; +import org.wso2.carbon.ndatasource.core.DataSourceService; + /** * @scr.component name="org.wso2.carbon.device.mgt.iot.arduino.internal.ArduinoManagementServiceComponent" * immediate="true" + * @scr.reference name="org.wso2.carbon.ndatasource" + * interface="org.wso2.carbon.ndatasource.core.DataSourceService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDataSourceService" + * unbind="unsetDataSourceService" */ public class ArduinoManagementServiceComponent { @@ -83,4 +91,16 @@ public class ArduinoManagementServiceComponent { log.error("Error occurred while de-activating Arduino Device Management bundle", e); } } + + protected void setDataSourceService(DataSourceService dataSourceService) { + /* This is to avoid mobile device management component getting initialized before the underlying datasources + are registered */ + if (log.isDebugEnabled()) { + log.debug("Data source service set to service component"); + } + } + + protected void unsetDataSourceService(DataSourceService dataSourceService) { + //do nothing + } } diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml index ce74d279a..aa2795e34 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml @@ -18,14 +18,12 @@ ~ under the License. --> - + arduino-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.hbs b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.hbs index 34e83580d..b00178cdc 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.hbs +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.analytics-view/analytics-view.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.hbs b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.hbs index 6e19b1660..2f94c0533 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.hbs +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#zone "topCss"}} + {{css "css/styles.css"}} {{/zone}} {{#zone "bottomJs"}} diff --git a/components/iot-plugins/arduino-plugin/pom.xml b/components/iot-plugins/arduino-plugin/pom.xml index 09236b0ad..32abf689e 100644 --- a/components/iot-plugins/arduino-plugin/pom.xml +++ b/components/iot-plugins/arduino-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/build.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/build.xml index acc6dc0e6..537f349cc 100644 --- a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/build.xml +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/build.xml @@ -34,6 +34,8 @@ + + @@ -74,5 +76,12 @@ + + + + + + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml index 863780c2e..0e76bd819 100644 --- a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml @@ -16,14 +16,12 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + org.wso2.carbon.devicemgt-plugins iot-analytics - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -34,19 +32,6 @@ - - maven-clean-plugin - 2.4.1 - - - auto-clean - initialize - - clean - - - - maven-antrun-plugin 1.7 @@ -55,7 +40,7 @@ process-resources - + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/artifacts.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/artifacts.xml new file mode 100644 index 000000000..78a81e7b6 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/artifacts.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_publisher/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_publisher/artifact.xml new file mode 100644 index 000000000..66bd7c891 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_publisher/artifact.xml @@ -0,0 +1,22 @@ + + + + + speed_publisher.xml + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_publisher/speed_publisher.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_publisher/speed_publisher.xml new file mode 100644 index 000000000..a2b18b5db --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_publisher/speed_publisher.xml @@ -0,0 +1,27 @@ + + + + + + + Email Alerts Speed + + text/html + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_receiver/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_receiver/artifact.xml new file mode 100644 index 000000000..f92a96656 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_receiver/artifact.xml @@ -0,0 +1,22 @@ + + + + + speed_receiver.xml + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_receiver/speed_receiver.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_receiver/speed_receiver.xml new file mode 100644 index 000000000..ce6c90eee --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_receiver/speed_receiver.xml @@ -0,0 +1,26 @@ + + + + + + false + + + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_store/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_store/artifact.xml new file mode 100644 index 000000000..aa7e5c69f --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_store/artifact.xml @@ -0,0 +1,22 @@ + + + + + org_wso2_iot_devices_speed.xml + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_store/org_wso2_iot_devices_speed.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_store/org_wso2_iot_devices_speed.xml new file mode 100644 index 000000000..e9ebd7669 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_store/org_wso2_iot_devices_speed.xml @@ -0,0 +1,62 @@ + + + + + + org.wso2.iot.devices.speed:1.0.0 + + EVENT_STORE + + + meta_owner + true + true + false + STRING + + + meta_deviceType + true + true + false + STRING + + + meta_deviceId + true + true + false + STRING + + + meta_time + true + true + false + LONG + + + limit + false + false + false + LONG + + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_stream/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_stream/artifact.xml new file mode 100644 index 000000000..ff22e4804 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_stream/artifact.xml @@ -0,0 +1,23 @@ + + + + + org.wso2.iot.devices.speed_1.0.0.json + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_stream/org.wso2.iot.devices.speed_1.0.0.json b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_stream/org.wso2.iot.devices.speed_1.0.0.json new file mode 100644 index 000000000..0d2b60898 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/speed_sensor/speed_stream/org.wso2.iot.devices.speed_1.0.0.json @@ -0,0 +1,30 @@ +{ + "name": "org.wso2.iot.devices.speed", + "version": "1.0.0", + "nickName": "speed", + "description": "speed data received from the Device", + "metaData": [ + { + "name": "owner", + "type": "STRING" + }, + { + "name": "deviceType", + "type": "STRING" + }, + { + "name": "deviceId", + "type": "STRING" + }, + { + "name": "time", + "type": "LONG" + } + ], + "payloadData": [ + { + "name": "limit", + "type": "FLOAT" + } + ] +} diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/artifacts.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/artifacts.xml new file mode 100644 index 000000000..23dcb9ff1 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/artifacts.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_publisher/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_publisher/artifact.xml new file mode 100644 index 000000000..f4ab5fa59 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_publisher/artifact.xml @@ -0,0 +1,22 @@ + + + + + turn_publisher.xml + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_publisher/turn_publisher.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_publisher/turn_publisher.xml new file mode 100644 index 000000000..ffca74c42 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_publisher/turn_publisher.xml @@ -0,0 +1,27 @@ + + + + + + + Email Alerts Turn + + text/html + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_receiver/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_receiver/artifact.xml new file mode 100644 index 000000000..7b9f14cf0 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_receiver/artifact.xml @@ -0,0 +1,22 @@ + + + + + turn_receiver.xml + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_receiver/turn_receiver.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_receiver/turn_receiver.xml new file mode 100644 index 000000000..c94db7500 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_receiver/turn_receiver.xml @@ -0,0 +1,26 @@ + + + + + + false + + + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_store/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_store/artifact.xml new file mode 100644 index 000000000..e6c987339 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_store/artifact.xml @@ -0,0 +1,22 @@ + + + + + org_wso2_iot_devices_turn.xml + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_store/org_wso2_iot_devices_turn.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_store/org_wso2_iot_devices_turn.xml new file mode 100644 index 000000000..a8ab51da7 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_store/org_wso2_iot_devices_turn.xml @@ -0,0 +1,62 @@ + + + + + + org.wso2.iot.devices.turn:1.0.0 + + EVENT_STORE + + + meta_owner + true + true + false + STRING + + + meta_deviceType + true + true + false + STRING + + + meta_deviceId + true + true + false + STRING + + + meta_time + true + true + false + LONG + + + turn + false + false + false + STRING + + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_stream/artifact.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_stream/artifact.xml new file mode 100644 index 000000000..5579b0595 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_stream/artifact.xml @@ -0,0 +1,23 @@ + + + + + org.wso2.iot.devices.turn_1.0.0.json + + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_stream/org.wso2.iot.devices.turn_1.0.0.json b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_stream/org.wso2.iot.devices.turn_1.0.0.json new file mode 100644 index 000000000..beec77a55 --- /dev/null +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/turn_sensor/turn_stream/org.wso2.iot.devices.turn_1.0.0.json @@ -0,0 +1,30 @@ +{ + "name": "org.wso2.iot.devices.turn", + "version": "1.0.0", + "nickName": "turn", + "description": "turn data received from the Device", + "metaData": [ + { + "name": "owner", + "type": "STRING" + }, + { + "name": "deviceType", + "type": "STRING" + }, + { + "name": "deviceId", + "type": "STRING" + }, + { + "name": "time", + "type": "LONG" + } + ], + "payloadData": [ + { + "name": "turn", + "type": "STRING" + } + ] +} diff --git a/components/iot-plugins/iot-analytics/pom.xml b/components/iot-plugins/iot-analytics/pom.xml index 9ec9a5f08..ab6c11bbd 100644 --- a/components/iot-plugins/iot-analytics/pom.xml +++ b/components/iot-plugins/iot-analytics/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml index 8690f20dd..9d5353c6c 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.extension/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 @@ -53,5 +53,4 @@ - \ No newline at end of file diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml index cd398000a..f93cd5846 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.http/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml index 44dd1dc5f..79e2d013f 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml index f4cc2eff8..cb41bc51b 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml index 50d0474e0..4b2e42ea5 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.mqtt/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/pom.xml new file mode 100644 index 000000000..449706e39 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/pom.xml @@ -0,0 +1,78 @@ + + + + + + + iot-base-plugin + org.wso2.carbon.devicemgt-plugins + 2.1.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint + war + WSO2 - Webapp for UI Output Event Adapter + http://wso2.org + + + + junit + junit + test + + + org.apache.tomcat + tomcat-websocket-api + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.output.adapter.ui + provided + + + javax.ws.rs + javax.ws.rs-api + + + org.apache.cxf + cxf-rt-frontend-jaxrs + + + org.apache.httpcomponents.wso2 + httpcore + provided + + + org.wso2.orbit.org.apache.httpcomponents + httpclient + provided + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth.stub + provided + + + + + secured-outputui + + diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/SubscriptionEndpoint.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/SubscriptionEndpoint.java new file mode 100644 index 000000000..9439b422c --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/SubscriptionEndpoint.java @@ -0,0 +1,73 @@ +/* + * + * 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. + * + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import util.ServiceHolder; + +import javax.websocket.CloseReason; +import javax.websocket.Session; + +/** + * Interface for subscription and un-subscription for web socket + */ + +public class SubscriptionEndpoint { + + private static final Log log = LogFactory.getLog(SubscriptionEndpoint.class); + + public SubscriptionEndpoint() { + + } + + /** + * Web socket onClose - Remove the registered sessions + * + * @param session - Users registered session. + * @param reason - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + public void onClose(Session session, CloseReason reason, String streamName, String version) { + if (log.isDebugEnabled()) { + log.debug("Closing a WebSocket due to " + reason.getReasonPhrase() + ", for session ID:" + session.getId + () + + ", for request URI - " + session.getRequestURI()); + } + ServiceHolder.getInstance().getUiOutputCallbackControllerService().unsubscribeWebsocket(streamName, version, + session); + } + + /** + * Web socket onError - Remove the registered sessions + * + * @param session - Users registered session. + * @param throwable - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + public void onError(Session session, Throwable throwable, String streamName, String version) { + log.error( + "Error occurred in session ID: " + session.getId() + ", for request URI - " + session.getRequestURI() + + ", " + throwable.getMessage(), throwable); + ServiceHolder.getInstance().getUiOutputCallbackControllerService().unsubscribeWebsocket(streamName, version, + session); + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/SuperTenantSubscriptionEndpoint.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/SuperTenantSubscriptionEndpoint.java new file mode 100644 index 000000000..546473cd3 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/SuperTenantSubscriptionEndpoint.java @@ -0,0 +1,134 @@ +/* + * 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. + */ + +import oauth.OAuthTokenValdiator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import util.ServiceHolder; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; +import util.AuthenticationInfo; + +import javax.websocket.CloseReason; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; + +/** + * Connect to web socket with Super tenant + */ + +@ServerEndpoint(value = "/{streamname}/{version}") +public class SuperTenantSubscriptionEndpoint extends SubscriptionEndpoint { + + private static final Log log = LogFactory.getLog(SuperTenantSubscriptionEndpoint.class); + + /** + * Web socket onOpen - When client sends a message + * + * @param session - Users registered session. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnOpen + public void onOpen(Session session, @PathParam("streamname") String streamName, + @PathParam("version") String version) { + if (log.isDebugEnabled()) { + log.debug("WebSocket opened, for Session id: " + session.getId() + ", for the Stream:" + streamName); + } + AuthenticationInfo authenticationInfo = OAuthTokenValdiator.getInstance().validateToken(session); + //TODO Authorization + if (authenticationInfo != null && authenticationInfo.isAuthenticated()) { + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + ServiceHolder.getInstance().getUiOutputCallbackControllerService().subscribeWebsocket(streamName, + version, session); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } else { + try { + session.close(new CloseReason(CloseReason.CloseCodes.CANNOT_ACCEPT, "Unauthorized Access")); + } catch (IOException e) { + log.error("Failed to disconnect the unauthorized client."); + } + } + } + + /** + * Web socket onMessage - When client sens a message + * + * @param session - Users registered session. + * @param message - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + */ + @OnMessage + public void onMessage(Session session, String message, @PathParam("streamname") String streamName) { + if (log.isDebugEnabled()) { + log.debug("Received and dropped message from client. Message: " + message + ", " + + "for Session id: " + session.getId() + ", for the Stream:" + streamName); + } + } + + /** + * Web socket onClose - Remove the registered sessions + * + * @param session - Users registered session. + * @param reason - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnClose + public void onClose(Session session, CloseReason reason, @PathParam("streamname") String streamName, + @PathParam("version") String version) { + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + super.onClose(session, reason, streamName, version); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + + /** + * Web socket onError - Remove the registered sessions + * + * @param session - Users registered session. + * @param throwable - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnError + public void onError(Session session, Throwable throwable, @PathParam("streamname") String streamName, + @PathParam("version") String version) { + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + super.onError(session, throwable, streamName, version); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/TenantSubscriptionEndpoint.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/TenantSubscriptionEndpoint.java new file mode 100644 index 000000000..837e75f00 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/TenantSubscriptionEndpoint.java @@ -0,0 +1,134 @@ +/* + * 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. + */ + +import oauth.OAuthTokenValdiator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import util.ServiceHolder; +import util.AuthenticationInfo; + +import javax.websocket.CloseReason; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; + +/** + * Connect to web socket with a tenant + */ + +@ServerEndpoint(value = "/t/{tdomain}/{streamname}/{version}") +public class TenantSubscriptionEndpoint extends SubscriptionEndpoint { + + private static final Log log = LogFactory.getLog(TenantSubscriptionEndpoint.class); + + /** + * Web socket onOpen - When client sends a message + * + * @param session - Users registered session. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + * @param tdomain - Tenant domain extracted from ws url. + */ + @OnOpen + public void onOpen (Session session, @PathParam("streamname") String streamName , + @PathParam("version") String version, @PathParam("tdomain") String tdomain) { + if (log.isDebugEnabled()) { + log.debug("WebSocket opened, for Session id: "+session.getId()+", for the Stream:"+streamName); + } + AuthenticationInfo authenticationInfo = OAuthTokenValdiator.getInstance().validateToken(session); + //TODO Authorization + if (authenticationInfo != null && authenticationInfo.isAuthenticated()) { + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tdomain, true); + ServiceHolder.getInstance().getUiOutputCallbackControllerService().subscribeWebsocket(streamName, + version, session); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } else { + try { + session.close(new CloseReason(CloseReason.CloseCodes.CANNOT_ACCEPT, "Unauthorized Access")); + } catch (IOException e) { + log.error("Failed to disconnect the unauthorized client."); + } + } + } + + /** + * Web socket onMessage - When client sens a message + * + * @param session - Users registered session. + * @param message - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + */ + @OnMessage + public void onMessage (Session session, String message, @PathParam("streamname") String streamName, @PathParam("tdomain") String tdomain) { + if (log.isDebugEnabled()) { + log.debug("Received and dropped message from client. Message: " + message+", for Session id: "+session.getId()+", for tenant domain"+tdomain+", for the Adaptor:"+streamName); + } + } + + /** + * Web socket onClose - Remove the registered sessions + * + * @param session - Users registered session. + * @param reason - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnClose + public void onClose (Session session, CloseReason reason, @PathParam("streamname") String streamName, + @PathParam("version") String version, @PathParam("tdomain") String tdomain) { + + try { + PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tdomain,true); + super.onClose(session, reason, streamName, version); + } finally { + PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow(); + } + } + + /** + * Web socket onError - Remove the registered sessions + * + * @param session - Users registered session. + * @param throwable - Status code for web-socket close. + * @param streamName - StreamName extracted from the ws url. + * @param version - Version extracted from the ws url. + */ + @OnError + public void onError (Session session, Throwable throwable, @PathParam("streamname") String streamName, + @PathParam("version") String version, @PathParam("tdomain") String tdomain) { + + try { + PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tdomain, true); + super.onError(session, throwable, streamName, version); + } finally { + PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow(); + } + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValdiator.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValdiator.java new file mode 100644 index 000000000..e33bb39fa --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValdiator.java @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package oauth; + +import org.apache.axis2.context.ServiceContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.pool.impl.GenericObjectPool; +import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; +import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO; +import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_OAuth2AccessToken; +import org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationResponseDTO; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.utils.CarbonUtils; +import org.wso2.carbon.utils.multitenancy.MultitenantUtils; +import util.AuthenticationInfo; + +import javax.websocket.Session; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.rmi.RemoteException; +import java.util.Properties; + +/** + * This acts as a contract point for OAuth token validation. + */ +public class OAuthTokenValdiator { + + private static String cookie; + private GenericObjectPool stubs; + private static Log log = LogFactory.getLog(OAuthTokenValdiator.class); + private static final String WEBSOCKET_CONFIG_LOCATION = + CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "websocket-validation.properties"; + private static final String QUERY_STRING_SEPERATOR = "&"; + private static final String QUERY_KEY_VALUE_SEPERATOR = "="; + private static final String TOKEN_TYPE = "bearer"; + private static final String TOKEN_IDENTIFIER = "token"; + private static OAuthTokenValdiator oAuthTokenValdiator; + + public static OAuthTokenValdiator getInstance() { + if (oAuthTokenValdiator == null) { + synchronized (OAuthTokenValdiator.class) { + if (oAuthTokenValdiator == null) { + oAuthTokenValdiator = new OAuthTokenValdiator(); + } + } + } + return oAuthTokenValdiator; + } + + private OAuthTokenValdiator() { + try { + Properties properties = getWebSocketConfig(); + this.stubs = new GenericObjectPool(new OAuthTokenValidaterStubFactory(properties)); + } catch (IOException e) { + log.error("Failed to parse the web socket config file " + WEBSOCKET_CONFIG_LOCATION); + } + } + + /** + * This method gets a string accessToken and validates it + * + * @param session which need to be validated. + * @return AuthenticationInfo with the validated results. + */ + public AuthenticationInfo validateToken(Session session) { + String token = getTokenFromSession(session); + if (token == null) { + AuthenticationInfo authenticationInfo = new AuthenticationInfo(); + authenticationInfo.setAuthenticated(false); + return authenticationInfo; + } + OAuth2TokenValidationServiceStub tokenValidationServiceStub = null; + try { + Object stub = this.stubs.borrowObject(); + if (stub != null) { + tokenValidationServiceStub = (OAuth2TokenValidationServiceStub) stub; + if (cookie != null) { + tokenValidationServiceStub._getServiceClient().getOptions().setProperty( + HTTPConstants.COOKIE_STRING, cookie); + } + return getAuthenticationInfo(token, tokenValidationServiceStub); + } else { + log.warn("Stub initialization failed."); + } + } catch (RemoteException e) { + log.error("Error on connecting with the validation endpoint.", e); + } catch (Exception e) { + log.error("Error occurred in borrowing an validation stub from the pool.", e); + + } finally { + try { + if (tokenValidationServiceStub != null) { + this.stubs.returnObject(tokenValidationServiceStub); + } + } catch (Exception e) { + log.warn("Error occurred while returning the object back to the oauth token validation service " + + "stub pool.", e); + } + } + AuthenticationInfo authenticationInfo = new AuthenticationInfo(); + authenticationInfo.setAuthenticated(false); + return authenticationInfo; + } + + /** + * This creates an AuthenticationInfo object that is used for authorization. This method will validate the token + * and + * sets the required parameters to the object. + * + * @param token that needs to be validated. + * @param tokenValidationServiceStub stub that is used to call the external service. + * @return AuthenticationInfo This contains the information related to authenticated client. + * @throws RemoteException that triggers when failing to call the external service.. + */ + private AuthenticationInfo getAuthenticationInfo(String token, + OAuth2TokenValidationServiceStub tokenValidationServiceStub) + throws RemoteException, UserStoreException { + AuthenticationInfo authenticationInfo = new AuthenticationInfo(); + OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO(); + OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken = + new OAuth2TokenValidationRequestDTO_OAuth2AccessToken(); + accessToken.setTokenType(TOKEN_TYPE); + accessToken.setIdentifier(token); + validationRequest.setAccessToken(accessToken); + boolean authenticated; + OAuth2TokenValidationResponseDTO tokenValidationResponse; + tokenValidationResponse = tokenValidationServiceStub.validate(validationRequest); + if (tokenValidationResponse == null) { + authenticationInfo.setAuthenticated(false); + return authenticationInfo; + } + authenticated = tokenValidationResponse.getValid(); + if (authenticated) { + String authorizedUser = tokenValidationResponse.getAuthorizedUser(); + String username = MultitenantUtils.getTenantAwareUsername(authorizedUser); + String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); + authenticationInfo.setUsername(username); + authenticationInfo.setTenantDomain(tenantDomain); + } else { + if (log.isDebugEnabled()) { + log.debug("Token validation failed for token: " + token); + } + } + ServiceContext serviceContext = tokenValidationServiceStub._getServiceClient() + .getLastOperationContext().getServiceContext(); + cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); + authenticationInfo.setAuthenticated(authenticated); + return authenticationInfo; + } + + /** + * Retrieve JWT configs from registry. + */ + private Properties getWebSocketConfig() throws IOException { + Properties properties = new Properties(); + File configFile =new File(WEBSOCKET_CONFIG_LOCATION); + if (configFile.exists()) { + InputStream fileInputStream = new FileInputStream(configFile); + if (fileInputStream != null) { + properties.load(fileInputStream); + } + } + return properties; + } + + /** + * @param session of the user. + * @return retreive the token from the query string + */ + private String getTokenFromSession(Session session) { + String queryString = session.getQueryString(); + if (queryString != null) { + String[] allQueryParamPairs = queryString.split(QUERY_STRING_SEPERATOR); + + for (String keyValuePair : allQueryParamPairs) { + String[] queryParamPair = keyValuePair.split(QUERY_KEY_VALUE_SEPERATOR); + + if (queryParamPair.length != 2) { + log.warn("Invalid query string [" + queryString + "] passed in."); + break; + } + if (queryParamPair[0].equals(TOKEN_IDENTIFIER)) { + return queryParamPair[1]; + } + } + } + return null; + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValidaterStubFactory.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValidaterStubFactory.java new file mode 100644 index 000000000..a43f87472 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValidaterStubFactory.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package oauth; + +import oauth.exception.OAuthTokenValidationException; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.transport.http.HttpTransportProperties; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; +import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; +import org.apache.commons.pool.BasePoolableObjectFactory; +import org.apache.log4j.Logger; +import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub; +import util.UIConstants; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.util.Properties; + +/** + * This follows object pool pattern to manage the stub for oauth validation service. + */ +public class OAuthTokenValidaterStubFactory extends BasePoolableObjectFactory { + private static final Logger log = Logger.getLogger(OAuthTokenValidaterStubFactory.class); + private HttpClient httpClient; + Properties tokenValidationProperties; + + + public OAuthTokenValidaterStubFactory(Properties tokenValidationProperties) { + this.tokenValidationProperties = tokenValidationProperties; + this.httpClient = createHttpClient(); + } + + /** + * This creates a OAuth2TokenValidationServiceStub object to the pool. + * + * @return an OAuthValidationStub object + * @throws Exception thrown when creating the object. + */ + @Override + public Object makeObject() throws Exception { + return this.generateStub(); + } + + /** + * This is used to clean up the OAuth validation stub and releases to the object pool. + * + * @param o object that needs to be released. + * @throws Exception throws when failed to release to the pool + */ + @Override + public void passivateObject(Object o) throws Exception { + if (o instanceof OAuth2TokenValidationServiceStub) { + OAuth2TokenValidationServiceStub stub = (OAuth2TokenValidationServiceStub) o; + stub._getServiceClient().cleanupTransport(); + } + } + + /** + * This is used to create a stub which will be triggered through object pool factory, which will create an + * instance of it. + * + * @return OAuth2TokenValidationServiceStub stub that is used to call an external service. + * @throws OAuthTokenValidationException will be thrown when initialization failed. + */ + private OAuth2TokenValidationServiceStub generateStub() throws OAuthTokenValidationException { + OAuth2TokenValidationServiceStub stub; + try { + URL hostURL = new URL(tokenValidationProperties.getProperty((UIConstants.TOKEN_VALIDATION_ENDPOINT_URL))); + if (hostURL != null) { + stub = new OAuth2TokenValidationServiceStub(hostURL.toString()); + if (stub != null) { + ServiceClient client = stub._getServiceClient(); + client.getServiceContext().getConfigurationContext().setProperty( + HTTPConstants.CACHED_HTTP_CLIENT, httpClient); + + HttpTransportProperties.Authenticator auth = + new HttpTransportProperties.Authenticator(); + auth.setPreemptiveAuthentication(true); + String username = tokenValidationProperties.getProperty(UIConstants.USERNAME); + String password = tokenValidationProperties.getProperty(UIConstants.PASSWORD); + auth.setPassword(username); + auth.setUsername(password); + Options options = client.getOptions(); + options.setProperty(HTTPConstants.AUTHENTICATE, auth); + options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE); + client.setOptions(options); + if (hostURL.getProtocol().equals("https")) { + // set up ssl factory since axis2 https transport is used. + EasySSLProtocolSocketFactory sslProtocolSocketFactory = + createProtocolSocketFactory(); + Protocol authhttps = new Protocol(hostURL.getProtocol(), + (ProtocolSocketFactory) sslProtocolSocketFactory, + hostURL.getPort()); + Protocol.registerProtocol(hostURL.getProtocol(), authhttps); + options.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, authhttps); + } + } else { + String errorMsg = "OAuth Validation instanization failed."; + throw new OAuthTokenValidationException(errorMsg); + } + } else { + String errorMsg = "host url is invalid"; + throw new OAuthTokenValidationException(errorMsg); + } + } catch (AxisFault axisFault) { + throw new OAuthTokenValidationException( + "Error occurred while creating the OAuth2TokenValidationServiceStub.", axisFault); + } catch (MalformedURLException e) { + throw new OAuthTokenValidationException( + "Error occurred while parsing token endpoint URL", e); + } + + return stub; + } + + /** + * This is required to create a trusted connection with the external entity. + * Have to manually configure it since we use CommonHTTPTransport(axis2 transport) in axis2. + * + * @return an EasySSLProtocolSocketFactory for SSL communication. + */ + private EasySSLProtocolSocketFactory createProtocolSocketFactory() throws OAuthTokenValidationException { + try { + EasySSLProtocolSocketFactory easySSLPSFactory = new EasySSLProtocolSocketFactory(); + return easySSLPSFactory; + } catch (IOException e) { + String errorMsg = "Failed to initiate EasySSLProtocolSocketFactory."; + throw new OAuthTokenValidationException(errorMsg, e); + } catch (GeneralSecurityException e) { + String errorMsg = "Failed to set the key material in easy ssl factory."; + throw new OAuthTokenValidationException(errorMsg, e); + } + } + + /** + * This created httpclient pool that can be used to connect to external entity. This connection can be configured + * via broker.xml by setting up the required http connection parameters. + * + * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager + */ + private HttpClient createHttpClient() { + HttpConnectionManagerParams params = new HttpConnectionManagerParams(); + params.setDefaultMaxConnectionsPerHost(Integer.parseInt(tokenValidationProperties.getProperty( + UIConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST))); + params.setMaxTotalConnections(Integer.parseInt(tokenValidationProperties.getProperty( + UIConstants.MAXIMUM_TOTAL_HTTP_CONNECTION))); + HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + connectionManager.setParams(params); + return new HttpClient(connectionManager); + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/exception/OAuthTokenValidationException.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/exception/OAuthTokenValidationException.java new file mode 100644 index 000000000..3f54c5244 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/exception/OAuthTokenValidationException.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package oauth.exception; + +/** + * This Exception will be thrown, when there any interference with token validation flow. + */ +public class OAuthTokenValidationException extends Exception { + private String errMessage; + + public OAuthTokenValidationException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public OAuthTokenValidationException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public OAuthTokenValidationException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public OAuthTokenValidationException() { + super(); + } + + public OAuthTokenValidationException(Throwable cause) { + super(cause); + } + + public String getErrorMessage() { + return errMessage; + } + + public void setErrorMessage(String errMessage) { + this.errMessage = errMessage; + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/AuthenticationInfo.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/AuthenticationInfo.java new file mode 100644 index 000000000..4e2115cf0 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/AuthenticationInfo.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package util; + +/** + * This is returned after authentication. + */ +public class AuthenticationInfo { + + /** + * this variable is used to check whether the client is authenticated. + */ + private boolean authenticated; + private String username; + private String tenantDomain; + /** + * returns whether the client is authenticated + */ + public boolean isAuthenticated() { + return authenticated; + } + + public void setAuthenticated(boolean authenticated) { + this.authenticated = authenticated; + } + + /** + * returns the authenticated client username + */ + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + /** + * return the authenticated client tenant domain + */ + public String getTenantDomain() { + return tenantDomain; + } + + public void setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/ServiceHolder.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/ServiceHolder.java new file mode 100644 index 000000000..1f35b27d0 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/ServiceHolder.java @@ -0,0 +1,27 @@ +package util; + + +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIOutputCallbackControllerService; + +public class ServiceHolder { + + private static ServiceHolder instance; + private UIOutputCallbackControllerService uiOutputCallbackControllerService; + + private ServiceHolder(){ + uiOutputCallbackControllerService = (UIOutputCallbackControllerService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(UIOutputCallbackControllerService.class, null); + } + + public synchronized static ServiceHolder getInstance(){ + if (instance==null){ + instance= new ServiceHolder(); + } + return instance; + } + + public UIOutputCallbackControllerService getUiOutputCallbackControllerService() { + return uiOutputCallbackControllerService; + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/UIConstants.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/UIConstants.java new file mode 100644 index 000000000..2db13ce81 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/UIConstants.java @@ -0,0 +1,38 @@ +/* + * + * * + * * 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 util; + +/** + * This class contains the constants related to ui client. + */ +public class UIConstants { + + private UIConstants() { + } + public static final String ADAPTER_UI_COLON = ":"; + public static final String MAXIMUM_TOTAL_HTTP_CONNECTION = "maximumTotalHttpConnection"; + public static final String MAXIMUM_HTTP_CONNECTION_PER_HOST = "maximumHttpConnectionPerHost"; + public static final String TOKEN_VALIDATION_ENDPOINT_URL = "tokenValidationEndpoint"; + public static final String USERNAME = "username"; + public static final String PASSWORD = "password"; +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..2ec7fc7e9 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + + Output WebSocket + diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml new file mode 100644 index 000000000..0739a96d4 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml @@ -0,0 +1,137 @@ + + + + + + iot-base-plugin + org.wso2.carbon.devicemgt-plugins + 2.1.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.output.adapter.ui + bundle + WSO2 Carbon - Event Output UI Adapter Module + org.wso2.carbon.event.output.adapter.ui provides the back-end functionality of + ui event adapter + + http://wso2.org + + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.output.adapter.core + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.core + + + javax.websocket + javax.websocket-api + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons + + + com.google.code.gson + gson + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.stream.core + + + + + + + org.apache.felix + maven-scr-plugin + + + generate-scr-descriptor + + scr + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + + org.wso2.carbon.device.mgt.iot.output.adapter.ui.internal, + org.wso2.carbon.device.mgt.iot.output.adapter.ui.internal.* + + + !org.wso2.carbon.device.mgt.iot.output.adapter.ui.internal, + !org.wso2.carbon.device.mgt.iot.output.adapter.ui.internal.*, + org.wso2.carbon.device.mgt.iot.output.adapter.ui.* + + + org.wso2.carbon.event.output.adapter.core.*, + javax.xml.namespace; version=0.0.0, + org.apache.axis2, + org.apache.axis2.client, + org.apache.axis2.context, + org.apache.axis2.transport.http, + org.apache.commons.httpclient, + org.apache.commons.httpclient.contrib.ssl, + org.apache.commons.httpclient.params, + org.apache.commons.httpclient.protocol, + org.apache.commons.pool, + org.apache.commons.pool.impl, + org.apache.log4j, + com.google.gson, + javax.websocket, + org.apache.commons.logging, + org.osgi.framework, + org.osgi.service.component, + org.wso2.carbon.context, + org.wso2.carbon.databridge.commons, + org.wso2.carbon.event.stream.core, + org.wso2.carbon.event.stream.core.exception, + org.wso2.carbon.utils + + + + + + + + + + + diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapter.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapter.java new file mode 100644 index 000000000..4f2898795 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapter.java @@ -0,0 +1,455 @@ +/* + * + * 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.output.adapter.ui; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.databridge.commons.Attribute; +import org.wso2.carbon.databridge.commons.Event; +import org.wso2.carbon.databridge.commons.StreamDefinition; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.internal.UIEventAdaptorServiceDataHolder; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.util.UIEventAdapterConstants; +import org.wso2.carbon.event.output.adapter.core.EventAdapterUtil; +import org.wso2.carbon.event.output.adapter.core.OutputEventAdapter; +import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; +import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; +import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterRuntimeException; +import org.wso2.carbon.event.output.adapter.core.exception.TestConnectionNotSupportedException; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.util.WebSocketSessionUtil; +import org.wso2.carbon.event.stream.core.EventStreamService; +import org.wso2.carbon.event.stream.core.exception.EventStreamConfigurationException; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * Contains the life cycle of executions regarding the UI Adapter + */ + +public class UIEventAdapter implements OutputEventAdapter { + + private static final Log log = LogFactory.getLog(UIEventAdapter.class); + private OutputEventAdapterConfiguration eventAdapterConfiguration; + private Map globalProperties; + private int queueSize; + private LinkedBlockingDeque streamSpecificEvents; + private static ThreadPoolExecutor executorService; + private int tenantId; + private boolean doLogDroppedMessage; + + private String streamId; + private List streamMetaAttributes; + private List streamCorrelationAttributes; + private List streamPayloadAttributes; + + public UIEventAdapter(OutputEventAdapterConfiguration eventAdapterConfiguration, Map globalProperties) { + this.eventAdapterConfiguration = eventAdapterConfiguration; + this.globalProperties = globalProperties; + this.doLogDroppedMessage = true; + } + + @Override + public void init() throws OutputEventAdapterException { + + tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + + //ExecutorService will be assigned if it is null + if (executorService == null) { + int minThread; + int maxThread; + long defaultKeepAliveTime; + int jobQueSize; + + //If global properties are available those will be assigned else constant values will be assigned + if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { + minThread = Integer.parseInt(globalProperties.get( + UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); + } else { + minThread = UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; + } + + if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { + maxThread = Integer.parseInt(globalProperties.get( + UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); + } else { + maxThread = UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; + } + + if (globalProperties.get(UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { + defaultKeepAliveTime = Integer.parseInt(globalProperties.get( + UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); + } else { + defaultKeepAliveTime = UIEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; + } + + if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { + jobQueSize = Integer.parseInt(globalProperties.get( + UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); + } else { + jobQueSize = UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; + } + + executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(jobQueSize)); + } + + streamId = eventAdapterConfiguration.getOutputStreamIdOfWso2eventMessageFormat(); + if (streamId == null || streamId.isEmpty()) { + throw new OutputEventAdapterRuntimeException("UI event adapter needs a output stream id"); + } + + // fetch the "streamDefinition" corresponding to the "streamId" and then fetch the different attribute types + // of the streamDefinition corresponding to the event's streamId. They are required when validating values in + // the events against the streamDef attributes. + StreamDefinition streamDefinition = getStreamDefinition(streamId); + streamMetaAttributes = streamDefinition.getMetaData(); + streamCorrelationAttributes = streamDefinition.getCorrelationData(); + streamPayloadAttributes = streamDefinition.getPayloadData(); + + ConcurrentHashMap> tenantSpecifcEventOutputAdapterMap = + UIEventAdaptorServiceDataHolder.getTenantSpecificOutputEventStreamAdapterMap(); + + ConcurrentHashMap streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); + + if (streamSpecifAdapterMap == null) { + streamSpecifAdapterMap = new ConcurrentHashMap<>(); + if (null != tenantSpecifcEventOutputAdapterMap.putIfAbsent(tenantId, streamSpecifAdapterMap)) { + streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); + } + } + + String adapterName = streamSpecifAdapterMap.get(streamId); + + if (adapterName != null) { + throw new OutputEventAdapterException(("An Output ui event adapter \"" + adapterName + "\" is already" + + " exist for stream id \"" + streamId + "\"")); + } else { + streamSpecifAdapterMap.put(streamId, eventAdapterConfiguration.getName()); + + ConcurrentHashMap>> tenantSpecificStreamMap = + UIEventAdaptorServiceDataHolder.getTenantSpecificStreamEventMap(); + ConcurrentHashMap> streamSpecificEventsMap = + tenantSpecificStreamMap.get(tenantId); + if (streamSpecificEventsMap == null) { + streamSpecificEventsMap = new ConcurrentHashMap<>(); + if (null != tenantSpecificStreamMap.putIfAbsent(tenantId, streamSpecificEventsMap)) { + streamSpecificEventsMap = tenantSpecificStreamMap.get(tenantId); + } + } + streamSpecificEvents = streamSpecificEventsMap.get(streamId); + if (streamSpecificEvents == null) { + streamSpecificEvents = new LinkedBlockingDeque<>(); + if (null != streamSpecificEventsMap.putIfAbsent(streamId, streamSpecificEvents)) { + streamSpecificEvents = streamSpecificEventsMap.get(streamId); + } + } + } + + if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME) != null) { + try { + queueSize = Integer.parseInt( + globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME)); + } catch (NumberFormatException e) { + log.error("String does not have the appropriate format for conversion." + e.getMessage()); + queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; + } + } else { + queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; + } + } + + @Override + public void testConnect() throws TestConnectionNotSupportedException { + throw new TestConnectionNotSupportedException("Test connection is not available"); + } + + @Override + public void connect() { + //Not needed + } + + @Override + public void publish(Object message, Map dynamicProperties) { + + Event event = (Event) message; + StringBuilder eventBuilder = new StringBuilder("["); + + if (streamSpecificEvents.size() == queueSize) { + streamSpecificEvents.removeFirst(); + } + + eventBuilder.append(event.getTimeStamp()); + + if (event.getMetaData() != null) { + eventBuilder.append(","); + Object[] metaData = event.getMetaData(); + for (int i = 0; i < metaData.length; i++) { + eventBuilder.append("\""); + eventBuilder.append(metaData[i]); + eventBuilder.append("\""); + if (i != (metaData.length - 1)) { + eventBuilder.append(","); + } + } + } + + if (event.getCorrelationData() != null) { + Object[] correlationData = event.getCorrelationData(); + + eventBuilder.append(","); + + for (int i = 0; i < correlationData.length; i++) { + eventBuilder.append("\""); + eventBuilder.append(correlationData[i]); + eventBuilder.append("\""); + if (i != (correlationData.length - 1)) { + eventBuilder.append(","); + } + } + } + + if (event.getPayloadData() != null) { + Object[] payloadData = event.getPayloadData(); + eventBuilder.append(","); + for (int i = 0; i < payloadData.length; i++) { + eventBuilder.append("\""); + eventBuilder.append(payloadData[i]); + eventBuilder.append("\""); + if (i != (payloadData.length - 1)) { + eventBuilder.append(","); + } + } + } + + eventBuilder.append("]"); + String eventString = eventBuilder.toString(); + Object[] eventValues = new Object[UIEventAdapterConstants.INDEX_TWO]; + eventValues[UIEventAdapterConstants.INDEX_ZERO] = eventString; + eventValues[UIEventAdapterConstants.INDEX_ONE] = System.currentTimeMillis(); + streamSpecificEvents.add(eventValues); + + // fetch all valid sessions checked against any queryParameters provided when subscribing. + CopyOnWriteArrayList validSessions = getValidSessions(event); + + try { + executorService.execute(new WebSocketSender(validSessions, eventString)); + } catch (RejectedExecutionException e) { + EventAdapterUtil.logAndDrop(eventAdapterConfiguration.getName(), message, "Job queue is full", e, log, + tenantId); + } + + } + + @Override + public void disconnect() { + //Not needed + } + + @Override + public void destroy() { + + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + + ConcurrentHashMap tenantSpecificAdapterMap = UIEventAdaptorServiceDataHolder + .getTenantSpecificOutputEventStreamAdapterMap().get(tenantId); + if (tenantSpecificAdapterMap != null && streamId != null) { + tenantSpecificAdapterMap.remove(streamId); //Removing outputadapter and streamId + } + + ConcurrentHashMap> tenantSpecificStreamEventMap = + UIEventAdaptorServiceDataHolder.getTenantSpecificStreamEventMap().get(tenantId); + if (tenantSpecificStreamEventMap != null && streamId != null) { + //Removing the streamId and events registered for the output adapter + tenantSpecificStreamEventMap.remove(streamId); + } + } + + @Override + public boolean isPolled() { + return true; + } + + /** + * Fetch the StreamDefinition corresponding to the given StreamId from the EventStreamService. + * + * @param streamId the streamId of this UIEventAdaptor. + * @return the "StreamDefinition" object corresponding to the streamId of this EventAdaptor. + * @throws OutputEventAdapterException if the "EventStreamService" OSGI service is unavailable/unregistered or if + * the matching Steam-Definition for the given StreamId cannot be retrieved. + */ + private StreamDefinition getStreamDefinition(String streamId) throws OutputEventAdapterException { + EventStreamService eventStreamService = UIEventAdaptorServiceDataHolder.getEventStreamService(); + if (eventStreamService != null) { + try { + return eventStreamService.getStreamDefinition(streamId); + } catch (EventStreamConfigurationException e) { + String adaptorType = eventAdapterConfiguration.getType(); + String adaptorName = eventAdapterConfiguration.getName(); + String errorMsg = "Error while retrieving Stream-Definition for Stream with id [" + streamId + "] " + + "for Adaptor [" + adaptorName + "] of type [" + adaptorType + "]."; + log.error(errorMsg); + throw new OutputEventAdapterException(errorMsg, e); + } + } + throw new OutputEventAdapterException( + "Could not retrieve the EventStreamService whilst trying to fetch the Stream-Definition of Stream " + + "with Id [" + streamId + "]."); + } + + /** + * Fetches all valid web-socket sessions from the entire pool of subscribed sessions. The validity is checked + * against any queryString provided when subscribing to the web-socket endpoint. + * + * @param event the current event received and that which needs to be published to subscribed sessions. + * @return a list of all validated web-socket sessions against the queryString values. + */ + private CopyOnWriteArrayList getValidSessions(Event event) { + CopyOnWriteArrayList validSessions = new CopyOnWriteArrayList<>(); + UIOutputCallbackControllerServiceImpl uiOutputCallbackControllerServiceImpl = + UIEventAdaptorServiceDataHolder.getUIOutputCallbackRegisterServiceImpl(); + // get all subscribed web-socket sessions. + CopyOnWriteArrayList webSocketSessionUtils = + uiOutputCallbackControllerServiceImpl.getSessions(tenantId, streamId); + if (webSocketSessionUtils != null) { + for (WebSocketSessionUtil webSocketSessionUtil : webSocketSessionUtils) { + boolean isValidSession = validateEventAgainstSessionFilters(event, webSocketSessionUtil); + if (isValidSession) { + validSessions.add(webSocketSessionUtil); + } + } + } + return validSessions; + } + + + /** + * Processes the given session's validity to receive the current "event" against any queryParams that was used at + * the time when the web-socket-session is subscribed. This method can be extended to validate the event against + * any additional attribute of the given session too. + * + * @param event the current event received and that which needs to be published to subscribed + * sessions. + * @param webSocketSessionUtil the session which needs validated for its authenticity to receive this event. + * @return "true" if the session is valid to receive the event else "false". + */ + private boolean validateEventAgainstSessionFilters(Event event, WebSocketSessionUtil webSocketSessionUtil) { + + // fetch the queryString Key:Value pair map of the given session. + Map queryParamValuePairs = webSocketSessionUtil.getQueryParamValuePairs(); + if (queryParamValuePairs != null) { + // fetch the different attribute values received as part of the current event. + Object[] eventMetaData = event.getMetaData(); + Object[] eventCorrelationData = event.getCorrelationData(); + Object[] eventPayloadData = event.getPayloadData(); + + if (streamMetaAttributes != null) { + for (int i = 0; i < streamMetaAttributes.size(); i++) { + String attributeName = streamMetaAttributes.get(i).getName(); + String queryValue = queryParamValuePairs.get(attributeName); + + if (queryValue != null && + (eventMetaData == null || !eventMetaData[i].toString().equals(queryValue))) { + return false; + } + } + } + + if (streamCorrelationAttributes != null) { + for (int i = 0; i < streamCorrelationAttributes.size(); i++) { + String attributeName = streamCorrelationAttributes.get(i).getName(); + String queryValue = queryParamValuePairs.get(attributeName); + + if (queryValue != null && + (eventCorrelationData == null || !eventCorrelationData[i].toString().equals(queryValue))) { + return false; + } + } + } + + if (streamPayloadAttributes != null) { + for (int i = 0; i < streamPayloadAttributes.size(); i++) { + String attributeName = streamPayloadAttributes.get(i).getName(); + String queryValue = queryParamValuePairs.get(attributeName); + + if (queryValue != null && (eventPayloadData == null || !eventPayloadData[i].toString().equals( + queryValue))) { + return false; + } + } + } + } + return true; + } + + private class WebSocketSender implements Runnable { + + private String message; + private CopyOnWriteArrayList webSocketSessionUtils; + + public WebSocketSender(CopyOnWriteArrayList webSocketSessionUtils, String message) { + this.webSocketSessionUtils = webSocketSessionUtils; + this.message = message; + } + + /** + * When an object implementing interface Runnable is used + * to create a thread, starting the thread causes the object's + * run method to be called in that separately executing + * thread. + *

+ * The general contract of the method run is that it may + * take any action whatsoever. + * + * @see Thread#run() + */ + @Override + public void run() { + if (webSocketSessionUtils != null) { + doLogDroppedMessage = true; + for (WebSocketSessionUtil webSocketSessionUtil : webSocketSessionUtils) { + synchronized (WebSocketSessionUtil.class) { + try { + webSocketSessionUtil.getSession().getBasicRemote().sendText(message); + } catch (IOException e) { + EventAdapterUtil.logAndDrop(eventAdapterConfiguration.getName(), message, + "Cannot send to endpoint", e, log, tenantId); + } + } + } + } else if (doLogDroppedMessage) { + EventAdapterUtil.logAndDrop(eventAdapterConfiguration.getName(), message, "No clients registered", log, + tenantId); + doLogDroppedMessage = false; + } + } + } +} + diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapterFactory.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapterFactory.java new file mode 100644 index 000000000..809518ce2 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapterFactory.java @@ -0,0 +1,81 @@ +/* + * + * 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.output.adapter.ui; + +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.util.UIEventAdapterConstants; +import org.wso2.carbon.event.output.adapter.core.MessageType; +import org.wso2.carbon.event.output.adapter.core.OutputEventAdapter; +import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; +import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterFactory; +import org.wso2.carbon.event.output.adapter.core.Property; +import org.wso2.carbon.utils.CarbonUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; + +/** + * The UI event adapter factory class to create a UI output adapter + */ +public class UIEventAdapterFactory extends OutputEventAdapterFactory { + + private ResourceBundle resourceBundle = ResourceBundle.getBundle("org.wso2.carbon.device.mgt.iot.output.adapter.ui.i18n" + + ".Resources", Locale.getDefault()); + + public UIEventAdapterFactory() { + } + + @Override + public String getType() { + return UIEventAdapterConstants.ADAPTER_TYPE_UI; + } + + @Override + public List getSupportedMessageFormats() { + List supportedMessageFormats = new ArrayList(); + supportedMessageFormats.add(MessageType.WSO2EVENT); + return supportedMessageFormats; + } + + @Override + public List getStaticPropertyList() { + return null; + } + + @Override + public List getDynamicPropertyList() { + return null; + } + + @Override + public String getUsageTips() { + return resourceBundle.getString(UIEventAdapterConstants.ADAPTER_USAGE_TIPS_PREFIX) + " " + + resourceBundle.getString(UIEventAdapterConstants.ADAPTER_USAGE_TIPS_POSTFIX); + } + + @Override + public OutputEventAdapter createEventAdapter(OutputEventAdapterConfiguration eventAdapterConfiguration, + Map globalProperties) { + return new UIEventAdapter(eventAdapterConfiguration, globalProperties); + } + +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIOutputCallbackControllerService.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIOutputCallbackControllerService.java new file mode 100644 index 000000000..74cb77ddf --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIOutputCallbackControllerService.java @@ -0,0 +1,50 @@ +/* + * + * 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.output.adapter.ui; + +import javax.websocket.Session; + +/** + * This interface is exposed as an OSGI service, which will be invoked by the local websocket endpoint to inform new subscriptions; and do un-subscriptions.. + */ +public interface UIOutputCallbackControllerService { + + /** + * Used to subscribe the session id and stream id for later web socket connectivity + * + * @param streamName - Stream name which user register to. + * @param version - Stream version which user uses. + * @param session - Session which user registered. + * @return + */ + void subscribeWebsocket(String streamName, String version, Session session); + + /** + * Used to return events per streamId + * + * @param streamName - Stream name which user register to. + * @param version - Stream version which user uses. + * @param session - Session which user subscribed to. + * @return the events list. + */ + void unsubscribeWebsocket(String streamName, String version, Session session); + +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIOutputCallbackControllerServiceImpl.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIOutputCallbackControllerServiceImpl.java new file mode 100644 index 000000000..0c9602033 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIOutputCallbackControllerServiceImpl.java @@ -0,0 +1,149 @@ +/* + * + * 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.output.adapter.ui; + +import com.google.gson.JsonObject; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.internal.UIEventAdaptorServiceDataHolder; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.util.WebSocketSessionUtil; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.util.UIEventAdapterConstants; + +import javax.websocket.Session; +import java.util.Iterator; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.LinkedBlockingDeque; + +/** + * Service implementation class which exposes to front end + */ +public class UIOutputCallbackControllerServiceImpl implements UIOutputCallbackControllerService { + + private ConcurrentHashMap>> + outputEventAdaptorSessionMap; + + public UIOutputCallbackControllerServiceImpl() { + outputEventAdaptorSessionMap = new ConcurrentHashMap<>(); + } + + /** + * Used to subscribe the session id and stream id for later web socket connectivity + * + * @param streamName - Stream name which user register to. + * @param version - Stream version which user uses. + * @param session - Session which user registered. + */ + public void subscribeWebsocket(String streamName, String version, Session session) { + + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + + if (version == null || " ".equals(version)) { + version = UIEventAdapterConstants.ADAPTER_UI_DEFAULT_OUTPUT_STREAM_VERSION; + } + String streamId = streamName + UIEventAdapterConstants.ADAPTER_UI_COLON + version; + ConcurrentHashMap> tenantSpecificAdaptorMap = + outputEventAdaptorSessionMap.get(tenantId); + if (tenantSpecificAdaptorMap == null) { + tenantSpecificAdaptorMap = new ConcurrentHashMap<>(); + if (null != outputEventAdaptorSessionMap.putIfAbsent(tenantId, tenantSpecificAdaptorMap)) { + tenantSpecificAdaptorMap = outputEventAdaptorSessionMap.get(tenantId); + } + } + CopyOnWriteArrayList adapterSpecificSessions = tenantSpecificAdaptorMap.get(streamId); + if (adapterSpecificSessions == null) { + adapterSpecificSessions = new CopyOnWriteArrayList<>(); + if (null != tenantSpecificAdaptorMap.putIfAbsent(streamId, adapterSpecificSessions)) { + adapterSpecificSessions = tenantSpecificAdaptorMap.get(streamId); + } + } + + WebSocketSessionUtil webSocketSessionUtil = new WebSocketSessionUtil(session); + adapterSpecificSessions.add(webSocketSessionUtil); + } + + /** + * Used to return registered sessions per streamId + * + * @param tenantId - Tenant id of the user. + * @param streamId - Stream name and version which user register to. + * @return the sessions list. + */ + public CopyOnWriteArrayList getSessions(int tenantId, String streamId) { + ConcurrentHashMap> tenantSpecificAdaptorMap + = outputEventAdaptorSessionMap.get(tenantId); + if (tenantSpecificAdaptorMap != null) { + return tenantSpecificAdaptorMap.get(streamId); + } + return null; + } + + /** + * Used to return events per streamId + * + * @param tenanId - Tenant id of the user. + * @param streamName - Stream name which user register to. + * @param version - Stream version which user uses. + * @return the events list. + */ + public LinkedBlockingDeque getEvents(int tenanId, String streamName, String version) { + ConcurrentHashMap> tenantSpecificStreamMap = + UIEventAdaptorServiceDataHolder.getTenantSpecificStreamEventMap().get(tenanId); + if (tenantSpecificStreamMap != null) { + String streamId = streamName + UIEventAdapterConstants.ADAPTER_UI_COLON + version; + return tenantSpecificStreamMap.get(streamId); + } + return null; + } + + /** + * Used to return events per streamId + * + * @param streamName - Stream name which user register to. + * @param version - Stream version which user uses. + * @param session - Session which user subscribed to. + */ + public void unsubscribeWebsocket(String streamName, String version, Session session) { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + if (version == null || " ".equals(version)) { + version = UIEventAdapterConstants.ADAPTER_UI_DEFAULT_OUTPUT_STREAM_VERSION; + } + String id = streamName + UIEventAdapterConstants.ADAPTER_UI_COLON + version; + ConcurrentHashMap> tenantSpecificAdaptorMap + = outputEventAdaptorSessionMap.get(tenantId); + if (tenantSpecificAdaptorMap != null) { + CopyOnWriteArrayList adapterSpecificSessions = tenantSpecificAdaptorMap.get(id); + if (adapterSpecificSessions != null) { + WebSocketSessionUtil sessionToRemove = null; + Iterator iterator = adapterSpecificSessions.iterator(); + while (iterator.hasNext()) { + WebSocketSessionUtil webSocketSessionUtil = iterator.next(); + if (session.getId().equals(webSocketSessionUtil.getSession().getId())) { + sessionToRemove = webSocketSessionUtil; + break; + } + } + if (sessionToRemove != null) { + adapterSpecificSessions.remove(sessionToRemove); + } + } + } + } + +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/internal/UIEventAdaptorServiceDataHolder.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/internal/UIEventAdaptorServiceDataHolder.java new file mode 100644 index 000000000..dd0894985 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/internal/UIEventAdaptorServiceDataHolder.java @@ -0,0 +1,67 @@ +/* + * + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.iot.output.adapter.ui.internal; + +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIOutputCallbackControllerServiceImpl; +import org.wso2.carbon.event.stream.core.EventStreamService; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingDeque; + +/** + * Creates a holder of type UIOutputCallbackRegisterServiceImpl. + */ +public final class UIEventAdaptorServiceDataHolder { + + private static UIOutputCallbackControllerServiceImpl UIOutputCallbackRegisterServiceImpl; + private static ConcurrentHashMap> + tenantSpecificOutputEventStreamAdapterMap = new ConcurrentHashMap>(); + private static ConcurrentHashMap>> + tenantSpecificStreamEventMap = new ConcurrentHashMap>>(); + private static EventStreamService eventStreamService; + + public static void registerEventStreamService(EventStreamService eventBuilderService) { + UIEventAdaptorServiceDataHolder.eventStreamService = eventBuilderService; + } + + public static EventStreamService getEventStreamService() { + return UIEventAdaptorServiceDataHolder.eventStreamService; + } + + public static void registerUIOutputCallbackRegisterServiceInternal( + UIOutputCallbackControllerServiceImpl UIOutputCallbackRegisterServiceImpl) { + UIEventAdaptorServiceDataHolder.UIOutputCallbackRegisterServiceImpl = + UIOutputCallbackRegisterServiceImpl; + } + + public static UIOutputCallbackControllerServiceImpl getUIOutputCallbackRegisterServiceImpl() { + return UIEventAdaptorServiceDataHolder.UIOutputCallbackRegisterServiceImpl; + } + + public static ConcurrentHashMap> + getTenantSpecificOutputEventStreamAdapterMap() { + return tenantSpecificOutputEventStreamAdapterMap; + } + + public static ConcurrentHashMap>> + getTenantSpecificStreamEventMap() { + return tenantSpecificStreamEventMap; + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/internal/UILocalEventAdapterServiceComponent.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/internal/UILocalEventAdapterServiceComponent.java new file mode 100644 index 000000000..341d4b377 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/internal/UILocalEventAdapterServiceComponent.java @@ -0,0 +1,79 @@ +/* + * + * 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.output.adapter.ui.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIEventAdapterFactory; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIOutputCallbackControllerServiceImpl; +import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterFactory; +import org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIOutputCallbackControllerService; +import org.wso2.carbon.event.stream.core.EventStreamService; + +/** + * @scr.component component.name="output.extensions.Ui.AdapterService.component" immediate="true" + * @scr.reference name="eventStreamService.service" + * interface="org.wso2.carbon.event.stream.core.EventStreamService" cardinality="1..1" + * policy="dynamic" bind="setEventStreamService" unbind="unsetEventStreamService" + */ +public class UILocalEventAdapterServiceComponent { + + private static final Log log = LogFactory.getLog(UILocalEventAdapterServiceComponent.class); + + /** + * initialize the ui adapter service here service here. + * + * @param context + */ + protected void activate(ComponentContext context) { + + try { + OutputEventAdapterFactory uiEventAdapterFactory = new UIEventAdapterFactory(); + context.getBundleContext().registerService(OutputEventAdapterFactory.class.getName(), uiEventAdapterFactory, null); + UIOutputCallbackControllerServiceImpl UIOutputCallbackRegisterServiceImpl = + new UIOutputCallbackControllerServiceImpl(); + context.getBundleContext().registerService(UIOutputCallbackControllerService.class.getName(), + UIOutputCallbackRegisterServiceImpl, null); + + UIEventAdaptorServiceDataHolder.registerUIOutputCallbackRegisterServiceInternal( + UIOutputCallbackRegisterServiceImpl); + if (log.isDebugEnabled()) { + log.debug("Successfully deployed the output ui adapter service"); + } + } catch (RuntimeException e) { + log.error("Can not create the output ui adapter service ", e); + } + } + + protected void setEventStreamService(EventStreamService eventStreamService) { + if (log.isDebugEnabled()) { + log.debug("Setting the EventStreamService reference for the UILocalEventAdaptor Service"); + } + UIEventAdaptorServiceDataHolder.registerEventStreamService(eventStreamService); + } + + protected void unsetEventStreamService(EventStreamService eventStreamService) { + if (log.isDebugEnabled()) { + log.debug("Un-Setting the EventStreamService reference for the UILocalEventAdaptor Service"); + } + UIEventAdaptorServiceDataHolder.registerEventStreamService(null); + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/UIEventAdapterConstants.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/UIEventAdapterConstants.java new file mode 100644 index 000000000..8fdea199c --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/UIEventAdapterConstants.java @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2014-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.output.adapter.ui.util; + +/** + * This class contains the constants related to ui Output Event Adaptor. + */ +public class UIEventAdapterConstants { + + private UIEventAdapterConstants() { + } + + public static final String ADAPTER_TYPE_UI = "iot-ui"; + public static final String ADAPTER_USAGE_TIPS_PREFIX = "ui.usage.tips_prefix"; + public static final String ADAPTER_USAGE_TIPS_POSTFIX = "ui.usage.tips_postfix"; + public static final String ADAPTER_UI_DEFAULT_OUTPUT_STREAM_VERSION = "1.0.0"; + public static final String ADAPTER_UI_COLON = ":"; + public static final int INDEX_ZERO = 0; + public static final int INDEX_ONE = 1; + public static final int INDEX_TWO = 2; + + public static final int ADAPTER_MIN_THREAD_POOL_SIZE = 8; + public static final int ADAPTER_MAX_THREAD_POOL_SIZE = 100; + public static final int ADAPTER_EXECUTOR_JOB_QUEUE_SIZE = 2000; + public static final long DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS = 20000; + public static final String ADAPTER_MIN_THREAD_POOL_SIZE_NAME = "minThread"; + public static final String ADAPTER_MAX_THREAD_POOL_SIZE_NAME = "maxThread"; + public static final String ADAPTER_KEEP_ALIVE_TIME_NAME = "keepAliveTimeInMillis"; + public static final String ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME = "jobQueueSize"; + + public static final String ADAPTER_EVENT_QUEUE_SIZE_NAME = "eventQueueSize"; + public static final int EVENTS_QUEUE_SIZE = 30; + +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionUtil.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionUtil.java new file mode 100644 index 000000000..7c083f8f0 --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionUtil.java @@ -0,0 +1,62 @@ +package org.wso2.carbon.device.mgt.iot.output.adapter.ui.util; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.websocket.Session; +import java.util.HashMap; +import java.util.Map; + +/** + * This is wrapper class over the javax.websocket.Session implementation. This class contains additional attributes + * of the Session object derived from processing some of the (default) existing attributes. + * Ex: Query-String's [Key:Value] Map derived from the queryString attribute of the original class. + */ +public class WebSocketSessionUtil { + private static final Log log = LogFactory.getLog(WebSocketSessionUtil.class); + + private static final String QUERY_STRING_SEPERATOR = "&"; + private static final String QUERY_KEY_VALUE_SEPERATOR = "="; + private Map queryParamValuePairs = null; + private Session session; + + public WebSocketSessionUtil(Session session) { + this.session = session; + setQueryParamValuePairs(); + } + + public Map getQueryParamValuePairs() { + return queryParamValuePairs; + } + + public Session getSession() { + return session; + } + + /** + * Processes the queryString from the current instance's Session attribute and constructs a map of Query + * Key:Value pair. + */ + private void setQueryParamValuePairs() { + if (session.getQueryString() != null) { + String queryString = session.getQueryString(); + String[] allQueryParamPairs = queryString.split(QUERY_STRING_SEPERATOR); + + for (String keyValuePair : allQueryParamPairs) { + String[] thisQueryParamPair = keyValuePair.split(QUERY_KEY_VALUE_SEPERATOR); + + if (thisQueryParamPair.length != 2) { + log.warn("Invalid query string [" + queryString + "] passed in."); + break; + } + + if (queryParamValuePairs == null) { + queryParamValuePairs = new HashMap<>(); + } + + queryParamValuePairs.put(thisQueryParamPair[0], thisQueryParamPair[1]); + } + } + } +} diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/resources/org/wso2/carbon/device/mgt/iot/output/adapter/ui/i18n/Resources.properties b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/resources/org/wso2/carbon/device/mgt/iot/output/adapter/ui/i18n/Resources.properties new file mode 100644 index 000000000..4a3dcba8e --- /dev/null +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/resources/org/wso2/carbon/device/mgt/iot/output/adapter/ui/i18n/Resources.properties @@ -0,0 +1,22 @@ +# +# 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. +# + +output.event.stream.name=Output Stream Name +output.event.stream.version=Output Stream Version +ui.usage.tips_prefix=There must be an UI output adaptor for each stream to be visualized +ui.usage.tips_postfix= via Analytics Dashboard. diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml index e991fa1b6..484ceeff7 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.xmpp/pom.xml @@ -20,7 +20,7 @@ iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml index c404ad4e7..42f571d92 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/pom.xml @@ -18,14 +18,12 @@ ~ under the License. --> - + iot-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.hbs b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.hbs index db16f3d35..ca52690eb 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.hbs +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/operation-bar.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#if control_operations}}
+ {{css "css/styles.css"}} {{/zone}} {{#zone "bottomJs"}} diff --git a/components/iot-plugins/raspberrypi-plugin/pom.xml b/components/iot-plugins/raspberrypi-plugin/pom.xml index e4eaf7507..fe5172be0 100644 --- a/components/iot-plugins/raspberrypi-plugin/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml index 99bbf77db..032f71c8c 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/pom.xml @@ -17,15 +17,13 @@ ~ under the License. --> - + 4.0.0 virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml index f3287ab2d..112265de2 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml @@ -17,15 +17,13 @@ ~ under the License. --> - + 4.0.0 virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml index 291381f85..4f35de341 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml @@ -17,13 +17,11 @@ ~ under the License. --> - + virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml index d13a2e1ae..a76d313cc 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/pom.xml @@ -18,13 +18,12 @@ ~ under the License. --> - + virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -92,7 +91,7 @@ javax.xml.bind, javax.xml.bind.annotation, javax.xml.parsers, - org.w3c.dom + org.w3c.dom, !org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal, diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java index 557376624..96617f47b 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFireAlarmManager.java @@ -26,7 +26,7 @@ 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.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException; @@ -50,13 +50,13 @@ public class VirtualFireAlarmManager implements DeviceManager { } @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + public boolean saveConfiguration(PlatformConfiguration PlatformConfiguration) throws DeviceManagementException { return false; } @Override - public TenantConfiguration getConfiguration() throws DeviceManagementException { + public PlatformConfiguration getConfiguration() throws DeviceManagementException { return null; } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAOUtil.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAOUtil.java index a3ec4f274..109cbe243 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAOUtil.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/dao/VirtualFireAlarmDAOUtil.java @@ -45,7 +45,7 @@ public class VirtualFireAlarmDAOUtil { Context ctx = new InitialContext(); dataSource = (DataSource) ctx.lookup(VirtualFireAlarmConstants.DATA_SOURCE_NAME); } catch (NamingException e) { - log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME); + log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME, e); } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/DeviceSchemaInitializer.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/DeviceSchemaInitializer.java index 450014502..a738386af 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/DeviceSchemaInitializer.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/DeviceSchemaInitializer.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.dbcreator.DatabaseCreator; @@ -33,7 +34,8 @@ public class DeviceSchemaInitializer extends DatabaseCreator{ private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class); private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts" - + File.separator + "cdm" + File.separator + "plugins" + File.separator; + + File.separator + "cdm" + File.separator + "plugins" + File.separator + + VirtualFireAlarmConstants.DEVICE_TYPE + File.separator; public DeviceSchemaInitializer(DataSource dataSource) { super(dataSource); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java index 16189c263..49bbe1982 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java @@ -100,12 +100,11 @@ public class VirtualFireAlarmUtils { try { Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(VirtualFireAlarmConstants.DATA_SOURCE_NAME); - DeviceSchemaInitializer initializer = - new DeviceSchemaInitializer(dataSource); + DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource); log.info("Initializing device management repository database schema"); initializer.createRegistryDatabase(); } catch (NamingException e) { - log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME); + log.error("Error while looking up the data source: " + VirtualFireAlarmConstants.DATA_SOURCE_NAME, e); } catch (Exception e) { throw new VirtualFirealarmDeviceMgtPluginException("Error occurred while initializing Iot Device " + "Management database schema", e); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml index af055e14d..57589f893 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml @@ -17,13 +17,11 @@ ~ under the License. --> - + virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml index da6b1953f..8f9ff83a9 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml @@ -18,14 +18,12 @@ ~ under the License. --> - + virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.hbs b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.hbs index 202e3ec45..3493330bc 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.hbs +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.analytics-view/analytics-view.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.hbs b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.hbs index 644c1407c..01fd58063 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.hbs +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#zone "topCss"}} + {{css "css/styles.css"}} {{/zone}} {{#zone "bottomJs"}} {{js "/js/download.js"}} {{js "/js/jquery.validate.js"}} -{{/zone}} +{{/zone}} \ No newline at end of file diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml index 613c9b81f..f4c22aec2 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins iot-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index f1a1d9f2d..d08016c5d 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -16,14 +16,12 @@ ~ under the License. --> - + android-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -48,7 +46,7 @@ 2.2 WEB-INF/lib/*cxf*.jar - ${project.artifactId} + mdm-android-agent @@ -74,7 +72,7 @@ - + @@ -165,13 +163,11 @@ org.wso2.carbon.device.mgt.mobile.android provided - commons-httpclient.wso2 commons-httpclient provided - io.swagger swagger-annotations @@ -182,5 +178,15 @@ com.google.code.gson gson + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.data.publisher + provided + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.api + provided + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java new file mode 100644 index 000000000..2c8d8c93d --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +/** + * This class represents information of configuring App Restriction ex: White list and Black list + */ +@ApiModel(value = "AppRestriction", + description = "This class carries all information related to application restriction.") +public class AppRestriction extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "restrictionType", value = "Restriction type of the application.", required = true) + private String restrictionType; + @ApiModelProperty(name = "restrictedList", value = "Device id list of the operation to be executed.", required = true) + private List restrictedList; + + public String getRestrictionType() { + return restrictionType; + } + + public void setRestrictionType(String restrictionType) { + this.restrictionType = restrictionType; + } + + public List getRestrictedList() { + return restrictedList; + } + + public void setRestrictedList(List restrictedList) { + this.restrictedList = restrictedList; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java new file mode 100644 index 000000000..f732f74a9 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * This class represents the information of Update application operation. + */ +@ApiModel(value = "ApplicationUpdate", + description = "This class carries all information related to application update.") +public class ApplicationUpdate extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "appIdentifier", value = "The package name of the application " + + "to be update.", required = true) + private String appIdentifier; + @ApiModelProperty(name = "type", value = "The type of the application. The following types of applications " + + "are supported: enterprise, public and webapp.", required = true) + private String type; + @ApiModelProperty(name = "url", value = "The URL of the application.", required = true) + private String url; + @ApiModelProperty(name = "schedule", value = "Application update schedule.", required = true) + private String schedule; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java new file mode 100644 index 000000000..5dc8b7904 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +@ApiModel(value = "DeviceLock", + description = "This class carries all information related to device lock operation.") +public class DeviceLock extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "message", value = "Pop up message of the lock operation.", required = true) + private String message; + @ApiModelProperty(name = "isHardLockEnabled", value = "Hard lock enable status of the Device", required = true) + private boolean isHardLockEnabled; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isHardLockEnabled() { + return isHardLockEnabled; + } + + public void setHardLockEnabled(boolean hardLockEnabled) { + isHardLockEnabled = hardLockEnabled; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java new file mode 100644 index 000000000..fb23b0fcc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@XmlRootElement +/** + * Store Device state event/data for androidDevice. + */ +@ApiModel(value = "DeviceState", + description = "This class carries all information related to device state.") +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeviceState { + + @XmlElementWrapper(required = true, name = "values") + @ApiModelProperty(name = "values", value = "Device and its statuses.", required = true) + private Map values; + + /** The id. */ + @XmlElement(required = false, name = "id") + @ApiModelProperty(name = "id", value = "Identification code.", required = true) + private String id; + + /** + * Gets the values. + * @return the values + */ + public Map getValues() { + return values; + } + + /** + * Sets the values. + * @param values the values + */ + public void setValues(Map values) { + this.values = values; + } + + /** + * Sets the id. + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the id. + * @return the id + */ + public String getId() { + return id; + } + + @Override + public String toString(){ + List valueList = new ArrayList(); + for (Map.Entry entry : values.entrySet()) { + valueList.add(entry.getKey() + ":" + entry.getValue()); + } + return valueList.toString(); + + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java new file mode 100644 index 000000000..fc3b5e08d --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * This class represents the information of sending Upgrade Firmware operation. + */ +@ApiModel(value = "UpgradeFirmware", + description = "This class carries all information related to UpgradeFirmware.") +public class UpgradeFirmware extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.") + private String schedule; + + @ApiModelProperty(name = "server", value = "Firmware package server.") + private String server; + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } + + public String getServer() { + return server; + } + + public void setServer(String server) { + this.server = server; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java new file mode 100644 index 000000000..188d44f8f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java @@ -0,0 +1,73 @@ +/* + * 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.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * This class represents the information of configuring VPN operation. + */ +@ApiModel(value = "Vpn", + description = "This class carries all information related to VPN.") +public class Vpn extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "serverAddress", value = "Server Address.", required = true) + private String serverAddress; + @ApiModelProperty(name = "serverPort", value = "Server Port.", required = true) + private String serverPort; + @ApiModelProperty(name = "sharedSecret", value = "Shared secret.", required = true) + private String sharedSecret; + @ApiModelProperty(name = "dnsServer", value = "DNS server.", required = true) + private String dnsServer; + + public String getServerAddress() { + return serverAddress; + } + + public void setServerAddress(String serverAddress) { + this.serverAddress = serverAddress; + } + + public String getServerPort() { + return serverPort; + } + + public void setServerPort(String serverPort) { + this.serverPort = serverPort; + } + + public String getSharedSecret() { + return sharedSecret; + } + + public void setSharedSecret(String sharedSecret) { + this.sharedSecret = sharedSecret; + } + + public String getDnsServer() { + return dnsServer; + } + + public void setDnsServer(String dnsServer) { + this.dnsServer = dnsServer; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java new file mode 100644 index 000000000..64412336e --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.AppRestriction; + +import java.util.List; + +/** + * This class is used to wrap AppRestriction bean with devices + */ +@ApiModel(value = "AppRestrictionBeanWrapper", + description = "Application Restriction related information.") +public class AppRestrictionBeanWrapper { + + @ApiModelProperty(name = "operation", value = "AppRestriction related information.", required = true) + private AppRestriction operation; + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + + public AppRestriction getOperation() { + return operation; + } + + public void setOperation(AppRestriction operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java new file mode 100644 index 000000000..b202bf883 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate; + +import java.util.List; + +/** + * This class is used to wrap the UpdateApplication bean with devices. + */ +@ApiModel(value = "ApplicationUpdateBeanWrapper", + description = "Application Update related Info.") +public class ApplicationUpdateBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Application Update related information.", required = true) + private ApplicationUpdate operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public ApplicationUpdate getOperation() { + return operation; + } + + public void setOperation(ApplicationUpdate operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java new file mode 100644 index 000000000..5811c3102 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.DeviceLock; + +import java.util.List; + +/** + * This class is used to wrap the Notification bean with devices. + */ +@ApiModel(value = "DeviceLockBeanWrapper", + description = "DeviceLock related Information.") +public class DeviceLockBeanWrapper { + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Information of the Device lock operation.", required = true) + private DeviceLock operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public DeviceLock getOperation() { + return operation; + } + + public void setOperation(DeviceLock operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java new file mode 100644 index 000000000..d8e21c8d4 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * This class is used to wrap the events which receive from the agent application. + */ +@ApiModel(value = "EventBeanWrapper", + description = "Android agent's event related Information.") +public class EventBeanWrapper { + @ApiModelProperty(name = "deviceIdentifier", value = "DeviceIdentifier to be need to retrieve/publish Event.", required = true) + private String deviceIdentifier; + @ApiModelProperty(name = "payload", value = "Event payload.", required = true) + private String payload; + @ApiModelProperty(name = "type", value = "Type of the event.", required = true) + private String type; + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public String getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(String deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java new file mode 100644 index 000000000..b881422c2 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * 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.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.UpgradeFirmware; + +import java.util.List; + +/** + * This class is used to wrap the UpgradeFirmware bean with devices. + */ +@ApiModel(value = "UpgradeFirmwareBeanWrapper", + description = "Information related to UpgradeFirmware.") +public class UpgradeFirmwareBeanWrapper { + @ApiModelProperty(name = "deviceIDs", + value = "List of device Ids to be need to execute UpgradeFirmware operation.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Information related to UpgradeFirmware operation.", required = true) + private UpgradeFirmware operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public UpgradeFirmware getOperation() { + return operation; + } + + public void setOperation(UpgradeFirmware operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java new file mode 100644 index 000000000..bfdbd43da --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.Vpn; + +import java.util.List; + +/** + * This class is used to wrap the Vpn bean with devices. + */ +@ApiModel(value = "VpnBeanWrapper", + description = "Information related to VPN Configuration.") +public class VpnBeanWrapper { + @ApiModelProperty(name = "operation", + value = "List of device Ids to be need to execute UpgradeFirmware operation.", required = true) + private Vpn operation; + @ApiModelProperty(name = "deviceIDs", + value = "List of device Ids to be need to execute VPN operation.", required = true) + private List deviceIDs; + + public Vpn getOperation() { + return operation; + } + + public void setOperation(Vpn operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java index 098a518bb..fb2edc239 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java @@ -31,7 +31,7 @@ import java.util.List; description = "Mapping between web clip operation and device list to be applied.") public class WebClipBeanWrapper { - @ApiModelProperty(name = "operation", value = "the information of setting up webclip", required = true) + @ApiModelProperty(name = "operation", value = "the information of setting up webclip.", required = true) private WebClip operation; @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) private List deviceIDs; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/ConfigurationMgtService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/ConfigurationMgtService.java index 3a378d9e7..c05579aaf 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/ConfigurationMgtService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/ConfigurationMgtService.java @@ -19,20 +19,17 @@ package org.wso2.carbon.mdm.services.android.services.configuration; import io.swagger.annotations.*; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; /** * Android Platform Configuration REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ @Api(value = "ConfigurationMgtService") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface ConfigurationMgtService { @@ -48,21 +45,21 @@ public interface ConfigurationMgtService { @ApiResponse(code = 201, message = "Android platform configuration saved successfully"), @ApiResponse(code = 500, message = "Internal Server Error") }) - Message configureSettings(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") - TenantConfiguration configuration) throws AndroidAgentException; + Response configureSettings(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") + PlatformConfiguration configuration) throws AndroidAgentException; @GET @ApiOperation( httpMethod = "GET", value = "Getting Android Platform Configurations", notes = "Get the Android platform configuration details using this REST API", - response = TenantConfiguration.class + response = PlatformConfiguration.class ) @ApiResponses(value = { @ApiResponse(code = 200, message = "Get Android Configurations"), @ApiResponse(code = 500, message = "Server Error") }) - TenantConfiguration getConfiguration() throws AndroidAgentException; + Response getConfiguration() throws AndroidAgentException; @PUT @ApiOperation( @@ -77,6 +74,6 @@ public interface ConfigurationMgtService { @ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " + "Android platform") }) - Message updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") - TenantConfiguration configuration) throws AndroidAgentException; + Response updateConfiguration(@ApiParam(name = "configuration", value = "AndroidPlatformConfiguration") + PlatformConfiguration configuration) throws AndroidAgentException; } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java index caf138e38..57f5d7693 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java @@ -23,15 +23,13 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtService; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; +import org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.ArrayList; @@ -41,14 +39,13 @@ import java.util.List; * Android Platform Configuration REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { private static Log log = LogFactory.getLog(ConfigurationMgtServiceImpl.class); @POST - public Message configureSettings(TenantConfiguration configuration) + public Response configureSettings(PlatformConfiguration configuration) throws AndroidAgentException { Message responseMsg = new Message(); @@ -82,24 +79,24 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } catch (DeviceManagementException e) { msg = "Error occurred while configuring the android platform"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; + return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } @GET - public TenantConfiguration getConfiguration() throws AndroidAgentException { + public Response getConfiguration() throws AndroidAgentException { String msg; - TenantConfiguration tenantConfiguration; + PlatformConfiguration PlatformConfiguration = null; List configs; try { - tenantConfiguration = AndroidAPIUtils.getDeviceManagementService(). + PlatformConfiguration = AndroidAPIUtils.getDeviceManagementService(). getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - if (tenantConfiguration != null) { - configs = tenantConfiguration.getConfiguration(); + if (PlatformConfiguration != null) { + configs = PlatformConfiguration.getConfiguration(); } else { - tenantConfiguration = new TenantConfiguration(); - configs = new ArrayList(); + PlatformConfiguration = new PlatformConfiguration(); + configs = new ArrayList<>(); } ConfigurationEntry entry = new ConfigurationEntry(); @@ -112,18 +109,18 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { entry.setName(AndroidConstants.TenantConfigProperties.LICENSE_KEY); entry.setValue(license.getText()); configs.add(entry); - tenantConfiguration.setConfiguration(configs); + PlatformConfiguration.setConfiguration(configs); } } catch (DeviceManagementException e) { msg = "Error occurred while retrieving the Android tenant configuration"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return tenantConfiguration; + return Response.status(Response.Status.OK).entity(PlatformConfiguration).build(); } @PUT - public Message updateConfiguration(TenantConfiguration configuration) throws AndroidAgentException { + public Response updateConfiguration(PlatformConfiguration configuration) throws AndroidAgentException { String msg; Message responseMsg = new Message(); ConfigurationEntry licenseEntry = null; @@ -148,15 +145,16 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } configuration.setConfiguration(configs); AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + //AndroidAPIUtils.getGCMService().resetTenantConfigCache(); Response.status(Response.Status.ACCEPTED); responseMsg.setResponseMessage("Android platform configuration has updated successfully."); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); } catch (DeviceManagementException e) { msg = "Error occurred while modifying configuration settings of Android platform"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; + return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/DeviceManagementService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/DeviceManagementService.java index f1b518c45..fc95711a7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/DeviceManagementService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/DeviceManagementService.java @@ -22,11 +22,9 @@ import io.swagger.annotations.*; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import java.util.List; /** @@ -35,7 +33,6 @@ import java.util.List; */ @Api(value = "DeviceManagementService", description = "Android Device Management REST-API implementation.") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface DeviceManagementService { @@ -62,7 +59,7 @@ public interface DeviceManagementService { @ApiResponse(code = 200, message = "List of Devices"), @ApiResponse(code = 500, message = "Error occurred while fetching the device list") }) - List getAllDevices() throws AndroidAgentException; + Response getAllDevices() throws AndroidAgentException; /** * Fetch Android device details of a given device Id. @@ -86,7 +83,7 @@ public interface DeviceManagementService { @ApiResponse(code = 200, message = "Information of the given device"), @ApiResponse(code = 500, message = "Error occurred while fetching the device information") }) - org.wso2.carbon.device.mgt.common.Device getDevice(@ApiParam(name = "id", value = "deviceIdentifier") + Response getDevice(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id) throws AndroidAgentException; /** @@ -110,7 +107,7 @@ public interface DeviceManagementService { @ApiResponse(code = 304, message = "Device not found for the update") }) @Path("{id}") - Message updateDevice(@ApiParam(name = "id", value = "deviceIdentifier") + Response updateDevice(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, @ApiParam(name = "device", value = "deviceIdentifier") Device device) throws AndroidAgentException; @@ -125,9 +122,9 @@ public interface DeviceManagementService { @ApiResponse(code = 202, message = "Device information has modified successfully"), @ApiResponse(code = 500, message = "Error occurred while modifying the application list") }) - Message updateApplicationList(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, + Response updateApplicationList(@ApiParam(name = "id", value = "deviceIdentifier") @PathParam("id") String id, @ApiParam(name = "applications", value = "updatable applications") - List applications); + List applications) throws AndroidAgentException; @GET @Path("license") @@ -144,5 +141,5 @@ public interface DeviceManagementService { @ApiResponse(code = 500, message = "Error occurred while retrieving the license configured for Android " + "device enrolment") }) - String getLicense() throws AndroidAgentException; + Response getLicense() throws AndroidAgentException; } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/impl/DeviceManagementServiceImpl.java index f1cb678df..06ccdf3e9 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/devicemgt/impl/DeviceManagementServiceImpl.java @@ -28,10 +28,9 @@ 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.license.mgt.License; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; +import org.wso2.carbon.mdm.services.android.services.devicemgt.DeviceManagementService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.List; @@ -40,10 +39,9 @@ import java.util.List; * Android Device Management REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) -public class DeviceManagementServiceImpl { +public class DeviceManagementServiceImpl implements DeviceManagementService { private static Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); @@ -54,7 +52,7 @@ public class DeviceManagementServiceImpl { * @throws AndroidAgentException */ @GET - public List getAllDevices() + public Response getAllDevices() throws AndroidAgentException { String msg; List devices; @@ -66,9 +64,9 @@ public class DeviceManagementServiceImpl { } catch (DeviceManagementException e) { msg = "Error occurred while fetching the device list."; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return devices; + return Response.status(Response.Status.OK).entity(devices).build(); } /** @@ -80,7 +78,7 @@ public class DeviceManagementServiceImpl { */ @GET @Path("{id}") - public Device getDevice(@PathParam("id") String id) + public Response getDevice(@PathParam("id") String id) throws AndroidAgentException { String msg; @@ -90,14 +88,14 @@ public class DeviceManagementServiceImpl { DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); if (device == null) { - Response.status(Response.Status.NOT_FOUND); + return Response.status(Response.Status.NOT_FOUND).build(); } } catch (DeviceManagementException deviceMgtEx) { msg = "Error occurred while fetching the device information."; log.error(msg, deviceMgtEx); - throw new AndroidAgentException(msg, deviceMgtEx); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return device; + return Response.status(Response.Status.OK).entity(device).build(); } /** @@ -110,7 +108,7 @@ public class DeviceManagementServiceImpl { */ @PUT @Path("{id}") - public Message updateDevice(@PathParam("id") String id, Device device) + public Response updateDevice(@PathParam("id") String id, Device device) throws AndroidAgentException { String msg; Message responseMessage = new Message(); @@ -124,23 +122,22 @@ public class DeviceManagementServiceImpl { result = AndroidAPIUtils.getDeviceManagementService() .updateDeviceInfo(deviceIdentifier, device); if (result) { - Response.status(Response.Status.ACCEPTED); responseMessage.setResponseMessage("Device information has modified successfully."); + return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); } else { - Response.status(Response.Status.NOT_MODIFIED); responseMessage.setResponseMessage("Device not found for the update."); + return Response.status(Response.Status.NOT_MODIFIED).entity(responseMessage).build(); } } catch (DeviceManagementException e) { msg = "Error occurred while modifying the device information."; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMessage; } @POST @Path("appList/{id}") - public Message updateApplicationList(@PathParam("id") String id, List applications) + public Response updateApplicationList(@PathParam("id") String id, List applications) throws AndroidAgentException { @@ -151,22 +148,20 @@ public class DeviceManagementServiceImpl { try { AndroidAPIUtils.getApplicationManagerService(). updateApplicationListInstalledInDevice(deviceIdentifier, applications); - Response.status(Response.Status.ACCEPTED); responseMessage.setResponseMessage("Device information has modified successfully."); - + return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while modifying the application list."; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMessage; } @GET @Path("license") @Produces("text/html") - public String getLicense() throws AndroidAgentException { - License license; + public Response getLicense() throws AndroidAgentException { + License license = null; try { license = @@ -176,9 +171,9 @@ public class DeviceManagementServiceImpl { } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving the license configured for Android device enrolment"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return (license == null) ? null : license.getText(); + return Response.status(Response.Status.OK).entity((license == null) ? null : license.getText()).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/EnrollmentService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/EnrollmentService.java index 6c6aa2e37..b150fd19d 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/EnrollmentService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/EnrollmentService.java @@ -20,11 +20,9 @@ package org.wso2.carbon.mdm.services.android.services.enrollment; import io.swagger.annotations.*; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; -import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; /** * Android Device Enrollment REST-API implementation. @@ -32,7 +30,6 @@ import javax.ws.rs.core.MediaType; */ @Api(value = "EnrollmentService", description = "Android Device Enrollment REST-API implementation.") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface EnrollmentService { @@ -51,7 +48,7 @@ public interface EnrollmentService { @ApiResponse(code = 201, message = "Device enrollment succeeded"), @ApiResponse(code = 500, message = "Device enrollment failed"), }) - Message enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") + Response enrollDevice(@ApiParam(name = "device", value = "Device Information to be enroll") org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException; @GET @@ -65,7 +62,7 @@ public interface EnrollmentService { @ApiResponse(code = 202, message = "Device has already enrolled"), @ApiResponse(code = 404, message = "Device not found") }) - Message isEnrolled(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) + Response isEnrolled(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) throws AndroidAgentException; @PUT @@ -79,7 +76,7 @@ public interface EnrollmentService { @ApiResponse(code = 202, message = "Device enrollment has updated successfully"), @ApiResponse(code = 404, message = "Device not found for enrollment") }) - Message modifyEnrollment(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id, + Response modifyEnrollment(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id, @ApiParam(name = "device", value = "Device information to be modify") org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException; @@ -95,6 +92,6 @@ public interface EnrollmentService { @ApiResponse(code = 404, message = "Device not found") }) @Path("{deviceId}") - Message disEnrollDevice(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) + Response disEnrollDevice(@ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) throws AndroidAgentException; } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/impl/EnrollmentServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/impl/EnrollmentServiceImpl.java index 328377047..cf8d295c0 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/impl/EnrollmentServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/enrollment/impl/EnrollmentServiceImpl.java @@ -27,8 +27,6 @@ import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; import org.wso2.carbon.mdm.services.android.services.enrollment.EnrollmentService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.Message; - -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.Response; @@ -36,7 +34,6 @@ import javax.ws.rs.core.Response; * Android Device Enrollment REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public class EnrollmentServiceImpl implements EnrollmentService { @@ -44,7 +41,7 @@ public class EnrollmentServiceImpl implements EnrollmentService { private static Log log = LogFactory.getLog(EnrollmentService.class); @POST - public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) + public Response enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { Message responseMsg = new Message(); @@ -56,23 +53,22 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (status) { Response.status(Response.Status.CREATED); responseMsg.setResponseMessage("Device enrollment succeeded."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); + return Response.status(Response.Status.CREATED).entity(responseMsg).build(); } else { Response.status(Response.Status.INTERNAL_SERVER_ERROR); responseMsg.setResponseMessage("Device enrollment failed."); - responseMsg.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMsg).build(); } } catch (DeviceManagementException e) { msg = "Error occurred while enrolling the device"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } @GET @Path("{deviceId}") - public Message isEnrolled(@PathParam("deviceId") String id) throws AndroidAgentException { + public Response isEnrolled(@PathParam("deviceId") String id) throws AndroidAgentException { String msg; boolean result; Message responseMsg = new Message(); @@ -83,11 +79,11 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (result) { responseMsg.setResponseMessage("Device has already enrolled"); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - Response.status(Response.Status.ACCEPTED); + return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); } else { responseMsg.setResponseMessage("Device not found"); responseMsg.setResponseCode(Response.Status.NOT_FOUND.toString()); - Response.status(Response.Status.NOT_FOUND); + return Response.status(Response.Status.NOT_FOUND).entity(responseMsg).build(); } } catch (DeviceManagementException e) { msg = "Error occurred while checking enrollment status of the device."; @@ -95,14 +91,13 @@ public class EnrollmentServiceImpl implements EnrollmentService { responseMsg.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); Response.status(Response.Status.INTERNAL_SERVER_ERROR); log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } @PUT @Path("{deviceId}") - public Message modifyEnrollment(@PathParam("deviceId") String id, + public Response modifyEnrollment(@PathParam("deviceId") String id, org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { String msg; @@ -114,23 +109,22 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (result) { responseMsg.setResponseMessage("Device enrollment has updated successfully"); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - Response.status(Response.Status.ACCEPTED); + return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); } else { responseMsg.setResponseMessage("Device not found for enrollment"); responseMsg.setResponseCode(Response.Status.NOT_MODIFIED.toString()); - Response.status(Response.Status.NOT_MODIFIED); + return Response.status(Response.Status.NOT_MODIFIED).entity(responseMsg).build(); } } catch (DeviceManagementException e) { msg = "Error occurred while modifying enrollment of the device"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } @DELETE @Path("{deviceId}") - public Message disEnrollDevice(@PathParam("deviceId") String id) throws AndroidAgentException { + public Response disEnrollDevice(@PathParam("deviceId") String id) throws AndroidAgentException { Message responseMsg = new Message(); boolean result; String msg; @@ -141,18 +135,17 @@ public class EnrollmentServiceImpl implements EnrollmentService { if (result) { responseMsg.setResponseMessage("Device has removed successfully"); responseMsg.setResponseCode(Response.Status.ACCEPTED.toString()); - Response.status(Response.Status.ACCEPTED); + return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build(); } else { responseMsg.setResponseMessage("Device not found"); responseMsg.setResponseCode(Response.Status.NOT_FOUND.toString()); - Response.status(Response.Status.NOT_FOUND); + return Response.status(Response.Status.NOT_FOUND).entity(responseMsg).build(); } } catch (DeviceManagementException e) { msg = "Error occurred while dis enrolling the device"; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } - return responseMsg; } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java new file mode 100644 index 000000000..6eb87f002 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.services.event; + +import io.swagger.annotations.*; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * APIs related to events published from Android agent are implemented here. + */ +@Api(value = "EventService", description = "Android Device Management REST-API implementation.") +public interface EventService { + String ACCEPT = "Accept"; + + @POST + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Event Publishing via REST API.", + notes = "Publish events received by the WSO2 EMM Android client to WSO2 DAS using this API." + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Event is published successfully."), + @ApiResponse(code = 500, message = "Error occurred while publishing the events from Android agent.") + }) + Response publishEvents(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "eventBeanWrapper", + value = "Information of the agent event to be published on DAS.") + EventBeanWrapper eventBeanWrapper); + + @GET + @Path("{deviceId}") + @Produces("application/json") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Event Details of a Device.", + notes = "Get the event details received by an Android device using this API.", + response = DeviceState.class, + responseContainer = "List" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "List of Device statuses."), + @ApiResponse(code = 500, + message = "Error occurred while getting published events for specific given device.") + }) + Response retrieveAlert(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "deviceId", value = "DeviceId which need to retrieve published events.") + @PathParam("deviceId") String deviceId); + + @GET + @Path("{deviceId}/date") + @Produces("application/json") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Event Details for a Given Time Period.", + notes = "Get the event details of a device for a given time duration using this API.", + response = DeviceState.class, + responseContainer = "List" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "event details of a device for a given time duration"), + @ApiResponse(code = 500, message = "Error occurred while getting published events for" + + " specific device on given Date.") + }) + Response retrieveAlertFromDate(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "deviceId", + value = "Device Identifier to be need to retrieve events.") + @PathParam("deviceId") String deviceId, + @ApiParam(name = "from", value = "From Date.") + @QueryParam("from") long from, + @ApiParam(name = "to", value = "To Date.") + @QueryParam("to") long to); + + @GET + @Path("{deviceId}/type/{type}") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Event Details for a Given Time Period.", + notes = "Get the event details of a device for a given time duration using this API.", + response = DeviceState.class, + responseContainer = "List" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "event details of a device for a given time duration"), + @ApiResponse(code = 500, message = "Error occurred while getting published events for" + + " specific device on given Date.") + }) + Response retrieveAlertType(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "deviceId", value = "Device Identifier to be need to retrieve events.") + @PathParam("deviceId") String deviceId, + @ApiParam(name = "type", value = "Type of the Alert to be need to retrieve events.") + @PathParam("type") String type); +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java new file mode 100644 index 000000000..00f9f9759 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.services.event.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; +import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; +import org.wso2.carbon.mdm.services.android.services.event.EventService; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.util.Message; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +public class EventServiceImpl implements EventService { + + private static final String ACCEPT = "Accept"; + private static Log log = LogFactory.getLog(EventService.class); + private static final String EVENT_STREAM_DEFINITION = "android_agent"; + + @POST + public Response publishEvents(@HeaderParam(ACCEPT) String acceptHeader, + EventBeanWrapper eventBeanWrapper) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android device even logging."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + + Object payload[] = {eventBeanWrapper.getDeviceIdentifier(), eventBeanWrapper.getPayload(), + eventBeanWrapper.getType()}; + try { + if (AndroidAPIUtils.getEventPublisherService().publishEvent( + EVENT_STREAM_DEFINITION, "1.0.0", new Object[0], new Object[0], payload)) { + message.setResponseCode("Event is published successfully."); + return Response.status(Response.Status.CREATED).entity(message).type(responseMediaType).build(); + } else { + message.setResponseCode("Error occurred while publishing the event."); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR). + entity(message).type(responseMediaType).build(); + } + } catch (DataPublisherConfigurationException e) { + String msg = "Error occurred while publishing the events from Android agent."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); + } + } + + @Path("{deviceId}") + @Produces("application/json") + @GET + public Response retrieveAlert(@HeaderParam(ACCEPT) String acceptHeader, + @PathParam("deviceId") String deviceId) { + + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device Identifier."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + String query = "deviceIdentifier:" + deviceId; + List deviceStates; + try { + deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + message.setResponseCode("No any alerts are published for Device: " + deviceId + "."); + return Response.status(Response.Status.OK).entity(message).type(responseMediaType).build(); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + "."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); + } + } + + @Path("{deviceId}/date") + @Produces("application/json") + @GET + public Response retrieveAlertFromDate(@HeaderParam(ACCEPT) String acceptHeader, + @PathParam("deviceId") String deviceId, @QueryParam("from") long from, + @QueryParam("to") long to) { + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device Identifier and time period."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + + String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; + List deviceStates; + try { + deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + message. + setResponseCode("No any alerts are published on given date for given Device: " + deviceId + "."); + return Response.status(Response.Status.OK).entity(message).build(); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + " on given Date."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); + } + } + + @Path("{deviceId}/type/{type}") + @GET + public Response retrieveAlertType(@HeaderParam(ACCEPT) String acceptHeader, + @PathParam("deviceId") String deviceId, @PathParam("type") String type) { + + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device identifier and type."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + String query = "deviceIdentifier:" + deviceId + " AND type:" + type; + List deviceStates; + try { + deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + message.setResponseCode("No any alerts are published for given Device: " + + deviceId + " on specific date."); + return Response.status(Response.Status.OK).entity(message).build(); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + "and given device Type."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); + } + + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/OperationMgtService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/OperationMgtService.java index ece87536c..0eec30f25 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/OperationMgtService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/OperationMgtService.java @@ -50,7 +50,7 @@ public interface OperationMgtService { @ApiResponse(code = 200, message = "List of pending operations"), @ApiResponse(code = 500, message = "Issue in retrieving operation management service instance") }) - List getPendingOperations( + Response getPendingOperations( @ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "id", value = "DeviceIdentifier") @PathParam("id") String id, @ApiParam(name = "resultOperations", value = "Device Operation Status") @@ -62,17 +62,34 @@ public interface OperationMgtService { consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Adding a Device Lock on Android Devices", - responseContainer = "List", notes = "Using this API you have the option of hard locking an Android device, where the Administrator " + - "permanently locks the device or screen locking an Android device", + "permanently locks the device or screen locking an Android device" + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response configureDeviceLock(@ApiParam(name = "acceptHeader", value = "Accept Header") + @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "cameraBeanWrapper", + value = "Device lock configurations with device IDs") DeviceLockBeanWrapper deviceLockBeanWrapper); + + @POST + @Path("unlock") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Adding a Device Unlock on Android Devices", + responseContainer = "List", + notes = "Using this API you have the option of unlocking an Android device, where the Administrator " + + "unlocks the device", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "created"), @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") }) - Response configureDeviceLock(@ApiParam(name = "acceptHeader", value = "Accept Header") + Response configureDeviceUnlock(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", value = - "DeviceIds to be enable device lock operation") + "DeviceIds to be enable device unlock operation") List deviceIDs); @@ -219,6 +236,22 @@ public interface OperationMgtService { @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", value = "Device Ids needs to be ring") List deviceIDs); + @POST + @Path("reboot-device") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Rebooting Android Devices", + notes = "Reboot Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response rebootDevice(@ApiParam(name = "acceptHeader", value = "Accept Header") + @HeaderParam(ACCEPT) String acceptHeader, @ApiParam(name = "deviceIDs", + value = "Device Ids needs to be rebooted") List deviceIDs); + @POST @ApiOperation( consumes = MediaType.APPLICATION_JSON, @@ -256,6 +289,27 @@ public interface OperationMgtService { value = "Properties of installed apps and device IDs") ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper); + @POST + @Path("update-application") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Updating an Application on Android Devices", + notes = "Update an application on an Android device. If the device you are updating the application" + + " has the WSO2 system service installed, the application update will happen in silent " + + "mode, else the device user's consent will be required" + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response updateApplication(@ApiParam(name = "acceptHeader", value = "Accept Header") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "applicationUpdateBeanWrapper", + value = "Properties of updated apps and device IDs") + ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper); + @POST @Path("uninstall-application") @ApiOperation( @@ -293,6 +347,44 @@ public interface OperationMgtService { value = "BlacklistApplications Configuration and DeviceIds") BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper); + @POST + @Path("upgrade-firmware") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Upgrading device firmware", + notes = "Device firmware upgrade" + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response upgradeFirmware(@ApiParam(name = "acceptHeader", value = "Accept Header") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "upgradeFirmwareBeanWrapper", + value = "Firmware upgrade configuration and DeviceIds") + UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper); + + @POST + @Path("vpn") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Configuring VPN on Android devices", + notes = "Configure VPN on Android devices" + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Created"), + @ApiResponse(code = 500, message = "Issue in retrieving device management service instance") + }) + Response configureVPN(@ApiParam(name = "acceptHeader", value = "Accept Header") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "vpnBeanWrapper", + value = "VPN configuration and DeviceIds") + VpnBeanWrapper vpnBeanWrapper); + @POST @Path("notification") @ApiOperation( diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/impl/OperationMgtServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/impl/OperationMgtServiceImpl.java index f85f218a8..030f96384 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/impl/OperationMgtServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/operationmgt/impl/OperationMgtServiceImpl.java @@ -29,8 +29,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.mdm.services.android.bean.*; +import org.wso2.carbon.mdm.services.android.bean.Notification; import org.wso2.carbon.mdm.services.android.bean.wrapper.*; -import org.wso2.carbon.mdm.services.android.exception.AndroidOperationException; import org.wso2.carbon.mdm.services.android.services.operationmgt.OperationMgtService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; @@ -43,7 +43,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; -public class OperationMgtServiceImpl { +public class OperationMgtServiceImpl implements OperationMgtService { private static Log log = LogFactory.getLog(OperationMgtService.class); private static final String ACCEPT = "Accept"; @@ -52,28 +52,31 @@ public class OperationMgtServiceImpl { @PUT @Path("{id}") - public List getPendingOperations + public Response getPendingOperations (@HeaderParam(ACCEPT) String acceptHeader, @PathParam("id") String id, List resultOperations) { Message message; + String errorMessage; MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); if (id == null || id.isEmpty()) { - String errorMessage = "Device identifier is null or empty, hence returning device not found"; + errorMessage = "Device identifier is null or empty, hence returning device not found"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.BAD_REQUEST.toString()).build(); log.error(errorMessage); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); try { if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { - String errorMessage = "Device not found for identifier '" + id + "'"; + errorMessage = "Device not found for identifier '" + id + "'"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.BAD_REQUEST.toString()).build(); log.error(errorMessage); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } if (log.isDebugEnabled()) { log.debug("Invoking Android pending operations:" + id); @@ -82,33 +85,51 @@ public class OperationMgtServiceImpl { updateOperations(id, resultOperations); } } catch (OperationManagementException e) { - log.error("Issue in retrieving operation management service instance", e); + errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( + responseMediaType).build(); } catch (PolicyComplianceException e) { - log.error("Issue in updating Monitoring operation"); + errorMessage = "Issue in updating Monitoring operation"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( + responseMediaType).build(); } catch (DeviceManagementException e) { - log.error("Issue in retrieving device management service instance", e); + errorMessage = "Issue in retrieving device management service instance"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( + responseMediaType).build(); } catch (ApplicationManagementException e) { - log.error("Issue in retrieving application management service instance", e); + errorMessage = "Issue in retrieving application management service instance"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( + responseMediaType).build(); } catch (NotificationManagementException e) { - log.error("Issue in retrieving Notification management service instance", e); + errorMessage = "Issue in retrieving Notification management service instance"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type( + responseMediaType).build(); } List pendingOperations; try { pendingOperations = AndroidAPIUtils.getPendingOperations(deviceIdentifier); } catch (OperationManagementException e) { - String errorMessage = "Issue in retrieving operation management service instance"; + errorMessage = "Issue in retrieving operation management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } - return pendingOperations; + return Response.status(Response.Status.CREATED).entity(pendingOperations).type( + responseMediaType).build(); } @POST @Path("lock") - public Response configureDeviceLock(@HeaderParam(ACCEPT) String acceptHeader, List deviceIDs) { + public Response configureDeviceLock(@HeaderParam(ACCEPT) String acceptHeader, + DeviceLockBeanWrapper deviceLockBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking Android device lock operation"); @@ -119,8 +140,56 @@ public class OperationMgtServiceImpl { Response response; try { - CommandOperation operation = new CommandOperation(); + DeviceLock lock = deviceLockBeanWrapper.getOperation(); + + if (lock == null) { + String errorMessage = "Lock bean is empty"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCK); + operation.setType(Operation.Type.PROFILE); + operation.setEnabled(true); + operation.setPayLoad(lock.toJSON()); + response = AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation, + message, responseMediaType); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Issue in retrieving device management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + return response; + } + + @POST + @Path("unlock") + public Response configureDeviceUnlock(@HeaderParam(ACCEPT) String acceptHeader, List deviceIDs) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android device unlock operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + Response response; + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK); operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); response = AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); @@ -129,13 +198,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } return response; } @@ -161,13 +232,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -194,13 +267,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -239,13 +314,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -265,7 +342,6 @@ public class OperationMgtServiceImpl { CommandOperation operation = new CommandOperation(); operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); operation.setType(Operation.Type.COMMAND); - getApplications(acceptHeader, deviceIDs); return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); } catch (OperationManagementException e) { @@ -273,13 +349,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -307,13 +385,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -349,13 +429,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -383,13 +465,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -416,13 +500,50 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + } + + @POST + @Path("reboot-device") + public Response rebootDevice(@HeaderParam(ACCEPT) String acceptHeader, + List deviceIDs) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android reboot-device device operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT); + operation.setType(Operation.Type.COMMAND); + return AndroidAPIUtils.getOperationResponse(deviceIDs, operation, message, + responseMediaType); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Issue in retrieving device management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -450,13 +571,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -479,7 +602,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the application installing operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new application installation instance"); + String errorMessage = "Issue in creating a new application installation instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -494,13 +622,66 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Issue in retrieving device management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + } + + @POST + @Path("update-application") + public Response updateApplication(@HeaderParam(ACCEPT) String acceptHeader, + ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) { + + if (log.isDebugEnabled()) { + log.debug("Invoking 'UpdateApplication' operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + + try { + ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); + + if (applicationUpdate == null) { + if (log.isDebugEnabled()) { + log.debug("The payload of the application update operation is incorrect"); + } + String errorMessage = "Issue in creating a new application update instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.UPDATE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(applicationUpdate.toJSON()); + + return AndroidAPIUtils.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(), + operation, message, responseMediaType); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -522,7 +703,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the application uninstalling operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new application uninstallation instance"); + String errorMessage = "Issue in creating a new application uninstallation instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -537,13 +723,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -565,7 +753,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the blacklisting apps operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new blacklist applications instance"); + String errorMessage = "Issue in creating a new blacklist applications instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -581,13 +774,115 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Issue in retrieving device management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + } + + @POST + @Path("upgrade-firmware") + public Response upgradeFirmware(@HeaderParam(ACCEPT) String acceptHeader, + UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android upgrade-firmware device operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + + try { + UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); + + if (upgradeFirmware == null) { + if (log.isDebugEnabled()) { + log.debug("The payload of the upgrade firmware operation is incorrect"); + } + String errorMessage = "Issue in creating a new upgrade firmware instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(upgradeFirmware.toJSON()); + return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), + operation, message, responseMediaType); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + } + + @POST + @Path("vpn") + public Response configureVPN(@HeaderParam(ACCEPT) String acceptHeader, + VpnBeanWrapper vpnBeanWrapper) { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android VPN device operation"); + } + + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + Message message = new Message(); + + try { + Vpn vpn = vpnBeanWrapper.getOperation(); + + if (vpn == null) { + if (log.isDebugEnabled()) { + log.debug("The payload of the VPN operation is incorrect"); + } + String errorMessage = "Issue in creating a new VPN instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.VPN); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(vpn.toJSON()); + return AndroidAPIUtils.getOperationResponse(vpnBeanWrapper.getDeviceIDs(), + operation, message, responseMediaType); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Issue in retrieving device management service instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -609,7 +904,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the notification operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new notification instance"); + String errorMessage = "Issue in creating a new notification instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -625,13 +925,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -653,7 +955,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the wifi operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new Wifi instance"); + String errorMessage = "Issue in creating a new Wifi instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -669,13 +976,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -697,7 +1006,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the device encryption operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new encryption instance"); + String errorMessage = "Issue in creating a new encryption instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } CommandOperation operation = new CommandOperation(); @@ -713,13 +1027,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -741,7 +1057,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the change lock code operation is incorrect"); } - throw new OperationManagementException("Issue in retrieving a new lock-code instance"); + String errorMessage = "Issue in retrieving a new lock-code instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -757,13 +1078,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -785,7 +1108,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the change password policy operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new Password policy instance"); + String errorMessage = "Issue in creating a new Password policy instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -801,13 +1129,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -829,7 +1159,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the add webclip operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new web clip instance"); + String errorMessage = "Issue in creating a new web clip instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } ProfileOperation operation = new ProfileOperation(); @@ -845,13 +1180,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } @@ -874,7 +1211,12 @@ public class OperationMgtServiceImpl { if (log.isDebugEnabled()) { log.debug("The payload of the device disenrollment operation is incorrect"); } - throw new OperationManagementException("Issue in creating a new disenrollment instance"); + String errorMessage = "Issue in creating a new disenrollment instance"; + message = Message.responseMessage(errorMessage). + responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); + log.error(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } CommandOperation operation = new CommandOperation(); @@ -890,13 +1232,15 @@ public class OperationMgtServiceImpl { message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; message = Message.responseMessage(errorMessage). responseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()).build(); log.error(errorMessage, e); - throw new AndroidOperationException(message, responseMediaType); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).type( + responseMediaType).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/PolicyMgtService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/PolicyMgtService.java index e35f08b23..adcb2228f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/PolicyMgtService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/PolicyMgtService.java @@ -26,6 +26,7 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature; import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import java.util.List; @Api(value = "PolicyMgtService", description = "Policy management related REST-API implementation.") @@ -47,9 +48,9 @@ public interface PolicyMgtService { @ApiResponse(code = 200, message = "Effective policy added to operation"), @ApiResponse(code = 204, message = "No effective policy found") }) - Message getEffectivePolicy(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam("Accept") + Response getEffectivePolicy(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam("Accept") String acceptHeader, - @ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") + @ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) throws AndroidAgentException; @GET @@ -66,7 +67,7 @@ public interface PolicyMgtService { @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Error occurred while getting the features") }) - List getEffectiveFeatures(@ApiParam(name = "acceptHeader", value = "Accept Header") + Response getEffectiveFeatures(@ApiParam(name = "acceptHeader", value = "Accept Header") @HeaderParam("Accept") String acceptHeader, @ApiParam(name = "deviceId", value = "DeviceIdentifier") @PathParam("deviceId") String id) throws AndroidAgentException; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/impl/PolicyMgtServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/impl/PolicyMgtServiceImpl.java index eed862683..33d9c1603 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/impl/PolicyMgtServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/policymgt/impl/PolicyMgtServiceImpl.java @@ -35,18 +35,20 @@ import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; -public class PolicyMgtServiceImpl { +public class PolicyMgtServiceImpl implements PolicyMgtService { private static Log log = LogFactory.getLog(PolicyMgtService.class); @GET @Path("{deviceId}") - public Message getEffectivePolicy(@HeaderParam("Accept") String acceptHeader, + public Response getEffectivePolicy(@HeaderParam("Accept") String acceptHeader, @PathParam("deviceId") String id) throws AndroidAgentException { DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); Message responseMessage = new Message(); Policy policy; try { @@ -55,35 +57,44 @@ public class PolicyMgtServiceImpl { if (policy == null) { responseMessage = Message.responseMessage("No effective policy found"). responseCode(Response.Status.NO_CONTENT.toString()).build(); + return Response.status(Response.Status.NO_CONTENT).entity(responseMessage).type( + responseMediaType).build(); } else { responseMessage = Message.responseMessage("Effective policy added to operation"). responseCode(Response.Status.OK.toString()).build(); + return Response.status(Response.Status.OK).entity(responseMessage).type( + responseMediaType).build(); } } catch (PolicyManagementException e) { String msg = "Error occurred while getting the policy."; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type( + responseMediaType).build(); } - return responseMessage; } @GET @Path("/features/{deviceId}") - public List getEffectiveFeatures(@HeaderParam("Accept") String acceptHeader, + public Response getEffectiveFeatures(@HeaderParam("Accept") String acceptHeader, @PathParam("deviceId") String id) throws AndroidAgentException { List profileFeatures; DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); try { PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService(); profileFeatures = policyManagerService.getEffectiveFeatures(deviceIdentifier); if (profileFeatures == null) { Response.status(Response.Status.NOT_FOUND); + return Response.status(Response.Status.NOT_FOUND).type( + responseMediaType).build(); } } catch (FeatureManagementException e) { String msg = "Error occurred while getting the features."; log.error(msg, e); - throw new AndroidAgentException(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type( + responseMediaType).build(); } - return profileFeatures; + return Response.status(Response.Status.OK).entity(profileFeatures).type( + responseMediaType).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java index 01ee8d029..acb487d68 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 @@ -11,36 +11,51 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.wso2.carbon.mdm.services.android.util; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; +import com.google.gson.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.analytics.api.AnalyticsDataAPI; +import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse; +import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry; +import org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceUtils; +import org.wso2.carbon.analytics.datasource.commons.Record; +import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * AndroidAPIUtil class provides utility functions used by Android REST-API classes. @@ -60,7 +75,7 @@ public class AndroidAPIUtils { PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); String username = threadLocalCarbonContext.getUsername(); String tenantDomain = threadLocalCarbonContext.getTenantDomain(); - if (username.endsWith(tenantDomain)) { + if (username != null && username.endsWith(tenantDomain)) { return username.substring(0, username.lastIndexOf("@")); } return username; @@ -107,13 +122,15 @@ public class AndroidAPIUtils { DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs, message, responseMediaType); - int status = - getDeviceManagementService().addOperation("android", operation, deviceIDHolder.getValidDeviceIDList()); -// if (status > 0) { + List validDeviceIds = deviceIDHolder.getValidDeviceIDList(); + Activity activity = getDeviceManagementService().addOperation( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, validDeviceIds); +// if (activity != null) { // GCMService gcmService = getGCMService(); // if (gcmService.isGCMEnabled()) { -// List devices = new ArrayList(); -// for (DeviceIdentifier deviceIdentifier : deviceIDHolder.getValidDeviceIDList()) { +// List deviceIDList = deviceIDHolder.getValidDeviceIDList(); +// List devices = new ArrayList(deviceIDList.size()); +// for (DeviceIdentifier deviceIdentifier : deviceIDList) { // devices.add(getDeviceManagementService().getDevice(deviceIdentifier)); // } // getGCMService().sendNotification(operation.getCode(), devices); @@ -125,7 +142,7 @@ public class AndroidAPIUtils { responseMediaType).entity(deviceUtils. convertErrorMapIntoErrorMessage(deviceIDHolder.getErrorDeviceIdList())).build(); } - return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.CREATED). + return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.CREATED).entity(activity). type(responseMediaType).build(); } @@ -167,40 +184,137 @@ public class AndroidAPIUtils { return notificationManagementService; } + public static EventsPublisherService getEventPublisherService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + EventsPublisherService eventsPublisherService = + (EventsPublisherService) ctx.getOSGiService(EventsPublisherService.class, null); + if (eventsPublisherService == null) { + String msg = "Event Publisher service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return eventsPublisherService; + } + + public static AnalyticsDataAPI getAnalyticsDataAPI() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + AnalyticsDataAPI analyticsDataAPI = + (AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null); + if (analyticsDataAPI == null) { + String msg = "Analytics api service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return analyticsDataAPI; + } + + public static List getAllEventsForDevice(String tableName, String query) throws AnalyticsException { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI(); + int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query); + if (eventCount == 0) { + return null; + } + List resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount); + List recordIds = getRecordIds(resultEntries); + AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); + Map deviceStateses = createDeviceStatusData(AnalyticsDataServiceUtils.listRecords( + analyticsDataAPI, response)); + return getSortedDeviceStateData(deviceStateses, resultEntries); + } + + private static List getRecordIds(List searchResults) { + List ids = new ArrayList(); + for (SearchResultEntry searchResult : searchResults) { + ids.add(searchResult.getId()); + } + return ids; + } + + public static Map createDeviceStatusData(List records) { + Map deviceStatuses = new HashMap(); + for (Record record : records) { + DeviceState deviceState = createDeviceStatusData(record); + deviceStatuses.put(deviceState.getId(), deviceState); + } + return deviceStatuses; + } + + private static DeviceState createDeviceStatusData(Record record) { + DeviceState deviceState = new DeviceState(); + deviceState.setId(record.getId()); + deviceState.setValues(record.getValues()); + return deviceState; + } + + public static List getSortedDeviceStateData(Map sensorDatas, + List searchResults) { + List sortedRecords = new ArrayList(); + for (SearchResultEntry searchResultEntry : searchResults) { + sortedRecords.add(sensorDatas.get(searchResultEntry.getId())); + } + return sortedRecords; + } + public static void updateOperation(String deviceId, Operation operation) throws OperationManagementException, PolicyComplianceException, ApplicationManagementException { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) { if (log.isDebugEnabled()) { log.info("Received compliance status from MONITOR operation ID: " + operation.getId()); } - getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, operation.getOperationResponse()); + getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, operation.getPayLoad()); } else if (AndroidConstants.OperationCodes.APPLICATION_LIST.equals(operation.getCode())) { if (log.isDebugEnabled()) { log.info("Received applications list from device '" + deviceId + "'"); } updateApplicationList(operation, deviceIdentifier); + + } else if (AndroidConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) { + + try { + Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); + org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device); + deviceInfo.setDeviceIdentifier(deviceIdentifier); + updateDeviceInfo(deviceInfo); + } catch (DeviceDetailsMgtException e) { + throw new OperationManagementException("Error occurred while updating the device information.", e); + } + + + } else if (AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { + try { + DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class); + if (location != null) { + location.setDeviceIdentifier(deviceIdentifier); + updateDeviceLocation(location); + } + } catch (DeviceDetailsMgtException e) { + throw new OperationManagementException("Error occurred while updating the device location.", e); + } } + getDeviceManagementService().updateOperation(deviceIdentifier, operation); } - public static List getPendingOperations + public static List getPendingOperations (DeviceIdentifier deviceIdentifier) throws OperationManagementException { - List operations; + List operations; operations = getDeviceManagementService().getPendingOperations(deviceIdentifier); return operations; } private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) throws ApplicationManagementException { - List applications = new ArrayList(); // Parsing json string to get applications list. JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); JsonArray jsonArray = jsonElement.getAsJsonArray(); Application app; + List applications = new ArrayList(jsonArray.size()); for (JsonElement element : jsonArray) { app = new Application(); app.setName(element.getAsJsonObject(). @@ -208,8 +322,152 @@ public class AndroidAPIUtils { app.setApplicationIdentifier(element.getAsJsonObject(). get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { + app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); + } + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { + app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + } applications.add(app); } getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); } + + + private static void updateDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException { + + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceInformationManager informationManager = + (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); + + informationManager.addDeviceLocation(deviceLocation); + } + + + private static void updateDeviceInfo(org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo) + throws DeviceDetailsMgtException { + + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceInformationManager informationManager = + (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); + + informationManager.addDeviceInfo(deviceInfo); + } + + + private static org.wso2.carbon.device.mgt.common.device.details.DeviceInfo convertDeviceToInfo(Device device) { + + org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = + new org.wso2.carbon.device.mgt.common.device.details.DeviceInfo(); + if (deviceInfo.getDeviceDetailsMap() == null) { + deviceInfo.setDeviceDetailsMap(new HashMap()); + } + List props = device.getProperties(); + + for (Device.Property prop : props) { + if (Utils.getDeviceDetailsColumnNames().containsValue(prop.getName())) { + if (prop.getName().equalsIgnoreCase("DEVICE_MODEL")) { + deviceInfo.setDeviceModel(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("VENDOR")) { + deviceInfo.setVendor(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("OS_VERSION")) { + deviceInfo.setOsVersion(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("IMEI")) { + deviceInfo.getDeviceDetailsMap().put("IMEI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("IMSI")) { + deviceInfo.getDeviceDetailsMap().put("IMSI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("MAC")) { + deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("SERIAL")) { + deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue()); + } + } else { + if (prop.getName().equalsIgnoreCase("CPU_INFO")) { + deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "User"))); + + deviceInfo.getDeviceDetailsMap().put("cpuUser", + getProperty(prop.getValue(), "User")); + deviceInfo.getDeviceDetailsMap().put("cpuSystem", + getProperty(prop.getValue(), "System")); + deviceInfo.getDeviceDetailsMap().put("IOW", + getProperty(prop.getValue(), "IOW")); + deviceInfo.getDeviceDetailsMap().put("IRQ", + getProperty(prop.getValue(), "IRQ")); + } else if (prop.getName().equalsIgnoreCase("RAM_INFO")) { + deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "TOTAL_MEMORY"))); + deviceInfo.setAvailableRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "AVAILABLE_MEMORY"))); + + deviceInfo.getDeviceDetailsMap().put("ramThreshold", + getProperty(prop.getValue(), "THRESHOLD")); + deviceInfo.getDeviceDetailsMap().put("ramLowMemory", + getProperty(prop.getValue(), "LOW_MEMORY")); + } else if (prop.getName().equalsIgnoreCase("BATTERY_INFO")) { + deviceInfo.setPluggedIn(Boolean.parseBoolean(getProperty(prop.getValue(), "PLUGGED"))); + + deviceInfo.getDeviceDetailsMap().put("batteryLevel", + getProperty(prop.getValue(), "BATTERY_LEVEL")); + deviceInfo.getDeviceDetailsMap().put("batteryScale", + getProperty(prop.getValue(), "SCALE")); + deviceInfo.getDeviceDetailsMap().put("batteryVoltage", + getProperty(prop.getValue(), "BATTERY_VOLTAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTemperature", + getProperty(prop.getValue(), "TEMPERATURE")); + deviceInfo.getDeviceDetailsMap().put("batteryCurrentTemperature", + getProperty(prop.getValue(), "CURRENT_AVERAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTechnology", + getProperty(prop.getValue(), "TECHNOLOGY")); + deviceInfo.getDeviceDetailsMap().put("batteryHealth", + getProperty(prop.getValue(), "HEALTH")); + deviceInfo.getDeviceDetailsMap().put("batteryStatus", + getProperty(prop.getValue(), "STATUS")); + } else if (prop.getName().equalsIgnoreCase("NETWORK_INFO")) { + deviceInfo.setSsid(getProperty(prop.getValue(), "WIFI_SSID")); + deviceInfo.setConnectionType(getProperty(prop.getValue(), "CONNECTION_TYPE")); + + deviceInfo.getDeviceDetailsMap().put("mobileSignalStrength", + getProperty(prop.getValue(), "MOBILE_SIGNAL_STRENGTH")); + deviceInfo.getDeviceDetailsMap().put("wifiSignalStrength", + getProperty(prop.getValue(), "WIFI_SIGNAL_STRENGTH")); + } else if (prop.getName().equalsIgnoreCase("DEVICE_INFO")) { + deviceInfo.setBatteryLevel(Double.parseDouble( + getProperty(prop.getValue(), "BATTERY_LEVEL"))); + deviceInfo.setInternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_TOTAL_MEMORY"))); + deviceInfo.setInternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_AVAILABLE_MEMORY"))); + deviceInfo.setExternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_TOTAL_MEMORY"))); + deviceInfo.setExternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_AVAILABLE_MEMORY"))); + + deviceInfo.getDeviceDetailsMap().put("encryptionEnabled", + getProperty(prop.getValue(), "ENCRYPTION_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("passcodeEnabled", + getProperty(prop.getValue(), "PASSCODE_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("operator", + getProperty(prop.getValue(), "OPERATOR")); + } + } + } + return deviceInfo; + } + + private static String getProperty(String a, String needed) { + + JsonElement jsonElement = new JsonParser().parse(a); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + boolean exist = false; + for (JsonElement element : jsonArray) { + // if (((JsonObject) element).entrySet().iterator().next().getValue().getAsString().equalsIgnoreCase(needed)); + for (Map.Entry ob : ((JsonObject) element).entrySet()) { + if (exist) { + return ob.getValue().getAsString().replace("%", ""); + } + if (ob.getValue().getAsString().equalsIgnoreCase(needed)) { + exist = true; + } + } + } + return ""; + } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java index ef9131bbb..8ba454da3 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -65,6 +65,7 @@ public final class AndroidConstants { throw new AssertionError(); } public static final String DEVICE_LOCK = "DEVICE_LOCK"; + public static final String DEVICE_UNLOCK = "DEVICE_UNLOCK"; public static final String DEVICE_LOCATION = "DEVICE_LOCATION"; public static final String WIFI = "WIFI"; public static final String CAMERA = "CAMERA"; @@ -77,14 +78,20 @@ public final class AndroidConstants { public static final String APPLICATION_LIST = "APPLICATION_LIST"; public static final String CHANGE_LOCK_CODE = "CHANGE_LOCK_CODE"; public static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; + public static final String UPDATE_APPLICATION = "UPDATE_APPLICATION"; public static final String UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; public static final String BLACKLIST_APPLICATIONS = "BLACKLIST_APPLICATIONS"; public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE"; public static final String DEVICE_RING = "DEVICE_RING"; + public static final String DEVICE_REBOOT = "REBOOT"; + public static final String UPGRADE_FIRMWARE = "UPGRADE_FIRMWARE"; public static final String NOTIFICATION = "NOTIFICATION"; public static final String WEBCLIP = "WEBCLIP"; public static final String DISENROLL = "DISENROLL"; public static final String MONITOR = "MONITOR"; + public static final String VPN = "VPN"; + public static final String APP_RESTRICTION = "APP-RESTRICTION"; + public static final String WORK_PROFILE = "WORK_PROFILE"; } public final class StatusCodes{ @@ -109,6 +116,8 @@ public final class AndroidConstants { } public static final String NAME = "name"; public static final String IDENTIFIER = "package"; + public static final String USS = "USS"; + public static final String VERSION = "version"; public static final String ICON = "icon"; } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml index 9c6e31a55..1fd0c7c66 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/META-INF/permissions.xml @@ -46,6 +46,14 @@ emm_admin,emm_user + + Unlock + /device-mgt/android/operations/unlock + /operation/unlock + POST + emm_admin,emm_user + + Mute /device-mgt/android/operations/mute @@ -117,6 +125,30 @@ emm_admin,emm_user + + Reboot + /device-mgt/android/operations/reboot-device + /operation/reboot-device + POST + emm_admin,emm_user + + + + Upgrade Firmware + /device-mgt/android/operations/upgrade-firmware + /operation/upgrade-firmware + POST + emm_admin,emm_user + + + + Configure VPN + /device-mgt/android/operations/vpn + /operation/vpn + POST + emm_admin,emm_user + + Install Application /device-mgt/android/operations/install-application @@ -125,6 +157,14 @@ emm_admin,emm_user + + Update Application + /device-mgt/android/operations/update-application + /operation/update-application + POST + emm_admin,emm_user + + Uninstall Application /device-mgt/android/operations/uninstall-application @@ -312,4 +352,32 @@ PUT emm_admin + + Event Addition + /device-mgt/android/events/add + /events + POST + emm_user,emm_admin + + + Event Retrieve + /device-mgt/android/events/view + /events/* + GET + emm_admin + + + Event Retrieve + /device-mgt/android/events/date + /events/*/date + GET + emm_admin + + + Event Retrieve + /device-mgt/android/events/type + /events/*/type/* + GET + emm_admin + \ No newline at end of file diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 010d83ff6..89e199a7b 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -68,12 +68,22 @@ + + + + + + + + + - - - - - + + + + + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml index ea919a40e..4f7b5286a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml @@ -18,20 +18,18 @@ ~ under the License. --> - + android-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.mobile.android.ui - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT WSO2 Carbon - Mobile Android UI pom diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/public/css/styles.css b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/public/css/styles.css new file mode 100644 index 000000000..04e2a2611 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/public/css/styles.css @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +.circle { + background: none repeat scroll 0 0 #191919; + border-radius: 50px; + height: 50px; + padding: 10px; + width: 50px; + color: #fff; +} +.padding-top-double { + padding-top: 20px; +} +.padding-double { + padding: 20px; +} +.grey { + color: #333; +} +hr { + display: block; + height: 1px; + border: 0; + border-top: 1px solid #7f7f7f; + margin: 1em 0; + padding: 0; + opacity: 0.2; +} +.light-grey { + color: #7c7c7c; +} +.uppercase { + text-transform: uppercase; +} +.grey-bg { + background-color: #f6f4f4; +} + +.doc-link { + background: #11375B; + padding: 20px; + color: white; + margin-top: 0; +} + +.doc-link a { + color: white; +} \ No newline at end of file diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs index 09c98431b..93e2e0a2f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/type-view.hbs @@ -79,59 +79,11 @@
{{#zone "topCss"}} - + {{css "css/styles.css"}} {{/zone}} {{#zone "bottomJs"}} {{/zone}} \ No newline at end of file diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml index 33605f760..acae2dc47 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/pom.xml @@ -18,12 +18,11 @@ ~ under the License. --> - + android-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -36,6 +35,10 @@ + + org.apache.maven.plugins + maven-compiler-plugin + org.apache.felix maven-scr-plugin diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java index 545de690a..951dd27e1 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java @@ -27,7 +27,7 @@ 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.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; @@ -85,7 +85,7 @@ public class AndroidDeviceManager implements DeviceManager { } @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + public boolean saveConfiguration(PlatformConfiguration tenantConfiguration) throws DeviceManagementException { boolean status; try { @@ -96,7 +96,7 @@ public class AndroidDeviceManager implements DeviceManager { DeviceManagementConstants. MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); StringWriter writer = new StringWriter(); - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); + JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(tenantConfiguration, writer); @@ -119,7 +119,7 @@ public class AndroidDeviceManager implements DeviceManager { } @Override - public TenantConfiguration getConfiguration() throws DeviceManagementException { + public PlatformConfiguration getConfiguration() throws DeviceManagementException { Resource resource; try { String androidRegPath = @@ -127,9 +127,9 @@ public class AndroidDeviceManager implements DeviceManager { MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath); if (resource != null) { - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); + JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class); Unmarshaller unmarshaller = context.createUnmarshaller(); - return (TenantConfiguration) unmarshaller.unmarshal( + return (PlatformConfiguration) unmarshaller.unmarshal( new StringReader(new String((byte[]) resource.getContent(), Charset. forName(MobilePluginConstants.CHARSET_UTF8)))); } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidFeatureManager.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidFeatureManager.java index d66f8d426..386355208 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidFeatureManager.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidFeatureManager.java @@ -234,11 +234,31 @@ public class AndroidFeatureManager implements FeatureManager { feature.setName("Password Policy"); feature.setDescription("Set passcode policy"); supportedFeatures.add(feature); + feature = new Feature(); feature.setCode("NOTIFICATION"); feature.setName("Message"); feature.setDescription("Send message"); supportedFeatures.add(feature); + + feature = new Feature(); + feature.setCode("DEVICE_REBOOT"); + feature.setName("Reboot"); + feature.setDescription("Reboot the device"); + supportedFeatures.add(feature); + + feature = new Feature(); + feature.setCode("UPGRADE_FIRMWARE"); + feature.setName("Upgrade Firmware"); + feature.setDescription("Upgrade Firmware"); + supportedFeatures.add(feature); + + feature = new Feature(); + feature.setCode("VPN"); + feature.setName("Configure VPN"); + feature.setDescription("Configure VPN settings"); + supportedFeatures.add(feature); + feature = new Feature(); feature.setCode("DISALLOW_ADJUST_VOLUME"); feature.setName("Adjust Volume"); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/gcm/GCMUtil.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/gcm/GCMUtil.java index ba41698e8..c89671403 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/gcm/GCMUtil.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/gcm/GCMUtil.java @@ -27,7 +27,7 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.mobile.android.impl.util.AndroidPluginConstants; import org.wso2.carbon.device.mgt.mobile.android.internal.AndroidDeviceManagementDataHolder; @@ -56,7 +56,7 @@ public class GCMUtil { private static final int TIME_TO_LIVE = 60; private static final int HTTP_STATUS_CODE_OK = 200; - private static HashMap tenantConfigurationCache = new HashMap<>(); + private static HashMap tenantConfigurationCache = new HashMap<>(); public static GCMResult sendWakeUpCall(String message, List devices) { GCMResult result = new GCMResult(); @@ -163,7 +163,7 @@ public class GCMUtil { getAndroidDeviceManagementService(); try { //Get the TenantConfiguration from cache if not we'll get it from DM service - TenantConfiguration tenantConfiguration = getTenantConfigurationFromCache(); + PlatformConfiguration tenantConfiguration = getTenantConfigurationFromCache(); if (tenantConfiguration == null) { tenantConfiguration = androidDMService.getDeviceManager().getConfiguration(); if (tenantConfiguration != null) { @@ -190,11 +190,11 @@ public class GCMUtil { tenantConfigurationCache.remove(getTenantId()); } - private static void addTenantConfigurationToCache(TenantConfiguration tenantConfiguration) { + private static void addTenantConfigurationToCache(PlatformConfiguration tenantConfiguration) { tenantConfigurationCache.put(getTenantId(), tenantConfiguration); } - private static TenantConfiguration getTenantConfigurationFromCache() { + private static PlatformConfiguration getTenantConfigurationFromCache() { return tenantConfigurationCache.get(getTenantId()); } diff --git a/components/mobile-plugins/android-plugin/pom.xml b/components/mobile-plugins/android-plugin/pom.xml index 788433cf8..339630a72 100644 --- a/components/mobile-plugins/android-plugin/pom.xml +++ b/components/mobile-plugins/android-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins mobile-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml index 56c146de5..2af40dcf1 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/pom.xml @@ -18,14 +18,12 @@ ~ under the License. --> - + mobile-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs index 78813761e..468bae0c4 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/operation-bar.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}}
{{#zone "bottomJs"}} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs index d193515b4..8d7e6bc16 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/operation-mod.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#zone "bottomJs"}} {{js "js/operation-mod.js"}} {{/zone}} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs index 293177871..e8b1fdfbd 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.platform.configuration/configuration.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}}
diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/edit.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/edit.hbs index 4f85e36c7..9c913a932 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/edit.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/edit.hbs @@ -1,4 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}}
diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/view.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/view.hbs index 223029164..ff5b1e03d 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/view.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/view.hbs @@ -1,4 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#defineZone "policy-profile-top"}}
diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.hbs index 08e9ca77d..b93a5ad1f 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.wizard/wizard.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}}
diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs index 7e30c1cb7..cef6f17c5 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.header.logo/logo.hbs @@ -1 +1,18 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#zone "productName"}}ENTERPRISE MOBILITY MANAGER{{/zone}} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml index bbb1c990a..9cf386acd 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml @@ -4,7 +4,7 @@ mobile-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/pom.xml b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/pom.xml index 73777a2da..b35d7fc0f 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/pom.xml +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/pom.xml @@ -18,12 +18,11 @@ ~ under the License. --> - + mobile-base-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java index 1bf5322da..e0058b6bd 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.mobile; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; @@ -33,9 +34,9 @@ public abstract class AbstractMobileOperationManager implements OperationManager } @Override - public int addOperation(Operation operation, List devices) throws - OperationManagementException { - return 1; + public Activity addOperation(Operation operation, List devices) throws + OperationManagementException { + return null; } } \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java deleted file mode 100644 index 5eae35cbe..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.mobile.impl.android; - -import org.wso2.carbon.device.mgt.common.*; -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.push.notification.PushNotificationConfig; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; - -import java.util.List; - -/** - * This represents the Android implementation of DeviceManagerService. - */ -public class AndroidDeviceManagementService implements DeviceManagementService { - - private DeviceManager deviceManager; - public static final String DEVICE_TYPE_ANDROID = "android"; - private static final String SUPER_TENANT_DOMAIN = "carbon.super"; - - @Override - public String getType() { - return AndroidDeviceManagementService.DEVICE_TYPE_ANDROID; - } - - @Override - public void init() throws DeviceManagementException { - this.deviceManager = new AndroidDeviceManager(); - } - - @Override - public DeviceManager getDeviceManager() { - return deviceManager; - } - - @Override - public ApplicationManager getApplicationManager() { - return null; - } - - @Override - public ProvisioningConfig getProvisioningConfig() { - return new ProvisioningConfig(SUPER_TENANT_DOMAIN, true); - } - - @Override - public PushNotificationConfig getPushNotificationConfig() { - return null; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java deleted file mode 100644 index c69e6b0cb..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * 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.mobile.impl.android; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.*; -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.common.license.mgt.LicenseManager; -import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; -import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; -import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; -import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginUtils; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; -import org.wso2.carbon.registry.api.RegistryException; -import org.wso2.carbon.registry.api.Resource; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -public class AndroidDeviceManager implements DeviceManager { - - private AbstractMobileDeviceManagementDAOFactory daoFactory; - private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class); - private FeatureManager featureManager = new AndroidFeatureManager(); - private LicenseManager licenseManager; - - public AndroidDeviceManager() { - this.daoFactory = new AndroidDAOFactory(); - this.licenseManager = new RegistryBasedLicenseManager(); - License defaultLicense; - - try { - if (licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, - MobilePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) { - defaultLicense = AndroidPluginUtils.getDefaultLicense(); - licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense); - } - featureManager.addSupportedFeaturesToDB(); - } catch (LicenseManagementException e) { - log.error("Error occurred while adding default license for Android devices", e); - } catch (DeviceManagementException e) { - throw new IllegalStateException("Error occurred while adding Android features to the DB."); - } - } - - @Override - public FeatureManager getFeatureManager() { - return featureManager; - } - - @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) - throws DeviceManagementException { - boolean status; - try { - if (log.isDebugEnabled()) { - log.debug("Persisting android configurations in Registry"); - } - String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( - DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - StringWriter writer = new StringWriter(); - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); - Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(tenantConfiguration, writer); - - Resource resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource(); - resource.setContent(writer.toString()); - resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); - MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource); - status = true; - } catch (MobileDeviceMgtPluginException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry instance", e); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while persisting the Registry resource of Android Configuration", e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Android configuration", e); - } - return status; - } - - @Override - public TenantConfiguration getConfiguration() throws DeviceManagementException { - Resource resource; - try { - String androidRegPath = - MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath); - if (resource != null) { - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - return (TenantConfiguration) unmarshaller.unmarshal( - new StringReader(new String((byte[]) resource.getContent(), Charset. - forName(MobilePluginConstants.CHARSET_UTF8)))); - } - return null; - } catch (MobileDeviceMgtPluginException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry instance", e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Android configuration", e); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry resource of Android Configuration", e); - } - } - - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - boolean status = false; - boolean isEnrolled = this.isEnrolled( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); - } - - if (isEnrolled) { - this.modifyEnrollment(device); - } else { - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - AndroidDAOFactory.beginTransaction(); - status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice); - AndroidDAOFactory.commitTransaction(); - } - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException mobileDAOEx) { - String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); - log.warn(msg, mobileDAOEx); - } - String msg = "Error occurred while enrolling the Android device : " + device.getDeviceIdentifier(); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Modifying the Android device enrollment data"); - } - AndroidDAOFactory.beginTransaction(); - status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice); - AndroidDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException mobileDAOEx) { - String msg = "Error occurred while roll back the update device transaction :" + device.toString(); - log.warn(msg, mobileDAOEx); - } - String msg = "Error occurred while updating the enrollment of the Android device : " + - device.getDeviceIdentifier(); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - //Here we don't have anything specific to do. Hence returning. - return true; - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - boolean isEnrolled = false; - try { - if (log.isDebugEnabled()) { - log.debug("Checking the enrollment of Android device : " + deviceId.getId()); - } - MobileDevice mobileDevice = - daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); - if (mobileDevice != null) { - isEnrolled = true; - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error occurred while checking the enrollment status of Android device : " + deviceId.getId(); - 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 Android device : '" + deviceId.getId() + "'"); - } - MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO(). - getMobileDevice(deviceId.getId()); - device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while fetching the Android device: '" + deviceId.getId() + "'", e); - } - return device; - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return true; - } - - @Override - public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return false; - } - - @Override - public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser, - EnrolmentInfo.Status status) throws DeviceManagementException { - return false; - } - - @Override - public License getLicense(String languageCode) throws LicenseManagementException { - return licenseManager. - getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode); - } - - @Override - public void addLicense(License license) throws LicenseManagementException { - licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license); - } - - @Override - public boolean requireDeviceAuthorization() { - return true; - } - - @Override - public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) - throws DeviceManagementException { - boolean status; - Device existingDevice = this.getDevice(deviceIdentifier); - // This object holds the current persisted device object - MobileDevice existingMobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(existingDevice); - // This object holds the newly received device object from response - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - // Updating current object features using newer ones - existingMobileDevice.setLatitude(mobileDevice.getLatitude()); - existingMobileDevice.setLongitude(mobileDevice.getLongitude()); - existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties()); - - try { - if (log.isDebugEnabled()) { - log.debug( - "updating the details of Android device : " + device.getDeviceIdentifier()); - } - AndroidDAOFactory.beginTransaction(); - status = daoFactory.getMobileDeviceDAO().updateMobileDevice(existingMobileDevice); - AndroidDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll back the update device info transaction : '" + - device.toString() + "'", e1); - } - throw new DeviceManagementException( - "Error occurred while updating the Android device: '" + device.getDeviceIdentifier() + "'", e); - } - return status; - } - - @Override - public List getAllDevices() throws DeviceManagementException { - List devices = null; - try { - if (log.isDebugEnabled()) { - log.debug("Fetching the details of all Android devices"); - } - List mobileDevices = - daoFactory.getMobileDeviceDAO().getAllMobileDevices(); - if (mobileDevices != null) { - devices = new ArrayList<>(mobileDevices.size()); - for (MobileDevice mobileDevice : mobileDevices) { - devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); - } - } - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while fetching all Android devices", e); - } - return devices; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java deleted file mode 100644 index a408360b9..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * 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.mobile.impl.android; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import java.util.ArrayList; -import java.util.List; - -public class AndroidFeatureManager implements FeatureManager { - - private MobileFeatureDAO featureDAO; - private static final Log log = LogFactory.getLog(AndroidFeatureManager.class); - - public AndroidFeatureManager() { - MobileDeviceManagementDAOFactory daoFactory = new AndroidDAOFactory(); - this.featureDAO = daoFactory.getMobileFeatureDAO(); - } - - @Override - public boolean addFeature(Feature feature) throws DeviceManagementException { - try { - AndroidDAOFactory.beginTransaction(); - MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); - featureDAO.addFeature(mobileFeature); - AndroidDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll-backing the transaction", e); - } - throw new DeviceManagementException("Error occurred while adding the feature", e); - } - } - - @Override - public boolean addFeatures(List features) throws DeviceManagementException { - List mobileFeatures = new ArrayList(features.size()); - for (Feature feature : features) { - mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); - } - try { - AndroidDAOFactory.beginTransaction(); - featureDAO.addFeatures(mobileFeatures); - AndroidDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll-backing the transaction", e); - } - throw new DeviceManagementException("Error occurred while adding the features", e); - } - } - - @Override - public Feature getFeature(String name) throws DeviceManagementException { - try { - MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); - Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); - return feature; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the feature", e); - } - } - - @Override - public List getFeatures() throws DeviceManagementException { - try { - List mobileFeatures = featureDAO.getAllFeatures(); - List featureList = new ArrayList(mobileFeatures.size()); - for (MobileFeature mobileFeature : mobileFeatures) { - featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); - } - return featureList; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + - "Android platform", e); - } - } - - @Override - public boolean removeFeature(String code) throws DeviceManagementException { - boolean status; - try { - AndroidDAOFactory.beginTransaction(); - featureDAO.deleteFeatureByCode(code); - AndroidDAOFactory.commitTransaction(); - status = true; - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll-backing the transaction", e); - } - throw new DeviceManagementException("Error occurred while removing the feature", e); - } - return status; - } - - @Override - public boolean addSupportedFeaturesToDB() throws DeviceManagementException { - synchronized (this) { - List supportedFeatures = getSupportedFeatures(); - List existingFeatures = this.getFeatures(); - List missingFeatures = MobileDeviceManagementUtil. - getMissingFeatures(supportedFeatures, existingFeatures); - if (missingFeatures.size() > 0) { - return this.addFeatures(missingFeatures); - } - return true; - } - } - - //Get the supported feature list. - private static List getSupportedFeatures() { - List supportedFeatures = new ArrayList(); - - Feature feature = new Feature(); - feature.setCode("DEVICE_LOCK"); - feature.setName("Device Lock"); - feature.setDescription("Lock the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_UNLOCK"); - feature.setName("Device Unlock"); - feature.setDescription("Unlock the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_LOCATION"); - feature.setName("Location"); - feature.setDescription("Request coordinates of device location"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("WIFI"); - feature.setName("wifi"); - feature.setDescription("Setting up wifi configuration"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("CAMERA"); - feature.setName("camera"); - feature.setDescription("Enable or disable camera"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("EMAIL"); - feature.setName("Email"); - feature.setDescription("Configure email settings"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_MUTE"); - feature.setName("Mute"); - feature.setDescription("Enable mute in the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_INFO"); - feature.setName("Device info"); - feature.setDescription("Request device information"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("ENTERPRISE_WIPE"); - feature.setName("Enterprise Wipe"); - feature.setDescription("Remove enterprise applications"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("CLEAR_PASSWORD"); - feature.setName("Clear Password"); - feature.setDescription("Clear current password"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("WIPE_DATA"); - feature.setName("Wipe Data"); - feature.setDescription("Factory reset the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("APPLICATION_LIST"); - feature.setName("Application List"); - feature.setDescription("Request list of current installed applications"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("CHANGE_LOCK_CODE"); - feature.setName("Change Lock-code"); - feature.setDescription("Change current lock code"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("INSTALL_APPLICATION"); - feature.setName("Install App"); - feature.setDescription("Install Enterprise or Market application"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("UPDATE_APPLICATION"); - feature.setName("Update App"); - feature.setDescription("Update Enterprise or Market application"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("UNINSTALL_APPLICATION"); - feature.setName("Uninstall App"); - feature.setDescription("Uninstall application"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("BLACKLIST_APPLICATIONS"); - feature.setName("Blacklist app"); - feature.setDescription("Blacklist applications"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("ENCRYPT_STORAGE"); - feature.setName("Encrypt storage"); - feature.setDescription("Encrypt storage"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_RING"); - feature.setName("Ring"); - feature.setDescription("Ring the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("PASSCODE_POLICY"); - feature.setName("Password Policy"); - feature.setDescription("Set passcode policy"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("NOTIFICATION"); - feature.setName("Message"); - feature.setDescription("Send message"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_REBOOT"); - feature.setName("Reboot"); - feature.setDescription("Reboot the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("UPGRADE_FIRMWARE"); - feature.setName("Upgrade Firmware"); - feature.setDescription("Upgrade Firmware"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("VPN"); - feature.setName("Configure VPN"); - feature.setDescription("Configure VPN settings"); - supportedFeatures.add(feature); - - return supportedFeatures; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java deleted file mode 100644 index ced47139f..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.mobile.impl.android; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; -import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; -import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; -import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; - -import java.util.ArrayList; -import java.util.List; - -public class AndroidPolicyMonitoringService implements PolicyMonitoringService { - - private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class); - - @Override - public void notifyDevices(List list) throws PolicyComplianceException { - GCMService gcmService = MobileDeviceManagementDataHolder.getInstance().getGCMService(); - if (gcmService.isGCMEnabled() && !list.isEmpty()) { - gcmService.sendNotification("POLICY_BUNDLE", list); - } - } - - @Override - public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, - Object compliancePayload) throws PolicyComplianceException { - if (log.isDebugEnabled()) { - log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); - } - ComplianceData complianceData = new ComplianceData(); - if (compliancePayload == null || policy == null) { - return complianceData; - } - String compliancePayloadString = new Gson().toJson(compliancePayload); - // Parsing json string to get compliance features. - JsonElement jsonElement; - if (compliancePayloadString instanceof String) { - jsonElement = new JsonParser().parse(compliancePayloadString); - } else { - throw new PolicyComplianceException("Invalid policy compliance payload"); - } - - JsonArray jsonArray = jsonElement.getAsJsonArray(); - Gson gson = new Gson(); - ComplianceFeature complianceFeature; - List complianceFeatures = new ArrayList(jsonArray.size()); - List nonComplianceFeatures = new ArrayList<>(); - - for (JsonElement element : jsonArray) { - complianceFeature = gson.fromJson(element, ComplianceFeature.class); - complianceFeatures.add(complianceFeature); - } - - for (ComplianceFeature cf : complianceFeatures) { - if (!cf.isCompliant()) { - complianceData.setStatus(false); - nonComplianceFeatures.add(cf); - break; - } - } - - complianceData.setComplianceFeatures(nonComplianceFeatures); - return complianceData; - } - - @Override - public String getType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java deleted file mode 100644 index 183a47e64..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.mobile.impl.android.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.*; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidDeviceDAOImpl; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidFeatureDAOImpl; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; - -public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory { - - private static final Log log = LogFactory.getLog(AndroidDAOFactory.class); - protected static DataSource dataSource; - private static ThreadLocal currentConnection = new ThreadLocal<>(); - - public AndroidDAOFactory() { - this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - } - - @Override - public MobileDeviceDAO getMobileDeviceDAO() { - return new AndroidDeviceDAOImpl(); - } - - public MobileFeatureDAO getMobileFeatureDAO() { - return new AndroidFeatureDAOImpl(); - } - - public static void beginTransaction() throws MobileDeviceManagementDAOException { - try { - Connection conn = dataSource.getConnection(); - conn.setAutoCommit(false); - currentConnection.set(conn); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); - } - } - - public static Connection getConnection() throws MobileDeviceManagementDAOException { - if (currentConnection.get() == null) { - try { - currentConnection.set(dataSource.getConnection()); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while retrieving data source connection", - e); - } - } - return currentConnection.get(); - } - - public static void commitTransaction() throws MobileDeviceManagementDAOException { - 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 MobileDeviceManagementDAOException("Error occurred while committing the transaction", e); - } - } - - public static void closeConnection() throws MobileDeviceManagementDAOException { - Connection conn = currentConnection.get(); - try { - if (conn != null) { - conn.close(); - } - } catch (SQLException e) { - log.error("Error occurred while close the connection"); - } - currentConnection.remove(); - } - - public static void rollbackTransaction() throws MobileDeviceManagementDAOException { - 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 MobileDeviceManagementDAOException("Error occurred while rollback the transaction", e); - } - } - -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java deleted file mode 100644 index 68d5a17d6..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.mobile.impl.android.dao; - -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; - -public class AndroidFeatureManagementDAOException extends MobileDeviceManagementDAOException { - - private String message; - private static final long serialVersionUID = 2021891706072918865L; - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message and - * nested exception. - * - * @param message error message - * @param nestedException exception - */ - public AndroidFeatureManagementDAOException(String message, Exception nestedException) { - super(message, nestedException); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message - * and cause. - * - * @param message the detail message. - * @param cause the cause of this exception. - */ - public AndroidFeatureManagementDAOException(String message, Throwable cause) { - super(message, cause); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message. - * - * @param message the detail message. - */ - public AndroidFeatureManagementDAOException(String message) { - super(message); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified and cause. - * - * @param cause the cause of this exception. - */ - public AndroidFeatureManagementDAOException(Throwable cause) { - super(cause); - } - - public String getMessage() { - return message; - } - - public void setErrorMessage(String errorMessage) { - this.message = errorMessage; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java deleted file mode 100644 index 84ad8512e..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * 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.mobile.impl.android.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants; - -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 MobileDeviceDAO for Android Devices. - */ -public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ - - private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class); - - @Override - public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - MobileDevice mobileDevice = null; - ResultSet rs = null; - try { - conn = AndroidDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + - "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" + - " FROM AD_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, mblDeviceId); - rs = stmt.executeQuery(); - - if (rs.next()) { - mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID)); - mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL)); - mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL)); - mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR)); - mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE)); - mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE)); - mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI)); - mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI)); - mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION)); - - Map propertyMap = new HashMap(); - propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN)); - propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO)); - propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME)); - mobileDevice.setDeviceProperties(propertyMap); - - if (log.isDebugEnabled()) { - log.debug("Android device " + mblDeviceId + " data has been fetched from " + - "Android database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while fetching Android device : '" + mblDeviceId + "'"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - - return mobileDevice; - } - - @Override - public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String createDBQuery = - "INSERT INTO AD_DEVICE(DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " + - "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, mobileDevice.getMobileDeviceId()); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(2, properties.get(AndroidPluginConstants.GCM_TOKEN)); - stmt.setString(3, properties.get(AndroidPluginConstants.DEVICE_INFO)); - stmt.setString(4, mobileDevice.getSerial()); - stmt.setString(5, mobileDevice.getVendor()); - stmt.setString(6, mobileDevice.getMobileDeviceId()); - stmt.setString(7, properties.get(AndroidPluginConstants.DEVICE_NAME)); - stmt.setString(8, mobileDevice.getLatitude()); - stmt.setString(9, mobileDevice.getLongitude()); - stmt.setString(10, mobileDevice.getImei()); - stmt.setString(11, mobileDevice.getImsi()); - stmt.setString(12, mobileDevice.getOsVersion()); - stmt.setString(13, mobileDevice.getModel()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" + - " added to the Android database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while adding the Android device '" + - mobileDevice.getMobileDeviceId() + "' information to the Android plugin data store.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " + - "MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " + - "IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(updateDBQuery); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(1, properties.get(AndroidPluginConstants.GCM_TOKEN)); - stmt.setString(2, properties.get(AndroidPluginConstants.DEVICE_INFO)); - stmt.setString(3, mobileDevice.getSerial()); - stmt.setString(4, mobileDevice.getVendor()); - stmt.setString(5, mobileDevice.getMobileDeviceId()); - stmt.setString(6, properties.get(AndroidPluginConstants.DEVICE_NAME)); - stmt.setString(7, mobileDevice.getLatitude()); - stmt.setString(8, mobileDevice.getLongitude()); - stmt.setString(9, mobileDevice.getImei()); - stmt.setString(10, mobileDevice.getImsi()); - stmt.setString(11, mobileDevice.getOsVersion()); - stmt.setString(12, mobileDevice.getModel()); - stmt.setString(13, mobileDevice.getMobileDeviceId()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" + - " modified."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while modifying the Android device '" + - mobileDevice.getMobileDeviceId() + "' data."; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileDevice(String mblDeviceId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String deleteDBQuery = - "DELETE FROM AD_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, mblDeviceId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android device " + mblDeviceId + " data has deleted" + - " from the Android database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while deleting android device '" + - mblDeviceId + "'", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public List getAllMobileDevices() throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - MobileDevice mobileDevice; - List mobileDevices = new ArrayList(); - try { - conn = AndroidDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + - "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " + - "FROM AD_DEVICE"; - stmt = conn.prepareStatement(selectDBQuery); - rs = stmt.executeQuery(); - - while (rs.next()) { - mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID)); - mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL)); - mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL)); - mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR)); - mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE)); - mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE)); - mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI)); - mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI)); - mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION)); - - Map propertyMap = new HashMap<>(); - propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN)); - propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO)); - propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME)); - mobileDevice.setDeviceProperties(propertyMap); - - mobileDevices.add(mobileDevice); - } - if (log.isDebugEnabled()) { - log.debug("All Android device details have fetched from Android database."); - } - return mobileDevices; - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while fetching all Android device data", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java deleted file mode 100644 index de6ec0bf6..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * 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.mobile.impl.android.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidFeatureManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class AndroidFeatureDAOImpl implements MobileFeatureDAO { - - private static final Log log = LogFactory.getLog(AndroidFeatureDAOImpl.class); - - public AndroidFeatureDAOImpl() { - - } - - @Override - public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.executeUpdate(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while adding android feature '" + - mobileFeature.getName() + "' into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - MobileFeature mobileFeature; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - stmt = conn.prepareStatement("INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"); - for (int i = 0; i < mobileFeatures.size(); i++) { - mobileFeature = mobileFeatures.get(i); - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.addBatch(); - } - stmt.executeBatch(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while adding android features into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE AD_FEATURE SET NAME = ?, DESCRIPTION = ?" + - "WHERE CODE = ?"; - - stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, mobileFeature.getName()); - stmt.setString(2, mobileFeature.getDescription()); - stmt.setString(3, mobileFeature.getCode()); - - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android Feature " + mobileFeature.getCode() + " data has been " + - "modified."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while updating the Android Feature '" + - mobileFeature.getCode() + "' to the Android db."; - log.error(msg, e); - throw new AndroidFeatureManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "DELETE FROM AD_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while deleting android feature '" + - mblFeatureId + "' from Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while deleting android feature '" + - mblFeatureCode + "' from Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - rs = stmt.executeQuery(); - - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID)); - mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE)); - mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(AndroidPluginConstants. - ANDROID_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - } - return mobileFeature; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while retrieving android feature '" + - mblFeatureId + "' from the Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } - - @Override - public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - rs = stmt.executeQuery(); - - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID)); - mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE)); - mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(AndroidPluginConstants. - ANDROID_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - } - return mobileFeature; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while retrieving android feature '" + - mblFeatureCode + "' from the Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } - - @Override - public List getFeatureByDeviceType(String deviceType) - throws MobileDeviceManagementDAOException { - return this.getAllFeatures(); - } - - @Override - public List getAllFeatures() throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn = null; - List features = new ArrayList<>(); - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE"; - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; - - while (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID)); - mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE)); - mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - features.add(mobileFeature); - } - return features; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " + - "android features from the android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java deleted file mode 100644 index c15d6d4c4..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.mobile.impl.android.gcm; - -/** - * Represents model object for holding GCM response data. - */ -public class GCMResult { - - private String errorMsg; - private String msg; - private int statusCode; - - public String getErrorMsg() { - return errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getMsg() { - return msg; - } - - public void setMsg(String msg) { - this.msg = msg; - } - - public int getStatusCode() { - return statusCode; - } - - public void setStatusCode(int statusCode) { - this.statusCode = statusCode; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java deleted file mode 100644 index e49e14d32..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.mobile.impl.android.gcm; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; - -import java.util.ArrayList; -import java.util.List; - -/** - * GCM notification service implementation for Android platform. - */ -public class GCMService { - - private static final Log log = LogFactory.getLog(GCMService.class); - private static final String NOTIFIER_TYPE = "notifierType"; - private static final String GCM_NOTIFIER_CODE = "2"; - - public boolean isGCMEnabled() { - String notifierType = GCMUtil.getConfigurationProperty(NOTIFIER_TYPE); - if (GCM_NOTIFIER_CODE.equals(notifierType)) { - return true; - } - return false; - } - - public void sendNotification(String messageData, Device device) { - List devices = new ArrayList<>(1); - devices.add(device); - GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices); - if (result.getStatusCode() != 200) { - log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg()); - } - } - - public void sendNotification(String messageData, List devices) { - GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices); - if (result.getStatusCode() != 200) { - log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg()); - } - } - - public void resetTenantConfigCache() { - GCMUtil.resetTenantConfigCache(); - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java deleted file mode 100644 index 19f594bc8..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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.mobile.impl.android.gcm; - -import com.google.gson.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants; -import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.ProtocolException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -/** - * Implements utility methods used by GCMService. - */ -public class GCMUtil { - - private static final Log log = LogFactory.getLog(GCMService.class); - - private final static String GCM_ENDPOINT = "https://gcm-http.googleapis.com/gcm/send"; - private static final String GCM_API_KEY = "gcmAPIKey"; - private static final int TIME_TO_LIVE = 60; - private static final int HTTP_STATUS_CODE_OK = 200; - - private static HashMap tenantConfigurationCache = new HashMap<>(); - - public static GCMResult sendWakeUpCall(String message, List devices) { - GCMResult result = new GCMResult(); - - byte[] bytes = getGCMRequest(message, getGCMTokens(devices)).getBytes(); - HttpURLConnection conn; - try { - conn = (HttpURLConnection) (new URL(GCM_ENDPOINT)).openConnection(); - conn.setDoOutput(true); - conn.setUseCaches(false); - conn.setFixedLengthStreamingMode(bytes.length); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/json"); - conn.setRequestProperty("Authorization", "key=" + getConfigurationProperty(GCM_API_KEY)); - - OutputStream out = conn.getOutputStream(); - out.write(bytes); - out.close(); - - int status = conn.getResponseCode(); - result.setStatusCode(status); - if (status != HTTP_STATUS_CODE_OK) { - result.setErrorMsg(getString(conn.getErrorStream())); - } else { - result.setMsg(getString(conn.getInputStream())); - } - } catch (ProtocolException e) { - log.error("Exception occurred while setting the HTTP protocol.", e); - } catch (IOException ex) { - log.error("Exception occurred while sending the GCM request.", ex); - } - - return result; - } - - private static String getString(InputStream stream) throws IOException { - if (stream != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - StringBuilder content = new StringBuilder(); - - String newLine; - do { - newLine = reader.readLine(); - if (newLine != null) { - content.append(newLine).append('\n'); - } - } while (newLine != null); - - if (content.length() > 0) { - content.setLength(content.length() - 1); - } - - return content.toString(); - } - return null; - } - - private static String getGCMRequest(String message, List registrationIds) { - JsonObject gcmRequest = new JsonObject(); - gcmRequest.addProperty("delay_while_idle", false); - gcmRequest.addProperty("time_to_live", TIME_TO_LIVE); - - //Add message to GCM request - JsonObject data = new JsonObject(); - if (message != null && !message.isEmpty()) { - data.addProperty("data", message); - gcmRequest.add("data", data); - } - - //Set device reg-ids - JsonArray regIds = new JsonArray(); - for (String regId : registrationIds) { - if (regId == null || regId.isEmpty()) { - continue; - } - regIds.add(new JsonPrimitive(regId)); - } - - gcmRequest.add("registration_ids", regIds); - return gcmRequest.toString(); - } - - private static List getGCMTokens(List devices) { - List tokens = new ArrayList<>(devices.size()); - for (Device device : devices) { - tokens.add(getGCMToken(device.getProperties())); - } - return tokens; - } - - private static String getGCMToken(List properties) { - String gcmToken = null; - for (Device.Property property : properties) { - if (AndroidPluginConstants.GCM_TOKEN.equals(property.getName())) { - gcmToken = property.getValue(); - break; - } - } - return gcmToken; - } - - public static String getConfigurationProperty(String property) { - DeviceManagementService androidDMService = MobileDeviceManagementDataHolder.getInstance(). - getAndroidDeviceManagementService(); - try { - //Get the TenantConfiguration from cache if not we'll get it from DM service - TenantConfiguration tenantConfiguration = getTenantConfigurationFromCache(); - if (tenantConfiguration == null) { - tenantConfiguration = androidDMService.getDeviceManager().getConfiguration(); - if (tenantConfiguration != null) { - addTenantConfigurationToCache(tenantConfiguration); - } - } - - if (tenantConfiguration != null) { - List configs = tenantConfiguration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (property.equals(entry.getName())) { - return (String) entry.getValue(); - } - } - } - return ""; - } catch (DeviceManagementException e) { - log.error("Exception occurred while fetching the tenant-config.",e); - } - return null; - } - - public static void resetTenantConfigCache() { - tenantConfigurationCache.remove(getTenantId()); - } - - private static void addTenantConfigurationToCache(TenantConfiguration tenantConfiguration) { - tenantConfigurationCache.put(getTenantId(), tenantConfiguration); - } - - private static TenantConfiguration getTenantConfigurationFromCache() { - return tenantConfigurationCache.get(getTenantId()); - } - - private static int getTenantId() { - return CarbonContext.getThreadLocalCarbonContext().getTenantId(); - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java deleted file mode 100644 index 798f5fef1..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.mobile.impl.android.util; - -/** - * Defines constants used by android plugin. - */ -public class AndroidPluginConstants { - - //Properties related to AD_DEVICE table - public static final String DEVICE_ID = "DEVICE_ID"; - public static final String GCM_TOKEN = "GCM_TOKEN"; - public static final String DEVICE_INFO = "DEVICE_INFO"; - public static final String SERIAL = "SERIAL"; - public static final String DEVICE_MODEL = "DEVICE_MODEL"; - public static final String DEVICE_NAME = "DEVICE_NAME"; - public static final String LATITUDE = "LATITUDE"; - public static final String LONGITUDE = "LONGITUDE"; - public static final String IMEI = "IMEI"; - public static final String IMSI = "IMSI"; - public static final String VENDOR = "VENDOR"; - public static final String OS_VERSION = "OS_VERSION"; - public static final String MAC_ADDRESS = "MAC_ADDRESS"; - - //Properties related to AD_FEATURE table - public static final String ANDROID_FEATURE_ID = "ID"; - public static final String ANDROID_FEATURE_CODE = "CODE"; - public static final String ANDROID_FEATURE_NAME = "NAME"; - public static final String ANDROID_FEATURE_DESCRIPTION = "DESCRIPTION"; - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java deleted file mode 100644 index ea93017c2..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.mobile.impl.android.util; - -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService; - -/** - * Contains utility methods used by Android plugin. - */ -public class AndroidPluginUtils { - - public static License getDefaultLicense() { - License license = new License(); - license.setName(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID); - license.setLanguage("en_US"); - license.setVersion("1.0.0"); - license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " + - "and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " + - "mobile device management program, and the loading to and removal from Your Device and Your use " + - "of certain applications and any associated software and user documentation, whether provided in " + - "\"online\" or electronic format, used in connection with the operation of or provision of services " + - "to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " + - "THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " + - "DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " + - "A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" + - "\n" + - "IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" + - "\n" + - "You agree that: (1) You understand and agree to be bound by the terms and conditions contained " + - "in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " + - "into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " + - "without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " + - "Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " + - "the cessation of Your relationship with SoR (including termination of Your employment if You are " + - "an employee or expiration or termination of Your applicable franchise or supply agreement if You " + - "are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " + - "rights not expressly granted herein."); - return license; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java deleted file mode 100644 index 48753ed4c..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.mobile.impl.android.util; - -import java.util.Map; - -/** - * Contains utility methods used by Android plugin. - */ -public class AndroidUtils { - - public static String getDeviceProperty(Map deviceProperties, String property) { - return deviceProperties.get(property); - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java deleted file mode 100644 index fe5372077..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.mobile.impl.windows; - -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.ProvisioningConfig; -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.push.notification.PushNotificationConfig; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; - -import java.util.List; - -/** - * This represents the Windows implementation of DeviceManagerService. - */ -public class WindowsDeviceManagementService implements DeviceManagementService { - - private DeviceManager deviceManager; - public static final String DEVICE_TYPE_WINDOWS = "windows"; - private static final String SUPER_TENANT_DOMAIN = "carbon.super"; - - @Override - public String getType() { - return WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS; - } - - @Override - public void init() throws DeviceManagementException { - this.deviceManager = new WindowsDeviceManager(); - } - - @Override - public DeviceManager getDeviceManager() { - return deviceManager; - } - - @Override - public ApplicationManager getApplicationManager() { - return null; - } - - @Override - public ProvisioningConfig getProvisioningConfig() { - return new ProvisioningConfig(SUPER_TENANT_DOMAIN, true); - } - - @Override - public PushNotificationConfig getPushNotificationConfig() { - return null; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java deleted file mode 100644 index b9f03cf49..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * 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.mobile.impl.windows; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.*; -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.common.license.mgt.LicenseManager; -import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; -import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; -import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; -import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginUtils; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; -import org.wso2.carbon.registry.api.RegistryException; -import org.wso2.carbon.registry.api.Resource; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -public class WindowsDeviceManager implements DeviceManager { - - private AbstractMobileDeviceManagementDAOFactory daoFactory; - private LicenseManager licenseManager; - private FeatureManager featureManager = new WindowsFeatureManager(); - private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class); - - public WindowsDeviceManager() { - this.daoFactory = new WindowsDAOFactory(); - this.licenseManager = new RegistryBasedLicenseManager(); - - License defaultLicense = WindowsPluginUtils.getDefaultLicense(); - - try { - if (licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, - MobilePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) { - licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense); - } - featureManager.addSupportedFeaturesToDB(); - } catch (LicenseManagementException e) { - log.error("Error occurred while adding default license for Windows devices", e); - } catch (DeviceManagementException e) { - throw new IllegalStateException("Error occurred while adding windows features to the DB."); - } - } - - @Override - public FeatureManager getFeatureManager() { - return featureManager; - } - - @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException { - boolean status; - Resource resource; - try { - if (log.isDebugEnabled()) { - log.debug("Persisting windows configurations in Registry"); - } - String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - StringWriter writer = new StringWriter(); - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); - Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(tenantConfiguration, writer); - - resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource(); - resource.setContent(writer.toString()); - resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); - MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource); - status = true; - } catch (MobileDeviceMgtPluginException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry instance", e); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while persisting the Registry resource of Windows configuration", e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Windows configuration", e); - } - return status; - } - - @Override - public TenantConfiguration getConfiguration() throws DeviceManagementException { - Resource resource; - try { - String windowsTenantRegistryPath = MobileDeviceManagementUtil. - getPlatformConfigPath(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - resource = MobileDeviceManagementUtil.getRegistryResource(windowsTenantRegistryPath); - if (resource != null) { - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - return (TenantConfiguration) unmarshaller.unmarshal(new StringReader( - new String((byte[]) resource.getContent(), Charset. - forName(MobilePluginConstants.CHARSET_UTF8)))); - } - return null; - } catch (MobileDeviceMgtPluginException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry instance", e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Windows configuration", e); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry resource of Windows configuration", e); - } - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - boolean status = false; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Modifying the Windows device enrollment data"); - } - WindowsDAOFactory.beginTransaction(); - if (daoFactory.getMobileDeviceDAO() != null) { - status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice); - } - WindowsDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while updating the enrollment of the " + - "Windows device : " + device.getDeviceIdentifier(), e); - } finally { - WindowsDAOFactory.closeConnection(); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - //Here we don't have anything specific to do. Hence returning. - return true; - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - MobileDevice mobileDevice; - try { - if (log.isDebugEnabled()) { - log.debug("Checking the enrollment of Windows device : " + deviceId.getId()); - } - if (daoFactory.getMobileDeviceDAO() != null) { - mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); - } else { - throw new DeviceManagementException("Error occurred while getting DAO object."); - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error occurred while checking the enrollment status of Windows device : " + deviceId.getId(); - throw new DeviceManagementException(msg, e); - } - return (mobileDevice != null); - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return true; - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException { - return true; - } - - public List getAllDevices() throws DeviceManagementException { - List devices = null; - List mobileDevices = null; - try { - if (log.isDebugEnabled()) { - log.debug("Fetching the details of all Windows devices"); - } - WindowsDAOFactory.openConnection(); - if (daoFactory.getMobileDeviceDAO() != null) { - mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices(); - } - if (mobileDevices != null) { - devices = new ArrayList<>(mobileDevices.size()); - for (MobileDevice mobileDevice : mobileDevices) { - devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); - } - } - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while fetching all Windows devices", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - return devices; - } - - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - Device device = null; - MobileDevice mobileDevice = null; - try { - if (log.isDebugEnabled()) { - log.debug("Getting the details of Windows device : '" + deviceId.getId() + "'"); - } - WindowsDAOFactory.openConnection(); - if (daoFactory.getMobileDeviceDAO() != null) { - mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); - } - device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while fetching the Windows device: '" + deviceId.getId() + "'", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - return device; - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return true; - } - - @Override - public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return false; - } - - @Override - public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser, - EnrolmentInfo.Status status) throws DeviceManagementException { - return false; - } - - @Override - public License getLicense(String languageCode) throws LicenseManagementException { - return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode); - } - - @Override - public void addLicense(License license) throws LicenseManagementException { - licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, license); - } - - @Override - public boolean requireDeviceAuthorization() { - return false; - } - - @Override - public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, - Device device) throws DeviceManagementException { - return true; - } - - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - boolean status = false; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new windows device : " + device.getDeviceIdentifier()); - } - boolean isEnrolled = this.isEnrolled( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - if (isEnrolled) { - this.modifyEnrollment(device); - } else { - WindowsDAOFactory.beginTransaction(); - if (daoFactory.getMobileDeviceDAO() != null) { - status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice); - } - WindowsDAOFactory.commitTransaction(); - } - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while enrolling the windows device : " - + device.getDeviceIdentifier(), e); - } - return status; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java deleted file mode 100644 index cdca8334c..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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.mobile.impl.windows; - -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import java.util.ArrayList; -import java.util.List; - -public class WindowsFeatureManager implements FeatureManager { - - private MobileFeatureDAO featureDAO; - - public WindowsFeatureManager() { - MobileDeviceManagementDAOFactory daoFactory = new WindowsDAOFactory(); - this.featureDAO = daoFactory.getMobileFeatureDAO(); - } - - @Override - public boolean addFeature(Feature feature) throws DeviceManagementException { - try { - WindowsDAOFactory.beginTransaction(); - MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); - featureDAO.addFeature(mobileFeature); - WindowsDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while adding the feature", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public boolean addFeatures(List features) throws DeviceManagementException { - List mobileFeatures = new ArrayList(features.size()); - for (Feature feature : features) { - mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); - } - try { - WindowsDAOFactory.beginTransaction(); - featureDAO.addFeatures(mobileFeatures); - WindowsDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while adding the features", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public Feature getFeature(String name) throws DeviceManagementException { - try { - WindowsDAOFactory.openConnection(); - MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); - Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); - return feature; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the feature", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public List getFeatures() throws DeviceManagementException { - - try { - WindowsDAOFactory.openConnection(); - List mobileFeatures = featureDAO.getAllFeatures(); - List featureList = new ArrayList(mobileFeatures.size()); - for (MobileFeature mobileFeature : mobileFeatures) { - featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); - } - return featureList; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + - "Windows platform", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public boolean removeFeature(String code) throws DeviceManagementException { - boolean status; - try { - WindowsDAOFactory.beginTransaction(); - featureDAO.deleteFeatureByCode(code); - WindowsDAOFactory.commitTransaction(); - status = true; - return status; - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while removing the feature", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public boolean addSupportedFeaturesToDB() throws DeviceManagementException { - synchronized (this) { - List supportedFeatures = getSupportedFeatures(); - List existingFeatures = this.getFeatures(); - List missingFeatures = MobileDeviceManagementUtil. - getMissingFeatures(supportedFeatures, existingFeatures); - if (missingFeatures.size() > 0) { - return this.addFeatures(missingFeatures); - } - return true; - } - } - - /** - * Get supported Windows features. - * - * @return Supported features. - */ - public static List getSupportedFeatures() { - List supportedFeatures = new ArrayList<>(); - Feature feature; - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DEVICE_LOCK"); - feature.setName("Device Lock"); - feature.setDescription("Lock the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("CAMERA"); - feature.setName("camera"); - feature.setDescription("Enable or disable camera"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DEVICE_INFO"); - feature.setName("Device info"); - feature.setDescription("Request device information"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("WIPE_DATA"); - feature.setName("Wipe Data"); - feature.setDescription("Factory reset the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("ENCRYPT_STORAGE"); - feature.setName("Encrypt storage"); - feature.setDescription("Encrypt storage"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DEVICE_RING"); - feature.setName("Ring"); - feature.setDescription("Ring the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("PASSCODE_POLICY"); - feature.setName("Password Policy"); - feature.setDescription("Set passcode policy"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DISENROLL"); - feature.setName("DisEnroll"); - feature.setDescription("DisEnroll the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("LOCK_RESET"); - feature.setName("LockReset"); - feature.setDescription("Lock Reset device"); - supportedFeatures.add(feature); - return supportedFeatures; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java deleted file mode 100644 index b4bb0bac1..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.mobile.impl.windows; - -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.DeviceManagementConstants; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; -import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; -import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; - -import java.util.ArrayList; -import java.util.List; - -public class WindowsPolicyMonitoringService implements PolicyMonitoringService { - - private static Log log = LogFactory.getLog(WindowsPolicyMonitoringService.class); - - @Override - public void notifyDevices(List list) throws PolicyComplianceException { - - } - - @Override - public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload) - throws PolicyComplianceException { - if (log.isDebugEnabled()) { - log.debug("checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); - } - List complianceFeatures = (List) compliancePayload; - List nonComplianceFeatures = new ArrayList<>(); - ComplianceData complianceData = new ComplianceData(); - - if (policy == null || compliancePayload == null) { - return complianceData; - } - - for (ComplianceFeature complianceFeature : complianceFeatures) { - if (!complianceFeature.isCompliant()) { - complianceData.setStatus(false); - nonComplianceFeatures.add(complianceFeature); - break; - } - } - complianceData.setComplianceFeatures(nonComplianceFeatures); - return complianceData; - } - - @Override - public String getType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java deleted file mode 100644 index 7fd0461c4..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.mobile.impl.windows.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsFeatureDAOImpl; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; - -public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory { - - private static final Log log = LogFactory.getLog(WindowsDAOFactory.class); - protected static DataSource dataSource; - private static ThreadLocal currentConnection = new ThreadLocal<>(); - - public WindowsDAOFactory() { - this.dataSource = getDataSourceMap().get( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - } - - @Override - public MobileDeviceDAO getMobileDeviceDAO() { - return new WindowsDeviceDAOImpl(); - } - - @Override - public MobileFeatureDAO getMobileFeatureDAO() { - return new WindowsFeatureDAOImpl(); - } - - public static void beginTransaction() throws MobileDeviceManagementDAOException { - try { - Connection conn = dataSource.getConnection(); - conn.setAutoCommit(false); - currentConnection.set(conn); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); - } - } - - public static void openConnection() throws MobileDeviceManagementDAOException { - if (currentConnection.get() == null) { - Connection conn; - try { - conn = dataSource.getConnection(); - currentConnection.set(conn); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException - ("Error occurred while retrieving data source connection", e); - } - } - } - - public static Connection getConnection() throws MobileDeviceManagementDAOException { - if (currentConnection.get() == null) { - try { - currentConnection.set(dataSource.getConnection()); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException - ("Error occurred while retrieving data source connection", e); - } - } - return currentConnection.get(); - } - - public static void commitTransaction() { - 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) { - log.error("Error occurred while committing the transaction", e); - } - } - - public static void closeConnection() { - Connection con = currentConnection.get(); - try { - con.close(); - } catch (SQLException e) { - log.error("Error occurred while close the connection"); - } - currentConnection.remove(); - } - - public static void rollbackTransaction() { - 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) { - log.warn("Error occurred while roll-backing the transaction", e); - } - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java deleted file mode 100644 index 7596b3956..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.mobile.impl.windows.dao; - -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; - -/** - * This class responsible for wrapping exceptions related on Windows device features. - */ -public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException { - - private String message; - private static final long serialVersionUID = 2021891706072918865L; - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message and - * nested exception. - * - * @param message error message - * @param nestedException exception - */ - public WindowsFeatureManagementDAOException(String message, Exception nestedException) { - super(message, nestedException); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message - * and cause. - * - * @param message the detail message. - * @param cause the cause of this exception. - */ - public WindowsFeatureManagementDAOException(String message, Throwable cause) { - super(message, cause); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message. - * - * @param message the detail message. - */ - public WindowsFeatureManagementDAOException(String message) { - super(message); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified and cause. - * - * @param cause the cause of this exception. - */ - public WindowsFeatureManagementDAOException(Throwable cause) { - super(cause); - } - - public String getMessage() { - return message; - } - - public void setErrorMessage(String errorMessage) { - this.message = errorMessage; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java deleted file mode 100644 index d8039f67f..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * 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.mobile.impl.windows.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginConstants; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils; - -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 MobileDeviceDAO for Windows Devices. - */ -public class WindowsDeviceDAOImpl implements MobileDeviceDAO { - - private static final Log log = LogFactory.getLog(WindowsDeviceDAOImpl.class); - - @Override - public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - MobileDevice mobileDevice = null; - try { - conn = WindowsDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + - " OS_VERSION, DEVICE_NAME " + - "FROM WIN_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, mblDeviceId); - rs = stmt.executeQuery(); - - while (rs.next()) { - mobileDevice = WindowsUtils.loadMobileDevices(rs); - Map propertyMap = new HashMap<>(); - propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); - propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); - propertyMap.put(WindowsPluginConstants.MAC_ADDRESS, rs.getString(WindowsPluginConstants.MAC_ADDRESS)); - propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME)); - - mobileDevice.setDeviceProperties(propertyMap); - } - if (log.isDebugEnabled()) { - log.debug("All Windows device details have fetched from Windows database."); - } - return mobileDevice; - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String createDBQuery = - "INSERT INTO WIN_DEVICE(DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, " + - "IMSI, OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, " + - "MAC_ADDRESS, DEVICE_NAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, mobileDevice.getMobileDeviceId()); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(2, properties.get(WindowsPluginConstants.CHANNEL_URI)); - stmt.setString(3, properties.get(WindowsPluginConstants.DEVICE_INFO)); - stmt.setString(4, mobileDevice.getImei()); - stmt.setString(5, mobileDevice.getImsi()); - stmt.setString(6, mobileDevice.getOsVersion()); - stmt.setString(7, mobileDevice.getModel()); - stmt.setString(8, mobileDevice.getVendor()); - stmt.setString(9, mobileDevice.getLatitude()); - stmt.setString(10, mobileDevice.getLongitude()); - stmt.setString(11, mobileDevice.getSerial()); - stmt.setString(12, properties.get(WindowsPluginConstants.MAC_ADDRESS)); - stmt.setString(13, properties.get(WindowsPluginConstants.DEVICE_NAME)); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows device " + mobileDevice.getMobileDeviceId() + " data has been" + - " added to the Windows database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while adding the Windows device '" + - mobileDevice.getMobileDeviceId() + "' to the Windows db.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE WIN_DEVICE SET CHANNEL_URI = ?, DEVICE_INFO = ?, IMEI = ?, IMSI = ?, " + - "OS_VERSION = ?, DEVICE_MODEL = ?, VENDOR = ?, LATITUDE = ?, LONGITUDE = ?, " + - "SERIAL = ?, MAC_ADDRESS = ?, DEVICE_NAME = ? WHERE DEVICE_ID = ?"; - - stmt = conn.prepareStatement(updateDBQuery); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(1, properties.get(WindowsPluginConstants.CHANNEL_URI)); - stmt.setString(2, properties.get(WindowsPluginConstants.DEVICE_INFO)); - stmt.setString(3, mobileDevice.getImei()); - stmt.setString(4, mobileDevice.getImsi()); - stmt.setString(5, mobileDevice.getOsVersion()); - stmt.setString(6, mobileDevice.getModel()); - stmt.setString(7, mobileDevice.getVendor()); - stmt.setString(8, mobileDevice.getLatitude()); - stmt.setString(9, mobileDevice.getLongitude()); - stmt.setString(10, mobileDevice.getSerial()); - stmt.setString(11, properties.get(WindowsPluginConstants.MAC_ADDRESS)); - stmt.setString(12, properties.get(WindowsPluginConstants.DEVICE_NAME)); - stmt.setString(13, mobileDevice.getMobileDeviceId()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows device " + mobileDevice.getMobileDeviceId() + " data has been" + - " modified."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while modifying the Windows device '" + - mobileDevice.getMobileDeviceId() + "' data.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String deleteDBQuery = "DELETE FROM WIN_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, mblDeviceId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows device " + mblDeviceId + " data has deleted" + - " from the windows database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while deleting windows device '" + - mblDeviceId + "'", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public List getAllMobileDevices() throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - MobileDevice mobileDevice; - List mobileDevices = new ArrayList<>(); - try { - conn = WindowsDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + - " OS_VERSION, DEVICE_NAME " + - "FROM WIN_DEVICE"; - stmt = conn.prepareStatement(selectDBQuery); - rs = stmt.executeQuery(); - - while (rs.next()) { - mobileDevice = WindowsUtils.loadMobileDevices(rs); - Map propertyMap = new HashMap<>(); - propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); - propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); - propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME)); - mobileDevice.setDeviceProperties(propertyMap); - mobileDevices.add(mobileDevice); - } - if (log.isDebugEnabled()) { - log.debug("All Windows device details have fetched from Windows database."); - } - return mobileDevices; - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java deleted file mode 100644 index 007eedb78..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * 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.mobile.impl.windows.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsFeatureManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginConstants; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -/** - * Implement MobileFeatureDAO for Windows devices. - */ -public class WindowsFeatureDAOImpl implements MobileFeatureDAO { - - private static final Log log = LogFactory.getLog(WindowsFeatureDAOImpl.class); - - @Override - public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.executeUpdate(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while adding windows feature '" + - mobileFeature.getName() + "' into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - stmt = conn.prepareStatement("INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"); - for (MobileFeature mobileFeature : mobileFeatures) { - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.addBatch(); - } - stmt.executeBatch(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while adding windows features into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE WIN_FEATURE SET NAME = ?, DESCRIPTION = ?" + - "WHERE CODE = ?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, mobileFeature.getName()); - stmt.setString(2, mobileFeature.getDescription()); - stmt.setString(3, mobileFeature.getCode()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows Feature " + mobileFeature.getCode() + " data has been " + - "modified."); - } - } - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException("Error occurred while updating the Windows Feature '" + - mobileFeature.getCode() + "' to the Windows db.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "DELETE FROM WIN_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while deleting windows feature '" + - mblFeatureId + "' from Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "DELETE FROM WIN_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while deleting windows feature '" + - mblFeatureCode + "' from Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); - mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); - mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - } - return mobileFeature; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while retrieving windows feature '" + - mblFeatureId + "' from the Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); - mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); - mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - } - return mobileFeature; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while retrieving windows feature '" + - mblFeatureCode + "' from the Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public List getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException { - return this.getAllFeatures(); - } - - @Override - public List getAllFeatures() throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - List features = new ArrayList<>(); - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE"; - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - MobileFeature mobileFeature; - while (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); - mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); - mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - features.add(mobileFeature); - } - return features; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException("Error occurred while retrieving all " + - "windows features from the Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java deleted file mode 100644 index edae380d4..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.mobile.impl.windows.util; - -/** - * Define constance used by Windows plugin. - */ -public class WindowsPluginConstants { - - //properties related to database table WINDOWS_DEVICE - public static final String DEVICE_ID = "DEVICE_ID"; - public static final String CHANNEL_URI = "CHANNEL_URI"; - public static final String DEVICE_INFO = "DEVICE_INFO"; - public static final String IMEI = "IMEI"; - public static final String IMSI = "IMSI"; - public static final String OS_VERSION = "OS_VERSION"; - public static final String DEVICE_MODEL = "DEVICE_MODEL"; - public static final String VENDOR = "VENDOR"; - public static final String LATITUDE = "LATITUDE"; - public static final String LONGITUDE = "LONGITUDE"; - public static final String SERIAL = "SERIAL"; - public static final String MAC_ADDRESS = "MAC_ADDRESS"; - public static final String DEVICE_NAME = "DEVICE_NAME"; - - //Properties related to WIN_FEATURE table - public static final String WINDOWS_FEATURE_ID = "ID"; - public static final String WINDOWS_FEATURE_CODE = "CODE"; - public static final String WINDOWS_FEATURE_NAME = "NAME"; - public static final String WINDOWS_FEATURE_DESCRIPTION = "DESCRIPTION"; - - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java deleted file mode 100644 index a3b389c9b..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.mobile.impl.windows.util; - -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService; - -/** - * Contains utility method used by Windows plugin. - */ -public class WindowsPluginUtils { - - public static License getDefaultLicense() { - License license = new License(); - license.setName(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS); - license.setLanguage("en_US"); - license.setVersion("1.0.0"); - license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " + - "and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " + - "mobile device management program, and the loading to and removal from Your Device and Your use " + - "of certain applications and any associated software and user documentation, whether provided in " + - "\"online\" or electronic format, used in connection with the operation of or provision of services " + - "to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " + - "THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " + - "DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " + - "A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" + - "\n" + - "IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" + - "\n" + - "You agree that: (1) You understand and agree to be bound by the terms and conditions contained " + - "in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " + - "into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " + - "without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " + - "Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " + - "the cessation of Your relationship with SoR (including termination of Your employment if You are " + - "an employee or expiration or termination of Your applicable franchise or supply agreement if You " + - "are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " + - "rights not expressly granted herein."); - return license; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java deleted file mode 100644 index e4ba56346..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.mobile.impl.windows.util; - -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; - -import java.sql.ResultSet; -import java.sql.SQLException; - -/** - * Contains utility methods which are used by Windows plugin. - */ -public class WindowsUtils { - - public static MobileDevice loadMobileDevices(ResultSet rs) throws SQLException { - MobileDevice mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); - mobileDevice.setImei(rs.getString(WindowsPluginConstants.IMEI)); - mobileDevice.setImsi(rs.getString(WindowsPluginConstants.IMSI)); - mobileDevice.setModel(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); - mobileDevice.setVendor(rs.getString(WindowsPluginConstants.VENDOR)); - mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.LATITUDE)); - mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.LONGITUDE)); - mobileDevice.setSerial(rs.getString(WindowsPluginConstants.SERIAL)); - mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); - return mobileDevice; - } - - public static Feature getMobileFeature() { - Feature feature = new Feature(); - return feature; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java index 869904e81..6444afd90 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.mobile.internal; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; import org.wso2.carbon.registry.core.service.RegistryService; /** @@ -29,7 +28,6 @@ public class MobileDeviceManagementDataHolder { private RegistryService registryService; private DeviceManagementService androidDeviceManagementService; - private GCMService gcmService; private static MobileDeviceManagementDataHolder thisInstance = new MobileDeviceManagementDataHolder(); @@ -57,11 +55,4 @@ public class MobileDeviceManagementDataHolder { this.androidDeviceManagementService = androidDeviceManagementService; } - public GCMService getGCMService() { - return gcmService; - } - - public void setGCMService(GCMService gcmService) { - this.gcmService = gcmService; - } } diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index 92404b67a..5b7f85931 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -23,20 +23,13 @@ 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.mobile.common.MobileDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidPolicyMonitoringService; -import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsPolicyMonitoringService; import org.wso2.carbon.ndatasource.core.DataSourceService; -import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; import org.wso2.carbon.registry.core.service.RegistryService; import java.util.Map; @@ -60,8 +53,6 @@ import java.util.Map; */ public class MobileDeviceManagementServiceComponent { - private ServiceRegistration androidServiceRegRef; - private ServiceRegistration windowsServiceRegRef; private ServiceRegistration gcmServiceRegRef; private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); @@ -100,30 +91,7 @@ public class MobileDeviceManagementServiceComponent { log.error("Exception occurred while initializing mobile device management database schema", e); } } - DeviceManagementService androidDeviceManagementService = new AndroidDeviceManagementService(); - GCMService gcmService = new GCMService(); - androidServiceRegRef = - bundleContext.registerService(DeviceManagementService.class.getName(), - androidDeviceManagementService, null); - windowsServiceRegRef = - bundleContext.registerService(DeviceManagementService.class.getName(), - new WindowsDeviceManagementService(), null); - - gcmServiceRegRef = - bundleContext.registerService(GCMService.class.getName(), gcmService, null); - - - // Policy management service - - bundleContext.registerService(PolicyMonitoringService.class, - new AndroidPolicyMonitoringService(), null); - bundleContext.registerService(PolicyMonitoringService.class, - new WindowsPolicyMonitoringService(), null); - - MobileDeviceManagementDataHolder.getInstance().setAndroidDeviceManagementService( - androidDeviceManagementService); - MobileDeviceManagementDataHolder.getInstance().setGCMService(gcmService); if (log.isDebugEnabled()) { log.debug("Mobile Device Management Service Component has been successfully activated"); } @@ -137,12 +105,6 @@ public class MobileDeviceManagementServiceComponent { log.debug("De-activating Mobile Device Management Service Component"); } try { - if (androidServiceRegRef != null) { - androidServiceRegRef.unregister(); - } - if (windowsServiceRegRef != null) { - windowsServiceRegRef.unregister(); - } if (gcmServiceRegRef != null) { gcmServiceRegRef.unregister(); } diff --git a/components/mobile-plugins/mobile-base-plugin/pom.xml b/components/mobile-plugins/mobile-base-plugin/pom.xml index af83bb23e..16d0327bd 100644 --- a/components/mobile-plugins/mobile-base-plugin/pom.xml +++ b/components/mobile-plugins/mobile-base-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins mobile-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/pom.xml b/components/mobile-plugins/pom.xml index fd8749a3e..276cf1072 100644 --- a/components/mobile-plugins/pom.xml +++ b/components/mobile-plugins/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins carbon-device-mgt-plugins-parent - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../../pom.xml diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml index a6a71d4bc..944446791 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/pom.xml @@ -3,7 +3,7 @@ ~ ~ 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. + ~ in compliance with the License.a ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 @@ -16,14 +16,12 @@ ~ under the License. --> - + windows-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml @@ -131,6 +129,12 @@ org.apache.cxf cxf-rt-bindings-http + + + org.slf4j + slf4j-api + + org.apache.ws.security @@ -265,6 +269,12 @@ org.wso2.carbon.identity org.wso2.carbon.identity.oauth provided + + + org.slf4j + slf4j-api + + javax.cache @@ -308,7 +318,6 @@ io.swagger swagger-annotations - provided diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/common/util/WindowsAPIUtils.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/common/util/WindowsAPIUtils.java index 6b8462e9f..13f115240 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/common/util/WindowsAPIUtils.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/common/util/WindowsAPIUtils.java @@ -27,7 +27,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; @@ -165,7 +165,7 @@ public class WindowsAPIUtils { getDeviceManagementService().updateOperation(deviceIdentifier, operation); } - public static TenantConfiguration getTenantConfiguration() throws DeviceManagementException { + public static PlatformConfiguration getTenantConfiguration() throws DeviceManagementException { return getDeviceManagementService().getConfiguration( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/authbst/BSTProvider.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/authbst/BSTProvider.java index a29170b37..fda4845a3 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/authbst/BSTProvider.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/authbst/BSTProvider.java @@ -18,6 +18,7 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.authbst; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; @@ -33,6 +34,7 @@ import javax.ws.rs.core.Response; /** * Interface for handling authentication request comes via MDM login page. */ +@Api(value = "BSTProvider", description = "Windows Device Management REST-API implementation.") @Path("/bst") public interface BSTProvider { diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java index f943affb0..018db96e5 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java @@ -18,10 +18,11 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; @@ -36,6 +37,7 @@ import javax.ws.rs.core.MediaType; @WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) +@Api(value = "ConfigurationMgtService", description = "Windows Device Management REST-API implementation.") public interface ConfigurationMgtService { /** @@ -56,7 +58,7 @@ public interface ConfigurationMgtService { @ApiResponse(code = 201, message = "Windows platform configuration saved successfully"), @ApiResponse(code = 500, message = "Internal Server Error") }) - Message ConfigureSettings(TenantConfiguration configuration) throws WindowsConfigurationException; + Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException; /** * Retrieve Tenant configurations according to the device type. @@ -69,13 +71,13 @@ public interface ConfigurationMgtService { httpMethod = "GET", value = "Getting Windows Platform Configurations", notes = "Get the Windows platform configuration details using this REST API", - response = TenantConfiguration.class + response = PlatformConfiguration.class ) @ApiResponses(value = { @ApiResponse(code = 200, message = "Get Windows Configurations"), @ApiResponse(code = 500, message = "Server Error") }) - TenantConfiguration getConfiguration() throws WindowsConfigurationException; + PlatformConfiguration getConfiguration() throws WindowsConfigurationException; /** * Update Tenant Configurations for the specific Device type. @@ -97,5 +99,5 @@ public interface ConfigurationMgtService { @ApiResponse(code = 500, message = "Error occurred while modifying configuration settings of " + "windows platform") }) - Message updateConfiguration(TenantConfiguration configuration) throws WindowsConfigurationException; + Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException; } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/impl/ConfigurationMgtServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/impl/ConfigurationMgtServiceImpl.java index 1fd0b2c84..1c7734d42 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/impl/ConfigurationMgtServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/impl/ConfigurationMgtServiceImpl.java @@ -23,7 +23,8 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants; import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; @@ -54,7 +55,7 @@ public class ConfigurationMgtServiceImpl { * @throws WindowsConfigurationException */ @POST - public Message ConfigureSettings(TenantConfiguration configuration) throws WindowsConfigurationException { + public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException { Message responseMsg = new Message(); ConfigurationEntry licenseEntry = null; String message; @@ -106,15 +107,15 @@ public class ConfigurationMgtServiceImpl { * @throws WindowsConfigurationException */ @GET - public TenantConfiguration getConfiguration() throws WindowsConfigurationException { + public PlatformConfiguration getConfiguration() throws WindowsConfigurationException { String msg; - TenantConfiguration tenantConfiguration = null; + PlatformConfiguration PlatformConfiguration = null; try { if (WindowsAPIUtils.getDeviceManagementService(). getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS) != null) { - tenantConfiguration = WindowsAPIUtils.getDeviceManagementService(). + PlatformConfiguration = WindowsAPIUtils.getDeviceManagementService(). getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - List configs = tenantConfiguration.getConfiguration(); + List configs = PlatformConfiguration.getConfiguration(); ConfigurationEntry entry = new ConfigurationEntry(); License license = WindowsAPIUtils.getDeviceManagementService().getLicense( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, PluginConstants. @@ -124,7 +125,7 @@ public class ConfigurationMgtServiceImpl { entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY); entry.setValue(license.getText()); configs.add(entry); - tenantConfiguration.setConfiguration(configs); + PlatformConfiguration.setConfiguration(configs); } } } catch (DeviceManagementException e) { @@ -132,7 +133,7 @@ public class ConfigurationMgtServiceImpl { log.error(msg, e); throw new WindowsConfigurationException(msg, e); } - return tenantConfiguration; + return PlatformConfiguration; } /** @@ -143,7 +144,7 @@ public class ConfigurationMgtServiceImpl { * @throws WindowsConfigurationException */ @PUT - public Message updateConfiguration(TenantConfiguration configuration) throws WindowsConfigurationException { + public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException { String message; Message responseMsg = new Message(); ConfigurationEntry licenseEntry = null; diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java index 34ff654fd..be175c9f1 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java @@ -27,7 +27,6 @@ import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; -import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import java.util.List; @@ -37,7 +36,6 @@ import java.util.List; * All end points supports JSON, XMl with content negotiation. */ @Api(value = "DeviceManagementService", description = "Windows Device Management REST-API implementation.") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface DeviceManagementService { diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/discovery/DiscoveryService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/discovery/DiscoveryService.java index b4a206fce..3bd6c7cb6 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/discovery/DiscoveryService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/discovery/DiscoveryService.java @@ -18,6 +18,7 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.discovery; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; @@ -43,6 +44,7 @@ import javax.xml.ws.soap.SOAPBinding; @WebService(targetNamespace = PluginConstants.DISCOVERY_SERVICE_TARGET_NAMESPACE, name = "IDiscoveryService") @BindingType(value = SOAPBinding.SOAP12HTTP_BINDING) +@Api(value = "DiscoveryService", description = "Windows Device Management REST-API implementation.") public interface DiscoveryService { @POST diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/policymgtservice/PolicyMgtService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/policymgtservice/PolicyMgtService.java index 348d3068f..bb1ed19b0 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/policymgtservice/PolicyMgtService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/policymgtservice/PolicyMgtService.java @@ -22,18 +22,15 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; - import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; -import javax.jws.WebService; import javax.ws.rs.*; /** * Endpoint for Enforce Effective Policy. */ @Api(value = "PolicyMgtService", description = "Windows Device Management REST-API implementation.") -@WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface PolicyMgtService { diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/wstep/impl/CertificateEnrollmentServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/wstep/impl/CertificateEnrollmentServiceImpl.java index b4e7a54ec..b21304e8d 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/wstep/impl/CertificateEnrollmentServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/wstep/impl/CertificateEnrollmentServiceImpl.java @@ -32,7 +32,7 @@ import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; -import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants; import org.wso2.carbon.mdm.mobileservices.windows.common.beans.CacheEntry; import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.CertificateGenerationException; @@ -372,7 +372,7 @@ public class CertificateEnrollmentServiceImpl implements CertificateEnrollmentSe */ private List getTenantConfigurationData() throws DeviceManagementException { if (WindowsAPIUtils.getTenantConfiguration() != null) { - TenantConfiguration configuration = WindowsAPIUtils.getTenantConfiguration(); + PlatformConfiguration configuration = WindowsAPIUtils.getTenantConfiguration(); return configuration.getConfiguration(); } else { return null; diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 168cb1c53..b19ad6fa7 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -197,11 +197,11 @@ class="org.wso2.carbon.mdm.mobileservices.windows.services.wstep.util.MessageHandler"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice.impl.ConfigurationMgtServiceImpl"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice.impl.PolicyMgtServiceImpl"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.devicemgtservice.impl.DeviceManagementServiceImpl"/> diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/pom.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/pom.xml index 92aa9f340..7f5e0927b 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/pom.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/pom.xml @@ -18,20 +18,18 @@ ~ under the License. --> - + windows-plugin org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.mobile.windows.ui - 2.1.0-SNAPSHOT + 2.1.1-SNAPSHOT WSO2 Carbon - Mobile Windows UI pom diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs index cfdb0ed54..c64e01b4f 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs @@ -1,3 +1,20 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{#zone "device-opetations"}}
Operations diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-edit/policy-edit.hbs b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-edit/policy-edit.hbs index c4bb415a1..d45fcc004 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-edit/policy-edit.hbs +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-edit/policy-edit.hbs @@ -1 +1,18 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{unit "mdm.unit.policy.edit"}} \ No newline at end of file diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-view/policy-view.hbs b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-view/policy-view.hbs index 12cffe6bd..e8a910cb1 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-view/policy-view.hbs +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-view/policy-view.hbs @@ -1 +1,18 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{unit "mdm.unit.policy.view"}} \ No newline at end of file diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-wizard/policy-wizard.hbs b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-wizard/policy-wizard.hbs index 0669d1ca6..9e1fd3b09 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-wizard/policy-wizard.hbs +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.policy-wizard/policy-wizard.hbs @@ -1 +1,18 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} {{unit "mdm.unit.policy.wizard"}} \ No newline at end of file diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/public/css/styles.css b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/public/css/styles.css new file mode 100644 index 000000000..04e2a2611 --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/public/css/styles.css @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +.circle { + background: none repeat scroll 0 0 #191919; + border-radius: 50px; + height: 50px; + padding: 10px; + width: 50px; + color: #fff; +} +.padding-top-double { + padding-top: 20px; +} +.padding-double { + padding: 20px; +} +.grey { + color: #333; +} +hr { + display: block; + height: 1px; + border: 0; + border-top: 1px solid #7f7f7f; + margin: 1em 0; + padding: 0; + opacity: 0.2; +} +.light-grey { + color: #7c7c7c; +} +.uppercase { + text-transform: uppercase; +} +.grey-bg { + background-color: #f6f4f4; +} + +.doc-link { + background: #11375B; + padding: 20px; + color: white; + margin-top: 0; +} + +.doc-link a { + color: white; +} \ No newline at end of file diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs index ad002615c..638a5e26d 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/type-view.hbs @@ -1,5 +1,22 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}}
-

Windows Mobile

+

Windows Mobile


@@ -7,28 +24,26 @@
- +

What it Does

-
+

Connect and manage your Windows device with WSO2 IoT Server.


What You Need


    -
  • STEP 01   Windows - Mobile. -
  • -
  • STEP 02   Go ahead - and click [Enroll Device]. +
  • STEP 01   Windows Mobile.
  • +
  • STEP 02   Go ahead and click [Enroll + Device].
  • -
  • STEP 03   Proceed - to [Prepare] section. +
  • STEP 03   Proceed to [Prepare] + section.

@@ -36,7 +51,7 @@ Enroll Device -

+

@@ -44,11 +59,8 @@
  • 01 Scan QR code.
  • -
  • 02 Follow instructions in wizard. -
  • -
  • 03 Configure your workspace - account -
  • +
  • 02 Follow instructions in wizard.
  • +
  • 03 Configure your workspace account

@@ -63,12 +75,12 @@
-
+