diff --git a/modules/distribution/src/repository/jaggeryapps/api-store/jagg.jag b/modules/distribution/src/repository/jaggeryapps/api-store/jagg.jag index 2ad77a05..c1068ed4 100644 --- a/modules/distribution/src/repository/jaggeryapps/api-store/jagg.jag +++ b/modules/distribution/src/repository/jaggeryapps/api-store/jagg.jag @@ -107,14 +107,14 @@ var jagg = jagg || (function () { var getThemeFile = function (path) { var p, index, theme = getUserTheme(); - if(theme.tenant_theme) { + if (theme.tenant_theme) { p = getTenantThemePath() + path; index = p.indexOf("?"); - if(new File(p.substring(0, index == -1 ? p.length : index)).isExists()) { + if (new File(p.substring(0, index == -1 ? p.length : index)).isExists()) { return p; } } - if(theme.subtheme) { + if (theme.subtheme) { p = getThemePath() + "subthemes/" + theme.subtheme + "/" + path; index = p.indexOf("?"); if(new File(p.substring(0, index == -1 ? p.length : index)).isExists()) { diff --git a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java b/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java index 9fe24b2c..3e0adfaf 100644 --- a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java +++ b/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java @@ -18,7 +18,8 @@ package org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization; -import org.apache.log4j.Logger; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.dna.mqtt.moquette.server.IAuthorizer; import org.wso2.andes.configuration.enums.MQTTAuthoriztionPermissionLevel; import org.wso2.andes.mqtt.MQTTAuthorizationSubject; @@ -36,7 +37,8 @@ import java.util.List; * This is just a simple authorization model. For dynamic topics use an implementation based on IAuthorizer */ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { - private static final Logger logger = Logger.getLogger(DeviceAccessBasedMQTTAuthorizer.class); + + private static Log logger = LogFactory.getLog(DeviceAccessBasedMQTTAuthorizer.class); private static final String CONNECTION_PERMISSION = "/permission/admin/device-mgt/user"; private static final String ADMIN_PERMISSION = "/permission/admin/device-mgt/admin"; private static final String SCOPE_IDENTIFIER = "scope"; diff --git a/modules/samples/connectedcup/component/api/src/main/java/org/coffeeking/api/ConnectedCupServiceImpl.java b/modules/samples/connectedcup/component/api/src/main/java/org/coffeeking/api/ConnectedCupServiceImpl.java index 1ada9b27..3206ab55 100644 --- a/modules/samples/connectedcup/component/api/src/main/java/org/coffeeking/api/ConnectedCupServiceImpl.java +++ b/modules/samples/connectedcup/component/api/src/main/java/org/coffeeking/api/ConnectedCupServiceImpl.java @@ -104,10 +104,10 @@ public class ConnectedCupServiceImpl implements ConnectedCupService { return Response.ok().entity(sensorDatas).build(); } catch (AnalyticsException e) { String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; - log.error(errorMsg); + log.error(errorMsg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build(); } catch (DeviceAccessAuthorizationException e) { - log.error(e.getErrorMessage()); + log.error(e.getErrorMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } } @@ -154,6 +154,7 @@ public class ConnectedCupServiceImpl implements ConnectedCupService { device.setEnrolmentInfo(enrolmentInfo); return APIUtil.getDeviceManagementService().enrollDevice(device); } catch (DeviceManagementException e) { + log.error("Failed to enroll device with device name :" + name, e); return false; } } diff --git a/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/exception/ConnectedCupDeviceMgtPluginException.java b/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/exception/ConnectedCupDeviceMgtPluginException.java index 34a5c639..92b85968 100644 --- a/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/exception/ConnectedCupDeviceMgtPluginException.java +++ b/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/exception/ConnectedCupDeviceMgtPluginException.java @@ -19,21 +19,16 @@ package org.coffeeking.connectedcup.plugin.exception; public class ConnectedCupDeviceMgtPluginException extends Exception { - private String errorMessage; - public ConnectedCupDeviceMgtPluginException(String msg, Exception nestedEx) { super(msg, nestedEx); - setErrorMessage(msg); } public ConnectedCupDeviceMgtPluginException(String message, Throwable cause) { super(message, cause); - setErrorMessage(message); } public ConnectedCupDeviceMgtPluginException(String msg) { super(msg); - setErrorMessage(msg); } public ConnectedCupDeviceMgtPluginException() { @@ -44,12 +39,4 @@ public class ConnectedCupDeviceMgtPluginException extends Exception { super(cause); } - public String getErrorMessage() { - return errorMessage; - } - - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - } diff --git a/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/impl/dao/util/ConnectedCupUtils.java b/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/impl/dao/util/ConnectedCupUtils.java index fce7c509..9c25f256 100644 --- a/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/impl/dao/util/ConnectedCupUtils.java +++ b/modules/samples/connectedcup/component/plugin/src/main/java/org/coffeeking/connectedcup/plugin/impl/dao/util/ConnectedCupUtils.java @@ -38,8 +38,8 @@ public class ConnectedCupUtils { public static String getDeviceProperty(List deviceProperties, String propertyKey) { String deviceProperty = ""; - for(Device.Property property :deviceProperties){ - if(propertyKey.equals(property.getName())){ + for (Device.Property property : deviceProperties) { + if (propertyKey.equals(property.getName())) { deviceProperty = property.getValue(); } } diff --git a/modules/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.analytics-view/public/js/connectedcup.js b/modules/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.analytics-view/public/js/connectedcup.js index 66d6534b..ebd48673 100644 --- a/modules/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.analytics-view/public/js/connectedcup.js +++ b/modules/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.analytics-view/public/js/connectedcup.js @@ -230,9 +230,7 @@ function drawGraph_connectedcup(from, to) { drawTemperatureLineGraph(JSON.parse(data)); } }; - invokerUtil.get(backendApiUrl, successCallback, function (message) { - console.log(message); - }); + invokerUtil.get(backendApiUrl, successCallback, function (message) {}); var coffeeLevelApiUrl = $('#connectedcup-div-chart').data('backend-api-url') + '/sensors/coffeelevel' + '?from=' + from + '&to=' + to; @@ -286,10 +284,10 @@ function drawGraph_connectedcup(from, to) { var chartData = []; for (var i = 0; i < data.length; i++) { chartData.push( - { - x: parseInt(data[i].values.time) - tzOffset, - y: parseInt(data[i].values.temperature) - } + { + x: parseInt(data[i].values.time) - tzOffset, + y: parseInt(data[i].values.temperature) + } ); } diff --git a/modules/samples/doormanager/feature/feature/src/main/resources/agent/src/mqttHandler.py b/modules/samples/doormanager/feature/feature/src/main/resources/agent/src/mqttHandler.py deleted file mode 100644 index 9f236018..00000000 --- a/modules/samples/doormanager/feature/feature/src/main/resources/agent/src/mqttHandler.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python - -""" -/** -* 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. -**/ -""" - -import time - -#import RPi.GPIO as GPIO -import paho.mqtt.client as mqtt -import iotUtils - -global mqttClient -mqttClient = mqtt.Client() - -global TOPIC_TO_PUBLISH_STREAM1 -global TOPIC_TO_PUBLISH_STREAM2 - - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# The callback for when the client receives a CONNACK response from the server. -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def on_connect(mqttClient, userdata, flags, rc): - print("MQTT_LISTENER: Connected with result code " + str(rc)) - # Subscribing in on_connect() means that if we lose the connection and - # reconnect then subscriptions will be renewed. - print ("MQTT_LISTENER: Subscribing with topic " + SUBSCRIBE_FOR_LOCKER_COMMAND) - mqttClient.subscribe(SUBSCRIBE_FOR_LOCKER_COMMAND) - print ("MQTT_LISTENER: Subscribing with topic " + SUBSCRIBE_FOR_FAN_COMMAND) - mqttClient.subscribe(SUBSCRIBE_FOR_FAN_COMMAND) - print ("MQTT_LISTENER: Subscribing with topic " + SUBSCRIBE_FOR_BULB_COMMAND) - mqttClient.subscribe(SUBSCRIBE_FOR_BULB_COMMAND) -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# The callback for when a PUBLISH message is received from the server. -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def on_message(mqttClient, userdata, msg): - print("MQTT_LISTENER: " + msg.topic + " " + str(msg.payload)) - if msg.topic == SUBSCRIBE_FOR_LOCKER_COMMAND: - request = str(msg.payload) - resource = "" - state = request.upper() - if state == "LOCK": - # GPIO.output(iotUtils.DOOR_LOCKER_2_PORT, GPIO.HIGH) - # GPIO.output(iotUtils.DOOR_LOCKER_1_PORT, GPIO.HIGH) - # GPIO.output(iotUtils.LOCK_STATE_OFF_NOTIFY_PORT, GPIO.HIGH) - # GPIO.output(iotUtils.LOCK_STATE_ON_NOTIFY_PORT, GPIO.LOW) - #mqttClient.publish(TOPIC_TO_PUBLISH, "Locker:LOCKED") - print "Door is locked" - elif state == "UNLOCK": - # GPIO.output(iotUtils.DOOR_LOCKER_2_PORT, GPIO.LOW) - # GPIO.output(iotUtils.DOOR_LOCKER_1_PORT, GPIO.LOW) - # GPIO.output(iotUtils.LOCK_STATE_OFF_NOTIFY_PORT, GPIO.LOW) - # GPIO.output(iotUtils.LOCK_STATE_ON_NOTIFY_PORT, GPIO.HIGH) - #mqttClient.publish(TOPIC_TO_PUBLISH, "Locker:UNLOCKED") - print "Door is unlocked" - else: - print "MQTT message in the wrong format" - print "MQTT_LISTENER: Resource- " + resource - elif msg.topic == SUBSCRIBE_FOR_FAN_COMMAND: - request = str(msg.payload) - resource = "" - state = request.upper() - if state == "ON": - # GPIO.output(iotUtils.DOOR_LOCKER_2_PORT, GPIO.HIGH) - # GPIO.output(iotUtils.DOOR_LOCKER_1_PORT, GPIO.HIGH) - # GPIO.output(iotUtils.LOCK_STATE_OFF_NOTIFY_PORT, GPIO.HIGH) - # GPIO.output(iotUtils.LOCK_STATE_ON_NOTIFY_PORT, GPIO.LOW) - #mqttClient.publish(TOPIC_TO_PUBLISH, "Locker:LOCKED") - print "Fan is locked" - elif state == "OFF": - # GPIO.output(iotUtils.DOOR_LOCKER_2_PORT, GPIO.LOW) - # GPIO.output(iotUtils.DOOR_LOCKER_1_PORT, GPIO.LOW) - # GPIO.output(iotUtils.LOCK_STATE_OFF_NOTIFY_PORT, GPIO.LOW) - # GPIO.output(iotUtils.LOCK_STATE_ON_NOTIFY_PORT, GPIO.HIGH) - #mqttClient.publish(TOPIC_TO_PUBLISH, "Locker:UNLOCKED") - print "Fan is off" - else: - print "MQTT message in the wrong format" - print "MQTT_LISTENER: Resource- " + resource - elif msg.topic == SUBSCRIBE_FOR_BULB_COMMAND: - request = str(msg.payload) - print "bulb is to blow" - resource = "" - print request -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# The callback for when a PUBLISH message to the server when door is open or close -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def on_publish(mqttClient, topic, msg): - mqttClient.publish(topic, msg) - - -def sendLockerStatus(msg): - global mqttClient - on_publish(mqttClient, msg) -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# The Main method of the server script -# This method is invoked from DoorLockerAgent.py on a new thread -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def main(): - MQTT_ENDPOINT = iotUtils.MQTT_EP.split(":") - MQTT_IP = MQTT_ENDPOINT[1].replace('//', '') - MQTT_PORT = int(MQTT_ENDPOINT[2]) - - DEV_OWNER = iotUtils.DEVICE_OWNER - DEV_ID = iotUtils.DEVICE_ID - DEV_TYPE =iotUtils.DEVICE_TYPE - TANENT_DOMAIN = iotUtils.SERVER_NAME - - global SUBSCRIBE_FOR_LOCKER_COMMAND - SUBSCRIBE_FOR_LOCKER_COMMAND = TANENT_DOMAIN + "/" + DEV_TYPE + "/" + DEV_ID + "/command" - global SUBSCRIBE_FOR_FAN_COMMAND - SUBSCRIBE_FOR_FAN_COMMAND = TANENT_DOMAIN + "/" + DEV_TYPE + "/" + DEV_ID + "/fan/command" - global SUBSCRIBE_FOR_BULB_COMMAND - SUBSCRIBE_FOR_BULB_COMMAND = TANENT_DOMAIN + "/" + DEV_TYPE + "/" + DEV_ID + "/bulb/command" - global TOPIC_TO_PUBLISH_STREAM1 - TOPIC_TO_PUBLISH_STREAM1 = TANENT_DOMAIN + "/" + DEV_TYPE + "/" + DEV_ID + "/smartLock" - global TOPIC_TO_PUBLISH_STREAM2 - TOPIC_TO_PUBLISH_STREAM2 = TANENT_DOMAIN + "/" + DEV_TYPE + "/" + DEV_ID + "/smartFan" - - print ("MQTT_LISTENER: MQTT_ENDPOINT is " + str(MQTT_ENDPOINT)) - print ("MQTT_LISTENER: MQTT_TOPIC is " + SUBSCRIBE_FOR_LOCKER_COMMAND) - global mqttClient - mqttClient.username_pw_set(iotUtils.AUTH_TOKEN, password = "") - mqttClient.on_connect = on_connect - mqttClient.on_message = on_message - - while True: - try: - mqttClient.connect(MQTT_IP, MQTT_PORT, 60) - print "MQTT_LISTENER: " + time.asctime(), "Connected to MQTT Broker - %s:%s" % (MQTT_IP, MQTT_PORT) - # Blocking call that processes network traffic, dispatches callbacks and - # handles reconnecting. - # Other loop*() functions are available that give a threaded interface and a - # manual interface. - mqttClient.loop_forever() - - except (KeyboardInterrupt, Exception) as e: - print "MQTT_LISTENER: Exception in MQTTServerThread (either KeyboardInterrupt or Other)" - print ("MQTT_LISTENER: " + str(e)) - - mqttClient.disconnect() - print "MQTT_LISTENER: " + time.asctime(), "Connection to Broker closed - %s:%s" % (MQTT_IP, MQTT_PORT) - print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' - pass - -if __name__ == '__main__': - main()