From 8656f84ac6c0cd0ca9d8bb1d4d3a9cd92377da7a Mon Sep 17 00:00:00 2001 From: NuwanSameera Date: Wed, 30 Mar 2016 16:14:42 +0530 Subject: [PATCH] Move device type plugins to iot-plugins --- .../impl/AndroidSenseControllerService.java | 667 ------------------ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 41 -- .../src/main/webapp/WEB-INF/web.xml | 49 -- .../pom.xml | 17 +- .../impl/AndroidSenseControllerService.java | 235 ++++++ .../AndroidSenseControllerServiceImpl.java | 443 ++++++++++++ .../impl/AndroidSenseManagerService.java | 62 ++ .../impl/AndroidSenseManagerServiceImpl.java} | 86 +-- .../transport/AndroidSenseMQTTConnector.java | 11 +- .../service/impl/util/APIUtil.java | 2 +- .../service/impl/util/DeviceData.java | 2 +- .../service/impl/util/SensorData.java | 2 +- .../src/main/webapp/META-INF/permissions.xml | 71 +- .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 8 +- .../src/main/webapp/WEB-INF/web.xml | 0 .../iot-plugins/androidsense-plugin/pom.xml | 3 +- .../pom.xml | 170 ----- .../impl/ArduinoControllerService.java | 300 -------- .../impl/transport/ArduinoMQTTConnector.java | 193 ----- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 48 -- .../pom.xml | 180 ----- .../service/impl/ArduinoManagerService.java | 274 ------- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 40 -- .../src/main/webapp/WEB-INF/web.xml | 51 -- .../pom.xml | 162 ++--- .../impl/ArduinoControllerService.java | 85 +++ .../impl/ArduinoControllerServiceImpl.java | 200 ++++++ .../service/impl/ArduinoManagerService.java | 68 ++ .../impl/ArduinoManagerServiceImpl.java | 240 +++++++ .../arduino}/service/impl/dto/DeviceData.java | 2 +- .../arduino}/service/impl/dto/SensorData.java | 2 +- .../impl/exception/ArduinoException.java | 2 +- .../arduino/service/impl}/util/APIUtil.java | 3 +- .../impl/util/ArduinoServiceUtils.java | 14 +- .../src/main/webapp/META-INF/permissions.xml | 44 +- .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 10 +- .../src/main/webapp/WEB-INF/web.xml | 0 components/iot-plugins/arduino-plugin/pom.xml | 3 +- .../pom.xml | 243 ------- .../api/DigitalDisplayControllerService.java | 432 ------------ .../api/DigitalDisplayManagerService.java | 243 ------- .../src/main/webapp/WEB-INF/web.xml | 68 -- .../pom.xml | 35 +- .../impl/DigitalDisplayControllerService.java | 175 +++++ .../DigitalDisplayControllerServiceImpl.java | 242 +++++++ .../impl/DigitalDisplayManagerService.java | 59 ++ .../DigitalDisplayManagerServiceImpl.java | 201 ++++++ .../service/impl}/dto/DeviceJSON.java | 2 +- .../exception/DigitalDisplayException.java | 2 +- .../service/impl}/model/ScreenShotModel.java | 2 +- .../service/impl/util/APIUtil.java | 2 +- .../util/DigitalDisplayMQTTConnector.java | 7 +- ...DigitalDisplayWebSocketServerEndPoint.java | 2 +- .../src/main/webapp/META-INF/permissions.xml | 137 ++++ .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 7 +- .../src/main/webapp/WEB-INF/web.xml | 0 .../digital-display-plugin/pom.xml | 3 +- .../pom.xml | 254 ------- .../webapp/META-INF/webapp-classloading.xml | 33 - .../webapp/META-INF/webapp-classloading.xml | 33 - .../src/main/webapp/WEB-INF/cxf-servlet.xml | 40 -- .../src/main/webapp/WEB-INF/web.xml | 62 -- .../pom.xml | 28 +- .../service/impl/DroneControllerService.java | 46 ++ .../impl/DroneControllerServiceImpl.java} | 52 +- .../service/impl/DroneManagerService.java | 69 ++ .../impl/DroneManagerServiceImpl.java} | 229 +++--- .../service}/impl/DroneRealTimeService.java | 6 +- .../exception/DroneAnalyzerException.java | 2 +- .../transport/DroneAnalyzerXMPPConnector.java | 4 +- .../impl/trasformer/MessageTransformer.java | 2 +- .../service}/impl/util/APIUtil.java | 2 +- .../impl/util/DroneAnalyzerServiceUtils.java | 4 +- .../src/main/webapp/META-INF/permissions.xml | 43 +- .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 10 +- .../src/main/webapp/WEB-INF/web.xml | 0 .../iot-plugins/drone-analyzer-plugin/pom.xml | 3 +- .../pom.xml | 2 +- .../org.wso2.carbon.device.mgt.iot/pom.xml | 2 +- components/iot-plugins/pom.xml | 12 +- .../pom.xml | 158 ----- .../impl/RaspberryPiControllerService.java | 295 -------- .../webapp/META-INF/webapp-classloading.xml | 33 - .../webapp/META-INF/webapp-classloading.xml | 33 - .../src/main/webapp/WEB-INF/cxf-servlet.xml | 43 -- .../src/main/webapp/WEB-INF/web.xml | 50 -- .../pom.xml | 20 +- .../impl/RaspberryPiControllerService.java | 77 ++ .../RaspberryPiControllerServiceImpl.java | 221 ++++++ .../impl/RaspberryPiManagerService.java | 72 ++ .../impl/RaspberryPiManagerServiceImpl.java} | 114 +-- .../service/impl/dto/DeviceData.java | 2 +- .../service/impl/dto/SensorData.java | 2 +- .../impl/exception/RaspberrypiException.java | 2 +- .../transport/RaspberryPiMQTTConnector.java | 6 +- .../service/impl/util/APIUtil.java | 2 +- .../impl/util/RaspberrypiServiceUtils.java | 6 +- .../src/main/webapp/META-INF/permissions.xml | 64 +- .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 10 +- .../src/main/webapp/WEB-INF/web.xml | 0 .../iot-plugins/raspberrypi-plugin/pom.xml | 3 +- .../pom.xml | 262 ------- .../VirtualFireAlarmControllerService.java | 614 ---------------- .../webapp/META-INF/webapp-classloading.xml | 33 - .../webapp/META-INF/webapp-classloading.xml | 33 - .../src/main/webapp/WEB-INF/cxf-servlet.xml | 39 - .../src/main/webapp/WEB-INF/web.xml | 65 -- .../pom.xml | 15 +- .../VirtualFireAlarmControllerService.java | 157 +++++ ...VirtualFireAlarmControllerServiceImpl.java | 468 ++++++++++++ .../impl/VirtualFireAlarmManagerService.java | 71 ++ .../VirtualFireAlarmManagerServiceImpl.java} | 108 +-- .../service/impl/dto/DeviceData.java | 2 +- .../service/impl/dto/SensorData.java | 2 +- .../exception/VirtualFireAlarmException.java | 2 +- .../VirtualFireAlarmMQTTConnector.java | 10 +- .../VirtualFireAlarmXMPPConnector.java | 9 +- .../service/impl/util/APIUtil.java | 2 +- .../service/impl/util/SecurityManager.java | 4 +- .../util/VirtualFireAlarmServiceUtils.java | 14 +- .../service/impl/util/scep/ContentType.java | 2 +- .../service/impl/util/scep/SCEPOperation.java | 2 +- .../src/main/webapp/META-INF/permissions.xml | 73 +- .../webapp/META-INF/webapp-classloading.xml | 0 .../src/main/webapp/WEB-INF/cxf-servlet.xml | 14 +- .../src/main/webapp/WEB-INF/web.xml | 0 .../virtual-fire-alarm-plugin/pom.xml | 3 +- pom.xml | 2 +- 133 files changed, 4018 insertions(+), 5791 deletions(-) delete mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/AndroidSenseControllerService.java delete mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/web.xml rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.manager.api => org.wso2.carbon.device.mgt.iot.androidsense.service.impl}/pom.xml (93%) create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerService.java rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager/service/impl/AndroidSenseManagerService.java => org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java} (59%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller => org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense}/service/impl/transport/AndroidSenseMQTTConnector.java (96%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager => org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense}/service/impl/util/APIUtil.java (94%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller => org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense}/service/impl/util/DeviceData.java (82%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller => org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense}/service/impl/util/SensorData.java (90%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.controller.api => org.wso2.carbon.device.mgt.iot.androidsense.service.impl}/src/main/webapp/META-INF/permissions.xml (66%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.controller.api => org.wso2.carbon.device.mgt.iot.androidsense.service.impl}/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.controller.api => org.wso2.carbon.device.mgt.iot.androidsense.service.impl}/src/main/webapp/WEB-INF/cxf-servlet.xml (80%) rename components/iot-plugins/androidsense-plugin/{org.wso2.carbon.device.mgt.iot.androidsense.controller.api => org.wso2.carbon.device.mgt.iot.androidsense.service.impl}/src/main/webapp/WEB-INF/web.xml (100%) delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/pom.xml delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/ArduinoControllerService.java delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/transport/ArduinoMQTTConnector.java delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/pom.xml delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager/service/impl/ArduinoManagerService.java delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/web.xml rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api => arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl}/pom.xml (61%) create mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java create mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java create mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java create mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java rename components/iot-plugins/arduino-plugin/{org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller => org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino}/service/impl/dto/DeviceData.java (93%) rename components/iot-plugins/arduino-plugin/{org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller => org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino}/service/impl/dto/SensorData.java (91%) rename components/iot-plugins/arduino-plugin/{org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller => org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino}/service/impl/exception/ArduinoException.java (92%) rename components/iot-plugins/{digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api => arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl}/util/APIUtil.java (96%) rename components/iot-plugins/arduino-plugin/{org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller => org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino}/service/impl/util/ArduinoServiceUtils.java (92%) rename components/iot-plugins/arduino-plugin/{org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl => org.wso2.carbon.device.mgt.iot.arduino.service.impl}/src/main/webapp/META-INF/permissions.xml (68%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api => arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl}/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/iot-plugins/{digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api => arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl}/src/main/webapp/WEB-INF/cxf-servlet.xml (77%) rename components/iot-plugins/arduino-plugin/{org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl => org.wso2.carbon.device.mgt.iot.arduino.service.impl}/src/main/webapp/WEB-INF/web.xml (100%) delete mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/pom.xml delete mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/DigitalDisplayControllerService.java delete mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api/DigitalDisplayManagerService.java delete mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/WEB-INF/web.xml rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl}/pom.xml (86%) create mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerService.java create mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerServiceImpl.java create mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerService.java create mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerServiceImpl.java rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl}/dto/DeviceJSON.java (93%) rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl}/exception/DigitalDisplayException.java (92%) rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl}/model/ScreenShotModel.java (89%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager => digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay}/service/impl/util/APIUtil.java (96%) rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl}/util/DigitalDisplayMQTTConnector.java (95%) rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl}/websocket/DigitalDisplayWebSocketServerEndPoint.java (95%) create mode 100644 components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/META-INF/permissions.xml rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl => digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl}/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl}/src/main/webapp/WEB-INF/cxf-servlet.xml (85%) rename components/iot-plugins/digital-display-plugin/{org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api => org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl}/src/main/webapp/WEB-INF/web.xml (100%) delete mode 100644 components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/pom.xml delete mode 100644 components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/META-INF/webapp-classloading.xml delete mode 100644 components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/META-INF/webapp-classloading.xml delete mode 100644 components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/web.xml rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl}/pom.xml (91%) create mode 100644 components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerService.java rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java} (51%) create mode 100644 components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerService.java rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api/impl/DroneManagerService.java => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java} (59%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service}/impl/DroneRealTimeService.java (93%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service}/impl/exception/DroneAnalyzerException.java (92%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service}/impl/transport/DroneAnalyzerXMPPConnector.java (97%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service}/impl/trasformer/MessageTransformer.java (98%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service}/impl/util/APIUtil.java (96%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service}/impl/util/DroneAnalyzerServiceUtils.java (95%) rename components/iot-plugins/{digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api => drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl}/src/main/webapp/META-INF/permissions.xml (70%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl => drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl}/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl}/src/main/webapp/WEB-INF/cxf-servlet.xml (80%) rename components/iot-plugins/drone-analyzer-plugin/{org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api => org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl}/src/main/webapp/WEB-INF/web.xml (100%) delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/RaspberryPiControllerService.java delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/web.xml rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl}/pom.xml (89%) create mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java create mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java create mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager/service/impl/RaspberryPiManagerService.java => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java} (73%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi}/service/impl/dto/DeviceData.java (93%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi}/service/impl/dto/SensorData.java (90%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi}/service/impl/exception/RaspberrypiException.java (92%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi}/service/impl/transport/RaspberryPiMQTTConnector.java (96%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi}/service/impl/util/APIUtil.java (96%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi}/service/impl/util/RaspberrypiServiceUtils.java (97%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api => raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl}/src/main/webapp/META-INF/permissions.xml (58%) rename components/iot-plugins/{digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api => raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl}/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl}/src/main/webapp/WEB-INF/cxf-servlet.xml (80%) rename components/iot-plugins/raspberrypi-plugin/{org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl => org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl}/src/main/webapp/WEB-INF/web.xml (100%) delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/pom.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/VirtualFireAlarmControllerService.java delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/web.xml rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl}/pom.xml (95%) create mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java create mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java create mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager/service/impl/VirtualFireAlarmManagerService.java => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java} (74%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/dto/DeviceData.java (93%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/dto/SensorData.java (90%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/exception/VirtualFireAlarmException.java (91%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/transport/VirtualFireAlarmMQTTConnector.java (95%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/transport/VirtualFireAlarmXMPPConnector.java (96%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/util/APIUtil.java (96%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/util/SecurityManager.java (98%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/util/VirtualFireAlarmServiceUtils.java (95%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/util/scep/ContentType.java (91%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm}/service/impl/util/scep/SCEPOperation.java (91%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl => virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl}/src/main/webapp/META-INF/permissions.xml (52%) rename components/iot-plugins/{digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api => virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl}/src/main/webapp/META-INF/webapp-classloading.xml (100%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl}/src/main/webapp/WEB-INF/cxf-servlet.xml (71%) rename components/iot-plugins/virtual-fire-alarm-plugin/{org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl => org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl}/src/main/webapp/WEB-INF/web.xml (100%) diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/AndroidSenseControllerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/AndroidSenseControllerService.java deleted file mode 100644 index 5d740dc33..000000000 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/AndroidSenseControllerService.java +++ /dev/null @@ -1,667 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.common.AnalyticsDataRecord; -import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.exception.DeviceManagementAnalyticsException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; -import org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.transport.AndroidSenseMQTTConnector; -import org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.util.DeviceData; -import org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.util.SensorData; -import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; -import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; -import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; -import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; - -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * The api for - */ -@DeviceType(value = "android_sense") -@API(name = "android_sense", version = "1.0.0", context = "/android_sense", tags = {"android_sense"}) -public class AndroidSenseControllerService { - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; - private static Log log = LogFactory.getLog(AndroidSenseControllerService.class); - private static AndroidSenseMQTTConnector androidSenseMQTTConnector; - - /** - * Fetches the `AndroidSenseMQTTConnector` specific to this Android Sense controller service. - * - * @return the 'AndroidSenseMQTTConnector' instance bound to the 'AndroidSenseMQTTConnector' variable of - * this service. - */ - @SuppressWarnings("Unused") - public AndroidSenseMQTTConnector getAndroidSenseMQTTConnector() { - return androidSenseMQTTConnector; - } - - /** - * Sets the `AndroidSenseMQTTConnector` variable of this Android Sense controller service. - * - * @param androidSenseMQTTConnector a 'AndroidSenseMQTTConnector' object that handles all MQTT related - * communications of any connected Android Sense device-type - */ - @SuppressWarnings("Unused") - public void setAndroidSenseMQTTConnector(final AndroidSenseMQTTConnector androidSenseMQTTConnector) { - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - AndroidSenseControllerService.androidSenseMQTTConnector = androidSenseMQTTConnector; - if (MqttConfig.getInstance().isEnabled()) { - androidSenseMQTTConnector.connect(); - } else { - log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - private boolean waitForServerStartup() { - while (!IoTServerStartupListener.isServerReady()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - return true; - } - } - return false; - } - - /** - * Service to push all the sensor data collected by the Android. Called by the Android device - * - * @param dataMsg The json string containing sensor readings - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API - */ - @Path("controller/sensors") - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void addSensorData(DeviceData dataMsg, @Context HttpServletResponse response) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx - .getOSGiService(DeviceAnalyticsService.class, null); - SensorData[] sensorData = dataMsg.values; - String streamDef = null; - Object payloadData[] = null; - String sensorName = null; - for (SensorData sensor : sensorData) { - switch (sensor.key) { - case "battery" : - streamDef = AndroidSenseConstants.BATTERY_STREAM_DEFINITION; - payloadData = new Float[]{Float.parseFloat(sensor.value)}; - sensorName = AndroidSenseConstants.SENSOR_BATTERY; - break; - case "GPS" : - streamDef = AndroidSenseConstants.GPS_STREAM_DEFINITION; - String gpsValue = sensor.value; - String gpsValuesString[] = gpsValue.split(","); - Float gpsValues[] = new Float[2]; - gpsValues[0] = Float.parseFloat(gpsValuesString[0]); - gpsValues[1] = Float.parseFloat(gpsValuesString[0]); - payloadData = gpsValues; - sensorName = AndroidSenseConstants.SENSOR_GPS; - break; - default : - try { - int androidSensorId = Integer.parseInt(sensor.key); - String value = sensor.value; - String sensorValueString[] = value.split(","); - Float sensorValues[] = new Float[1]; - switch (androidSensorId) { - case 1: - streamDef = AndroidSenseConstants.ACCELEROMETER_STREAM_DEFINITION; - sensorValues[0] = Float.parseFloat(sensorValueString[0]) * - Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); - payloadData = sensorValues; - sensorName = AndroidSenseConstants.SENSOR_ACCELEROMETER; - break; - case 2: - streamDef = AndroidSenseConstants.MAGNETIC_STREAM_DEFINITION; - sensorValues[0] = Float.parseFloat(sensorValueString[0]) * - Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); - payloadData = sensorValues; - sensorName = AndroidSenseConstants.SENSOR_MAGNETIC; - break; - case 4: - streamDef = AndroidSenseConstants.GYROSCOPE_STREAM_DEFINITION; - sensorValues[0] = Float.parseFloat(sensorValueString[0]) * - Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); - payloadData = sensorValues; - sensorName = AndroidSenseConstants.SENSOR_GYROSCOPE; - break; - case 5: - streamDef = AndroidSenseConstants.LIGHT_STREAM_DEFINITION; - sensorName = AndroidSenseConstants.SENSOR_LIGHT; - payloadData = new Float[]{Float.parseFloat(sensorValueString[0])}; - break; - case 6: - streamDef = AndroidSenseConstants.PRESSURE_STREAM_DEFINITION; - sensorName = AndroidSenseConstants.SENSOR_PRESSURE; - payloadData = new Float[]{Float.parseFloat(sensorValueString[0])}; - break; - case 8: - streamDef = AndroidSenseConstants.PROXIMITY_STREAM_DEFINITION; - sensorName = AndroidSenseConstants.SENSOR_PROXIMITY; - payloadData = new Float[]{Float.parseFloat(sensorValueString[0])}; - break; - case 9: - streamDef = AndroidSenseConstants.GRAVITY_STREAM_DEFINITION; - sensorValues[0] = Float.parseFloat(sensorValueString[0]) * - Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); - payloadData = sensorValues; - sensorName = AndroidSenseConstants.SENSOR_GRAVITY; - break; - case 11: - streamDef = AndroidSenseConstants.ROTATION_STREAM_DEFINITION; - sensorValues[0] = Float.parseFloat(sensorValueString[0]) * - Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); - payloadData = sensorValues; - sensorName = AndroidSenseConstants.SENSOR_ROTATION; - break; - } - } catch (NumberFormatException e) { - log.error("Invalid sensor value is sent from the device"); - continue; - } - } - Object metaData[] = {dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time}; - if (streamDef != null && payloadData != null && payloadData.length > 0) { - try { - SensorDataManager.getInstance() - .setSensorRecord(dataMsg.deviceId, sensorName, sensor.value, sensor.time); - deviceAnalyticsService.publishEvent(streamDef, "1.0.0", metaData, new Object[0], payloadData); - } catch (DataPublisherConfigurationException e) { - response.setStatus(Response.Status.UNSUPPORTED_MEDIA_TYPE.getStatusCode()); - } - } - } - } - - - /** - * End point which is called by Front-end js to get Light sensor readings from the server. - * - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/light") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "light", name = "Light", description = "Read Light data from the device", type = "monitor") - public SensorRecord getLightData(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants.SENSOR_LIGHT); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Battery data from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/battery") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "battery", name = "Battery", description = "Read Battery data from the device", type = "monitor") - public SensorRecord getBattery(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants.SENSOR_BATTERY); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get GPS data from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/gps") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "gps", name = "gps", description = "Read GPS data from the device", type = "monitor") - public SensorRecord getGPS(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants.SENSOR_GPS); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Magnetic data readings from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/magnetic") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "magnetic", name = "Magnetic", description = "Read Magnetic data from the device", type = "monitor") - public SensorRecord readMagnetic(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants.SENSOR_MAGNETIC); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Accelerometer data from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/accelerometer") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "accelerometer", name = "Accelerometer", description = "Read Accelerometer data from the device", - type = "monitor") - public SensorRecord readAccelerometer(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - AndroidSenseConstants.SENSOR_ACCELEROMETER); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Rotation data from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/rotation") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "rotation", name = "Rotation", description = "Read Rotational Vector data from the device", - type = "monitor") - public SensorRecord readRotation(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - AndroidSenseConstants.SENSOR_ROTATION); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Proximity data from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/proximity") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "proximity", name = "Proximity", description = "Read Proximity data from the device", - type = "monitor") - public SensorRecord readProximity(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - AndroidSenseConstants.SENSOR_PROXIMITY); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Gyroscope data from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/gyroscope") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "gyroscope", name = "Gyroscope", description = "Read Gyroscope data from the device", - type = "monitor") - public SensorRecord readGyroscope(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - AndroidSenseConstants.SENSOR_GYROSCOPE); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Pressure data from the server. - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/pressure") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "pressure", name = "Pressure", description = "Read Pressure data from the device", type = "monitor") - public SensorRecord readPressure(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - AndroidSenseConstants.SENSOR_PRESSURE); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point which is called by Front-end js to get Gravity data from the server. - * - * @param deviceId The registered device id - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API. - * @return This method returns a SensorRecord object. - */ - @Path("controller/device/{deviceId}/sensors/gravity") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "gravity", name = "Gravity", - description = "Read Gravity data from the device", type = "monitor") - public SensorRecord readGravity(@PathParam("deviceId") String deviceId, @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - AndroidSenseConstants.SENSOR_GRAVITY); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - @Path("controller/device/{deviceId}/sensors/words") - @GET - @Consumes("application/json") - @Produces("application/json") - @Feature(code = "words", name = "Words", description = "Get the key words and occurrences", - type = "monitor") - public SensorRecord getWords(@PathParam("deviceId") String deviceId, @QueryParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - AndroidSenseConstants.SENSOR_WORDCOUNT); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - return sensorRecord; - } - - /** - * End point to send the key words to the device - - * @param deviceId The registered device Id. - * @param keywords The key words to be sent. (Comma separated values) - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API - */ - @Path("controller/device/{deviceId}/sensors/words") - @POST - @Feature(code = "keywords", name = "Add Keywords", description = "Send keywords to the device", - type = "operation") - public void sendKeyWords(@PathParam("deviceId") String deviceId, @FormParam("keywords") String keywords, - @Context HttpServletResponse response) { - try { - String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - androidSenseMQTTConnector.publishDeviceData(username, deviceId, "add", keywords); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (TransportHandlerException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } - } - - /** - * End point to send the key words to the device - * - * @param deviceId The registered device Id. - * @param threshold The key words to be sent. (Comma separated values) - * @param response the HTTP servlet response object received by default as part of the HTTP - * call to this API - */ - @Path("controller/device/{deviceId}/sensors/words/threshold") - @POST - @Feature(code = "threshold", name = "Add a Threshold", description = "Set a threshold for word in the device", - type = "operation") - public void sendThreshold(@PathParam("deviceId") String deviceId, @FormParam("threshold") String threshold, - @Context HttpServletResponse response) { - try { - String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - androidSenseMQTTConnector.publishDeviceData(username, deviceId, "threshold", threshold); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (TransportHandlerException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } - } - - @Path("controller/device/{deviceId}/sensors/words") - @DELETE - @Feature(code = "remove", name = "Remove Keywords", description = "Remove the keywords", - type = "operation") - public void removeKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("words") String words, - @Context HttpServletResponse response) { - try { - String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - androidSenseMQTTConnector.publishDeviceData(username, deviceId, "remove", words); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (TransportHandlerException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } - } - - /** - * Retrieve Sensor data for the device type - * - */ - @Path("controller/stats/device/{deviceId}/sensors/{sensorName}") - @GET - @Consumes("application/json") - @Produces("application/json") - public SensorData[] getAndroidSenseDeviceStats(@PathParam("deviceId") String deviceId, - @PathParam("sensorName") String sensor, - @QueryParam("from") long from, - @QueryParam("to") long to) { - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - String user = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - List sensorDatas = new ArrayList<>(); - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx - .getOSGiService(DeviceAnalyticsService.class, null); - String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + - AndroidSenseConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; - if (sensor.equals(AndroidSenseConstants.SENSOR_WORDCOUNT)) { - query = "owner:" + user + " AND deviceId:" + deviceId; - } - String sensorTableName = getSensorEventTableName(sensor); - try { - List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); - if (sensor.equals(AndroidSenseConstants.SENSOR_WORDCOUNT)) { - for (AnalyticsDataRecord record : records) { - SensorData sensorData = new SensorData(); - sensorData.setKey((String)record.getValue("word")); - sensorData.setTime((long) record.getValue("occurence")); - sensorData.setValue((String) record.getValue("sessionId")); - sensorDatas.add(sensorData); - } - } else { - Collections.sort(records, new Comparator() { - @Override - public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { - long t1 = (Long) o1.getValue("time"); - long t2 = (Long) o2.getValue("time"); - if (t1 < t2) { - return -1; - } else if (t1 > t2) { - return 1; - } else { - return 0; - } - } - }); - for (AnalyticsDataRecord record : records) { - SensorData sensorData = new SensorData(); - sensorData.setTime((long) record.getValue("time")); - sensorData.setValue("" + (float) record.getValue(sensor)); - sensorDatas.add(sensorData); - } - } - return sensorDatas.toArray(new SensorData[sensorDatas.size()]); - } catch (DeviceManagementAnalyticsException e) { - String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; - log.error(errorMsg); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return sensorDatas.toArray(new SensorData[sensorDatas.size()]); - } - } - - /** - * get the event table from the sensor name. - */ - private String getSensorEventTableName(String sensorName) { - String sensorEventTableName; - switch (sensorName) { - case AndroidSenseConstants.SENSOR_ACCELEROMETER: - sensorEventTableName = "DEVICE_ACCELEROMETER_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_BATTERY: - sensorEventTableName = "DEVICE_BATTERY_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_GPS: - sensorEventTableName = "DEVICE_GPS_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_GRAVITY: - sensorEventTableName = "DEVICE_GRAVITY_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_GYROSCOPE: - sensorEventTableName = "DEVICE_GYROSCOPE_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_LIGHT: - sensorEventTableName = "DEVICE_LIGHT_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_MAGNETIC: - sensorEventTableName = "DEVICE_MAGNETIC_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_PRESSURE: - sensorEventTableName = "DEVICE_PRESSURE_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_PROXIMITY: - sensorEventTableName = "DevicePROXIMITYSummaryData"; - break; - case AndroidSenseConstants.SENSOR_ROTATION: - sensorEventTableName = "DEVICE_ROTATION_SUMMARY"; - break; - case AndroidSenseConstants.SENSOR_WORDCOUNT: - sensorEventTableName = "WORD_COUNT_SUMMARY"; - break; - default: - sensorEventTableName = ""; - } - return sensorEventTableName; - } -} diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index e732f7427..000000000 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 0c0ec3ef1..000000000 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - Android Sense - Android Sense - - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - true - - - - managed-api-enabled - false - - - managed-api-owner - admin - - - managed-api-context-template - /android_sense_mgt/{version} - - - managed-api-application - android_sense - - - managed-api-isSecured - false - - diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/pom.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/pom.xml similarity index 93% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/pom.xml rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/pom.xml index 91f33ca0c..ff7e3bfa1 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/pom.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/pom.xml @@ -3,20 +3,20 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - androidsense-plugin + device-mgt-iot-androidsense org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.0.4-SNAPSHOT ../pom.xml 4.0.0 - org.wso2.carbon.device.mgt.iot.androidsense.manager.api + org.wso2.carbon.device.mgt.iot.androidsense.service.impl + 2.0.4-SNAPSHOT war - WSO2 Carbon - Android Sense Management API - WSO2 Carbon - Android Sense Management Service-API Implementation + WSO2 Carbon - Android Sense API + WSO2 Carbon - Android Sense Service-API Implementation http://wso2.org - @@ -97,7 +97,8 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics + org.wso2.carbon.device.mgt.analytics.data.publisher + 1.1.0-SNAPSHOT provided @@ -196,7 +197,7 @@ maven-war-plugin - android_sense_mgt + android_sense diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java new file mode 100644 index 000000000..427f113ba --- /dev/null +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java @@ -0,0 +1,235 @@ +/* + * 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.androidsense.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceData; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@DeviceType(value = "android_sense") +@API(name = "android_sense", version = "1.0.0", context = "/android_sense", tags = {"android_sense"}) +public interface AndroidSenseControllerService { + + /** + * Service to push all the sensor data collected by the Android. Called by the Android device + * + * @param dataMsg The json string containing sensor readings + */ + @Path("device/sensors") + @POST + @Consumes(MediaType.APPLICATION_JSON) + Response addSensorData(DeviceData dataMsg); + + /** + * End point which is called by Front-end js to get Light sensor readings from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/light") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "light", name = "Light", description = "Read Light data from the device", type = "monitor") + Response getLightData(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Battery data from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/battery") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "battery", name = "Battery", description = "Read Battery data from the device", type = "monitor") + Response getBattery(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get GPS data from the server. + * + * @param deviceId The registered device id call to this API. + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/gps") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "gps", name = "gps", description = "Read GPS data from the device", type = "monitor") + Response getGPS(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Magnetic data readings from the server. + * + * @param deviceId The registered device id + * call to this API. + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/magnetic") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "magnetic", name = "Magnetic", description = "Read Magnetic data from the device", type = "monitor") + Response readMagnetic(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Accelerometer data from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/accelerometer") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "accelerometer", name = "Accelerometer", description = "Read Accelerometer data from the device", + type = "monitor") + Response readAccelerometer(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Rotation data from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/rotation") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "rotation", name = "Rotation", description = "Read Rotational Vector data from the device", + type = "monitor") + Response readRotation(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Proximity data from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/proximity") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "proximity", name = "Proximity", description = "Read Proximity data from the device", + type = "monitor") + Response readProximity(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Gyroscope data from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/gyroscope") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "gyroscope", name = "Gyroscope", description = "Read Gyroscope data from the device", + type = "monitor") + Response readGyroscope(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Pressure data from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/pressure") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "pressure", name = "Pressure", description = "Read Pressure data from the device", type = "monitor") + Response readPressure(@PathParam("deviceId") String deviceId); + + /** + * End point which is called by Front-end js to get Gravity data from the server. + * + * @param deviceId The registered device id + * @return This method returns a SensorRecord object. + */ + @Path("device/{deviceId}/sensors/gravity") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "gravity", name = "Gravity", + description = "Read Gravity data from the device", type = "monitor") + Response readGravity(@PathParam("deviceId") String deviceId); + + @Path("device/{deviceId}/sensors/words") + @GET + @Consumes("application/json") + @Produces("application/json") + @Feature(code = "words", name = "Words", description = "Get the key words and occurrences", + type = "monitor") + Response getWords(@PathParam("deviceId") String deviceId, @QueryParam("sessionId") String sessionId); + + /** + * End point to send the key words to the device + * + * @param deviceId The registered device Id. + * @param keywords The key words to be sent. (Comma separated values) + */ + @Path("device/{deviceId}/sensors/words") + @POST + @Feature(code = "keywords", name = "Add Keywords", description = "Send keywords to the device", + type = "operation") + Response sendKeyWords(@PathParam("deviceId") String deviceId, @FormParam("keywords") String keywords); + + /** + * End point to send the key words to the device + * + * @param deviceId The registered device Id. + * @param threshold The key words to be sent. (Comma separated values) + */ + @Path("device/{deviceId}/sensors/words/threshold") + @POST + @Feature(code = "threshold", name = "Add a Threshold", description = "Set a threshold for word in the device", + type = "operation") + Response sendThreshold(@PathParam("deviceId") String deviceId, @FormParam("threshold") String threshold); + + @Path("device/{deviceId}/sensors/words") + @DELETE + @Feature(code = "remove", name = "Remove Keywords", description = "Remove the keywords", + type = "operation") + Response removeKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("words") String words); + + /** + * Retrieve Sensor data for the device type + */ + @Path("stats/device/{deviceId}/sensors/{sensorName}") + @GET + @Consumes("application/json") + @Produces("application/json") + Response getAndroidSenseDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensor, + @QueryParam("from") long from, @QueryParam("to") long to); + +} diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java new file mode 100644 index 000000000..3d0dfa7f3 --- /dev/null +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java @@ -0,0 +1,443 @@ +/* + * 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.androidsense.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.data.publisher.AnalyticsDataRecord; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DeviceManagementAnalyticsException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceData; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorData; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; +import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; +import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; + +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * The api for + */ +public class AndroidSenseControllerServiceImpl implements AndroidSenseControllerService { + + private static Log log = LogFactory.getLog(AndroidSenseControllerServiceImpl.class); + private static AndroidSenseMQTTConnector androidSenseMQTTConnector; + + /** + * Fetches the `AndroidSenseMQTTConnector` specific to this Android Sense controller service. + * + * @return the 'AndroidSenseMQTTConnector' instance bound to the 'AndroidSenseMQTTConnector' variable of + * this service. + */ + @SuppressWarnings("Unused") + public AndroidSenseMQTTConnector getAndroidSenseMQTTConnector() { + return androidSenseMQTTConnector; + } + + /** + * Sets the `AndroidSenseMQTTConnector` variable of this Android Sense controller service. + * + * @param androidSenseMQTTConnector a 'AndroidSenseMQTTConnector' object that handles all MQTT related + * communications of any connected Android Sense device-type + */ + @SuppressWarnings("Unused") + public void setAndroidSenseMQTTConnector(final AndroidSenseMQTTConnector androidSenseMQTTConnector) { + Runnable connector = new Runnable() { + public void run() { + if (waitForServerStartup()) { + return; + } + AndroidSenseControllerServiceImpl.androidSenseMQTTConnector = androidSenseMQTTConnector; + if (MqttConfig.getInstance().isEnabled()) { + androidSenseMQTTConnector.connect(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); + } + } + }; + Thread connectorThread = new Thread(connector); + connectorThread.setDaemon(true); + connectorThread.start(); + } + + private boolean waitForServerStartup() { + while (!IoTServerStartupListener.isServerReady()) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + return true; + } + } + return false; + } + + public Response addSensorData(DeviceData dataMsg) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + SensorData[] sensorData = dataMsg.values; + String streamDef = null; + Object payloadData[] = null; + String sensorName = null; + for (SensorData sensor : sensorData) { + switch (sensor.key) { + case "battery": + streamDef = AndroidSenseConstants.BATTERY_STREAM_DEFINITION; + payloadData = new Float[]{Float.parseFloat(sensor.value)}; + sensorName = AndroidSenseConstants.SENSOR_BATTERY; + break; + case "GPS": + streamDef = AndroidSenseConstants.GPS_STREAM_DEFINITION; + String gpsValue = sensor.value; + String gpsValuesString[] = gpsValue.split(","); + Float gpsValues[] = new Float[2]; + gpsValues[0] = Float.parseFloat(gpsValuesString[0]); + gpsValues[1] = Float.parseFloat(gpsValuesString[0]); + payloadData = gpsValues; + sensorName = AndroidSenseConstants.SENSOR_GPS; + break; + default: + try { + int androidSensorId = Integer.parseInt(sensor.key); + String value = sensor.value; + String sensorValueString[] = value.split(","); + Float sensorValues[] = new Float[1]; + switch (androidSensorId) { + case 1: + streamDef = AndroidSenseConstants.ACCELEROMETER_STREAM_DEFINITION; + sensorValues[0] = Float.parseFloat(sensorValueString[0]) * + Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); + payloadData = sensorValues; + sensorName = AndroidSenseConstants.SENSOR_ACCELEROMETER; + break; + case 2: + streamDef = AndroidSenseConstants.MAGNETIC_STREAM_DEFINITION; + sensorValues[0] = Float.parseFloat(sensorValueString[0]) * + Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); + payloadData = sensorValues; + sensorName = AndroidSenseConstants.SENSOR_MAGNETIC; + break; + case 4: + streamDef = AndroidSenseConstants.GYROSCOPE_STREAM_DEFINITION; + sensorValues[0] = Float.parseFloat(sensorValueString[0]) * + Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); + payloadData = sensorValues; + sensorName = AndroidSenseConstants.SENSOR_GYROSCOPE; + break; + case 5: + streamDef = AndroidSenseConstants.LIGHT_STREAM_DEFINITION; + sensorName = AndroidSenseConstants.SENSOR_LIGHT; + payloadData = new Float[]{Float.parseFloat(sensorValueString[0])}; + break; + case 6: + streamDef = AndroidSenseConstants.PRESSURE_STREAM_DEFINITION; + sensorName = AndroidSenseConstants.SENSOR_PRESSURE; + payloadData = new Float[]{Float.parseFloat(sensorValueString[0])}; + break; + case 8: + streamDef = AndroidSenseConstants.PROXIMITY_STREAM_DEFINITION; + sensorName = AndroidSenseConstants.SENSOR_PROXIMITY; + payloadData = new Float[]{Float.parseFloat(sensorValueString[0])}; + break; + case 9: + streamDef = AndroidSenseConstants.GRAVITY_STREAM_DEFINITION; + sensorValues[0] = Float.parseFloat(sensorValueString[0]) * + Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); + payloadData = sensorValues; + sensorName = AndroidSenseConstants.SENSOR_GRAVITY; + break; + case 11: + streamDef = AndroidSenseConstants.ROTATION_STREAM_DEFINITION; + sensorValues[0] = Float.parseFloat(sensorValueString[0]) * + Float.parseFloat(sensorValueString[0]) * Float.parseFloat(sensorValueString[0]); + payloadData = sensorValues; + sensorName = AndroidSenseConstants.SENSOR_ROTATION; + break; + } + } catch (NumberFormatException e) { + log.error("Invalid sensor value is sent from the device"); + continue; + } + } + Object metaData[] = {dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time}; + if (streamDef != null && payloadData != null && payloadData.length > 0) { + try { + SensorDataManager.getInstance() + .setSensorRecord(dataMsg.deviceId, sensorName, sensor.value, sensor.time); + deviceAnalyticsService.publishEvent(streamDef, "1.0.0", metaData, new Object[0], payloadData); + } catch (DataPublisherConfigurationException e) { + return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE.getStatusCode()).build(); + } + } + } + return Response.ok().build(); + } + + public Response getLightData(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants + .SENSOR_LIGHT); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response getBattery(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants + .SENSOR_BATTERY); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response getGPS(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants + .SENSOR_GPS); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response readMagnetic(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, AndroidSenseConstants + .SENSOR_MAGNETIC); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response readAccelerometer(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + AndroidSenseConstants.SENSOR_ACCELEROMETER); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response readRotation(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + AndroidSenseConstants.SENSOR_ROTATION); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response readProximity(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + AndroidSenseConstants.SENSOR_PROXIMITY); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response readGyroscope(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + AndroidSenseConstants.SENSOR_GYROSCOPE); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response readPressure(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + AndroidSenseConstants.SENSOR_PRESSURE); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response readGravity(String deviceId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + AndroidSenseConstants.SENSOR_GRAVITY); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response getWords(String deviceId, String sessionId) { + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + AndroidSenseConstants.SENSOR_WORDCOUNT); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response sendKeyWords(String deviceId, String keywords) { + try { + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + androidSenseMQTTConnector.publishDeviceData(username, deviceId, "add", keywords); + return Response.ok().build(); + } catch (TransportHandlerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response sendThreshold(String deviceId, String threshold) { + try { + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + androidSenseMQTTConnector.publishDeviceData(username, deviceId, "threshold", threshold); + return Response.ok().build(); + } catch (TransportHandlerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response removeKeyWords(String deviceId, String words) { + try { + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + androidSenseMQTTConnector.publishDeviceData(username, deviceId, "remove", words); + return Response.ok().build(); + } catch (TransportHandlerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response getAndroidSenseDeviceStats(String deviceId, String sensor, long from, long to) { + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + String user = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + List sensorDatas = new ArrayList<>(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + + AndroidSenseConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; + if (sensor.equals(AndroidSenseConstants.SENSOR_WORDCOUNT)) { + query = "owner:" + user + " AND deviceId:" + deviceId; + } + String sensorTableName = getSensorEventTableName(sensor); + try { + List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); + if (sensor.equals(AndroidSenseConstants.SENSOR_WORDCOUNT)) { + for (AnalyticsDataRecord record : records) { + SensorData sensorData = new SensorData(); + sensorData.setKey((String) record.getValue("word")); + sensorData.setTime((long) record.getValue("occurence")); + sensorData.setValue((String) record.getValue("sessionId")); + sensorDatas.add(sensorData); + } + } else { + Collections.sort(records, new Comparator() { + @Override + public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { + long t1 = (Long) o1.getValue("time"); + long t2 = (Long) o2.getValue("time"); + if (t1 < t2) { + return -1; + } else if (t1 > t2) { + return 1; + } else { + return 0; + } + } + }); + for (AnalyticsDataRecord record : records) { + SensorData sensorData = new SensorData(); + sensorData.setTime((long) record.getValue("time")); + sensorData.setValue("" + (float) record.getValue(sensor)); + sensorDatas.add(sensorData); + } + } + SensorData[] sensorDetails = sensorDatas.toArray(new SensorData[sensorDatas.size()]); + return Response.ok().entity(sensorDetails).build(); + } catch (DeviceManagementAnalyticsException e) { + String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; + log.error(errorMsg); + SensorData[] senserDetails = sensorDatas.toArray(new SensorData[sensorDatas.size()]); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(senserDetails).build(); + } + } + + /** + * get the event table from the sensor name. + */ + private String getSensorEventTableName(String sensorName) { + String sensorEventTableName; + switch (sensorName) { + case AndroidSenseConstants.SENSOR_ACCELEROMETER: + sensorEventTableName = "DEVICE_ACCELEROMETER_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_BATTERY: + sensorEventTableName = "DEVICE_BATTERY_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_GPS: + sensorEventTableName = "DEVICE_GPS_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_GRAVITY: + sensorEventTableName = "DEVICE_GRAVITY_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_GYROSCOPE: + sensorEventTableName = "DEVICE_GYROSCOPE_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_LIGHT: + sensorEventTableName = "DEVICE_LIGHT_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_MAGNETIC: + sensorEventTableName = "DEVICE_MAGNETIC_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_PRESSURE: + sensorEventTableName = "DEVICE_PRESSURE_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_PROXIMITY: + sensorEventTableName = "DevicePROXIMITYSummaryData"; + break; + case AndroidSenseConstants.SENSOR_ROTATION: + sensorEventTableName = "DEVICE_ROTATION_SUMMARY"; + break; + case AndroidSenseConstants.SENSOR_WORDCOUNT: + sensorEventTableName = "WORD_COUNT_SUMMARY"; + break; + default: + sensorEventTableName = ""; + } + return sensorEventTableName; + } +} diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerService.java new file mode 100644 index 000000000..770930ec5 --- /dev/null +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerService.java @@ -0,0 +1,62 @@ +/* + * 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.androidsense.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +@DeviceType(value = "android_sense") +@API(name = "android_sense_mgt", version = "1.0.0", context = "/android_sense_mgt", tags = {"android_sense"}) +public interface AndroidSenseManagerService { + + @Path("device/{device_id}") + @POST + Response register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName); + + @Path("devices/{device_id}") + @DELETE + Response removeDevice(@PathParam("device_id") String deviceId); + + @Path("devices/{device_id}") + @PUT + Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name); + + @Path("devices/{device_id}") + @GET + @Consumes("application/json") + @Produces("application/json") + Response getDevice(@PathParam("device_id") String deviceId); + + @Path("devices/{sketch_type}/download") + @GET + @Produces("application/octet-stream") + Response downloadSketch(@PathParam("sketch_type") String sketchType); + +} + diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager/service/impl/AndroidSenseManagerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java similarity index 59% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager/service/impl/AndroidSenseManagerService.java rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java index a9f942fde..531bc5deb 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager/service/impl/AndroidSenseManagerService.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java @@ -16,51 +16,32 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.androidsense.manager.service.impl; +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.iot.androidsense.manager.service.impl.util.APIUtil; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; import org.wso2.carbon.utils.CarbonUtils; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import java.io.File; import java.util.Date; -public class AndroidSenseManagerService { +public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerService { - private static Log log = LogFactory.getLog(AndroidSenseManagerService.class); + private static Log log = LogFactory.getLog(AndroidSenseManagerServiceImpl.class); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; - - @Path("manager/device") - @POST - public boolean register(@QueryParam("deviceId") String deviceId, @QueryParam("deviceName") String deviceName) { + public Response register(String deviceId, String deviceName) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); try { if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { - response.setStatus(Response.Status.CONFLICT.getStatusCode()); - return true; + return Response.status(Response.Status.CONFLICT.getStatusCode()).build(); } Device device = new Device(); @@ -75,41 +56,32 @@ public class AndroidSenseManagerService { device.setEnrolmentInfo(enrolmentInfo); boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); if (added) { - response.setStatus(Response.Status.OK.getStatusCode()); + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } - return added; } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return false; + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{device_id}") - @DELETE - public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) { + public Response removeDevice(String deviceId) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); try { boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(deviceIdentifier); if (removed) { - response.setStatus(Response.Status.OK.getStatusCode()); - + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{device_id}") - @PUT - public boolean updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name, - @Context HttpServletResponse response) { + public Response updateDevice(String deviceId, String name) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); @@ -121,46 +93,38 @@ public class AndroidSenseManagerService { device.setType(AndroidSenseConstants.DEVICE_TYPE); boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); if (updated) { - response.setStatus(Response.Status.OK.getStatusCode()); + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } - return updated; } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return false; + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{device_id}") - @GET - @Consumes("application/json") - @Produces("application/json") - public Device getDevice(@PathParam("device_id") String deviceId) { + public Response getDevice(String deviceId) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); try { - return APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + return Response.ok().entity(device).build(); } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{sketch_type}/download") - @GET - @Produces("application/octet-stream") - public Response downloadSketch(@PathParam("sketch_type") String sketchType) { + public Response downloadSketch(String sketchType) { try { String sep = File.separator; String sketchFolder = "repository" + sep + "resources" + sep + "sketches" + sep + "android_sense" + sep; String archivesPath = CarbonUtils.getCarbonHome() + sep + sketchFolder; - Response.ResponseBuilder rb = Response.ok(new File(archivesPath+sep+"androidsense.apk")); + Response.ResponseBuilder rb = Response.ok(new File(archivesPath + sep + "androidsense.apk")); rb.header("Content-Disposition", "attachment; filename=\"" + "androidsense.apk" + "\""); return rb.build(); } catch (IllegalArgumentException ex) { - return Response.status(400).entity(ex.getMessage()).build();//bad request + return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build(); } } + } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/transport/AndroidSenseMQTTConnector.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/transport/AndroidSenseMQTTConnector.java similarity index 96% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/transport/AndroidSenseMQTTConnector.java rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/transport/AndroidSenseMQTTConnector.java index 52ace2bf5..ca6825b82 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/transport/AndroidSenseMQTTConnector.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/transport/AndroidSenseMQTTConnector.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.transport; +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -25,16 +25,15 @@ import org.apache.commons.logging.LogFactory; import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.util.DeviceData; -import org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.util.SensorData; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceData; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorData; import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; -import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager/service/impl/util/APIUtil.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/APIUtil.java similarity index 94% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager/service/impl/util/APIUtil.java rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/APIUtil.java index ec55710dd..73287696e 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/manager/service/impl/util/APIUtil.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/APIUtil.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.androidsense.manager.service.impl.util; +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/util/DeviceData.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceData.java similarity index 82% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/util/DeviceData.java rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceData.java index 2577a21f8..6b72507bb 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/util/DeviceData.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceData.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.util; +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/util/SensorData.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorData.java similarity index 90% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/util/SensorData.java rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorData.java index a2f9cebf9..becd17085 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/controller/service/impl/util/SensorData.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorData.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.androidsense.controller.service.impl.util; +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/META-INF/permissions.xml similarity index 66% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/META-INF/permissions.xml rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/META-INF/permissions.xml index d30a5096f..d099e50e5 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/META-INF/permissions.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/META-INF/permissions.xml @@ -31,113 +31,150 @@ add sensor information /login - /controller/sensors + /device/sensors POST Get light information /login - /controller/device/{deviceId}/sensors/light + /device/*/sensors/light GET Get battery information /login - /controller/device/{deviceId}/sensors/battery + /device/*/sensors/battery GET Get gps information /login - /controller/device/{deviceId}/sensors/gps + /device/*/sensors/gps GET Get magnetic information /login - /controller/device/{deviceId}/sensors/magnetic + /device/*/sensors/magnetic GET Get accelerometer information /login - /controller/device/{deviceId}/sensors/accelerometer + /device/*/sensors/accelerometer GET Get rotation information /login - /controller/device/{deviceId}/sensors/rotation + /device/*/sensors/rotation GET Get proximity information /login - /controller/device/{deviceId}/sensors/proximity + /device/*/sensors/proximity GET Get gyroscope information /login - /controller/device/{deviceId}/sensors/gyroscope + /device/*/sensors/gyroscope GET Get pressure information /login - /controller/device/{deviceId}/sensors/pressure + /device/*/sensors/pressure GET Get gravity information /login - /controller/device/{deviceId}/sensors/gravity + /device/*/sensors/gravity GET Get words information /login - /controller/device/{deviceId}/sensors/words + /device/*/sensors/words GET Get words information /login - /controller/device/{deviceId}/sensors/words + /device/*/sensors/words POST set word threshold information /login - /controller/device/{deviceId}/sensors/words/threshold + /device/*/sensors/words/threshold POST delete words /login - /controller/device/{deviceId}/sensors/words + /device/*/sensors/words DELETE get device stats /login - /controller/stats/device/{deviceId}/sensors/{sensorName} + /stats/device/*/sensors/* GET - \ No newline at end of file + + + Get device + /device-mgt/user/devices/list + /devices/* + GET + + + + Add device + /device-mgt/user/devices/add + /devices/register + POST + + + + Remove device + /device-mgt/user/devices/remove + /devices/* + DELETE + + + + Download device + /device-mgt/user/devices/add + /devices/*/download + GET + + + + Update device + /device-mgt/user/devices/update + /devices/* + POST + + + + diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/META-INF/webapp-classloading.xml rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 80% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml index 476cbcc61..9ddba99b0 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -22,12 +22,14 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + + class="org.wso2.carbon.device.mgt.iot.androidsense.service.impl.AndroidSenseControllerServiceImpl"> + @@ -35,7 +37,7 @@ + class="org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector"> diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/src/main/webapp/WEB-INF/web.xml rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.service.impl/src/main/webapp/WEB-INF/web.xml diff --git a/components/iot-plugins/androidsense-plugin/pom.xml b/components/iot-plugins/androidsense-plugin/pom.xml index 59a343d4c..5dfd9d68e 100644 --- a/components/iot-plugins/androidsense-plugin/pom.xml +++ b/components/iot-plugins/androidsense-plugin/pom.xml @@ -34,8 +34,7 @@ org.wso2.carbon.device.mgt.iot.androidsense.analytics - org.wso2.carbon.device.mgt.iot.androidsense.controller.api - org.wso2.carbon.device.mgt.iot.androidsense.manager.api + org.wso2.carbon.device.mgt.iot.androidsense.service.impl org.wso2.carbon.device.mgt.iot.androidsense.plugin org.wso2.carbon.device.mgt.iot.androidsense.ui diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/pom.xml deleted file mode 100644 index 9ef464d1a..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/pom.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - arduino-plugin - org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT - ../pom.xml - - - - 4.0.0 - org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl - war - WSO2 Carbon - IoT Server Arduino Controller API - WSO2 Carbon - Arduino Service Controller API Implementation - http://wso2.org - - - - - org.wso2.carbon - org.wso2.carbon.utils - provided - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - - - org.apache.cxf - cxf-rt-frontend-jaxws - provided - - - org.apache.cxf - cxf-rt-frontend-jaxrs - provided - - - org.apache.cxf - cxf-rt-transports-http - provided - - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - provided - - - - - org.apache.httpcomponents - httpasyncclient - 4.1 - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.arduino.plugin.impl - provided - - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-jaxrs - - - javax - javaee-web-api - provided - - - javax.ws.rs - jsr311-api - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions - provided - - - - - - - - maven-compiler-plugin - - UTF-8 - ${wso2.maven.compiler.source} - ${wso2.maven.compiler.target} - - - - maven-war-plugin - - arduino - - - - - - \ No newline at end of file diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/ArduinoControllerService.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/ArduinoControllerService.java deleted file mode 100644 index 7c5be93c0..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/ArduinoControllerService.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.common.AnalyticsDataRecord; -import org.wso2.carbon.device.mgt.analytics.exception.DeviceManagementAnalyticsException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; -import org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.dto.DeviceData; -import org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.dto.SensorData; -import org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.transport.ArduinoMQTTConnector; -import org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.util.ArduinoServiceUtils; -import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; -import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; -import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.concurrent.ConcurrentHashMap; - - -@API( name="arduino", version="1.0.0", context="/arduino", tags = {"arduino"}) -@DeviceType( value = "arduino") -public class ArduinoControllerService { - - private static Log log = LogFactory.getLog(ArduinoControllerService.class); - private static Map> replyMsgQueue = new HashMap<>(); - private static Map> internalControlsQueue = new HashMap<>(); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; - private ArduinoMQTTConnector arduinoMQTTConnector; - private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); - - /** - * @return the queue containing all the MQTT reply messages from all Arduinos communicating to this service - */ - public static Map> getReplyMsgQueue() { - return replyMsgQueue; - } - - /** - * @return the queue containing all the MQTT controls received to be sent to any Arduinos connected to this server - */ - public static Map> getInternalControlsQueue() { - return internalControlsQueue; - } - - private boolean waitForServerStartup() { - while (!IoTServerStartupListener.isServerReady()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - return true; - } - } - return false; - } - - /** - * @return the "ArduinoMQTTConnector" object of this ArduinoControllerService instance - */ - @SuppressWarnings("unused") - public ArduinoMQTTConnector getArduinoMQTTConnector() { - return arduinoMQTTConnector; - } - - /** - * @param arduinoMQTTConnector an object of type "ArduinoMQTTConnector" specific for this ArduinoControllerService - */ - @SuppressWarnings("unused") - public void setArduinoMQTTConnector(final ArduinoMQTTConnector arduinoMQTTConnector) { - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - ArduinoControllerService.this.arduinoMQTTConnector = arduinoMQTTConnector; - if (MqttConfig.getInstance().isEnabled()) { - arduinoMQTTConnector.connect(); - } else { - log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, ArduinoMQTTConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - @Path("controller/register/device/{deviceId}/{ip}/{port}") - @POST - public String registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, - @PathParam("port") String devicePort, @Context HttpServletResponse response, - @Context HttpServletRequest request) { - String result; - if (log.isDebugEnabled()) { - log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: "); - } - String deviceHttpEndpoint = deviceIP + ":" + devicePort; - deviceToIpMap.put(deviceId, deviceHttpEndpoint); - result = "Device-IP Registered"; - response.setStatus(Response.Status.OK.getStatusCode()); - if (log.isDebugEnabled()) { - log.debug(result); - } - return result; - } - - @Path("controller/device/{deviceId}/bulb") - @POST - @Feature(code = "bulb", name = "Control Bulb", type = "operation", description = "Control Bulb on Arduino Uno") - public void switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, - @FormParam("state") String state, @Context HttpServletResponse response) { - - LinkedList deviceControlList = internalControlsQueue.get(deviceId); - String operation = "BULB:" + state.toUpperCase(); - log.info(operation); - if (deviceControlList == null) { - deviceControlList = new LinkedList<>(); - deviceControlList.add(operation); - internalControlsQueue.put(deviceId, deviceControlList); - } else { - deviceControlList.add(operation); - } - response.setStatus(Response.Status.OK.getStatusCode()); - } - - @Path("controller/device/{deviceId}/temperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Feature( code="temperature", name="Temperature", type="monitor", description="Request temperature reading from Arduino agent") - public SensorRecord requestTemperature(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, - @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - ArduinoConstants.SENSOR_TEMPERATURE); - } catch (DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - response.setStatus(Response.Status.OK.getStatusCode()); - return sensorRecord; - } - - @Path("controller/sensor") - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void pushData(DeviceData dataMsg, @Context HttpServletResponse response) { - String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - String deviceId = dataMsg.deviceId; - float pinData = dataMsg.value; - SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE, - String.valueOf(pinData), - Calendar.getInstance().getTimeInMillis()); - if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" + - deviceId + "] of owner [" + owner + "]"); - } - } - - @Path("controller/device/{deviceId}/controls") - @GET - public String readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, - @Context HttpServletResponse response) { - String result; - LinkedList deviceControlList = internalControlsQueue.get(deviceId); - String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - if (deviceControlList == null) { - result = "No controls have been set for device " + deviceId + " of owner " + owner; - response.setStatus(HttpStatus.SC_NO_CONTENT); - } else { - try { - result = deviceControlList.remove(); - response.setStatus(HttpStatus.SC_ACCEPTED); - } catch (NoSuchElementException ex) { - result = "There are no more controls for device " + deviceId + " of owner " + owner; - response.setStatus(HttpStatus.SC_NO_CONTENT); - } - } - if (log.isDebugEnabled()) { - log.debug(result); - } - return result; - } - - @Path("controller/temperature") - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void pushTemperatureData(final DeviceData dataMsg, @Context HttpServletResponse response, - @Context HttpServletRequest request) { - String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - String deviceId = dataMsg.deviceId; - float temperature = dataMsg.value; - SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE, - String.valueOf(temperature), - Calendar.getInstance().getTimeInMillis()); - if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId + - "] of owner [" + owner + "]"); - } - } - - /** - * Retreive Sensor data for the device type - */ - @Path("controller/stats/device/{deviceId}/sensors/temperature") - @GET - @Consumes("application/json") - @Produces("application/json") - public SensorData[] getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, - @QueryParam("from") long from, - @QueryParam("to") long to) { - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - List sensorDatas = new ArrayList<>(); - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx - .getOSGiService(DeviceAnalyticsService.class, null); - String query = "deviceId:" + deviceId + " AND deviceType:" + - ArduinoConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; - String sensorTableName = ArduinoConstants.TEMPERATURE_EVENT_TABLE; - try { - List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); - Collections.sort(records, new Comparator() { - @Override - public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { - long t1 = (Long) o1.getValue("time"); - long t2 = (Long) o2.getValue("time"); - if (t1 < t2) { - return -1; - } else if (t1 > t2) { - return 1; - } else { - return 0; - } - } - }); - for (AnalyticsDataRecord record : records) { - SensorData sensorData = new SensorData(); - sensorData.setTime((long) record.getValue("time")); - sensorData.setValue("" + (float) record.getValue(ArduinoConstants.SENSOR_TEMPERATURE)); - sensorDatas.add(sensorData); - } - return sensorDatas.toArray(new SensorData[sensorDatas.size()]); - } catch (DeviceManagementAnalyticsException e) { - String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; - log.error(errorMsg); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return sensorDatas.toArray(new SensorData[sensorDatas.size()]); - } - } - -} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/transport/ArduinoMQTTConnector.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/transport/ArduinoMQTTConnector.java deleted file mode 100644 index 246fb7903..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/transport/ArduinoMQTTConnector.java +++ /dev/null @@ -1,193 +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.iot.arduino.controller.service.impl.transport; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; -import org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.ArduinoControllerService; -import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager; -import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; -import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; - -import java.io.File; -import java.util.LinkedList; -import java.util.UUID; - -public class ArduinoMQTTConnector extends MQTTTransportHandler { - private static Log log = LogFactory.getLog(ArduinoMQTTConnector.class); - private static final String subscribeTopic = "wso2/" + ArduinoConstants.DEVICE_TYPE + "/#"; - private static final String iotServerSubscriber = UUID.randomUUID().toString().substring(0, 5); - - private static final String MESSAGE_TO_SEND = "IN"; - private static final String MESSAGE_RECEIVED = "OUT"; - - private ArduinoMQTTConnector() { - super(iotServerSubscriber, ArduinoConstants.DEVICE_TYPE, - MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic); - } - - @Override - public void connect() { - Runnable connector = new Runnable() { - public void run() { - while (!isConnected()) { - try { - String brokerUsername = MqttConfig.getInstance().getMqttQueueUsername(); - String brokerPassword = MqttConfig.getInstance().getMqttQueuePassword(); - setUsernameAndPassword(brokerUsername, brokerPassword); - connectToQueue(); - } catch (TransportHandlerException e) { - log.error("Connection to MQTT Broker at: " + mqttBrokerEndPoint + " failed", e); - try { - Thread.sleep(timeoutInterval); - } catch (InterruptedException ex) { - log.error("MQTT-Connector: Thread Sleep Interrupt Exception.", ex); - } - } - - try { - subscribeToQueue(); - } catch (TransportHandlerException e) { - log.warn("Subscription to MQTT Broker at: " + mqttBrokerEndPoint + " failed", e); - } - } - } - }; - - - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - @Override - public void processIncomingMessage(MqttMessage message, String... messageParams) throws TransportHandlerException { - if(messageParams.length != 0) { - // owner and the deviceId are extracted from the MQTT topic to which the message was received. - // = [ServerName/Owner/DeviceType/DeviceId] - String topic = messageParams[0]; - String[] topicParams = topic.split("/"); - String deviceId = topicParams[3]; - - if (log.isDebugEnabled()) { - log.debug("Received MQTT message for: [DEVICE.ID-" + deviceId + "]"); - } - - int lastIndex = message.toString().lastIndexOf(":"); - String msgContext = message.toString().substring(lastIndex + 1); - - LinkedList deviceControlList; - LinkedList replyMessageList; - - if (msgContext.equals(MESSAGE_TO_SEND) || msgContext.equals(ArduinoConstants.STATE_ON) || msgContext.equals( - ArduinoConstants.STATE_OFF)) { - - if (log.isDebugEnabled()) { - log.debug("Received a control message: "); - log.debug("Control message topic: " + topic); - log.debug("Control message: " + message.toString()); - } - - synchronized (ArduinoControllerService.getInternalControlsQueue()) { - deviceControlList = ArduinoControllerService.getInternalControlsQueue().get(deviceId); - if (deviceControlList == null) { - ArduinoControllerService.getInternalControlsQueue() - .put(deviceId, deviceControlList = new LinkedList()); - } - } - deviceControlList.add(message.toString()); - - } else if (msgContext.equals(MESSAGE_RECEIVED)) { - - if (log.isDebugEnabled()) { - log.debug("Received reply from a device: "); - log.debug("Reply message topic: " + topic); - log.debug("Reply message: " + message.toString().substring(0, lastIndex)); - } - - synchronized (ArduinoControllerService.getReplyMsgQueue()) { - replyMessageList = ArduinoControllerService.getReplyMsgQueue().get(deviceId); - if (replyMessageList == null) { - ArduinoControllerService.getReplyMsgQueue() - .put(deviceId, replyMessageList = new LinkedList<>()); - } - } - replyMessageList.add(message.toString()); - } - } - } - - @Override - public void disconnect() { - Runnable stopConnection = new Runnable() { - public void run() { - while (isConnected()) { - try { - closeConnection(); - } catch (MqttException e) { - if (log.isDebugEnabled()) { - log.warn("Unable to 'STOP' MQTT connection at broker at: " + mqttBrokerEndPoint - + " for device-type - " + ArduinoConstants.DEVICE_TYPE, e); - } - - try { - Thread.sleep(timeoutInterval); - } catch (InterruptedException e1) { - log.error("MQTT-Terminator: Thread Sleep Interrupt Exception at device-type - " + - ArduinoConstants.DEVICE_TYPE, e1); - } - } - } - } - }; - - Thread terminatorThread = new Thread(stopConnection); - terminatorThread.setDaemon(true); - terminatorThread.start(); - } - - @Override - public void processIncomingMessage() throws TransportHandlerException { - - } - - @Override - public void processIncomingMessage(MqttMessage message) throws TransportHandlerException { - - } - - @Override - public void publishDeviceData() throws TransportHandlerException { - - } - - @Override - public void publishDeviceData(MqttMessage publishData) throws TransportHandlerException { - - } - - @Override - public void publishDeviceData(String... publishData) throws TransportHandlerException { - - } -} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index 291443c92..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/pom.xml deleted file mode 100644 index 9824474d5..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/pom.xml +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - arduino-plugin - org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT - ../pom.xml - - - - 4.0.0 - org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl - war - WSO2 Carbon - IoT Server Arduino ManagerService API - WSO2 Carbon - Arduino ManagerService API Implementation - http://wso2.org - - - - - org.wso2.carbon - org.wso2.carbon.utils - provided - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - - - org.apache.cxf - cxf-rt-frontend-jaxws - provided - - - org.apache.cxf - cxf-rt-frontend-jaxrs - provided - - - org.apache.cxf - cxf-rt-transports-http - provided - - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - provided - - - - - org.apache.httpcomponents - httpasyncclient - 4.1 - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.arduino.plugin.impl - provided - - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-jaxrs - - - javax - javaee-web-api - provided - - - javax.ws.rs - jsr311-api - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.webapp.publisher - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.jwt.client.extension - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.application.extension - provided - - - - - - - - maven-compiler-plugin - - UTF-8 - ${wso2.maven.compiler.source} - ${wso2.maven.compiler.target} - - - - maven-war-plugin - - arduino_mgt - - - - - - \ No newline at end of file diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager/service/impl/ArduinoManagerService.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager/service/impl/ArduinoManagerService.java deleted file mode 100644 index 6d5969c58..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager/service/impl/ArduinoManagerService.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl; - -import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; -import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; -import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl.util.APIUtil; -import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.util.ZipArchive; -import org.wso2.carbon.device.mgt.iot.util.ZipUtil; -import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClient; -import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClientManager; -import org.wso2.carbon.device.mgt.jwt.client.extension.dto.AccessTokenInfo; -import org.wso2.carbon.device.mgt.jwt.client.extension.exception.JWTClientException; -import org.wso2.carbon.user.api.UserStoreException; - -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.UUID; - -public class ArduinoManagerService { - - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; - private static final String KEY_TYPE = "PRODUCTION"; - private static ApiApplicationKey apiApplicationKey; - - @Path("manager/device/{device_id}") - @DELETE - public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); - try { - boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(deviceIdentifier); - if (removed) { - response.setStatus(Response.Status.OK.getStatusCode()); - - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - - } - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - } - - @Path("manager/device/{device_id}") - @PUT - public boolean updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name, - @Context HttpServletResponse response) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); - try { - Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); - device.setDeviceIdentifier(deviceId); - device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); - device.setName(name); - device.setType(ArduinoConstants.DEVICE_TYPE); - boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); - if (updated) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } - return updated; - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return false; - } - } - - @Path("manager/device/{device_id}") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Device getDevice(@PathParam("device_id") String deviceId) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); - try { - return APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; - } - } - - @Path("manager/devices") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Device[] getArduinoDevices() { - try { - List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser( - APIUtil.getAuthenticatedUser()); - ArrayList userDevicesforArduino = new ArrayList<>(); - for (Device device : userDevices) { - if (device.getType().equals(ArduinoConstants.DEVICE_TYPE) && - device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) { - userDevicesforArduino.add(device); - } - } - return userDevicesforArduino.toArray(new Device[]{}); - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; - } - } - - @Path("manager/device/download") - @GET - @Produces("application/octet-stream") - public Response downloadSketch(@QueryParam("deviceName") String customDeviceName) { - try { - ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName); - Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); - rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); - return rb.build(); - } catch (IllegalArgumentException ex) { - return Response.status(400).entity(ex.getMessage()).build();//bad request - } catch (DeviceManagementException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (DeviceControllerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (JWTClientException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (APIManagerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (UserStoreException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } - } - - @Path("manager/device/generate_link") - @GET - public Response generateSketchLink(@QueryParam("deviceName") String deviceName) { - try { - ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName); - Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); - return rb.build(); - } catch (IllegalArgumentException ex) { - return Response.status(400).entity(ex.getMessage()).build();//bad request - } catch (DeviceManagementException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (JWTClientException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (DeviceControllerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (APIManagerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (UserStoreException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } - } - - private ZipArchive createDownloadFile(String owner, String deviceName) - throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException, - UserStoreException { - if (owner == null) { - throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); - } - //create new device id - String deviceId = shortUUID(); - String applicationUsername = - PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() - .getAdminUserName(); - if (apiApplicationKey == null) { - APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); - String[] tags = {ArduinoConstants.DEVICE_TYPE}; - apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( - ArduinoConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true); - } - JWTClient jwtClient = JWTClientManager.getInstance().getJWTClient(); - String scopes = "device_type_" + ArduinoConstants.DEVICE_TYPE + " device_" + deviceId; - AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), - apiApplicationKey.getConsumerSecret(), owner, - scopes); - //create token - String accessToken = accessTokenInfo.getAccess_token(); - String refreshToken = accessTokenInfo.getRefresh_token(); - //Register the device with CDMF - boolean status = register(deviceId, deviceName); - if (!status) { - String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; - throw new DeviceManagementException(msg); - } - ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), - ArduinoConstants.DEVICE_TYPE, deviceId, - deviceName, accessToken, refreshToken); - zipFile.setDeviceId(deviceId); - return zipFile; - } - - private static String shortUUID() { - UUID uuid = UUID.randomUUID(); - long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); - return Long.toString(l, Character.MAX_RADIX); - } - - private boolean register(String deviceId, String name) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); - try { - if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { - response.setStatus(Response.Status.CONFLICT.getStatusCode()); - return false; - } - Device device = new Device(); - device.setDeviceIdentifier(deviceId); - EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); - enrolmentInfo.setDateOfEnrolment(new Date().getTime()); - enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); - enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); - enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); - device.setName(name); - device.setType(ArduinoConstants.DEVICE_TYPE); - enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); - device.setEnrolmentInfo(enrolmentInfo); - boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); - if (added) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } - return added; - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return false; - } - } -} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index 98bfb6d53..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index e2c67f55a..000000000 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - Arduino - Arduino - - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - true - - - - - managed-api-enabled - false - - - managed-api-owner - admin - - - managed-api-context-template - /arduino/{version} - - - managed-api-application - arduino - - - managed-api-isSecured - true - - diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/pom.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/pom.xml similarity index 61% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/pom.xml rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/pom.xml index 4b2b5e682..5962d72b0 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.controller.api/pom.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/pom.xml @@ -1,23 +1,74 @@ + + - androidsense-plugin + device-mgt-iot-arduino org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.0.4-SNAPSHOT ../pom.xml 4.0.0 - org.wso2.carbon.device.mgt.iot.androidsense.controller.api + org.wso2.carbon.device.mgt.iot.arduino.service.impl + 2.0.4-SNAPSHOT war - WSO2 Carbon - Android Sense Controller API - WSO2 Carbon - Android Sense Service Controller API Implementation + WSO2 Carbon - IoT Server Arduino Service API + WSO2 Carbon - Arduino Service API Implementation http://wso2.org + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.application.extension + 1.1.0-SNAPSHOT + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.jwt.client.extension + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.application.extension + provided + + org.wso2.carbon.devicemgt @@ -36,6 +87,20 @@ + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.data.publisher + 1.1.0-SNAPSHOT + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + org.apache.cxf @@ -52,6 +117,7 @@ cxf-rt-transports-http provided + org.eclipse.paho @@ -73,9 +139,10 @@ org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.androidsense.plugin + org.wso2.carbon.device.mgt.iot.arduino.plugin.impl provided + org.codehaus.jackson @@ -95,82 +162,6 @@ jsr311-api provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics - provided - - - - commons-httpclient.wso2 - commons-httpclient - provided - - - - org.wso2.carbon - org.wso2.carbon.utils - provided - - - org.bouncycastle.wso2 - bcprov-jdk15on - - - org.wso2.carbon - org.wso2.carbon.user.api - - - org.wso2.carbon - org.wso2.carbon.queuing - - - org.wso2.carbon - org.wso2.carbon.base - - - org.apache.axis2.wso2 - axis2 - - - org.igniterealtime.smack.wso2 - smack - - - org.igniterealtime.smack.wso2 - smackx - - - jaxen - jaxen - - - commons-fileupload.wso2 - commons-fileupload - - - org.apache.ant.wso2 - ant - - - org.apache.ant.wso2 - ant - - - commons-httpclient.wso2 - commons-httpclient - - - org.eclipse.equinox - javax.servlet - - - org.wso2.carbon - org.wso2.carbon.registry.api - - - org.wso2.carbon.devicemgt org.wso2.carbon.apimgt.annotations @@ -178,11 +169,12 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions + org.wso2.carbon.apimgt.webapp.publisher provided + @@ -196,10 +188,10 @@ maven-war-plugin - android_sense + arduino - + \ No newline at end of file diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java new file mode 100644 index 000000000..de4702357 --- /dev/null +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java @@ -0,0 +1,85 @@ +/* + * 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.arduino.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; +import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.DeviceData; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@API(name = "arduino", version = "1.0.0", context = "/arduino", tags = {"arduino"}) +@DeviceType(value = "arduino") +public interface ArduinoControllerService { + + @Path("register/device/{deviceId}/{ip}/{port}") + @POST + Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort, @Context HttpServletRequest request); + + @Path("device/{deviceId}/bulb") + @POST + @Feature(code = "bulb", name = "Control Bulb", type = "operation", description = "Control Bulb on Arduino Uno") + Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, + @FormParam("state") String state); + + @Path("device/{deviceId}/temperature") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Feature(code = "temperature", name = "Temperature", type = "monitor", description = "Request temperature reading " + + "from Arduino agent") + Response requestTemperature(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol); + + @Path("sensor") + @POST + @Consumes(MediaType.APPLICATION_JSON) + Response pushData(DeviceData dataMsg); + + @Path("{deviceId}/controls") + @GET + Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol); + + @Path("temperature") + @POST + @Consumes(MediaType.APPLICATION_JSON) + Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request); + + /** + * Retreive Sensor data for the device type + */ + @Path("stats/device/{deviceId}/sensors/temperature") + @GET + @Consumes("application/json") + @Produces("application/json") + Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from, + @QueryParam("to") long to); + +} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java new file mode 100644 index 000000000..0b7de4e64 --- /dev/null +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java @@ -0,0 +1,200 @@ +/* + * 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.arduino.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.data.publisher.AnalyticsDataRecord; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DeviceManagementAnalyticsException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.DeviceData; +import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorData; +import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils; +import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.concurrent.ConcurrentHashMap; + +public class ArduinoControllerServiceImpl implements ArduinoControllerService { + + private static Log log = LogFactory.getLog(ArduinoControllerServiceImpl.class); + private static Map> internalControlsQueue = new HashMap<>(); + private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); + + @Override + public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) { + String result; + if (log.isDebugEnabled()) { + log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: "); + } + String deviceHttpEndpoint = deviceIP + ":" + devicePort; + deviceToIpMap.put(deviceId, deviceHttpEndpoint); + result = "Device-IP Registered"; + if (log.isDebugEnabled()) { + log.debug(result); + } + return Response.ok(result).build(); + } + + @Override + public Response switchBulb(String deviceId, String protocol, String state) { + + LinkedList deviceControlList = internalControlsQueue.get(deviceId); + String operation = "BULB:" + state.toUpperCase(); + log.info(operation); + if (deviceControlList == null) { + deviceControlList = new LinkedList<>(); + deviceControlList.add(operation); + internalControlsQueue.put(deviceId, deviceControlList); + } else { + deviceControlList.add(operation); + } + return Response.status(Response.Status.OK.getStatusCode()).build(); + } + + @Override + public Response requestTemperature(String deviceId, String protocol) { + + try { + SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + ArduinoConstants.SENSOR_TEMPERATURE); + return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecord).build(); + } catch (DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + @Override + public Response pushData(DeviceData dataMsg) { + String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String deviceId = dataMsg.deviceId; + float pinData = dataMsg.value; + SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE, + String.valueOf(pinData), + Calendar.getInstance().getTimeInMillis()); + if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { + log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" + + deviceId + "] of owner [" + owner + "]"); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + return Response.status(Response.Status.OK.getStatusCode()).build(); + } + + @Override + public Response readControls(String deviceId, String protocol) { + String result; + LinkedList deviceControlList = internalControlsQueue.get(deviceId); + String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + if (deviceControlList == null) { + result = "No controls have been set for device " + deviceId + " of owner " + owner; + if (log.isDebugEnabled()) { + log.debug(result); + } + return Response.status(Response.Status.CONFLICT.getStatusCode()).entity(result).build(); + } else { + try { + result = deviceControlList.remove(); + if (log.isDebugEnabled()) { + log.debug(result); + } + return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(result).build(); + } catch (NoSuchElementException ex) { + result = "There are no more controls for device " + deviceId + " of owner " + owner; + if (log.isDebugEnabled()) { + log.debug(result); + } + return Response.status(Response.Status.NO_CONTENT.getStatusCode()).entity(result).build(); + } + } + } + + @Override + public Response pushTemperatureData(final DeviceData dataMsg, HttpServletRequest request) { + String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String deviceId = dataMsg.deviceId; + float temperature = dataMsg.value; + SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE, + String.valueOf(temperature), + Calendar.getInstance().getTimeInMillis()); + if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { + log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId + + "] of owner [" + owner + "]"); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + return Response.status(Response.Status.OK.getStatusCode()).build(); + } + + @Override + public Response getArduinoTemperatureStats(String deviceId, long from, long to) { + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + List sensorDatas = new ArrayList<>(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + String query = "deviceId:" + deviceId + " AND deviceType:" + + ArduinoConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; + String sensorTableName = ArduinoConstants.TEMPERATURE_EVENT_TABLE; + SensorData[] sensorDetails; + try { + List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); + Collections.sort(records, new Comparator() { + @Override + public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { + long t1 = (Long) o1.getValue("time"); + long t2 = (Long) o2.getValue("time"); + if (t1 < t2) { + return -1; + } else if (t1 > t2) { + return 1; + } else { + return 0; + } + } + }); + for (AnalyticsDataRecord record : records) { + SensorData sensorData = new SensorData(); + sensorData.setTime((long) record.getValue("time")); + sensorData.setValue("" + (float) record.getValue(ArduinoConstants.SENSOR_TEMPERATURE)); + sensorDatas.add(sensorData); + } + sensorDetails = sensorDatas.toArray(new SensorData[sensorDatas.size()]); + return Response.status(Response.Status.OK.getStatusCode()).entity(sensorDetails).build(); + } catch (DeviceManagementAnalyticsException e) { + String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; + log.error(errorMsg); + sensorDetails = sensorDatas.toArray(new SensorData[sensorDatas.size()]); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(sensorDetails).build(); + } + } + +} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java new file mode 100644 index 000000000..eb0524b31 --- /dev/null +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java @@ -0,0 +1,68 @@ +/* + * 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.arduino.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"}) +@DeviceType(value = "arduino") +public interface ArduinoManagerService { + + @Path("devices/{device_id}") + @PUT + Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name); + + @Path("devices/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + Response getDevice(@PathParam("device_id") String deviceId); + + @Path("devices/{device_id}") + @DELETE + Response removeDevice(@PathParam("device_id") String deviceId); + + @Path("devices") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + Response getArduinoDevices(); + + @Path("devices/download") + @GET + @Produces("application/octet-stream") + Response downloadSketch(@QueryParam("deviceName") String customDeviceName); + + @Path("devices/generate_link") + @GET + Response generateSketchLink(@QueryParam("deviceName") String deviceName); + +} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java new file mode 100644 index 000000000..db9ad20be --- /dev/null +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java @@ -0,0 +1,240 @@ +/* + * 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.arduino.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; +import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; +import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil; +import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.util.ZipArchive; +import org.wso2.carbon.device.mgt.iot.util.ZipUtil; +import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClient; +import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClientManager; +import org.wso2.carbon.device.mgt.jwt.client.extension.dto.AccessTokenInfo; +import org.wso2.carbon.device.mgt.jwt.client.extension.exception.JWTClientException; +import org.wso2.carbon.user.api.UserStoreException; +import javax.ws.rs.core.Response; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"}) +@DeviceType(value = "arduino") +public class ArduinoManagerServiceImpl implements ArduinoManagerService { + + private static final String KEY_TYPE = "PRODUCTION"; + private static ApiApplicationKey apiApplicationKey; + + @Override + public Response removeDevice(String deviceId) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); + try { + boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(deviceIdentifier); + if (removed) { + return Response.status(Response.Status.OK.getStatusCode()).entity(true).build(); + } else { + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); + } + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + @Override + public Response updateDevice(String deviceId, String name) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); + try { + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + device.setDeviceIdentifier(deviceId); + device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); + device.setName(name); + device.setType(ArduinoConstants.DEVICE_TYPE); + boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); + if (updated) { + return Response.status(Response.Status.OK.getStatusCode()).entity(true).build(); + } else { + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); + } + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + @Override + public Response getDevice(String deviceId) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); + try { + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + return Response.status(Response.Status.OK.getStatusCode()).entity(device).build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + @Override + public Response getArduinoDevices() { + try { + List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser( + APIUtil.getAuthenticatedUser()); + ArrayList userDevicesforArduino = new ArrayList<>(); + for (Device device : userDevices) { + if (device.getType().equals(ArduinoConstants.DEVICE_TYPE) && + device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) { + userDevicesforArduino.add(device); + } + } + Device[] devices = userDevicesforArduino.toArray(new Device[]{}); + return Response.status(Response.Status.OK.getStatusCode()).entity(devices).build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(true).build(); + } + } + + @Override + public Response downloadSketch(String customDeviceName) { + try { + ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName); + Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); + rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); + return rb.build(); + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (JWTClientException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (APIManagerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (UserStoreException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + } + + @Override + public Response generateSketchLink(String deviceName) { + try { + ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName); + Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); + return rb.build(); + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (JWTClientException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (APIManagerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (UserStoreException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + } + + private ZipArchive createDownloadFile(String owner, String deviceName) + throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException, + UserStoreException { + if (owner == null) { + throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); + } + //create new device id + String deviceId = shortUUID(); + String applicationUsername = + PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() + .getAdminUserName(); + if (apiApplicationKey == null) { + APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); + String[] tags = {ArduinoConstants.DEVICE_TYPE}; + apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( + ArduinoConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true); + } + JWTClient jwtClient = JWTClientManager.getInstance().getJWTClient(); + String scopes = "device_type_" + ArduinoConstants.DEVICE_TYPE + " device_" + deviceId; + AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), + apiApplicationKey.getConsumerSecret(), owner, + scopes); + //create token + String accessToken = accessTokenInfo.getAccess_token(); + String refreshToken = accessTokenInfo.getRefresh_token(); + //Register the device with CDMF + boolean status = register(deviceId, deviceName); + if (!status) { + String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; + throw new DeviceManagementException(msg); + } + ZipUtil ziputil = new ZipUtil(); + ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), + ArduinoConstants.DEVICE_TYPE, deviceId, + deviceName, accessToken, refreshToken); + zipFile.setDeviceId(deviceId); + return zipFile; + } + + private static String shortUUID() { + UUID uuid = UUID.randomUUID(); + long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); + return Long.toString(l, Character.MAX_RADIX); + } + + private boolean register(String deviceId, String name) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); + try { + if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { + return false; + } + Device device = new Device(); + device.setDeviceIdentifier(deviceId); + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); + enrolmentInfo.setDateOfEnrolment(new Date().getTime()); + enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); + enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); + enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); + device.setName(name); + device.setType(ArduinoConstants.DEVICE_TYPE); + enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); + device.setEnrolmentInfo(enrolmentInfo); + return APIUtil.getDeviceManagementService().enrollDevice(device); + } catch (DeviceManagementException e) { + return false; + } + } + +} diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/dto/DeviceData.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/dto/DeviceData.java similarity index 93% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/dto/DeviceData.java rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/dto/DeviceData.java index 00de218bd..d25354b53 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/dto/DeviceData.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/dto/DeviceData.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.dto; +package org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/dto/SensorData.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/dto/SensorData.java similarity index 91% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/dto/SensorData.java rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/dto/SensorData.java index 22a58f0f8..9e46a7cad 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/dto/SensorData.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/dto/SensorData.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.dto; +package org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/exception/ArduinoException.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/exception/ArduinoException.java similarity index 92% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/exception/ArduinoException.java rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/exception/ArduinoException.java index 82766a0db..1911190c1 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/exception/ArduinoException.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/exception/ArduinoException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.exception; +package org.wso2.carbon.device.mgt.iot.arduino.service.impl.exception; public class ArduinoException extends Exception { private static final long serialVersionUID = 118512086957330189L; diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api/util/APIUtil.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/APIUtil.java similarity index 96% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api/util/APIUtil.java rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/APIUtil.java index a593b67cf..fb759f25a 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api/util/APIUtil.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/APIUtil.java @@ -1,10 +1,11 @@ -package org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api.util; +package org.wso2.carbon.device.mgt.iot.arduino.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; + /** * This class provides utility functions used by REST-API. */ diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/util/ArduinoServiceUtils.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ArduinoServiceUtils.java similarity index 92% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/util/ArduinoServiceUtils.java rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ArduinoServiceUtils.java index bdba9fef1..421541c41 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/controller/service/impl/util/ArduinoServiceUtils.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ArduinoServiceUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl.util; +package org.wso2.carbon.device.mgt.iot.arduino.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,16 +26,10 @@ import org.apache.http.concurrent.FutureCallback; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClients; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; - import javax.ws.rs.HttpMethod; import java.io.BufferedReader; import java.io.IOException; @@ -50,8 +44,6 @@ import java.util.concurrent.Future; public class ArduinoServiceUtils { private static final Log log = LogFactory.getLog(ArduinoServiceUtils.class); - //TODO; replace this tenant domain - private static final String SUPER_TENANT = "carbon.super"; private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature"; public static String sendCommandViaHTTP(final String deviceHTTPEndpoint, String urlContext, diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/permissions.xml similarity index 68% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/META-INF/permissions.xml rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/permissions.xml index f2595154a..b202144cd 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/META-INF/permissions.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/permissions.xml @@ -31,57 +31,85 @@ Register Device /login - /controller/register/device/{deviceId}/{ip}/{port} + /register/device/*/*/* POST get device bulb statjs /login - /controller/device/{deviceId}/bulb + /device/*/bulb GET get device temperature /login - /controller/device/{deviceId}/temperature + /device/*/temperature GET get device temperature /login - /controller/device/{deviceId}/temperature + /device/*/temperature GET get device temperature /login - /controller/sensor + /sensor POST get controls /login - /controller/device/{deviceId}/controls + /device/*/controls POST push temperature /login - /controller/temperature + /temperature POST get temperature /login - /controller/stats/device/{deviceId}/sensors/temperature + /stats/device/*/sensors/temperature GET + + Get device + /device-mgt/user/devices/list + /devices/* + GET + + + + Remove device + /device-mgt/user/devices/remove + /devices/* + DELETE + + + + Download device + /device-mgt/user/devices/add + /devices/download + GET + + + + Update device + /device-mgt/user/devices/update + /devices/* + PUT + + \ No newline at end of file diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/META-INF/webapp-classloading.xml rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 77% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml index 14cc35426..c902d3024 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -23,10 +23,13 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + - + + + @@ -35,4 +38,3 @@ - diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/WEB-INF/web.xml rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/web.xml diff --git a/components/iot-plugins/arduino-plugin/pom.xml b/components/iot-plugins/arduino-plugin/pom.xml index 9e08a4120..9d2d85743 100644 --- a/components/iot-plugins/arduino-plugin/pom.xml +++ b/components/iot-plugins/arduino-plugin/pom.xml @@ -35,8 +35,7 @@ org.wso2.carbon.device.mgt.iot.arduino.analytics - org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl - org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl + org.wso2.carbon.device.mgt.iot.arduino.service.impl org.wso2.carbon.device.mgt.iot.arduino.plugin.impl org.wso2.carbon.device.mgt.iot.arduino.ui diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/pom.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/pom.xml deleted file mode 100644 index 104e025e7..000000000 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/pom.xml +++ /dev/null @@ -1,243 +0,0 @@ - - - - - digital-display-plugin - org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT - ../pom.xml - - - 4.0.0 - org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api - war - WSO2 Carbon - IoT Server DigitalDisplay API - WSO2 Carbon - Digital Display Service API Implementation - http://wso2.org - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.certificate.mgt.core - provided - - - commons-codec.wso2 - commons-codec - - - - - - - org.apache.cxf - cxf-rt-frontend-jaxws - provided - - - org.apache.cxf - cxf-rt-frontend-jaxrs - provided - - - org.apache.cxf - cxf-rt-transports-http - provided - - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - provided - - - - - org.apache.httpcomponents - httpasyncclient - 4.1 - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin - provided - - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-jaxrs - - - javax - javaee-web-api - provided - - - javax.ws.rs - jsr311-api - provided - - - - commons-httpclient.wso2 - commons-httpclient - provided - - - - org.wso2.carbon - org.wso2.carbon.utils - provided - - - org.bouncycastle.wso2 - bcprov-jdk15on - - - org.wso2.carbon - org.wso2.carbon.user.api - - - org.wso2.carbon - org.wso2.carbon.queuing - - - org.wso2.carbon - org.wso2.carbon.base - - - org.apache.axis2.wso2 - axis2 - - - org.igniterealtime.smack.wso2 - smack - - - org.igniterealtime.smack.wso2 - smackx - - - jaxen - jaxen - - - commons-fileupload.wso2 - commons-fileupload - - - org.apache.ant.wso2 - ant - - - org.apache.ant.wso2 - ant - - - commons-httpclient.wso2 - commons-httpclient - - - org.eclipse.equinox - javax.servlet - - - org.wso2.carbon - org.wso2.carbon.registry.api - - - - - - commons-codec.wso2 - commons-codec - - - - org.igniterealtime.smack.wso2 - smack - provided - - - org.igniterealtime.smack.wso2 - smackx - provided - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions - provided - - - - - - - - maven-compiler-plugin - - UTF-8 - ${wso2.maven.compiler.source} - ${wso2.maven.compiler.target} - - - - maven-war-plugin - - digital_display - - - - - - \ No newline at end of file diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/DigitalDisplayControllerService.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/DigitalDisplayControllerService.java deleted file mode 100644 index dde096d50..000000000 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/DigitalDisplayControllerService.java +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; -import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.exception.DigitalDisplayException; -import org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.util.DigitalDisplayMQTTConnector; -import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDisplayConstants; -import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; -import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; -import javax.servlet.http.HttpServletResponse; -import javax.websocket.server.PathParam; -import javax.ws.rs.FormParam; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; - - -@API(name = "digital_display", version = "1.0.0", context = "/digital_display", tags = {"digital_display"}) -@DeviceType(value = "digital_display") -public class DigitalDisplayControllerService { - - private static Log log = LogFactory.getLog(DigitalDisplayControllerService.class); - private static DigitalDisplayMQTTConnector digitalDisplayMQTTConnector; - - private boolean waitForServerStartup() { - while (!IoTServerStartupListener.isServerReady()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - return true; - } - } - return false; - } - - public DigitalDisplayMQTTConnector getDigitalDisplayMQTTConnector() { - return DigitalDisplayControllerService.digitalDisplayMQTTConnector; - } - - public void setDigitalDisplayMQTTConnector(final - DigitalDisplayMQTTConnector digitalDisplayMQTTConnector) { - - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - DigitalDisplayControllerService.digitalDisplayMQTTConnector = digitalDisplayMQTTConnector; - if (MqttConfig.getInstance().isEnabled()) { - digitalDisplayMQTTConnector.connect(); - } else { - log.warn("MQTT disabled in 'devicemgt-config.xml'. " + - "Hence, DigitalDisplayMQTTConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - /** - * Restart the running browser in the given digital display. - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - */ - @Path("device/{deviceId}/restart-browser") - @POST - @Feature(code = "restart-browser", name = "Restart Browser", type = "operation", - description = "Restart Browser in Digital Display") - public void restartBrowser(@PathParam("deviceId") String deviceId, - @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + "::", ""); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Terminate all running processes. If this execute we have to reboot digital display manually. - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - */ - @Path("device/{deviceId}/terminate-display") - @POST - @Feature(code = "terminate-display", name = "Terminate Display", type = "operation", - description = "Terminate all running process in Digital Display") - public void terminateDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + "::", ""); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - - } - - /** - * Reboot running digital display - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - */ - @Path("device/{deviceId}/restart-display") - @POST - @Feature(code = "restart-display", name = "Restart Display", type = "operation", - description = "Restart Digital Display") - public void restartDisplay(@PathParam("deviceId") String deviceId, - @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + "::", ""); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Search through the sequence and edit requested resource - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - * @param name name of page need to change - * @param attribute this can be path,time or type - * @param newValue page is used to replace path - */ - @Path("device/{deviceId}/edit-sequence") - @POST - @Feature(code = "edit-sequence", name = "Edit Sequence", type = "operation", - description = "Search through the sequence and edit requested resource in Digital Display") - public void editSequence(@PathParam("deviceId") String deviceId, @FormParam("name") String name, - @FormParam("attribute") String attribute, @FormParam("new-value") String newValue, - @HeaderParam("sessionId") String sessionId, @Context HttpServletResponse response) { - try { - String params = name + "|" + attribute + "|" + newValue; - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + "::", params); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - - } - - @Path("device/{deviceId}/upload-content") - @POST - @Feature(code = "upload-content", name = "Upload Content", type = "operation", - description = "Search through the sequence and edit requested resource in Digital Display") - public void uploadContent(@PathParam("deviceId") String deviceId, @FormParam("remote-path") String remotePath, - @FormParam("screen-name") String screenName, @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - String params = remotePath + "|" + screenName; - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.UPLOAD_CONTENT_CONSTANT + "::", - params); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Add new resource end to the existing sequence - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - * @param type type of new resource - * @param time new resource visible time - * @param path URL of the new resource - */ - @Path("device/{deviceId}/add-resource") - @POST - @Feature(code = "add-resource", name = "Add Resource", type = "operation", - description = "Add new resource end to the existing sequence in Digital Display") - public void addNewResource(@PathParam("deviceId") String deviceId, - @FormParam("type") String type, - @FormParam("time") String time, - @FormParam("path") String path, - @FormParam("name") String name, - @FormParam("position") String position, - @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - String params; - try { - if (position.isEmpty()) { - params = type + "|" + time + "|" + path + "|" + name; - } else { - params = type + "|" + time + "|" + path + "|" + name + - "|" + "after=" + position; - } - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT + "::", params); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Delete a resource in sequence - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - * @param name name of the page no need to delete - */ - @Path("device/{deviceId}/remove-resource") - @POST - @Feature(code = "remove-resource", name = "Remove Resource", type = "operation", - description = "Delete a resource from sequence in Digital Display") - public void removeResource(@PathParam("deviceId") String deviceId, @FormParam("name") String name, - @HeaderParam("sessionId") String sessionId, @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + "::", name); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Restart HTTP in running display - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - */ - @Path("device/{deviceId}/restart-server") - @POST - @Feature(code = "restart-server", name = "Restart Server", type = "operation", - description = "Stop HTTP Server running in Digital Display") - public void restartServer(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_SERVER_CONSTANT + "::", ""); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Get screenshot of running display - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - */ - @Path("device/{deviceId}/screenshot") - @POST - @Feature(code = "screenshot", name = "Take Screenshot", type = "operation", - description = "Show current view in Digital Display") - public void showScreenshot(@PathParam("deviceId") String deviceId, - @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.SCREENSHOT_CONSTANT + "::", ""); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Get statistics of running display - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - */ - @Path("device/{deviceId}/get-device-status") - @POST - @Feature(code = "get-device-status", name = "Get Device Statistics", type = "operation", - description = "Current status in Digital Display") - public void getDevicestatus(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_DEVICE_STATUS_CONSTANT + "::", ""); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Stop specific display - * - * @param deviceId id of the controlling digital display - * @param sessionId web socket id of the method invoke client - * @param response response type of the method - */ - @Path("device/{deviceId}/get-content-list") - @POST - @Feature(code = "get-content-list", name = "Get Content List", type = "operation", - description = "Content List in Digital Display") - public void getResources(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId, - @Context HttpServletResponse response) { - try { - sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_CONTENTLIST_CONSTANT + "::", ""); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException e) { - log.error(e); - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); - } catch (DigitalDisplayException e) { - log.error(e); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Send message via MQTT protocol - * - * @param deviceId id of the target digital display - * @param operation operation need to execute - * @param param parameters need to given operation - * @throws DeviceManagementException - * @throws DigitalDisplayException - */ - private void sendCommandViaMQTT(String deviceId, String operation, String param) - throws DeviceManagementException, DigitalDisplayException { - String topic = String.format(DigitalDisplayConstants.PUBLISH_TOPIC, deviceId); - String payload = operation + param; - try { - digitalDisplayMQTTConnector.publishToDigitalDisplay(topic, payload, 2, false); - } catch (TransportHandlerException e) { - String errorMessage = "Error publishing data to device with ID " + deviceId; - throw new DigitalDisplayException(errorMessage, e); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - -} diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api/DigitalDisplayManagerService.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api/DigitalDisplayManagerService.java deleted file mode 100644 index 063a23d39..000000000 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/manager/api/DigitalDisplayManagerService.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; -import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; -import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api.util.APIUtil; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.util.ZipArchive; -import org.wso2.carbon.device.mgt.iot.util.ZipUtil; -import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDisplayConstants; -import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClient; -import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClientManager; -import org.wso2.carbon.device.mgt.jwt.client.extension.dto.AccessTokenInfo; -import org.wso2.carbon.device.mgt.jwt.client.extension.exception.JWTClientException; -import org.wso2.carbon.user.api.UserStoreException; - -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Date; -import java.util.UUID; - -public class DigitalDisplayManagerService { - - private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; - private static final String KEY_TYPE = "PRODUCTION"; - private static ApiApplicationKey apiApplicationKey; - - @Path("manager/device") - @POST - public boolean register(@QueryParam("deviceId") String deviceId, @QueryParam("name") String name) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); - try { - if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { - response.setStatus(Response.Status.CONFLICT.getStatusCode()); - return false; - } - Device device = new Device(); - device.setDeviceIdentifier(deviceId); - EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); - enrolmentInfo.setDateOfEnrolment(new Date().getTime()); - enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); - enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); - device.setName(name); - device.setType(DigitalDisplayConstants.DEVICE_TYPE); - enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); - device.setEnrolmentInfo(enrolmentInfo); - boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); - if (added) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } - - return added; - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @Path("manager/device/{device_id}") - @DELETE - public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); - try { - boolean removed = APIUtil.getDeviceManagementService().disenrollDevice( - deviceIdentifier); - if (removed) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @Path("manager/device/{device_id}") - @PUT - public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); - try { - Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); - device.setDeviceIdentifier(deviceId); - device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); - device.setName(name); - device.setType(DigitalDisplayConstants.DEVICE_TYPE); - boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); - if (updated) { - response.setStatus(Response.Status.OK.getStatusCode()); - - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } - return updated; - } catch (DeviceManagementException e) { - log.error(e.getErrorMessage()); - return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @Path("manager/device/{device_id}") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Device getDevice(@PathParam("device_id") String deviceId) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); - try { - return APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); - } catch (DeviceManagementException ex) { - log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex); - return null; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @Path("manager/device/{sketch_type}/download") - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response downloadSketch(@QueryParam("deviceName") String deviceName, - @PathParam("sketch_type") String - sketchType) { - try { - ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); - Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile())); - response.type("application/zip"); - response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); - return response.build(); - } catch (IllegalArgumentException ex) { - return Response.status(400).entity(ex.getMessage()).build();//bad request - } catch (DeviceManagementException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (JWTClientException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (DeviceControllerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (APIManagerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (IOException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (UserStoreException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType) - throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException, - UserStoreException { - if (owner == null) { - throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); - } - //create new device id - String deviceId = shortUUID(); - if (apiApplicationKey == null) { - String applicationUsername = - PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName(); - APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); - String[] tags = {DigitalDisplayConstants.DEVICE_TYPE}; - apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( - DigitalDisplayConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true); - } - JWTClient jwtClient = JWTClientManager.getInstance().getJWTClient(); - String scopes = "device_type_" + DigitalDisplayConstants.DEVICE_TYPE + " device_" + deviceId; - AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), - apiApplicationKey.getConsumerSecret(), owner, scopes); - //create token - String accessToken = accessTokenInfo.getAccess_token(); - String refreshToken = accessTokenInfo.getRefresh_token(); - //adding registering data - boolean status; - //Register the device with CDMF - status = register(deviceId, deviceName); - if (!status) { - String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; - throw new DeviceManagementException(msg); - } - ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), sketchType, deviceId, - deviceName, accessToken, refreshToken); - zipFile.setDeviceId(deviceId); - return zipFile; - } - - private static String shortUUID() { - UUID uuid = UUID.randomUUID(); - long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); - return Long.toString(l, Character.MAX_RADIX); - } - -} diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index e5ae03197..000000000 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - Digital-Display-Agent-Webapp - - JAX-WS/JAX-RS MDM Android Endpoint - JAX-WS/JAX-RS Servlet - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - true - - - - - managed-api-enabled - false - - - managed-api-owner - admin - - - managed-api-context-template - /digital_display/{version} - - - managed-api-application - digital_display - - - managed-api-isSecured - true - - - - diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/pom.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/pom.xml similarity index 86% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/pom.xml rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/pom.xml index b68cd2afd..25355cd3f 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/pom.xml +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/pom.xml @@ -4,14 +4,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - digital-display-plugin + device-mgt-iot-digitaldisplay org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.0.4-SNAPSHOT ../pom.xml 4.0.0 - org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl + 2.0.4-SNAPSHOT war WSO2 Carbon - IoT Server DigitalDisplay API WSO2 Carbon - Digital Display Service API Implementation @@ -36,6 +37,32 @@ + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.application.extension + 1.1.0-SNAPSHOT + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.jwt.client.extension + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.application.extension + provided + + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.analytics @@ -237,7 +264,7 @@ maven-war-plugin - digital_display_mgt + digital_display diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerService.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerService.java new file mode 100644 index 000000000..eb0cdcaea --- /dev/null +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerService.java @@ -0,0 +1,175 @@ +/* + * 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.digitaldisplay.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; +import javax.websocket.server.PathParam; +import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +@API(name = "digital_display", version = "1.0.0", context = "/digital_display", tags = {"digital_display"}) +@DeviceType(value = "digital_display") +public interface DigitalDisplayControllerService { + + /** + * Restart the running browser in the given digital display. + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + */ + @Path("device/{deviceId}/restart-browser") + @POST + @Feature(code = "restart-browser", name = "Restart Browser", type = "operation", + description = "Restart Browser in Digital Display") + Response restartBrowser(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); + + /** + * Terminate all running processes. If this execute we have to reboot digital display manually. + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + */ + @Path("device/{deviceId}/terminate-display") + @POST + @Feature(code = "terminate-display", name = "Terminate Display", type = "operation", + description = "Terminate all running process in Digital Display") + Response terminateDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); + + /** + * Reboot running digital display + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + */ + @Path("device/{deviceId}/restart-display") + @POST + @Feature(code = "restart-display", name = "Restart Display", type = "operation", + description = "Restart Digital Display") + Response restartDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); + + /** + * Search through the sequence and edit requested resource + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + * @param name name of page need to change + * @param attribute this can be path,time or type + * @param newValue page is used to replace path + */ + @Path("device/{deviceId}/edit-sequence") + @POST + @Feature(code = "edit-sequence", name = "Edit Sequence", type = "operation", + description = "Search through the sequence and edit requested resource in Digital Display") + Response editSequence(@PathParam("deviceId") String deviceId, @FormParam("name") String name, + @FormParam("attribute") String attribute, @FormParam("new-value") String newValue, + @HeaderParam("sessionId") String sessionId); + + @Path("device/{deviceId}/upload-content") + @POST + @Feature(code = "upload-content", name = "Upload Content", type = "operation", + description = "Search through the sequence and edit requested resource in Digital Display") + Response uploadContent(@PathParam("deviceId") String deviceId, @FormParam("remote-path") String remotePath, + @FormParam("screen-name") String screenName, @HeaderParam("sessionId") String sessionId); + + /** + * Add new resource end to the existing sequence + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + * @param type type of new resource + * @param time new resource visible time + * @param path URL of the new resource + */ + @Path("device/{deviceId}/add-resource") + @POST + @Feature(code = "add-resource", name = "Add Resource", type = "operation", + description = "Add new resource end to the existing sequence in Digital Display") + Response addNewResource(@PathParam("deviceId") String deviceId, @FormParam("type") String type, + @FormParam("time") String time, @FormParam("path") String path, + @FormParam("name") String name, @FormParam("position") String position, + @HeaderParam("sessionId") String sessionId); + + /** + * Delete a resource in sequence + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + * @param name name of the page no need to delete + */ + @Path("device/{deviceId}/remove-resource") + @POST + @Feature(code = "remove-resource", name = "Remove Resource", type = "operation", + description = "Delete a resource from sequence in Digital Display") + Response removeResource(@PathParam("deviceId") String deviceId, @FormParam("name") String name, + @HeaderParam("sessionId") String sessionId); + + /** + * Restart HTTP in running display + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + */ + @Path("device/{deviceId}/restart-server") + @POST + @Feature(code = "restart-server", name = "Restart Server", type = "operation", + description = "Stop HTTP Server running in Digital Display") + Response restartServer(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); + + /** + * Get screenshot of running display + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + */ + @Path("device/{deviceId}/screenshot") + @POST + @Feature(code = "screenshot", name = "Take Screenshot", type = "operation", + description = "Show current view in Digital Display") + Response showScreenshot(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); + + /** + * Get statistics of running display + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + */ + @Path("device/{deviceId}/get-device-status") + @POST + @Feature(code = "get-device-status", name = "Get Device Statistics", type = "operation", + description = "Current status in Digital Display") + Response getDevicestatus(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); + + /** + * Stop specific display + * + * @param deviceId id of the controlling digital display + * @param sessionId web socket id of the method invoke client + */ + @Path("device/{deviceId}/get-content-list") + @POST + @Feature(code = "get-content-list", name = "Get Content List", type = "operation", + description = "Content List in Digital Display") + Response getResources(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); + +} diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerServiceImpl.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerServiceImpl.java new file mode 100644 index 000000000..0bb084db6 --- /dev/null +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerServiceImpl.java @@ -0,0 +1,242 @@ +/* + * 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.digitaldisplay.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.exception.DigitalDisplayException; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.util.DigitalDisplayMQTTConnector; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDisplayConstants; +import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; +import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; + +import javax.servlet.http.HttpServletResponse; +import javax.websocket.server.PathParam; +import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; + +public class DigitalDisplayControllerServiceImpl implements DigitalDisplayControllerService { + + private static Log log = LogFactory.getLog(DigitalDisplayControllerServiceImpl.class); + private static DigitalDisplayMQTTConnector digitalDisplayMQTTConnector; + + private boolean waitForServerStartup() { + while (!IoTServerStartupListener.isServerReady()) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + return true; + } + } + return false; + } + + public DigitalDisplayMQTTConnector getDigitalDisplayMQTTConnector() { + return DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector; + } + + public void setDigitalDisplayMQTTConnector(final + DigitalDisplayMQTTConnector digitalDisplayMQTTConnector) { + + Runnable connector = new Runnable() { + public void run() { + if (waitForServerStartup()) { + return; + } + DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector = digitalDisplayMQTTConnector; + if (MqttConfig.getInstance().isEnabled()) { + digitalDisplayMQTTConnector.connect(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. " + + "Hence, DigitalDisplayMQTTConnector not started."); + } + } + }; + Thread connectorThread = new Thread(connector); + connectorThread.setDaemon(true); + connectorThread.start(); + } + + public Response restartBrowser(String deviceId, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + "::", ""); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response terminateDisplay(String deviceId, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + "::", ""); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + + } + + public Response restartDisplay(String deviceId, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + "::", ""); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response editSequence(String deviceId, String name, String attribute, String newValue, String sessionId) { + try { + String params = name + "|" + attribute + "|" + newValue; + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + "::", params); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response uploadContent(String deviceId, String remotePath, String screenName, String sessionId) { + try { + String params = remotePath + "|" + screenName; + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.UPLOAD_CONTENT_CONSTANT + "::", + params); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response addNewResource(String deviceId, String type, String time, String path, String name, String position, + String sessionId) { + String params; + try { + if (position.isEmpty()) { + params = type + "|" + time + "|" + path + "|" + name; + } else { + params = type + "|" + time + "|" + path + "|" + name + + "|" + "after=" + position; + } + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT + "::", params); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response removeResource(String deviceId, String name, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + "::", name); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response restartServer(String deviceId, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_SERVER_CONSTANT + "::", ""); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response showScreenshot(String deviceId, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.SCREENSHOT_CONSTANT + "::", ""); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response getDevicestatus(String deviceId, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_DEVICE_STATUS_CONSTANT + "::", ""); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response getResources(String deviceId, String sessionId) { + try { + sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_CONTENTLIST_CONSTANT + "::", ""); + return Response.ok().build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + } catch (DigitalDisplayException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + /** + * Send message via MQTT protocol + * + * @param deviceId id of the target digital display + * @param operation operation need to execute + * @param param parameters need to given operation + * @throws DeviceManagementException + * @throws DigitalDisplayException + */ + private void sendCommandViaMQTT(String deviceId, String operation, String param) + throws DeviceManagementException, DigitalDisplayException { + String topic = String.format(DigitalDisplayConstants.PUBLISH_TOPIC, deviceId); + String payload = operation + param; + try { + digitalDisplayMQTTConnector.publishToDigitalDisplay(topic, payload, 2, false); + } catch (TransportHandlerException e) { + String errorMessage = "Error publishing data to device with ID " + deviceId; + throw new DigitalDisplayException(errorMessage, e); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + +} diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerService.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerService.java new file mode 100644 index 000000000..300fb211a --- /dev/null +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerService.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@API(name = "digital_display_mgt", version = "1.0.0", context = "/digital_display_mgt", tags = {"digital_display"}) +@DeviceType(value = "digital_display") +public interface DigitalDisplayManagerService { + + @Path("devices/{device_id}") + @PUT + Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name); + + @Path("devices/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + Response getDevice(@PathParam("device_id") String deviceId); + + @Path("devices/{device_id}") + @DELETE + Response removeDevice(@PathParam("device_id") String deviceId); + + @Path("devices/download") + @GET + @Produces("application/octet-stream") + Response downloadSketch(@QueryParam("deviceName") String customDeviceName); + +} diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerServiceImpl.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerServiceImpl.java new file mode 100644 index 000000000..6cfc34159 --- /dev/null +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerServiceImpl.java @@ -0,0 +1,201 @@ +/* + * 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.digitaldisplay.service.impl; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; +import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; +import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.util.APIUtil; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDisplayConstants; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.util.ZipArchive; +import org.wso2.carbon.device.mgt.iot.util.ZipUtil; +import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClient; +import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClientManager; +import org.wso2.carbon.device.mgt.jwt.client.extension.dto.AccessTokenInfo; +import org.wso2.carbon.device.mgt.jwt.client.extension.exception.JWTClientException; +import org.wso2.carbon.user.api.UserStoreException; + +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Date; +import java.util.UUID; + +public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerService { + + private static Log log = LogFactory.getLog(DigitalDisplayManagerServiceImpl.class); + private static final String KEY_TYPE = "PRODUCTION"; + private static ApiApplicationKey apiApplicationKey; + + private boolean register(String deviceId, String name) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + try { + if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { + return false; + } + Device device = new Device(); + device.setDeviceIdentifier(deviceId); + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); + enrolmentInfo.setDateOfEnrolment(new Date().getTime()); + enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); + enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); + device.setName(name); + device.setType(DigitalDisplayConstants.DEVICE_TYPE); + enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); + device.setEnrolmentInfo(enrolmentInfo); + boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); + return added; + } catch (DeviceManagementException e) { + return false; + } + } + + public Response removeDevice(String deviceId) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + try { + boolean removed = APIUtil.getDeviceManagementService().disenrollDevice( + deviceIdentifier); + if (removed) { + return Response.ok().build(); + } else { + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); + } + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response updateDevice(String deviceId, String name) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + try { + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + device.setDeviceIdentifier(deviceId); + device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); + device.setName(name); + device.setType(DigitalDisplayConstants.DEVICE_TYPE); + boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); + if (updated) { + return Response.ok().build(); + } else { + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); + } + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response getDevice(String deviceId) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + try { + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + return Response.ok().entity(device).build(); + } catch (DeviceManagementException ex) { + log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response downloadSketch(String deviceName) { + try { + ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName); + Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile())); + response.type("application/zip"); + response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); + return response.build(); + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (JWTClientException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (APIManagerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (IOException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (UserStoreException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + } + + private ZipArchive createDownloadFile(String owner, String deviceName) + throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException, + UserStoreException { + if (owner == null) { + throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); + } + //create new device id + String deviceId = shortUUID(); + if (apiApplicationKey == null) { + String applicationUsername = + PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName(); + APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); + String[] tags = {DigitalDisplayConstants.DEVICE_TYPE}; + apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( + DigitalDisplayConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true); + } + JWTClient jwtClient = JWTClientManager.getInstance().getJWTClient(); + String scopes = "device_type_" + DigitalDisplayConstants.DEVICE_TYPE + " device_" + deviceId; + AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), + apiApplicationKey.getConsumerSecret(), owner, scopes); + //create token + String accessToken = accessTokenInfo.getAccess_token(); + String refreshToken = accessTokenInfo.getRefresh_token(); + //adding registering data + boolean status; + //Register the device with CDMF + status = register(deviceId, deviceName); + if (!status) { + String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; + throw new DeviceManagementException(msg); + } + ZipUtil ziputil = new ZipUtil(); + ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), + DigitalDisplayConstants.DEVICE_TYPE, deviceId, + deviceName, accessToken, refreshToken); + zipFile.setDeviceId(deviceId); + return zipFile; + } + + private static String shortUUID() { + UUID uuid = UUID.randomUUID(); + long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); + return Long.toString(l, Character.MAX_RADIX); + } + +} diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/dto/DeviceJSON.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/dto/DeviceJSON.java similarity index 93% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/dto/DeviceJSON.java rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/dto/DeviceJSON.java index 309a6cf9f..538d490fe 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/dto/DeviceJSON.java +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/dto/DeviceJSON.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.dto; +package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.dto; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/exception/DigitalDisplayException.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/exception/DigitalDisplayException.java similarity index 92% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/exception/DigitalDisplayException.java rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/exception/DigitalDisplayException.java index c80d9e61a..dba4f6ff5 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/exception/DigitalDisplayException.java +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/exception/DigitalDisplayException.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.exception; +package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.exception; /** * Created by nuwan on 12/2/15. diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/model/ScreenShotModel.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/model/ScreenShotModel.java similarity index 89% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/model/ScreenShotModel.java rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/model/ScreenShotModel.java index e20f6991a..f0ed04021 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/model/ScreenShotModel.java +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/model/ScreenShotModel.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.model; +package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.model; public class ScreenShotModel { diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager/service/impl/util/APIUtil.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/util/APIUtil.java similarity index 96% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager/service/impl/util/APIUtil.java rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/util/APIUtil.java index 5ffe0198c..51b41cd72 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/manager/service/impl/util/APIUtil.java +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/util/APIUtil.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl.util; +package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/util/DigitalDisplayMQTTConnector.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/util/DigitalDisplayMQTTConnector.java similarity index 95% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/util/DigitalDisplayMQTTConnector.java rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/util/DigitalDisplayMQTTConnector.java index b356640ca..4c4c5b257 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/util/DigitalDisplayMQTTConnector.java +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/util/DigitalDisplayMQTTConnector.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.util; +package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -6,13 +6,12 @@ import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.json.JSONObject; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.model.ScreenShotModel; -import org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.websocket.DigitalDisplayWebSocketServerEndPoint; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.model.ScreenShotModel; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.websocket.DigitalDisplayWebSocketServerEndPoint; import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDisplayConstants; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; -import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.UUID; diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/websocket/DigitalDisplayWebSocketServerEndPoint.java b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/websocket/DigitalDisplayWebSocketServerEndPoint.java similarity index 95% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/websocket/DigitalDisplayWebSocketServerEndPoint.java rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/websocket/DigitalDisplayWebSocketServerEndPoint.java index 5ac54331e..1d28001b4 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/controller/api/websocket/DigitalDisplayWebSocketServerEndPoint.java +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/websocket/DigitalDisplayWebSocketServerEndPoint.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.websocket; +package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.websocket; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/META-INF/permissions.xml new file mode 100644 index 000000000..54f242bba --- /dev/null +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/META-INF/permissions.xml @@ -0,0 +1,137 @@ + + + + + + + + + + Get device + /device-mgt/user/devices/list + /devices/* + GET + + + + Remove device + /device-mgt/user/devices/remove + /devices/* + DELETE + + + + Download device + /device-mgt/user/devices/add + /devices/*/download + GET + + + + Update device + /device-mgt/user/devices/update + /devices/* + POST + + + + + + /device/*/restart-browser + POST + + + + + + /device/*/terminate-display + POST + + + + + + /device/*/restart-display + POST + + + + + + /device/*/edit-sequence + POST + + + + + + /device/*/upload-content + POST + + + + + + /device/*/add-resource + POST + + + + + + /device/*/remove-resource + POST + + + + + + /device/*/restart-server + POST + + + + + + /device/*/screenshot + POST + + + + + + /device/*/get-device-status + POST + + + + + + /device/*/get-content-list + POST + + + + diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 85% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml index edb998126..aed7bdb71 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -27,9 +27,12 @@ + class="org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.DigitalDisplayControllerServiceImpl"> + + @@ -37,7 +40,7 @@ + class="org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.util.DigitalDisplayMQTTConnector" > diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/WEB-INF/web.xml rename to components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl/src/main/webapp/WEB-INF/web.xml diff --git a/components/iot-plugins/digital-display-plugin/pom.xml b/components/iot-plugins/digital-display-plugin/pom.xml index ff50040e3..638c77813 100644 --- a/components/iot-plugins/digital-display-plugin/pom.xml +++ b/components/iot-plugins/digital-display-plugin/pom.xml @@ -33,8 +33,7 @@ http://wso2.org - org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api - org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api + org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin org.wso2.carbon.device.mgt.iot.digitaldisplay.ui diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/pom.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/pom.xml deleted file mode 100644 index 5f70578fb..000000000 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/pom.xml +++ /dev/null @@ -1,254 +0,0 @@ - - - - drone-analyzer-plugin - org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT - ../pom.xml - - - 4.0.0 - org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api - war - WSO2 Carbon - IoT Server Drone Analyzer Controller API - http://maven.apache.org - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.certificate.mgt.core - provided - - - commons-codec.wso2 - commons-codec - - - - - - - - org.apache.cxf - cxf-rt-frontend-jaxws - provided - - - org.apache.cxf - cxf-rt-frontend-jaxrs - provided - - - org.apache.cxf - cxf-rt-transports-http - provided - - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - provided - - - - - org.springframework - spring-context - - - - - org.apache.httpcomponents - httpasyncclient - 4.1 - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin - provided - - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-jaxrs - - - javax - javaee-web-api - provided - - - javax.ws.rs - jsr311-api - provided - - - commons-httpclient.wso2 - commons-httpclient - provided - - - - org.wso2.carbon - org.wso2.carbon.utils - provided - - - org.bouncycastle.wso2 - bcprov-jdk15on - - - org.wso2.carbon - org.wso2.carbon.user.api - - - org.wso2.carbon - org.wso2.carbon.queuing - - - org.wso2.carbon - org.wso2.carbon.base - - - org.apache.axis2.wso2 - axis2 - - - org.igniterealtime.smack.wso2 - smack - - - org.igniterealtime.smack.wso2 - smackx - - - jaxen - jaxen - - - commons-fileupload.wso2 - commons-fileupload - - - org.apache.ant.wso2 - ant - - - org.apache.ant.wso2 - ant - - - commons-httpclient.wso2 - commons-httpclient - - - org.eclipse.equinox - javax.servlet - - - org.wso2.carbon - org.wso2.carbon.registry.api - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions - provided - - - - commons-codec.wso2 - commons-codec - - - - org.igniterealtime.smack.wso2 - smack - provided - - - org.igniterealtime.smack.wso2 - smackx - provided - - - org.apache.commons - commons-collections4 - 4.0 - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - provided - - - - - - - - - - maven-compiler-plugin - - UTF-8 - ${wso2.maven.compiler.source} - ${wso2.maven.compiler.target} - - - - maven-war-plugin - - src/main/webapp/WEB-INF/web.xml - drone_analyzer - - - - - diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/META-INF/webapp-classloading.xml deleted file mode 100644 index fa4461919..000000000 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/META-INF/webapp-classloading.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - false - - - CXF,Carbon - diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/META-INF/webapp-classloading.xml deleted file mode 100644 index fa4461919..000000000 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/META-INF/webapp-classloading.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - false - - - CXF,Carbon - diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index 3a8849969..000000000 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 6947c58e1..000000000 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - WSO2 IoT Server - WSO2 IoT Server - - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - true - - - - - managed-api-enabled - false - - - managed-api-owner - admin - - - managed-api-context-template - /drone_analyzer/{version} - - - managed-api-application - drone_analyzer - - - managed-api-isSecured - true - - - - - - - - - - - - diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/pom.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/pom.xml similarity index 91% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/pom.xml rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/pom.xml index 34bf4cacd..c5ad56224 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/pom.xml +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/pom.xml @@ -1,17 +1,16 @@ - - drone-analyzer-plugin + device-mgt-iot-droneanalyzer org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.0.4-SNAPSHOT ../pom.xml - 4.0.0 - org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api + org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl + 2.0.4-SNAPSHOT war - WSO2 Carbon - IoT Server Drone Analyzer Manager API + WSO2 Carbon - IoT Server Drone Analyzer API http://maven.apache.org @@ -35,7 +34,8 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics + org.wso2.carbon.device.mgt.analytics.data.publisher + 1.1.0-SNAPSHOT provided @@ -56,8 +56,6 @@ - - org.apache.cxf @@ -226,6 +224,16 @@ org.wso2.carbon.apimgt.annotations provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.application.extension + 1.1.0-SNAPSHOT + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.jwt.client.extension @@ -253,7 +261,7 @@ maven-war-plugin src/main/webapp/WEB-INF/web.xml - drone_analyzer_mgt + drone_analyzer diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerService.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerService.java new file mode 100644 index 000000000..fbc0b7108 --- /dev/null +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerService.java @@ -0,0 +1,46 @@ +/* + * 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.droneanalyzer.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +@API(name = "drone_analyzer", version = "1.0.0", context = "/drone_analyzer", tags = {"drone_analyzer"}) +@DeviceType(value = "drone_analyzer") +public interface DroneControllerService { + + @Path("device/register/{deviceId}/{ip}/{port}") + @POST + Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort); + + @Path("device/{deviceId}/send_command") + @POST + /*@Feature( code="send_command", name="Send Command", type="operation", + description="Send Commands to Drone")*/ + Response droneController(@PathParam("deviceId") String deviceId, @FormParam("action") String action, + @FormParam("duration") String duration, @FormParam("speed") String speed); + +} \ No newline at end of file diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java similarity index 51% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java index 17ea3c5d0..6e6f0e69e 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java @@ -15,68 +15,48 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.util.DroneAnalyzerServiceUtils; +import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.util.DroneAnalyzerServiceUtils; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.impl.DroneControllerImpl; + import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import java.util.concurrent.ConcurrentHashMap; -@API( name="drone_analyzer", version="1.0.0", context="/drone_analyzer", tags = {"drone_analyzer"}) -@DeviceType( value = "drone_analyzer") -public class DroneControllerService { +public class DroneControllerServiceImpl implements DroneControllerService { - private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneControllerService.class); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; + private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneControllerServiceImpl.class); private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); private DroneController droneController = new DroneControllerImpl(); - - @Path("controller/register/{deviceId}/{ip}/{port}") - @POST - public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, - @PathParam("port") String devicePort, @Context HttpServletResponse response) { - try { - String result; - String deviceHttpEndpoint = deviceIP + ":" + devicePort; - deviceToIpMap.put(deviceId, deviceHttpEndpoint); - result = "Device-IP Registered"; - response.setStatus(Response.Status.OK.getStatusCode()); - if (log.isDebugEnabled()) { - log.debug(result); - } - return Response.ok(Response.Status.OK.getStatusCode()).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); + public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort) { + String result; + String deviceHttpEndpoint = deviceIP + ":" + devicePort; + deviceToIpMap.put(deviceId, deviceHttpEndpoint); + result = "Device-IP Registered"; + if (log.isDebugEnabled()) { + log.debug(result); } + return Response.ok(Response.Status.OK.getStatusCode()).build(); } - @Path("controller/device/{deviceId}/send_command") - @POST - /*@Feature( code="send_command", name="Send Command", type="operation", - description="Send Commands to Drone")*/ - public Response droneController(@PathParam("deviceId") String deviceId, - @FormParam("action") String action, @FormParam("duration") String duration, - @FormParam("speed") String speed){ + public Response droneController(String deviceId, String action, String duration, String speed) { try { DroneAnalyzerServiceUtils.sendControlCommand(droneController, deviceId, action, Double.valueOf(speed), - Double.valueOf(duration)); + Double.valueOf(duration)); return Response.status(Response.Status.ACCEPTED).build(); } catch (DeviceManagementException e) { - log.error("Drone command didn't success. Try again, \n"+ e); + log.error("Drone command didn't success. Try again, \n" + e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); } } } diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerService.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerService.java new file mode 100644 index 000000000..377f09eed --- /dev/null +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerService.java @@ -0,0 +1,69 @@ +/* + * 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.droneanalyzer.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +@API(name = "drone_analyzer_mgt", version = "1.0.0", context = "/drone_analyzer_mgt", tags = {"drone_analyzer"}) +@DeviceType(value = "drone_analyzer") +public interface DroneManagerService { + + @Path("devices/{device_id}") + @DELETE + Response removeDevice(@PathParam("device_id") String deviceId); + + @Path("devices/{device_id}") + @PUT + Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name); + + @Path("devices/{device_id}") + @GET + @Consumes("application/json") + @Produces("application/json") + Response getDevice(@PathParam("device_id") String deviceId); + + @Path("devices") + @GET + @Consumes("application/json") + @Produces("application/json") + Response getDroneDevices(); + + @Path("devices/{sketch_type}/download") + @GET + @Produces("application/octet-stream") + Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String sketchType); + + @Path("devices/{sketch_type}/generate_link") + @GET + Response generateSketchLink(@QueryParam("deviceName") String deviceName, + @PathParam("sketch_type") String sketchType); + +} + diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api/impl/DroneManagerService.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java similarity index 59% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api/impl/DroneManagerService.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java index 149c9070e..1cd052644 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api/impl/DroneManagerService.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api.impl; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; @@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api.impl.util.APIUtil; +import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.util.ZipArchive; @@ -40,18 +40,6 @@ import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClientManager; import org.wso2.carbon.device.mgt.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.device.mgt.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; - -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -60,23 +48,18 @@ import java.util.Date; import java.util.List; import java.util.UUID; -public class DroneManagerService { +public class DroneManagerServiceImpl implements DroneManagerService { - private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneManagerService.class); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; + private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneManagerServiceImpl.class); private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; - @Path("manager/device/register") - @POST - public boolean register(@QueryParam("deviceId") String deviceId, @QueryParam("name") String name) { + private boolean register(String deviceId, String name) { try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { - response.setStatus(Response.Status.CONFLICT.getStatusCode()); return false; } Device device = new Device(); @@ -91,49 +74,33 @@ public class DroneManagerService { enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); device.setEnrolmentInfo(enrolmentInfo); boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); - if (added) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } return added; } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @Path("manager/device/{device_id}") - @DELETE - public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) { - try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); - boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(deviceIdentifier); - if (removed) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - - } - } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } + } } - @Path("manager/device/{device_id}") - @PUT - public boolean updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name, - @Context HttpServletResponse response) { + public Response removeDevice(String deviceId) { try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); + boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(deviceIdentifier); + if (removed) { + return Response.ok().build(); + } else { + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); + } + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + public Response updateDevice(String deviceId, String name) { + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); device.setDeviceIdentifier(deviceId); device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); @@ -141,102 +108,75 @@ public class DroneManagerService { device.setType(DroneConstants.DEVICE_TYPE); boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); if (updated) { - response.setStatus(Response.Status.OK.getStatusCode()); + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } - return updated; } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } - @Path("manager/device/{device_id}") - @GET - @Consumes("application/json") - @Produces("application/json") - public Device getDevice(@PathParam("device_id") String deviceId) { + public Response getDevice(String deviceId) { try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); - return APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + return Response.ok().entity(device).build(); } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } - @Path("manager/devices") - @GET - @Consumes("application/json") - @Produces("application/json") - public Device[] getDroneDevices() { + public Response getDroneDevices() { try { List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser()); ArrayList userDevicesforDrone = new ArrayList<>(); for (Device device : userDevices) { if (device.getType().equals(DroneConstants.DEVICE_TYPE) && - device.getEnrolmentInfo().getStatus().equals( - EnrolmentInfo.Status.ACTIVE)) { + device.getEnrolmentInfo().getStatus().equals( + EnrolmentInfo.Status.ACTIVE)) { userDevicesforDrone.add(device); } } - return userDevicesforDrone.toArray(new Device[]{}); + Device[] devices = userDevicesforDrone.toArray(new Device[]{}); + return Response.ok().entity(devices).build(); } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + public Response downloadSketch(String deviceName, String sketchType) { + //create new device id + String deviceId = shortUUID(); + //create token + String token = UUID.randomUUID().toString(); + String refreshToken = UUID.randomUUID().toString(); + //adding registering data + boolean status = register(deviceId, deviceName); + if (!status) { + return Response.status(500).entity( + "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + + APIUtil.getAuthenticatedUser()).build(); - @Path("manager/device/{sketch_type}/download") - @GET - @Produces("application/octet-stream") - public Response downloadSketch(@QueryParam("deviceName") String deviceName, - @PathParam("sketch_type") String sketchType) { + } + ZipUtil ziputil = new ZipUtil(); + ZipArchive zipFile; try { - //create new device id - String deviceId = shortUUID(); - //create token - String token = UUID.randomUUID().toString(); - String refreshToken = UUID.randomUUID().toString(); - //adding registering data - boolean status = register(deviceId, deviceName); - if (!status) { - return Response.status(500).entity( - "Error occurred while registering the device with " + "id: " + deviceId - + " owner:" + APIUtil.getAuthenticatedUser()).build(); + zipFile = ziputil.createZipFile(APIUtil.getAuthenticatedUser(), APIUtil.getTenantDomainOftheUser(), + sketchType, deviceId, deviceName, token, refreshToken); + } catch (DeviceManagementException ex) { + return Response.status(500).entity("Error occurred while creating zip file").build(); + } + Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); + rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); + return rb.build(); - } - ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile; - try { - zipFile = ziputil.createZipFile(APIUtil.getAuthenticatedUser(), APIUtil.getTenantDomainOftheUser(), - sketchType, deviceId, deviceName, token, refreshToken); - } catch (DeviceManagementException ex) { - return Response.status(500).entity("Error occurred while creating zip file").build(); - } - Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); - rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); - return rb.build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } + } - @Path("manager/device/{sketch_type}/generate_link") - @GET - public Response generateSketchLink(@QueryParam("deviceName") String deviceName, - @PathParam("sketch_type") String sketchType) { + public Response generateSketchLink(String deviceName, String sketchType) { try { ZipArchive zipFile = createDownloadFile(deviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); @@ -250,13 +190,11 @@ public class DroneManagerService { } catch (DeviceControllerException ex) { return Response.status(500).entity(ex.getMessage()).build(); } catch (APIManagerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (UserStoreException ex) { return Response.status(500).entity(ex.getMessage()).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } + } catch (UserStoreException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + } private ZipArchive createDownloadFile(String deviceName, String sketchType) throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException, @@ -272,7 +210,7 @@ public class DroneManagerService { DroneConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true); } JWTClient jwtClient = JWTClientManager.getInstance().getJWTClient(); - String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String scopes = "device_type_" + DroneConstants.DEVICE_TYPE + " device_" + deviceId; AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), apiApplicationKey.getConsumerSecret(), owner, scopes); @@ -292,7 +230,8 @@ public class DroneManagerService { status = xmppServerClient.createXMPPAccount(newXmppAccount); if (!status) { String msg = "XMPP Account was not created for device - " + deviceId + " of owner - " + - APIUtil.getAuthenticatedUser() + ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config.server.configs"; + APIUtil.getAuthenticatedUser() + ".XMPP might have been disabled in " + + "org.wso2.carbon.device.mgt.iot.common.config.server.configs"; log.warn(msg); throw new DeviceManagementException(msg); } @@ -301,7 +240,7 @@ public class DroneManagerService { status = register(deviceId, deviceName); if (!status) { String msg = "Error occurred while registering the device with " + "id: " + deviceId - + " owner:" + APIUtil.getAuthenticatedUser(); + + " owner:" + APIUtil.getAuthenticatedUser(); throw new DeviceManagementException(msg); } ZipUtil ziputil = new ZipUtil(); diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneRealTimeService.java similarity index 93% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneRealTimeService.java index c0c85bc94..da4ef1533 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneRealTimeService.java @@ -15,13 +15,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.trasformer.MessageTransformer; +import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.transport.DroneAnalyzerXMPPConnector; +import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.trasformer.MessageTransformer; import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants; import javax.websocket.OnClose; diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/exception/DroneAnalyzerException.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/exception/DroneAnalyzerException.java similarity index 92% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/exception/DroneAnalyzerException.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/exception/DroneAnalyzerException.java index 7421c5932..d72634f89 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/exception/DroneAnalyzerException.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/exception/DroneAnalyzerException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.exception; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.exception; public class DroneAnalyzerException extends Exception { private static final long serialVersionUID = 118512086958330189L; diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/transport/DroneAnalyzerXMPPConnector.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/transport/DroneAnalyzerXMPPConnector.java similarity index 97% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/transport/DroneAnalyzerXMPPConnector.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/transport/DroneAnalyzerXMPPConnector.java index a4130c06b..5c4a002f9 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/transport/DroneAnalyzerXMPPConnector.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/transport/DroneAnalyzerXMPPConnector.java @@ -16,13 +16,13 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.transport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jivesoftware.smack.packet.Message; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.trasformer.MessageTransformer; +import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.trasformer.MessageTransformer; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler; diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/trasformer/MessageTransformer.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/trasformer/MessageTransformer.java similarity index 98% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/trasformer/MessageTransformer.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/trasformer/MessageTransformer.java index 74d080771..ddb5af863 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/trasformer/MessageTransformer.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/trasformer/MessageTransformer.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.trasformer; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.trasformer; import org.apache.commons.collections4.queue.CircularFifoQueue; diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api/impl/util/APIUtil.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/util/APIUtil.java similarity index 96% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api/impl/util/APIUtil.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/util/APIUtil.java index e9980fa5a..4af82a9ba 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/manager/api/impl/util/APIUtil.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/util/APIUtil.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api.impl.util; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/util/DroneAnalyzerServiceUtils.java similarity index 95% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/util/DroneAnalyzerServiceUtils.java index 0b6a3abff..4b01bd8d6 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/util/DroneAnalyzerServiceUtils.java @@ -16,12 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.util; +package org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.util; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector; +import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl.transport.DroneAnalyzerXMPPConnector; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/META-INF/permissions.xml similarity index 70% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/META-INF/permissions.xml rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/META-INF/permissions.xml index 91ed83257..f25c321b8 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/META-INF/permissions.xml +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/META-INF/permissions.xml @@ -31,36 +31,57 @@ Get device /device-mgt/user/devices/list - /manager/device/{device_id} + /devices/* GET - - Add device - /device-mgt/user/devices/add - /manager/device - POST - - Remove device /device-mgt/user/devices/remove - /manager/device/{device_id} + /devices/* DELETE Download device /device-mgt/user/devices/add - /manager/device/{sketch_type}/download + /devices/*/download GET Update device /device-mgt/user/devices/update - /manager/device/{device_id} + /devices/* POST + + + + /devices + GET + + + + + + /devices/*/generate_link + GET + + + + + + /device/register/*/*/* + POST + + + + + + /device/*/send_command + POST + + \ No newline at end of file diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 80% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml index cbaf62e25..9e2ebee0f 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -28,11 +28,15 @@ - + - - + + + + diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/webapp/WEB-INF/web.xml rename to components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl/src/main/webapp/WEB-INF/web.xml diff --git a/components/iot-plugins/drone-analyzer-plugin/pom.xml b/components/iot-plugins/drone-analyzer-plugin/pom.xml index 4260130be..63728b11c 100644 --- a/components/iot-plugins/drone-analyzer-plugin/pom.xml +++ b/components/iot-plugins/drone-analyzer-plugin/pom.xml @@ -34,8 +34,7 @@ org.wso2.carbon.device.mgt.iot.droneanalyzer.ui - org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api - org.wso2.carbon.device.mgt.iot.droneanalyzer.manager.api + org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.api/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.api/pom.xml index b81253fe7..25c69e357 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.api/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.api/pom.xml @@ -103,7 +103,7 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics + org.wso2.carbon.device.mgt.analytics.data.publisher provided diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml index f7c729133..76bc21a38 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/pom.xml @@ -191,7 +191,7 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics + org.wso2.carbon.device.mgt.analytics.data.publisher diff --git a/components/iot-plugins/pom.xml b/components/iot-plugins/pom.xml index 45e660e7c..5738bf180 100644 --- a/components/iot-plugins/pom.xml +++ b/components/iot-plugins/pom.xml @@ -33,12 +33,12 @@ http://wso2.org - - - - - - + androidsense-plugin + arduino-plugin + digital-display-plugin + drone-analyzer-plugin + raspberrypi-plugin + virtual-fire-alarm-plugin iot-base-plugin diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml deleted file mode 100644 index 4173e23e1..000000000 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - raspberrypi-plugin - org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT - ../pom.xml - - - 4.0.0 - org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl - war - WSO2 Carbon - IoT Server RaspberryPi Controller API - WSO2 Carbon - RaspberryPi Controller Service API Implementation - http://wso2.org - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - - org.apache.cxf - cxf-rt-frontend-jaxws - provided - - - org.apache.cxf - cxf-rt-frontend-jaxrs - provided - - - org.apache.cxf - cxf-rt-transports-http - provided - - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - provided - - - - - org.apache.httpcomponents - httpasyncclient - 4.1 - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl - provided - - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-jaxrs - - - javax - javaee-web-api - provided - - - javax.ws.rs - jsr311-api - provided - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - provided - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions - provided - - - - - - - - - - maven-compiler-plugin - - UTF-8 - ${wso2.maven.compiler.source} - ${wso2.maven.compiler.target} - - - - maven-war-plugin - - raspberrypi - - - - - - \ No newline at end of file diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/RaspberryPiControllerService.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/RaspberryPiControllerService.java deleted file mode 100644 index 1af824749..000000000 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/RaspberryPiControllerService.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.common.AnalyticsDataRecord; -import org.wso2.carbon.device.mgt.analytics.exception.DeviceManagementAnalyticsException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; -import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.dto.DeviceData; -import org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.dto.SensorData; -import org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.transport.RaspberryPiMQTTConnector; -import org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.util.RaspberrypiServiceUtils; -import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; -import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - -@API(name = "raspberrypi", version = "1.0.0", context = "/raspberrypi", tags = {"raspberrypi"}) -@DeviceType(value = "raspberrypi") -public class RaspberryPiControllerService { - - private static Log log = LogFactory.getLog(RaspberryPiControllerService.class); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; - private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); - private RaspberryPiMQTTConnector raspberryPiMQTTConnector; - - private boolean waitForServerStartup() { - while (!IoTServerStartupListener.isServerReady()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - return true; - } - } - return false; - } - - public RaspberryPiMQTTConnector getRaspberryPiMQTTConnector() { - return raspberryPiMQTTConnector; - } - - public void setRaspberryPiMQTTConnector( - final RaspberryPiMQTTConnector raspberryPiMQTTConnector) { - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - RaspberryPiControllerService.this.raspberryPiMQTTConnector = raspberryPiMQTTConnector; - if (MqttConfig.getInstance().isEnabled()) { - raspberryPiMQTTConnector.connect(); - } else { - log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, RaspberryPiMQTTConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - @Path("controller/register/{deviceId}/{ip}/{port}") - @POST - public String registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, - @PathParam("port") String devicePort, @Context HttpServletResponse response, - @Context HttpServletRequest request) { - try { - String result; - if (log.isDebugEnabled()) { - log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId); - } - String deviceHttpEndpoint = deviceIP + ":" + devicePort; - deviceToIpMap.put(deviceId, deviceHttpEndpoint); - result = "Device-IP Registered"; - response.setStatus(Response.Status.OK.getStatusCode()); - if (log.isDebugEnabled()) { - log.debug(result); - } - return result; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - - @Path("controller/device/{deviceId}/bulb") - @POST - @Feature(code = "bulb", name = "Bulb On / Off", type = "operation", - description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)") - public void switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state, - @Context HttpServletResponse response) { - try { - String switchToState = state.toUpperCase(); - if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals( - RaspberrypiConstants.STATE_OFF)) { - log.error("The requested state change shoud be either - 'ON' or 'OFF'"); - response.setStatus(Response.Status.BAD_REQUEST.getStatusCode()); - return; - } - String callUrlPattern = RaspberrypiConstants.BULB_CONTEXT + switchToState; - try { - String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); - if (deviceHTTPEndpoint == null) { - response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); - return; - } - RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true); - } catch (DeviceManagementException e) { - log.error("Failed to send switch-bulb request to device [" + deviceId + "] via "); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return; - } - response.setStatus(Response.Status.OK.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @Path("controller/device/{deviceId}/readtemperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Feature(code = "readtemperature", name = "Temperature", type = "monitor", - description = "Request temperature reading from Raspberry Pi agent") - public SensorRecord requestTemperature(@PathParam("deviceId") String deviceId, - @Context HttpServletResponse response) { - try { - SensorRecord sensorRecord = null; - if (log.isDebugEnabled()) { - log.debug("Sending request to read raspberrypi-temperature of device [" + deviceId + "] via "); - } - try { - String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); - if (deviceHTTPEndpoint == null) { - response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); - } - String temperatureValue = RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, - RaspberrypiConstants - .TEMPERATURE_CONTEXT, - - false); - SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, - temperatureValue, Calendar.getInstance() - .getTimeInMillis - ()); - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - RaspberrypiConstants - .SENSOR_TEMPERATURE); - } catch (DeviceManagementException | DeviceControllerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - response.setStatus(Response.Status.OK.getStatusCode()); - return sensorRecord; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - @Path("controller/push_temperature") - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void pushTemperatureData(final DeviceData dataMsg, @Context HttpServletResponse response, - @Context HttpServletRequest request) { - try { - String owner = dataMsg.owner; - String deviceId = dataMsg.deviceId; - String deviceIp = dataMsg.reply; - float temperature = dataMsg.value; - String registeredIp = deviceToIpMap.get(deviceId); - if (registeredIp == null) { - log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " + deviceIp + - " for device ID - " + deviceId); - response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); - return; - } else if (!registeredIp.equals(deviceIp)) { - log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId + - " is already registered under some other IP. Re-registration required"); - response.setStatus(Response.Status.CONFLICT.getStatusCode()); - return; - } - if (log.isDebugEnabled()) { - log.debug("Received Pin Data Value: " + temperature + " degrees C"); - } - SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, - String.valueOf(temperature), - Calendar.getInstance().getTimeInMillis()); - if (!RaspberrypiServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" + - deviceId + "] of owner [" + owner + "]"); - } - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Retreive Sensor data for the device type - */ - @Path("controller/stats/device/{deviceId}/sensors/temperature") - @GET - @Consumes("application/json") - @Produces("application/json") - public SensorData[] getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, - @QueryParam("username") String user, - @QueryParam("from") long from, - @QueryParam("to") long to) { - - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - List sensorDatas = new ArrayList<>(); - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx - .getOSGiService(DeviceAnalyticsService.class, null); - String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + - RaspberrypiConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; - String sensorTableName = RaspberrypiConstants.TEMPERATURE_EVENT_TABLE; - try { - List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); - Collections.sort(records, new Comparator() { - @Override - public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { - long t1 = (Long) o1.getValue("time"); - long t2 = (Long) o2.getValue("time"); - if (t1 < t2) { - return -1; - } else if (t1 > t2) { - return 1; - } else { - return 0; - } - } - }); - for (AnalyticsDataRecord record : records) { - SensorData sensorData = new SensorData(); - sensorData.setTime((long) record.getValue("time")); - sensorData.setValue("" + (float) record.getValue(RaspberrypiConstants.SENSOR_TEMPERATURE)); - sensorDatas.add(sensorData); - } - return sensorDatas.toArray(new SensorData[sensorDatas.size()]); - } catch (DeviceManagementAnalyticsException e) { - String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; - log.error(errorMsg); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return sensorDatas.toArray(new SensorData[sensorDatas.size()]); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } -} diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml deleted file mode 100644 index fa4461919..000000000 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - false - - - CXF,Carbon - diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml deleted file mode 100644 index fa4461919..000000000 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - false - - - CXF,Carbon - diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index 48216c9b8..000000000 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index abda0a6a4..000000000 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - RaspberryPi - RaspberryPi - - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - - CXFServlet - /* - - - isAdminService - false - - - doAuthentication - true - - - - - managed-api-enabled - false - - - managed-api-owner - admin - - - managed-api-context-template - /raspberrypi/{version} - - - managed-api-application - raspberrypi - - - managed-api-isSecured - true - - diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/pom.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/pom.xml similarity index 89% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/pom.xml rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/pom.xml index 9a2750ba3..1800946bb 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/pom.xml @@ -20,19 +20,20 @@ - - - raspberrypi-plugin + + device-mgt-iot-raspberrypi org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.0.4-SNAPSHOT ../pom.xml + 4.0.0 - org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl + org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl + 2.0.4-SNAPSHOT war - WSO2 Carbon - IoT Server RaspberryPi Manager API - WSO2 Carbon - RaspberryPi Manager Service API Implementation + WSO2 Carbon - IoT Server RaspberryPi API + WSO2 Carbon - RaspberryPi Service API Implementation http://wso2.org @@ -118,7 +119,8 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics + org.wso2.carbon.device.mgt.analytics.data.publisher + 1.1.0-SNAPSHOT provided @@ -157,7 +159,7 @@ maven-war-plugin - raspberrypi_mgt + raspberrypi diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java new file mode 100644 index 000000000..a6025d0e3 --- /dev/null +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java @@ -0,0 +1,77 @@ +/* + * 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.raspberrypi.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; +import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.DeviceData; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@API(name = "raspberrypi", version = "1.0.0", context = "/raspberrypi", tags = {"raspberrypi"}) +@DeviceType(value = "raspberrypi") +public interface RaspberryPiControllerService { + + @Path("device/register/{deviceId}/{ip}/{port}") + @POST + Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort, @Context HttpServletRequest request); + + @Path("device/{deviceId}/bulb") + @POST + @Feature(code = "bulb", name = "Bulb On / Off", type = "operation", + description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)") + Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state); + + @Path("device/{deviceId}/readtemperature") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Feature(code = "readtemperature", name = "Temperature", type = "monitor", + description = "Request temperature reading from Raspberry Pi agent") + Response requestTemperature(@PathParam("deviceId") String deviceId); + + @Path("device/push_temperature") + @POST + @Consumes(MediaType.APPLICATION_JSON) + Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request); + + /** + * Retreive Sensor data for the device type + */ + @Path("device/stats/{deviceId}/sensors/temperature") + @GET + @Consumes("application/json") + @Produces("application/json") + Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("username") String user, + @QueryParam("from") long from, @QueryParam("to") long to); + +} diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java new file mode 100644 index 000000000..81b906a59 --- /dev/null +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java @@ -0,0 +1,221 @@ +/* + * 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.raspberrypi.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.data.publisher.AnalyticsDataRecord; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DeviceManagementAnalyticsException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.DeviceData; +import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorData; +import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector; +import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils; +import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; +import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerService { + + private static Log log = LogFactory.getLog(RaspberryPiControllerServiceImpl.class); + private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); + private RaspberryPiMQTTConnector raspberryPiMQTTConnector; + + private boolean waitForServerStartup() { + while (!IoTServerStartupListener.isServerReady()) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + return true; + } + } + return false; + } + + public RaspberryPiMQTTConnector getRaspberryPiMQTTConnector() { + return raspberryPiMQTTConnector; + } + + public void setRaspberryPiMQTTConnector( + final RaspberryPiMQTTConnector raspberryPiMQTTConnector) { + Runnable connector = new Runnable() { + public void run() { + if (waitForServerStartup()) { + return; + } + RaspberryPiControllerServiceImpl.this.raspberryPiMQTTConnector = raspberryPiMQTTConnector; + if (MqttConfig.getInstance().isEnabled()) { + raspberryPiMQTTConnector.connect(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, RaspberryPiMQTTConnector not started."); + } + } + }; + Thread connectorThread = new Thread(connector); + connectorThread.setDaemon(true); + connectorThread.start(); + } + + public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) { + String result; + if (log.isDebugEnabled()) { + log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId); + } + String deviceHttpEndpoint = deviceIP + ":" + devicePort; + deviceToIpMap.put(deviceId, deviceHttpEndpoint); + result = "Device-IP Registered"; + if (log.isDebugEnabled()) { + log.debug(result); + } + return Response.ok().entity(result).build(); + } + + public Response switchBulb(String deviceId, String state) { + String switchToState = state.toUpperCase(); + if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals( + RaspberrypiConstants.STATE_OFF)) { + log.error("The requested state change shoud be either - 'ON' or 'OFF'"); + return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build(); + } + String callUrlPattern = RaspberrypiConstants.BULB_CONTEXT + switchToState; + try { + String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); + if (deviceHTTPEndpoint == null) { + return Response.status(Response.Status.PRECONDITION_FAILED.getStatusCode()).build(); + } + RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true); + } catch (DeviceManagementException e) { + log.error("Failed to send switch-bulb request to device [" + deviceId + "] via "); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + return Response.ok().build(); + } + + public Response requestTemperature(@PathParam("deviceId") String deviceId) { + SensorRecord sensorRecord = null; + if (log.isDebugEnabled()) { + log.debug("Sending request to read raspberrypi-temperature of device [" + deviceId + "] via "); + } + try { + String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); + if (deviceHTTPEndpoint == null) { + return Response.status(Response.Status.PRECONDITION_FAILED.getStatusCode()).build(); + } + String temperatureValue = RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, + RaspberrypiConstants + .TEMPERATURE_CONTEXT, + false); + SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, + temperatureValue, Calendar.getInstance() + .getTimeInMillis()); + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, + RaspberrypiConstants.SENSOR_TEMPERATURE); + } catch (DeviceManagementException | DeviceControllerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + return Response.ok().entity(sensorRecord).build(); + } + + public Response pushTemperatureData(final DeviceData dataMsg, HttpServletRequest request) { + String owner = dataMsg.owner; + String deviceId = dataMsg.deviceId; + String deviceIp = dataMsg.reply; + float temperature = dataMsg.value; + String registeredIp = deviceToIpMap.get(deviceId); + if (registeredIp == null) { + log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " + deviceIp + + " for device ID - " + deviceId); + return Response.status(Response.Status.PRECONDITION_FAILED.getStatusCode()).build(); + } else if (!registeredIp.equals(deviceIp)) { + log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId + + " is already registered under some other IP. Re-registration required"); + return Response.status(Response.Status.CONFLICT.getStatusCode()).build(); + } + if (log.isDebugEnabled()) { + log.debug("Received Pin Data Value: " + temperature + " degrees C"); + } + SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, + String.valueOf(temperature), + Calendar.getInstance().getTimeInMillis()); + if (!RaspberrypiServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { + log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" + + deviceId + "] of owner [" + owner + "]"); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + return Response.ok().build(); + } + + public Response getArduinoTemperatureStats(String deviceId, String user, long from, long to) { + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + List sensorDatas = new ArrayList<>(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + + RaspberrypiConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; + String sensorTableName = RaspberrypiConstants.TEMPERATURE_EVENT_TABLE; + try { + List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); + Collections.sort(records, new Comparator() { + @Override + public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { + long t1 = (Long) o1.getValue("time"); + long t2 = (Long) o2.getValue("time"); + if (t1 < t2) { + return -1; + } else if (t1 > t2) { + return 1; + } else { + return 0; + } + } + }); + for (AnalyticsDataRecord record : records) { + SensorData sensorData = new SensorData(); + sensorData.setTime((long) record.getValue("time")); + sensorData.setValue("" + (float) record.getValue(RaspberrypiConstants.SENSOR_TEMPERATURE)); + sensorDatas.add(sensorData); + } + SensorData[] sensorDetails = sensorDatas.toArray(new SensorData[sensorDatas.size()]); + return Response.ok().entity(sensorDetails).build(); + } catch (DeviceManagementAnalyticsException e) { + String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; + log.error(errorMsg); + SensorData[] sensorDetails = sensorDatas.toArray(new SensorData[sensorDatas.size()]); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(sensorDetails).build(); + } + } + +} diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java new file mode 100644 index 000000000..294c27b3e --- /dev/null +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java @@ -0,0 +1,72 @@ +/* + * 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.raspberrypi.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@API(name = "raspberrypi_mgt", version = "1.0.0", context = "/raspberrypi_mgt", tags = {"raspberrypi"}) +@DeviceType(value = "raspberrypi") +public interface RaspberryPiManagerService { + + @Path("devices/{device_id}") + @DELETE + Response removeDevice(@PathParam("device_id") String deviceId); + + @Path("devices/{device_id}") + @PUT + Response updateDevice(@PathParam("device_id") String deviceId, + @QueryParam("name") String name); + + @Path("devices/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + Response getDevice(@PathParam("device_id") String deviceId); + + @Path("devices") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + Response getRaspberrypiDevices(); + + + @Path("devices/{sketch_type}/download") + @GET + @Produces(MediaType.APPLICATION_JSON) + Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String + sketchType); + + @Path("devices/{sketch_type}/generate_link") + @GET + Response generateSketchLink(@QueryParam("deviceName") String deviceName, + @PathParam("sketch_type") String sketchType); + +} diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager/service/impl/RaspberryPiManagerService.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java similarity index 73% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager/service/impl/RaspberryPiManagerService.java rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java index abc970e89..ecc5e3a32 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager/service/impl/RaspberryPiManagerService.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl; +package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; @@ -33,8 +33,8 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants; +import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipUtil; import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClient; @@ -43,18 +43,6 @@ import org.wso2.carbon.device.mgt.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.device.mgt.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.IOException; import java.nio.ByteBuffer; @@ -64,25 +52,19 @@ import java.util.Date; import java.util.List; import java.util.UUID; -public class RaspberryPiManagerService { +public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService { - private static Log log = LogFactory.getLog(RaspberryPiManagerService.class); + private static Log log = LogFactory.getLog(RaspberryPiManagerServiceImpl.class); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; - @Path("manager/device/register") - @POST - public boolean register(@QueryParam("deviceId") String deviceId, - @QueryParam("name") String name) { + private boolean register(String deviceId, String name) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { - response.setStatus(Response.Status.CONFLICT.getStatusCode()); return false; } Device device = new Device(); @@ -96,24 +78,13 @@ public class RaspberryPiManagerService { enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); device.setEnrolmentInfo(enrolmentInfo); boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); - if (added) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } return added; } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); } } - @Path("manager/device/{device_id}") - @DELETE - public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + public Response removeDevice(String deviceId) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); @@ -121,22 +92,16 @@ public class RaspberryPiManagerService { boolean removed = APIUtil.getDeviceManagementService().disenrollDevice( deviceIdentifier); if (removed) { - response.setStatus(Response.Status.OK.getStatusCode()); + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{device_id}") - @PUT - public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { + public Response updateDevice(String deviceId, String name) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); @@ -148,67 +113,48 @@ public class RaspberryPiManagerService { device.setType(RaspberrypiConstants.DEVICE_TYPE); boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); if (updated) { - response.setStatus(Response.Status.OK.getStatusCode()); + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } - return updated; } catch (DeviceManagementException e) { log.error(e.getErrorMessage()); - return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{device_id}") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Device getDevice(@PathParam("device_id") String deviceId) { + public Response getDevice(String deviceId) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); try { - return APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + return Response.ok().entity(device).build(); } catch (DeviceManagementException ex) { log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex); - return null; - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/devices") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Device[] getRaspberrypiDevices() { + public Response getRaspberrypiDevices() { try { List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser( APIUtil.getAuthenticatedUser()); ArrayList usersRaspberrypiDevices = new ArrayList<>(); for (Device device : userDevices) { if (device.getType().equals(RaspberrypiConstants.DEVICE_TYPE) && - device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) { + device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) { usersRaspberrypiDevices.add(device); } } - return usersRaspberrypiDevices.toArray(new Device[]{}); - + Device[] devices = usersRaspberrypiDevices.toArray(new Device[]{}); + return Response.ok().entity(devices).build(); } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{sketch_type}/download") - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String - sketchType) { + public Response downloadSketch(String deviceName, String sketchType) { try { ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile())); @@ -229,16 +175,10 @@ public class RaspberryPiManagerService { return Response.status(500).entity(ex.getMessage()).build(); } catch (UserStoreException ex) { return Response.status(500).entity(ex.getMessage()).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); } } - - @Path("manager/device/{sketch_type}/generate_link") - @GET - public Response generateSketchLink(@QueryParam("deviceName") String deviceName, - @PathParam("sketch_type") String sketchType) { + public Response generateSketchLink(String deviceName, String sketchType) { try { ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); @@ -256,8 +196,6 @@ public class RaspberryPiManagerService { return Response.status(500).entity(ex.getMessage()).build(); } catch (UserStoreException ex) { return Response.status(500).entity(ex.getMessage()).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); } } @@ -295,8 +233,8 @@ public class RaspberryPiManagerService { status = xmppServerClient.createXMPPAccount(newXmppAccount); if (!status) { String msg = "XMPP Account was not created for device - " + deviceId + " of owner - " + owner + - ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config" + - ".server.configs"; + ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config" + + ".server.configs"; log.warn(msg); throw new DeviceManagementException(msg); } diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/dto/DeviceData.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/dto/DeviceData.java similarity index 93% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/dto/DeviceData.java rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/dto/DeviceData.java index 6482d1e01..4bc753dda 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/dto/DeviceData.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/dto/DeviceData.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.dto; +package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/dto/SensorData.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/dto/SensorData.java similarity index 90% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/dto/SensorData.java rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/dto/SensorData.java index 4709b54f6..ec026dbe5 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/dto/SensorData.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/dto/SensorData.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.dto; +package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/exception/RaspberrypiException.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/exception/RaspberrypiException.java similarity index 92% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/exception/RaspberrypiException.java rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/exception/RaspberrypiException.java index 26fa4d538..5be178e09 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/exception/RaspberrypiException.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/exception/RaspberrypiException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.exception; +package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.exception; public class RaspberrypiException extends Exception { private static final long serialVersionUID = 118512086957330189L; diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/transport/RaspberryPiMQTTConnector.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java similarity index 96% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/transport/RaspberryPiMQTTConnector.java rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java index d00da115b..1d01f36dd 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/transport/RaspberryPiMQTTConnector.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.transport; +package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -27,16 +27,14 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.util.RaspberrypiServiceUtils; +import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils; import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import java.io.File; import java.util.Calendar; import java.util.UUID; diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager/service/impl/util/APIUtil.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/APIUtil.java similarity index 96% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager/service/impl/util/APIUtil.java rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/APIUtil.java index 412629443..b0e91eb49 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/manager/service/impl/util/APIUtil.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/APIUtil.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl.util; +package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/util/RaspberrypiServiceUtils.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/RaspberrypiServiceUtils.java similarity index 97% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/util/RaspberrypiServiceUtils.java rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/RaspberrypiServiceUtils.java index a641ab09d..e0c98e7b6 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/controller/service/impl/util/RaspberrypiServiceUtils.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/RaspberrypiServiceUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl.util; +package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,8 +26,8 @@ import org.apache.http.concurrent.FutureCallback; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClients; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants; diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/META-INF/permissions.xml similarity index 58% rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/META-INF/permissions.xml rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/META-INF/permissions.xml index 44c1677f0..5128de1ed 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.manager.api/src/main/webapp/META-INF/permissions.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/META-INF/permissions.xml @@ -31,36 +31,78 @@ Get device /device-mgt/user/devices/list - /manager/device/* + /devices/* GET - - Add device - /device-mgt/user/devices/add - /manager/device - POST - - Remove device /device-mgt/user/devices/remove - /manager/device/* + /devices/* DELETE Download device /device-mgt/user/devices/add - /manager/device/*/download + /devices/*/download GET Update device /device-mgt/user/devices/update - /manager/device/* + /devices/* POST + + + + /devices + GET + + + + + + /devices/*/generate_link + GET + + + + + + /device/register/*/*/* + POST + + + + + + /device/*/bulb + POST + + + + + + /device/*/readtemperature + GET + + + + + + /device/push_temperature + POST + + + + + + /device/stats/*/sensors/temperature + GET + + \ No newline at end of file diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api/src/main/webapp/META-INF/webapp-classloading.xml rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 80% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml index 0ccfb9745..ab4f105d7 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -25,12 +25,15 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + + class="org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.RaspberryPiControllerServiceImpl"> + + @@ -38,8 +41,7 @@ + class="org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector"> - diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/webapp/WEB-INF/web.xml rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/webapp/WEB-INF/web.xml diff --git a/components/iot-plugins/raspberrypi-plugin/pom.xml b/components/iot-plugins/raspberrypi-plugin/pom.xml index 3b85d06d0..7d1d84f82 100644 --- a/components/iot-plugins/raspberrypi-plugin/pom.xml +++ b/components/iot-plugins/raspberrypi-plugin/pom.xml @@ -33,11 +33,10 @@ http://wso2.org - org.wso2.carbon.device.mgt.iot.raspberrypi.manager.service.impl org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl org.wso2.carbon.device.mgt.iot.raspberrypi.ui org.wso2.carbon.device.mgt.iot.raspberrypi.analytics - org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl + org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/pom.xml deleted file mode 100644 index f9a2c1abc..000000000 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/pom.xml +++ /dev/null @@ -1,262 +0,0 @@ - - - - - - - virtual-fire-alarm-plugin - org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT - ../pom.xml - - - 4.0.0 - org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl - war - WSO2 Carbon - IoT Server VirtualFireAlarm API - WSO2 Carbon - Virtual FireAlarm Service Controller API Implementation - http://wso2.org - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.certificate.mgt.core - provided - - - commons-codec.wso2 - commons-codec - - - - - - - - org.apache.cxf - cxf-rt-frontend-jaxws - provided - - - org.apache.cxf - cxf-rt-frontend-jaxrs - provided - - - org.apache.cxf - cxf-rt-transports-http - provided - - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - provided - - - - - org.apache.httpcomponents - httpasyncclient - 4.1 - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot - provided - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl - provided - - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-jaxrs - - - javax - javaee-web-api - provided - - - javax.ws.rs - jsr311-api - provided - - - commons-httpclient.wso2 - commons-httpclient - provided - - - - org.wso2.carbon - org.wso2.carbon.utils - provided - - - org.bouncycastle.wso2 - bcprov-jdk15on - - - org.wso2.carbon - org.wso2.carbon.user.api - - - org.wso2.carbon - org.wso2.carbon.queuing - - - org.wso2.carbon - org.wso2.carbon.base - - - org.apache.axis2.wso2 - axis2 - - - org.igniterealtime.smack.wso2 - smack - - - org.igniterealtime.smack.wso2 - smackx - - - jaxen - jaxen - - - commons-fileupload.wso2 - commons-fileupload - - - org.apache.ant.wso2 - ant - - - org.apache.ant.wso2 - ant - - - commons-httpclient.wso2 - commons-httpclient - - - org.eclipse.equinox - javax.servlet - - - org.wso2.carbon - org.wso2.carbon.registry.api - - - - - - commons-codec.wso2 - commons-codec - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - provided - - - - org.igniterealtime.smack.wso2 - smack - provided - - - org.igniterealtime.smack.wso2 - smackx - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions - provided - - - - - - - - - maven-compiler-plugin - - UTF-8 - ${wso2.maven.compiler.source} - ${wso2.maven.compiler.target} - - - - maven-war-plugin - - virtual_firealarm - - - - - - diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/VirtualFireAlarmControllerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/VirtualFireAlarmControllerService.java deleted file mode 100644 index 1318caf7f..000000000 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/VirtualFireAlarmControllerService.java +++ /dev/null @@ -1,614 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.annotations.api.API; -import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; -import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; -import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.common.AnalyticsDataRecord; -import org.wso2.carbon.device.mgt.analytics.exception.DeviceManagementAnalyticsException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; -import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; -import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; -import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.dto.DeviceData; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.dto.SensorData; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.exception.VirtualFireAlarmException; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.transport.VirtualFireAlarmMQTTConnector; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.transport.VirtualFireAlarmXMPPConnector; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.SecurityManager; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.VirtualFireAlarmServiceUtils; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.scep.ContentType; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.scep.SCEPOperation; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - -/** - * This class consists the functions/APIs specific to the "actions" of the VirtualFirealarm device-type. These APIs - * include the ones that are used by the [Device] to contact the server (i.e: Enrollment & Publishing Data) and the - * ones used by the [Server/Owner] to contact the [Device] (i.e: sending control signals). This class also initializes - * the transport 'Connectors' [XMPP & MQTT] specific to the VirtualFirealarm device-type in order to communicate with - * such devices and to receive messages form it. - */ -@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm", tags = "virtual_firealarm") -@DeviceType(value = "virtual_firealarm") -@SuppressWarnings("Non-Annoted WebService") -public class VirtualFireAlarmControllerService { - - private static final String XMPP_PROTOCOL = "XMPP"; - private static final String HTTP_PROTOCOL = "HTTP"; - private static final String MQTT_PROTOCOL = "MQTT"; - private static Log log = LogFactory.getLog(VirtualFireAlarmControllerService.class); - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; - // consists of utility methods related to encrypting and decrypting messages - private SecurityManager securityManager; - // connects to the given MQTT broker and handles MQTT communication - private VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector; - // connects to the given XMPP server and handles XMPP communication - private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector; - // holds a mapping of the IP addresses to Device-IDs for HTTP communication - private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); - - private boolean waitForServerStartup() { - while (!IoTServerStartupListener.isServerReady()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - return true; - } - } - return false; - } - - /** - * Fetches the `SecurityManager` specific to this VirtualFirealarm controller service. - * - * @return the 'SecurityManager' instance bound to the 'securityManager' variable of this service. - */ - @SuppressWarnings("Unused") - public SecurityManager getSecurityManager() { - return securityManager; - } - - /** - * Sets the `securityManager` variable of this VirtualFirealarm controller service. - * - * @param securityManager a 'SecurityManager' object that handles the encryption, decryption, signing and validation - * of incoming messages from VirtualFirealarm device-types. - */ - @SuppressWarnings("Unused") - public void setSecurityManager(SecurityManager securityManager) { - this.securityManager = securityManager; - securityManager.initVerificationManager(); - } - - /** - * Fetches the `VirtualFireAlarmXMPPConnector` specific to this VirtualFirealarm controller service. - * - * @return the 'VirtualFireAlarmXMPPConnector' instance bound to the 'virtualFireAlarmXMPPConnector' variable of - * this service. - */ - @SuppressWarnings("Unused") - public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() { - return virtualFireAlarmXMPPConnector; - } - - /** - * Sets the `virtualFireAlarmXMPPConnector` variable of this VirtualFirealarm controller service. - * - * @param virtualFireAlarmXMPPConnector a 'VirtualFireAlarmXMPPConnector' object that handles all XMPP related - * communications of any connected VirtualFirealarm device-type - */ - @SuppressWarnings("Unused") - public void setVirtualFireAlarmXMPPConnector( - final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) { - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - VirtualFireAlarmControllerService.this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector; - - if (XmppConfig.getInstance().isEnabled()) { - Runnable xmppStarter = new Runnable() { - @Override - public void run() { - virtualFireAlarmXMPPConnector.initConnector(); - virtualFireAlarmXMPPConnector.connect(); - } - }; - - Thread xmppStarterThread = new Thread(xmppStarter); - xmppStarterThread.setDaemon(true); - xmppStarterThread.start(); - } else { - log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - /** - * Fetches the `VirtualFireAlarmMQTTConnector` specific to this VirtualFirealarm controller service. - * - * @return the 'VirtualFireAlarmMQTTConnector' instance bound to the 'virtualFireAlarmMQTTConnector' variable of - * this service. - */ - @SuppressWarnings("Unused") - public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() { - return virtualFireAlarmMQTTConnector; - } - - /** - * Sets the `virtualFireAlarmMQTTConnector` variable of this VirtualFirealarm controller service. - * - * @param virtualFireAlarmMQTTConnector a 'VirtualFireAlarmMQTTConnector' object that handles all MQTT related - * communications of any connected VirtualFirealarm device-type - */ - @SuppressWarnings("Unused") - public void setVirtualFireAlarmMQTTConnector( - final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) { - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - VirtualFireAlarmControllerService.this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector; - if (MqttConfig.getInstance().isEnabled()) { - virtualFireAlarmMQTTConnector.connect(); - } else { - log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - /** - * This is an API used/called by the device. It registers the IP of a VirtualFirealarm device against its DeviceID - * when the device connects with the server for the first time. This DeviceID to IP mapping is necessary only for - * cases where HTTP communication is to be used. At such instances, this mapping is used by the server to - * identify the IP of the device to which it has some message to be sent. This method becomes useful only in - * scenarios where HTTP communication is used in a setup where the IoT-Server and the devices communicating with it - * are in the same IP network. - * - * @param deviceId the ID of the VirtualFirealarm device from which this register-IP call was initiated. - * @param deviceIP the IP of the VirtualFirealarm device which has sent this register-IP request. - * @param devicePort the PORT on the VirtualFirealarm device (on this IP) that's open for HTTP communication. - * @param request the HTTP servlet request object received by default as part of the HTTP call to this API. - * @param response the HTTP servlet response object received by default as part of the HTTP call to this API. - * @return a custom message indicating whether the DeviceID to IP mapping was successful. - */ - @POST - @Path("controller/register/{deviceId}/{ip}/{port}") - public String registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, - @PathParam("port") String devicePort, @Context HttpServletRequest request, - @Context HttpServletResponse response) { - try { - String result; - if (log.isDebugEnabled()) { - log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId); - } - String deviceHttpEndpoint = deviceIP + ":" + devicePort; - deviceToIpMap.put(deviceId, deviceHttpEndpoint); - result = "Device-IP Registered"; - response.setStatus(Response.Status.OK.getStatusCode()); - if (log.isDebugEnabled()) { - log.debug(result); - } - return result; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command to - * the VirtualFirealarm device to switch `ON` or `OFF` its buzzer. The method also takes in the protocol to be used - * to connect-to and send the command to the device. - * - * @param deviceId the ID of the VirtualFirealarm device on which the buzzer needs to switched `ON` or `OFF`. - * @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device. - * @param state the state to which the buzzer on the device needs to be changed. Either "ON" or "OFF". - * (Case-Insensitive String) - * @param response the HTTP servlet response object received by default as part of the HTTP call to this API. - */ - @POST - @Path("controller/device/{deviceId}/buzz/") - @Feature(code = "buzz", name = "Buzzer On / Off", type = "operation", - description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)") - public void switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, - @FormParam("state") String state, @Context HttpServletResponse response) { - String switchToState = state.toUpperCase(); - if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals( - VirtualFireAlarmConstants.STATE_OFF)) { - log.error("The requested state change shoud be either - 'ON' or 'OFF'"); - response.setStatus(Response.Status.BAD_REQUEST.getStatusCode()); - return; - } - String protocolString = protocol.toUpperCase(); - String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState; - if (log.isDebugEnabled()) { - log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " + - protocolString); - } - try { - switch (protocolString) { - case HTTP_PROTOCOL: - String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); - if (deviceHTTPEndpoint == null) { - response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); - return; - } - VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true); - break; - case XMPP_PROTOCOL: - String xmppResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); - virtualFireAlarmXMPPConnector.publishDeviceData(deviceId, xmppResource, switchToState); - break; - default: - String mqttResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); - virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, switchToState); - break; - } - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException | TransportHandlerException e) { - log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command - * to the VirtualFirealarm device to 'tell what's its current temperature reading'. The method also takes in the - * protocol to be used to connect-to and send the command to the device. - * - * @param deviceId the ID of the VirtualFirealarm device on which the temperature reading is be read-from. - * @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device. - * @param response the HTTP servlet response object received by default as part of the HTTP call to this API. - * @return an instance of the 'SensorRecord' object that holds the last updated temperature of the VirtualFirealarm - * whose temperature reading was requested. - */ - @GET - @Path("controller/device/{deviceId}/temperature") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Feature(code = "temperature", name = "Temperature", type = "monitor", - description = "Request Temperature reading from Virtual Fire Alarm") - public SensorRecord requestTemperature(@PathParam("deviceId") String deviceId, - @QueryParam("protocol") String protocol, - @Context HttpServletResponse response) { - SensorRecord sensorRecord = null; - String protocolString = protocol.toUpperCase(); - if (log.isDebugEnabled()) { - log.debug("Sending request to read virtual-firealarm-temperature of device " + - "[" + deviceId + "] via " + protocolString); - } - try { - switch (protocolString) { - case HTTP_PROTOCOL: - String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); - if (deviceHTTPEndpoint == null) { - response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); - } - String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP( - deviceHTTPEndpoint, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false); - SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, - temperatureValue, - Calendar.getInstance().getTimeInMillis()); - break; - case XMPP_PROTOCOL: - String xmppResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", ""); - virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, xmppResource, ""); - break; - default: - String mqttResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", ""); - virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, ""); - break; - } - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, VirtualFireAlarmConstants - .SENSOR_TEMP); - response.setStatus(Response.Status.OK.getStatusCode()); - } catch (DeviceManagementException | DeviceControllerException | TransportHandlerException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - return sensorRecord; - } - - /** - * This is an API called/used by the VirtualFirealarm device to publish its temperature to the IoT-Server. The - * received data from the device is stored in a 'DeviceRecord' under the device's ID in the 'SensorDataManager' - * of the Server. - * - * @param dataMsg the temperature data received from the device in JSON format complying to type 'DeviceData'. - * @param response the HTTP servlet response object received by default as part of the HTTP call to this API. - */ - @POST - @Path("controller/temperature") - @Consumes(MediaType.APPLICATION_JSON) - public void pushTemperatureData(final DeviceData dataMsg, @Context HttpServletResponse response) { - try { - String deviceId = dataMsg.deviceId; - String deviceIp = dataMsg.reply; - float temperature = dataMsg.value; - String registeredIp = deviceToIpMap.get(deviceId); - if (registeredIp == null) { - log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " + - deviceIp + " for device ID - " + deviceId); - response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); - return; - } else if (!registeredIp.equals(deviceIp)) { - log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId + - " is already registered under some other IP. Re-registration required"); - response.setStatus(Response.Status.CONFLICT.getStatusCode()); - return; - } - SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, - String.valueOf(temperature), - Calendar.getInstance().getTimeInMillis()); - if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process. - * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two - * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client - * of the enrolling device. The API supports 2 SCEP Operations [GetCACert] and [GetCACaps]. - *

- * Operation [GetCACert] returns the CA cert of the SCEP-Server for the device to verify its authenticity. - * Operation [GetCACaps] returns the CA Capabilities of the SCEP-Server. - * - * @param operation the SCEP operation requested by the client. [GetCACert] or [GetCACaps] - * @param message any messages pertaining to the requested SCEP Operation. - * @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation. - */ - @GET - @Path("controller/scep") - public Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message) { - try { - if (log.isDebugEnabled()) { - log.debug("Invoking SCEP operation " + operation); - } - if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) { - if (log.isDebugEnabled()) { - log.debug("Invoking GetCACert"); - } - try { - CertificateManagementService certificateManagementService = - VirtualFireAlarmServiceUtils.getCertificateManagementService(); - SCEPResponse scepResponse = certificateManagementService.getCACertSCEP(); - Response.ResponseBuilder responseBuilder; - switch (scepResponse.getResultCriteria()) { - case CA_CERT_FAILED: - log.error("CA cert failed"); - responseBuilder = Response.serverError(); - break; - case CA_CERT_RECEIVED: - if (log.isDebugEnabled()) { - log.debug("CA certificate received in GetCACert"); - } - responseBuilder = Response.ok(scepResponse.getEncodedResponse(), - ContentType.X_X509_CA_CERT); - break; - case CA_RA_CERT_RECEIVED: - if (log.isDebugEnabled()) { - log.debug("CA and RA certificates received in GetCACert"); - } - responseBuilder = Response.ok(scepResponse.getEncodedResponse(), - ContentType.X_X509_CA_RA_CERT); - break; - default: - log.error("Invalid SCEP request"); - responseBuilder = Response.serverError(); - break; - } - - return responseBuilder.build(); - } catch (VirtualFireAlarmException e) { - log.error("Error occurred while enrolling the VirtualFireAlarm device", e); - } catch (KeystoreException e) { - log.error("Keystore error occurred while enrolling the VirtualFireAlarm device", e); - } - - } else if (SCEPOperation.GET_CA_CAPS.getValue().equals(operation)) { - - if (log.isDebugEnabled()) { - log.debug("Invoking GetCACaps"); - } - - try { - CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. - getCertificateManagementService(); - byte caCaps[] = certificateManagementService.getCACapsSCEP(); - - return Response.ok(caCaps, MediaType.TEXT_PLAIN).build(); - - } catch (VirtualFireAlarmException e) { - log.error("Error occurred while enrolling the device", e); - } - - } else { - log.error("Invalid SCEP operation " + operation); - } - - return Response.serverError().build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process. - * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two - * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client - * of the enrolling device. This API supports the SCEP Operation [PKIOperation]. - *

- * Operation [PKIOperation] returns a certificate generated by the SCEP-Server for the enrolling device. - * - * @param operation the final SCEP operation executed in the enrollment process - which is [PKIOperation] - * @param inputStream an input stream consisting of the Certificate-Signing-Request (CSR) from the device. - * @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server. - */ - @POST - @Path("controller/scep") - public Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream) { - try { - if (log.isDebugEnabled()) { - log.debug("Invoking SCEP operation " + operation); - } - if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) { - if (log.isDebugEnabled()) { - log.debug("Invoking PKIOperation"); - } - try { - CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. - getCertificateManagementService(); - byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream); - return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build(); - } catch (VirtualFireAlarmException e) { - log.error("Error occurred while enrolling the device", e); - } catch (KeystoreException e) { - log.error("Keystore error occurred while enrolling the device", e); - } - } - return Response.serverError().build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - /** - * Retreive Sensor data for the device type - */ - @Path("controller/stats/device/{deviceId}/sensors/{sensorName}") - @GET - @Consumes("application/json") - @Produces("application/json") - public SensorData[] getVirtualFirealarmStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensor, - @QueryParam("username") String user, @QueryParam("from") long from, - @QueryParam("to") long to) { - try { - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - List sensorDatas = new ArrayList<>(); - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx - .getOSGiService(DeviceAnalyticsService.class, null); - String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + - VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; - String sensorTableName = getSensorEventTableName(sensor); - if (sensorTableName != null) { - List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); - Collections.sort(records, new Comparator() { - @Override - public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { - long t1 = (Long) o1.getValue("time"); - long t2 = (Long) o2.getValue("time"); - if (t1 < t2) { - return -1; - } else if (t1 > t2) { - return 1; - } else { - return 0; - } - } - }); - for (AnalyticsDataRecord record : records) { - SensorData sensorData = new SensorData(); - sensorData.setTime((long) record.getValue("time")); - sensorData.setValue("" + (float) record.getValue(sensor)); - sensorDatas.add(sensorData); - } - return sensorDatas.toArray(new SensorData[sensorDatas.size()]); - } - } catch (DeviceManagementAnalyticsException e) { - String errorMsg = "Error on retrieving stats on table for sensor name" + sensor; - log.error(errorMsg); - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - return new SensorData[0]; - } - - /** - * get the event table from the sensor name. - */ - private String getSensorEventTableName(String sensorName){ - String sensorEventTableName; - switch (sensorName) { - case VirtualFireAlarmConstants.SENSOR_TEMP: - sensorEventTableName = VirtualFireAlarmConstants.TEMPERATURE_EVENT_TABLE; - break; - case VirtualFireAlarmConstants.SENSOR_HUMIDITY: - sensorEventTableName = VirtualFireAlarmConstants.HUMIDITY_EVENT_TABLE; - break; - default: - sensorEventTableName = null; - } - return sensorEventTableName; - } -} diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml deleted file mode 100644 index fa4461919..000000000 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/META-INF/webapp-classloading.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - false - - - CXF,Carbon - diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml deleted file mode 100644 index fa4461919..000000000 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/META-INF/webapp-classloading.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - false - - - CXF,Carbon - diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index 532cd8e97..000000000 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 0b6b913db..000000000 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - WSO2 IoT Server - WSO2 IoT Server - - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - true - - - - - managed-api-enabled - false - - - managed-api-owner - admin - - - managed-api-context-template - /virtual_firealarm/{version} - - - managed-api-application - virtual_firealarm - - - managed-api-isSecured - true - - - - - - - - - - - - - - - diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/pom.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml similarity index 95% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/pom.xml rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml index ed8eb5d9b..abb81ac7e 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/pom.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml @@ -20,16 +20,16 @@ - - - virtual-fire-alarm-plugin + + device-mgt-iot-virtualfirealarm org.wso2.carbon.devicemgt-plugins - 2.1.0-SNAPSHOT + 2.0.4-SNAPSHOT ../pom.xml 4.0.0 - org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl + org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl + 2.0.4-SNAPSHOT war WSO2 Carbon - IoT Server VirtualFireAlarm API WSO2 Carbon - Virtual FireAlarm Service Management API Implementation @@ -56,7 +56,8 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.analytics + org.wso2.carbon.device.mgt.analytics.data.publisher + 1.1.0-SNAPSHOT provided @@ -262,7 +263,7 @@ maven-war-plugin - virtual_firealarm_mgt + virtual_firealarm diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java new file mode 100644 index 000000000..0c5abe7b7 --- /dev/null +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java @@ -0,0 +1,157 @@ +/* + * 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.virtualfirealarm.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.InputStream; + +@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm", tags = "virtual_firealarm") +@DeviceType(value = "virtual_firealarm") +public interface VirtualFireAlarmControllerService { + + /** + * This is an API used/called by the device. It registers the IP of a VirtualFirealarm device against its DeviceID + * when the device connects with the server for the first time. This DeviceID to IP mapping is necessary only for + * cases where HTTP communication is to be used. At such instances, this mapping is used by the server to + * identify the IP of the device to which it has some message to be sent. This method becomes useful only in + * scenarios where HTTP communication is used in a setup where the IoT-Server and the devices communicating with it + * are in the same IP network. + * + * @param deviceId the ID of the VirtualFirealarm device from which this register-IP call was initiated. + * @param deviceIP the IP of the VirtualFirealarm device which has sent this register-IP request. + * @param devicePort the PORT on the VirtualFirealarm device (on this IP) that's open for HTTP communication. + * @param request the HTTP servlet request object received by default as part of the HTTP call to this API. + * @return a custom message indicating whether the DeviceID to IP mapping was successful. + */ + @POST + @Path("device/register/{deviceId}/{ip}/{port}") + Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort, @Context HttpServletRequest request); + + + /** + * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command to + * the VirtualFirealarm device to switch `ON` or `OFF` its buzzer. The method also takes in the protocol to be used + * to connect-to and send the command to the device. + * + * @param deviceId the ID of the VirtualFirealarm device on which the buzzer needs to switched `ON` or `OFF`. + * @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device. + * @param state the state to which the buzzer on the device needs to be changed. Either "ON" or "OFF". + * (Case-Insensitive String) + */ + @POST + @Path("device/{deviceId}/buzz") + @Feature(code = "buzz", name = "Buzzer On / Off", type = "operation", + description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)") + Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, + @FormParam("state") String state); + + /** + * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command + * to the VirtualFirealarm device to 'tell what's its current temperature reading'. The method also takes in the + * protocol to be used to connect-to and send the command to the device. + * + * @param deviceId the ID of the VirtualFirealarm device on which the temperature reading is be read-from. + * @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device. + * @return an instance of the 'SensorRecord' object that holds the last updated temperature of the VirtualFirealarm + * whose temperature reading was requested. + */ + @GET + @Path("device/{deviceId}/temperature") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Feature(code = "temperature", name = "Temperature", type = "monitor", + description = "Request Temperature reading from Virtual Fire Alarm") + Response requestTemperature(@PathParam("deviceId") String deviceId, + @QueryParam("protocol") String protocol); + + /** + * This is an API called/used by the VirtualFirealarm device to publish its temperature to the IoT-Server. The + * received data from the device is stored in a 'DeviceRecord' under the device's ID in the 'SensorDataManager' + * of the Server. + * + * @param dataMsg the temperature data received from the device in JSON format complying to type 'DeviceData'. + */ + @POST + @Path("device/temperature") + @Consumes(MediaType.APPLICATION_JSON) + Response pushTemperatureData(final DeviceData dataMsg); + + /** + * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process. + * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two + * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client + * of the enrolling device. The API supports 2 SCEP Operations [GetCACert] and [GetCACaps]. + *

