diff --git a/modules/samples/firealarm/component/analytics/build.xml b/modules/samples/firealarm/component/analytics/build.xml index 3b22c228..370ac5c5 100644 --- a/modules/samples/firealarm/component/analytics/build.xml +++ b/modules/samples/firealarm/component/analytics/build.xml @@ -1,21 +1,22 @@ - + + @@ -39,4 +40,3 @@ - diff --git a/modules/samples/firealarm/component/analytics/pom.xml b/modules/samples/firealarm/component/analytics/pom.xml index dd20f744..6593e939 100644 --- a/modules/samples/firealarm/component/analytics/pom.xml +++ b/modules/samples/firealarm/component/analytics/pom.xml @@ -1,20 +1,21 @@ - + + @@ -83,4 +84,4 @@ - \ No newline at end of file + diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql index 4f677bb4..f1c8cb6e 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql @@ -21,4 +21,4 @@ insert into temperature; from firealarm select meta_owner, 'firealarm' as meta_deviceType, meta_deviceId, time:timestampInMilliseconds() as meta_time, humidity -insert into humidity; \ No newline at end of file +insert into humidity; diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_publisher/firealarm_publisher.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_publisher/firealarm_publisher.xml index 2c8fca96..23382fc3 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_publisher/firealarm_publisher.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_publisher/firealarm_publisher.xml @@ -22,4 +22,3 @@ - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_receiver/firealarm_receiver.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_receiver/firealarm_receiver.xml index a8a27c6e..a5d03dad 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_receiver/firealarm_receiver.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_receiver/firealarm_receiver.xml @@ -31,4 +31,3 @@ - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/artifact.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/artifact.xml index fbfc7946..b7d52d83 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/artifact.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/artifact.xml @@ -20,4 +20,3 @@ org.wso2.iot.firealarm_1.0.0.json - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json index 3ed80873..3306dfa6 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json @@ -4,11 +4,23 @@ "nickName": "firealarm_stream", "description": "This hold the device type stream of firealarm", "metaData": [ - {"name": "owner", "type": "STRING"}, - {"name": "deviceId", "type": "STRING"} + { + "name": "owner", + "type": "STRING" + }, + { + "name": "deviceId", + "type": "STRING" + } ], "payloadData": [ - {"name": "temperature", "type": "FLOAT"}, - {"name": "humidity", "type": "FLOAT"} + { + "name": "temperature", + "type": "FLOAT" + }, + { + "name": "humidity", + "type": "FLOAT" + } ] -} \ No newline at end of file +} diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_store/org_wso2_iot_devices_humidity.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_store/org_wso2_iot_devices_humidity.xml index e1994513..c722a26d 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_store/org_wso2_iot_devices_humidity.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_store/org_wso2_iot_devices_humidity.xml @@ -59,4 +59,4 @@ FLOAT - \ No newline at end of file + diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/artifact.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/artifact.xml index cf82eac1..eee196e5 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/artifact.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/artifact.xml @@ -20,4 +20,3 @@ org.wso2.iot.devices.humidity_1.0.0.json - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/org.wso2.iot.devices.humidity_1.0.0.json b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/org.wso2.iot.devices.humidity_1.0.0.json index 7e6006f8..5b0c66c2 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/org.wso2.iot.devices.humidity_1.0.0.json +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_stream/org.wso2.iot.devices.humidity_1.0.0.json @@ -4,17 +4,27 @@ "nickName": "Humidity Data", "description": "Humidity data received from the Device", "metaData": [ - {"name":"owner","type":"STRING"}, - {"name":"deviceType","type":"STRING"}, - {"name":"deviceId","type":"STRING"}, - {"name":"time","type":"LONG"} + { + "name": "owner", + "type": "STRING" + }, + { + "name": "deviceType", + "type": "STRING" + }, + { + "name": "deviceId", + "type": "STRING" + }, + { + "name": "time", + "type": "LONG" + } ], "payloadData": [ { - "name": "humidity","type": "FLOAT" + "name": "humidity", + "type": "FLOAT" } ] } - - - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml index 3ab9a7d3..9ef03714 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml @@ -22,4 +22,3 @@ - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_store/org_wso2_iot_devices_temperature.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_store/org_wso2_iot_devices_temperature.xml index d06f73b1..9351cb4c 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_store/org_wso2_iot_devices_temperature.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_store/org_wso2_iot_devices_temperature.xml @@ -59,4 +59,4 @@ FLOAT - \ No newline at end of file + diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/artifact.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/artifact.xml index cc733b79..4e23982e 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/artifact.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/artifact.xml @@ -20,4 +20,3 @@ org.wso2.iot.devices.temperature_1.0.0.json - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/org.wso2.iot.devices.temperature_1.0.0.json b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/org.wso2.iot.devices.temperature_1.0.0.json index 5d94b982..6dae0d80 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/org.wso2.iot.devices.temperature_1.0.0.json +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/temperature_sensor/temperature_stream/org.wso2.iot.devices.temperature_1.0.0.json @@ -4,17 +4,27 @@ "nickName": "Temperature Data", "description": "Temperature data received from the Device", "metaData": [ - {"name":"owner","type":"STRING"}, - {"name":"deviceType","type":"STRING"}, - {"name":"deviceId","type":"STRING"}, - {"name":"time","type":"LONG"} + { + "name": "owner", + "type": "STRING" + }, + { + "name": "deviceType", + "type": "STRING" + }, + { + "name": "deviceId", + "type": "STRING" + }, + { + "name": "time", + "type": "LONG" + } ], "payloadData": [ { - "name": "temperature","type": "FLOAT" + "name": "temperature", + "type": "FLOAT" } ] } - - - diff --git a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeService.java b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeService.java index 1311dde1..fcf6c1d4 100644 --- a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeService.java +++ b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeService.java @@ -19,29 +19,27 @@ package org.homeautomation.firealarm.api; import org.homeautomation.firealarm.api.dto.DeviceJSON; - import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.Path; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; -import javax.ws.rs.Produces; +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.PUT; -import javax.ws.rs.DELETE; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - /** - * This is the controller API which is used to control agent side functionality + * This is the controller API which is used to control agent side functionality. */ @SuppressWarnings("NonJaxWsWebServices") @API(name = "firealarm", version = "1.0.0", context = "/firealarm", tags = "firealarm") @@ -49,8 +47,10 @@ import javax.ws.rs.core.Response; public interface DeviceTypeService { /** - * @param agentInfo device owner,id and sensor value - * @return + * Validate registration information. + * + * @param agentInfo device owner,id. + * @return true if device instance is added to map. */ @Path("device/register") @POST @@ -59,9 +59,11 @@ public interface DeviceTypeService { Response registerDevice(final DeviceJSON agentInfo); /** - * @param deviceId unique identifier for given device type - * @param state change status of sensor: on/off - * @param response + * Change buzzer status. + * + * @param deviceId unique identifier for given device type. + * @param state change status of buzzer: on/off. + * @param response operation is success or not. */ @Path("device/{deviceId}/change-status") @POST @@ -73,30 +75,48 @@ public interface DeviceTypeService { @Context HttpServletResponse response); /** - * Retrieve Sensor data for the given time period - * @param deviceId unique identifier for given device type instance - * @param sensorName name of the sensor - * @param from starting time - * @param to ending time - * @return response with List object which includes sensor data which is requested + * Retrieve Sensor data for the given time period. + * + * @param deviceId unique identifier for given device type instance. + * @param sensorName name of the sensor. + * @param from starting time. + * @param to ending time. + * @return response with List object which includes sensor data which is requested. */ @Path("device/stats/{deviceId}/sensors/{sensorName}") @GET @Consumes("application/json") @Produces("application/json") Response getSensorStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensorName, - @QueryParam("from") long from, @QueryParam("to") long to); + @QueryParam("from") long from, @QueryParam("to") long to); + /** + * Remove device type instance using device id. + * + * @param deviceId unique identifier for given device type instance. + */ @Path("/device/{device_id}") @DELETE @Permission(scope = "firealarm_user", permissions = {"/permission/admin/device-mgt/removeDevice"}) Response removeDevice(@PathParam("device_id") String deviceId); + /** + * Update device instance name. + * + * @param deviceId unique identifier for given device type instance. + * @param name new name for the device type instance. + */ @Path("/device/{device_id}") @PUT @Permission(scope = "firealarm_user", permissions = {"/permission/admin/device-mgt/updateDevice"}) Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name); + /** + * To get device information. + * + * @param deviceId unique identifier for given device type instance. + * @return firealarm device. + */ @Path("/device/{device_id}") @GET @Consumes(MediaType.APPLICATION_JSON) @@ -104,6 +124,11 @@ public interface DeviceTypeService { @Permission(scope = "firealarm_user", permissions = {"/permission/admin/device-mgt/updateDevice"}) Response getDevice(@PathParam("device_id") String deviceId); + /** + * Get all device type instance which belongs to user. + * + * @return Array of devices which includes device's information. + */ @Path("/devices") @GET @Consumes(MediaType.APPLICATION_JSON) @@ -111,9 +136,16 @@ public interface DeviceTypeService { @Permission(scope = "firealarm_user", permissions = {"/permission/admin/device-mgt/devices"}) Response getAllDevices(); + /** + * To download device type agent source code as zip file. + * + * @param deviceName name for the device type instance. + * @param sketchType folder name where device type agent was installed into server. + * @return Agent source code as zip file. + */ @Path("/device/download") @GET @Produces("application/zip") @Permission(scope = "firealarm_user", permissions = {"/permission/admin/device-mgt/download"}) Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType); -} \ No newline at end of file +} diff --git a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java index 37498bc8..effaf602 100644 --- a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java +++ b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java @@ -69,11 +69,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - /** - * This is the API which is used to control and manage device type functionality + * This is the API which is used to control and manage device type functionality. */ @SuppressWarnings("NonJaxWsWebServices") @API(name = "firealarm", version = "1.0.0", context = "/firealarm", tags = "firealarm") @@ -83,7 +81,6 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { private static final String KEY_TYPE = "PRODUCTION"; private static Log log = LogFactory.getLog(DeviceTypeService.class); private static ApiApplicationKey apiApplicationKey; - private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); private static String shortUUID() { UUID uuid = UUID.randomUUID(); @@ -92,8 +89,10 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { } /** - * @param agentInfo device owner,id - * @return true if device instance is added to map + * Validate registration information. + * + * @param agentInfo device owner,id. + * @return true if device instance is added to map. */ @Path("device/register") @POST @@ -101,15 +100,17 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { public Response registerDevice(final DeviceJSON agentInfo) { String deviceId = agentInfo.deviceId; if ((agentInfo.deviceId != null) && (agentInfo.owner != null)) { - deviceToIpMap.put(deviceId, agentInfo); return Response.status(Response.Status.OK).build(); } return Response.status(Response.Status.NOT_ACCEPTABLE).build(); } /** - * @param deviceId unique identifier for given device type instance - * @param state change status of sensor: on/off + * Change buzzer status. + * + * @param deviceId unique identifier for given device type. + * @param state change status of buzzer: on/off. + * @param response operation is success or not. */ @Path("device/{deviceId}/change-status") @POST @@ -119,15 +120,18 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { @QueryParam("state") String state, @Context HttpServletResponse response) { try { - if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId, - DeviceTypeConstants.DEVICE_TYPE))) { - return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + if (!APIUtil.getDeviceAccessAuthorizationService() + .isUserAuthorized(new DeviceIdentifier(deviceId, DeviceTypeConstants.DEVICE_TYPE))) { + return Response.status(Response.Status.UNAUTHORIZED).build(); + } + if (state == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); } String sensorState = state.toUpperCase(); - if (!sensorState.equals(DeviceTypeConstants.STATE_ON) && !sensorState.equals( - DeviceTypeConstants.STATE_OFF)) { + if (!DeviceTypeConstants.STATE_ON.equals(sensorState) + && !sensorState.equals(DeviceTypeConstants.STATE_OFF)) { log.error("The requested state change should be either - 'ON' or 'OFF'"); - return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build(); + return Response.status(Response.Status.BAD_REQUEST).build(); } Map dynamicProperties = new HashMap<>(); String publishTopic = APIUtil.getAuthenticatedUserTenantDomain() @@ -137,19 +141,19 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { dynamicProperties, state); return Response.ok().build(); } catch (DeviceAccessAuthorizationException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + log.error("Unable to change buzzer status", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } } /** - * Retrieve Sensor data for the given time period + * Retrieve Sensor data for the given time period. * - * @param deviceId unique identifier for given device type instance - * @param sensorName name of the sensor - * @param from starting time - * @param to ending time - * @return response with List object which includes sensor data which is requested + * @param deviceId unique identifier for given device type instance. + * @param sensorName name of the sensor. + * @param from starting time. + * @param to ending time. + * @return response with List object which includes sensor data which is requested. */ @Path("device/stats/{deviceId}/sensors/{sensorName}") @GET @@ -174,29 +178,29 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { } try { - if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId, - DeviceTypeConstants.DEVICE_TYPE))) { - return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + if (!APIUtil.getDeviceAccessAuthorizationService() + .isUserAuthorized(new DeviceIdentifier(deviceId, DeviceTypeConstants.DEVICE_TYPE))) { + return Response.status(Response.Status.UNAUTHORIZED).build(); } 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(); + return Response.status(Response.Status.OK).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(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).build(); } catch (DeviceAccessAuthorizationException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + log.error("Unable to get sensor stats", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } } /** - * Remove device type instance using device id + * Remove device type instance using device id. * - * @param deviceId unique identifier for given device type instance + * @param deviceId unique identifier for given device type instance. */ @Path("/device/{deviceId}") @DELETE @@ -206,29 +210,26 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { deviceIdentifier.setId(deviceId); deviceIdentifier.setType(DeviceTypeConstants.DEVICE_TYPE); if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier)) { - return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + return Response.status(Response.Status.UNAUTHORIZED).build(); } boolean removed = APIUtil.getDeviceManagementService().disenrollDevice( deviceIdentifier); if (removed) { return Response.ok().build(); } else { - return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); + return Response.status(Response.Status.NOT_ACCEPTABLE).build(); } - } catch (DeviceManagementException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } catch (DeviceAccessAuthorizationException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } catch (DeviceManagementException | DeviceAccessAuthorizationException e) { + log.error("Unable to remove device", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } /** - * Update device instance name + * Update device instance name. * - * @param deviceId unique identifier for given device type instance - * @param name new name for the device type instance + * @param deviceId unique identifier for given device type instance. + * @param name new name for the device type instance. */ @Path("/device/{deviceId}") @PUT @@ -238,7 +239,7 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { deviceIdentifier.setId(deviceId); deviceIdentifier.setType(DeviceTypeConstants.DEVICE_TYPE); if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier)) { - return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + return Response.status(Response.Status.UNAUTHORIZED).build(); } Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); device.setDeviceIdentifier(deviceId); @@ -249,22 +250,19 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { if (updated) { return Response.ok().build(); } else { - return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build(); + return Response.status(Response.Status.NOT_ACCEPTABLE).build(); } - } catch (DeviceManagementException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } catch (DeviceAccessAuthorizationException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } catch (DeviceManagementException | DeviceAccessAuthorizationException e) { + log.error("Unable to update device", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } } /** - * To get device information + * To get device information. * - * @param deviceId unique identifier for given device type instance - * @return + * @param deviceId unique identifier for given device type instance. + * @return firealarm device. */ @Path("/device/{deviceId}") @GET @@ -276,23 +274,20 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { deviceIdentifier.setId(deviceId); deviceIdentifier.setType(DeviceTypeConstants.DEVICE_TYPE); if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier)) { - return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); + return Response.status(Response.Status.UNAUTHORIZED).build(); } Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier); return Response.ok().entity(device).build(); - } catch (DeviceManagementException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } catch (DeviceAccessAuthorizationException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } catch (DeviceManagementException | DeviceAccessAuthorizationException e) { + log.error("Unable to get device", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } /** - * Get all device type instance which belongs to user + * Get all device type instance which belongs to user. * - * @return Array of devices which includes device's information + * @return Array of devices which includes device's information. */ @Path("/devices") @GET @@ -312,17 +307,17 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { Device[] devices = userDevicesforFirealarm.toArray(new Device[]{}); return Response.ok().entity(devices).build(); } catch (DeviceManagementException e) { - log.error(e.getErrorMessage(), e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + log.error("Unable to get all devices", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } /** - * To download device type agent source code as zip file + * To download device type agent source code as zip file. * - * @param deviceName name for the device type instance - * @param sketchType folder name where device type agent was installed into server - * @return Agent source code as zip file + * @param deviceName name for the device type instance. + * @param sketchType folder name where device type agent was installed into server. + * @return Agent source code as zip file. */ @Path("/device/download") @GET @@ -339,62 +334,58 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { zipFile.getZipFile().delete(); return resp; } catch (IllegalArgumentException ex) { - return Response.status(400).entity(ex.getMessage()).build();//bad request - } catch (DeviceManagementException ex) { - log.error(ex.getMessage(), ex); - return Response.status(500).entity(ex.getMessage()).build(); - } catch (JWTClientException ex) { - log.error(ex.getMessage(), ex); - return Response.status(500).entity(ex.getMessage()).build(); - } catch (APIManagerException ex) { - log.error(ex.getMessage(), ex); - return Response.status(500).entity(ex.getMessage()).build(); - } catch (IOException ex) { - log.error(ex.getMessage(), ex); - return Response.status(500).entity(ex.getMessage()).build(); - } catch (UserStoreException ex) { - log.error(ex.getMessage(), ex); - return Response.status(500).entity(ex.getMessage()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException | JWTClientException | APIManagerException | IOException + | UserStoreException ex) { + log.error("Unable to download sketch", ex); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } } /** - * Register device into device management service + * Register device into device management service. * - * @param deviceId unique identifier for given device type instance - * @param name name for the device type instance - * @return check whether device is installed into cdmf + * @param deviceId unique identifier for given device type instance. + * @param name name for the device type instance. + * @return whether device is installed into cdmf or not. */ - private boolean register(String deviceId, String name) { - try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceId); - deviceIdentifier.setType(DeviceTypeConstants.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(DeviceTypeConstants.DEVICE_TYPE); - enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); - device.setEnrolmentInfo(enrolmentInfo); - boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); - if (added) { - APIUtil.registerApiAccessRoles(APIUtil.getAuthenticatedUser()); - } - return added; - } catch (DeviceManagementException e) { - log.error(e.getMessage(), e); + private boolean register(String deviceId, String name) throws DeviceManagementException { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DeviceTypeConstants.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(DeviceTypeConstants.DEVICE_TYPE); + enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser()); + device.setEnrolmentInfo(enrolmentInfo); + boolean added = APIUtil.getDeviceManagementService().enrollDevice(device); + if (added) { + APIUtil.registerApiAccessRoles(APIUtil.getAuthenticatedUser()); + } + return added; } + /** + * Generates zip archive with the device agent. + * + * @param owner of the device. + * @param deviceName given to the device. + * @param sketchType of the device. + * @return zip archive to download. + * @throws DeviceManagementException + * @throws JWTClientException + * @throws APIManagerException + * @throws UserStoreException + */ private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType) throws DeviceManagementException, JWTClientException, APIManagerException, UserStoreException { @@ -412,8 +403,9 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient(); String scopes = "device_type_" + DeviceTypeConstants.DEVICE_TYPE + " device_" + deviceId; AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), - apiApplicationKey.getConsumerSecret(), owner + "@" + APIUtil.getAuthenticatedUserTenantDomain(), scopes); - + apiApplicationKey.getConsumerSecret(), + owner + "@" + APIUtil.getAuthenticatedUserTenantDomain(), + scopes); //create token String accessToken = accessTokenInfo.getAccessToken(); String refreshToken = accessTokenInfo.getRefreshToken(); @@ -423,9 +415,8 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { throw new DeviceManagementException(msg); } ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), sketchType, - deviceId, deviceName, accessToken, refreshToken); - return zipFile; + return ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), sketchType, + deviceId, deviceName, accessToken, refreshToken); } -} +} diff --git a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/DeviceJSON.java b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/DeviceJSON.java index 0b56aa99..40dcfa4d 100644 --- a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/DeviceJSON.java +++ b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/DeviceJSON.java @@ -28,10 +28,12 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement @JsonIgnoreProperties(ignoreUnknown = true) public class DeviceJSON { + @XmlElement(required = true) public String owner; @XmlElement(required = true) public String deviceId; @XmlElement(required = true) public Float sensorValue; + } diff --git a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/SensorRecord.java b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/SensorRecord.java index 24946d42..12352f27 100644 --- a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/SensorRecord.java +++ b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/dto/SensorRecord.java @@ -82,7 +82,6 @@ public class SensorRecord { valueList.add(entry.getKey() + ":" + entry.getValue()); } return valueList.toString(); - } } diff --git a/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/impl/dao/DeviceTypeDAO.java b/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/impl/dao/DeviceTypeDAO.java index a8d20768..9d3da595 100644 --- a/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/impl/dao/DeviceTypeDAO.java +++ b/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/impl/dao/DeviceTypeDAO.java @@ -20,10 +20,9 @@ package org.homeautomation.firealarm.plugin.impl.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.homeautomation.firealarm.plugin.constants.DeviceTypeConstants; -import org.homeautomation.firealarm.plugin.impl.dao.impl.DeviceTypeDAOImpl; import org.homeautomation.firealarm.plugin.exception.DeviceMgtPluginException; +import org.homeautomation.firealarm.plugin.impl.dao.impl.DeviceTypeDAOImpl; import javax.naming.Context; import javax.naming.InitialContext; @@ -32,6 +31,9 @@ import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; +/** + * Device type data transfer object implementation. + */ public class DeviceTypeDAO { private static final Log log = LogFactory.getLog(DeviceTypeDAO.class); @@ -42,16 +44,24 @@ public class DeviceTypeDAO { initDeviceTypeDAO(); } + /** + * Initialize the device type. + */ public static void initDeviceTypeDAO() { try { Context ctx = new InitialContext(); dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME); } catch (NamingException e) { log.error("Error while looking up the data source: " + - DeviceTypeConstants.DATA_SOURCE_NAME); + DeviceTypeConstants.DATA_SOURCE_NAME); } } + /** + * Begin transactions with data sources. + * + * @throws DeviceMgtPluginException + */ public static void beginTransaction() throws DeviceMgtPluginException { try { Connection conn = dataSource.getConnection(); @@ -62,18 +72,29 @@ public class DeviceTypeDAO { } } + /** + * Get connection to the datasource. + * + * @return the datasource connection. + * @throws DeviceMgtPluginException + */ public static Connection getConnection() throws DeviceMgtPluginException { if (currentConnection.get() == null) { try { currentConnection.set(dataSource.getConnection()); } catch (SQLException e) { throw new DeviceMgtPluginException("Error occurred while retrieving data source connection", - e); + e); } } return currentConnection.get(); } + /** + * Commit transaction after editing. + * + * @throws DeviceMgtPluginException + */ public static void commitTransaction() throws DeviceMgtPluginException { try { Connection conn = currentConnection.get(); @@ -82,7 +103,7 @@ public class DeviceTypeDAO { } else { if (log.isDebugEnabled()) { log.debug("Datasource connection associated with the current thread is null, hence commit " + - "has not been attempted"); + "has not been attempted"); } } } catch (SQLException e) { @@ -92,6 +113,11 @@ public class DeviceTypeDAO { } } + /** + * Close current connection with the datasource. + * + * @throws DeviceMgtPluginException + */ public static void closeConnection() throws DeviceMgtPluginException { Connection con = currentConnection.get(); @@ -105,6 +131,11 @@ public class DeviceTypeDAO { currentConnection.remove(); } + /** + * Rollback transactions to recover from failure. + * + * @throws DeviceMgtPluginException + */ public static void rollbackTransaction() throws DeviceMgtPluginException { try { Connection conn = currentConnection.get(); @@ -113,7 +144,7 @@ public class DeviceTypeDAO { } else { if (log.isDebugEnabled()) { log.debug("Datasource connection associated with the current thread is null, hence rollback " + - "has not been attempted"); + "has not been attempted"); } } } catch (SQLException e) { @@ -123,7 +154,13 @@ public class DeviceTypeDAO { } } + /** + * Get device type specific data object. + * + * @return device type specific data object. + */ public DeviceTypeDAOImpl getDeviceTypeDAO() { return new DeviceTypeDAOImpl(); } -} \ No newline at end of file + +} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs index 91af2442..94411fb2 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs @@ -42,7 +42,6 @@
- {{#zone "bottomJs"}} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js index 299a5b13..c51b47c0 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js @@ -19,24 +19,24 @@ function onRequest(context) { var devices = context.unit.params.devices; var deviceType = context.uriParams.deviceType; - var deviceId = request.getParameter("deviceId"); + var deviceId = request.getParameter('deviceId'); if (devices) { return { - "devices": stringify(devices), - "backendApiUri": devicemgtProps["httpsURL"] + "/firealarm/device/stats/" + 'devices': stringify(devices), + 'backendApiUri': devicemgtProps['httpsURL'] + '/firealarm/device/stats/' }; - } else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { - var deviceModule = require("/app/modules/device.js").deviceModule; + } else if (deviceType && deviceId) { + var deviceModule = require('/app/modules/device.js').deviceModule; var device = deviceModule.viewDevice(deviceType, deviceId); - if (device && device.status != "error") { + if (device && device.status != 'error') { return { - "device": device, - "backendApiUrl": devicemgtProps["httpsURL"] + "/firealarm/device/stats/" + deviceId + "/sensors/" + 'device': device, + 'backendApiUrl': devicemgtProps['httpsURL'] + '/firealarm/device/stats/' + deviceId + '/sensors/' }; } else { - response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); + response.sendError(404, 'Device Id ' + deviceId + ' of type ' + deviceType + ' cannot be found!'); exit(); } } -} \ No newline at end of file +} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js index af8e0c4c..29fa0157 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js @@ -16,15 +16,15 @@ * under the License. */ -var palette = new Rickshaw.Color.Palette({scheme: "classic9"}); +var palette = new Rickshaw.Color.Palette({scheme: 'classic9'}); var graphMap = {}; function drawGraph_firealarm(from, to) { - var devices = $("#firealarm-details").data("devices"); + var devices = $('#firealarm-details').data('devices'); var tzOffset = new Date().getTimezoneOffset() * 60; var streamIndex = 0; - var streams = ["temperature", "humidity"]; + var streams = ['temperature', 'humidity']; populateGraph(); @@ -34,12 +34,12 @@ function drawGraph_firealarm(from, to) { } function clearContent(type) { - $("#y_axis-" + type).html(""); - $("#smoother-" + type).html(""); - $("#legend-" + type).html(""); - $("#chart-" + type).html(""); - $("#x_axis-" + type).html(""); - $("#slider-" + type).html(""); + $('#y_axis-' + type).html(''); + $('#smoother-' + type).html(''); + $('#legend-' + type).html(''); + $('#chart-' + type).html(''); + $('#x_axis-' + type).html(''); + $('#slider-' + type).html(''); } function initGraph(type) { @@ -47,16 +47,16 @@ function drawGraph_firealarm(from, to) { return graphMap[type]; } - var chartWrapperElmId = "#firealarm-div-chart"; + var chartWrapperElmId = '#firealarm-div-chart'; var graphWidth = $(chartWrapperElmId).width() - 50; var graphConfig = { - element: document.getElementById("chart-" + type), + element: document.getElementById('chart-' + type), width: graphWidth, height: 400, strokeWidth: 2, renderer: 'line', - interpolation: "linear", + interpolation: 'linear', unstack: true, stack: false, xScale: d3.time.scale(), @@ -84,7 +84,7 @@ function drawGraph_firealarm(from, to) { x: parseInt(new Date().getTime() / 1000), y: 0 }], - 'name': $("#firealarm-details").data("devicename") + 'name': $('#firealarm-details').data('devicename') }); } @@ -99,7 +99,7 @@ function drawGraph_firealarm(from, to) { var yAxis = new Rickshaw.Graph.Axis.Y({ graph: graph, orientation: 'left', - element: document.getElementById("y_axis-" + type), + element: document.getElementById('y_axis-' + type), width: 40, height: 410 }); @@ -107,12 +107,12 @@ function drawGraph_firealarm(from, to) { var slider = new Rickshaw.Graph.RangeSlider.Preview({ graph: graph, - element: document.getElementById("slider-" + type) + element: document.getElementById('slider-' + type) }); var legend = new Rickshaw.Graph.Legend({ graph: graph, - element: document.getElementById("legend-" + type) + element: document.getElementById('legend-' + type) }); var hoverDetail = new Rickshaw.Graph.HoverDetail({ @@ -122,7 +122,7 @@ function drawGraph_firealarm(from, to) { moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + ''; var swatch = ''; - return swatch + series.name + ": " + parseInt(y) + '
' + date; + return swatch + series.name + ': ' + parseInt(y) + '
' + date; } }); @@ -159,7 +159,7 @@ function drawGraph_firealarm(from, to) { if (devices) { getData(); } else { - var backendApiUrl = $("#firealarm-div-chart").data("backend-api-url") + type + "?from=" + from + "&to=" + to; + var backendApiUrl = $('#firealarm-div-chart').data('backend-api-url') + type + '?from=' + from + '&to=' + to; var successCallback = function (data) { if (data) { drawLineGraph(JSON.parse(data)); @@ -175,8 +175,8 @@ function drawGraph_firealarm(from, to) { if (deviceIndex >= devices.length) { return; } - var backendApiUrl = $("#firealarm-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier - + "/sensors/" + type + "?from=" + from + "&to=" + to; + var backendApiUrl = $('#firealarm-div-chart').data('backend-api-url') + devices[deviceIndex].deviceIdentifier + + '/sensors/' + type + '?from=' + from + '&to=' + to; var successCallback = function (data) { if (data) { drawLineGraph(JSON.parse(data)); @@ -214,10 +214,10 @@ function drawGraph_firealarm(from, to) { function getFieldData(data, type) { var columnData; switch (type) { - case "temperature" : + case 'temperature' : columnData = data.values.temperature; break; - case "humidity" : + case 'humidity' : columnData = data.values.humidity; break; } @@ -225,4 +225,4 @@ function drawGraph_firealarm(from, to) { return columnData; } -} \ No newline at end of file +} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.hbs b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.hbs index 2d9fd3e4..3731ed54 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.hbs +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.hbs @@ -65,4 +65,4 @@ -{{/zone}} \ No newline at end of file +{{/zone}} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.js index b0b65887..445194ff 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.device-view/device-view.js @@ -17,21 +17,25 @@ */ function onRequest(context) { - var log = new Log("device-view.js"); + var deviceType = context.uriParams.deviceType; - var deviceId = request.getParameter("id"); + var deviceId = request.getParameter('id'); var autoCompleteParams = [ - {"name" : "deviceId", "value" : deviceId} + {'name': 'deviceId', 'value': deviceId} ]; - if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { - var deviceModule = require("/app/modules/device.js").deviceModule; + if (deviceType && deviceId) { + var deviceModule = require('/app/modules/device.js').deviceModule; var device = deviceModule.viewDevice(deviceType, deviceId); - if (device && device.status != "error") { - return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/"+deviceType+"/", "autoCompleteParams" : autoCompleteParams}; + if (device && device.status != 'error') { + return { + 'device': device, + 'backendApiUri': devicemgtProps['httpsURL'] + '/' + deviceType + '/', + 'autoCompleteParams': autoCompleteParams + }; } else { - response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); + response.sendError(404, 'Device Id ' + deviceId + ' of type ' + deviceType + ' cannot be found!'); exit(); } } -} \ No newline at end of file +} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.js index b7429e96..286802d0 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.js @@ -19,14 +19,14 @@ function onRequest(context) { var device = context.unit.params.device; var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); - var constants = require("/app/modules/constants.js"); - var websocketEndpoint = devicemgtProps["httpsURL"].replace("https", "wss"); + var constants = require('/app/modules/constants.js'); + var websocketEndpoint = devicemgtProps['httpsURL'].replace('https', 'wss'); var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER); - var token = ""; + var token = ''; if (tokenPair) { - token = tokenPair.accessToken; + token = tokenPair.accessToken; } - websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.firealarm/1.0.0?" + - "token="+ token +"&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type; - return {"device": device, "websocketEndpoint" : websocketEndpoint}; -} \ No newline at end of file + websocketEndpoint = websocketEndpoint + '/secured-outputui/org.wso2.iot.firealarm/1.0.0?' + + 'token=' + token + '&deviceId=' + device.deviceIdentifier + '&deviceType=' + device.type; + return {'device': device, 'websocketEndpoint': websocketEndpoint}; +} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js index d7299ad9..1daf9a4d 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js @@ -24,14 +24,14 @@ var temperatureData = []; var humidity; var humidityData = []; -var palette = new Rickshaw.Color.Palette({scheme: "classic9"}); +var palette = new Rickshaw.Color.Palette({scheme: 'classic9'}); $(window).load(function () { - temperature = lineGraph("temperature", temperatureData); - humidity = lineGraph("humidity", humidityData); + temperature = lineGraph('temperature', temperatureData); + humidity = lineGraph('humidity', humidityData); - var websocketUrl = $("#div-chart").data("websocketurl"); + var websocketUrl = $('#div-chart').data('websocketurl'); connect(websocketUrl) }); @@ -49,10 +49,10 @@ function lineGraph(type, chartData) { } var graph = new Rickshaw.Graph({ - element: document.getElementById("chart-" + type), - width: $("#div-chart").width() - 50, + element: document.getElementById('chart-' + type), + width: $('#div-chart').width() - 50, height: 300, - renderer: "line", + renderer: 'line', padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2}, xScale: d3.time.scale(), series: [{ @@ -83,7 +83,7 @@ function lineGraph(type, chartData) { formatter: function (series, x, y) { var date = '' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + ''; var swatch = ''; - return swatch + series.name + ": " + parseInt(y) + '
' + date; + return swatch + series.name + ': ' + parseInt(y) + '
' + date; } }); diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/moment.min.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/moment.min.js index 78e5aaad..d0b48f73 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/moment.min.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/moment.min.js @@ -1,21 +1,3 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - //! moment.js //! version : 2.10.2 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/private/config.json b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/private/config.json index f9e83e97..5f633261 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/private/config.json +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/private/config.json @@ -1,4 +1,3 @@ - { "deviceType": { "label": "Firealarm", diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/download.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/download.js index c8901643..b6c54b22 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/download.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/download.js @@ -16,10 +16,10 @@ * under the License. */ -var modalPopup = ".wr-modalpopup"; -var modalPopupContainer = modalPopup + " .modalpopup-container"; -var modalPopupContent = modalPopup + " .modalpopup-content"; -var body = "body"; +var modalPopup = '.wr-modalpopup'; +var modalPopupContainer = modalPopup + ' .modalpopup-container'; +var modalPopupContent = modalPopup + ' .modalpopup-content'; +var body = 'body'; /* * set popup maximum height function. @@ -50,9 +50,9 @@ function showPopup() { $('label[for=deviceName]').remove(); } }); - var deviceType = ""; + var deviceType = ''; $('.deviceType').each(function () { - if (this.value != "") { + if (this.value != '') { deviceType = this.value; } }); @@ -81,17 +81,17 @@ function attachEvents() { * when a user clicks on "Download" link * on Device Management page in WSO2 DC Console. */ - $("a.download-link").click(function () { - var sketchType = $(this).data("sketchtype"); - var deviceType = $(this).data("devicetype"); - var downloadDeviceAPI = "/devicemgt/api/devices/sketch/generate_link"; - var payload = {"sketchType": sketchType, "deviceType": deviceType}; + $('a.download-link').click(function () { + var sketchType = $(this).data('sketchtype'); + var deviceType = $(this).data('devicetype'); + var downloadDeviceAPI = '/devicemgt/api/devices/sketch/generate_link'; + var payload = {'sketchType': sketchType, 'deviceType': deviceType}; $(modalPopupContent).html($('#download-device-modal-content').html()); showPopup(); var deviceName; - $("a#download-device-download-link").click(function () { + $('a#download-device-download-link').click(function () { $('.new-device-name').each(function () { - if (this.value != "") { + if (this.value != '') { deviceName = this.value; } }); @@ -121,7 +121,7 @@ function attachEvents() { } }); - $("a#download-device-cancel-link").click(function () { + $('a#download-device-cancel-link').click(function () { hidePopup(); }); }); @@ -130,7 +130,7 @@ function attachEvents() { function downloadAgent() { var deviceName; $('.new-device-name').each(function () { - if (this.value != "") { + if (this.value != '') { deviceName = this.value; } }); @@ -144,8 +144,8 @@ function downloadAgent() { hidePopup(); }, 1000); }else { - $("#invalid-username-error-msg span").text("Invalid device name"); - $("#invalid-username-error-msg").removeClass("hidden"); + $('#invalid-username-error-msg span').text('Invalid device name'); + $('#invalid-username-error-msg').removeClass('hidden'); } } @@ -155,29 +155,29 @@ function doAction(data) { document.write(data); } - if (data.status == "200") { + if (data.status == 200) { $(modalPopupContent).html($('#download-device-modal-content-links').html()); - $("input#download-device-url").val(data.responseText); - $("input#download-device-url").focus(function () { + $('input#download-device-url').val(data.responseText); + $('input#download-device-url').focus(function () { $(this).select(); }); showPopup(); - } else if (data.status == "401") { + } else if (data.status == 401) { $(modalPopupContent).html($('#device-401-content').html()); - $("#device-401-link").click(function () { - window.location = "/devicemgt/login"; + $('#device-401-link').click(function () { + window.location = '/devicemgt/login'; }); showPopup(); - } else if (data == "403") { + } else if (data == 403) { $(modalPopupContent).html($('#device-403-content').html()); - $("#device-403-link").click(function () { - window.location = "/devicemgt/login"; + $('#device-403-link').click(function () { + window.location = '/devicemgt/login'; }); showPopup(); } else { $(modalPopupContent).html($('#device-unexpected-error-content').html()); - $("a#device-unexpected-error-link").click(function () { + $('a#device-unexpected-error-link').click(function () { hidePopup(); }); } -} \ No newline at end of file +} diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/jquery.validate.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/jquery.validate.js index fe7ecf07..70cd4b7f 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/jquery.validate.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.type-view/public/js/jquery.validate.js @@ -1,21 +1,3 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - (function($) { $.extend($.fn, {