Fixing MQTT adpater and analytics resources for androidsense userstory

Jasintha 8 years ago
parent 7bc6941530
commit b04b58324a

@ -33,6 +33,9 @@
} else if(action === 'getData'){
print(providerAPI.getData(id, type, timeFrom, timeTo));
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 tableName = "ORG_WSO2_GEO_FUSEDSPATIALEVENT";
var alertTable = "ORG_WSO2_GEO_ALERTSNOTIFICATION";
var typeMap = {
"bool": "string",
@ -130,9 +131,9 @@ var getConfig, validate, getMode, getSchema, getData, registerCallBackforPush;
"query": luceneQuery,
"start": 0,
"count": limit,
"sortBy" : [{
"field" : "timeStamp",
"sortType" : "ASC"
"sortBy": [{
"field": "timeStamp",
"sortType": "ASC"
}]
};
result = connector.search(loggedInUser, tableName, stringify(filter)).getMessage();
@ -151,4 +152,28 @@ var getConfig, validate, getMode, getSchema, getData, registerCallBackforPush;
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,38 +509,43 @@ function removeGeoFence(geoFenceElement, id) {
}
function getAlertsHistory(objectId) {
$.getJSON("/portal/store/carbon.super/fs/gadget/geo-dashboard/controllers/get_alerts_history.jag?objectId=" + objectId, function (data) {
var alertsContainer = $('#showAlertsArea').empty();
$.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
switch (val.STATE) {
case "NORMAL":
$.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();
$.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
switch (val.STATE) {
case "NORMAL":
// $(alertDOMElement).addClass("list-group-item list-group-item-info");
return;
case "WARNING":
$(alertDOMElement).addClass("list-group-item list-group-item-warning");
break;
case "ALERTED":
$(alertDOMElement).addClass("list-group-item list-group-item-danger");
break;
case "OFFLINE":
$(alertDOMElement).addClass("list-group-item list-group-item-success");
break;
}
$(alertDOMElement).html(val.INFORMATION);
$(alertDOMElement).css({marginTop: "5px"});
$(alertDOMElement).attr('onClick', 'showAlertInMap(this)');
// Set HTML5 data attributes for later use
$(alertDOMElement).attr('data-id', val.ID);
$(alertDOMElement).attr('data-latitude', val.LATITUDE);
$(alertDOMElement).attr('data-longitude', val.LONGITUDE);
$(alertDOMElement).attr('data-state', val.STATE);
$(alertDOMElement).attr('data-information', val.INFORMATION);
alertsContainer.append(alertDOMElement);
});
return;
case "WARNING":
$(alertDOMElement).addClass("list-group-item list-group-item-warning");
break;
case "ALERTED":
$(alertDOMElement).addClass("list-group-item list-group-item-danger");
break;
case "OFFLINE":
$(alertDOMElement).addClass("list-group-item list-group-item-success");
break;
}
$(alertDOMElement).html(val.INFORMATION);
$(alertDOMElement).css({marginTop: "5px"});
$(alertDOMElement).attr('onClick', 'showAlertInMap(this)');
// Set HTML5 data attributes for later use
$(alertDOMElement).attr('data-id', val.ID);
$(alertDOMElement).attr('data-latitude', val.LATITUDE);
$(alertDOMElement).attr('data-longitude', val.LONGITUDE);
$(alertDOMElement).attr('data-state', val.STATE);
$(alertDOMElement).attr('data-information', val.INFORMATION);
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.
-->
<artifact name="Geo-Publisher-RDBMS-GeoAlertNotifications" version="1.0.0" type="event/publisher" serverRole="GeoDashboard">
<file>Geo-Publisher-RDBMS-GeoAlertNotifications-1.0.0.xml</file>
<artifact name="Geo-Publisher-RDBMS-GeoAlertNotifications" version="1.0.0" type="analytics/eventstore" serverRole="GeoDashboard">
<file>Geo-Publisher-RDBMS-GeoAlertNotifications.xml</file>
</artifact>

@ -27,19 +27,19 @@
android:id="@+id/username"
android:inputType="text"
android:maxLines="1" android:singleLine="true"
/>
android:text="Onely1973.gustr.com@Onely1973" />
<EditText android:id="@+id/password" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/prompt_password"
android:inputType="textPassword"
android:maxLines="1" android:singleLine="true"
/>
android:text="Onely1973@gustr.com" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/hostname"
android:id="@+id/hostname"
android:text="https://localhost:8243"
android:text="http://gateway.api.clouddev.wso2.com"
android:inputType="text"
android:maxLines="1" android:singleLine="true"/>

@ -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"/>
<dependency artifact="android_un_secured_devices_gadget" version="1.0.0" include="true"
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_accelerometer_streams" version="1.0.0" include="true"

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

@ -32,10 +32,10 @@
<url>http://wso2.org</url>
<dependencies>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.input.adapter.core</artifactId>
@ -76,10 +76,10 @@
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>org.wso2.carbon.device.mgt.input.adapter.extension</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.identity.jwt.client.extension</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.identity.jwt.client.extension</artifactId>
</dependency>
</dependencies>
<build>
@ -133,18 +133,22 @@
org.apache.http.impl.client;version="${httpclient.version.range}",
org.json.simple.*,
com.jayway.jsonpath.*,
org.wso2.carbon.identity.jwt.client.extension.*,
javax.net.ssl,
org.apache.commons.codec.binary,
org.apache.commons.logging,
org.apache.http.entity,
org.osgi.framework,
org.osgi.service.component,
org.osgi.service.http,
org.wso2.carbon.context,
org.wso2.carbon.core,
org.wso2.carbon.device.mgt.input.adapter.extension,
org.wso2.carbon.user.api
org.wso2.carbon.identity.jwt.client.extension.*,
javax.net.ssl,
org.apache.commons.codec.binary,
org.apache.commons.logging,
org.apache.http.entity,
org.osgi.framework,
org.osgi.service.component,
org.osgi.service.http,
org.wso2.carbon.context,
org.wso2.carbon.core,
org.wso2.carbon.device.mgt.input.adapter.extension,
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>
</instructions>
</configuration>

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

@ -17,6 +17,7 @@
*/
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.LogFactory;
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.mqtt.MQTTEventAdapterFactory;
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.utils.ConfigurationContextService;
/**
* @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"
* bind="setJWTClientManagerService"
* 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 {
@ -80,4 +92,21 @@ public class InputAdapterServiceComponent {
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;
import org.apache.axis2.context.ConfigurationContext;
import org.osgi.service.http.HttpService;
import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionService;
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.
@ -26,6 +28,8 @@ public final class InputAdapterServiceDataHolder {
private static HttpService httpService;
private static InputAdapterExtensionService inputAdapterExtensionService;
private static JWTClientManagerService jwtClientManagerService;
private static InputEventAdapterService inputEventAdapterService;
private static ConfigurationContext mainServerConfigContext;
private InputAdapterServiceDataHolder() {
}
@ -55,4 +59,20 @@ public final class 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;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -33,10 +34,12 @@ import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.wso2.carbon.context.PrivilegedCarbonContext;
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.ContentTransformer;
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.event.input.adapter.core.InputEventAdapterConfiguration;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener;
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterRuntimeException;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
@ -63,26 +66,29 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
private MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration;
private String topic;
private int tenantId;
private String tenantDomain;
private boolean connectionSucceeded = false;
ContentValidator contentValidator;
ContentTransformer contentTransformer;
private ContentValidator contentValidator;
private ContentTransformer contentTransformer;
private InputEventAdapterConfiguration inputEventAdapterConfiguration;
private InputEventAdapterListener eventAdapterListener = null;
public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration,
String topic, String mqttClientId,
InputEventAdapterListener inputEventAdapterListener, int tenantId) {
String topic, InputEventAdapterConfiguration inputEventAdapterConfiguration,
InputEventAdapterListener inputEventAdapterListener, String tenantDomain) {
String mqttClientId = inputEventAdapterConfiguration.getProperties()
.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID);
if(mqttClientId == null || mqttClientId.trim().isEmpty()){
mqttClientId = MqttClient.generateClientId();
}
this.inputEventAdapterConfiguration = inputEventAdapterConfiguration;
this.mqttBrokerConnectionConfiguration = mqttBrokerConnectionConfiguration;
this.cleanSession = mqttBrokerConnectionConfiguration.isCleanSession();
int keepAlive = mqttBrokerConnectionConfiguration.getKeepAlive();
this.topic = PropertyUtils.replaceTenantDomainProperty(topic);
this.eventAdapterListener = inputEventAdapterListener;
this.tenantId = tenantId;
this.tenantDomain = tenantDomain;
//SORTING messages until the server fetches them
String temp_directory = System.getProperty("java.io.tmpdir");
@ -145,7 +151,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
if (!mqttBrokerConnectionConfiguration.isGlobalCredentailSet()) {
registrationProfile.setClientName(MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
+ mqttBrokerConnectionConfiguration.getAdapterName() +
"_" + tenantId);
"_" + tenantDomain);
registrationProfile.setIsSaasApp(false);
} else {
registrationProfile.setClientName(MQTTEventAdapterConstants.APPLICATION_NAME_PREFIX
@ -186,6 +192,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
}
mqttClient.connect(connectionOptions);
mqttClient.subscribe(topic);
}
public void stopListener(String adapterName) {
@ -218,7 +225,12 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
log.debug(msgText);
}
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()) {
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);
contentInfo = contentValidator.validate(msgText, dynamicProperties);
if (contentInfo != null && contentInfo.isValidContent()) {
eventAdapterListener.onEvent(contentInfo.getMessage());
inputEventAdapterListener.onEvent(contentInfo.getMessage());
}
} else {
eventAdapterListener.onEvent(msgText);
inputEventAdapterListener.onEvent(msgText);
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
@ -276,7 +288,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
private String getToken(String clientId, String clientSecret)
throws UserStoreException, JWTClientException {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
try {
String scopes = mqttBrokerConnectionConfiguration.getBrokerScopes();
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/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/reciever);\
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.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}/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}/datasources/,target:${installFolder}/../../conf/datasources/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\
@ -28,4 +31,4 @@ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../dep
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.platform.configuration);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.realtime.analytics-view);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/android_sense.car);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/devicetypes/android_sense.xml);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/devicetypes/android_sense.xml);\

@ -17,11 +17,12 @@
~ 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">
<property name="topic">${tenant-domain}/android_sense/+/data</property>
<property name="contentValidator">iot-mqtt</property>
<property name="cleanSession">true</property>
<property name="clientId">android_sense_receiver-${tenant-domain}</property>
</from>
<mapping customMapping="disable" type="json"/>
<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