From 2d4f07fc55d1cc3c81da001fb36dd0a1f218a91c Mon Sep 17 00:00:00 2001 From: NuwanSameera Date: Tue, 19 Apr 2016 11:33:31 +0530 Subject: [PATCH 1/4] Add REST Api annotations to Api implementations. --- .../impl/ArduinoControllerServiceImpl.java | 47 +- .../service/impl/ArduinoManagerService.java | 1 + .../impl/ArduinoManagerServiceImpl.java | 42 +- .../src/main/webapp/WEB-INF/web.xml | 86 ++- .../impl/DigitalDisplayControllerService.java | 4 +- .../DigitalDisplayControllerServiceImpl.java | 350 ++++++------ .../impl/DigitalDisplayManagerService.java | 2 +- .../DigitalDisplayManagerServiceImpl.java | 169 +++--- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../src/main/webapp/WEB-INF/web.xml | 38 +- .../impl/DroneControllerServiceImpl.java | 10 +- .../service/impl/DroneManagerService.java | 1 + .../service/impl/DroneManagerServiceImpl.java | 93 ++-- .../src/main/webapp/WEB-INF/web.xml | 75 ++- .../impl/RaspberryPiControllerService.java | 2 +- .../RaspberryPiControllerServiceImpl.java | 290 +++++----- .../impl/RaspberryPiManagerService.java | 10 +- .../impl/RaspberryPiManagerServiceImpl.java | 261 +++++---- .../src/main/webapp/WEB-INF/web.xml | 78 ++- .../VirtualFireAlarmControllerService.java | 14 +- ...VirtualFireAlarmControllerServiceImpl.java | 527 +++++++++--------- .../impl/VirtualFireAlarmManagerService.java | 11 +- .../VirtualFireAlarmManagerServiceImpl.java | 257 +++++---- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 10 +- .../src/main/webapp/WEB-INF/web.xml | 81 ++- 25 files changed, 1323 insertions(+), 1138 deletions(-) diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java index 0b7de4e64..076a7bf03 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java @@ -31,7 +31,18 @@ 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.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; @@ -51,7 +62,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); @Override - public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) { + @Path("device/register/{deviceId}/{ip}/{port}") + @POST + public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort, @Context HttpServletRequest request) { String result; if (log.isDebugEnabled()) { log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: "); @@ -66,7 +80,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { } @Override - public Response switchBulb(String deviceId, String protocol, String state) { + @Path("device/{deviceId}/bulb") + @POST + public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, + @FormParam("state") String state) { LinkedList deviceControlList = internalControlsQueue.get(deviceId); String operation = "BULB:" + state.toUpperCase(); @@ -82,7 +99,12 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { } @Override - public Response requestTemperature(String deviceId, String protocol) { + @Path("device/{deviceId}/temperature") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response requestTemperature(@PathParam("deviceId") String deviceId, + @QueryParam("protocol") String protocol) { try { SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, @@ -94,6 +116,9 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { } @Override + @Path("device/sensor") + @POST + @Consumes(MediaType.APPLICATION_JSON) public Response pushData(DeviceData dataMsg) { String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String deviceId = dataMsg.deviceId; @@ -110,7 +135,9 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { } @Override - public Response readControls(String deviceId, String protocol) { + @Path("device/{deviceId}/controls") + @GET + public Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol) { String result; LinkedList deviceControlList = internalControlsQueue.get(deviceId); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); @@ -138,7 +165,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { } @Override - public Response pushTemperatureData(final DeviceData dataMsg, HttpServletRequest request) { + @Path("device/temperature") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request) { String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String deviceId = dataMsg.deviceId; float temperature = dataMsg.value; @@ -154,7 +184,12 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { } @Override - public Response getArduinoTemperatureStats(String deviceId, long from, long to) { + @Path("device/stats/{deviceId}/sensors/temperature") + @GET + @Consumes("application/json") + @Produces("application/json") + public Response 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<>(); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java index eb0524b31..cd0e196fd 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java @@ -32,6 +32,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +@Path("enrollment") @API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"}) @DeviceType(value = "arduino") public interface ArduinoManagerService { diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java index 3ef897128..a5cd8b5e8 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java @@ -18,7 +18,6 @@ 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; @@ -27,7 +26,6 @@ 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; @@ -38,6 +36,16 @@ import org.wso2.carbon.identity.jwt.client.extension.JWTClientManager; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; + +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; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -46,15 +54,16 @@ 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") +@Path("enrollment") public class ArduinoManagerServiceImpl implements ArduinoManagerService { private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; @Override - public Response removeDevice(String deviceId) { + @Path("devices/{device_id}") + @DELETE + public Response removeDevice(@PathParam("device_id") String deviceId) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); @@ -71,7 +80,9 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService { } @Override - public Response updateDevice(String deviceId, String name) { + @Path("devices/{device_id}") + @PUT + public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); @@ -93,7 +104,11 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService { } @Override - public Response getDevice(String deviceId) { + @Path("devices/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response getDevice(@PathParam("device_id") String deviceId) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); @@ -106,6 +121,10 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService { } @Override + @Path("devices") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) public Response getArduinoDevices() { try { List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser( @@ -125,7 +144,10 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService { } @Override - public Response downloadSketch(String customDeviceName) { + @Path("devices/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()); @@ -147,7 +169,9 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService { } @Override - public Response generateSketchLink(String deviceName) { + @Path("devices/generate_link") + @GET + public Response generateSketchLink(@QueryParam("deviceName") String deviceName) { try { ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/web.xml index c62aa6100..4c3855352 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/web.xml +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/web.xml @@ -7,56 +7,40 @@ Arduino Arduino - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - + + CXFServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServlet + /* + + + isAdminService + false + + + doAuthentication + true + + + isSharedWithAllTenants + true + + + providerTenantDomain + carbon.super + + + + managed-api-enabled + true + + + managed-api-owner + admin + - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - false - - - isSharedWithAllTenants - true - - - providerTenantDomain - carbon.super - - - - managed-api-enabled - true - - - managed-api-owner - admin - - - managed-api-context-template - /arduino/{version} - - - managed-api-application - arduino - - - managed-api-isSecured - true - - - - - + \ No newline at end of file diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerService.java index eb0cdcaea..b672380bd 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerService.java @@ -21,11 +21,11 @@ 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.PathParam; import javax.ws.rs.core.Response; @API(name = "digital_display", version = "1.0.0", context = "/digital_display", tags = {"digital_display"}) @@ -54,7 +54,7 @@ public interface DigitalDisplayControllerService { @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); + Response terminateDisplay(@HeaderParam("sessionId") String sessionId, @PathParam("deviceId") String deviceId); /** * Reboot running digital display diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerServiceImpl.java index 0bb084db6..185c63eba 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayControllerServiceImpl.java @@ -20,10 +20,8 @@ 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; @@ -32,13 +30,11 @@ import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDis 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.PathParam; import javax.ws.rs.core.Response; public class DigitalDisplayControllerServiceImpl implements DigitalDisplayControllerService { @@ -46,6 +42,194 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro private static Log log = LogFactory.getLog(DigitalDisplayControllerServiceImpl.class); private static DigitalDisplayMQTTConnector digitalDisplayMQTTConnector; + @Path("device/{deviceId}/restart-browser") + @POST + public Response restartBrowser(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") 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(); + } + } + + @Path("device/{deviceId}/terminate-display") + @POST + public Response terminateDisplay(@HeaderParam("sessionId") String sessionId, + @PathParam("deviceId") String deviceId) { + 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(); + } + } + + @Path("device/{deviceId}/restart-display") + @POST + public Response restartDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") 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(); + } + } + + @Path("device/{deviceId}/edit-sequence") + @POST + public Response editSequence(@PathParam("deviceId") String deviceId, @FormParam("name") String name, + @FormParam("attribute") String attribute, @FormParam("new-value") String newValue, + @HeaderParam("sessionId") 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(); + } + } + + + @Path("device/{deviceId}/upload-content") + @POST + public Response uploadContent(@PathParam("deviceId") String deviceId, @FormParam("remote-path") String remotePath, + @FormParam("screen-name") String screenName, + @HeaderParam("sessionId") 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(); + } + } + + @Path("device/{deviceId}/add-resource") + @POST + public 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) { + 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(); + } + } + + @Path("device/{deviceId}/remove-resource") + @POST + public Response removeResource(@PathParam("deviceId") String deviceId, @FormParam("name") String name, + @HeaderParam("sessionId") 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(); + } + } + + @Path("device/{deviceId}/restart-server") + @POST + public Response restartServer(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") 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(); + } + } + + + @Path("device/{deviceId}/screenshot") + @POST + public Response showScreenshot(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") 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(); + } + } + + @Path("device/{deviceId}/get-device-status") + @POST + public Response getDevicestatus(@PathParam("deviceId") String deviceId, + @HeaderParam("sessionId") 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(); + } + } + + @Path("device/{deviceId}/get-content-list") + @POST + public Response getResources(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") 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(); + } + } + private boolean waitForServerStartup() { while (!IoTServerStartupListener.isServerReady()) { try { @@ -83,160 +267,4 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro 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.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerService.java index 300fb211a..a33412eab 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerService.java @@ -24,7 +24,6 @@ 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; @@ -33,6 +32,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +@Path("enrollment") @API(name = "digital_display_mgt", version = "1.0.0", context = "/digital_display_mgt", tags = {"digital_display"}) @DeviceType(value = "digital_display") public interface DigitalDisplayManagerService { diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerServiceImpl.java index 382a22c6f..c15a16fb6 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/service/impl/DigitalDisplayManagerServiceImpl.java @@ -40,6 +40,15 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; +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; import java.io.IOException; import java.nio.ByteBuffer; @@ -47,12 +56,97 @@ import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.UUID; +@Path("enrollment") public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerService { private static Log log = LogFactory.getLog(DigitalDisplayManagerServiceImpl.class); private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; + @Path("devices/{device_id}") + @DELETE + public Response removeDevice(@PathParam("device_id") 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(); + } + } + + @Path("devices/{device_id}") + @PUT + public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") 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(); + } + } + @Path("devices/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response getDevice(@PathParam("device_id") 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(); + } + } + @Path("devices/download") + @GET + @Produces("application/octet-stream") + public Response downloadSketch(@QueryParam("deviceName") String customDeviceName) { + try { + ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName); + 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 boolean register(String deviceId, String name) { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); @@ -78,81 +172,6 @@ public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerSe } } - 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 { diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml index aed7bdb71..b8cdfd331 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -24,7 +24,7 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + diff --git a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml index c6fb5fe50..af70d2124 100644 --- a/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml +++ b/components/iot-plugins/digital-display-plugin/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml @@ -21,28 +21,16 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> Digital-Display-Agent-Webapp + - JAX-WS/JAX-RS MDM Android Endpoint - JAX-WS/JAX-RS Servlet CXFServlet - - org.apache.cxf.transport.servlet.CXFServlet - + org.apache.cxf.transport.servlet.CXFServlet 1 CXFServlet /* - - - isSharedWithAllTenants - true - - - providerTenantDomain - carbon.super - isAdminService false @@ -51,6 +39,14 @@ doAuthentication true + + isSharedWithAllTenants + true + + + providerTenantDomain + carbon.super + @@ -61,17 +57,5 @@ managed-api-owner admin - - managed-api-context-template - /digital_display/{version} - - - managed-api-application - digital_display - - - managed-api-isSecured - true - - + \ No newline at end of file diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java index 6e6f0e69e..4c6ca60e5 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneControllerServiceImpl.java @@ -38,7 +38,10 @@ public class DroneControllerServiceImpl implements DroneControllerService { private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); private DroneController droneController = new DroneControllerImpl(); - public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort) { + @Path("device/register/{deviceId}/{ip}/{port}") + @POST + public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort) { String result; String deviceHttpEndpoint = deviceIP + ":" + devicePort; deviceToIpMap.put(deviceId, deviceHttpEndpoint); @@ -49,7 +52,10 @@ public class DroneControllerServiceImpl implements DroneControllerService { return Response.ok(Response.Status.OK.getStatusCode()).build(); } - public Response droneController(String deviceId, String action, String duration, String speed) { + @Path("device/{deviceId}/send_command") + @POST + public Response droneController(@PathParam("deviceId") String deviceId, @FormParam("action") String action, + @FormParam("duration") String duration, @FormParam("speed") String speed) { try { DroneAnalyzerServiceUtils.sendControlCommand(droneController, deviceId, action, Double.valueOf(speed), Double.valueOf(duration)); diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerService.java index 377f09eed..535479ad3 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerService.java @@ -31,6 +31,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +@Path("enrollment") @API(name = "drone_analyzer_mgt", version = "1.0.0", context = "/drone_analyzer_mgt", tags = {"drone_analyzer"}) @DeviceType(value = "drone_analyzer") public interface DroneManagerService { diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java index d9fbfb44b..6066f2de2 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/impl/DroneManagerServiceImpl.java @@ -40,6 +40,15 @@ import org.wso2.carbon.identity.jwt.client.extension.JWTClientManager; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; + +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; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -48,39 +57,16 @@ import java.util.Date; import java.util.List; import java.util.UUID; +@Path("enrollment") public class DroneManagerServiceImpl implements DroneManagerService { private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneManagerServiceImpl.class); private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; - private boolean register(String deviceId, String name) { - try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); - 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(DroneConstants.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) { + @Path("devices/{device_id}") + @DELETE + public Response removeDevice(@PathParam("device_id") String deviceId) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); @@ -96,7 +82,10 @@ public class DroneManagerServiceImpl implements DroneManagerService { } } - public Response updateDevice(String deviceId, String name) { + + @Path("devices/{device_id}") + @PUT + public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); @@ -117,7 +106,11 @@ public class DroneManagerServiceImpl implements DroneManagerService { } } - public Response getDevice(String deviceId) { + @Path("devices/{device_id}") + @GET + @Consumes("application/json") + @Produces("application/json") + public Response getDevice(@PathParam("device_id") String deviceId) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); @@ -129,6 +122,10 @@ public class DroneManagerServiceImpl implements DroneManagerService { } } + @Path("devices") + @GET + @Consumes("application/json") + @Produces("application/json") public Response getDroneDevices() { try { List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser()); @@ -147,7 +144,11 @@ public class DroneManagerServiceImpl implements DroneManagerService { } } - public Response downloadSketch(String deviceName, String sketchType) { + @Path("devices/{sketch_type}/download") + @GET + @Produces("application/octet-stream") + public Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String + sketchType) { //create new device id String deviceId = shortUUID(); @@ -173,10 +174,12 @@ public class DroneManagerServiceImpl implements DroneManagerService { Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); return rb.build(); - } - public Response generateSketchLink(String deviceName, String sketchType) { + @Path("devices/{sketch_type}/generate_link") + @GET + public Response generateSketchLink(@QueryParam("deviceName") String deviceName, + @PathParam("sketch_type") String sketchType) { try { ZipArchive zipFile = createDownloadFile(deviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); @@ -196,6 +199,32 @@ public class DroneManagerServiceImpl implements DroneManagerService { } } + private boolean register(String deviceId, String name) { + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DroneConstants.DEVICE_TYPE); + 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(DroneConstants.DEVICE_TYPE); + enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); + device.setEnrolmentInfo(enrolmentInfo); + boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); + return added; + } catch (DeviceManagementException e) { + return false; + } + } + private ZipArchive createDownloadFile(String deviceName, String sketchType) throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException, UserStoreException { diff --git a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/webapp/WEB-INF/web.xml index 2a9646df6..2f18393cf 100644 --- a/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/webapp/WEB-INF/web.xml +++ b/components/iot-plugins/drone-analyzer-plugin/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/webapp/WEB-INF/web.xml @@ -6,44 +6,41 @@ metadata-complete="true"> WSO2 IoT Server WSO2 IoT Server - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - CXFServlet - /* - - - isAdminService - false - - - doAuthentication - false - + + CXFServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServlet + /* + + + isAdminService + false + + + doAuthentication + true + + + isSharedWithAllTenants + true + + + providerTenantDomain + carbon.super + - - - managed-api-enabled - true - - - managed-api-owner - admin - - - managed-api-context-template - /drone_analyzer/{version} - - - managed-api-application - drone_analyzer - - - managed-api-isSecured - true - - + + + managed-api-enabled + true + + + managed-api-owner + admin + + + \ No newline at end of file diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java index a6025d0e3..12d5f4389 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java @@ -71,7 +71,7 @@ public interface RaspberryPiControllerService { @GET @Consumes("application/json") @Produces("application/json") - Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("username") String user, + Response getRaspberryPiTemperatureStats(@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.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java index 81b906a59..b744455d2 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java @@ -25,6 +25,7 @@ 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.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.service.impl.dto.DeviceData; @@ -37,7 +38,16 @@ 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.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; @@ -52,6 +62,155 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); private RaspberryPiMQTTConnector raspberryPiMQTTConnector; + @Path("device/register/{deviceId}/{ip}/{port}") + @POST + public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort, @Context 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(); + } + + @Path("device/{deviceId}/bulb") + @POST + public Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") 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(); + } + + @Path("device/{deviceId}/readtemperature") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + 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(); + } + + @Path("device/push_temperature") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response pushTemperatureData(final DeviceData dataMsg, @Context 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(); + } + + @Path("device/stats/{deviceId}/sensors/temperature") + @GET + @Consumes("application/json") + @Produces("application/json") + public Response getRaspberryPiTemperatureStats(@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); + } + 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(); + } + } + private boolean waitForServerStartup() { while (!IoTServerStartupListener.isServerReady()) { try { @@ -87,135 +246,4 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe 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.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java index 294c27b3e..cd4d2cb25 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java @@ -32,6 +32,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +@Path("enrollment") @API(name = "raspberrypi_mgt", version = "1.0.0", context = "/raspberrypi_mgt", tags = {"raspberrypi"}) @DeviceType(value = "raspberrypi") public interface RaspberryPiManagerService { @@ -43,7 +44,7 @@ public interface RaspberryPiManagerService { @Path("devices/{device_id}") @PUT Response updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name); + @QueryParam("name") String name); @Path("devices/{device_id}") @GET @@ -57,16 +58,15 @@ public interface RaspberryPiManagerService { @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); + 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); + @PathParam("sketch_type") String sketchType); } diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java index 5151a6fa9..6d0281694 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java @@ -43,6 +43,15 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; +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; import java.io.IOException; import java.nio.ByteBuffer; @@ -52,13 +61,147 @@ import java.util.Date; import java.util.List; import java.util.UUID; +@Path("enrollment") public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService { private static Log log = LogFactory.getLog(RaspberryPiManagerServiceImpl.class); - private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; + @Path("devices/{device_id}") + @DELETE + public Response removeDevice(@PathParam("device_id") String deviceId) { + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(RaspberrypiConstants.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(); + } + } + + @Path("devices/{device_id}") + @PUT + public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); + try { + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + device.setDeviceIdentifier(deviceId); + device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); + device.setName(name); + device.setType(RaspberrypiConstants.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) { + log.error(e.getErrorMessage()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + @Path("devices/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response getDevice(@PathParam("device_id") String deviceId) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(RaspberrypiConstants.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(); + } + } + + @Path("devices") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + 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)) { + usersRaspberrypiDevices.add(device); + } + } + Device[] devices = usersRaspberrypiDevices.toArray(new Device[]{}); + return Response.ok().entity(devices).build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + + @Path("devices/{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 (IOException 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("devices/{sketch_type}/generate_link") + @GET + public Response generateSketchLink(@QueryParam("deviceName") String deviceName, + @PathParam("sketch_type") String sketchType) { + try { + ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); + Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); + return rb.build(); + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (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 boolean register(String deviceId, String name) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -84,122 +227,6 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService } } - public Response removeDevice(String deviceId) { - try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(RaspberrypiConstants.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) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); - try { - Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); - device.setDeviceIdentifier(deviceId); - device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); - device.setName(name); - device.setType(RaspberrypiConstants.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) { - log.error(e.getErrorMessage()); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } - } - - public Response getDevice(String deviceId) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(RaspberrypiConstants.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 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)) { - usersRaspberrypiDevices.add(device); - } - } - Device[] devices = usersRaspberrypiDevices.toArray(new Device[]{}); - return Response.ok().entity(devices).build(); - } catch (DeviceManagementException e) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } - } - - public Response downloadSketch(String deviceName, 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 (IOException 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(); - } - } - - public Response generateSketchLink(String deviceName, String sketchType) { - - try { - ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); - Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); - return rb.build(); - } catch (IllegalArgumentException ex) { - return Response.status(400).entity(ex.getMessage()).build();//bad request - } catch (DeviceManagementException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (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, String sketchType) throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException, UserStoreException { diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/web.xml index f2fe934b8..623d182b7 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/web.xml +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/web.xml @@ -7,48 +7,40 @@ RaspberryPi RaspberryPi - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - + + CXFServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServlet + /* + + + isAdminService + false + + + doAuthentication + true + + + isSharedWithAllTenants + true + + + providerTenantDomain + carbon.super + + + + managed-api-enabled + true + + + managed-api-owner + admin + - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - true - - - - - managed-api-enabled - true - - - managed-api-owner - admin - - - managed-api-context-template - /raspberrypi/{version} - - - managed-api-application - raspberrypi - - - managed-api-isSecured - true - - - - + \ No newline at end of file diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java index 4281934c1..a46762b21 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java @@ -56,7 +56,7 @@ public interface VirtualFireAlarmControllerService { * @return a custom message indicating whether the DeviceID to IP mapping was successful. */ @POST - @Path("register/{deviceId}/{ip}/{port}") + @Path("device/register/{deviceId}/{ip}/{port}") Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, @PathParam("port") String devicePort, @Context HttpServletRequest request); @@ -72,7 +72,7 @@ public interface VirtualFireAlarmControllerService { * (Case-Insensitive String) */ @POST - @Path("{deviceId}/buzz") + @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, @@ -89,7 +89,7 @@ public interface VirtualFireAlarmControllerService { * whose temperature reading was requested. */ @GET - @Path("{deviceId}/temperature") + @Path("device/{deviceId}/temperature") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Feature(code = "temperature", name = "Temperature", type = "monitor", @@ -105,7 +105,7 @@ public interface VirtualFireAlarmControllerService { * @param dataMsg the temperature data received from the device in JSON format complying to type 'DeviceData'. */ @POST - @Path("temperature") + @Path("device/temperature") @Consumes(MediaType.APPLICATION_JSON) Response pushTemperatureData(final DeviceData dataMsg); @@ -123,7 +123,7 @@ public interface VirtualFireAlarmControllerService { * @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation. */ @GET - @Path("scep") + @Path("device/scep") Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message); @@ -140,13 +140,13 @@ public interface VirtualFireAlarmControllerService { * @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server. */ @POST - @Path("scep") + @Path("device/scep") Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream); /** * Retrieve Sensor data for the device type */ - @Path("stats/{deviceId}/sensors/{sensorName}") + @Path("device/stats/{deviceId}/sensors/{sensorName}") @GET @Consumes("application/json") @Produces("application/json") diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java index 60fb360d3..b776a3e63 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java @@ -28,6 +28,7 @@ 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.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; @@ -47,6 +48,15 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.scep.SC import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; 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; @@ -80,6 +90,275 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo // holds a mapping of the IP addresses to Device-IDs for HTTP communication private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); + @POST + @Path("device/register/{deviceId}/{ip}/{port}") + public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, + @PathParam("port") String devicePort, @Context 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(); + } + + @POST + @Path("device/{deviceId}/buzz") + public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, + @FormParam("state") 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(); + } + } + + @GET + @Path("device/{deviceId}/temperature") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response requestTemperature(@PathParam("deviceId") String deviceId, + @QueryParam("protocol") 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(); + } + } + + @POST + @Path("device/temperature") + @Consumes(MediaType.APPLICATION_JSON) + 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(); + } + + @GET + @Path("device/scep") + public Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message) { + if (log.isDebugEnabled()) { + log.debug("Invoking SCEP operation " + operation); + } + if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) { + if (log.isDebugEnabled()) { + log.debug("Invoking GetCACert"); + } + try { + CertificateManagementService certificateManagementService = + VirtualFireAlarmServiceUtils.getCertificateManagementService(); + SCEPResponse scepResponse = certificateManagementService.getCACertSCEP(); + Response.ResponseBuilder responseBuilder; + switch (scepResponse.getResultCriteria()) { + case CA_CERT_FAILED: + log.error("CA cert failed"); + responseBuilder = Response.serverError(); + break; + case CA_CERT_RECEIVED: + if (log.isDebugEnabled()) { + log.debug("CA certificate received in GetCACert"); + } + responseBuilder = Response.ok(scepResponse.getEncodedResponse(), + ContentType.X_X509_CA_CERT); + break; + case CA_RA_CERT_RECEIVED: + if (log.isDebugEnabled()) { + log.debug("CA and RA certificates received in GetCACert"); + } + responseBuilder = Response.ok(scepResponse.getEncodedResponse(), + ContentType.X_X509_CA_RA_CERT); + break; + default: + log.error("Invalid SCEP request"); + responseBuilder = Response.serverError(); + break; + } + + return responseBuilder.build(); + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the 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(); + } + + @POST + @Path("device/scep") + public Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream) { + if (log.isDebugEnabled()) { + log.debug("Invoking SCEP operation " + operation); + } + if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) { + if (log.isDebugEnabled()) { + log.debug("Invoking PKIOperation"); + } + try { + CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. + getCertificateManagementService(); + byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream); + return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build(); + } catch (VirtualFireAlarmException e) { + log.error("Error occurred while enrolling the device", e); + } catch (KeystoreException e) { + log.error("Keystore error occurred while enrolling the device", e); + } + } + return Response.serverError().build(); + } + + @Path("device/stats/{deviceId}/sensors/{sensorName}") + @GET + @Consumes("application/json") + @Produces("application/json") + public Response 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); + } + 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(); + } + private boolean waitForServerStartup() { while (!IoTServerStartupListener.isServerReady()) { try { @@ -200,254 +479,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo 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. */ diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java index 8057ec45d..1d48b0764 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java @@ -32,20 +32,21 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +@Path("enrollment") @API(name = "virtual_firealarm_mgt", version = "1.0.0", context = "/virtual_firealarm_mgt", tags = "virtual_firealarm") @DeviceType(value = "virtual_firealarm") public interface VirtualFireAlarmManagerService { - @Path("{device_id}") + @Path("devices/{device_id}") @DELETE Response removeDevice(@PathParam("device_id") String deviceId); - @Path("{device_id}") + @Path("devices/{device_id}") @PUT Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name); - @Path("{device_id}") + @Path("devices/{device_id}") @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @@ -57,13 +58,13 @@ public interface VirtualFireAlarmManagerService { @Produces(MediaType.APPLICATION_JSON) Response getFirealarmDevices(); - @Path("download") + @Path("devices/download") @GET @Produces(MediaType.APPLICATION_JSON) Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType); - @Path("generate_link") + @Path("devices/generate_link") @GET Response generateSketchLink(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java index f230dac1a..5656a83bd 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java @@ -41,6 +41,15 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; +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; import java.io.IOException; import java.nio.ByteBuffer; @@ -50,11 +59,143 @@ import java.util.Date; import java.util.List; import java.util.UUID; +@Path("enrollment") public class VirtualFireAlarmManagerServiceImpl implements VirtualFireAlarmManagerService { private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; + @Path("devices/{device_id}") + @DELETE + public Response removeDevice(@PathParam("device_id") String deviceId) { + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(VirtualFireAlarmConstants.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(); + } + } + + @Path("devices/{device_id}") + @PUT + public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) { + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + device.setDeviceIdentifier(deviceId); + device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); + device.setName(name); + device.setType(VirtualFireAlarmConstants.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(); + } + } + + @Path("devices/{device_id}") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response getDevice(@PathParam("device_id") String deviceId) { + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); + Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); + return Response.ok().entity(device).build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + @Path("devices") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response getFirealarmDevices() { + try { + List userDevices = + APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser()); + ArrayList userDevicesforFirealarm = new ArrayList<>(); + for (Device device : userDevices) { + if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) && + device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) { + userDevicesforFirealarm.add(device); + } + } + Device[] devices = userDevicesforFirealarm.toArray(new Device[]{}); + return Response.ok().entity(devices).build(); + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } + + @Path("devices/download") + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response downloadSketch(@QueryParam("deviceName") String deviceName, + @QueryParam("sketchType") 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 (APIManagerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException 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(); + } + } + + @Path("devices/generate_link") + @GET + public Response generateSketchLink(@QueryParam("deviceName") String deviceName, + @QueryParam("sketchType") String sketchType) { + try { + ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); + Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); + return rb.build(); + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (JWTClientException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (APIManagerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (UserStoreException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + } + private boolean register(String deviceId, String name) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -81,122 +222,6 @@ public class VirtualFireAlarmManagerServiceImpl implements VirtualFireAlarmManag } } - public Response removeDevice(String deviceId) { - try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(VirtualFireAlarmConstants.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(VirtualFireAlarmConstants.DEVICE_TYPE); - Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); - device.setDeviceIdentifier(deviceId); - device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); - device.setName(name); - device.setType(VirtualFireAlarmConstants.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) { - try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); - Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); - return Response.ok().entity(device).build(); - } catch (DeviceManagementException e) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } - } - - public Response getFirealarmDevices() { - try { - List userDevices = - APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser()); - ArrayList userDevicesforFirealarm = new ArrayList<>(); - for (Device device : userDevices) { - if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) && - device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) { - userDevicesforFirealarm.add(device); - } - } - Device[] devices = userDevicesforFirealarm.toArray(new Device[]{}); - return Response.ok().entity(devices).build(); - } catch (DeviceManagementException e) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } - } - - public Response downloadSketch(String deviceName, 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 (APIManagerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (DeviceControllerException 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(); - } - } - - public Response generateSketchLink(String deviceName, String sketchType) { - try { - ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); - Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); - return rb.build(); - } catch (IllegalArgumentException ex) { - return Response.status(400).entity(ex.getMessage()).build();//bad request - } catch (DeviceManagementException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (JWTClientException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (APIManagerException ex) { - return Response.status(500).entity(ex.getMessage()).build(); - } catch (DeviceControllerException 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, APIManagerException, JWTClientException, DeviceControllerException, UserStoreException { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 6dd0282d3..62608adfb 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -23,7 +23,7 @@ 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"> - + @@ -31,14 +31,6 @@ - - - - - - - - diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml index 0689ffaf0..2f18393cf 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml @@ -7,59 +7,40 @@ WSO2 IoT Server WSO2 IoT Server - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - - - CXFServlet - /* - - - - isAdminService - false - - - doAuthentication - false - - - - - managed-api-enabled - true - - - managed-api-owner - admin - + + CXFServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServlet + /* + - managed-api-context-template - /virtual_firealarm/{version} + isAdminService + false - managed-api-application - virtual_firealarm + doAuthentication + true + + + isSharedWithAllTenants + true + + + providerTenantDomain + carbon.super - - managed-api-isSecured - true - - - - - - - - - - - + + + managed-api-enabled + true + + + managed-api-owner + admin + - - + \ No newline at end of file From 4ad62b1dc175372c0dcbce4acb55356d70973127 Mon Sep 17 00:00:00 2001 From: NuwanSameera Date: Tue, 19 Apr 2016 17:16:58 +0530 Subject: [PATCH 2/4] Remove monitor operations from controller api. --- .../impl/AndroidSenseControllerService.java | 1 + .../AndroidSenseControllerServiceImpl.java | 7 - .../impl/ArduinoControllerService.java | 8 - .../impl/ArduinoControllerServiceImpl.java | 26 -- .../impl/RaspberryPiControllerService.java | 8 - .../RaspberryPiControllerServiceImpl.java | 34 --- .../transport/RaspberryPiMQTTConnector.java | 5 +- .../VirtualFireAlarmControllerService.java | 19 -- ...VirtualFireAlarmControllerServiceImpl.java | 226 ++---------------- .../VirtualFireAlarmMQTTConnector.java | 5 - .../VirtualFireAlarmXMPPConnector.java | 5 - 11 files changed, 20 insertions(+), 324 deletions(-) diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java index 4d63e66b0..2a574f8e6 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java @@ -80,3 +80,4 @@ public interface AndroidSenseControllerService { @QueryParam("from") long from, @QueryParam("to") long to); } + diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java index 5e3d31c5a..0db0b2610 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java @@ -24,18 +24,11 @@ import org.wso2.carbon.analytics.dataservice.commons.SORT; import org.wso2.carbon.analytics.dataservice.commons.SortByField; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil; -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.service.impl.util.SensorRecord; 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.service.IoTServerStartupListener; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java index 02e39d88b..f82ff603a 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java @@ -50,14 +50,6 @@ public interface ArduinoControllerService { 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("device/sensor") @POST @Consumes(MediaType.APPLICATION_JSON) diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java index 6434c7b65..ce40e39ef 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java @@ -29,8 +29,6 @@ import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil; 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 javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; @@ -44,7 +42,6 @@ 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.HashMap; import java.util.LinkedList; import java.util.List; @@ -95,23 +92,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { return Response.status(Response.Status.OK.getStatusCode()).build(); } - @Override - @Path("device/{deviceId}/temperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response requestTemperature(@PathParam("deviceId") String deviceId, - @QueryParam("protocol") String protocol) { - - try { - org.wso2.carbon.device.mgt.iot.sensormgt.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 @Path("device/sensor") @POST @@ -120,9 +100,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { 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 + "]"); @@ -169,9 +146,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { 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 + "]"); diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java index 12d5f4389..5ac51e24f 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java @@ -51,14 +51,6 @@ public interface RaspberryPiControllerService { 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) diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java index 756882345..cecde2d43 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java @@ -25,14 +25,12 @@ import org.wso2.carbon.analytics.dataservice.commons.SortByField; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; 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.SensorRecord; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil; 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.service.IoTServerStartupListener; import javax.servlet.http.HttpServletRequest; @@ -98,35 +96,6 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe return Response.ok().build(); } - @Path("device/{deviceId}/readtemperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response requestTemperature(@PathParam("deviceId") String deviceId) { - org.wso2.carbon.device.mgt.iot.sensormgt.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(); - } - @Path("device/push_temperature") @POST @Consumes(MediaType.APPLICATION_JSON) @@ -148,9 +117,6 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe 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 + "]"); diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java index d5bf225be..ff0c7e1ca 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java @@ -25,7 +25,6 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; 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.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -35,7 +34,6 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil; 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.identity.jwt.client.extension.JWTClient; @@ -161,8 +159,7 @@ public class RaspberryPiMQTTConnector extends MQTTTransportHandler { } else if (receivedMessage.contains("TEMPERATURE")) { String temperatureValue = receivedMessage.split(":")[1]; - SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, - temperatureValue, Calendar.getInstance().getTimeInMillis()); + } } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java index a46762b21..ba2694742 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java @@ -78,25 +78,6 @@ public interface VirtualFireAlarmControllerService { 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' diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java index f49a2606e..f3e9d796d 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/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.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java @@ -27,11 +27,8 @@ import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -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.service.IoTServerStartupListener; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData; @@ -60,7 +57,6 @@ 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.List; import java.util.concurrent.ConcurrentHashMap; @@ -87,142 +83,10 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo // holds a mapping of the IP addresses to Device-IDs for HTTP communication private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); -<<<<<<< HEAD @POST @Path("device/register/{deviceId}/{ip}/{port}") public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, @PathParam("port") String devicePort, @Context HttpServletRequest request) { -======= - 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; - //The delay is added for the server starts up. - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - if (MqttConfig.getInstance().isEnabled()) { - synchronized (virtualFireAlarmMQTTConnector) { - 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) { ->>>>>>> 8a7d4bb6e0a9b94b8a5c9ca8d6d21c3924b2c677 String result; if (log.isDebugEnabled()) { log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId); @@ -277,53 +141,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo } } -<<<<<<< HEAD - @GET - @Path("device/{deviceId}/temperature") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response requestTemperature(@PathParam("deviceId") String deviceId, - @QueryParam("protocol") String protocol) { - SensorRecord sensorRecord = null; -======= - public Response requestTemperature(String deviceId, String protocol) { - org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = null; ->>>>>>> 8a7d4bb6e0a9b94b8a5c9ca8d6d21c3924b2c677 - 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(); - } - } - @POST @Path("device/temperature") @Consumes(MediaType.APPLICATION_JSON) @@ -341,9 +158,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo " 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(); } @@ -442,7 +256,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo return Response.serverError().build(); } -<<<<<<< HEAD @Path("device/stats/{deviceId}/sensors/{sensorName}") @GET @Consumes("application/json") @@ -451,29 +264,26 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo @PathParam("sensorName") String sensor, @QueryParam("username") String user, @QueryParam("from") long from, @QueryParam("to") long to) { -======= - public Response getVirtualFirealarmStats(String deviceId, String sensor, String user, long from, long to) { - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + - VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; - String sensorTableName = getSensorEventTableName(sensor); ->>>>>>> 8a7d4bb6e0a9b94b8a5c9ca8d6d21c3924b2c677 - try { - if (sensorTableName != null) { - List sortByFields = new ArrayList<>(); - SortByField sortByField = new SortByField("time", SORT.ASC, false); - sortByFields.add(sortByField); - List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields); - return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build(); + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + + VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; + String sensorTableName = getSensorEventTableName(sensor); + try { + if (sensorTableName != null) { + List sortByFields = new ArrayList<>(); + SortByField sortByField = new SortByField("time", SORT.ASC, false); + sortByFields.add(sortByField); + List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields); + return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build(); + } + } catch (AnalyticsException e) { + String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; + log.error(errorMsg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build(); } - } catch (AnalyticsException e) { - String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; - log.error(errorMsg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build(); + return Response.status(Response.Status.BAD_REQUEST).build(); } - return Response.status(Response.Status.BAD_REQUEST).build(); - } private boolean waitForServerStartup() { while (!IoTServerStartupListener.isServerReady()) { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java index 6cbd9af81..c9c1a4b79 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java @@ -25,14 +25,12 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; 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.base.MultitenantConstants; 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.core.service.DeviceManagementProviderService; 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.service.impl.exception.VirtualFireAlarmException; @@ -208,9 +206,6 @@ public class VirtualFireAlarmMQTTConnector extends MQTTTransportHandler { } else if (actualMessage.contains("TEMPERATURE")) { String temperatureValue = actualMessage.split(":")[1]; - SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, - temperatureValue, - Calendar.getInstance().getTimeInMillis()); } } catch (VirtualFireAlarmException e) { String errorMsg = diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java index 39588caef..fc6ea6ca1 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java @@ -26,7 +26,6 @@ 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.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; @@ -182,10 +181,6 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler { break; case "CONTROL-REPLY": String tempVal = actualMessage.split(":")[1]; - SensorDataManager.getInstance().setSensorRecord(deviceId, - VirtualFireAlarmConstants.SENSOR_TEMP, - tempVal, - Calendar.getInstance().getTimeInMillis()); break; default: From f5fc978b5b520a4e56cd3bb378f14dc3970ccf05 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 19 Apr 2016 23:43:27 +0530 Subject: [PATCH 3/4] refactored analytics scripts --- .../data/publisher/DataPublisherService.java | 3 +- .../android/sense/data/publisher/Event.java | 6 +- .../mqtt/AndroidSenseMQTTHandler.java | 2 - .../mqtt/transport/MQTTTransportHandler.java | 4 +- .../realtimeviewer/ActivitySelectSensor.java | 3 + .../sense/util/SenseClientAsyncExecutor.java | 7 +- .../src/main/res/layout/activity_register.xml | 59 ++++----- .../build.xml | 46 +------ .../EventExecution_AndroidSense.siddhiql | 87 +++++++++++++ .../artifact.xml | 4 +- .../EventPublisher_AndroidSense.xml | 25 ++++ .../artifact.xml | 4 +- .../EventReceiver_AndroidSense.xml | 33 +++++ .../artifact.xml | 4 +- .../artifact.xml | 5 +- .../org.wso2.iot.android.sense_1.0.0.json | 38 ++++++ .../carbonapps/Android_Sense/artifacts.xml | 27 ++++ .../AndroidSenseControllerServiceImpl.java | 12 +- .../transport/AndroidSenseMQTTConnector.java | 2 - .../build.xml | 38 ------ .../Temperature_Sensor_Script.xml | 31 ----- components/iot-plugins/arduino-plugin/pom.xml | 1 - .../DigitalDisplayControllerServiceImpl.java | 1 - .../util/DigitalDisplayMQTTConnector.java | 2 - .../service/impl/DroneRealTimeService.java | 1 - .../transport/DroneAnalyzerXMPPConnector.java | 1 - .../build.xml | 82 ++++++++++++ .../pom.xml | 7 +- .../src/assembly/src.xml | 0 .../EventReceiver_accelerometer.xml | 0 .../artifact.xml | 0 .../artifact.xml | 0 .../org_wso2_iot_devices_accelerometer.xml | 16 ++- .../artifact.xml | 4 +- ....wso2.iot.devices.accelerometer_1.0.0.json | 6 +- .../Accelerometer_Sensor_Script.xml | 5 +- .../Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Accelerometer/artifacts.xml | 4 +- .../EventReceiver_battery.xml | 0 .../Eventreceiver_battery_1.0.0/artifact.xml | 0 .../Eventstore_battery_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_battery.xml | 4 +- .../Eventstream_battery_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.battery_1.0.0.json | 2 +- .../Battery_Sensor_Script.xml | 5 +- .../Battery/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Battery/artifacts.xml | 0 .../EventReceiver_gps.xml | 0 .../GPS/Eventreceiver_gps_1.0.0/artifact.xml | 0 .../GPS/Eventstore_gps_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_gps.xml | 4 +- .../GPS/Eventstream_gps_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.gps_1.0.0.json | 8 +- .../Sparkscripts_1.0.0/GPS_Sensor_Script.xml | 3 +- .../GPS/Sparkscripts_1.0.0/artifact.xml | 0 .../resources/carbonapps/GPS/artifacts.xml | 4 +- .../EventReceiver_gravity.xml | 0 .../Eventreceiver_gravaity_1.0.0/artifact.xml | 0 .../Eventstore_gravity_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_gravity.xml | 16 ++- .../Eventstream_gravity_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.gravity_1.0.0.json | 6 +- .../Gravity_Sensor_Script.xml | 5 +- .../Gravity/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Gravity/artifacts.xml | 2 - .../EventReceiver_gyroscope.xml | 0 .../artifact.xml | 0 .../Eventstore_gyroscope_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_gyroscope.xml | 16 ++- .../Eventstream_gyroscope_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.gyroscope_1.0.0.json | 6 +- .../Gyroscope_Sensor_Script.xml | 5 +- .../Gyroscope/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Gyroscope/artifacts.xml | 0 .../EventReceiver_light.xml | 0 .../Eventreceiver_light_1.0.0/artifact.xml | 0 .../Light/Eventstore_light_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_light.xml | 0 .../Eventstream_light_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.light_1.0.0.json | 4 +- .../Light_Sensor_Script.xml | 1 - .../Light/Sparkscripts_1.0.0/artifact.xml | 0 .../resources/carbonapps/Light/artifacts.xml | 4 +- .../EventReceiver_magnetic.xml | 0 .../Eventreceiver_magnetic_1.0.0/artifact.xml | 0 .../Eventstore_magnetic_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_magnetic.xml | 16 ++- .../Eventstream_magnetic_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.magnetic_1.0.0.json | 6 +- .../Magnetic_Sensor_Script.xml | 4 +- .../Magnetic/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Magnetic/artifacts.xml | 4 +- .../EventReceiver_pressure.xml | 0 .../Eventreceiver_pressure_1.0.0/artifact.xml | 0 .../Eventstore_pressure_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_pressure.xml | 0 .../Eventstream_pressure_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.pressure_1.0.0.json | 4 +- .../Pressure_Sensor_Script.xml | 1 - .../Pressure/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Pressure/artifacts.xml | 2 - .../EventReceiver_proximity.xml | 0 .../artifact.xml | 0 .../Eventstore_proximity_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_proximity.xml | 0 .../Eventstream_proximity_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.proximity_1.0.0.json | 0 .../Proximity_Sensor_Script.xml | 0 .../Proximity/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Proximity/artifacts.xml | 0 .../EventReceiver_rotation.xml | 0 .../Eventreceiver_rotation_1.0.0/artifact.xml | 0 .../Eventstore_rotation_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_rotation.xml | 16 ++- .../Eventstream_rotation_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.rotation_1.0.0.json | 6 +- .../Rotation_Sensor_Script.xml | 5 +- .../Rotation/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Rotation/artifacts.xml | 0 .../EventPublisher_temperature.xml} | 11 +- .../artifact.xml | 4 +- .../EventReceiver_temperature.xml | 0 .../artifact.xml | 0 .../Eventstore_temperature_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_temperature.xml | 0 .../artifact.xml | 0 ...rg.wso2.iot.devices.temperature_1.0.0.json | 0 .../Temperature_Sensor_Script.xml | 1 - .../Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/Temperature}/artifacts.xml | 5 +- .../EventReceiver_wordcount.xml | 0 .../artifact.xml | 0 .../Eventstore_wordcount_1.0.0/artifact.xml | 0 .../org_wso2_iot_devices_wordcount.xml | 0 .../Eventstream_wordcount_1.0.0/artifact.xml | 0 .../org.wso2.iot.devices.wordcount_1.0.0.json | 0 .../Sparkscripts_1.0.0/Wordcount_Script.xml | 0 .../WordCount/Sparkscripts_1.0.0/artifact.xml | 0 .../carbonapps/WordCount/artifacts.xml | 2 - components/iot-plugins/iot-analytics/pom.xml | 39 ++++++ .../transport/mqtt/MQTTTransportHandler.java | 6 +- .../transport/xmpp/XMPPTransportHandler.java | 3 - components/iot-plugins/pom.xml | 1 + .../build.xml | 38 ------ .../pom.xml | 92 -------------- .../src/assembly/src.xml | 36 ------ .../EventReceiver_temperature.xml | 26 ---- .../Eventstore_temperature_1.0.0/artifact.xml | 22 ---- .../org_wso2_iot_devices_temperature.xml | 62 --------- ...rg.wso2.iot.devices.temperature_1.0.0.json | 20 --- .../Temperature_Sensor/artifacts.xml | 29 ----- .../RaspberryPiControllerServiceImpl.java | 1 - .../transport/RaspberryPiMQTTConnector.java | 1 - .../iot-plugins/raspberrypi-plugin/pom.xml | 1 - .../transport/mqtt/MQTTTransportHandler.java | 1 - .../build.xml | 38 ------ .../pom.xml | 92 -------------- .../src/assembly/src.xml | 36 ------ .../Eventstore_temperature_1.0.0/artifact.xml | 22 ---- .../org_wso2_iot_devices_temperature.xml | 62 --------- ...rg.wso2.iot.devices.temperature_1.0.0.json | 20 --- .../Temperature_Sensor_Script.xml | 31 ----- .../Temperature_Sensor/artifacts.xml | 29 ----- ...VirtualFireAlarmControllerServiceImpl.java | 3 - .../VirtualFireAlarmMQTTConnector.java | 2 - .../VirtualFireAlarmXMPPConnector.java | 1 - .../virtual-fire-alarm-plugin/pom.xml | 1 - .../pom.xml | 5 + .../pom.xml | 17 +-- .../pom.xml | 120 ++++++++++++++++++ .../src/main/resources/build.properties | 1 + .../src/main/resources/p2.inf | 3 + .../iot-analytics-feature/pom.xml | 40 ++++++ features/iot-plugins-feature/pom.xml | 1 + .../pom.xml | 17 +-- .../pom.xml | 64 +++++----- .../src/main/resources/p2.inf | 2 - 177 files changed, 732 insertions(+), 1005 deletions(-) create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventExecution_AndroidSense_1.0.0/EventExecution_AndroidSense.siddhiql rename components/iot-plugins/{raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstream_temperature_1.0.0 => androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventExecution_AndroidSense_1.0.0}/artifact.xml (81%) create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventPublisher_AndroidSense_1.0.0/EventPublisher_AndroidSense.xml rename components/iot-plugins/{virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Sparkscripts_1.0.0 => androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventPublisher_AndroidSense_1.0.0}/artifact.xml (81%) create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventReceiver_AndroidSense_1.0.0/EventReceiver_AndroidSense.xml rename components/iot-plugins/{virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventreceiver_temperature_1.0.0 => androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventReceiver_AndroidSense_1.0.0}/artifact.xml (81%) rename components/iot-plugins/{raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventreceiver_temperature_1.0.0 => androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventStream_AndroidSense_1.0.0}/artifact.xml (81%) create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/EventStream_AndroidSense_1.0.0/org.wso2.iot.android.sense_1.0.0.json create mode 100644 components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/Android_Sense/artifacts.xml delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/build.xml delete mode 100644 components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor/Sparkscripts_1.0.0/Temperature_Sensor_Script.xml create mode 100644 components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/build.xml rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/pom.xml (94%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/assembly/src.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/Eventreceiver_accelerometer_1.0.0/EventReceiver_accelerometer.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/Eventreceiver_accelerometer_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/Eventstore_accelerometer_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/Eventstore_accelerometer_1.0.0/org_wso2_iot_devices_accelerometer.xml (82%) rename components/iot-plugins/{virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstream_temperature_1.0.0 => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Accelerometer/Eventstream_accelerometer_1.0.0}/artifact.xml (81%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/Eventstream_accelerometer_1.0.0/org.wso2.iot.devices.accelerometer_1.0.0.json (80%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/Sparkscripts_1.0.0/Accelerometer_Sensor_Script.xml (69%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Accelerometer/artifacts.xml (97%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Eventreceiver_battery_1.0.0/EventReceiver_battery.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Eventreceiver_battery_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Eventstore_battery_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Eventstore_battery_1.0.0/org_wso2_iot_devices_battery.xml (97%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Eventstream_battery_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Eventstream_battery_1.0.0/org.wso2.iot.devices.battery_1.0.0.json (91%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Sparkscripts_1.0.0/Battery_Sensor_Script.xml (65%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Battery/artifacts.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Eventreceiver_gps_1.0.0/EventReceiver_gps.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Eventreceiver_gps_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Eventstore_gps_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Eventstore_gps_1.0.0/org_wso2_iot_devices_gps.xml (97%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Eventstream_gps_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Eventstream_gps_1.0.0/org.wso2.iot.devices.gps_1.0.0.json (78%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Sparkscripts_1.0.0/GPS_Sensor_Script.xml (85%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/GPS/artifacts.xml (98%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Eventreceiver_gravaity_1.0.0/EventReceiver_gravity.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Eventreceiver_gravaity_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Eventstore_gravity_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Eventstore_gravity_1.0.0/org_wso2_iot_devices_gravity.xml (82%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Eventstream_gravity_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Eventstream_gravity_1.0.0/org.wso2.iot.devices.gravity_1.0.0.json (79%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Sparkscripts_1.0.0/Gravity_Sensor_Script.xml (77%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gravity/artifacts.xml (99%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Eventreceiver_gyroscope_1.0.0/EventReceiver_gyroscope.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Eventreceiver_gyroscope_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Eventstore_gyroscope_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Eventstore_gyroscope_1.0.0/org_wso2_iot_devices_gyroscope.xml (82%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Eventstream_gyroscope_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Eventstream_gyroscope_1.0.0/org.wso2.iot.devices.gyroscope_1.0.0.json (79%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Sparkscripts_1.0.0/Gyroscope_Sensor_Script.xml (66%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Gyroscope/artifacts.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Eventreceiver_light_1.0.0/EventReceiver_light.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Eventreceiver_light_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Eventstore_light_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Eventstore_light_1.0.0/org_wso2_iot_devices_light.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Eventstream_light_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Eventstream_light_1.0.0/org.wso2.iot.devices.light_1.0.0.json (88%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Sparkscripts_1.0.0/Light_Sensor_Script.xml (98%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Light/artifacts.xml (97%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Eventreceiver_magnetic_1.0.0/EventReceiver_magnetic.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Eventreceiver_magnetic_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Eventstore_magnetic_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Eventstore_magnetic_1.0.0/org_wso2_iot_devices_magnetic.xml (82%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Eventstream_magnetic_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Eventstream_magnetic_1.0.0/org.wso2.iot.devices.magnetic_1.0.0.json (79%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Sparkscripts_1.0.0/Magnetic_Sensor_Script.xml (75%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Magnetic/artifacts.xml (98%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Eventreceiver_pressure_1.0.0/EventReceiver_pressure.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Eventreceiver_pressure_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Eventstore_pressure_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Eventstore_pressure_1.0.0/org_wso2_iot_devices_pressure.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Eventstream_pressure_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Eventstream_pressure_1.0.0/org.wso2.iot.devices.pressure_1.0.0.json (88%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Sparkscripts_1.0.0/Pressure_Sensor_Script.xml (99%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Pressure/artifacts.xml (99%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Eventreceiver_proximity_1.0.0/EventReceiver_proximity.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Eventreceiver_proximity_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Eventstore_proximity_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Eventstore_proximity_1.0.0/org_wso2_iot_devices_proximity.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Eventstream_proximity_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Eventstream_proximity_1.0.0/org.wso2.iot.devices.proximity_1.0.0.json (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Sparkscripts_1.0.0/Proximity_Sensor_Script.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Proximity/artifacts.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Eventreceiver_rotation_1.0.0/EventReceiver_rotation.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Eventreceiver_rotation_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Eventstore_rotation_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Eventstore_rotation_1.0.0/org_wso2_iot_devices_rotation.xml (82%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Eventstream_rotation_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Eventstream_rotation_1.0.0/org.wso2.iot.devices.rotation_1.0.0.json (79%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Sparkscripts_1.0.0/Rotation_Sensor_Script.xml (66%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/Rotation/artifacts.xml (100%) rename components/iot-plugins/{virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventreceiver_temperature_1.0.0/EventReceiver_temperature.xml => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature/Eventpublisher_temperature_1.0.0/EventPublisher_temperature.xml} (69%) rename components/iot-plugins/{raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/Sparkscripts_1.0.0 => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature/Eventpublisher_temperature_1.0.0}/artifact.xml (81%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Eventreceiver_temperature_1.0.0/EventReceiver_temperature.xml (100%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Eventreceiver_temperature_1.0.0/artifact.xml (100%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Eventstore_temperature_1.0.0/artifact.xml (100%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Eventstore_temperature_1.0.0/org_wso2_iot_devices_temperature.xml (100%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Eventstream_temperature_1.0.0/artifact.xml (100%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Eventstream_temperature_1.0.0/org.wso2.iot.devices.temperature_1.0.0.json (100%) rename components/iot-plugins/{raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Sparkscripts_1.0.0/Temperature_Sensor_Script.xml (99%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Temperature_Sensor => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/Temperature}/artifacts.xml (85%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Eventreceiver_wordcount_1.0.0/EventReceiver_wordcount.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Eventreceiver_wordcount_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Eventstore_wordcount_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Eventstore_wordcount_1.0.0/org_wso2_iot_devices_wordcount.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Eventstream_wordcount_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Eventstream_wordcount_1.0.0/org.wso2.iot.devices.wordcount_1.0.0.json (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Sparkscripts_1.0.0/Wordcount_Script.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/Sparkscripts_1.0.0/artifact.xml (100%) rename components/iot-plugins/{androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics => iot-analytics/org.wso2.carbon.device.mgt.iot.analytics}/src/main/resources/carbonapps/WordCount/artifacts.xml (99%) create mode 100644 components/iot-plugins/iot-analytics/pom.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/build.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/assembly/src.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventreceiver_temperature_1.0.0/EventReceiver_temperature.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstore_temperature_1.0.0/artifact.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstore_temperature_1.0.0/org_wso2_iot_devices_temperature.xml delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstream_temperature_1.0.0/org.wso2.iot.devices.temperature_1.0.0.json delete mode 100644 components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/src/main/resources/carbonapps/Temperature_Sensor/artifacts.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/build.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/assembly/src.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstore_temperature_1.0.0/artifact.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstore_temperature_1.0.0/org_wso2_iot_devices_temperature.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Eventstream_temperature_1.0.0/org.wso2.iot.devices.temperature_1.0.0.json delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/Sparkscripts_1.0.0/Temperature_Sensor_Script.xml delete mode 100644 components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/Temperature_Sensor/artifacts.xml create mode 100644 features/iot-plugins-feature/iot-analytics-feature/org.wso2.carbon.device.mgt.iot.analytics.feature/pom.xml create mode 100644 features/iot-plugins-feature/iot-analytics-feature/org.wso2.carbon.device.mgt.iot.analytics.feature/src/main/resources/build.properties create mode 100644 features/iot-plugins-feature/iot-analytics-feature/org.wso2.carbon.device.mgt.iot.analytics.feature/src/main/resources/p2.inf create mode 100644 features/iot-plugins-feature/iot-analytics-feature/pom.xml diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java index 51c7cb807..0f852fd6c 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/DataPublisherService.java @@ -23,6 +23,7 @@ import android.util.Log; import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler; import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler; import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException; @@ -149,7 +150,7 @@ public class DataPublisherService extends Service { for (Event event : events) { event.setOwner(user); event.setDeviceId(deviceId); - jsonArray.put(event.getEvent()); + jsonArray.put(new JSONObject().put("event", event.getEvent())); } MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(context); if (!mqttTransportHandler.isConnected()) { diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java index 554c38b12..a8d936010 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/Event.java @@ -11,7 +11,7 @@ public class Event { private String owner; private String deviceId; private String type; - private float battery; + private int battery; private double gps[]; //lat,long private float accelerometer[]; //x,y,z private float magnetic[]; //x,y,z @@ -26,11 +26,11 @@ public class Event { private String wordStatus; private long timestamp; - private float getBattery() { + private int getBattery() { return battery; } - public void setBattery(float battery) { + public void setBattery(int battery) { this.type = "battery"; this.battery = battery; } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/AndroidSenseMQTTHandler.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/AndroidSenseMQTTHandler.java index 5ae9b3739..989ad6d38 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/AndroidSenseMQTTHandler.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/AndroidSenseMQTTHandler.java @@ -104,7 +104,6 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler { }; Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); connectorThread.start(); } @@ -207,7 +206,6 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler { }; Thread terminatorThread = new Thread(stopConnection); - terminatorThread.setDaemon(true); terminatorThread.start(); } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/transport/MQTTTransportHandler.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/transport/MQTTTransportHandler.java index 689138d72..5fc5112d6 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/transport/MQTTTransportHandler.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/data/publisher/mqtt/transport/MQTTTransportHandler.java @@ -81,8 +81,8 @@ public abstract class MQTTTransportHandler implements MqttCallback, TransportHan this.clientWillTopic = DISCONNECTION_WILL_TOPIC_PREFIX + SenseConstants.DEVICE_TYPE; this.mqttBrokerEndPoint = "tcp://" + LocalRegistry.getServerHost(context) + ":" + LocalRegistry.getMqttPort(context); this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL; - setUsernameAndPassword(LocalRegistry.getAccessToken(context), ""); this.initMQTTClient(); + setUsernameAndPassword(LocalRegistry.getAccessToken(context), ""); } /** @@ -308,7 +308,6 @@ public abstract class MQTTTransportHandler implements MqttCallback, TransportHan connect(); } }; - reconnectThread.setDaemon(true); reconnectThread.start(); } @@ -333,7 +332,6 @@ public abstract class MQTTTransportHandler implements MqttCallback, TransportHan } } }; - messageProcessorThread.setDaemon(true); messageProcessorThread.start(); } diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/realtimeviewer/ActivitySelectSensor.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/realtimeviewer/ActivitySelectSensor.java index 053b7e38c..b93a3a627 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/realtimeviewer/ActivitySelectSensor.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/realtimeviewer/ActivitySelectSensor.java @@ -180,6 +180,9 @@ public class ActivitySelectSensor extends AppCompatActivity LocalRegistry.removeUsername(getApplicationContext()); LocalRegistry.removeDeviceId(getApplicationContext()); LocalRegistry.removeServerURL(getApplicationContext()); + LocalRegistry.removeAccessToken(getApplicationContext()); + LocalRegistry.removeRefreshToken(getApplicationContext()); + LocalRegistry.removeMqttPort(getApplicationContext()); LocalRegistry.setExist(false); //Stop the current running background services. stopService(new Intent(this, SenseService.class)); //Stop sensor reading service diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseClientAsyncExecutor.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseClientAsyncExecutor.java index 79b3d740b..c16759ee7 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseClientAsyncExecutor.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/SenseClientAsyncExecutor.java @@ -95,6 +95,7 @@ public class SenseClientAsyncExecutor extends AsyncTask responseMap = new HashMap<>(); responseMap.put(STATUS, "200"); + AccessTokenInfo accessTokenInfo = null; try { //DynamicClientRegistraiton. DynamicClientRegistrationService dynamicClientRegistrationService = Feign.builder() @@ -116,7 +117,7 @@ public class SenseClientAsyncExecutor extends AsyncTask + android:paddingTop="@dimen/activity_vertical_margin" tools:context="org.wso2.carbon.iot.android.sense.RegisterActivity" + android:weightSum="1"> @@ -14,7 +15,8 @@ + android:fillViewport="false" + android:layout_weight="0.07"> @@ -37,43 +39,36 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/hostname" android:id="@+id/hostname" - android:text="https://localhost:9443" + android:text="https://10.10.10.149:9443" android:inputType="text" android:maxLines="1" android:singleLine="true"/> -