diff --git a/modules/samples/watertank/component/analytics/build.xml b/modules/samples/watertank/component/analytics/build.xml
index 3464a310..81e74d0a 100644
--- a/modules/samples/watertank/component/analytics/build.xml
+++ b/modules/samples/watertank/component/analytics/build.xml
@@ -43,4 +43,3 @@
-
diff --git a/modules/samples/watertank/component/analytics/pom.xml b/modules/samples/watertank/component/analytics/pom.xml
index bf13fe6f..704a7513 100644
--- a/modules/samples/watertank/component/analytics/pom.xml
+++ b/modules/samples/watertank/component/analytics/pom.xml
@@ -15,6 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/-->
+
@@ -23,12 +24,14 @@
1.0-SNAPSHOT
../pom.xml
+
4.0.0
${groupId}.watertank.analytics
1.0-SNAPSHOT
pom
${groupId}.watertank.analytics
http://wso2.org
+
@@ -83,4 +86,4 @@
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/analytics/src/assembly/src.xml b/modules/samples/watertank/component/analytics/src/assembly/src.xml
index b7735b0b..1d948164 100644
--- a/modules/samples/watertank/component/analytics/src/assembly/src.xml
+++ b/modules/samples/watertank/component/analytics/src/assembly/src.xml
@@ -33,4 +33,4 @@
true
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_publisher/relay_publisher.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_publisher/relay_publisher.xml
index d4c6e704..182d0796 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_publisher/relay_publisher.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_publisher/relay_publisher.xml
@@ -23,4 +23,3 @@
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_receiver/artifact.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_receiver/artifact.xml
index 98cf9a57..43770b81 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_receiver/artifact.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_receiver/artifact.xml
@@ -2,19 +2,19 @@
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_store/org_wso2_iot_devices_relay.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_store/org_wso2_iot_devices_relay.xml
index 74f2f7c3..2fd5fcf5 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_store/org_wso2_iot_devices_relay.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_store/org_wso2_iot_devices_relay.xml
@@ -59,4 +59,4 @@
BOOLEAN
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/artifact.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/artifact.xml
index 389fd6b3..8d3210bd 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/artifact.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/artifact.xml
@@ -20,4 +20,3 @@
org.wso2.iot.devices.relay_1.0.0.json
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/org.wso2.iot.devices.relay_1.0.0.json b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/org.wso2.iot.devices.relay_1.0.0.json
index 9e6649ca..aef0e923 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/org.wso2.iot.devices.relay_1.0.0.json
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/relay_sensor/relay_stream/org.wso2.iot.devices.relay_1.0.0.json
@@ -28,6 +28,3 @@
}
]
}
-
-
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_store/org_wso2_iot_devices_waterlevel.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_store/org_wso2_iot_devices_waterlevel.xml
index f413f99b..bcb2eb15 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_store/org_wso2_iot_devices_waterlevel.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_store/org_wso2_iot_devices_waterlevel.xml
@@ -59,4 +59,4 @@
FLOAT
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/artifact.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/artifact.xml
index f07f6722..827d0698 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/artifact.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/artifact.xml
@@ -20,4 +20,3 @@
org.wso2.iot.devices.waterlevel_1.0.0.json
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/org.wso2.iot.devices.waterlevel_1.0.0.json b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/org.wso2.iot.devices.waterlevel_1.0.0.json
index 954e05b8..b971ca9e 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/org.wso2.iot.devices.waterlevel_1.0.0.json
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_sensor/waterlevel_stream/org.wso2.iot.devices.waterlevel_1.0.0.json
@@ -28,6 +28,3 @@
}
]
}
-
-
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_execution_pain/org_wso2_iot_devices_waterlevel_summary.siddhiql b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_execution_pain/org_wso2_iot_devices_waterlevel_summary.siddhiql
index 71926d7b..c28448b0 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_execution_pain/org_wso2_iot_devices_waterlevel_summary.siddhiql
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_execution_pain/org_wso2_iot_devices_waterlevel_summary.siddhiql
@@ -15,4 +15,4 @@ define stream waterLevelOutputMapper (meta_owner string, meta_deviceType string,
from waterLevelInputMapper#window.timeBatch(1 min)
select meta_owner, meta_deviceType, meta_deviceId, meta_time, waterlevel, 0.0 as waterLevelMargin, avg(waterlevel) as averageValue
group by meta_owner, meta_deviceType, meta_deviceId, meta_time
-insert into waterLevelOutputMapper;
\ No newline at end of file
+insert into waterLevelOutputMapper;
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_store/org_wso2_iot_devices_waterlevel_summary.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_store/org_wso2_iot_devices_waterlevel_summary.xml
index c2d3ba3b..8af30843 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_store/org_wso2_iot_devices_waterlevel_summary.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_store/org_wso2_iot_devices_waterlevel_summary.xml
@@ -74,4 +74,4 @@
false
EVENT_STORE
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_stream/artifact.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_stream/artifact.xml
index 156063eb..0f6ce9a3 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_stream/artifact.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/waterlevel_summary/waterlevel_summary_stream/artifact.xml
@@ -20,4 +20,3 @@
org.wso2.iot.devices.waterlevel.stats_1.0.0.json
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/artifact.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/artifact.xml
index 8f56540a..bf883c9c 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/artifact.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/artifact.xml
@@ -20,4 +20,3 @@
watertank_execution.siddhiql
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/watertank_execution.siddhiql b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/watertank_execution.siddhiql
index bc39749a..b54f63f6 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/watertank_execution.siddhiql
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_execution/watertank_execution.siddhiql
@@ -21,4 +21,4 @@ insert into relay;
from watertank
select meta_owner, 'watertank' as meta_deviceType, meta_deviceId, time:timestampInMilliseconds() as meta_time, waterlevel
-insert into waterlevel;
\ No newline at end of file
+insert into waterlevel;
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_publisher/watertank_publisher.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_publisher/watertank_publisher.xml
index 45e15756..f0c4a70f 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_publisher/watertank_publisher.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_publisher/watertank_publisher.xml
@@ -23,4 +23,3 @@
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_receiver/watertank_receiver.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_receiver/watertank_receiver.xml
index df75155b..3338a1c3 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_receiver/watertank_receiver.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_receiver/watertank_receiver.xml
@@ -17,16 +17,12 @@
~ under the License.
-->
-
+
carbon.super/watertank/+/data
admin
-
- device_id_json_path:event.metaData.deviceId,device_id_topic_hierarchy_index:2
-
- org.wso2.carbon.device.mgt.iot.input.adapter.mqtt.util.MQTTContentValidator
-
+ device_id_json_path:event.metaData.deviceId,device_id_topic_hierarchy_index:2
+ org.wso2.carbon.device.mgt.iot.input.adapter.mqtt.util.MQTTContentValidator
default
https://localhost:${carbon.https.port}/dynamic-client-web/register
tcp://${mqtt.broker.host}:${mqtt.broker.port}
@@ -35,4 +31,3 @@
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/artifact.xml b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/artifact.xml
index cb98d649..7440e6db 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/artifact.xml
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/artifact.xml
@@ -20,4 +20,3 @@
org.wso2.iot.watertank_1.0.0.json
-
diff --git a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/org.wso2.iot.watertank_1.0.0.json b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/org.wso2.iot.watertank_1.0.0.json
index dd4adb7c..8b9a848e 100644
--- a/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/org.wso2.iot.watertank_1.0.0.json
+++ b/modules/samples/watertank/component/analytics/src/main/resources/carbonapps/watertank/watertank_stream/org.wso2.iot.watertank_1.0.0.json
@@ -23,4 +23,4 @@
"type": "FLOAT"
}
]
-}
\ No newline at end of file
+}
diff --git a/modules/samples/watertank/component/api/pom.xml b/modules/samples/watertank/component/api/pom.xml
index c3d56db6..2750292d 100644
--- a/modules/samples/watertank/component/api/pom.xml
+++ b/modules/samples/watertank/component/api/pom.xml
@@ -165,4 +165,4 @@
provided
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/DeviceTypeService.java b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/DeviceTypeService.java
index 3ad5df0b..1958ef95 100644
--- a/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/DeviceTypeService.java
+++ b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/DeviceTypeService.java
@@ -38,7 +38,6 @@ 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
*/
@@ -118,4 +117,5 @@ interface DeviceTypeService {
@Produces("application/zip")
@Permission(scope = "watertank_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/watertank/component/api/src/main/java/org/homeautomation/watertank/api/DeviceTypeServiceImpl.java b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/DeviceTypeServiceImpl.java
index 2ac6244a..21954a8c 100644
--- a/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/DeviceTypeServiceImpl.java
+++ b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/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 = "watertank", version = "1.0.0", context = "/watertank", tags = "watertank")
@@ -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,26 +89,28 @@ 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
@Consumes(MediaType.APPLICATION_JSON)
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
- * @param onLevel level to turn on the relay
- * @param offLevel level to turn off the relay
- * @param sensorHeight height to water level sensor from bottom of the tank
+ * Update watertank configurations.
+ *
+ * @param deviceId unique identifier for given device type.
+ * @param onLevel level to turn on the relay.
+ * @param offLevel level to turn off the relay.
+ * @param sensorHeight height to water level sensor from bottom of the tank.
*/
@Path("device/{deviceId}/change-levels")
@POST
@@ -125,7 +124,7 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
try {
if (!APIUtil.getDeviceAccessAuthorizationService()
.isUserAuthorized(new DeviceIdentifier(deviceId, DeviceTypeConstants.DEVICE_TYPE))) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
+ return Response.status(Response.Status.UNAUTHORIZED).build();
}
String configs = onLevel + "," + offLevel + "," + sensorHeight;
@@ -137,19 +136,19 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
dynamicProperties, configs);
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 update configs", 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
@@ -170,33 +169,30 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
sensorTableName = DeviceTypeConstants.WATERLEVEL_EVENT_TABLE;
break;
default:
- return Response.status(Response.Status.BAD_REQUEST).entity("Invalid event stream").build();
+ return Response.status(Response.Status.BAD_REQUEST).entity("Invalid event stream name").build();
}
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();
- } catch (AnalyticsException e) {
+ return Response.status(Response.Status.OK).entity(sensorRecords).build();
+ } catch (AnalyticsException | DeviceAccessAuthorizationException e) {
String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
log.error(errorMsg);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).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 +202,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 the device", e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).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 +231,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 +242,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 the 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 device object.
*/
@Path("/device/{deviceId}")
@GET
@@ -276,23 +266,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 the device", e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).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
@@ -302,27 +289,27 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
try {
List userDevices =
APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser());
- ArrayList userDevicesforwatertank = new ArrayList<>();
+ ArrayList waterTankDevices = new ArrayList<>();
for (Device device : userDevices) {
if (device.getType().equals(DeviceTypeConstants.DEVICE_TYPE) &&
device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
- userDevicesforwatertank.add(device);
+ waterTankDevices.add(device);
}
}
- Device[] devices = userDevicesforwatertank.toArray(new Device[]{});
+ Device[] devices = waterTankDevices.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).entity(e.getMessage()).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
@@ -331,70 +318,65 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
@QueryParam("sketchType") String sketchType) {
try {
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
+ zipFile.getZipFile().delete();
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
response.status(Response.Status.OK);
response.type("application/zip");
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
- Response resp = response.build();
- zipFile.getZipFile().delete();
- return resp;
+ return response.build();
} 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 +394,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 +406,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/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/DeviceJSON.java b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/DeviceJSON.java
index 74395100..55a3a237 100644
--- a/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/DeviceJSON.java
+++ b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/DeviceJSON.java
@@ -19,6 +19,7 @@
package org.homeautomation.watertank.api.dto;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -28,10 +29,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/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/SensorRecord.java b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/SensorRecord.java
index c4aa657d..7e0075a4 100644
--- a/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/SensorRecord.java
+++ b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/dto/SensorRecord.java
@@ -38,14 +38,14 @@ public class SensorRecord {
private Map values;
/**
- * Unique identifier for each recode
+ * Unique identifier for each recode.
*/
@XmlElement(required = false, name = "id")
private String id;
/**
* Gets the values.
- * @return the values
+ * @return the values.
*/
public Map getValues() {
return values;
@@ -53,23 +53,23 @@ public class SensorRecord {
/**
* Sets the values.
- * @param values
+ * @param values of the sensor readings.
*/
public void setValues(Map values) {
this.values = values;
}
/**
- * Gets the id.
- * @return the id
+ * Gets the sensor id.
+ * @return the sensor id.
*/
public String getId() {
return id;
}
/**
- * Sets the id.
- * @param id set unique identifier
+ * Sets sensor unique identifier.
+ * @param id of the sensor.
*/
public void setId(String id) {
this.id = id;
@@ -77,12 +77,11 @@ public class SensorRecord {
@Override
public String toString() {
- List valueList = new ArrayList();
+ List valueList = new ArrayList<>();
for (Map.Entry entry : values.entrySet()) {
valueList.add(entry.getKey() + ":" + entry.getValue());
}
return valueList.toString();
-
}
}
diff --git a/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/exception/DeviceTypeException.java b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/exception/DeviceTypeException.java
index c4d4f3d8..c452dd75 100644
--- a/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/exception/DeviceTypeException.java
+++ b/modules/samples/watertank/component/api/src/main/java/org/homeautomation/watertank/api/exception/DeviceTypeException.java
@@ -1,23 +1,26 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.
*/
package org.homeautomation.watertank.api.exception;
+/**
+ * Wraps device type specific exceptions
+ */
public class DeviceTypeException extends Exception {
private static final long serialVersionUID = 2736466563251105441L;
@@ -54,4 +57,5 @@ public class DeviceTypeException extends Exception {
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
+
}
diff --git a/modules/samples/watertank/component/api/src/main/webapp/META-INF/permissions.xml b/modules/samples/watertank/component/api/src/main/webapp/META-INF/permissions.xml
index a1d3123f..665aadfb 100644
--- a/modules/samples/watertank/component/api/src/main/webapp/META-INF/permissions.xml
+++ b/modules/samples/watertank/component/api/src/main/webapp/META-INF/permissions.xml
@@ -84,4 +84,4 @@
GET
watertank_device
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/api/src/main/webapp/META-INF/webapp-classloading.xml b/modules/samples/watertank/component/api/src/main/webapp/META-INF/webapp-classloading.xml
index fa446191..41e48ccb 100644
--- a/modules/samples/watertank/component/api/src/main/webapp/META-INF/webapp-classloading.xml
+++ b/modules/samples/watertank/component/api/src/main/webapp/META-INF/webapp-classloading.xml
@@ -17,7 +17,8 @@
-->
@@ -25,9 +26,9 @@
false
CXF,Carbon
diff --git a/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/cxf-servlet.xml b/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/cxf-servlet.xml
index 5a222d12..9c7fa85c 100644
--- a/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -33,4 +33,4 @@
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/web.xml b/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/web.xml
index 612804f2..848017d2 100644
--- a/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/web.xml
+++ b/modules/samples/watertank/component/api/src/main/webapp/WEB-INF/web.xml
@@ -1,9 +1,28 @@
+
+
+
WSO2 IoT Server
WSO2 IoT Server
@@ -43,4 +62,4 @@
admin
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/plugin/pom.xml b/modules/samples/watertank/component/plugin/pom.xml
index 0f2d1a08..a9659abe 100644
--- a/modules/samples/watertank/component/plugin/pom.xml
+++ b/modules/samples/watertank/component/plugin/pom.xml
@@ -130,4 +130,4 @@
org.wso2.carbon.event.output.adapter.core
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/constants/DeviceTypeConstants.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/constants/DeviceTypeConstants.java
index 79ca70e0..f2bb8e0d 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/constants/DeviceTypeConstants.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/constants/DeviceTypeConstants.java
@@ -21,12 +21,14 @@ package org.homeautomation.watertank.plugin.constants;
import org.wso2.carbon.utils.CarbonUtils;
import java.io.File;
+/**
+ * Device type specific constants.
+ */
public class DeviceTypeConstants {
+
public final static String DEVICE_TYPE = "watertank";
public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME";
public final static String DEVICE_PLUGIN_DEVICE_ID = "watertank_DEVICE_ID";
- public final static String STATE_ON = "ON";
- public final static String STATE_OFF = "OFF";
//sensor events summarized table name
public final static String STREAM_RELAY = "relay";
@@ -60,4 +62,3 @@ public class DeviceTypeConstants {
public static final String MQTT_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator
+ "mqtt.properties";
}
-
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/exception/DeviceMgtPluginException.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/exception/DeviceMgtPluginException.java
index 5f5283c7..dfd6b13f 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/exception/DeviceMgtPluginException.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/exception/DeviceMgtPluginException.java
@@ -18,6 +18,9 @@
package org.homeautomation.watertank.plugin.exception;
+/**
+ * Custom exception implementation to wrap device management plugin related errors.
+ */
public class DeviceMgtPluginException extends Exception {
private String errorMessage;
@@ -53,4 +56,4 @@ public class DeviceMgtPluginException extends Exception {
this.errorMessage = errorMessage;
}
-}
\ No newline at end of file
+}
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManager.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManager.java
index 4423afb3..f4b6b16b 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManager.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManager.java
@@ -18,10 +18,11 @@
package org.homeautomation.watertank.plugin.impl;
+import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.homeautomation.watertank.plugin.impl.dao.DeviceTypeDAO;
import org.homeautomation.watertank.plugin.exception.DeviceMgtPluginException;
+import org.homeautomation.watertank.plugin.impl.dao.DeviceTypeDAO;
import org.homeautomation.watertank.plugin.impl.feature.DeviceTypeFeatureManager;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@@ -104,7 +105,7 @@ public class DeviceTypeManager implements DeviceManager {
log.warn(msg, iotDAOEx);
}
String msg = "Error while updating the enrollment of the watertank device : " +
- device.getDeviceIdentifier();
+ device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
@@ -149,7 +150,7 @@ public class DeviceTypeManager implements DeviceManager {
}
} catch (DeviceMgtPluginException e) {
String msg = "Error while checking the enrollment status of watertank device : " +
- deviceId.getId();
+ deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
@@ -164,7 +165,8 @@ public class DeviceTypeManager implements DeviceManager {
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException {
- return true;
+ //Status is not implemented for this device type.
+ throw new NotImplementedException();
}
@Override
@@ -186,7 +188,8 @@ public class DeviceTypeManager implements DeviceManager {
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException {
- return true;
+ //Ownership changing is not implemented for this device type.
+ throw new NotImplementedException();
}
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
@@ -196,17 +199,20 @@ public class DeviceTypeManager implements DeviceManager {
@Override
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
EnrolmentInfo.Status status) throws DeviceManagementException {
- return false;
+ //Status is not implemented for this device type.
+ throw new NotImplementedException();
}
@Override
public License getLicense(String s) throws LicenseManagementException {
- return null;
+ //License is not implemented for this device type.
+ throw new NotImplementedException();
}
@Override
public void addLicense(License license) throws LicenseManagementException {
-
+ //License is not implemented for this device type.
+ throw new NotImplementedException();
}
@Override
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManagerService.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManagerService.java
index 4f4fb04f..a874aa9d 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManagerService.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/DeviceTypeManagerService.java
@@ -19,14 +19,15 @@
package org.homeautomation.watertank.plugin.impl;
import org.homeautomation.watertank.plugin.constants.DeviceTypeConstants;
-import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
+import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
public class DeviceTypeManagerService implements DeviceManagementService {
+
private DeviceManager deviceManager;
@Override
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/DeviceTypeDAO.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/DeviceTypeDAO.java
index bfb32394..92c052d6 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/DeviceTypeDAO.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/DeviceTypeDAO.java
@@ -32,6 +32,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,6 +45,9 @@ public class DeviceTypeDAO {
initDeviceTypeDAO();
}
+ /**
+ * Initialize the device type.
+ */
public static void initDeviceTypeDAO() {
try {
Context ctx = new InitialContext();
@@ -52,6 +58,11 @@ public class DeviceTypeDAO {
}
}
+ /**
+ * Begin transactions with data sources.
+ *
+ * @throws DeviceMgtPluginException
+ */
public static void beginTransaction() throws DeviceMgtPluginException {
try {
Connection conn = dataSource.getConnection();
@@ -62,6 +73,12 @@ 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 {
@@ -74,6 +91,11 @@ public class DeviceTypeDAO {
return currentConnection.get();
}
+ /**
+ * Commit transaction after editing.
+ *
+ * @throws DeviceMgtPluginException
+ */
public static void commitTransaction() throws DeviceMgtPluginException {
try {
Connection conn = currentConnection.get();
@@ -92,6 +114,11 @@ public class DeviceTypeDAO {
}
}
+ /**
+ * Close current connection with the datasource.
+ *
+ * @throws DeviceMgtPluginException
+ */
public static void closeConnection() throws DeviceMgtPluginException {
Connection con = currentConnection.get();
@@ -105,6 +132,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();
@@ -123,6 +155,11 @@ public class DeviceTypeDAO {
}
}
+ /**
+ * Get device type specific data object.
+ *
+ * @return device type specific data object.
+ */
public DeviceTypeDAOImpl getDeviceTypeDAO() {
return new DeviceTypeDAOImpl();
}
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/impl/DeviceTypeDAOImpl.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/impl/DeviceTypeDAOImpl.java
index 24e7e3c6..67bbaaf4 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/impl/DeviceTypeDAOImpl.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/dao/impl/DeviceTypeDAOImpl.java
@@ -43,16 +43,22 @@ public class DeviceTypeDAOImpl {
private static final Log log = LogFactory.getLog(DeviceTypeDAOImpl.class);
+ /**
+ * Get device from the database.
+ *
+ * @param deviceId to retive the device.
+ * @return device object.
+ * @throws DeviceMgtPluginException
+ */
public Device getDevice(String deviceId) throws DeviceMgtPluginException {
- Connection conn = null;
+ Connection conn;
PreparedStatement stmt = null;
Device iotDevice = null;
ResultSet resultSet = null;
try {
conn = DeviceTypeDAO.getConnection();
String selectDBQuery =
- "SELECT watertank_DEVICE_ID, DEVICE_NAME" +
- " FROM watertank_DEVICE WHERE watertank_DEVICE_ID = ?";
+ "SELECT watertank_DEVICE_ID, DEVICE_NAME FROM watertank_DEVICE WHERE watertank_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
resultSet = stmt.executeQuery();
@@ -77,6 +83,13 @@ public class DeviceTypeDAOImpl {
return iotDevice;
}
+ /**
+ * Add new device.
+ *
+ * @param device to be added.
+ * @return added or not.
+ * @throws DeviceMgtPluginException
+ */
public boolean addDevice(Device device) throws DeviceMgtPluginException {
boolean status = false;
Connection conn;
@@ -107,9 +120,16 @@ public class DeviceTypeDAOImpl {
return status;
}
+ /**
+ * Update existing device.
+ *
+ * @param device to be updated.
+ * @return updated or not.
+ * @throws DeviceMgtPluginException
+ */
public boolean updateDevice(Device device) throws DeviceMgtPluginException {
boolean status = false;
- Connection conn = null;
+ Connection conn;
PreparedStatement stmt = null;
try {
conn = DeviceTypeDAO.getConnection();
@@ -140,14 +160,20 @@ public class DeviceTypeDAOImpl {
return status;
}
+ /**
+ * Delete device.
+ *
+ * @param deviceId of the device to be deleted.
+ * @return deleted or not.
+ * @throws DeviceMgtPluginException
+ */
public boolean deleteDevice(String deviceId) throws DeviceMgtPluginException {
boolean status = false;
- Connection conn = null;
+ Connection conn;
PreparedStatement stmt = null;
try {
conn = DeviceTypeDAO.getConnection();
- String deleteDBQuery =
- "DELETE FROM watertank_DEVICE WHERE watertank_DEVICE_ID = ?";
+ String deleteDBQuery = "DELETE FROM watertank_DEVICE WHERE watertank_DEVICE_ID = ?";
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setString(1, deviceId);
int rows = stmt.executeUpdate();
@@ -168,8 +194,14 @@ public class DeviceTypeDAOImpl {
return status;
}
+ /**
+ * Get all watertank devices.
+ *
+ * @return list of devices.
+ * @throws DeviceMgtPluginException
+ */
public List getAllDevices() throws DeviceMgtPluginException {
- Connection conn = null;
+ Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
Device device;
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/feature/DeviceTypeFeatureManager.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/feature/DeviceTypeFeatureManager.java
index bd1ecb97..f42b3bf3 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/feature/DeviceTypeFeatureManager.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/feature/DeviceTypeFeatureManager.java
@@ -15,6 +15,7 @@
*/
package org.homeautomation.watertank.plugin.impl.feature;
+import org.apache.commons.lang.NotImplementedException;
import org.homeautomation.watertank.plugin.constants.DeviceTypeConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature;
@@ -26,12 +27,14 @@ import java.util.List;
public class DeviceTypeFeatureManager implements FeatureManager {
@Override
public boolean addFeature(Feature feature) throws DeviceManagementException {
- return false;
+ //Features are not used for this device type.
+ throw new NotImplementedException();
}
@Override
public boolean addFeatures(List features) throws DeviceManagementException {
- return false;
+ //Features are not used for this device type.
+ throw new NotImplementedException();
}
@Override
@@ -48,7 +51,8 @@ public class DeviceTypeFeatureManager implements FeatureManager {
@Override
public boolean removeFeature(String name) throws DeviceManagementException {
- return false;
+ //Features are not used for this device type.
+ throw new NotImplementedException();
}
@Override
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceSchemaInitializer.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceSchemaInitializer.java
index 512d63a6..45779375 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceSchemaInitializer.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceSchemaInitializer.java
@@ -28,22 +28,23 @@ import java.io.File;
/**
* Provides methods for initializing the database script.
*/
-public class DeviceSchemaInitializer extends DatabaseCreator{
+public class DeviceSchemaInitializer extends DatabaseCreator {
- private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
- private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
- + File.separator + "cdm" + File.separator + "plugins" + File.separator;
+ private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
+ private static final String setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
+ + File.separator + "cdm" + File.separator + "plugins"
+ + File.separator;
- public DeviceSchemaInitializer(DataSource dataSource) {
- super(dataSource);
- }
+ public DeviceSchemaInitializer(DataSource dataSource) {
+ super(dataSource);
+ }
- @Override
- protected String getDbScriptLocation(String databaseType) {
- String scriptName = databaseType + ".sql";
- if (log.isDebugEnabled()) {
- log.debug("Loading database script from :" + scriptName);
- }
- return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
- }
+ @Override
+ protected String getDbScriptLocation(String databaseType) {
+ String scriptName = databaseType + ".sql";
+ if (log.isDebugEnabled()) {
+ log.debug("Loading database script from :" + scriptName);
+ }
+ return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
+ }
}
diff --git a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceTypeUtils.java b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceTypeUtils.java
index a69aa5b3..bc9afc5b 100644
--- a/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceTypeUtils.java
+++ b/modules/samples/watertank/component/plugin/src/main/java/org/homeautomation/watertank/plugin/impl/util/DeviceTypeUtils.java
@@ -18,11 +18,11 @@
package org.homeautomation.watertank.plugin.impl.util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.homeautomation.watertank.plugin.constants.DeviceTypeConstants;
import org.homeautomation.watertank.plugin.exception.DeviceMgtPluginException;
import org.homeautomation.watertank.plugin.internal.DeviceTypeManagementDataHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.Utils;
@@ -52,7 +52,7 @@ public class DeviceTypeUtils {
private static Log log = LogFactory.getLog(DeviceTypeUtils.class);
- public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
+ private static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
@@ -95,24 +95,26 @@ public class DeviceTypeUtils {
log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
} catch (Exception e) {
throw new DeviceMgtPluginException("Error occurred while initializing Iot Device " +
- "Management database schema", e);
+ "Management database schema", e);
}
}
public static String replaceMqttProperty(String urlWithPlaceholders) {
String MQTT_BROKER_HOST = null;
String MQTT_PORT = null;
- if(!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")){
+ if (!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")) {
MQTT_BROKER_HOST = "\\$".concat(DeviceTypeConstants.MQTT_BROKER_HOST);
}
- if(!DeviceTypeConstants.MQTT_PORT.startsWith("$")){
+ if (!DeviceTypeConstants.MQTT_PORT.startsWith("$")) {
MQTT_PORT = "\\$".concat(DeviceTypeConstants.MQTT_PORT);
}
urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders);
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_PORT, "" +
- (DeviceTypeConstants.DEFAULT_MQTT_PORT + getPortOffset()));
+ (DeviceTypeConstants.DEFAULT_MQTT_PORT
+ + getPortOffset()));
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_BROKER_HOST,
- System.getProperty(DeviceTypeConstants.DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost"));
+ System.getProperty(DeviceTypeConstants.DEFAULT_CARBON_LOCAL_IP_PROPERTY,
+ "localhost"));
return urlWithPlaceholders;
}
@@ -131,10 +133,10 @@ public class DeviceTypeUtils {
}
}
- public static void setupMqttOutputAdapter() throws IOException {
+ static void setupMqttOutputAdapter() throws IOException {
OutputEventAdapterConfiguration outputEventAdapterConfiguration =
createMqttOutputEventAdapterConfiguration(DeviceTypeConstants.MQTT_ADAPTER_NAME,
- DeviceTypeConstants.MQTT_ADAPTER_TYPE, MessageType.TEXT);
+ DeviceTypeConstants.MQTT_ADAPTER_TYPE, MessageType.TEXT);
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
@@ -157,7 +159,8 @@ public class DeviceTypeUtils {
* @return OutputEventAdapterConfiguration instance for given configuration
*/
private static OutputEventAdapterConfiguration createMqttOutputEventAdapterConfiguration(String name, String type,
- String msgFormat) throws IOException {
+ String msgFormat)
+ throws IOException {
OutputEventAdapterConfiguration outputEventAdapterConfiguration = new OutputEventAdapterConfiguration();
outputEventAdapterConfiguration.setName(name);
outputEventAdapterConfiguration.setType(type);
diff --git a/modules/samples/watertank/component/pom.xml b/modules/samples/watertank/component/pom.xml
index 52befd69..87109c10 100644
--- a/modules/samples/watertank/component/pom.xml
+++ b/modules/samples/watertank/component/pom.xml
@@ -1,21 +1,22 @@
-
+
+
@@ -53,4 +54,4 @@
ui
analytics
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/ui/pom.xml b/modules/samples/watertank/component/ui/pom.xml
index 9b6a6d42..28de3b95 100644
--- a/modules/samples/watertank/component/ui/pom.xml
+++ b/modules/samples/watertank/component/ui/pom.xml
@@ -16,6 +16,7 @@
~ specific language governing permissions and limitations
~ under the License.
-->
+
@@ -53,4 +54,4 @@
-
\ No newline at end of file
+
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/analytics-view.js b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/analytics-view.js
index 9a6b1620..b0721f26 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/analytics-view.js
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/analytics-view.js
@@ -19,23 +19,23 @@
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"] + "/watertank/device/stats/"
+ 'devices': stringify(devices),
+ 'backendApiUri': devicemgtProps['httpsURL'] + '/watertank/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"] + "/watertank/device/stats/" + deviceId + "/sensors/"
+ 'device': device,
+ 'backendApiUrl': devicemgtProps['httpsURL'] + '/watertank/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();
}
}
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/public/js/watertank.js b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/public/js/watertank.js
index a92554f8..bfb10015 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/public/js/watertank.js
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.analytics-view/public/js/watertank.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_watertank(from, to) {
- var devices = $("#watertank-details").data("devices");
+ var devices = $('#watertank-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_watertank(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_watertank(from, to) {
return graphMap[type];
}
- var chartWrapperElmId = "#watertank-div-chart";
+ var chartWrapperElmId = '#watertank-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_watertank(from, to) {
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
- 'name': $("#watertank-details").data("devicename")
+ 'name': $('#watertank-details').data('devicename')
});
}
@@ -99,7 +99,7 @@ function drawGraph_watertank(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_watertank(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_watertank(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_watertank(from, to) {
if (devices) {
getData();
} else {
- var backendApiUrl = $("#watertank-div-chart").data("backend-api-url") + type + "?from=" + from + "&to=" + to;
+ var backendApiUrl = $('#watertank-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_watertank(from, to) {
if (deviceIndex >= devices.length) {
return;
}
- var backendApiUrl = $("#watertank-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
- + "/sensors/" + type + "?from=" + from + "&to=" + to;
+ var backendApiUrl = $('#watertank-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_watertank(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_watertank(from, to) {
return columnData;
}
-}
\ No newline at end of file
+}
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.device-view/device-view.js b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.device-view/device-view.js
index 422e9002..6262ee17 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.device-view/device-view.js
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.device-view/device-view.js
@@ -17,24 +17,24 @@
*/
function onRequest(context) {
- var log = new Log("cdmf.unit.device.type.watertank.device-view.js");
+ var log = new Log('cdmf.unit.device.type.watertank.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") {
+ if (device && device.status != 'error') {
return {
- "device": device,
- "backendApiUri": devicemgtProps["httpsURL"] + "/" + deviceType + "/",
- "autoCompleteParams": autoCompleteParams
+ '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();
}
}
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/analytics-view.hbs b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/analytics-view.hbs
index 2e31a33c..18c2a2c7 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/analytics-view.hbs
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/analytics-view.hbs
@@ -1,26 +1,19 @@
{{unit "cdmf.unit.lib.handlebars"}}
{{#zone "topCss"}}
- {{css "css/coffee.css"}}
+ {{css "css/water-level.css"}}
{{/zone}}
-
-
-
-
-
-
-
+
@@ -34,5 +27,4 @@
{{js "js/moment.min.js"}}
{{js "js/socket.io.min.js"}}
{{js "js/device-stats.js"}}
- {{js "js/coffee.js"}}
{{/zone}}
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/analytics-view.js b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/analytics-view.js
index d231140b..e79125f2 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/analytics-view.js
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.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;
}
- websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.watertank/1.0.0?" +
- "token=" + token + "&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type;
- return {"device": device, "websocketEndpoint": websocketEndpoint};
+ websocketEndpoint = websocketEndpoint + '/secured-outputui/org.wso2.iot.watertank/1.0.0?' +
+ 'token=' + token + '&deviceId=' + device.deviceIdentifier + '&deviceType=' + device.type;
+ return {'device': device, 'websocketEndpoint': websocketEndpoint};
}
\ No newline at end of file
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/css/coffee.css b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/css/water-level.css
similarity index 92%
rename from modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/css/coffee.css
rename to modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/css/water-level.css
index fc5790a3..6496a98f 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/css/coffee.css
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/css/water-level.css
@@ -25,7 +25,6 @@ input[type=range][orient=vertical]
padding: 0 5px;
}
-
.left-pane{
float: left;
width: 30%;
@@ -37,10 +36,10 @@ input[type=range][orient=vertical]
background-color: rgba(204, 204, 204, 0.61);
width: 70%;
}
-.coffee-wrapper{
+.water-level-wrapper{
margin: 50px;
}
-.coffee-top{
+.water-level-top{
position: absolute;
bottom: 10px;
height: 30px;
@@ -48,7 +47,7 @@ input[type=range][orient=vertical]
z-index: 99;
background-color: aquamarine;
}
-.coffee-bottom{
+.water-level-bottom{
position: absolute;
bottom: 0px;
height: 10px;
@@ -85,21 +84,21 @@ input[type=range][orient=vertical]
background: rgba(204, 204, 204, 0.3);
}
-.coffee-wrapper *:before, .coffee-wrapper *:after {
+.water-level-wrapper *:before, .water-level-wrapper *:after {
content: '';
display: block;
position: absolute;
}
-.coffee {
+.water-level {
display: inline-block;
position: relative;
width: 300px;
margin: 0 20px 50px 0;
}
-.coffee:after {
+.water-level:after {
height: 14px;
width: 300px;
border-radius: 46px/10px;
@@ -108,7 +107,7 @@ input[type=range][orient=vertical]
z-index: 0;
}
-.coffee:before {
+.water-level:before {
height: 14px;
width: 300px;
border-radius: 46px/10px;
@@ -117,7 +116,7 @@ input[type=range][orient=vertical]
z-index: 0;
}
-.coffee_main {
+.water-level_main {
height: 300px;
position: relative;
width: 298px;
@@ -127,7 +126,7 @@ input[type=range][orient=vertical]
border-bottom: none;
}
-.coffee_main:after, .coffee_main:before {
+.water-level_main:after, .water-level_main:before {
height: 12px;
width: 296px;
border-radius: 46px/10px;
@@ -137,17 +136,17 @@ input[type=range][orient=vertical]
left: -1px;
}
-.coffee_main:after {
+.water-level_main:after {
top: -7px;
box-shadow: 0px 0px 6px rgba(255, 255, 255, 0.6) inset, 0px 3px 3px -1px rgba(255, 255, 255, 0.4), 0px 0px 3px rgba(0, 0, 0, 0.05) inset, 0px 0px 6px rgba(255, 255, 255, 0.7) inset, 0px 0px 3px rgba(0, 0, 0, 0.15) inset;
}
-.coffee_main:before {
+.water-level_main:before {
top: 294px;
box-shadow: 0px 0px 6px rgba(255, 255, 255, 0.7) inset, 0px 0px 3px rgba(0, 0, 0, 0.15) inset;
}
-.coffee_mouth {
+.water-level_mouth {
height: 52px;
width: 44px;
margin: 0px auto;
@@ -160,7 +159,7 @@ input[type=range][orient=vertical]
box-shadow: 0px 0px 6px rgba(255, 255, 255, 0.3);
}
-.coffee_mouth:after {
+.water-level_mouth:after {
height: 6px;
width: 44px;
border-radius: 25px/6px;
@@ -171,7 +170,7 @@ input[type=range][orient=vertical]
box-shadow: 0px 0px 3px rgba(255, 255, 255, 0.3);
}
-.coffee_inner {
+.water-level_inner {
height: 295px;
width: 92%;
margin: 0px auto;
@@ -185,7 +184,7 @@ input[type=range][orient=vertical]
top: 1px;
}
-.coffee_inner:before {
+.water-level_inner:before {
border-radius: 40px/4px;
top: 140px;
width: 90%;
@@ -193,7 +192,7 @@ input[type=range][orient=vertical]
height: 9px;
}
-.coffee_top .highlight {
+.water-level_top .highlight {
display: block;
height: 30px;
width: 20px;
@@ -204,7 +203,7 @@ input[type=range][orient=vertical]
background: linear-gradient(to right, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.6) 4%, rgba(255, 255, 255, 0.2) 98%, rgba(255, 255, 255, 0));
}
-.coffee_top .highlight:after {
+.water-level_top .highlight:after {
height: 30px;
width: 2px;
left: -3px;
@@ -213,7 +212,7 @@ input[type=range][orient=vertical]
background: rgba(255, 255, 255, 0.3);
}
-.coffee_main .highlight {
+.water-level_main .highlight {
display: block;
height: 301px;
width: 25px;
@@ -225,7 +224,7 @@ input[type=range][orient=vertical]
z-index: 2;
}
-.coffee_main .highlight:after {
+.water-level_main .highlight:after {
height: 150px;
width: 4px;
left: -6px;
@@ -234,7 +233,7 @@ input[type=range][orient=vertical]
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 80%);
}
-.coffee_neck .highlight {
+.water-level_neck .highlight {
display: block;
height: 20px;
width: 25px;
@@ -288,4 +287,7 @@ input[type=range][orient=vertical]
transition: all 3s ease-out;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
+ text-align: center;
+ font-weight: bold;
+ font-size: 30px;
}
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/coffee.js b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/coffee.js
deleted file mode 100644
index 1f51cfce..00000000
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/coffee.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.
- */
-
-var temperature = 0;
-var coffee_amount = 0;
-
-function updateCoffee(newValue){
- //var coffee_level = document.getElementById("coffee_level");
- //coffee_level.innerHTML = newValue + "%";
- coffee_amount =newValue;
-
- var coffee = document.getElementById("water");
- if(newValue == 0){
- coffee.style.height= (newValue*3) + 'px';
- }else{
- coffee.style.height= (newValue*3) - 3 + 'px';
- }
-}
-
-function updateTemperature(newValue){
- temperature = newValue;
- var temperature_level = document.getElementById("temperature_level");
- temperature_level.innerHTML = newValue + " C";
-}
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/device-stats.js b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/device-stats.js
index 484c1379..d898fe08 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/device-stats.js
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/device-stats.js
@@ -18,75 +18,15 @@
var ws;
-var temperature;
-var temperatureData = [];
-
-var humidity;
-var humidityData = [];
-
-//var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
-
$(window).load(function () {
- var websocketUrl = $("#div-chart").data("websocketurl");
+ var websocketUrl = $('#div-chart').data('websocketurl');
connect(websocketUrl);
- updateCoffee(20);
});
$(window).unload(function () {
disconnect();
});
-//function lineGraph(type, chartData) {
-// var tNow = new Date().getTime() / 1000;
-// for (var i = 0; i < 30; i++) {
-// chartData.push({
-// x: tNow - (30 - i) * 15,
-// y: parseFloat(0)
-// });
-// }
-//
-// var graph = new Rickshaw.Graph({
-// element: document.getElementById("chart-" + type),
-// width: $("#div-chart").width() - 50,
-// height: 300,
-// renderer: "line",
-// padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2},
-// xScale: d3.time.scale(),
-// series: [{
-// 'color': palette.color(),
-// 'data': chartData,
-// 'name': type && type[0].toUpperCase() + type.slice(1)
-// }]
-// });
-//
-// graph.render();
-//
-// var xAxis = new Rickshaw.Graph.Axis.Time({
-// graph: graph
-// });
-//
-// xAxis.render();
-//
-// new Rickshaw.Graph.Axis.Y({
-// graph: graph,
-// orientation: 'left',
-// height: 300,
-// tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
-// element: document.getElementById('y_axis-' + type)
-// });
-//
-// new Rickshaw.Graph.HoverDetail({
-// graph: graph,
-// 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 graph;
-//}
-
//websocket connection
function connect(target) {
if ('WebSocket' in window) {
@@ -100,21 +40,27 @@ function connect(target) {
ws.onmessage = function (event) {
var dataPoint = JSON.parse(event.data);
if (dataPoint) {
- var time = parseInt(dataPoint[0]) / 1000;
- graphUpdate(temperatureData, time, dataPoint[3], temperature);
- graphUpdate(humidityData, time, dataPoint[4], humidity);
+ updateWaterLevel(dataPoint[4]);
}
};
}
}
-function graphUpdate(chartData, xValue, yValue, graph) {
- updateCoffee(xValue);
-}
-
function disconnect() {
if (ws != null) {
ws.close();
ws = null;
}
}
+
+function updateWaterLevel(newValue) {
+ var waterLevel = document.getElementById('water');
+ waterLevel.innerHTML = (newValue | 0) + '%';
+ if (newValue == 0) {
+ waterLevel.style.height = (newValue * 3) + 'px';
+ waterLevel.style.paddingTop = 0;
+ } else {
+ waterLevel.style.height = (newValue * 3) - 3 + 'px';
+ waterLevel.style.paddingTop = (newValue * 3 / 2.4) - 10 + 'px';
+ }
+}
\ No newline at end of file
diff --git a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/libs/htmlpreview.min.js b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/libs/htmlpreview.min.js
index 58db9038..97bb17d0 100644
--- a/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/libs/htmlpreview.min.js
+++ b/modules/samples/watertank/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.watertank.realtime.analytics-view/public/js/libs/htmlpreview.min.js
@@ -1,19 +1 @@
-/*
- * 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.
- */
-
var HTMLPreview={content:"",previewform:document.getElementById("previewform"),file:function(){return location.search.substring(1)},raw:function(){return HTMLPreview.file().replace(/\/\/github\.com/,"//raw.githubusercontent.com").replace(/\/blob\//,"/")},replaceAssets:function(){var a,b,c;a=document.querySelectorAll("iframe[src],frame[src]");for(b=0;ba[b].innerHTML.indexOf("HTMLPreview")&&document.write(a[b].outerHTML)}},loadHTML:function(a){a&&a.query&&a.query.diagnostics&&a.query.diagnostics.redirect?HTMLPreview.send(a.query.diagnostics.redirect.content,"loadHTML"):a&&a.query&&a.query.results&&a.query.results.resources&&a.query.results.resources.content&&200==a.query.results.resources.status?(HTMLPreview.content=a.query.results.resources.content.replace(//i,'').replace(/<\/body>/i,'