From 9bb3839c87237207893ed2aaa98dcc79de42c174 Mon Sep 17 00:00:00 2001 From: madhawap Date: Fri, 6 Jan 2017 17:05:48 +0530 Subject: [PATCH 1/2] Adding Swagger to Android sense end-points --- .../service/impl/AndroidSenseService.java | 290 ++++++++++++++++-- 1 file changed, 267 insertions(+), 23 deletions(-) diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java index 2c60c0b4df..3fc98bf66e 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -19,14 +19,23 @@ package org.wso2.carbon.device.mgt.iot.androidsense.service.impl; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Info; -import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; +import io.swagger.annotations.ResponseHeader; +import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; -import org.wso2.carbon.apimgt.annotations.api.Scope; -import javax.ws.rs.*; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; @SwaggerDefinition( @@ -52,10 +61,57 @@ public interface AndroidSenseService { * @param deviceId The registered device Id. * @param keywords The key words to be sent. (Comma separated values) */ - @Path("device/{deviceId}/words") @POST - @Scope(key = "device:android-sense:enroll", name = "", description = "") - Response sendKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("keywords") String keywords); + @Path("device/{deviceId}/words") + @ApiOperation( + httpMethod = "POST", + value = "End point to send the key words to the device", + notes = "", + tags = "android_sense", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "", value = "perm:android-sense:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK.", + response = Response.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid Device Identifiers found.", + response = Response.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Unauthorized request."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while executing command operation to" + + " send keywords", + response = Response.class) + }) + Response sendKeyWords( + @ApiParam( + name = "deviceId", + value = "The registered device Id.", + required = true) + @PathParam("deviceId") String deviceId, + @ApiParam( + name = "keywords", + value = "The key words to be sent. (Comma separated values)", + required = true) + @QueryParam("keywords") String keywords); /** * End point to send the key words to the device @@ -63,34 +119,222 @@ public interface AndroidSenseService { * @param deviceId The registered device Id. * @param threshold The key words to be sent. (Comma separated values) */ - @Path("device/{deviceId}/words/threshold") @POST - @Scope(key = "device:android-sense:enroll", name = "", description = "") - Response sendThreshold(@PathParam("deviceId") String deviceId, @QueryParam("threshold") String threshold); + @Path("device/{deviceId}/words/threshold") + @ApiOperation( + httpMethod = "POST", + value = "End point to send threshold value to the device", + notes = "", + tags = "android_sense", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "", value = "perm:android-sense:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK.", + response = Response.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid Device Identifiers found.", + response = Response.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Unauthorized request."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while executing command operation to" + + " send threashold", + response = Response.class) + }) + Response sendThreshold( + @ApiParam( + name = "deviceId", + value = "The registered device Id.", + required = true) + @PathParam("deviceId") String deviceId, + @ApiParam( + name = "threshold", + value = "Threshold to be sent.", + required = true) + @QueryParam("threshold") String threshold); - @Path("device/{deviceId}/words") + /** + * End point to remove key words from the device + */ @DELETE - @Scope(key = "device:android-sense:enroll", name = "", description = "") - Response removeKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("words") String words); + @Path("device/{deviceId}/words") + @ApiOperation( + httpMethod = "DELETE", + value = "Remove key words from the device", + notes = "", + response = Response.class, + tags = "android_sense", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "", value = "perm:android-sense:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK.", + response = Response.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid Device Identifiers found.", + response = Response.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Unauthorized request."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while executing command operation to" + + " send threashold", + response = Response.class) + }) + Response removeKeyWords( + @ApiParam( + name = "deviceId", + value = "The registered device Id.", + required = true) + @PathParam("deviceId") String deviceId, + @ApiParam( + name = "words", + value = "The key words to be sent. (Comma separated values)", + required = true) + @QueryParam("words") String words); /** * Retrieve Sensor data for the device type */ - @Path("stats/{deviceId}/sensors/{sensorName}") @GET - @Consumes("application/json") - @Scope(key = "device:android-sense:enroll", name = "", description = "") - @Produces("application/json") - Response getAndroidSenseDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensor, - @QueryParam("from") long from, @QueryParam("to") long to); + @Path("stats/{deviceId}/sensors/{sensorName}") + @ApiOperation( + consumes = "application/json", + produces = "application/json", + httpMethod = "GET", + value = "Retrieve Sensor data for the device type", + notes = "", + response = Response.class, + tags = "android_sense", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "", value = "perm:android-sense:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK.", + response = Response.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid Device Identifiers found.", + response = Response.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Unauthorized request."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error on retrieving stats", + response = Response.class) + }) + Response getAndroidSenseDeviceStats( + @ApiParam( + name = "deviceId", + value = "The registered device Id.", + required = true) + @PathParam("deviceId") String deviceId, + @ApiParam( + name = "sensorName", + value = "Name of the sensor", + required = true) + @PathParam("sensorName") String sensor, + @ApiParam( + name = "from", + value = "Get stats from what time", + required = true) + @QueryParam("from") long from, + @ApiParam( + name = "to", + value = "Get stats up to what time", + required = true) + @QueryParam("to") long to); /** * Enroll devices. */ - @Path("device/{device_id}/register") @POST - @Scope(key = "device:android-sense:enroll", name = "", description = "") - Response register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName); + @Path("device/{device_id}/register") + @ApiOperation( + httpMethod = "POST", + value = "Enroll device", + notes = "", + response = Response.class, + tags = "android_sense", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "", value = "perm:android-sense:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 202, + message = "Accepted.", + response = Response.class), + @ApiResponse( + code = 406, + message = "Not Acceptable"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error on retrieving stats", + response = Response.class) + }) + Response register( + @ApiParam( + name = "deviceId", + value = "Device identifier id of the device to be added", + required = true) + @PathParam("device_id") String deviceId, + @ApiParam( + name = "deviceName", + value = "Device name of the device to be added", + required = true) + @QueryParam("deviceName") String deviceName); } From 8c36f310304bdc317034bbeceb2a4d335059347d Mon Sep 17 00:00:00 2001 From: dunithd Date: Fri, 6 Jan 2017 18:36:16 +0530 Subject: [PATCH 2/2] Adding Geo fencing link to Android device --- .../device-view.js | 1 + .../device-view.js | 1 + .../device-view.js | 1 + .../device-view.hbs | 7 +++++++ .../device-view.js | 7 ++++++- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js index 999d4ee64c..a3ef93ec7b 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js @@ -20,6 +20,7 @@ function onRequest(context) { var log = new Log("device-view.js"); var deviceType = context.uriParams.deviceType; var deviceId = request.getParameter("id"); + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var autoCompleteParams = [ {"name" : "deviceId", "value" : deviceId} ]; diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js index 5da6f194bf..9ea752caaf 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.device-view/device-view.js @@ -20,6 +20,7 @@ function onRequest(context) { var log = new Log("device-view.js"); var deviceType = context.uriParams.deviceType; var deviceId = request.getParameter("id"); + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var autoCompleteParams = [ {"name" : "deviceId", "value" : deviceId} ]; diff --git a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js index 5da6f194bf..9ea752caaf 100644 --- a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js +++ b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.device-view/device-view.js @@ -20,6 +20,7 @@ function onRequest(context) { var log = new Log("device-view.js"); var deviceType = context.uriParams.deviceType; var deviceId = request.getParameter("id"); + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var autoCompleteParams = [ {"name" : "deviceId", "value" : deviceId} ]; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs index 1b42bdfc63..0342e82ac4 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs @@ -336,6 +336,13 @@ {{else}}
diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js index b7ce950c06..ee77264770 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js @@ -21,6 +21,7 @@ function onRequest(context) { var deviceType = context["uriParams"]["deviceType"]; var deviceId = request.getParameter("id"); var deviceViewData = {}; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; if (deviceType && deviceId) { var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; @@ -210,5 +211,9 @@ function onRequest(context) { ]; deviceViewData["autoCompleteParams"] = autoCompleteParams; + + deviceViewData["portalUrl"] = devicemgtProps['portalURL']; + var anchor = { "device" : { "id" : deviceId, "type" : deviceType}}; + deviceViewData["anchor"] = JSON.stringify(anchor); return deviceViewData; -} \ No newline at end of file +}