Merge pull request #644 from Jasintha/cloud-3.1.0

Fixing MQTT adapter and analytics resources for android-sense user story
Ayyoob Hamza 8 years ago committed by GitHub
commit c386f562eb

@ -33,6 +33,9 @@
} else if(action === 'getData'){ } else if(action === 'getData'){
print(providerAPI.getData(id, type, timeFrom, timeTo)); print(providerAPI.getData(id, type, timeFrom, timeTo));
return; return;
} else if(action === 'getAlerts'){
print(providerAPI.getAlerts(id));
return;
} }
}()); }());

@ -34,6 +34,7 @@ var getConfig, validate, getMode, getSchema, getData, registerCallBackforPush;
var JS_MIN_VALUE = "-9007199254740992"; var JS_MIN_VALUE = "-9007199254740992";
var tableName = "ORG_WSO2_GEO_FUSEDSPATIALEVENT"; var tableName = "ORG_WSO2_GEO_FUSEDSPATIALEVENT";
var alertTable = "ORG_WSO2_GEO_ALERTSNOTIFICATION";
var typeMap = { var typeMap = {
"bool": "string", "bool": "string",
@ -151,4 +152,28 @@ var getConfig, validate, getMode, getSchema, getData, registerCallBackforPush;
return data; return data;
}; };
getAlerts = function (deviceId) {
var limit = 50;
var result;
//if there's a filter present, we should perform a Lucene search instead of reading the table
var luceneQuery = 'id:"' + deviceId;
var filter = {
"query": luceneQuery,
"start": 0,
"count": limit,
"sortBy": [{
"field": "timeStamp",
"sortType": "ASC"
}]
};
result = connector.search(loggedInUser, tableName, stringify(filter)).getMessage();
result = JSON.parse(result);
var data = [];
for (var i = 0; i < result.length; i++) {
var values = result[i].values;
data.push(values);
}
return data;
};
}()); }());

