diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml index 08e244b9af..69bb002679 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml @@ -80,12 +80,10 @@ org.codehaus.jackson jackson-core-asl - provided org.codehaus.jackson jackson-jaxrs - provided javax diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java index 39fcc7f252..ac9bb9c6f8 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -25,13 +25,13 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.iot.DeviceManagement; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceJSON; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorJSON; -import org.wso2.carbon.device.mgt.iot.DeviceManagement; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; -import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; @@ -83,8 +83,10 @@ public class AndroidSenseService { @Context //injected response proxy supporting multiple thread private HttpServletResponse response; - @Path("manager/device") @PUT public boolean register(@FormParam("deviceId") String deviceId, - @FormParam("owner") String owner) { + @Path("manager/device") + @PUT + public boolean register(@FormParam("deviceId") String deviceId, + @FormParam("owner") String owner) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -126,8 +128,10 @@ public class AndroidSenseService { } } - @Path("manager/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + @Path("manager/device/remove/{device_id}") + @DELETE + public void removeDevice(@PathParam("device_id") String deviceId, + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -150,9 +154,10 @@ public class AndroidSenseService { } - @Path("manager/device/update/{device_id}") @POST - public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, + @Path("manager/device/update/{device_id}") + @POST + public boolean updateDevice( + @PathParam("device_id") String deviceId, @QueryParam("name") String name, @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -189,7 +194,11 @@ public class AndroidSenseService { } - @Path("manager/device/{device_id}") @GET @Consumes("application/json") @Produces("application/json") public Device getDevice( + @Path("manager/device/{device_id}") + @GET + @Consumes("application/json") + @Produces("application/json") + public Device getDevice( @PathParam("device_id") String deviceId) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -211,8 +220,11 @@ public class AndroidSenseService { /* Service to push all the sensor data collected by the Android Called by the Android device */ - @Path("controller/sensordata") @POST @Consumes(MediaType.APPLICATION_JSON) - public void pushSensorData(final DeviceJSON dataMsg, @Context HttpServletResponse response) { + @Path("controller/sensordata") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public void pushSensorData( + final DeviceJSON dataMsg, @Context HttpServletResponse response) { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); @@ -227,91 +239,91 @@ public class AndroidSenseService { for (SensorJSON sensor : sensorData) { switch (sensor.key) { - case "battery": - streamDef = BATTERY_STREAM_DEFINITION; - payloadData = new Object[] { Float.parseFloat(sensor.value) }; - sensorName = SENSOR_BATTERY; - break; - case "GPS": - streamDef = GPS_STREAM_DEFINITION; - String gpsValue = sensor.value; - String gpsValues[] = gpsValue.split(","); - Float gpsValuesF[] = new Float[2]; - gpsValuesF[0] = Float.parseFloat(gpsValues[0]); - gpsValuesF[1] = Float.parseFloat(gpsValues[0]); - payloadData = gpsValuesF; - sensorName = SENSOR_GPS; - break; - default: - try { - int androidSensorId = Integer.parseInt(sensor.key); - - if (androidSensorId == 2) { - streamDef = MAGNETIC_STREAM_DEFINITION; - String value = sensor.value; - String valuesM[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float - .parseFloat(valuesM[0]); - payloadData = gValuesF; - sensorName = SENSOR_MAGNETIC; - } else if (androidSensorId == 5) { - streamDef = LIGHT_STREAM_DEFINITION; - sensorName = SENSOR_LIGHT; - payloadData = new Object[] { Float.parseFloat(sensor.value) }; - } else if (androidSensorId == 1){ - streamDef = ACCELEROMETER_STREAM_DEFINITION; - String value = sensor.value; - String valuesM[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float - .parseFloat(valuesM[0]); - payloadData = gValuesF; - sensorName = SENSOR_ACCELEROMETER; - } else if (androidSensorId == 4) { - streamDef = GYROSCOPE_STREAM_DEFINITION; - String value = sensor.value; - String valuesG[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float - .parseFloat(valuesG[0]); - payloadData = gValuesF; - sensorName = SENSOR_GYROSCOPE; - } else if (androidSensorId == 9) { - streamDef = GRAVITY_STREAM_DEFINITION; - String value = sensor.value; - String valuesG[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float - .parseFloat(valuesG[0]); - payloadData = gValuesF; - sensorName = SENSOR_GRVITY; - } else if (androidSensorId == 11) { - streamDef = ROTATION_STREAM_DEFINITION; - String value = sensor.value; - String valuesG[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float - .parseFloat(valuesG[0]); - payloadData = gValuesF; - sensorName = SENSOR_ROTATION; - } else if (androidSensorId == 8) { - streamDef = PROXIMITY_STREAM_DEFINITION; - sensorName = SENSOR_PROXIMITY; - payloadData = new Object[] { Float.parseFloat(sensor.value) }; - } else if (androidSensorId == 6) { - streamDef = PRESSURE_STREAM_DEFINITION; - sensorName = SENSOR_PRESSURE; - payloadData = new Object[] { Float.parseFloat(sensor.value) }; + case "battery": + streamDef = BATTERY_STREAM_DEFINITION; + payloadData = new Object[]{Float.parseFloat(sensor.value)}; + sensorName = SENSOR_BATTERY; + break; + case "GPS": + streamDef = GPS_STREAM_DEFINITION; + String gpsValue = sensor.value; + String gpsValues[] = gpsValue.split(","); + Float gpsValuesF[] = new Float[2]; + gpsValuesF[0] = Float.parseFloat(gpsValues[0]); + gpsValuesF[1] = Float.parseFloat(gpsValues[0]); + payloadData = gpsValuesF; + sensorName = SENSOR_GPS; + break; + default: + try { + int androidSensorId = Integer.parseInt(sensor.key); + + if (androidSensorId == 2) { + streamDef = MAGNETIC_STREAM_DEFINITION; + String value = sensor.value; + String valuesM[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float + .parseFloat(valuesM[0]); + payloadData = gValuesF; + sensorName = SENSOR_MAGNETIC; + } else if (androidSensorId == 5) { + streamDef = LIGHT_STREAM_DEFINITION; + sensorName = SENSOR_LIGHT; + payloadData = new Object[]{Float.parseFloat(sensor.value)}; + } else if (androidSensorId == 1) { + streamDef = ACCELEROMETER_STREAM_DEFINITION; + String value = sensor.value; + String valuesM[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float + .parseFloat(valuesM[0]); + payloadData = gValuesF; + sensorName = SENSOR_ACCELEROMETER; + } else if (androidSensorId == 4) { + streamDef = GYROSCOPE_STREAM_DEFINITION; + String value = sensor.value; + String valuesG[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float + .parseFloat(valuesG[0]); + payloadData = gValuesF; + sensorName = SENSOR_GYROSCOPE; + } else if (androidSensorId == 9) { + streamDef = GRAVITY_STREAM_DEFINITION; + String value = sensor.value; + String valuesG[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float + .parseFloat(valuesG[0]); + payloadData = gValuesF; + sensorName = SENSOR_GRVITY; + } else if (androidSensorId == 11) { + streamDef = ROTATION_STREAM_DEFINITION; + String value = sensor.value; + String valuesG[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float + .parseFloat(valuesG[0]); + payloadData = gValuesF; + sensorName = SENSOR_ROTATION; + } else if (androidSensorId == 8) { + streamDef = PROXIMITY_STREAM_DEFINITION; + sensorName = SENSOR_PROXIMITY; + payloadData = new Object[]{Float.parseFloat(sensor.value)}; + } else if (androidSensorId == 6) { + streamDef = PRESSURE_STREAM_DEFINITION; + sensorName = SENSOR_PRESSURE; + payloadData = new Object[]{Float.parseFloat(sensor.value)}; + } + //Add the remaining sensor types. + + } catch (NumberFormatException e) { + continue; } - //Add the remaining sensor types. - - } catch (NumberFormatException e) { - continue; - } } - Object metdaData[] = { dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time }; + Object metdaData[] = {dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time}; if (streamDef != null && payloadData != null && payloadData.length > 0) { try { @@ -385,13 +397,12 @@ public class AndroidSenseService { return sensorRecord; } - @Path("controller/readmagnetic") @GET @Consumes("application/json") @Produces("application/json") - public SensorRecord readMagnetic(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, + public SensorRecord readMagnetic( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @Context HttpServletResponse response) { SensorRecord sensorRecord = null; @@ -408,14 +419,14 @@ public class AndroidSenseService { /** * Created by Menaka * Adding Accelerometer - * */ + */ @Path("controller/readaccelerometer") @GET @Consumes("application/json") @Produces("application/json") - public SensorRecord readAccelerometer(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, + public SensorRecord readAccelerometer( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @Context HttpServletResponse response) { SensorRecord sensorRecord = null; @@ -433,8 +444,8 @@ public class AndroidSenseService { @GET @Consumes("application/json") @Produces("application/json") - public SensorRecord readRotation(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, + public SensorRecord readRotation( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @Context HttpServletResponse response) { SensorRecord sensorRecord = null; @@ -452,8 +463,8 @@ public class AndroidSenseService { @GET @Consumes("application/json") @Produces("application/json") - public SensorRecord readProximity(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, + public SensorRecord readProximity( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @Context HttpServletResponse response) { SensorRecord sensorRecord = null; @@ -471,8 +482,8 @@ public class AndroidSenseService { @GET @Consumes("application/json") @Produces("application/json") - public SensorRecord readGyroscope(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, + public SensorRecord readGyroscope( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @Context HttpServletResponse response) { SensorRecord sensorRecord = null; @@ -490,8 +501,8 @@ public class AndroidSenseService { @GET @Consumes("application/json") @Produces("application/json") - public SensorRecord readPressure(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, + public SensorRecord readPressure( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @Context HttpServletResponse response) { SensorRecord sensorRecord = null; @@ -509,8 +520,8 @@ public class AndroidSenseService { @GET @Consumes("application/json") @Produces("application/json") - public SensorRecord readGravity(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, + public SensorRecord readGravity( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @Context HttpServletResponse response) { SensorRecord sensorRecord = null; @@ -524,5 +535,4 @@ public class AndroidSenseService { return sensorRecord; } - } diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/resources.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/resources.xml index fda8f3253c..a2f040ee53 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/resources.xml +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/resources.xml @@ -84,6 +84,36 @@ http://localhost:9763/android_sense/controller/readmagnetic /controller/readmagnetic + + Any + GET + http://localhost:9763/android_sense/controller/readgravity + /controller/readgravity + + + Any + GET + http://localhost:9763/android_sense/controller/readpressure + /controller/readpressure + + + Any + GET + http://localhost:9763/android_sense/controller/readproximity + /controller/readproximity + + + Any + GET + http://localhost:9763/android_sense/controller/readgyroscope + /controller/readgyroscope + + + Any + GET + http://localhost:9763/android_sense/controller/readrotation + /controller/readrotation + Any GET diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/web.xml index 5227008858..db5733aaff 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/web.xml +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/web.xml @@ -19,44 +19,44 @@ /* - - isAdminService - false - - - doAuthentication - false - + + + + + + + + - - managed-api-enabled - true - - - managed-api-owner - admin - - - managed-api-name - android_sense - - - managed-api-endpoint - http://localhost:9763/android_sense - - - managed-api-version - 1.0.0 - - - managed-api-context - /android_sense - - - managed-api-isSecured - true - + + + + + + + + + + + + + + + + + + + + + + + + + + + +