code formatting and resource xml file/ deployment failure fixed

Menaka Madushanka 9 years ago committed by menaka
parent e4296b301b
commit 972484faef

@ -80,12 +80,10 @@
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>

@ -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;
}
}

@ -84,6 +84,36 @@
<Uri>http://localhost:9763/android_sense/controller/readmagnetic</Uri>
<UriTemplate>/controller/readmagnetic</UriTemplate>
</Resource>
<Resource>
<AuthType>Any</AuthType>
<HttpVerb>GET</HttpVerb>
<Uri>http://localhost:9763/android_sense/controller/readgravity</Uri>
<UriTemplate>/controller/readgravity</UriTemplate>
</Resource>
<Resource>
<AuthType>Any</AuthType>
<HttpVerb>GET</HttpVerb>
<Uri>http://localhost:9763/android_sense/controller/readpressure</Uri>
<UriTemplate>/controller/readpressure</UriTemplate>
</Resource>
<Resource>
<AuthType>Any</AuthType>
<HttpVerb>GET</HttpVerb>
<Uri>http://localhost:9763/android_sense/controller/readproximity</Uri>
<UriTemplate>/controller/readproximity</UriTemplate>
</Resource>
<Resource>
<AuthType>Any</AuthType>
<HttpVerb>GET</HttpVerb>
<Uri>http://localhost:9763/android_sense/controller/readgyroscope</Uri>
<UriTemplate>/controller/readgyroscope</UriTemplate>
</Resource>
<Resource>
<AuthType>Any</AuthType>
<HttpVerb>GET</HttpVerb>
<Uri>http://localhost:9763/android_sense/controller/readrotation</Uri>
<UriTemplate>/controller/readrotation</UriTemplate>
</Resource>
<Resource>
<AuthType>Any</AuthType>
<HttpVerb>GET</HttpVerb>

@ -19,44 +19,44 @@
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>isAdminService</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>doAuthentication</param-name>
<param-value>false</param-value>
</context-param>
<!--<context-param>-->
<!--<param-name>isAdminService</param-name>-->
<!--<param-value>false</param-value>-->
<!--</context-param>-->
<!--<context-param>-->
<!--<param-name>doAuthentication</param-name>-->
<!--<param-value>false</param-value>-->
<!--</context-param>-->
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
<context-param>
<param-name>managed-api-name</param-name>
<param-value>android_sense</param-value>
</context-param>
<context-param>
<param-name>managed-api-endpoint</param-name>
<param-value>http://localhost:9763/android_sense</param-value>
</context-param>
<context-param>
<param-name>managed-api-version</param-name>
<param-value>1.0.0</param-value>
</context-param>
<context-param>
<param-name>managed-api-context</param-name>
<param-value>/android_sense</param-value>
</context-param>
<context-param>
<param-name>managed-api-isSecured</param-name>
<param-value>true</param-value>
</context-param>
<!--<context-param>-->
<!--<param-name>managed-api-enabled</param-name>-->
<!--<param-value>true</param-value>-->
<!--</context-param>-->
<!--<context-param>-->
<!--<param-name>managed-api-owner</param-name>-->
<!--<param-value>admin</param-value>-->
<!--</context-param>-->
<!--<context-param>-->
<!--<param-name>managed-api-name</param-name>-->
<!--<param-value>android_sense</param-value>-->
<!--</context-param>-->
<!--<context-param>-->
<!--<param-name>managed-api-endpoint</param-name>-->
<!--<param-value>http://localhost:9763/android_sense</param-value>-->
<!--</context-param>-->
<!--<context-param>-->
<!--<param-name>managed-api-version</param-name>-->
<!--<param-value>1.0.0</param-value>-->
<!--</context-param>-->
<!--<context-param>-->
<!--<param-name>managed-api-context</param-name>-->
<!--<param-value>/android_sense</param-value>-->
<!--</context-param>-->
<!--<context-param>-->
<!--<param-name>managed-api-isSecured</param-name>-->
<!--<param-value>true</param-value>-->
<!--</context-param>-->
<!-- Below configuration is used to redirect http requests to https -->
<!--<security-constraint>-->

Loading…
Cancel
Save