@ -509,11 +509,15 @@ function removeGeoFence(geoFenceElement, id) {
} }
function getAlertsHistory(objectId) { function getAlertsHistory(objectId) {
$.getJSON("/portal/store/carbon.super/fs/gadget/geo-dashboard/controllers/get_alerts_history.jag?objectId=" + objectId, function (data) { $.ajax({
url: '/portal/store/carbon.super/fs/gadget/geo-dashboard/controllers/gadget-controller.jag?action=getAlerts&id=' + objectId,
method: "GET",
contentType: "application/json",
async: false,
success: function (data) {
var alertsContainer = $('#showAlertsArea').empty(); var alertsContainer = $('#showAlertsArea').empty();
$.each(data, function (key, val) { $.each(data, function (key, val) {
var alertDOMElement = document.createElement('a'); // Reason for using document.createElement (performance issue) http://stackoverflow.com/questions/268490/jquery-document-createelement-equivalent var alertDOMElement = document.createElement('a'); // Reason for using document.createElement (performance issue) http://stackoverflow.com/questions/268490/jquery-document-createelement-equivalent
switch (val.STATE) { switch (val.STATE) {
case "NORMAL": case "NORMAL":
// $(alertDOMElement).addClass("list-group-item list-group-item-info"); // $(alertDOMElement).addClass("list-group-item list-group-item-info");
@ -541,6 +545,7 @@ function getAlertsHistory(objectId) {
alertsContainer.append(alertDOMElement); alertsContainer.append(alertDOMElement);
}); });
}
}); });
} }

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<eventPublisher name="Geo-Publisher-RDBMS-GeoAlertNotifications"
statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
<from streamName="org.wso2.geo.AlertsNotifications" version="1.0.0"/>
<mapping customMapping="enable" type="map">
<property>
<from name="id"/>
<to name="id"/>
</property>
<property>
<from name="state"/>
<to name="state"/>
</property>
<property>
<from name="information"/>
<to name="information"/>
</property>
<property>
<from name="timeStamp"/>
<to name="timeStamp"/>
</property>
<property>
<from name="longitude"/>
<to name="longitude"/>
</property>
<property>
<from name="latitude"/>
<to name="latitude"/>
</property>
</mapping>
<to eventAdapterType="rdbms">
<property name="datasource.name">WSO2_GEO_DB</property>
<property name="table.name">alerts_history</property>
<property name="execution.mode">insert</property>
<property name="update.keys"/>
</to>
</eventPublisher>

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<EventStoreConfiguration>
<TableSchema>
<ColumnDefinition>
<Name>id</Name>
<IsFacet>false</IsFacet>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>STRING</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>state</Name>
<IsFacet>false</IsFacet>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>STRING</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>information</Name>
<IsFacet>false</IsFacet>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>STRING</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>timeStamp</Name>
<IsFacet>false</IsFacet>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>LONG</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>latitude</Name>
<IsFacet>false</IsFacet>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>DOUBLE</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>longitude</Name>
<IsFacet>false</IsFacet>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>DOUBLE</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>type</Name>
<IsFacet>false</IsFacet>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>STRING</Type>
</ColumnDefinition>
</TableSchema>
<Source>
<StreamId>Geo-Publisher-RDBMS-GeoAlertNotifications:1.0.0</StreamId>
</Source>
<MergeSchema>false</MergeSchema>
<RecordStoreName>EVENT_STORE</RecordStoreName>
</EventStoreConfiguration>

@ -16,6 +16,6 @@
~ under the License. ~ under the License.
--> -->
<artifact name="Geo-Publisher-RDBMS-GeoAlertNotifications" version="1.0.0" type="event/publisher" serverRole="GeoDashboard"> <artifact name="Geo-Publisher-RDBMS-GeoAlertNotifications" version="1.0.0" type="analytics/eventstore" serverRole="GeoDashboard">
<file>Geo-Publisher-RDBMS-GeoAlertNotifications-1.0.0.xml</file> <file>Geo-Publisher-RDBMS-GeoAlertNotifications.xml</file>
</artifact> </artifact>

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<artifact name="android_sense_receiver" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer">
<file>android_sense_receiver.xml</file>
</artifact>

@ -174,7 +174,6 @@
serverRole="DataAnalyticsServer"/> serverRole="DataAnalyticsServer"/>
<dependency artifact="android_un_secured_devices_gadget" version="1.0.0" include="true" <dependency artifact="android_un_secured_devices_gadget" version="1.0.0" include="true"
serverRole="DataAnalyticsServer"/> serverRole="DataAnalyticsServer"/>
<dependency artifact="android_sense_receiver" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="android_sense_publisher" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="android_sense_publisher" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="android_accelerometer_streams" version="1.0.0" include="true" <dependency artifact="android_accelerometer_streams" version="1.0.0" include="true"

@ -40,7 +40,7 @@ public class MQTTContentValidator implements ContentValidator {
@Override @Override
public String getType() { public String getType() {
return null; return CDMF_MQTT_CONTENT_VALIDATOR;
} }
@Override @Override

@ -144,7 +144,11 @@
org.wso2.carbon.context, org.wso2.carbon.context,
org.wso2.carbon.core, org.wso2.carbon.core,
org.wso2.carbon.device.mgt.input.adapter.extension, org.wso2.carbon.device.mgt.input.adapter.extension,
org.wso2.carbon.user.api org.wso2.carbon.user.api,
org.wso2.carbon.utils.multitenancy,
org.apache.axis2.context,
org.wso2.carbon.core.multitenancy.utils,
org.wso2.carbon.utils
</Import-Package> </Import-Package>
</instructions> </instructions>
</configuration> </configuration>

@ -18,6 +18,7 @@
package org.wso2.carbon.device.mgt.input.adapter.mqtt; package org.wso2.carbon.device.mgt.input.adapter.mqtt;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.internal.InputAdapterServiceDataHolder;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTAdapterListener; import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTAdapterListener;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTEventAdapterConstants; import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTEventAdapterConstants;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTBrokerConnectionConfiguration; import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTBrokerConnectionConfiguration;
@ -26,6 +27,7 @@ import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener;
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException; import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
import org.wso2.carbon.event.input.adapter.core.exception.TestConnectionNotSupportedException; import org.wso2.carbon.event.input.adapter.core.exception.TestConnectionNotSupportedException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -54,10 +56,12 @@ public class MQTTEventAdapter implements InputEventAdapter {
try { try {
mqttBrokerConnectionConfiguration = new MQTTBrokerConnectionConfiguration(eventAdapterConfiguration mqttBrokerConnectionConfiguration = new MQTTBrokerConnectionConfiguration(eventAdapterConfiguration
,globalProperties); ,globalProperties);
String topic = eventAdapterConfiguration.getProperties().get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_TOPIC);
String tenantDomain = topic.split("/")[0];
mqttAdapterListener = new MQTTAdapterListener(mqttBrokerConnectionConfiguration mqttAdapterListener = new MQTTAdapterListener(mqttBrokerConnectionConfiguration
,eventAdapterConfiguration.getProperties().get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_TOPIC) ,topic
,eventAdapterConfiguration.getProperties().get(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID) ,eventAdapterConfiguration
,eventAdapterListener, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); ,eventAdapterListener, tenantDomain);
} catch (Throwable t) { } catch (Throwable t) {
throw new InputEventAdapterException(t.getMessage(), t); throw new InputEventAdapterException(t.getMessage(), t);
} }
@ -77,6 +81,10 @@ public class MQTTEventAdapter implements InputEventAdapter {
@Override @Override
public void connect() { public void connect() {
if (!PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
return;
}
if (!mqttAdapterListener.isConnectionInitialized()) { if (!mqttAdapterListener.isConnectionInitialized()) {
mqttAdapterListener.createConnection(); mqttAdapterListener.createConnection();
} }

@ -17,6 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.input.adapter.mqtt.internal; package org.wso2.carbon.device.mgt.input.adapter.mqtt.internal;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
@ -24,7 +25,9 @@ import org.osgi.service.http.HttpService;
import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionService; import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionService;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.MQTTEventAdapterFactory; import org.wso2.carbon.device.mgt.input.adapter.mqtt.MQTTEventAdapterFactory;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterFactory; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterFactory;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.wso2.carbon.utils.ConfigurationContextService;
/** /**
* @scr.component name="input.iot.mqtt.AdapterService.component" immediate="true" * @scr.component name="input.iot.mqtt.AdapterService.component" immediate="true"
@ -38,6 +41,15 @@ import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerSer
* policy="dynamic" * policy="dynamic"
* bind="setJWTClientManagerService" * bind="setJWTClientManagerService"
* unbind="unsetJWTClientManagerService" * unbind="unsetJWTClientManagerService"
* @scr.reference name="input.adapter.service" interface="org.wso2.carbon.event.input.adapter.core.InputEventAdapterService"
* cardinality="1..1"
* policy="dynamic"
* bind="setInputEventAdapterService"
* unbind="unsetInputEventAdapterService"
* @scr.reference name="config.context.service"
* interface="org.wso2.carbon.utils.ConfigurationContextService"
* cardinality="1..1" policy="dynamic" bind="setConfigurationContextService"
* unbind="unsetConfigurationContextService"
*/ */
public class InputAdapterServiceComponent { public class InputAdapterServiceComponent {
@ -80,4 +92,21 @@ public class InputAdapterServiceComponent {
InputAdapterServiceDataHolder.setJwtClientManagerService(null); InputAdapterServiceDataHolder.setJwtClientManagerService(null);
} }
protected void setInputEventAdapterService(InputEventAdapterService inputEventAdapterService) {
InputAdapterServiceDataHolder.setInputEventAdapterService(inputEventAdapterService);
}
protected void unsetInputEventAdapterService(InputEventAdapterService inputEventAdapterService) {
InputAdapterServiceDataHolder.setInputEventAdapterService(null);
}
protected void setConfigurationContextService(ConfigurationContextService contextService) {
ConfigurationContext serverConfigContext = contextService.getServerConfigContext();
InputAdapterServiceDataHolder.setMainServerConfigContext(serverConfigContext);
}
protected void unsetConfigurationContextService(ConfigurationContextService contextService) {
InputAdapterServiceDataHolder.setMainServerConfigContext(null);
}
} }

@ -14,9 +14,11 @@
*/ */
package org.wso2.carbon.device.mgt.input.adapter.mqtt.internal; package org.wso2.carbon.device.mgt.input.adapter.mqtt.internal;
import org.apache.axis2.context.ConfigurationContext;
import org.osgi.service.http.HttpService; import org.osgi.service.http.HttpService;
import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionService; import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionService;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService;
/** /**
* common place to hold some OSGI service references. * common place to hold some OSGI service references.
@ -26,6 +28,8 @@ public final class InputAdapterServiceDataHolder {
private static HttpService httpService; private static HttpService httpService;
private static InputAdapterExtensionService inputAdapterExtensionService; private static InputAdapterExtensionService inputAdapterExtensionService;
private static JWTClientManagerService jwtClientManagerService; private static JWTClientManagerService jwtClientManagerService;
private static InputEventAdapterService inputEventAdapterService;
private static ConfigurationContext mainServerConfigContext;
private InputAdapterServiceDataHolder() { private InputAdapterServiceDataHolder() {
} }
@ -55,4 +59,20 @@ public final class InputAdapterServiceDataHolder {
JWTClientManagerService jwtClientManagerService) { JWTClientManagerService jwtClientManagerService) {
InputAdapterServiceDataHolder.jwtClientManagerService = jwtClientManagerService; InputAdapterServiceDataHolder.jwtClientManagerService = jwtClientManagerService;
} }
public static InputEventAdapterService getInputEventAdapterService() {
return inputEventAdapterService;
}
public static void setInputEventAdapterService(InputEventAdapterService inputEventAdapterService) {
InputAdapterServiceDataHolder.inputEventAdapterService = inputEventAdapterService;
}
public static ConfigurationContext getMainServerConfigContext() {
return mainServerConfigContext;
}
public static void setMainServerConfigContext(ConfigurationContext mainServerConfigContext) {
InputAdapterServiceDataHolder.mainServerConfigContext = mainServerConfigContext;
}
} }

@ -17,6 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.input.adapter.mqtt.util; package org.wso2.carbon.device.mgt.input.adapter.mqtt.util;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -33,10 +34,12 @@ import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.ServerStatus; import org.wso2.carbon.core.ServerStatus;
import org.wso2.carbon.core.multitenancy.utils.TenantAxisUtils;
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentInfo; import org.wso2.carbon.device.mgt.input.adapter.extension.ContentInfo;
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer; import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer;
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator; import org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.internal.InputAdapterServiceDataHolder; import org.wso2.carbon.device.mgt.input.adapter.mqtt.internal.InputAdapterServiceDataHolder;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener;
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterRuntimeException; import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterRuntimeException;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
@ -63,26 +66,29 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
private MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration; private MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration;
private String topic; private String topic;
private int tenantId; private String tenantDomain;
private boolean connectionSucceeded = false; private boolean connectionSucceeded = false;
ContentValidator contentValidator; private ContentValidator contentValidator;
ContentTransformer contentTransformer; private ContentTransformer contentTransformer;
private InputEventAdapterConfiguration inputEventAdapterConfiguration;
private InputEventAdapterListener eventAdapterListener = null; private InputEventAdapterListener eventAdapterListener = null;
public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration, public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration,
String topic, String mqttClientId, String topic, InputEventAdapterConfiguration inputEventAdapterConfiguration,
InputEventAdapterListener inputEventAdapterListener, int tenantId) { InputEventAdapterListener inputEventAdapterListener, String tenantDomain) {
String mqttClientId = inputEventAdapterConfiguration.getProperties()
.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID);
if(mqttClientId == null || mqttClientId.trim().isEmpty()){ if(mqttClientId == null || mqttClientId.trim().isEmpty()){
mqttClientId = MqttClient.generateClientId(); mqttClientId = MqttClient.generateClientId();
} }
this.inputEventAdapterConfiguration = inputEventAdapterConfiguration;
this.mqttBrokerConnectionConfiguration = mqttBrokerConnectionConfiguration; this.mqttBrokerConnectionConfiguration = mqttBrokerConnectionConfiguration;
this.cleanSession = mqttBrokerConnectionConfiguration.isCleanSession(); this.cleanSession = mqttBrokerConnectionConfiguration.isCleanSession();
int keepAlive = mqttBrokerConnectionConfiguration.getKeepAlive(); int keepAlive = mqttBrokerConnectionConfiguration.getKeepAlive();
this.topic = PropertyUtils.replaceTenantDomainProperty(topic); this.topic = PropertyUtils.replaceTenantDomainProperty(topic);
this.eventAdapterListener = inputEventAdapterListener; this.eventAdapterListener = inputEventAdapterListener;
this.tenantId = tenantId; this.tenantDomain = tenantDomain;
//SORTING messages until the server fetches them //SORTING messages until the server fetches them
String temp_directory = System.getProperty("java.io.tmpdir"); String temp_directory = System.getProperty("java.io.tmpdir");
@ -145,7 +151,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
if (!mqttBrokerConnectionConfiguration.isGlobalCredentailSet()) { if (!mqttBrokerConnectionConfiguration.isGlobalCredentailSet()) {
registrationProfile.setClientName(MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX registrationProfile.setClientName(MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
+ mqttBrokerConnectionConfiguration.getAdapterName() + + mqttBrokerConnectionConfiguration.getAdapterName() +
"_" + tenantId); "_" + tenantDomain);
registrationProfile.setIsSaasApp(false); registrationProfile.setIsSaasApp(false);
} else { } else {
registrationProfile.setClientName(MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX registrationProfile.setClientName(MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
@ -186,6 +192,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
} }
mqttClient.connect(connectionOptions); mqttClient.connect(connectionOptions);
mqttClient.subscribe(topic); mqttClient.subscribe(topic);
} }
public void stopListener(String adapterName) { public void stopListener(String adapterName) {
@ -218,7 +225,12 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
log.debug(msgText); log.debug(msgText);
} }
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
TenantAxisUtils.getTenantConfigurationContext(tenantDomain,InputAdapterServiceDataHolder.getMainServerConfigContext());
InputEventAdapterListener inputEventAdapterListener = InputAdapterServiceDataHolder
.getInputEventAdapterService().getInputAdapterRuntime(PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getTenantId(), inputEventAdapterConfiguration.getName());
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Event received in MQTT Event Adapter - " + msgText); log.debug("Event received in MQTT Event Adapter - " + msgText);
@ -231,10 +243,10 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
msgText = (String) contentTransformer.transform(msgText, dynamicProperties); msgText = (String) contentTransformer.transform(msgText, dynamicProperties);
contentInfo = contentValidator.validate(msgText, dynamicProperties); contentInfo = contentValidator.validate(msgText, dynamicProperties);
if (contentInfo != null && contentInfo.isValidContent()) { if (contentInfo != null && contentInfo.isValidContent()) {
eventAdapterListener.onEvent(contentInfo.getMessage()); inputEventAdapterListener.onEvent(contentInfo.getMessage());
} }
} else { } else {
eventAdapterListener.onEvent(msgText); inputEventAdapterListener.onEvent(msgText);
} }
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
@ -276,7 +288,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
private String getToken(String clientId, String clientSecret) private String getToken(String clientId, String clientSecret)
throws UserStoreException, JWTClientException { throws UserStoreException, JWTClientException {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
try { try {
String scopes = mqttBrokerConnectionConfiguration.getBrokerScopes(); String scopes = mqttBrokerConnectionConfiguration.getBrokerScopes();
String username = mqttBrokerConnectionConfiguration.getUsername(); String username = mqttBrokerConnectionConfiguration.getUsername();

@ -2,10 +2,13 @@ instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/devicetypes/);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/devicetypes/);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/devicetypes/android_sense/);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/devicetypes/android_sense/);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/devicetypes/android_sense/reciever);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/carbonapps/);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/carbonapps/);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/carbonapps/,target:${installFolder}/../../resources/devicetypes/android_sense/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/carbonapps/,target:${installFolder}/../../resources/devicetypes/android_sense/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/receiver/,target:${installFolder}/../../resources/devicetypes/android_sense/receiver/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/streams/,target:${installFolder}/../../resources/devicetypes/android_sense/streams/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/android_sense,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/android_sense,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/datasources/,target:${installFolder}/../../conf/datasources/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/datasources/,target:${installFolder}/../../conf/datasources/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\

@ -17,11 +17,12 @@
~ under the License. ~ under the License.
--> -->
<eventReceiver name="android_sense_receiver" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver"> <eventReceiver name="android_sense_receiver-${tenant-domain}" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
<from eventAdapterType="oauth-mqtt"> <from eventAdapterType="oauth-mqtt">
<property name="topic">${tenant-domain}/android_sense/+/data</property> <property name="topic">${tenant-domain}/android_sense/+/data</property>
<property name="contentValidator">iot-mqtt</property> <property name="contentValidator">iot-mqtt</property>
<property name="cleanSession">true</property> <property name="cleanSession">true</property>
<property name="clientId">android_sense_receiver-${tenant-domain}</property>
</from> </from>
<mapping customMapping="disable" type="json"/> <mapping customMapping="disable" type="json"/>
<to streamName="org.wso2.iot.android.sense" version="1.0.0"/> <to streamName="org.wso2.iot.android.sense" version="1.0.0"/>

@ -0,0 +1,63 @@
{
"name": "org.wso2.iot.android.sense",
"version": "1.0.0",
"nickName": "android_sense_stream",
"description": "This hold the device type stream of android sense",
"metaData": [
{"name": "owner", "type": "STRING"},
{"name": "deviceId", "type": "STRING"},
{"name": "type", "type": "STRING"},
{"name": "timestamp", "type": "LONG"}
],
"payloadData": [
{"name": "battery", "type": "INT"},
{"name": "battery_state", "type": "STRING"},
{"name": "battery_status", "type": "STRING"},
{"name": "battery_temperature", "type": "INT"},
{"name": "gps_lat", "type": "DOUBLE"},
{"name": "gps_long", "type": "DOUBLE"},
{"name": "accelerometer_x", "type": "FLOAT"},
{"name": "accelerometer_y", "type": "FLOAT"},
{"name": "accelerometer_z", "type": "FLOAT"},
{"name": "speed_limit", "type": "FLOAT"},
{"name": "turn_way", "type": "STRING"},
{"name": "magnetic_x", "type": "FLOAT"},
{"name": "magnetic_y", "type": "FLOAT"},
{"name": "magnetic_z", "type": "FLOAT"},
{"name": "gyroscope_x", "type": "FLOAT"},
{"name": "gyroscope_y", "type": "FLOAT"},
{"name": "gyroscope_z", "type": "FLOAT"},
{"name": "light", "type": "FLOAT"},
{"name": "pressure", "type": "FLOAT"},
{"name": "proximity", "type": "FLOAT"},
{"name": "gravity_x", "type": "FLOAT"},
{"name": "gravity_y", "type": "FLOAT"},
{"name": "gravity_z", "type": "FLOAT"},
{"name": "rotation_x", "type": "FLOAT"},
{"name": "rotation_y", "type": "FLOAT"},
{"name": "rotation_z", "type": "FLOAT"},
{"name": "word", "type": "STRING"},
{"name": "word_sessionId", "type": "STRING"},
{"name": "word_status", "type": "STRING"},
{"name": "beacon_major", "type": "INT"},
{"name": "beacon_minor", "type": "INT"},
{"name": "beacon_proximity", "type": "STRING"},
{"name": "beacon_uuid", "type": "INT"},
{"name": "call_number", "type": "STRING"},
{"name": "call_type", "type": "STRING"},
{"name": "call_start_time", "type": "LONG"},
{"name": "call_end_time", "type": "LONG"},
{"name": "screen_state", "type": "STRING"},
{"name": "audio_playing", "type": "BOOL"},
{"name": "headset_on", "type": "BOOL"},
{"name": "music_volume", "type": "INT"},
{"name": "activity_type", "type": "INT"},
{"name": "confidence", "type": "INT"},
{"name": "sms_number", "type": "STRING"},
{"name": "application_name", "type": "STRING"},
{"name": "action", "type": "STRING"},
{"name": "data_type", "type": "STRING"},
{"name": "data_sent", "type": "LONG"},
{"name": "data_received", "type": "LONG"}
]
}
Loading…
Cancel
Save