diff --git a/modules/distribution/src/repository/conf/identity/sso-idp-config.xml b/modules/distribution/src/repository/conf/identity/sso-idp-config.xml index f084edd9..5823cfa7 100755 --- a/modules/distribution/src/repository/conf/identity/sso-idp-config.xml +++ b/modules/distribution/src/repository/conf/identity/sso-idp-config.xml @@ -29,7 +29,6 @@ social https://localhost:9443/store/acs https://localhost:9443/social/acs - https://localhost:9443/social/acs true /social/login @@ -37,7 +36,6 @@ publisher https://localhost:9443/store/acs https://localhost:9443/publisher/acs - https://localhost:9443/publisher/acs true /publisher/controllers/login.jag diff --git a/modules/distribution/src/statistics/carbonapps/Temperature_Sensor.car b/modules/distribution/src/statistics/carbonapps/Temperature_Sensor.car index 88eab641..44a3dbac 100644 Binary files a/modules/distribution/src/statistics/carbonapps/Temperature_Sensor.car and b/modules/distribution/src/statistics/carbonapps/Temperature_Sensor.car differ diff --git a/modules/p2-profile-gen/pom.xml b/modules/p2-profile-gen/pom.xml index 00b4c130..d79a7376 100644 --- a/modules/p2-profile-gen/pom.xml +++ b/modules/p2-profile-gen/pom.xml @@ -1165,14 +1165,14 @@ org.wso2.carbon.social.feature.group ${carbon.social.version} - - org.wso2.carbon.store.extensions.assets.gadget.feature.group - ${carbon.store.version} - - - org.wso2.carbon.store.extensions.assets.site.feature.group - ${carbon.store.version} - + + + + + + + + diff --git a/modules/samples/android_sense/src/org.wso2.carbon.device.mgt.iot.sample.android.sense.service.impl/pom.xml b/modules/samples/android_sense/src/org.wso2.carbon.device.mgt.iot.sample.android.sense.service.impl/pom.xml index 5626c9b6..450db516 100644 --- a/modules/samples/android_sense/src/org.wso2.carbon.device.mgt.iot.sample.android.sense.service.impl/pom.xml +++ b/modules/samples/android_sense/src/org.wso2.carbon.device.mgt.iot.sample.android.sense.service.impl/pom.xml @@ -21,29 +21,35 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + provided org.apache.cxf cxf-rt-frontend-jaxws + provided org.apache.cxf cxf-rt-frontend-jaxrs + provided org.apache.cxf cxf-rt-transports-http + provided org.eclipse.paho mqtt-client + provided @@ -55,10 +61,12 @@ org.wso2.carbon.device.mgt.iot org.wso2.carbon.device.mgt.iot.common + provided org.wso2.carbon.device.mgt.iot.server.sample org.wso2.carbon.device.mgt.iot.sample.android.sense.plugin.impl + provided @@ -72,10 +80,12 @@ javax javaee-web-api + provided javax.ws.rs jsr311-api + provided diff --git a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/pom.xml b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/pom.xml index 81fb07ea..e2ef9f75 100644 --- a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/pom.xml +++ b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/pom.xml @@ -27,30 +27,36 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + provided org.apache.cxf cxf-rt-frontend-jaxws + provided org.apache.cxf cxf-rt-frontend-jaxrs + provided org.apache.cxf cxf-rt-transports-http + provided org.eclipse.paho mqtt-client + provided @@ -62,10 +68,12 @@ org.wso2.carbon.device.mgt.iot org.wso2.carbon.device.mgt.iot.common + provided org.wso2.carbon.device.mgt.iot.server.sample org.wso2.carbon.device.mgt.iot.sample.arduino.plugin.impl + provided @@ -79,16 +87,19 @@ javax javaee-web-api + provided javax.ws.rs jsr311-api + provided + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.analytics + provided - diff --git a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoControllerService.java b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoControllerService.java index 952154c1..f0545137 100644 --- a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoControllerService.java +++ b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoControllerService.java @@ -27,9 +27,7 @@ import org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl.util.DeviceJSO import org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl.util.MqttArduinoSubscriber; import org.wso2.carbon.device.mgt.iot.sample.arduino.plugin.constants.ArduinoConstants; import org.wso2.carbon.device.mgt.iot.common.DeviceController; -import org.wso2.carbon.device.mgt.iot.common.datastore.impl.DataStreamDefinitions; import org.wso2.carbon.device.mgt.iot.common.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.common.exception.UnauthorizedException; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; @@ -44,7 +42,8 @@ public class ArduinoControllerService { private static Map> replyMsgQueue = new HashMap<>(); private static Map> internalControlsQueue = new HashMap<>(); private static MqttArduinoSubscriber mqttArduinoSubscriber; - + private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature"; + private final String SUPER_TENANT = "carbon.super"; public void setMqttArduinoSubscriber(MqttArduinoSubscriber mqttArduinoSubscriber) { ArduinoControllerService.mqttArduinoSubscriber = mqttArduinoSubscriber; @@ -137,57 +136,32 @@ public class ArduinoControllerService { } - /* Service to push all the sensor data collected by the Arduino + /*Service to push all the sensor data collected by the Arduino Called by the Arduino device */ @Path("/pushdata") @POST @Consumes(MediaType.APPLICATION_JSON) public void pushData(final DeviceJSON dataMsg, @Context HttpServletResponse response) { - String temperature = dataMsg.value; //TEMP - log.info("Recieved Sensor Data Values: " + temperature); + float temperature = dataMsg.value; if (log.isDebugEnabled()) { log.debug("Recieved Temperature Data Value: " + temperature + " degrees C"); } - try { - DeviceController deviceController = new DeviceController(); - boolean result = deviceController.pushBamData(dataMsg.owner, - ArduinoConstants.DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - temperature, - DataStreamDefinitions.StreamTypeLabel - .TEMPERATURE); - - if (!result) { - response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); - } - - } catch (UnauthorizedException e) { - response.setStatus(HttpStatus.SC_UNAUTHORIZED); - - } - } - - @Path("/test/{value}") - @POST - public void pushtData(@PathParam("value") double value, @Context HttpServletResponse - response) { - PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - ctx.setTenantDomain("carbon.super", true); + ctx.setTenantDomain(SUPER_TENANT, true); DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx - .getOSGiService( - DeviceAnalyticsService.class, null); - Object metdaData[] = {"ayyoob", "firealarm", "123", System.currentTimeMillis()}; - Object payloadData[] = {value}; + .getOSGiService(DeviceAnalyticsService.class, null); + Object metdaData[] = {dataMsg.owner, ArduinoConstants.DEVICE_TYPE, dataMsg.deviceId, + System.currentTimeMillis()}; + Object payloadData[] = {temperature}; try { - deviceAnalyticsService.publishEvent("org.wso2.iot.devices.temperature", "1.0.0", + deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", metdaData, new Object[0], payloadData); } catch (DataPublisherConfigurationException e) { + log.error("Error on connecting to data publisher"); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } finally { diff --git a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/util/DeviceJSON.java b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/util/DeviceJSON.java index 86c739e4..469c4eb9 100644 --- a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/util/DeviceJSON.java +++ b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/util/DeviceJSON.java @@ -14,5 +14,5 @@ public class DeviceJSON { @XmlElement(required = true) public String reply; @XmlElement public Long time; @XmlElement public String key; - @XmlElement public String value; + @XmlElement public float value; } diff --git a/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/pom.xml b/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/pom.xml index 4f6c5a8c..dfbf4e46 100644 --- a/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/pom.xml +++ b/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/pom.xml @@ -21,29 +21,35 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + provided org.apache.cxf cxf-rt-frontend-jaxws + provided org.apache.cxf cxf-rt-frontend-jaxrs + provided org.apache.cxf cxf-rt-transports-http + provided org.eclipse.paho mqtt-client + provided @@ -55,10 +61,12 @@ org.wso2.carbon.device.mgt.iot org.wso2.carbon.device.mgt.iot.common + provided org.wso2.carbon.device.mgt.iot.server.sample org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.plugin.impl + provided @@ -72,10 +80,12 @@ javax javaee-web-api + provided javax.ws.rs jsr311-api + provided diff --git a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/pom.xml b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/pom.xml index 947cb546..f591305f 100644 --- a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/pom.xml +++ b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/pom.xml @@ -21,29 +21,35 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + provided org.apache.cxf cxf-rt-frontend-jaxws + provided org.apache.cxf cxf-rt-frontend-jaxrs + provided org.apache.cxf cxf-rt-transports-http + provided org.eclipse.paho mqtt-client + provided @@ -55,10 +61,12 @@ org.wso2.carbon.device.mgt.iot org.wso2.carbon.device.mgt.iot.common + provided org.wso2.carbon.device.mgt.iot.server.sample org.wso2.carbon.device.mgt.iot.sample.firealarm.plugin.impl + provided @@ -72,20 +80,30 @@ javax javaee-web-api + provided javax.ws.rs jsr311-api + provided commons-httpclient.wso2 commons-httpclient + provided org.wso2.carbon org.wso2.carbon.utils + provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics + provided + + diff --git a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmControllerService.java b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmControllerService.java index 72247904..eb12180c 100644 --- a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmControllerService.java +++ b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmControllerService.java @@ -23,6 +23,9 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.concurrent.FutureCallback; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClients; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.iot.common.DeviceController; @@ -65,7 +68,7 @@ public class FireAlarmControllerService { private final String SUPER_TENANT = "carbon.super"; @Context //injected response proxy supporting multiple thread private HttpServletResponse response; - + private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature"; private static final String URL_PREFIX = "http://"; private static final String BULB_CONTEXT = "/BULB/"; @@ -380,143 +383,121 @@ public class FireAlarmControllerService { boolean result; String deviceId = dataMsg.deviceId; String deviceIp = dataMsg.reply; - String temperature = dataMsg.value; + float temperature = dataMsg.value; String registeredIp = deviceToIpMap.get(deviceId); if (registeredIp == null) { - log.warn( - "Unregistered IP: Temperature Data Received from an un-registered IP " + - deviceIp + - " for device ID - " + deviceId); + log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " + + deviceIp + " for device ID - " + deviceId); response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); return; } else if (!registeredIp.equals(deviceIp)) { log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + - deviceId + - " is already registered under some other IP. Re-registration " + - "required"); + deviceId + " is already registered under some other IP. Re-registration " + "required"); response.setStatus(Response.Status.CONFLICT.getStatusCode()); return; } + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(SUPER_TENANT, true); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + Object metdaData[] = {dataMsg.owner, FireAlarmConstants.DEVICE_TYPE, dataMsg.deviceId, + System.currentTimeMillis()}; + Object payloadData[] = {temperature}; try { - DeviceController deviceController = new DeviceController(); - result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants - .DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - temperature, - DataStreamDefinitions.StreamTypeLabel - .TEMPERATURE); - - - if (!result) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - } catch (UnauthorizedException e) { + deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", + metdaData, new Object[0], payloadData); + } catch (DataPublisherConfigurationException e) { response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.error("Data Push Attempt Failed for BAM Publisher: " + e.getMessage()); - } - try { - DeviceController deviceController = new DeviceController(); - result = deviceController.pushCepData(dataMsg.owner, FireAlarmConstants - .DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - temperature, - DataStreamDefinitions.StreamTypeLabel - .TEMPERATURE); - - - if (!result) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - } catch (UnauthorizedException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.error("Data Push Attempt Failed for CEP Publisher: " + e.getMessage()); + } finally { + PrivilegedCarbonContext.endTenantFlow(); } + + } /* Service to push all the sensor data collected by the FireAlarm Called by the FireAlarm device */ - @Path("/pushalarmdata") - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void pushAlarmData(final DeviceJSON dataMsg, @Context HttpServletResponse response) { - boolean result; - String sensorValues = dataMsg.value; - log.info("Recieved Sensor Data Values: " + sensorValues); - - String sensors[] = sensorValues.split(":"); - try { - if (sensors.length == 3) { - String temperature = sensors[0]; - String bulb = sensors[1]; - String sonar = sensors[2]; - - sensorValues = "Temperature:" + temperature + "C\tBulb Status:" + bulb + - "\t\tSonar Status:" + sonar; - log.info(sensorValues); - DeviceController deviceController = new DeviceController(); - result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants - .DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - temperature, "TEMPERATURE"); - - if (!result) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.error("Error whilst pushing temperature: " + sensorValues); - return; - } - - result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants - .DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - bulb, - "BULB"); - - if (!result) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.error("Error whilst pushing Bulb data: " + sensorValues); - return; - } - - result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants - .DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - sonar, - "SONAR"); - - if (!result) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.error("Error whilst pushing Sonar data: " + sensorValues); - } - - } else { - DeviceController deviceController = new DeviceController(); - result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants - .DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - dataMsg.value, dataMsg.reply); - if (!result) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.error("Error whilst pushing sensor data: " + sensorValues); - } - } - - } catch (UnauthorizedException e) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - log.error("Data Push Attempt Failed at Publisher: " + e.getMessage()); - } - } +// @Path("/pushalarmdata") +// @POST +// @Consumes(MediaType.APPLICATION_JSON) +// public void pushAlarmData(final DeviceJSON dataMsg, @Context HttpServletResponse response) { +// boolean result; +// String sensorValues = dataMsg.value; +// log.info("Recieved Sensor Data Values: " + sensorValues); +// +// String sensors[] = sensorValues.split(":"); +// try { +// if (sensors.length == 3) { +// String temperature = sensors[0]; +// String bulb = sensors[1]; +// String sonar = sensors[2]; + +// sensorValues = "Temperature:" + temperature + "C\tBulb Status:" + bulb + +// "\t\tSonar Status:" + sonar; +// log.info(sensorValues); +// DeviceController deviceController = new DeviceController(); +// result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants +// .DEVICE_TYPE, +// dataMsg.deviceId, +// System.currentTimeMillis(), "DeviceData", +// temperature, "TEMPERATURE"); +// +// if (!result) { +// response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); +// log.error("Error whilst pushing temperature: " + sensorValues); +// return; +// } +// +// result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants +// .DEVICE_TYPE, +// dataMsg.deviceId, +// System.currentTimeMillis(), "DeviceData", +// bulb, +// "BULB"); +// +// if (!result) { +// response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); +// log.error("Error whilst pushing Bulb data: " + sensorValues); +// return; +// } +// +// result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants +// .DEVICE_TYPE, +// dataMsg.deviceId, +// System.currentTimeMillis(), "DeviceData", +// sonar, +// "SONAR"); +// +// if (!result) { +// response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); +// log.error("Error whilst pushing Sonar data: " + sensorValues); +// } +// +// } else { +// DeviceController deviceController = new DeviceController(); +// result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants +// .DEVICE_TYPE, +// dataMsg.deviceId, +// System.currentTimeMillis(), "DeviceData", +// dataMsg.value, dataMsg.reply); +// if (!result) { +// response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); +// log.error("Error whilst pushing sensor data: " + sensorValues); +// } +// } +// +// } catch (UnauthorizedException e) { +// response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); +// log.error("Data Push Attempt Failed at Publisher: " + e.getMessage()); +// } +// } private String sendCommandViaXMPP(String deviceOwner, String deviceId, String resource, diff --git a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/util/DeviceJSON.java b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/util/DeviceJSON.java index 2fe4cb31..2f6da159 100644 --- a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/util/DeviceJSON.java +++ b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/util/DeviceJSON.java @@ -14,5 +14,5 @@ public class DeviceJSON { @XmlElement(required = true) public String reply; @XmlElement public Long time; @XmlElement public String key; - @XmlElement public String value; + @XmlElement public float value; } diff --git a/modules/samples/pom.xml b/modules/samples/pom.xml index 33d20475..c379481d 100644 --- a/modules/samples/pom.xml +++ b/modules/samples/pom.xml @@ -210,6 +210,16 @@ + + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.datasource.commons + ${carbon.analytics.version} + provided + + + org.eclipse.osgi @@ -305,8 +315,6 @@ provided - - org.wso2.carbon org.wso2.carbon.utils @@ -369,6 +377,7 @@ org.wso2.carbon.registry.api + provided @@ -435,6 +444,7 @@ 1.7 1.7 + 1.0.3 diff --git a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/pom.xml b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/pom.xml index 122df7fe..6891f148 100644 --- a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/pom.xml +++ b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/pom.xml @@ -21,29 +21,35 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + provided org.apache.cxf cxf-rt-frontend-jaxws + provided org.apache.cxf cxf-rt-frontend-jaxrs + provided org.apache.cxf cxf-rt-transports-http + provided org.eclipse.paho mqtt-client + provided @@ -55,10 +61,12 @@ org.wso2.carbon.device.mgt.iot org.wso2.carbon.device.mgt.iot.common + provided org.wso2.carbon.device.mgt.iot.server.sample org.wso2.carbon.device.mgt.iot.sample.raspberrypi.plugin.impl + provided @@ -72,10 +80,17 @@ javax javaee-web-api + provided javax.ws.rs jsr311-api + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics + provided diff --git a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiControllerService.java b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiControllerService.java index 134b281c..1a7170d1 100644 --- a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiControllerService.java +++ b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiControllerService.java @@ -17,6 +17,9 @@ package org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.iot.common.datastore.impl.DataStreamDefinitions; import org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl.util.DeviceJSON; import org.wso2.carbon.device.mgt.iot.sample.raspberrypi.plugin.constants.RaspberrypiConstants; @@ -35,6 +38,9 @@ import javax.ws.rs.core.Response; public class RaspberrypiControllerService { private static Log log = LogFactory.getLog(RaspberrypiControllerService.class); + private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature"; + //TODO; replace this tenant domain + private final String SUPER_TENANT = "carbon.super"; @Context //injected response proxy supporting multiple thread private HttpServletResponse response; @@ -46,29 +52,29 @@ public class RaspberrypiControllerService { @Consumes(MediaType.APPLICATION_JSON) public void pushData(final DeviceJSON dataMsg, @Context HttpServletResponse response) { - String temperature = dataMsg.value; //TEMP + float temperature = dataMsg.value; //TEMP log.info("Recieved Sensor Data Values: " + temperature); if (log.isDebugEnabled()) { log.debug("Recieved Temperature Data Value: " + temperature + " degrees C"); } - try { - - DeviceController deviceController = new DeviceController(); - boolean result = deviceController.pushBamData(dataMsg.owner, - RaspberrypiConstants.DEVICE_TYPE, - dataMsg.deviceId, - System.currentTimeMillis(), "DeviceData", - temperature, - DataStreamDefinitions.StreamTypeLabel.TEMPERATURE); - if (!result) { - response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - } - - } catch (UnauthorizedException e) { - response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(SUPER_TENANT, true); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + Object metdaData[] = {dataMsg.owner, RaspberrypiConstants.DEVICE_TYPE, dataMsg.deviceId, + System.currentTimeMillis()}; + Object payloadData[] = {temperature}; + try { + deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", + metdaData, new Object[0], payloadData); + } catch (DataPublisherConfigurationException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } finally { + PrivilegedCarbonContext.endTenantFlow(); } } } diff --git a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/util/DeviceJSON.java b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/util/DeviceJSON.java index c44de244..e8e4e479 100644 --- a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/util/DeviceJSON.java +++ b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/util/DeviceJSON.java @@ -14,5 +14,5 @@ public class DeviceJSON { @XmlElement(required = true) public String reply; @XmlElement public Long time; @XmlElement public String key; - @XmlElement public String value; + @XmlElement public float value; } diff --git a/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/pom.xml b/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/pom.xml index 12abd2ff..c62b182e 100644 --- a/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/pom.xml +++ b/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/pom.xml @@ -21,29 +21,35 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + provided org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + provided org.apache.cxf cxf-rt-frontend-jaxws + provided org.apache.cxf cxf-rt-frontend-jaxrs + provided org.apache.cxf cxf-rt-transports-http + provided org.eclipse.paho mqtt-client + provided @@ -55,10 +61,12 @@ org.wso2.carbon.device.mgt.iot org.wso2.carbon.device.mgt.iot.common + provided org.wso2.carbon.device.mgt.iot.server.sample org.wso2.carbon.device.mgt.iot.sample.sensebot.plugin.impl + provided @@ -72,15 +80,18 @@ javax javaee-web-api + provided javax.ws.rs jsr311-api + provided commons-httpclient.wso2 commons-httpclient + provided