From 2d6aa46ca2252123b9f7b36343ad8283da34a9d6 Mon Sep 17 00:00:00 2001 From: charithag Date: Tue, 1 Dec 2015 13:37:22 +0530 Subject: [PATCH] Add iot related stuffs --- .../pom.xml | 11 + .../src/main/resources/conf/iot-config.xml | 7 +- .../public/js/device-details.js | 266 ++++++++++++++++++ .../app/units/iot.unit.device.stats/stats.hbs | 101 +++++++ .../app/units/iot.unit.device.stats/stats.js | 3 + .../units/iot.unit.device.stats/stats.json | 3 + .../firealarm-overview.hbs | 36 +++ .../firealarm-overview.js | 25 ++ .../firealarm-overview.json | 3 + .../src/main/resources/p2.inf | 4 +- 10 files changed, 454 insertions(+), 5 deletions(-) create mode 100644 features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/public/js/device-details.js create mode 100644 features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.hbs create mode 100644 features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.js create mode 100644 features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.json create mode 100644 features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.hbs create mode 100644 features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.js create mode 100644 features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.json diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml index e5f2ff4900..bf37e192e1 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/pom.xml @@ -40,10 +40,12 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + provided org.apache.axis2.wso2 @@ -55,6 +57,7 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.analytics + provided org.apache.axis2.wso2 @@ -66,6 +69,7 @@ org.wso2.carbon.devicemgt org.wso2.carbon.certificate.mgt.core + provided commons-codec.wso2 @@ -102,10 +106,12 @@ org.apache.httpcomponents httpasyncclient 4.1 + provided org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.iot + provided org.wso2.carbon.devicemgt-plugins @@ -117,10 +123,12 @@ org.codehaus.jackson jackson-core-asl + provided org.codehaus.jackson jackson-jaxrs + provided javax @@ -135,11 +143,13 @@ commons-httpclient.wso2 commons-httpclient + provided org.wso2.carbon org.wso2.carbon.utils + provided org.bouncycastle.wso2 @@ -203,6 +213,7 @@ commons-codec commons-codec + provided diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/iot-config.xml b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/iot-config.xml index 18245657e5..51aa7e4702 100644 --- a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/iot-config.xml +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/iot-config.xml @@ -1,5 +1,8 @@ - - + + jdbc/VirtualFireAlarmDM_DB + + + diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/public/js/device-details.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/public/js/device-details.js new file mode 100644 index 0000000000..9a0b6004a2 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/public/js/device-details.js @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2015, 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 graph; +var xAxis; + +var deviceType = $("#details").data("devicetype"); +var deviceId = $("#details").data("deviceid"); +var monitor_operations = $("#details").data("monitor"); + +var marker_1 = '/store/extensions/app/store-device-type/themes/store/img/map-marker-1.png'; +var marker_2 = '/store/extensions/app/store-device-type/themes/store/img/map-marker-2.png'; + +var map; +var mapPoints = [], mapPaths = [], mapMarkers = []; +function initMap() { + map = new google.maps.Map(document.getElementById('map'), { + center: {lat: 6.9344, lng: 79.8428}, + zoom: 12 + }); +} + +function formatDates() { + $(".formatDate").each(function () { + var timeStamp = $(this).html(); + $(this).html(getDateString(timeStamp)); + }); +} + +function getDateString(timeStamp) { + var monthNames = [ + "Jan", "Feb", "Mar", + "Apr", "May", "Jun", "Jul", + "Aug", "Sept", "Oct", + "Nov", "Dec" + ]; + + var date = new Date(parseInt(timeStamp)); + var day = date.getDate(); + var monthIndex = date.getMonth() + 1; + if (monthIndex < 10) { + monthIndex = "0" + monthIndex; + } + var year = date.getFullYear(); + + var hours = date.getHours(); + var amPm = hours < 12 ? "AM" : "PM"; + if (hours > 12) { + hours -= 12; + } + if (hours == 0) { + hours = 12; + } + return day + '-' + + monthNames[monthIndex - 1] + '-' + + year + ' ' + hours + ':' + date.getMinutes() + amPm; +} + +$(window).on('resize', function () { + if (graph) { + location.reload(false); + } +}); + +$(document).ready(function () { + formatDates(); + updateGraphs(); +}); + +$("form").on('submit', function (e) { + var postOperationRequest = $.ajax({ + url: $(this).attr("action") + '&' + $(this).serialize(), + method: "post" + }); + + var lblSending = $('#lblSending', this); + lblSending.removeClass('hidden'); + + var lblSent = $('#lblSent', this); + var sentValue = $(this).find('input[name="value"]').val(); + postOperationRequest.done(function (data) { + lblSending.addClass('hidden'); + lblSent.removeClass('hidden'); + setTimeout(function () { + lblSent.addClass('hidden'); + }, 3000); + $('#lblLastState').text('Current value: ' + (sentValue == '1' ? 'On' : 'Off')); + }); + + postOperationRequest.fail(function (jqXHR, textStatus) { + lblSending.addClass('hidden'); + lblSent.addClass('hidden'); + }); + e.preventDefault(); +}); + +function updateGraphs() { + var tv = 5000; + + var fields = []; + for (var op in monitor_operations) { + if (monitor_operations[op].name == 'gps') { + $('#map').removeClass('hidden'); + } else { + fields.push({name: monitor_operations[op].name}); + } + } + + // instantiate our graph! + graph = new Rickshaw.Graph({ + element: document.getElementById("chart"), + width: $("#chartWrapper").width() - 50, + height: 300, + renderer: 'line', + series: new Rickshaw.Series.FixedDuration(fields, undefined, { + timeInterval: 10000, + maxDataPoints: 20, + timeBase: new Date().getTime() / 1000 + }) + }); + + var iv = setInterval(function () { + + var getStatsRequest = $.ajax({ + url: "/store/apis/operations/" + deviceType + "/stats?deviceId=" + deviceId, + method: "get" + }); + + getStatsRequest.done(function (data) { + var stats = data.data; + var lastUpdate = -1; + var graphVals = {}; + for (var s in stats) { + var val = stats[s]; + if (!val){ + continue; + } + if (val.time > lastUpdate) { + lastUpdate = val.time; + } + delete val['time']; + if (val.map) { + mapPoints.push(val.map); + var marker = new google.maps.Marker({ + position: val.map, + map: map, + icon: marker_1, + title: 'Seen at ' + getDateString(lastUpdate) + }); + marker.setMap(map); + map.panTo(val.map); + mapMarkers.push(marker); + + if (mapPoints.length > 1 ){ + var l = mapPoints.length; + var path = new google.maps.Polyline({ + path: [mapPoints[l - 1], mapPoints[l - 2]], + geodesic: true, + strokeColor: '#FF0000', + strokeOpacity: 1.0, + strokeWeight: 2 + }); + + path.setMap(map); + mapPaths.push(path); + + mapMarkers[l - 2].setIcon(marker_2); + } + + if (mapPoints.length >= 10){ + mapMarkers[0].setMap(null); + mapMarkers.splice(0, 1); + + mapPaths[0].setMap(null); + mapPaths.splice(0, 1); + + mapPoints.splice(0, 1); + } + } else { + for (var key in val) { + graphVals[key] = val[key]; + } + } + } + graph.series.addData(graphVals); + + if (lastUpdate == -1){ + $('#last_seen').text("Not seen recently"); + } + + var timeDiff = new Date().getTime() - lastUpdate; + if (timeDiff < tv * 2) { + graph.render(); + $('#last_seen').text("Last seen: A while ago"); + } else if (timeDiff < 60 * 1000) { + graph.render(); + $('#last_seen').text("Last seen: Less than a minute ago"); + } else if (timeDiff < 60 * 60 * 1000) { + $('#last_seen').text("Last seen: " + Math.round(timeDiff / (60 * 1000)) + " minutes ago"); + } else { + $('#last_seen').text("Last seen: " + getDateString(lastUpdate)); + } + }); + + //var data = {Temperature: Math.floor(Math.random() * (50 - 20) + 20)}; + // + //graph.series.addData(data); + //graph.render(); + + }, tv); + + graph.render(); + + xAxis = new Rickshaw.Graph.Axis.Time({ + graph: graph + }); + + xAxis.render(); + + var y_ticks = new Rickshaw.Graph.Axis.Y({ + graph: graph, + orientation: 'left', + height: 300, + tickFormat: Rickshaw.Fixtures.Number.formatKMBT, + element: document.getElementById('y_axis') + }); + + var legend = new Rickshaw.Graph.Legend({ + graph: graph, + element: document.getElementById('legend') + }); + + var hoverDetail = new Rickshaw.Graph.HoverDetail({ + graph: graph + }); + + var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({ + graph: graph, + legend: legend + }); + + var order = new Rickshaw.Graph.Behavior.Series.Order({ + graph: graph, + legend: legend + }); + + var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({ + graph: graph, + legend: legend + }); +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.hbs new file mode 100644 index 0000000000..1d395d4e50 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.hbs @@ -0,0 +1,101 @@ + +
+ +
+
+
+
+
+
+
+
+
+
+
+ + + + + + View Device Analytics +
+
+
+ + + +
+ +
+
+ {{#if data}} +
+
+
+
+
+ + + + + + + + + {{#each data}} + + + + + {{/each}} + +
TimeActivity
{{time}}{{activity}}
+
+
+
+
+
+ {{else}} +
+
You don't have any + events logged at + the moment. +
+
+ {{/if}} +
+
+
+{{#zone "bottomJs"}} + {{js "js/device-details.js"}} +{{/zone}} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.js new file mode 100644 index 0000000000..a4309ce7c8 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.js @@ -0,0 +1,3 @@ +function onRequest(context) { + return context; +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.json new file mode 100644 index 0000000000..688e939808 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.stats/stats.json @@ -0,0 +1,3 @@ +{ + "version": "1.0.0" +} \ No newline at end of file diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.hbs b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.hbs new file mode 100644 index 0000000000..b6ee822acd --- /dev/null +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.hbs @@ -0,0 +1,36 @@ +
+
+ {{unit "cdmf.unit.device.overview.firealarm-display-image"}} +
+
+
Device Overview - Virtual Firealarm
+ {{#defineZone "device-detail-properties"}} + + + + + + {{#if device.viewModel.udid}} + + {{/if}} + {{#if device.viewModel.phoneNumber}} + + {{/if}} + + + + + +
Device{{device.viewModel.vendor}} {{device.properties.model}}
Model{{device.viewModel.model}}
IMEI{{device.viewModel.imei}}
UDID{{device.viewModel.udid}}
Phone Number{{device.viewModel.phoneNumber}}
Status + {{#equal device.status "ACTIVE"}} Active{{/equal}} + {{#equal device.status "INACTIVE"}} Inactive{{/equal}} + {{#equal device.status "BLOCKED"}} Blocked{{/equal}} + {{#equal device.status "REMOVED"}} Removed{{/equal}} +
+ {{/defineZone}} +
Operations
+
+ {{unit "cdmf.unit.device.iot-operation" deviceType=device.type}} +
+
+
\ No newline at end of file diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.js b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.js new file mode 100644 index 0000000000..4db0045b5e --- /dev/null +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.js @@ -0,0 +1,25 @@ +function onRequest (context) { + var log = new Log("detail.js"); + var deviceType = request.getParameter("type"); + var deviceId = request.getParameter("id"); + + if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { + var deviceModule = require("/modules/device.js").deviceModule; + var device = deviceModule.viewDevice(deviceType, deviceId); + + if (device) { + var viewModel = {}; + var deviceInfo = device.properties.DEVICE_INFO; + if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) { + deviceInfo = parse(stringify(deviceInfo)); + viewModel.system = device.properties.IMEI; + viewModel.machine = "Virtual Firealarm"; + viewModel.vendor = device.properties.VENDOR; + } + device.viewModel = viewModel; + } + context.device = device; + + return context; + } +} \ No newline at end of file diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.json b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.json new file mode 100644 index 0000000000..688e939808 --- /dev/null +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.firealarm-overview/firealarm-overview.json @@ -0,0 +1,3 @@ +{ + "version": "1.0.0" +} \ No newline at end of file diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf index 6074b856e8..286ed018df 100644 --- a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf @@ -6,8 +6,6 @@ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../reso org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/agent/,target:${installFolder}/../../resources/sketches/virtual_firealarm/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/sketches/virtual_firealarm_advanced/);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/advanced_agent/,target:${installFolder}/../../resources/sketches/virtual_firealarm_advanced/,overwrite:true);\ -org.wso2.carbon.p2.touchpoint.addXMLElement(file:${installFolder}/../../conf/iot/iot-config.xml,xpath:/IoTDeviceTypeConfigManager,element:jdbc/${data_source}); \ -org.wso2.carbon.p2.touchpoint.addXMLElement(file:${installFolder}/../../conf/datasources/master-datasources.xml,xpath:/datasources-configuration/datasources,element:${data_source}The datasource used for the Virtual-Firealarm databasejdbc/${data_source}jdbc${#58}h2${#58}repository/database/${data_source}${#59}DB_CLOSE_ON_EXIT=FALSEwso2carbonwso2carbonorg.h2.Driver5060000trueSELECT 130000); \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/virtual_firealarm,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.devicemgt.ui_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\