+ * Operation [GetCACert] returns the CA cert of the SCEP-Server for the device to verify its authenticity. + * Operation [GetCACaps] returns the CA Capabilities of the SCEP-Server. + * + * @param operation the SCEP operation requested by the client. [GetCACert] or [GetCACaps] + * @param message any messages pertaining to the requested SCEP Operation. + * @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation. + */ + @GET + @Path("device/scep") + Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message); + + + /** + * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process. + * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two + * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client + * of the enrolling device. This API supports the SCEP Operation [PKIOperation]. + *

+ * Operation [PKIOperation] returns a certificate generated by the SCEP-Server for the enrolling device. + * + * @param operation the final SCEP operation executed in the enrollment process - which is [PKIOperation] + * @param inputStream an input stream consisting of the Certificate-Signing-Request (CSR) from the device. + * @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server. + */ + @POST + @Path("device/scep") + Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream); + + /** + * Retreive Sensor data for the device type + */ + @Path("device/stats/{deviceId}/sensors/{sensorName}") + @GET + @Consumes("application/json") + @Produces("application/json") + Response getVirtualFirealarmStats(@PathParam("deviceId") String deviceId, + @PathParam("sensorName") String sensor, + @QueryParam("username") String user, @QueryParam("from") long from, + @QueryParam("to") long to); + +} diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java new file mode 100644 index 000000000..60fb360d3 --- /dev/null +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java @@ -0,0 +1,468 @@ +/* + * 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.virtualfirealarm.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; +import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; +import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.data.publisher.AnalyticsDataRecord; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DeviceManagementAnalyticsException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; +import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; +import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorData; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.transport.VirtualFireAlarmMQTTConnector; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.transport.VirtualFireAlarmXMPPConnector; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.SecurityManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.VirtualFireAlarmServiceUtils; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.scep.ContentType; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.scep.SCEPOperation; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +/** + * This class consists the functions/APIs specific to the "actions" of the VirtualFirealarm device-type. These APIs + * include the ones that are used by the [Device] to contact the server (i.e: Enrollment & Publishing Data) and the + * ones used by the [Server/Owner] to contact the [Device] (i.e: sending control signals). This class also initializes + * the transport 'Connectors' [XMPP & MQTT] specific to the VirtualFirealarm device-type in order to communicate with + * such devices and to receive messages form it. + */ +@SuppressWarnings("Non-Annoted WebService") +public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmControllerService { + + private static final String XMPP_PROTOCOL = "XMPP"; + private static final String HTTP_PROTOCOL = "HTTP"; + private static final String MQTT_PROTOCOL = "MQTT"; + private static Log log = LogFactory.getLog(VirtualFireAlarmControllerServiceImpl.class); + // consists of utility methods related to encrypting and decrypting messages + private SecurityManager securityManager; + // connects to the given MQTT broker and handles MQTT communication + private VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector; + // connects to the given XMPP server and handles XMPP communication + private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector; + // holds a mapping of the IP addresses to Device-IDs for HTTP communication + private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); + + private boolean waitForServerStartup() { + while (!IoTServerStartupListener.isServerReady()) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + return true; + } + } + return false; + } + + /** + * Fetches the `SecurityManager` specific to this VirtualFirealarm controller service. + * + * @return the 'SecurityManager' instance bound to the 'securityManager' variable of this service. + */ + @SuppressWarnings("Unused") + public SecurityManager getSecurityManager() { + return securityManager; + } + + /** + * Sets the `securityManager` variable of this VirtualFirealarm controller service. + * + * @param securityManager a 'SecurityManager' object that handles the encryption, decryption, signing and validation + * of incoming messages from VirtualFirealarm device-types. + */ + @SuppressWarnings("Unused") + public void setSecurityManager(SecurityManager securityManager) { + this.securityManager = securityManager; + securityManager.initVerificationManager(); + } + + /** + * Fetches the `VirtualFireAlarmXMPPConnector` specific to this VirtualFirealarm controller service. + * + * @return the 'VirtualFireAlarmXMPPConnector' instance bound to the 'virtualFireAlarmXMPPConnector' variable of + * this service. + */ + @SuppressWarnings("Unused") + public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() { + return virtualFireAlarmXMPPConnector; + } + + /** + * Sets the `virtualFireAlarmXMPPConnector` variable of this VirtualFirealarm controller service. + * + * @param virtualFireAlarmXMPPConnector a 'VirtualFireAlarmXMPPConnector' object that handles all XMPP related + * communications of any connected VirtualFirealarm device-type + */ + @SuppressWarnings("Unused") + public void setVirtualFireAlarmXMPPConnector( + final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) { + Runnable connector = new Runnable() { + public void run() { + if (waitForServerStartup()) { + return; + } + VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector; + + if (XmppConfig.getInstance().isEnabled()) { + Runnable xmppStarter = new Runnable() { + @Override + public void run() { + virtualFireAlarmXMPPConnector.initConnector(); + virtualFireAlarmXMPPConnector.connect(); + } + }; + + Thread xmppStarterThread = new Thread(xmppStarter); + xmppStarterThread.setDaemon(true); + xmppStarterThread.start(); + } else { + log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started."); + } + } + }; + Thread connectorThread = new Thread(connector); + connectorThread.setDaemon(true); + connectorThread.start(); + } + + /** + * Fetches the `VirtualFireAlarmMQTTConnector` specific to this VirtualFirealarm controller service. + * + * @return the 'VirtualFireAlarmMQTTConnector' instance bound to the 'virtualFireAlarmMQTTConnector' variable of + * this service. + */ + @SuppressWarnings("Unused") + public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() { + return virtualFireAlarmMQTTConnector; + } + + /** + * Sets the `virtualFireAlarmMQTTConnector` variable of this VirtualFirealarm controller service. + * + * @param virtualFireAlarmMQTTConnector a 'VirtualFireAlarmMQTTConnector' object that handles all MQTT related + * communications of any connected VirtualFirealarm device-type + */ + @SuppressWarnings("Unused") + public void setVirtualFireAlarmMQTTConnector( + final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) { + Runnable connector = new Runnable() { + public void run() { + if (waitForServerStartup()) { + return; + } + VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector; + if (MqttConfig.getInstance().isEnabled()) { + virtualFireAlarmMQTTConnector.connect(); + } else { + log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); + } + } + }; + Thread connectorThread = new Thread(connector); + connectorThread.setDaemon(true); + connectorThread.start(); + } + + public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) { + String result; + if (log.isDebugEnabled()) { + log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId); + } + String deviceHttpEndpoint = deviceIP + ":" + devicePort; + deviceToIpMap.put(deviceId, deviceHttpEndpoint); + result = "Device-IP Registered"; + if (log.isDebugEnabled()) { + log.debug(result); + } + return Response.ok().entity(result).build(); + } + + public Response switchBuzzer(String deviceId, String protocol, String state) { + String switchToState = state.toUpperCase(); + if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals( + VirtualFireAlarmConstants.STATE_OFF)) { + log.error("The requested state change shoud be either - 'ON' or 'OFF'"); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + String protocolString = protocol.toUpperCase(); + String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState; + if (log.isDebugEnabled()) { + log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " + + protocolString); + } + try { + switch (protocolString) { + case HTTP_PROTOCOL: + String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); + if (deviceHTTPEndpoint == null) { + return Response.status(Response.Status.PRECONDITION_FAILED).build(); + } + VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true); + break; + case XMPP_PROTOCOL: + String xmppResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); + virtualFireAlarmXMPPConnector.publishDeviceData(deviceId, xmppResource, switchToState); + break; + default: + String mqttResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); + virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, switchToState); + break; + } + return Response.ok().build(); + } catch (DeviceManagementException | TransportHandlerException e) { + log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + public Response requestTemperature(String deviceId, String protocol) { + SensorRecord sensorRecord = null; + String protocolString = protocol.toUpperCase(); + if (log.isDebugEnabled()) { + log.debug("Sending request to read virtual-firealarm-temperature of device " + + "[" + deviceId + "] via " + protocolString); + } + try { + switch (protocolString) { + case HTTP_PROTOCOL: + String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); + if (deviceHTTPEndpoint == null) { + return Response.status(Response.Status.PRECONDITION_FAILED).build(); + } + String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP( + deviceHTTPEndpoint, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false); + SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, + temperatureValue, + Calendar.getInstance().getTimeInMillis()); + break; + case XMPP_PROTOCOL: + String xmppResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", ""); + virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, xmppResource, ""); + break; + default: + String mqttResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", ""); + virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, ""); + break; + } + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, VirtualFireAlarmConstants + .SENSOR_TEMP); + return Response.ok().entity(sensorRecord).build(); + } catch (DeviceManagementException | DeviceControllerException | TransportHandlerException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + public Response pushTemperatureData(final DeviceData dataMsg) { + String deviceId = dataMsg.deviceId; + String deviceIp = dataMsg.reply; + float temperature = dataMsg.value; + String registeredIp = deviceToIpMap.get(deviceId); + if (registeredIp == null) { + log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " + + deviceIp + " for device ID - " + deviceId); + return Response.status(Response.Status.PRECONDITION_FAILED).build(); + } else if (!registeredIp.equals(deviceIp)) { + log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId + + " is already registered under some other IP. Re-registration required"); + return Response.status(Response.Status.CONFLICT).build(); + } + SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, + String.valueOf(temperature), + Calendar.getInstance().getTimeInMillis()); + if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + return Response.ok().build(); + } + + public Response scepRequest(String operation, String message) { + if (log.isDebugEnabled()) { + log.debug("Invoking SCEP operation " + operation); + } + if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) { + if (log.isDebugEnabled()) { + log.debug("Invoking GetCACert"); + } + try { + CertificateManagementService certificateManagementService = + VirtualFireAlarmServiceUtils.getCertificateManagementService(); + SCEPResponse scepResponse = certificateManagementService.getCACertSCEP(); + Response.ResponseBuilder responseBuilder; + switch (scepResponse.getResultCriteria()) { + case CA_CERT_FAILED: + log.error("CA cert failed"); + responseBuilder = Response.serverError(); + break; + case CA_CERT_RECEIVED: + if (log.isDebugEnabled()) { + log.debug("CA certificate received in GetCACert"); + } + responseBuilder = Response.ok(scepResponse.getEncodedResponse(), + ContentType.X_X509_CA_CERT); + break; + case CA_RA_CERT_RECEIVED: + if (log.isDebugEnabled()) { + log.debug("CA and RA certificates received in GetCACert"); + } + responseBuilder = Response.ok(scepResponse.getEncodedResponse(), + ContentType.X_X509_CA_RA_CERT); + break; + default: + log.error("Invalid SCEP request"); + responseBuilder = Response.serverError(); + break; + } + + return responseBuilder.build(); + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the VirtualFireAlarm device", e); + } catch (KeystoreException e) { + log.error("Keystore error occurred while enrolling the VirtualFireAlarm device", e); + } + + } else if (SCEPOperation.GET_CA_CAPS.getValue().equals(operation)) { + + if (log.isDebugEnabled()) { + log.debug("Invoking GetCACaps"); + } + + try { + CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. + getCertificateManagementService(); + byte caCaps[] = certificateManagementService.getCACapsSCEP(); + + return Response.ok(caCaps, MediaType.TEXT_PLAIN).build(); + + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the device", e); + } + + } else { + log.error("Invalid SCEP operation " + operation); + } + + return Response.serverError().build(); + + } + + public Response scepRequestPost(String operation, InputStream inputStream) { + if (log.isDebugEnabled()) { + log.debug("Invoking SCEP operation " + operation); + } + if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) { + if (log.isDebugEnabled()) { + log.debug("Invoking PKIOperation"); + } + try { + CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. + getCertificateManagementService(); + byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream); + return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build(); + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the device", e); + } catch (KeystoreException e) { + log.error("Keystore error occurred while enrolling the device", e); + } + } + return Response.serverError().build(); + } + + public Response getVirtualFirealarmStats(String deviceId, String sensor, String user, long from, long to) { + try { + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + List sensorDatas = new ArrayList<>(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + + VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; + String sensorTableName = getSensorEventTableName(sensor); + if (sensorTableName != null) { + List records = deviceAnalyticsService.getAllEventsForDevice(sensorTableName, query); + Collections.sort(records, new Comparator() { + @Override + public int compare(AnalyticsDataRecord o1, AnalyticsDataRecord o2) { + long t1 = (Long) o1.getValue("time"); + long t2 = (Long) o2.getValue("time"); + if (t1 < t2) { + return -1; + } else if (t1 > t2) { + return 1; + } else { + return 0; + } + } + }); + for (AnalyticsDataRecord record : records) { + SensorData sensorData = new SensorData(); + sensorData.setTime((long) record.getValue("time")); + sensorData.setValue("" + (float) record.getValue(sensor)); + sensorDatas.add(sensorData); + } + SensorData[] sensorDetails = sensorDatas.toArray(new SensorData[sensorDatas.size()]); + return Response.ok().entity(sensorDetails).build(); + } + } catch (DeviceManagementAnalyticsException e) { + String errorMsg = "Error on retrieving stats on table for sensor name" + sensor; + log.error(errorMsg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + return Response.status(Response.Status.BAD_REQUEST).build(); + } + + /** + * get the event table from the sensor name. + */ + private String getSensorEventTableName(String sensorName) { + String sensorEventTableName; + switch (sensorName) { + case VirtualFireAlarmConstants.SENSOR_TEMP: + sensorEventTableName = VirtualFireAlarmConstants.TEMPERATURE_EVENT_TABLE; + break; + case VirtualFireAlarmConstants.SENSOR_HUMIDITY: + sensorEventTableName = VirtualFireAlarmConstants.HUMIDITY_EVENT_TABLE; + break; + default: + sensorEventTableName = null; + } + return sensorEventTableName; + } +} diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java new file mode 100644 index 000000000..9f89af761 --- /dev/null +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl; + +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@API(name = "virtual_firealarm_mgt", version = "1.0.0", context = "/virtual_firealarm_mgt", tags = "virtual_firealarm") +@DeviceType(value = "virtual_firealarm") +public interface VirtualFireAlarmManagerService { + + @Path("manager/device/{device_id}") + @DELETE + Response removeDevice(@PathParam("device_id") String deviceId); + + + @Path("manager/device/{device_id}") + @PUT + Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name); + + @Path("manager/device/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + Response getDevice(@PathParam("device_id") String deviceId); + + @Path("manager/devices") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + Response getFirealarmDevices(); + + @Path("manager/device/{sketch_type}/download") + @GET + @Produces(MediaType.APPLICATION_JSON) + Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String sketchType); + + + @Path("manager/device/{sketch_type}/generate_link") + @GET + Response generateSketchLink(@QueryParam("deviceName") String deviceName, + @PathParam("sketch_type") String sketchType); + +} diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager/service/impl/VirtualFireAlarmManagerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java similarity index 74% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager/service/impl/VirtualFireAlarmManagerService.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java index 50f1c1c19..98af9fd42 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager/service/impl/VirtualFireAlarmManagerService.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl; import org.apache.commons.io.FileUtils; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; @@ -33,25 +33,14 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipUtil; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl.util.APIUtil; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClient; import org.wso2.carbon.device.mgt.jwt.client.extension.JWTClientManager; import org.wso2.carbon.device.mgt.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.device.mgt.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; + import javax.ws.rs.core.Response; import java.io.IOException; import java.nio.ByteBuffer; @@ -61,23 +50,17 @@ import java.util.Date; import java.util.List; import java.util.UUID; -public class VirtualFireAlarmManagerService { - @Context //injected response proxy supporting multiple thread - private HttpServletResponse response; +public class VirtualFireAlarmManagerServiceImpl implements VirtualFireAlarmManagerService { + private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; - - @Path("manager/device/register") - @POST - public boolean register(@QueryParam("deviceId") String deviceId, - @QueryParam("name") String name) { + private boolean register(String deviceId, String name) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) { - response.setStatus(Response.Status.CONFLICT.getStatusCode()); return false; } Device device = new Device(); @@ -92,24 +75,13 @@ public class VirtualFireAlarmManagerService { enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); device.setEnrolmentInfo(enrolmentInfo); boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); - if (added) { - response.setStatus(Response.Status.OK.getStatusCode()); - } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - } return added; } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); } } - @Path("manager/device/{device_id}") - @DELETE - public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + public Response removeDevice(String deviceId) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); @@ -117,22 +89,16 @@ public class VirtualFireAlarmManagerService { boolean removed = APIUtil.getDeviceManagementService().disenrollDevice( deviceIdentifier); if (removed) { - response.setStatus(Response.Status.OK.getStatusCode()); + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{device_id}") - @PUT - public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { + public Response updateDevice(String deviceId, String name) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); @@ -144,42 +110,28 @@ public class VirtualFireAlarmManagerService { device.setType(VirtualFireAlarmConstants.DEVICE_TYPE); boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device); if (updated) { - response.setStatus(Response.Status.OK.getStatusCode()); + return Response.ok().build(); } else { - response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); } - return updated; } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{device_id}") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Device getDevice(@PathParam("device_id") String deviceId) { + public Response getDevice(String deviceId) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); - return APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + return Response.ok().entity(device).build(); } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/devices") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Device[] getFirealarmDevices() { + public Response getFirealarmDevices() { try { List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser()); @@ -190,20 +142,14 @@ public class VirtualFireAlarmManagerService { userDevicesforFirealarm.add(device); } } - return userDevicesforFirealarm.toArray(new Device[]{}); + Device[] devices = userDevicesforFirealarm.toArray(new Device[]{}); + return Response.ok().entity(devices).build(); } catch (DeviceManagementException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - return null; - } finally { - PrivilegedCarbonContext.endTenantFlow(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } - @Path("manager/device/{sketch_type}/download") - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response downloadSketch(@QueryParam("deviceName") String deviceName, - @PathParam("sketch_type") String sketchType) { + public Response downloadSketch(String deviceName, String sketchType) { try { ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile())); @@ -218,7 +164,7 @@ public class VirtualFireAlarmManagerService { return Response.status(500).entity(ex.getMessage()).build(); } catch (APIManagerException ex) { return Response.status(500).entity(ex.getMessage()).build(); - }catch (DeviceControllerException ex) { + } catch (DeviceControllerException ex) { return Response.status(500).entity(ex.getMessage()).build(); } catch (IOException ex) { return Response.status(500).entity(ex.getMessage()).build(); @@ -229,10 +175,7 @@ public class VirtualFireAlarmManagerService { } } - @Path("manager/device/{sketch_type}/generate_link") - @GET - public Response generateSketchLink(@QueryParam("deviceName") String deviceName, - @PathParam("sketch_type") String sketchType) { + public Response generateSketchLink(String deviceName, String sketchType) { try { ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); @@ -309,4 +252,5 @@ public class VirtualFireAlarmManagerService { long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); return Long.toString(l, Character.MAX_RADIX); } + } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/dto/DeviceData.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/dto/DeviceData.java similarity index 93% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/dto/DeviceData.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/dto/DeviceData.java index a6dde796b..45c62020f 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/dto/DeviceData.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/dto/DeviceData.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.dto; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/dto/SensorData.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/dto/SensorData.java similarity index 90% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/dto/SensorData.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/dto/SensorData.java index a4792fca7..e5e99609f 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/dto/SensorData.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/dto/SensorData.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.dto; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto; import org.codehaus.jackson.annotate.JsonIgnoreProperties; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/exception/VirtualFireAlarmException.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/exception/VirtualFireAlarmException.java similarity index 91% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/exception/VirtualFireAlarmException.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/exception/VirtualFireAlarmException.java index 4dd6faacb..c0e848f14 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/exception/VirtualFireAlarmException.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/exception/VirtualFireAlarmException.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.exception; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception; public class VirtualFireAlarmException extends Exception { private static final long serialVersionUID = 118512086957330189L; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/transport/VirtualFireAlarmMQTTConnector.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java similarity index 95% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/transport/VirtualFireAlarmMQTTConnector.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java index 05c0a459e..e4e8e3cb8 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/transport/VirtualFireAlarmMQTTConnector.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.transport; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.transport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -27,18 +27,16 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.exception.VirtualFireAlarmException; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.SecurityManager; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.VirtualFireAlarmServiceUtils; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.SecurityManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.VirtualFireAlarmServiceUtils; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import java.io.File; import java.nio.charset.StandardCharsets; import java.security.PrivateKey; import java.security.PublicKey; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/transport/VirtualFireAlarmXMPPConnector.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java similarity index 96% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/transport/VirtualFireAlarmXMPPConnector.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java index 00697c81a..39588caef 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/transport/VirtualFireAlarmXMPPConnector.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java @@ -16,13 +16,12 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.transport; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.transport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jivesoftware.smack.packet.Message; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; @@ -31,9 +30,9 @@ import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.exception.VirtualFireAlarmException; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.SecurityManager; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.VirtualFireAlarmServiceUtils; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.SecurityManager; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.VirtualFireAlarmServiceUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.io.File; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager/service/impl/util/APIUtil.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/APIUtil.java similarity index 96% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager/service/impl/util/APIUtil.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/APIUtil.java index dca274402..8f92c500a 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/manager/service/impl/util/APIUtil.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/APIUtil.java @@ -1,4 +1,4 @@ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.manager.service.impl.util; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/SecurityManager.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/SecurityManager.java similarity index 98% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/SecurityManager.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/SecurityManager.java index 5098e4eab..5384db878 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/SecurityManager.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/SecurityManager.java @@ -16,14 +16,14 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util; import org.apache.commons.codec.binary.Base64; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.exception.VirtualFireAlarmException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/VirtualFireAlarmServiceUtils.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmServiceUtils.java similarity index 95% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/VirtualFireAlarmServiceUtils.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmServiceUtils.java index 4126235b1..4b8f1d2ad 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/VirtualFireAlarmServiceUtils.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmServiceUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -29,21 +29,17 @@ import org.json.JSONObject; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.exception.VirtualFireAlarmException; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; import javax.ws.rs.HttpMethod; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.lang.*; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/scep/ContentType.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/scep/ContentType.java similarity index 91% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/scep/ContentType.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/scep/ContentType.java index 879309c12..672f773bc 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/scep/ContentType.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/scep/ContentType.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.scep; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.scep; public class ContentType { public static final String X_PKI_MESSAGE = "application/x-pki-message"; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/scep/SCEPOperation.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/scep/SCEPOperation.java similarity index 91% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/scep/SCEPOperation.java rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/scep/SCEPOperation.java index f9f8f0898..563261dd4 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/controller/service/impl/util/scep/SCEPOperation.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/scep/SCEPOperation.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl.util.scep; +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.scep; public enum SCEPOperation { GET_CA_CERT("GetCACert"), diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/permissions.xml similarity index 52% rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/META-INF/permissions.xml rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/permissions.xml index 5d829b850..7ae82a831 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.manager.service.impl/src/main/webapp/META-INF/permissions.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/permissions.xml @@ -31,29 +31,92 @@ Get device /device-mgt/user/devices/list - /manager/device/{device_id} + /devices/* GET Remove device /device-mgt/user/devices/remove - /manager/device/{device_id} + /devices/* DELETE Download device /device-mgt/user/devices/add - /manager/device/download + /devices/*/download GET Update device /device-mgt/user/devices/update - /manager/device/{device_id} - PUT + /devices/* + POST + + + + /devices + GET + + + + + + /devices/*/generate_link + GET + + + + + + /device/register/*/*/* + POST + + + + + + /device/*/buzz + POST + + + + + + /device/*/temperature + GET + + + + + + /device/temperature + POST + + + + + + /device/scep + GET + + + + + + /device/scep + POST + + + + + + /device/stats/*/sensors/* + GET + + \ No newline at end of file diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml similarity index 100% rename from components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.manager.api/src/main/webapp/META-INF/webapp-classloading.xml rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/META-INF/webapp-classloading.xml diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml similarity index 71% rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml index fdb49fd8a..f6a4d217c 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.controller.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -1,5 +1,4 @@ -