mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt-plugins
This commit is contained in:
commit
b33023a770
@ -52,7 +52,6 @@ public class RegisterActivity extends Activity {
|
|||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
private EditText mHostView;
|
private EditText mHostView;
|
||||||
private EditText mMqttPortView;
|
|
||||||
private View mProgressView;
|
private View mProgressView;
|
||||||
private View mLoginFormView;
|
private View mLoginFormView;
|
||||||
private Handler mUiHandler = new Handler();
|
private Handler mUiHandler = new Handler();
|
||||||
@ -71,7 +70,6 @@ public class RegisterActivity extends Activity {
|
|||||||
mUsernameView = (EditText) findViewById(R.id.username);
|
mUsernameView = (EditText) findViewById(R.id.username);
|
||||||
mPasswordView = (EditText) findViewById(R.id.password);
|
mPasswordView = (EditText) findViewById(R.id.password);
|
||||||
mHostView = (EditText) findViewById(R.id.hostname);
|
mHostView = (EditText) findViewById(R.id.hostname);
|
||||||
mMqttPortView = (EditText) findViewById(R.id.mqttPort);
|
|
||||||
AvailableSensorsInDevice availableSensorsInDevice = new AvailableSensorsInDevice(getApplicationContext());
|
AvailableSensorsInDevice availableSensorsInDevice = new AvailableSensorsInDevice(getApplicationContext());
|
||||||
availableSensorsInDevice.setContent();
|
availableSensorsInDevice.setContent();
|
||||||
|
|
||||||
@ -99,7 +97,6 @@ public class RegisterActivity extends Activity {
|
|||||||
final String username = mUsernameView.getText().toString();
|
final String username = mUsernameView.getText().toString();
|
||||||
final String password = mPasswordView.getText().toString();
|
final String password = mPasswordView.getText().toString();
|
||||||
final String hostname = mHostView.getText().toString();
|
final String hostname = mHostView.getText().toString();
|
||||||
String mqttPort = mMqttPortView.getText().toString();
|
|
||||||
boolean cancel = false;
|
boolean cancel = false;
|
||||||
View focusView = null;
|
View focusView = null;
|
||||||
|
|
||||||
@ -124,7 +121,6 @@ public class RegisterActivity extends Activity {
|
|||||||
if (cancel) {
|
if (cancel) {
|
||||||
focusView.requestFocus();
|
focusView.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
final int mqttPortNo= Integer.parseInt(mqttPort);
|
|
||||||
Thread myThread = new Thread(new Runnable() {
|
Thread myThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -143,7 +139,6 @@ public class RegisterActivity extends Activity {
|
|||||||
LocalRegistry.setEnrolled(getApplicationContext(), true);
|
LocalRegistry.setEnrolled(getApplicationContext(), true);
|
||||||
LocalRegistry.addUsername(getApplicationContext(), username);
|
LocalRegistry.addUsername(getApplicationContext(), username);
|
||||||
LocalRegistry.addDeviceId(getApplicationContext(), deviceId);
|
LocalRegistry.addDeviceId(getApplicationContext(), deviceId);
|
||||||
LocalRegistry.addMqttPort(getApplicationContext(), mqttPortNo);
|
|
||||||
MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(getApplicationContext());
|
MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(getApplicationContext());
|
||||||
if (!mqttTransportHandler.isConnected()) {
|
if (!mqttTransportHandler.isConnected()) {
|
||||||
mqttTransportHandler.connect();
|
mqttTransportHandler.connect();
|
||||||
|
|||||||
@ -23,14 +23,12 @@ public class SenseConstants {
|
|||||||
public final static String TOKEN_ISSUER_CONTEXT = "/oauth2";
|
public final static String TOKEN_ISSUER_CONTEXT = "/oauth2";
|
||||||
public final static String API_APPLICATION_REGISTRATION_CONTEXT = "/api-application-registration";
|
public final static String API_APPLICATION_REGISTRATION_CONTEXT = "/api-application-registration";
|
||||||
|
|
||||||
public static final int MQTT_BROKER_PORT = 1883;
|
|
||||||
public static final String EVENT_LISTENER_STARTED = "xxStartedxx";
|
public static final String EVENT_LISTENER_STARTED = "xxStartedxx";
|
||||||
public static final String EVENT_LISTENER_FINISHED = "xxFinishedxx";
|
public static final String EVENT_LISTENER_FINISHED = "xxFinishedxx";
|
||||||
public static final String EVENT_LISTENER_ONGOING = "xxOngoingxx";
|
public static final String EVENT_LISTENER_ONGOING = "xxOngoingxx";
|
||||||
|
|
||||||
public final class Request {
|
public final class Request {
|
||||||
public final static String REQUEST_SUCCESSFUL = "200";
|
public final static String REQUEST_SUCCESSFUL = "200";
|
||||||
public final static String REQUEST_CONFLICT = "409";
|
|
||||||
public final static int MAX_ATTEMPTS = 2;
|
public final static int MAX_ATTEMPTS = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,7 @@ public class DataPublisherService extends Service {
|
|||||||
private static String VALUE_TAG = "value";
|
private static String VALUE_TAG = "value";
|
||||||
public static Context context;
|
public static Context context;
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
@ -70,34 +71,39 @@ public class DataPublisherService extends Service {
|
|||||||
for (SensorData sensorData : sensorDataMap) {
|
for (SensorData sensorData : sensorDataMap) {
|
||||||
Event event = new Event();
|
Event event = new Event();
|
||||||
event.setTimestamp(sensorData.getTimestamp());
|
event.setTimestamp(sensorData.getTimestamp());
|
||||||
|
|
||||||
switch (sensorData.getSensorType()) {
|
switch (sensorData.getSensorType()) {
|
||||||
case Sensor.TYPE_ACCELEROMETER:
|
case Sensor.TYPE_ACCELEROMETER:
|
||||||
event.setAccelerometer(sensorData.getSensorValues());
|
event.setAccelerometer(sensorData.getSensorValues());
|
||||||
|
events.add(event);
|
||||||
break;
|
break;
|
||||||
case Sensor.TYPE_MAGNETIC_FIELD:
|
case Sensor.TYPE_MAGNETIC_FIELD:
|
||||||
event.setMagnetic(sensorData.getSensorValues());
|
event.setMagnetic(sensorData.getSensorValues());
|
||||||
|
events.add(event);
|
||||||
break;
|
break;
|
||||||
case Sensor.TYPE_GYROSCOPE:
|
case Sensor.TYPE_GYROSCOPE:
|
||||||
event.setGyroscope(sensorData.getSensorValues());
|
event.setGyroscope(sensorData.getSensorValues());
|
||||||
|
events.add(event);
|
||||||
break;
|
break;
|
||||||
case Sensor.TYPE_LIGHT:
|
case Sensor.TYPE_LIGHT:
|
||||||
event.setLight(sensorData.getSensorValues()[0]);
|
event.setLight(sensorData.getSensorValues()[0]);
|
||||||
break;
|
break;
|
||||||
case Sensor.TYPE_PRESSURE:
|
case Sensor.TYPE_PRESSURE:
|
||||||
event.setPressure(sensorData.getSensorValues()[0]);
|
event.setPressure(sensorData.getSensorValues()[0]);
|
||||||
|
events.add(event);
|
||||||
break;
|
break;
|
||||||
case Sensor.TYPE_PROXIMITY:
|
case Sensor.TYPE_PROXIMITY:
|
||||||
event.setProximity(sensorData.getSensorValues()[0]);
|
event.setProximity(sensorData.getSensorValues()[0]);
|
||||||
|
events.add(event);
|
||||||
break;
|
break;
|
||||||
case Sensor.TYPE_GRAVITY:
|
case Sensor.TYPE_GRAVITY:
|
||||||
event.setGravity(sensorData.getSensorValues());
|
event.setGravity(sensorData.getSensorValues());
|
||||||
|
events.add(event);
|
||||||
break;
|
break;
|
||||||
case Sensor.TYPE_ROTATION_VECTOR:
|
case Sensor.TYPE_GAME_ROTATION_VECTOR:
|
||||||
event.setGravity(sensorData.getSensorValues());
|
event.setRotation(sensorData.getSensorValues());
|
||||||
|
events.add(event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
events.add(event);
|
|
||||||
}
|
}
|
||||||
SenseDataHolder.resetSensorDataHolder();
|
SenseDataHolder.resetSensorDataHolder();
|
||||||
|
|
||||||
@ -120,7 +126,7 @@ public class DataPublisherService extends Service {
|
|||||||
}
|
}
|
||||||
SenseDataHolder.resetLocationDataHolder();
|
SenseDataHolder.resetLocationDataHolder();
|
||||||
|
|
||||||
//retreive words
|
//retrieve words
|
||||||
ProcessWords.cleanAndPushToWordMap();
|
ProcessWords.cleanAndPushToWordMap();
|
||||||
List<WordData> wordDatMap = SenseDataHolder.getWordDataHolder();
|
List<WordData> wordDatMap = SenseDataHolder.getWordDataHolder();
|
||||||
for (WordData wordData : wordDatMap) {
|
for (WordData wordData : wordDatMap) {
|
||||||
@ -156,7 +162,9 @@ public class DataPublisherService extends Service {
|
|||||||
if (!mqttTransportHandler.isConnected()) {
|
if (!mqttTransportHandler.isConnected()) {
|
||||||
mqttTransportHandler.connect();
|
mqttTransportHandler.connect();
|
||||||
}
|
}
|
||||||
mqttTransportHandler.publishDeviceData(user, deviceId, jsonArray.toString());
|
String topic = "wso2/" + LocalRegistry.getTenantDomain(context) + "/" + SenseConstants
|
||||||
|
.DEVICE_TYPE + "/" + deviceId + "/data";
|
||||||
|
mqttTransportHandler.publishDeviceData(user, deviceId, jsonArray.toString(), topic);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG, "Json Data Parsing Exception", e);
|
Log.e(TAG, "Json Data Parsing Exception", e);
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTrans
|
|||||||
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
|
||||||
import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
|
import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
|
||||||
import org.wso2.carbon.iot.android.sense.speech.detector.util.ProcessWords;
|
import org.wso2.carbon.iot.android.sense.speech.detector.util.ProcessWords;
|
||||||
|
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -46,7 +47,7 @@ import java.util.Arrays;
|
|||||||
public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
|
public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
|
||||||
private static final String TAG = "AndroidSenseMQTTHandler";
|
private static final String TAG = "AndroidSenseMQTTHandler";
|
||||||
private static volatile AndroidSenseMQTTHandler mInstance;
|
private static volatile AndroidSenseMQTTHandler mInstance;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a sigleton Instance
|
* return a sigleton Instance
|
||||||
@ -54,6 +55,7 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
|
|||||||
* @return AndroidSenseMQTTHandler.
|
* @return AndroidSenseMQTTHandler.
|
||||||
*/
|
*/
|
||||||
public static AndroidSenseMQTTHandler getInstance(Context context) {
|
public static AndroidSenseMQTTHandler getInstance(Context context) {
|
||||||
|
context = context;
|
||||||
if (mInstance == null) {
|
if (mInstance == null) {
|
||||||
Class clazz = AndroidSenseMQTTHandler.class;
|
Class clazz = AndroidSenseMQTTHandler.class;
|
||||||
synchronized (clazz) {
|
synchronized (clazz) {
|
||||||
@ -157,7 +159,7 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void publishDeviceData(String... publishData) throws TransportHandlerException {
|
public void publishDeviceData(String... publishData) throws TransportHandlerException {
|
||||||
if (publishData.length != 3) {
|
if (publishData.length != 4) {
|
||||||
String errorMsg = "Incorrect number of arguments received to SEND-MQTT Message. " +
|
String errorMsg = "Incorrect number of arguments received to SEND-MQTT Message. " +
|
||||||
"Need to be [owner, deviceId, content]";
|
"Need to be [owner, deviceId, content]";
|
||||||
Log.e(TAG, errorMsg);
|
Log.e(TAG, errorMsg);
|
||||||
@ -169,7 +171,7 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
|
|||||||
String resource = publishData[2];
|
String resource = publishData[2];
|
||||||
|
|
||||||
MqttMessage pushMessage = new MqttMessage();
|
MqttMessage pushMessage = new MqttMessage();
|
||||||
String publishTopic = "wso2/" + SenseConstants.DEVICE_TYPE + "/" + deviceId + "/data";
|
String publishTopic = publishData[3];
|
||||||
String actualMessage = resource;
|
String actualMessage = resource;
|
||||||
pushMessage.setPayload(actualMessage.getBytes(StandardCharsets.UTF_8));
|
pushMessage.setPayload(actualMessage.getBytes(StandardCharsets.UTF_8));
|
||||||
pushMessage.setQos(DEFAULT_MQTT_QUALITY_OF_SERVICE);
|
pushMessage.setQos(DEFAULT_MQTT_QUALITY_OF_SERVICE);
|
||||||
|
|||||||
@ -77,9 +77,10 @@ public abstract class MQTTTransportHandler implements MqttCallback, TransportHan
|
|||||||
String username = LocalRegistry.getUsername(context);
|
String username = LocalRegistry.getUsername(context);
|
||||||
String deviceId = LocalRegistry.getDeviceId(context);
|
String deviceId = LocalRegistry.getDeviceId(context);
|
||||||
this.clientId = deviceId + ":" + SenseConstants.DEVICE_TYPE;
|
this.clientId = deviceId + ":" + SenseConstants.DEVICE_TYPE;
|
||||||
this.subscribeTopic = "wso2/" + SenseConstants.DEVICE_TYPE + "/" + deviceId + "/command/#";
|
this.subscribeTopic = "wso2/" + LocalRegistry.getTenantDomain(context)+ "/" + SenseConstants.DEVICE_TYPE + "/" +
|
||||||
|
deviceId + "/command/#";
|
||||||
this.clientWillTopic = DISCONNECTION_WILL_TOPIC_PREFIX + SenseConstants.DEVICE_TYPE;
|
this.clientWillTopic = DISCONNECTION_WILL_TOPIC_PREFIX + SenseConstants.DEVICE_TYPE;
|
||||||
this.mqttBrokerEndPoint = "tcp://" + LocalRegistry.getServerHost(context) + ":" + LocalRegistry.getMqttPort(context);
|
this.mqttBrokerEndPoint = LocalRegistry.getMqttEndpoint(context);
|
||||||
this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL;
|
this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL;
|
||||||
this.initMQTTClient();
|
this.initMQTTClient();
|
||||||
setUsernameAndPassword(LocalRegistry.getAccessToken(context), "");
|
setUsernameAndPassword(LocalRegistry.getAccessToken(context), "");
|
||||||
|
|||||||
@ -70,7 +70,6 @@ public class SensorDataReader extends DataReader implements SensorEventListener
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.d(TAG, "error on sensors");
|
Log.d(TAG, "error on sensors");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
mSensorManager.unregisterListener(this);
|
mSensorManager.unregisterListener(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -182,7 +182,8 @@ public class ActivitySelectSensor extends AppCompatActivity
|
|||||||
LocalRegistry.removeServerURL(getApplicationContext());
|
LocalRegistry.removeServerURL(getApplicationContext());
|
||||||
LocalRegistry.removeAccessToken(getApplicationContext());
|
LocalRegistry.removeAccessToken(getApplicationContext());
|
||||||
LocalRegistry.removeRefreshToken(getApplicationContext());
|
LocalRegistry.removeRefreshToken(getApplicationContext());
|
||||||
LocalRegistry.removeMqttPort(getApplicationContext());
|
LocalRegistry.removeMqttEndpoint(getApplicationContext());
|
||||||
|
LocalRegistry.removeTenantDomain(getApplicationContext());
|
||||||
LocalRegistry.setExist(false);
|
LocalRegistry.setExist(false);
|
||||||
//Stop the current running background services.
|
//Stop the current running background services.
|
||||||
stopService(new Intent(this, SenseService.class)); //Stop sensor reading service
|
stopService(new Intent(this, SenseService.class)); //Stop sensor reading service
|
||||||
|
|||||||
@ -34,8 +34,9 @@ public class LocalRegistry {
|
|||||||
private static final String SERVER_HOST_KEY = "serverHostKey";
|
private static final String SERVER_HOST_KEY = "serverHostKey";
|
||||||
private static final String ACCESS_TOKEN_KEY = "accessTokenKey";
|
private static final String ACCESS_TOKEN_KEY = "accessTokenKey";
|
||||||
private static final String REFRESH_TOKEN_KEY = "refreshTokenKey";
|
private static final String REFRESH_TOKEN_KEY = "refreshTokenKey";
|
||||||
private static final String MQTT_PORT_KEY = "mqttPort";
|
private static final String MQTT_ENDPOINT_KEY = "mqttEndpointKey";
|
||||||
private static final String IS_ENROLLED_KEY = "enrolled";
|
private static final String IS_ENROLLED_KEY = "enrolledKey";
|
||||||
|
private static final String TENANT_DOMAIN_KEY = "tenantDomainKey";
|
||||||
private static boolean exists = false;
|
private static boolean exists = false;
|
||||||
private static String username;
|
private static String username;
|
||||||
private static String deviceId;
|
private static String deviceId;
|
||||||
@ -43,8 +44,9 @@ public class LocalRegistry {
|
|||||||
private static MQTTTransportHandler mqttTransportHandler;
|
private static MQTTTransportHandler mqttTransportHandler;
|
||||||
private static String accessToken;
|
private static String accessToken;
|
||||||
private static String refreshToken;
|
private static String refreshToken;
|
||||||
private static int mqttPort;
|
private static String mqttEndpoint;
|
||||||
private static boolean enrolled;
|
private static boolean enrolled;
|
||||||
|
private static String tenantDomain;
|
||||||
|
|
||||||
public static boolean isExist(Context context) {
|
public static boolean isExist(Context context) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
@ -186,29 +188,29 @@ public class LocalRegistry {
|
|||||||
return LocalRegistry.refreshToken;
|
return LocalRegistry.refreshToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addMqttPort(Context context, int port) {
|
public static void addMqttEndpoint(Context context, String endpoint) {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putInt(MQTT_PORT_KEY, port);
|
editor.putString(MQTT_ENDPOINT_KEY, endpoint);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
LocalRegistry.mqttPort = port;
|
LocalRegistry.mqttEndpoint = endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeMqttPort(Context context) {
|
public static void removeMqttEndpoint(Context context) {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.remove(MQTT_PORT_KEY);
|
editor.remove(MQTT_ENDPOINT_KEY);
|
||||||
editor.clear();
|
editor.clear();
|
||||||
editor.commit();
|
editor.commit();
|
||||||
LocalRegistry.mqttPort = 0;
|
LocalRegistry.mqttEndpoint = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMqttPort(Context context) {
|
public static String getMqttEndpoint(Context context) {
|
||||||
if (LocalRegistry.mqttPort == 0) {
|
if (LocalRegistry.mqttEndpoint == null) {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||||
LocalRegistry.mqttPort = sharedpreferences.getInt(MQTT_PORT_KEY, SenseConstants.MQTT_BROKER_PORT);
|
LocalRegistry.mqttEndpoint = sharedpreferences.getString(MQTT_ENDPOINT_KEY, "");
|
||||||
}
|
}
|
||||||
return LocalRegistry.mqttPort;
|
return LocalRegistry.mqttEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setEnrolled(Context context, boolean enrolled) {
|
public static void setEnrolled(Context context, boolean enrolled) {
|
||||||
@ -227,6 +229,31 @@ public class LocalRegistry {
|
|||||||
return LocalRegistry.enrolled;
|
return LocalRegistry.enrolled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addTenantDomain(Context context, String tenantDomain) {
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(TENANT_DOMAIN_KEY, tenantDomain);
|
||||||
|
editor.commit();
|
||||||
|
LocalRegistry.tenantDomain = tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeTenantDomain(Context context) {
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.remove(TENANT_DOMAIN_KEY);
|
||||||
|
editor.clear();
|
||||||
|
editor.commit();
|
||||||
|
LocalRegistry.tenantDomain = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTenantDomain(Context context) {
|
||||||
|
if (LocalRegistry.tenantDomain == null) {
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||||
|
LocalRegistry.tenantDomain = sharedpreferences.getString(TENANT_DOMAIN_KEY, "");
|
||||||
|
}
|
||||||
|
return LocalRegistry.tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getServerHost(Context context) {
|
public static String getServerHost(Context context) {
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|||||||
@ -51,11 +51,7 @@ public class SenseClient {
|
|||||||
String responseStatus = response.get("status");
|
String responseStatus = response.get("status");
|
||||||
RegisterInfo registerInfo = new RegisterInfo();
|
RegisterInfo registerInfo = new RegisterInfo();
|
||||||
if (responseStatus.trim().contains(SenseConstants.Request.REQUEST_SUCCESSFUL)) {
|
if (responseStatus.trim().contains(SenseConstants.Request.REQUEST_SUCCESSFUL)) {
|
||||||
registerInfo.setMsg("Device Registered");
|
registerInfo.setMsg("Login Succesful");
|
||||||
registerInfo.setIsRegistered(true);
|
|
||||||
return registerInfo;
|
|
||||||
} else if (responseStatus.trim().contains(SenseConstants.Request.REQUEST_CONFLICT)) {
|
|
||||||
registerInfo.setMsg("Login Successful");
|
|
||||||
registerInfo.setIsRegistered(true);
|
registerInfo.setIsRegistered(true);
|
||||||
return registerInfo;
|
return registerInfo;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
|
import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
|
||||||
import org.wso2.carbon.iot.android.sense.util.dto.AccessTokenInfo;
|
import org.wso2.carbon.iot.android.sense.util.dto.AccessTokenInfo;
|
||||||
|
import org.wso2.carbon.iot.android.sense.util.dto.AndroidConfiguration;
|
||||||
import org.wso2.carbon.iot.android.sense.util.dto.AndroidSenseManagerService;
|
import org.wso2.carbon.iot.android.sense.util.dto.AndroidSenseManagerService;
|
||||||
import org.wso2.carbon.iot.android.sense.util.dto.ApiApplicationRegistrationService;
|
import org.wso2.carbon.iot.android.sense.util.dto.ApiApplicationRegistrationService;
|
||||||
import org.wso2.carbon.iot.android.sense.util.dto.ApiRegistrationProfile;
|
import org.wso2.carbon.iot.android.sense.util.dto.ApiRegistrationProfile;
|
||||||
@ -138,18 +139,16 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
|
|||||||
.requestInterceptor(new OAuthRequestInterceptor(accessTokenInfo.getAccess_token()))
|
.requestInterceptor(new OAuthRequestInterceptor(accessTokenInfo.getAccess_token()))
|
||||||
.contract(new JAXRSContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder())
|
.contract(new JAXRSContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder())
|
||||||
.target(AndroidSenseManagerService.class, endpoint + SenseConstants.REGISTER_CONTEXT);
|
.target(AndroidSenseManagerService.class, endpoint + SenseConstants.REGISTER_CONTEXT);
|
||||||
boolean registered = androidSenseManagerService.register(deviceId, DEVICE_NAME);
|
AndroidConfiguration androidConfiguration = androidSenseManagerService.register(deviceId, DEVICE_NAME);
|
||||||
if (registered) {
|
if (androidConfiguration != null) {
|
||||||
LocalRegistry.addAccessToken(context, accessTokenInfo.getAccess_token());
|
LocalRegistry.addAccessToken(context, accessTokenInfo.getAccess_token());
|
||||||
LocalRegistry.addRefreshToken(context, accessTokenInfo.getRefresh_token());
|
LocalRegistry.addRefreshToken(context, accessTokenInfo.getRefresh_token());
|
||||||
|
LocalRegistry.addMqttEndpoint(context, androidConfiguration.getMqttEndpoint());
|
||||||
|
LocalRegistry.addTenantDomain(context, androidConfiguration.getTenantDomain());
|
||||||
}
|
}
|
||||||
return responseMap;
|
return responseMap;
|
||||||
} catch (FeignException e) {
|
} catch (FeignException e) {
|
||||||
responseMap.put(STATUS, "" + e.status());
|
responseMap.put(STATUS, "" + e.status());
|
||||||
if (e.status() == 409) {
|
|
||||||
LocalRegistry.addAccessToken(context, accessTokenInfo.getAccess_token());
|
|
||||||
LocalRegistry.addRefreshToken(context, accessTokenInfo.getRefresh_token());
|
|
||||||
}
|
|
||||||
return responseMap;
|
return responseMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,18 +15,29 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.wso2.carbon.iot.android.sense.util.dto;
|
||||||
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util;
|
|
||||||
|
|
||||||
import org.wso2.carbon.user.core.Permission;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This hold the constants related to the device type.
|
* This holds the required configuration for agent to connect to the server.
|
||||||
*/
|
*/
|
||||||
public class Constants {
|
public class AndroidConfiguration {
|
||||||
|
|
||||||
public static final String DEFAULT_PERMISSION_RESOURCE = "/permission/admin/device-mgt/virtual_firealarm/user";
|
public String tenantDomain;
|
||||||
public static final String DEFAULT_ROLE_NAME = "virtual_firealarm_user";
|
public String mqttEndpoint;
|
||||||
public static final Permission DEFAULT_PERMISSION[] = new Permission[]{new Permission(Constants.DEFAULT_PERMISSION_RESOURCE,
|
|
||||||
"ui.execute")};
|
public String getTenantDomain() {
|
||||||
|
return tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantDomain(String tenantDomain) {
|
||||||
|
this.tenantDomain = tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMqttEndpoint() {
|
||||||
|
return mqttEndpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMqttEndpoint(String mqttEndpoint) {
|
||||||
|
this.mqttEndpoint = mqttEndpoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -26,5 +26,5 @@ public interface AndroidSenseManagerService {
|
|||||||
|
|
||||||
@Path("/enrollment/devices/{device_id}")
|
@Path("/enrollment/devices/{device_id}")
|
||||||
@POST
|
@POST
|
||||||
boolean register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName);
|
AndroidConfiguration register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,9 +14,9 @@
|
|||||||
android:layout_marginBottom="8dp" android:visibility="gone" />
|
android:layout_marginBottom="8dp" android:visibility="gone" />
|
||||||
|
|
||||||
<ScrollView android:id="@+id/login_form" android:layout_width="match_parent"
|
<ScrollView android:id="@+id/login_form" android:layout_width="match_parent"
|
||||||
android:layout_height="211dp"
|
android:layout_height="153dp"
|
||||||
android:fillViewport="false"
|
android:fillViewport="false"
|
||||||
android:layout_weight="0.07">
|
>
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent"
|
<LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:orientation="vertical">
|
android:layout_height="wrap_content" android:orientation="vertical">
|
||||||
@ -43,32 +43,14 @@
|
|||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:maxLines="1" android:singleLine="true"/>
|
android:maxLines="1" android:singleLine="true"/>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:text="MQTT Port"
|
|
||||||
android:id="@+id/textView4"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:hint="@string/hostname"
|
|
||||||
android:id="@+id/mqttPort"
|
|
||||||
android:text="1883"
|
|
||||||
android:inputType="text"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:singleLine="true"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<Button android:id="@+id/device_register_button" style="?android:textAppearanceSmall"
|
<Button android:id="@+id/device_register_button" style="?android:textAppearanceSmall"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp" android:text="@string/action_sign_in"
|
android:layout_marginTop="16dp" android:text="@string/action_sign_in"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold"
|
||||||
|
android:layout_gravity="center_horizontal"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
@Plan:name('android_sense_execution')
|
@Plan:name('android_sense_execution')
|
||||||
|
|
||||||
/* Enter a unique description for ExecutionPlan */
|
/* Enter a unique description for ExecutionPlan */
|
||||||
-- @Plan:description('ExecutionPlan')
|
-- @Plan:description('android_sense_execution')
|
||||||
|
|
||||||
/* define streams/tables and write queries here ... */
|
/* define streams/tables and write queries here ... */
|
||||||
|
|
||||||
|
|||||||
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
<eventReceiver name="EventReceiver_AndroidSense" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
|
<eventReceiver name="EventReceiver_AndroidSense" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
|
||||||
<from eventAdapterType="oauth-mqtt">
|
<from eventAdapterType="oauth-mqtt">
|
||||||
<property name="topic">wso2/android_sense/+/data</property>
|
<property name="topic">wso2/carbon.super/android_sense/+/data</property>
|
||||||
<property name="username">admin</property>
|
<property name="username">admin</property>
|
||||||
<property name="contentValidationParams">device_id_json_path:event.metaData.deviceId,device_id_topic_hierarchy_index:2</property>
|
<property name="contentValidationParams">device_id_json_path:event.metaData.deviceId,device_id_topic_hierarchy_index:3</property>
|
||||||
<property name="contentValidation">default</property>
|
<property name="contentValidation">default</property>
|
||||||
<property name="dcrUrl">https://localhost:9443/dynamic-client-web/register</property>
|
<property name="dcrUrl">https://localhost:9443/dynamic-client-web/register</property>
|
||||||
<property name="url">tcp://localhost:1883</property>
|
<property name="url">tcp://localhost:1883</property>
|
||||||
|
|||||||
@ -21,17 +21,14 @@ package org.wso2.carbon.device.mgt.iot.androidsense.service.impl;
|
|||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceData;
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.FormParam;
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@DeviceType(value = "android_sense")
|
@DeviceType(value = "android_sense")
|
||||||
|
|||||||
@ -133,7 +133,7 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
|
|||||||
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||||
}
|
}
|
||||||
List<SensorRecord> sensorDatas;
|
List<SensorRecord> sensorDatas;
|
||||||
if (sensor.equals(AndroidSenseConstants.SENSOR_WORDCOUNT)) {
|
if (!sensor.equals(AndroidSenseConstants.SENSOR_WORDCOUNT)) {
|
||||||
List<SortByField> sortByFields = new ArrayList<>();
|
List<SortByField> sortByFields = new ArrayList<>();
|
||||||
SortByField sortByField = new SortByField("time", SORT.ASC, false);
|
SortByField sortByField = new SortByField("time", SORT.ASC, false);
|
||||||
sortByFields.add(sortByField);
|
sortByFields.add(sortByField);
|
||||||
@ -183,7 +183,7 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
|
|||||||
sensorEventTableName = "DEVICE_PRESSURE_SUMMARY";
|
sensorEventTableName = "DEVICE_PRESSURE_SUMMARY";
|
||||||
break;
|
break;
|
||||||
case AndroidSenseConstants.SENSOR_PROXIMITY:
|
case AndroidSenseConstants.SENSOR_PROXIMITY:
|
||||||
sensorEventTableName = "DevicePROXIMITYSummaryData";
|
sensorEventTableName = "DEVICE_PROXIMITY_SUMMARY";
|
||||||
break;
|
break;
|
||||||
case AndroidSenseConstants.SENSOR_ROTATION:
|
case AndroidSenseConstants.SENSOR_ROTATION:
|
||||||
sensorEventTableName = "DEVICE_ROTATION_SUMMARY";
|
sensorEventTableName = "DEVICE_ROTATION_SUMMARY";
|
||||||
|
|||||||
@ -27,6 +27,11 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|||||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.AndroidConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.Constants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.exception.IoTException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.IoTUtil;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
@ -53,7 +58,15 @@ public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerServic
|
|||||||
deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE);
|
||||||
try {
|
try {
|
||||||
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
|
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
|
||||||
return Response.status(Response.Status.CONFLICT.getStatusCode()).build();
|
AndroidConfiguration androidConfiguration = new AndroidConfiguration();
|
||||||
|
androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
|
||||||
|
String mqttEndpoint = MqttConfig.getInstance().getMqttQueueEndpoint();
|
||||||
|
if (mqttEndpoint.contains(Constants.LOCALHOST)) {
|
||||||
|
mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, IoTUtil.getHostName());
|
||||||
|
}
|
||||||
|
androidConfiguration.setMqttEndpoint(mqttEndpoint);
|
||||||
|
return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.setDeviceIdentifier(deviceId);
|
device.setDeviceIdentifier(deviceId);
|
||||||
@ -68,14 +81,23 @@ public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerServic
|
|||||||
device.setEnrolmentInfo(enrolmentInfo);
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
|
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
|
||||||
if (added) {
|
if (added) {
|
||||||
APIUtil.registerApiAccessRoles(APIUtil.getAuthenticatedUser());
|
AndroidConfiguration androidConfiguration = new AndroidConfiguration();
|
||||||
return Response.ok(true).build();
|
androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
|
||||||
|
String mqttEndpoint = MqttConfig.getInstance().getMqttQueueEndpoint();
|
||||||
|
if (mqttEndpoint.contains(Constants.LOCALHOST)) {
|
||||||
|
mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, IoTUtil.getHostName());
|
||||||
|
}
|
||||||
|
androidConfiguration.setMqttEndpoint(mqttEndpoint);
|
||||||
|
return Response.ok(androidConfiguration.toString()).build();
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).entity(false).build();
|
return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).entity(false).build();
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
log.error(e.getErrorMessage(), e);
|
log.error(e.getErrorMessage(), e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build();
|
||||||
|
} catch (IoTException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -131,7 +131,8 @@ public class AndroidSenseMQTTConnector extends MQTTTransportHandler {
|
|||||||
String operation = publishData[1];
|
String operation = publishData[1];
|
||||||
String resource = publishData[2];
|
String resource = publishData[2];
|
||||||
MqttMessage pushMessage = new MqttMessage();
|
MqttMessage pushMessage = new MqttMessage();
|
||||||
String publishTopic = "wso2/" + AndroidSenseConstants.DEVICE_TYPE + "/" + deviceId + "/command";
|
String publishTopic = "wso2/" + APIUtil.getAuthenticatedUserTenantDomain()
|
||||||
|
+ "/" + AndroidSenseConstants.DEVICE_TYPE + "/" + deviceId + "/command";
|
||||||
if (operation.equals("add")) {
|
if (operation.equals("add")) {
|
||||||
publishTopic = publishTopic + "/words";
|
publishTopic = publishTopic + "/words";
|
||||||
} else if (operation.equals("remove")) {
|
} else if (operation.equals("remove")) {
|
||||||
|
|||||||
@ -48,6 +48,11 @@ public class APIUtil {
|
|||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getAuthenticatedUserTenantDomain() {
|
||||||
|
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
return threadLocalCarbonContext.getTenantDomain();
|
||||||
|
}
|
||||||
|
|
||||||
public static DeviceManagementProviderService getDeviceManagementService() {
|
public static DeviceManagementProviderService getDeviceManagementService() {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
DeviceManagementProviderService deviceManagementProviderService =
|
DeviceManagementProviderService deviceManagementProviderService =
|
||||||
@ -80,14 +85,8 @@ public class APIUtil {
|
|||||||
if (eventCount == 0) {
|
if (eventCount == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
AnalyticsDrillDownRequest drillDownRequest = new AnalyticsDrillDownRequest();
|
List<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount,
|
||||||
drillDownRequest.setQuery(query);
|
sortByFields);
|
||||||
drillDownRequest.setTableName(tableName);
|
|
||||||
drillDownRequest.setRecordCount(eventCount);
|
|
||||||
if (sortByFields != null) {
|
|
||||||
drillDownRequest.setSortByFields(sortByFields);
|
|
||||||
}
|
|
||||||
List<SearchResultEntry> resultEntries = analyticsDataAPI.drillDownSearch(tenantId, drillDownRequest);
|
|
||||||
List<String> recordIds = getRecordIds(resultEntries);
|
List<String> recordIds = getRecordIds(resultEntries);
|
||||||
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
||||||
Map<String, SensorRecord> sensorDatas = createSensorData(AnalyticsDataServiceUtils.listRecords(
|
Map<String, SensorRecord> sensorDatas = createSensorData(AnalyticsDataServiceUtils.listRecords(
|
||||||
@ -176,45 +175,4 @@ public class APIUtil {
|
|||||||
}
|
}
|
||||||
return deviceAccessAuthorizationService;
|
return deviceAccessAuthorizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerApiAccessRoles(String user) {
|
|
||||||
UserStoreManager userStoreManager = null;
|
|
||||||
try {
|
|
||||||
userStoreManager = getUserStoreManager();
|
|
||||||
String[] userList = new String[]{user};
|
|
||||||
if (userStoreManager != null) {
|
|
||||||
String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
|
|
||||||
if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
|
|
||||||
userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
|
|
||||||
} else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
log.error("Error while creating a role and adding a user for virtual_firealarm.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UserStoreManager getUserStoreManager() {
|
|
||||||
RealmService realmService;
|
|
||||||
UserStoreManager userStoreManager;
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
|
||||||
String msg = "Realm service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
int tenantId = ctx.getTenantId();
|
|
||||||
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return userStoreManager;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,44 +18,36 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util;
|
package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util;
|
||||||
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
import org.json.simple.JSONObject;
|
||||||
|
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
/**
|
/**
|
||||||
* This stores sensor event data for android sense.
|
* This holds the required configuration for agent to connect to the server.
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
public class AndroidConfiguration {
|
||||||
public class SensorData {
|
public String tenantDomain;
|
||||||
|
public String mqttEndpoint;
|
||||||
|
|
||||||
@XmlElement public Long time;
|
public String getTenantDomain() {
|
||||||
@XmlElement public String key;
|
return tenantDomain;
|
||||||
@XmlElement public String value;
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setTenantDomain(String tenantDomain) {
|
||||||
this.value = value;
|
this.tenantDomain = tenantDomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getMqttEndpoint() {
|
||||||
return key;
|
return mqttEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String key) {
|
public void setMqttEndpoint(String mqttEndpoint) {
|
||||||
this.key = key;
|
this.mqttEndpoint = mqttEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTime() {
|
public String toString() {
|
||||||
return time;
|
JSONObject obj = new JSONObject();
|
||||||
|
obj.put("tenantDomain", tenantDomain);
|
||||||
|
obj.put("mqttEndpoint", mqttEndpoint);
|
||||||
|
return obj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(Long time) {
|
|
||||||
this.time = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -24,9 +24,5 @@ import org.wso2.carbon.user.core.Permission;
|
|||||||
* This hold the constants related to the device type.
|
* This hold the constants related to the device type.
|
||||||
*/
|
*/
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
public static final String LOCALHOST = "localhost";
|
||||||
public static final String DEFAULT_PERMISSION_RESOURCE = "/permission/admin/device-mgt/android_sense/user";
|
|
||||||
public static final String DEFAULT_ROLE_NAME = "android_sense_user";
|
|
||||||
public static final Permission DEFAULT_PERMISSION[] = new Permission[]{new Permission(Constants.DEFAULT_PERMISSION_RESOURCE,
|
|
||||||
"ui.execute")};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class DeviceData {
|
|
||||||
@XmlElement(required = true) public String owner;
|
|
||||||
@XmlElement(required = true) public String deviceId;
|
|
||||||
@XmlElement public SensorData[] values;
|
|
||||||
}
|
|
||||||
@ -30,56 +30,56 @@
|
|||||||
<!-- Device related APIs -->
|
<!-- Device related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Set words</name>
|
<name>Set words</name>
|
||||||
<path>/device-mgt/android_sense/user</path>
|
<path>/device-mgt/user/operations</path>
|
||||||
<url>/device/*/words</url>
|
<url>/device/*/words</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>android_sense_user</scope>
|
<scope>android_sense_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>set word threshold information</name>
|
<name>set word threshold information</name>
|
||||||
<path>/device-mgt/android_sense/user</path>
|
<path>/device-mgt/user/operations</path>
|
||||||
<url>/device/*/words/threshold</url>
|
<url>/device/*/words/threshold</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>android_sense_user</scope>
|
<scope>android_sense_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>delete words</name>
|
<name>delete words</name>
|
||||||
<path>/device-mgt/android_sense/user</path>
|
<path>/device-mgt/user/operations</path>
|
||||||
<url>/device/*/words</url>
|
<url>/device/*/words</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
<scope>android_sense_user</scope>
|
<scope>android_sense_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>get device stats</name>
|
<name>get device stats</name>
|
||||||
<path>/device-mgt/android_sense/user</path>
|
<path>/device-mgt/user/stats</path>
|
||||||
<url>/stats/*/sensors/*</url>
|
<url>/stats/*/sensors/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
<scope>android_sense_device</scope>
|
<scope>android_sense_device</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Get device</name>
|
<name>Get device</name>
|
||||||
<path>/device-mgt/android_sense/user</path>
|
<path>/device-mgt/user/devices/list</path>
|
||||||
<url>/enrollment/devices/*</url>
|
<url>/enrollment/devices/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
<scope>android_sense_user</scope>
|
<scope>android_sense_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add device</name>
|
<name>Add device</name>
|
||||||
<path>/device-mgt/user</path>
|
<path>/device-mgt/user/devices</path>
|
||||||
<url>/enrollment/devices/*</url>
|
<url>/enrollment/devices/*</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>android_sense_user</scope>
|
<scope>android_sense_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Remove device</name>
|
<name>Remove device</name>
|
||||||
<path>/device-mgt/android_sense/user</path>
|
<path>/device-mgt/user/devices/remove</path>
|
||||||
<url>/enrollment/devices/*</url>
|
<url>/enrollment/devices/*</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
<scope>android_sense_user</scope>
|
<scope>android_sense_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update device</name>
|
<name>Update device</name>
|
||||||
<path>/device-mgt/android_sense/user</path>
|
<path>/device-mgt/user/devices/update</path>
|
||||||
<url>/enrollment/devices/*</url>
|
<url>/enrollment/devices/*</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
<scope>android_sense_user</scope>
|
<scope>android_sense_user</scope>
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class AndroidSenseConstants {
|
|||||||
public static final String SENSOR_ROTATION = "rotation";
|
public static final String SENSOR_ROTATION = "rotation";
|
||||||
public static final String SENSOR_WORDCOUNT = "wordcounter";
|
public static final String SENSOR_WORDCOUNT = "wordcounter";
|
||||||
//MQTT Subscribe topic
|
//MQTT Subscribe topic
|
||||||
public static final String MQTT_SUBSCRIBE_WORDS_TOPIC = "wso2/android_sense/+/data";
|
public static final String MQTT_SUBSCRIBE_WORDS_TOPIC = "wso2/+/android_sense/+/data";
|
||||||
public static final String DATA_SOURCE_NAME = "jdbc/AndroidSenseDM_DB";
|
public static final String DATA_SOURCE_NAME = "jdbc/AndroidSenseDM_DB";
|
||||||
public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super";
|
public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
|||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.feature.AndroidSenseFeatureManager;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.feature.AndroidSenseFeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.AndroidSenseDAO;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.AndroidSenseDAOUtil;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class AndroidSenseManager implements DeviceManager {
|
public class AndroidSenseManager implements DeviceManager {
|
||||||
|
|
||||||
private static final AndroidSenseDAO androidSenseDAO = new AndroidSenseDAO();
|
private static final AndroidSenseDAOUtil androidSenseDAO = new AndroidSenseDAOUtil();
|
||||||
private static final Log log = LogFactory.getLog(AndroidSenseManager.class);
|
private static final Log log = LogFactory.getLog(AndroidSenseManager.class);
|
||||||
private FeatureManager androidSenseFeatureManager = new AndroidSenseFeatureManager();
|
private FeatureManager androidSenseFeatureManager = new AndroidSenseFeatureManager();
|
||||||
|
|
||||||
@ -68,12 +68,12 @@ public class AndroidSenseManager implements DeviceManager {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
AndroidSenseDAO.beginTransaction();
|
AndroidSenseDAOUtil.beginTransaction();
|
||||||
status = androidSenseDAO.getDeviceDAO().addDevice(device);
|
status = androidSenseDAO.getDeviceDAO().addDevice(device);
|
||||||
AndroidSenseDAO.commitTransaction();
|
AndroidSenseDAOUtil.commitTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException e) {
|
} catch (AndroidSenseDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
AndroidSenseDAO.rollbackTransaction();
|
AndroidSenseDAOUtil.rollbackTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
@ -92,12 +92,12 @@ public class AndroidSenseManager implements DeviceManager {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Modifying the Android device enrollment data");
|
log.debug("Modifying the Android device enrollment data");
|
||||||
}
|
}
|
||||||
AndroidSenseDAO.beginTransaction();
|
AndroidSenseDAOUtil.beginTransaction();
|
||||||
status = androidSenseDAO.getDeviceDAO().updateDevice(device);
|
status = androidSenseDAO.getDeviceDAO().updateDevice(device);
|
||||||
AndroidSenseDAO.commitTransaction();
|
AndroidSenseDAOUtil.commitTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException e) {
|
} catch (AndroidSenseDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
AndroidSenseDAO.rollbackTransaction();
|
AndroidSenseDAOUtil.rollbackTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
@ -117,12 +117,12 @@ public class AndroidSenseManager implements DeviceManager {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Dis-enrolling Android device : " + deviceId);
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
||||||
}
|
}
|
||||||
AndroidSenseDAO.beginTransaction();
|
AndroidSenseDAOUtil.beginTransaction();
|
||||||
status = androidSenseDAO.getDeviceDAO().deleteDevice(deviceId.getId());
|
status = androidSenseDAO.getDeviceDAO().deleteDevice(deviceId.getId());
|
||||||
AndroidSenseDAO.commitTransaction();
|
AndroidSenseDAOUtil.commitTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException e) {
|
} catch (AndroidSenseDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
AndroidSenseDAO.rollbackTransaction();
|
AndroidSenseDAOUtil.rollbackTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
|
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
@ -219,12 +219,12 @@ public class AndroidSenseManager implements DeviceManager {
|
|||||||
log.debug(
|
log.debug(
|
||||||
"updating the details of Android device : " + deviceIdentifier);
|
"updating the details of Android device : " + deviceIdentifier);
|
||||||
}
|
}
|
||||||
AndroidSenseDAO.beginTransaction();
|
AndroidSenseDAOUtil.beginTransaction();
|
||||||
status = androidSenseDAO.getDeviceDAO().updateDevice(device);
|
status = androidSenseDAO.getDeviceDAO().updateDevice(device);
|
||||||
AndroidSenseDAO.commitTransaction();
|
AndroidSenseDAOUtil.commitTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException e) {
|
} catch (AndroidSenseDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
AndroidSenseDAO.rollbackTransaction();
|
AndroidSenseDAOUtil.rollbackTransaction();
|
||||||
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
} catch (AndroidSenseDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
|
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -18,106 +18,180 @@ package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao;
|
|||||||
|
|
||||||
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.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.impl.AndroidSenseDAOImpl;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException;
|
||||||
import javax.naming.Context;
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.util.AndroidSenseUtils;
|
||||||
import javax.naming.InitialContext;
|
|
||||||
import javax.naming.NamingException;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements dao impl for android Devices.
|
||||||
|
*/
|
||||||
public class AndroidSenseDAO {
|
public class AndroidSenseDAO {
|
||||||
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(AndroidSenseDAO.class);
|
private static final Log log = LogFactory.getLog(AndroidSenseDAO.class);
|
||||||
static DataSource dataSource;
|
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
|
||||||
|
|
||||||
public AndroidSenseDAO() {
|
public Device getDevice(String deviceId) throws AndroidSenseDeviceMgtPluginException {
|
||||||
initAndroidDAO();
|
Connection conn = null;
|
||||||
}
|
PreparedStatement stmt = null;
|
||||||
|
Device device = null;
|
||||||
public static void initAndroidDAO() {
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
Context ctx = new InitialContext();
|
conn = AndroidSenseDAOUtil.getConnection();
|
||||||
dataSource = (DataSource) ctx.lookup(AndroidSenseConstants.DATA_SOURCE_NAME);
|
String selectDBQuery =
|
||||||
} catch (NamingException e) {
|
"SELECT ANDROID_DEVICE_ID, DEVICE_NAME" +
|
||||||
log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME);
|
" FROM ANDROID_SENSE_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
||||||
}
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
}
|
stmt.setString(1, deviceId);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
public AndroidSenseDAOImpl getDeviceDAO() {
|
if (resultSet.next()) {
|
||||||
return new AndroidSenseDAOImpl();
|
device = new Device();
|
||||||
}
|
device.setName(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
||||||
|
|
||||||
public static void beginTransaction() throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
try {
|
|
||||||
Connection conn = dataSource.getConnection();
|
|
||||||
conn.setAutoCommit(false);
|
|
||||||
currentConnection.set(conn);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new AndroidSenseDeviceMgtPluginException("Error occurred while retrieving datasource connection", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Connection getConnection() throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
if (currentConnection.get() == null) {
|
|
||||||
try {
|
|
||||||
currentConnection.set(dataSource.getConnection());
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new AndroidSenseDeviceMgtPluginException("Error occurred while retrieving data source connection", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return currentConnection.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void commitTransaction() throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
try {
|
|
||||||
Connection conn = currentConnection.get();
|
|
||||||
if (conn != null) {
|
|
||||||
conn.commit();
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Datasource connection associated with the current thread is null, hence commit "
|
log.debug("Android device " + deviceId + " data has been fetched from " +
|
||||||
+ "has not been attempted");
|
"Android database.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new AndroidSenseDeviceMgtPluginException("Error occurred while committing the transaction", e);
|
String msg = "Error occurred while fetching Android device : '" + deviceId + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
AndroidSenseUtils.cleanupResources(stmt, resultSet);
|
||||||
|
AndroidSenseDAOUtil.closeConnection();
|
||||||
}
|
}
|
||||||
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeConnection() throws AndroidSenseDeviceMgtPluginException {
|
public boolean addDevice(Device device)throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
boolean status = false;
|
||||||
Connection con = currentConnection.get();
|
Connection conn = null;
|
||||||
if (con != null) {
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
con.close();
|
conn = AndroidSenseDAOUtil.getConnection();
|
||||||
} catch (SQLException e) {
|
String createDBQuery =
|
||||||
log.error("Error occurred while close the connection");
|
"INSERT INTO ANDROID_SENSE_DEVICE(ANDROID_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
|
||||||
}
|
|
||||||
}
|
|
||||||
currentConnection.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rollbackTransaction() throws AndroidSenseDeviceMgtPluginException {
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
try {
|
stmt.setString(1, device.getDeviceIdentifier());
|
||||||
Connection conn = currentConnection.get();
|
stmt.setString(2, device.getName());
|
||||||
if (conn != null) {
|
int rows = stmt.executeUpdate();
|
||||||
conn.rollback();
|
if (rows > 0) {
|
||||||
} else {
|
status = true;
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Datasource connection associated with the current thread is null, hence rollback "
|
log.debug("Android device " + device.getDeviceIdentifier() + " data has been" +
|
||||||
+ "has not been attempted");
|
" added to the Android database.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new AndroidSenseDeviceMgtPluginException("Error occurred while rollback the transaction", e);
|
String msg = "Error occurred while adding the Android device '" + device.getDeviceIdentifier()
|
||||||
|
+ "' to the Android db.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
AndroidSenseUtils.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean updateDevice(Device device) throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = AndroidSenseDAOUtil.getConnection();
|
||||||
|
String updateDBQuery =
|
||||||
|
"UPDATE ANDROID_SENSE_DEVICE SET DEVICE_NAME = ? WHERE ANDROID_DEVICE_ID = ?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
|
stmt.setString(1, device.getName());
|
||||||
|
stmt.setString(2, device.getDeviceIdentifier());
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Android device " + device.getDeviceIdentifier() + " data has been modified.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while modifying the Android device '" +
|
||||||
|
device.getDeviceIdentifier() + "' data.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
||||||
|
} finally {
|
||||||
|
AndroidSenseUtils.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteDevice(String deviceId) throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = AndroidSenseDAOUtil.getConnection();
|
||||||
|
String deleteDBQuery =
|
||||||
|
"DELETE FROM ANDROID_SENSE_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
|
stmt.setString(1, deviceId);
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Android device " + deviceId + " data has deleted from the Android database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while deleting Android device " + deviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
||||||
|
} finally {
|
||||||
|
AndroidSenseUtils.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Device> getAllDevices() throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
Device device;
|
||||||
|
List<Device> iotDevices = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = AndroidSenseDAOUtil.getConnection();
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT ANDROID_DEVICE_ID, DEVICE_NAME FROM ANDROID_SENSE_DEVICE";
|
||||||
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
device = new Device();
|
||||||
|
device.setDeviceIdentifier(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_ID));
|
||||||
|
device.setName(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
||||||
|
iotDevices.add(device);
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("All Android device details have fetched from Android database.");
|
||||||
|
}
|
||||||
|
return iotDevices;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while fetching all Android device data'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
||||||
|
} finally {
|
||||||
|
AndroidSenseUtils.cleanupResources(stmt, resultSet);
|
||||||
|
AndroidSenseDAOUtil.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
||||||
|
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class AndroidSenseDAOUtil {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(AndroidSenseDAOUtil.class);
|
||||||
|
static DataSource dataSource;
|
||||||
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
|
|
||||||
|
public AndroidSenseDAOUtil() {
|
||||||
|
initAndroidDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initAndroidDAO() {
|
||||||
|
try {
|
||||||
|
Context ctx = new InitialContext();
|
||||||
|
dataSource = (DataSource) ctx.lookup(AndroidSenseConstants.DATA_SOURCE_NAME);
|
||||||
|
} catch (NamingException e) {
|
||||||
|
log.error("Error while looking up the data source: " + AndroidSenseConstants.DATA_SOURCE_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AndroidSenseDAO getDeviceDAO() {
|
||||||
|
return new AndroidSenseDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void beginTransaction() throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
try {
|
||||||
|
Connection conn = dataSource.getConnection();
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
currentConnection.set(conn);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException("Error occurred while retrieving datasource connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection() throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
if (currentConnection.get() == null) {
|
||||||
|
try {
|
||||||
|
currentConnection.set(dataSource.getConnection());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException("Error occurred while retrieving data source connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentConnection.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commitTransaction() throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.commit();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence commit "
|
||||||
|
+ "has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException("Error occurred while committing the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void closeConnection() throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
|
||||||
|
Connection con = currentConnection.get();
|
||||||
|
if (con != null) {
|
||||||
|
try {
|
||||||
|
con.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while close the connection");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentConnection.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void rollbackTransaction() throws AndroidSenseDeviceMgtPluginException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.rollback();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence rollback "
|
||||||
|
+ "has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new AndroidSenseDeviceMgtPluginException("Error occurred while rollback the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,198 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Licensed 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.impl;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.exception.AndroidSenseDeviceMgtPluginException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.AndroidSenseDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.util.AndroidSenseUtils;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements dao impl for android Devices.
|
|
||||||
*/
|
|
||||||
public class AndroidSenseDAOImpl {
|
|
||||||
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(AndroidSenseDAOImpl.class);
|
|
||||||
|
|
||||||
public Device getDevice(String deviceId) throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
Device device = null;
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
try {
|
|
||||||
conn = AndroidSenseDAO.getConnection();
|
|
||||||
String selectDBQuery =
|
|
||||||
"SELECT ANDROID_DEVICE_ID, DEVICE_NAME" +
|
|
||||||
" FROM ANDROID_SENSE_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
|
||||||
stmt.setString(1, deviceId);
|
|
||||||
resultSet = stmt.executeQuery();
|
|
||||||
|
|
||||||
if (resultSet.next()) {
|
|
||||||
device = new Device();
|
|
||||||
device.setName(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Android device " + deviceId + " data has been fetched from " +
|
|
||||||
"Android database.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while fetching Android device : '" + deviceId + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
|
||||||
} finally {
|
|
||||||
AndroidSenseUtils.cleanupResources(stmt, resultSet);
|
|
||||||
AndroidSenseDAO.closeConnection();
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addDevice(Device device)throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
boolean status = false;
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = AndroidSenseDAO.getConnection();
|
|
||||||
String createDBQuery =
|
|
||||||
"INSERT INTO ANDROID_SENSE_DEVICE(ANDROID_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
|
||||||
stmt.setString(1, device.getDeviceIdentifier());
|
|
||||||
stmt.setString(2, device.getName());
|
|
||||||
int rows = stmt.executeUpdate();
|
|
||||||
if (rows > 0) {
|
|
||||||
status = true;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Android device " + device.getDeviceIdentifier() + " data has been" +
|
|
||||||
" added to the Android database.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while adding the Android device '" + device.getDeviceIdentifier()
|
|
||||||
+ "' to the Android db.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
|
||||||
} finally {
|
|
||||||
AndroidSenseUtils.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean updateDevice(Device device) throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
boolean status = false;
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = AndroidSenseDAO.getConnection();
|
|
||||||
String updateDBQuery =
|
|
||||||
"UPDATE ANDROID_SENSE_DEVICE SET DEVICE_NAME = ? WHERE ANDROID_DEVICE_ID = ?";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
|
||||||
stmt.setString(1, device.getName());
|
|
||||||
stmt.setString(2, device.getDeviceIdentifier());
|
|
||||||
int rows = stmt.executeUpdate();
|
|
||||||
if (rows > 0) {
|
|
||||||
status = true;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Android device " + device.getDeviceIdentifier() + " data has been modified.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while modifying the Android device '" +
|
|
||||||
device.getDeviceIdentifier() + "' data.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
|
||||||
} finally {
|
|
||||||
AndroidSenseUtils.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean deleteDevice(String deviceId) throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
boolean status = false;
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = AndroidSenseDAO.getConnection();
|
|
||||||
String deleteDBQuery =
|
|
||||||
"DELETE FROM ANDROID_SENSE_DEVICE WHERE ANDROID_DEVICE_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
|
||||||
stmt.setString(1, deviceId);
|
|
||||||
int rows = stmt.executeUpdate();
|
|
||||||
if (rows > 0) {
|
|
||||||
status = true;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Android device " + deviceId + " data has deleted from the Android database.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while deleting Android device " + deviceId;
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
|
||||||
} finally {
|
|
||||||
AndroidSenseUtils.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Device> getAllDevices() throws AndroidSenseDeviceMgtPluginException {
|
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
Device device;
|
|
||||||
List<Device> iotDevices = new ArrayList<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = AndroidSenseDAO.getConnection();
|
|
||||||
String selectDBQuery =
|
|
||||||
"SELECT ANDROID_DEVICE_ID, DEVICE_NAME FROM ANDROID_SENSE_DEVICE";
|
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
|
||||||
resultSet = stmt.executeQuery();
|
|
||||||
while (resultSet.next()) {
|
|
||||||
device = new Device();
|
|
||||||
device.setDeviceIdentifier(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_ID));
|
|
||||||
device.setName(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
|
||||||
iotDevices.add(device);
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("All Android device details have fetched from Android database.");
|
|
||||||
}
|
|
||||||
return iotDevices;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while fetching all Android device data'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new AndroidSenseDeviceMgtPluginException(msg, e);
|
|
||||||
} finally {
|
|
||||||
AndroidSenseUtils.cleanupResources(stmt, resultSet);
|
|
||||||
AndroidSenseDAO.closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
{{#zone "topCss"}}
|
||||||
|
{{css "css/graph.css"}}
|
||||||
|
{{/zone}}
|
||||||
|
<span id="details" data-devicename="{{device.name}}" data-deviceid="{{device.deviceIdentifier}}"
|
||||||
|
data-appcontext="{{@app.context}}"></span>
|
||||||
|
<div id="device-chart" data-backend-api-url = {{backendApiUrl}}>
|
||||||
|
<div class="chartWrapper" id="chartWrapper-battery">
|
||||||
|
<span id="span-title">Battery</span>
|
||||||
|
<div id="y_axis-battery" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-battery" title="Smoothing"></div>
|
||||||
|
<div id="legend-battery"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-battery" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-battery" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-battery" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-light">
|
||||||
|
<span id="span-title">Light</span>
|
||||||
|
<div id="y_axis-light" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-light" title="Smoothing"></div>
|
||||||
|
<div id="legend-light"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-light" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-light" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-light" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-pressure">
|
||||||
|
<span id="span-title">Pressure</span>
|
||||||
|
<div id="y_axis-pressure" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-pressure" title="Smoothing"></div>
|
||||||
|
<div id="legend-pressure"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-pressure" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-pressure" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-pressure" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-proximity">
|
||||||
|
<span id="span-title">Proximity</span>
|
||||||
|
<div id="y_axis-proximity" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-proximity" title="Smoothing"></div>
|
||||||
|
<div id="legend-proximity"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-proximity" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-proximity" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-proximity" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-accelerometer">
|
||||||
|
<span id="span-title">Acceleromter</span>
|
||||||
|
<div id="y_axis-accelerometer" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-accelerometer" title="Smoothing"></div>
|
||||||
|
<div id="legend-accelerometer"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-accelerometer" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-accelerometer" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-accelerometer" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-magnetic">
|
||||||
|
<span id="span-title">Magnetic</span>
|
||||||
|
<div id="y_axis-magnetic" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-magnetic" title="Smoothing"></div>
|
||||||
|
<div id="legend-magnetic"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-magnetic" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-magnetic" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-magnetic" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-rotation">
|
||||||
|
<span id="span-title">Rotation</span>
|
||||||
|
<div id="y_axis-rotation" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-rotation" title="Smoothing"></div>
|
||||||
|
<div id="legend-rotation"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-rotation" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-rotation" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-rotation" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-gyroscope">
|
||||||
|
<span id="span-title">Gyroscope</span>
|
||||||
|
<div id="y_axis-gyroscope" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-gyroscope" title="Smoothing"></div>
|
||||||
|
<div id="legend-gyroscope"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-gyroscope" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-gyroscope" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-gyroscope" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chartWrapper" id="chartWrapper-gravity">
|
||||||
|
<span id="span-title">Gravity</span>
|
||||||
|
<div id="y_axis-gravity" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother-gravity" title="Smoothing"></div>
|
||||||
|
<div id="legend-gravity"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-gravity" class="custom_rickshaw_graph" ></div>
|
||||||
|
<div id="x_axis-gravity" class="custom_x_axis"></div>
|
||||||
|
<div id="slider-gravity" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/d3.min.js"}}
|
||||||
|
{{js "js/rickshaw.min.js"}}
|
||||||
|
{{js "js/moment.min.js"}}
|
||||||
|
{{js "js/devicetype-graph.js"}}
|
||||||
|
{{/zone}}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
|
||||||
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||||
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
if (device && device.status != "error") {
|
||||||
|
return {
|
||||||
|
"device": device,
|
||||||
|
"backendApiUrl": devicemgtProps["httpsURL"] + "/android_sense/stats/" + deviceId + "/sensors/"
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,470 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* graph */
|
||||||
|
|
||||||
|
.rickshaw_graph {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph svg {
|
||||||
|
display: block;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ticks */
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 0;
|
||||||
|
border-left: 1px dotted rgba(0, 0, 0, 0.2);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick .title {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
opacity: 0.5;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin-left: 3px;
|
||||||
|
bottom: -20px;
|
||||||
|
height: auto;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* annotations */
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline {
|
||||||
|
height: 1px;
|
||||||
|
border-top: 1px solid #e0e0e0;
|
||||||
|
margin-top: 10px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation {
|
||||||
|
position: absolute;
|
||||||
|
height: 6px;
|
||||||
|
width: 6px;
|
||||||
|
margin-left: -2px;
|
||||||
|
top: -3px;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_line {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: -6px;
|
||||||
|
width: 0;
|
||||||
|
border-left: 2px solid rgba(0, 0, 0, 0.3);
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_line.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range {
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: -6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range.active.offscreen {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content {
|
||||||
|
background: white;
|
||||||
|
color: black;
|
||||||
|
opacity: 0.9;
|
||||||
|
box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
|
||||||
|
border-radius: 3px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 20;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 6px 8px 8px;
|
||||||
|
top: 18px;
|
||||||
|
left: -11px;
|
||||||
|
width: 160px;
|
||||||
|
display: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content:before {
|
||||||
|
content: "\25b2";
|
||||||
|
position: absolute;
|
||||||
|
top: -11px;
|
||||||
|
color: white;
|
||||||
|
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation.active,
|
||||||
|
.rickshaw_annotation_timeline .annotation:hover {
|
||||||
|
background-color: rgba(0, 0, 0, 0.8);
|
||||||
|
cursor: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content:hover {
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation.active .content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation:hover .content {
|
||||||
|
display: block;
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_axis,
|
||||||
|
.rickshaw_graph .x_axis_d3 {
|
||||||
|
fill: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks .tick line,
|
||||||
|
.rickshaw_graph .x_ticks_d3 .tick {
|
||||||
|
stroke: rgba(0, 0, 0, 0.16);
|
||||||
|
stroke-width: 2px;
|
||||||
|
shape-rendering: crisp-edges;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid .tick,
|
||||||
|
.rickshaw_graph .x_grid_d3 .tick {
|
||||||
|
z-index: -1;
|
||||||
|
stroke: rgba(0, 0, 0, 0.20);
|
||||||
|
stroke-width: 1px;
|
||||||
|
stroke-dasharray: 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid .tick[data-y-value="0"] {
|
||||||
|
stroke-dasharray: 1 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid path,
|
||||||
|
.rickshaw_graph .x_grid_d3 path {
|
||||||
|
fill: none;
|
||||||
|
stroke: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks path,
|
||||||
|
.rickshaw_graph .x_ticks_d3 path {
|
||||||
|
fill: none;
|
||||||
|
stroke: #808080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks text,
|
||||||
|
.rickshaw_graph .x_ticks_d3 text {
|
||||||
|
opacity: 0.5;
|
||||||
|
font-size: 12px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick.glow .title,
|
||||||
|
.rickshaw_graph .y_ticks.glow text {
|
||||||
|
fill: black;
|
||||||
|
color: black;
|
||||||
|
text-shadow: -1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px -1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
0 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
0 -1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px 0 0 rgba(255, 255, 255, 0.1),
|
||||||
|
-1px 0 0 rgba(255, 255, 255, 0.1),
|
||||||
|
-1px -1px 0 rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick.inverse .title,
|
||||||
|
.rickshaw_graph .y_ticks.inverse text {
|
||||||
|
fill: white;
|
||||||
|
color: white;
|
||||||
|
text-shadow: -1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px -1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
0 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
0 -1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px 0 0 rgba(0, 0, 0, 0.8),
|
||||||
|
-1px 0 0 rgba(0, 0, 0, 0.8),
|
||||||
|
-1px -1px 0 rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_rickshaw_graph {
|
||||||
|
position: relative;
|
||||||
|
left: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_y_axis {
|
||||||
|
position: absolute;
|
||||||
|
width: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_slider {
|
||||||
|
left: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_x_axis {
|
||||||
|
position: relative;
|
||||||
|
left: 40px;
|
||||||
|
height: 30px;
|
||||||
|
width: 97%;
|
||||||
|
top: 20px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chartWrapper {
|
||||||
|
padding-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*detail*/
|
||||||
|
|
||||||
|
.rickshaw_graph .detail {
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
z-index: 2;
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
bottom: 0;
|
||||||
|
width: 1px;
|
||||||
|
transition: opacity 0.25s linear;
|
||||||
|
-moz-transition: opacity 0.25s linear;
|
||||||
|
-o-transition: opacity 0.25s linear;
|
||||||
|
-webkit-transition: opacity 0.25s linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail.inactive {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.active {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 6px;
|
||||||
|
opacity: 0.5;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
font-size: 12px;
|
||||||
|
position: absolute;
|
||||||
|
background: white;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label.left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label.right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0.25em;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
opacity: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.4);
|
||||||
|
color: white;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.4);
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
|
margin-top: -1em;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.active {
|
||||||
|
opacity: 1;
|
||||||
|
background: rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item:after {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
|
||||||
|
content: "";
|
||||||
|
|
||||||
|
border: 5px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.left:after {
|
||||||
|
top: 1em;
|
||||||
|
left: -5px;
|
||||||
|
margin-top: -5px;
|
||||||
|
border-right-color: rgba(0, 0, 0, 0.8);
|
||||||
|
border-left-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.right:after {
|
||||||
|
top: 1em;
|
||||||
|
right: -5px;
|
||||||
|
margin-top: -5px;
|
||||||
|
border-left-color: rgba(0, 0, 0, 0.8);
|
||||||
|
border-right-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .dot {
|
||||||
|
width: 4px;
|
||||||
|
height: 4px;
|
||||||
|
margin-left: -3px;
|
||||||
|
margin-top: -3.5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
position: absolute;
|
||||||
|
box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
|
||||||
|
box-sizing: content-box;
|
||||||
|
-moz-box-sizing: content-box;
|
||||||
|
background: white;
|
||||||
|
border-width: 2px;
|
||||||
|
border-style: solid;
|
||||||
|
display: none;
|
||||||
|
background-clip: padding-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .dot.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*legend*/
|
||||||
|
.rickshaw_legend {
|
||||||
|
font-family: Arial;
|
||||||
|
font-size: 12px;
|
||||||
|
color: white;
|
||||||
|
background: #404040;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 12px 5px;
|
||||||
|
border-radius: 2px;
|
||||||
|
position: relative;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend:hover {
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .swatch {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line {
|
||||||
|
clear: both;
|
||||||
|
line-height: 140%;
|
||||||
|
padding-right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line .swatch {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .label {
|
||||||
|
margin: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
display: inline;
|
||||||
|
font-size: inherit;
|
||||||
|
background-color: transparent;
|
||||||
|
color: inherit;
|
||||||
|
font-weight: normal;
|
||||||
|
line-height: normal;
|
||||||
|
padding: 0;
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .action:hover {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .action {
|
||||||
|
margin-right: 0.2em;
|
||||||
|
opacity: 0.2;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line.disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li {
|
||||||
|
padding: 0 0 0 2px;
|
||||||
|
min-width: 80px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li:active {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend {
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend_container {
|
||||||
|
float: right;
|
||||||
|
padding-right: 10px;
|
||||||
|
width: 0;
|
||||||
|
z-index: 1;
|
||||||
|
position: relative;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spaced {
|
||||||
|
margin-top: 20px !important;
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,350 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
|
||||||
|
|
||||||
|
function drawGraph(from, to) {
|
||||||
|
retrieveDataAndDrawLineGraph("battery", from, to);
|
||||||
|
retrieveDataAndDrawLineGraph("light", from, to);
|
||||||
|
retrieveDataAndDrawLineGraph("pressure", from, to);
|
||||||
|
retrieveDataAndDrawLineGraph("proximity", from, to);
|
||||||
|
retrieveDataAndDrawMultiLineGraph("accelerometer", from, to);
|
||||||
|
retrieveDataAndDrawMultiLineGraph("magnetic", from, to);
|
||||||
|
retrieveDataAndDrawMultiLineGraph("rotation", from, to);
|
||||||
|
retrieveDataAndDrawMultiLineGraph("gyroscope", from, to);
|
||||||
|
retrieveDataAndDrawMultiLineGraph("gravity", from, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
function retrieveDataAndDrawLineGraph(sensorType, from, to) {
|
||||||
|
var backendApiUrl = $("#device-chart").data("backend-api-url") + sensorType + "?from=" + from + "&to=" + to;
|
||||||
|
var successCallback = function (data) {
|
||||||
|
if (data) {
|
||||||
|
drawLineGraph(JSON.parse(data), sensorType);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
invokerUtil.get(backendApiUrl, successCallback, function (message) {
|
||||||
|
console.log(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function retrieveDataAndDrawMultiLineGraph(sensorType, from, to) {
|
||||||
|
var backendApiUrl = $("#device-chart").data("backend-api-url") + sensorType + "?from=" + from + "&to=" + to;
|
||||||
|
var successCallback = function (data) {
|
||||||
|
if (data) {
|
||||||
|
drawMultiLineGraph(JSON.parse(data), sensorType);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
invokerUtil.get(backendApiUrl, successCallback, function (message) {
|
||||||
|
console.log(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawLineGraph(data, type) {
|
||||||
|
var chartWrapperElmId = "#device-chart";
|
||||||
|
var graphWidth = $(chartWrapperElmId).width() - 50;
|
||||||
|
if (data.length == 0 || data.length == undefined) {
|
||||||
|
$("#chart-" + type).html("<br/>No data available...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$("#chart-" + type).empty();
|
||||||
|
|
||||||
|
var graphConfig = {
|
||||||
|
element: document.getElementById("chart-" + type),
|
||||||
|
width: graphWidth,
|
||||||
|
height: 400,
|
||||||
|
strokeWidth: 2,
|
||||||
|
renderer: 'line',
|
||||||
|
interpolation: "linear",
|
||||||
|
unstack: true,
|
||||||
|
stack: false,
|
||||||
|
xScale: d3.time.scale(),
|
||||||
|
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0.2},
|
||||||
|
series: []
|
||||||
|
};
|
||||||
|
|
||||||
|
var tzOffset = new Date().getTimezoneOffset() * 60;
|
||||||
|
|
||||||
|
var min = Number.MAX_VALUE;
|
||||||
|
var max = Number.MIN_VALUE;
|
||||||
|
var range_min = 99999, range_max = 0;
|
||||||
|
var max_val = parseInt(getData(data[0], type));
|
||||||
|
var min_val = max_val;
|
||||||
|
var chartData = [];
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
var y_val = parseInt(getData(data[i], type));
|
||||||
|
if (y_val > max_val) {
|
||||||
|
max_val = y_val;
|
||||||
|
} else if (y_val < min_val) {
|
||||||
|
min_val = y_val;
|
||||||
|
}
|
||||||
|
chartData.push(
|
||||||
|
{
|
||||||
|
x: parseInt(data[i].values.time) - tzOffset,
|
||||||
|
y: y_val
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (range_max < max_val) {
|
||||||
|
range_max = max_val;
|
||||||
|
}
|
||||||
|
if (range_min > min_val) {
|
||||||
|
range_min = min_val;
|
||||||
|
}
|
||||||
|
graphConfig['series'].push(
|
||||||
|
{
|
||||||
|
'color': palette.color(),
|
||||||
|
'data': chartData,
|
||||||
|
'name': type,
|
||||||
|
'scale': d3.scale.linear().domain([Math.min(min, min_val), Math.max(max, max_val)])
|
||||||
|
.nice()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var graph = new Rickshaw.Graph(graphConfig);
|
||||||
|
|
||||||
|
graph.render();
|
||||||
|
|
||||||
|
var xAxis = new Rickshaw.Graph.Axis.Time({
|
||||||
|
graph: graph
|
||||||
|
});
|
||||||
|
|
||||||
|
xAxis.render();
|
||||||
|
|
||||||
|
var yAxis = new Rickshaw.Graph.Axis.Y.Scaled({
|
||||||
|
graph: graph,
|
||||||
|
orientation: 'left',
|
||||||
|
element: document.getElementById("y_axis-" + type),
|
||||||
|
width: 40,
|
||||||
|
height: 410,
|
||||||
|
'scale': d3.scale.linear().domain([Math.min(min, range_min), Math.max(max, range_max)]).nice()
|
||||||
|
});
|
||||||
|
|
||||||
|
yAxis.render();
|
||||||
|
|
||||||
|
var slider = new Rickshaw.Graph.RangeSlider.Preview({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById("slider-" + type)
|
||||||
|
});
|
||||||
|
|
||||||
|
var legend = new Rickshaw.Graph.Legend({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById('legend-' + type)
|
||||||
|
});
|
||||||
|
|
||||||
|
var hoverDetail = new Rickshaw.Graph.HoverDetail({
|
||||||
|
graph: graph,
|
||||||
|
formatter: function (series, x, y) {
|
||||||
|
var date = '<span class="date">' +
|
||||||
|
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
||||||
|
var swatch = '<span class="detail_swatch" style="background-color: ' +
|
||||||
|
series.color + '"></span>';
|
||||||
|
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
|
||||||
|
var order = new Rickshaw.Graph.Behavior.Series.Order({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
|
||||||
|
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function drawMultiLineGraph(data, type) {
|
||||||
|
var chartWrapperElmId = "#device-chart";
|
||||||
|
var graphWidth = $(chartWrapperElmId).width() - 50;
|
||||||
|
if (data.length == 0 || data.length == undefined) {
|
||||||
|
$("#chart-" + type).html("<br/>No data available...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$("#chart-" + type).empty();
|
||||||
|
|
||||||
|
var graphConfig = {
|
||||||
|
element: document.getElementById("chart-" + type),
|
||||||
|
width: graphWidth,
|
||||||
|
height: 400,
|
||||||
|
strokeWidth: 2,
|
||||||
|
renderer: 'line',
|
||||||
|
interpolation: "linear",
|
||||||
|
unstack: true,
|
||||||
|
stack: false,
|
||||||
|
xScale: d3.time.scale(),
|
||||||
|
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0.2},
|
||||||
|
series: []
|
||||||
|
};
|
||||||
|
|
||||||
|
var tzOffset = new Date().getTimezoneOffset() * 60;
|
||||||
|
|
||||||
|
var min = Number.MAX_VALUE;
|
||||||
|
var max = Number.MIN_VALUE;
|
||||||
|
var range_min = 99999, range_max = 0;
|
||||||
|
var max_valX = parseInt(data[0].values.x);
|
||||||
|
var min_valX = max_valX;
|
||||||
|
|
||||||
|
var max_valY = parseInt(data[0].values.x);
|
||||||
|
var min_valY = max_valY;
|
||||||
|
|
||||||
|
var max_valZ = parseInt(data[0].values.x);
|
||||||
|
var min_valZ = max_valZ;
|
||||||
|
var chartDataX = [];
|
||||||
|
var chartDataY = [];
|
||||||
|
var chartDataZ = [];
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
var y_valX = parseInt(data[i].values.x);
|
||||||
|
if (y_valX > max_valX) {
|
||||||
|
max_valX = y_valX;
|
||||||
|
} else if (y_valX < min_valX) {
|
||||||
|
min_valX = y_valX;
|
||||||
|
}
|
||||||
|
|
||||||
|
var y_valY = parseInt(data[i].values.y);
|
||||||
|
if (y_valY > max_valY) {
|
||||||
|
max_valY = y_valY;
|
||||||
|
} else if (y_valY < min_valY) {
|
||||||
|
min_valY = y_valY;
|
||||||
|
}
|
||||||
|
|
||||||
|
var y_valZ = parseInt(data[i].values.z);
|
||||||
|
if (y_valZ > max_valZ) {
|
||||||
|
max_valZ = y_valZ;
|
||||||
|
} else if (y_valZ < min_valZ) {
|
||||||
|
min_valZ = y_valZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
chartDataX.push(
|
||||||
|
{
|
||||||
|
x: parseInt(data[i].values.time) - tzOffset,
|
||||||
|
y: parseInt(data[i].values.y)
|
||||||
|
});
|
||||||
|
|
||||||
|
chartDataY.push(
|
||||||
|
{
|
||||||
|
x: parseInt(data[i].values.time) - tzOffset,
|
||||||
|
y: parseInt(data[i].values.x)
|
||||||
|
});
|
||||||
|
|
||||||
|
chartDataZ.push(
|
||||||
|
{
|
||||||
|
x: parseInt(data[i].values.time) - tzOffset,
|
||||||
|
y: parseInt(data[i].values.z)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
graphConfig['series'].push(
|
||||||
|
{
|
||||||
|
'color': palette.color(),
|
||||||
|
'data': chartDataX,
|
||||||
|
'name': "x",
|
||||||
|
'scale': d3.scale.linear().domain([Math.min(min, min_valX), Math.max(max, max_valX)]).nice()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'color': palette.color(),
|
||||||
|
'data': chartDataY,
|
||||||
|
'name': "y",
|
||||||
|
'scale': d3.scale.linear().domain([Math.min(min, min_valY), Math.max(max, max_valY)]).nice()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'color': palette.color(),
|
||||||
|
'data': chartDataZ,
|
||||||
|
'name': "z",
|
||||||
|
'scale': d3.scale.linear().domain([Math.min(min, min_valZ), Math.max(max, max_valZ)]).nice()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var graph = new Rickshaw.Graph(graphConfig);
|
||||||
|
|
||||||
|
graph.render();
|
||||||
|
|
||||||
|
var xAxis = new Rickshaw.Graph.Axis.Time({
|
||||||
|
graph: graph
|
||||||
|
});
|
||||||
|
|
||||||
|
xAxis.render();
|
||||||
|
|
||||||
|
var yAxis = new Rickshaw.Graph.Axis.Y({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById("y_axis-" + type)
|
||||||
|
});
|
||||||
|
|
||||||
|
yAxis.render();
|
||||||
|
|
||||||
|
var slider = new Rickshaw.Graph.RangeSlider.Preview({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById("slider-" + type)
|
||||||
|
});
|
||||||
|
|
||||||
|
var legend = new Rickshaw.Graph.Legend({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById('legend-' + type)
|
||||||
|
});
|
||||||
|
|
||||||
|
var hoverDetail = new Rickshaw.Graph.HoverDetail({
|
||||||
|
graph: graph,
|
||||||
|
formatter: function (series, x, y) {
|
||||||
|
var date = '<span class="date">' +
|
||||||
|
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
||||||
|
var swatch = '<span class="detail_swatch" style="background-color: ' +
|
||||||
|
series.color + '"></span>';
|
||||||
|
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
|
||||||
|
var order = new Rickshaw.Graph.Behavior.Series.Order({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
|
||||||
|
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getData(data, type) {
|
||||||
|
var columnData
|
||||||
|
switch (type) {
|
||||||
|
case "battery" :
|
||||||
|
columnData = data.values.level
|
||||||
|
break;
|
||||||
|
case "light" :
|
||||||
|
columnData = data.values.light
|
||||||
|
break;
|
||||||
|
case "proximity" :
|
||||||
|
columnData = data.values.proximity
|
||||||
|
break;
|
||||||
|
case "pressure" :
|
||||||
|
columnData = data.values.pressure
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return columnData;
|
||||||
|
}
|
||||||
@ -14,7 +14,7 @@
|
|||||||
Operations
|
Operations
|
||||||
</div>
|
</div>
|
||||||
<div class="add-margin-top-4x">
|
<div class="add-margin-top-4x">
|
||||||
{{unit "iot.unit.device.operation-bar" device=device backendApiUri=backendApiUri}}
|
{{unit "iot.unit.device.operation-bar" device=device backendApiUri=backendApiUri autoCompleteParams=autoCompleteParams}}
|
||||||
</div>
|
</div>
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@
|
|||||||
<div class="panel panel-default tab-pane active"
|
<div class="panel panel-default tab-pane active"
|
||||||
id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
|
id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
|
||||||
<div class="panel-heading">Device Statistics</div>
|
<div class="panel-heading">Device Statistics</div>
|
||||||
{{unit "iot.unit.device.stats" device=device}}
|
{{unit "cdmf.unit.device.type.android_sense.realtime.analytics-view" device=device}}
|
||||||
</div>
|
</div>
|
||||||
<div class="panel panel-default tab-pane" id="device_location" role="tabpanel"
|
<div class="panel panel-default tab-pane" id="device_location" role="tabpanel"
|
||||||
aria-labelledby="device_location">
|
aria-labelledby="device_location">
|
||||||
|
|||||||
@ -20,14 +20,19 @@ function onRequest(context) {
|
|||||||
var log = new Log("device-view.js");
|
var log = new Log("device-view.js");
|
||||||
var deviceType = context.uriParams.deviceType;
|
var deviceType = context.uriParams.deviceType;
|
||||||
var deviceId = request.getParameter("id");
|
var deviceId = request.getParameter("id");
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var autoCompleteParams = [
|
||||||
|
{"name" : "deviceId", "value" : deviceId}
|
||||||
|
];
|
||||||
|
|
||||||
if (deviceType && deviceId) {
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||||
var deviceModule = require("/app/modules/device.js").deviceModule;
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
var device = deviceModule.viewDevice(deviceType, deviceId);
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
|
||||||
if (device && device.status != "error") {
|
if (device && device.status != "error") {
|
||||||
return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/android_sense/"};
|
return {
|
||||||
|
"device": device,
|
||||||
|
"backendApiUri": devicemgtProps["httpsURL"] + "/android_sense/",
|
||||||
|
"autoCompleteParams": autoCompleteParams
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
||||||
exit();
|
exit();
|
||||||
|
|||||||
@ -0,0 +1,106 @@
|
|||||||
|
|
||||||
|
{{#zone "topCss"}}
|
||||||
|
{{css "css/graph.css"}}
|
||||||
|
{{/zone}}
|
||||||
|
<span id="details" data-devicetype="{{device.type}}" data-deviceid="{{device.deviceIdentifier}}"
|
||||||
|
data-appcontext="{{@app.context}}"></span>
|
||||||
|
<div id="chartWrapper">
|
||||||
|
</div>
|
||||||
|
<div id="div-chart" data-websocketurl="{{websocketEndpoint}}">
|
||||||
|
<div id="chartWrapper-battery" class="chartWrapper"><div id="y_axis-battery" class="custom_y_axis">Battery</div>
|
||||||
|
<div class="legend_container-battery">
|
||||||
|
<div id="smoother-battery" title="Smoothing"></div>
|
||||||
|
<div id="legend-battery"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-battery" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-light" class="chartWrapper"><div id="y_axis-light" class="custom_y_axis">Light</div>
|
||||||
|
<div class="legend_container-light">
|
||||||
|
<div id="smoother-light" title="Smoothing"></div>
|
||||||
|
<div id="legend-light"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-light" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-pressure" class="chartWrapper"><div id="y_axis-pressure" class="custom_y_axis">Pressure</div>
|
||||||
|
<div class="legend_container-pressure">
|
||||||
|
<div id="smoother-pressure" title="Smoothing"></div>
|
||||||
|
<div id="legend-pressure"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-pressure" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-proximity" class="chartWrapper"><div id="y_axis-proximity" class="custom_y_axis">Proximity</div>
|
||||||
|
<div class="legend_container-proximity">
|
||||||
|
<div id="smoother-proximity" title="Smoothing"></div>
|
||||||
|
<div id="legend-proximity"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-proximity" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-accelerometer" class="chartWrapper"><div id="y_axis-accelerometer" class="custom_y_axis">Accelerometer</div>
|
||||||
|
<div class="legend_container-accelerometer">
|
||||||
|
<div id="smoother-accelerometer" title="Smoothing"></div>
|
||||||
|
<div id="legend-accelerometer"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-accelerometer" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-magnetic" class="chartWrapper"><div id="y_axis-magnetic" class="custom_y_axis">Magnetic</div>
|
||||||
|
<div class="legend_container-magnetic">
|
||||||
|
<div id="smoother-magnetic" title="Smoothing"></div>
|
||||||
|
<div id="legend-magnetic"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-magnetic" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-rotation" class="chartWrapper"><div id="y_axis-rotation" class="custom_y_axis">Rotation</div>
|
||||||
|
<div class="legend_container-rotation">
|
||||||
|
<div id="smoother-rotation" title="Smoothing"></div>
|
||||||
|
<div id="legend-rotation"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-rotation" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-gyroscope" class="chartWrapper"><div id="y_axis-gyroscope" class="custom_y_axis">Gyroscope</div>
|
||||||
|
<div class="legend_container-gyroscope">
|
||||||
|
<div id="smoother-gyroscope" title="Smoothing"></div>
|
||||||
|
<div id="legend-gyroscope"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-gyroscope" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="chartWrapper-gravity" class="chartWrapper"><div id="y_axis-gravity" class="custom_y_axis">Gravity</div>
|
||||||
|
<div class="legend_container-gravity">
|
||||||
|
<div id="smoother-gravity" title="Smoothing"></div>
|
||||||
|
<div id="legend-gravity"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart-gravity" class="custom_rickshaw_graph"></div>
|
||||||
|
<div class="custom_x_axis">Time</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<a class="padding-left"
|
||||||
|
href="{{@app.context}}/device/{{device.type}}/analytics?deviceId={{device.deviceIdentifier}}&deviceName={{device.name}}">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-statistics fw-stack-1x"></i>
|
||||||
|
</span> View Device Analytics
|
||||||
|
</a>
|
||||||
|
<!-- /statistics -->
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/d3.min.js"}}
|
||||||
|
{{js "js/rickshaw.min.js"}}
|
||||||
|
{{js "js/moment.min.js"}}
|
||||||
|
{{js "js/socket.io.min.js"}}
|
||||||
|
{{js "js/device-stats.js"}}
|
||||||
|
{{/zone}}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var log = new Log("stats.js");
|
||||||
|
var device = context.unit.params.device;
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var websocketEndpoint = devicemgtProps["httpsURL"].replace("https", "wss");
|
||||||
|
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
||||||
|
var token = ""
|
||||||
|
if (tokenPair) {
|
||||||
|
token = tokenPair.accessToken;
|
||||||
|
}
|
||||||
|
websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.android.sense/1.0.0?" +
|
||||||
|
"token="+ token +"&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type;
|
||||||
|
return {"device": device, "websocketEndpoint" : websocketEndpoint};
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,306 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var ws;
|
||||||
|
var typeId = 3;
|
||||||
|
var batteryId = 5;
|
||||||
|
var gps_latId = 6;
|
||||||
|
var gps_longId = 7;
|
||||||
|
var accelerometer_xId = 8;
|
||||||
|
var accelerometer_yId = 9;
|
||||||
|
var accelerometer_zId = 10;
|
||||||
|
var magnetic_xId = 11;
|
||||||
|
var magnetic_yId = 12;
|
||||||
|
var magnetic_zId = 13;
|
||||||
|
var gyroscope_xId = 14;
|
||||||
|
var gyroscope_yId = 15;
|
||||||
|
var gyroscope_zId = 16;
|
||||||
|
var lightId = 17;
|
||||||
|
var pressureId = 18;
|
||||||
|
var proximityId = 19;
|
||||||
|
var gravity_xId = 20;
|
||||||
|
var gravity_yId = 21;
|
||||||
|
var gravity_zId = 22;
|
||||||
|
var rotation_xId = 23;
|
||||||
|
var rotation_yId = 24;
|
||||||
|
var rotation_zId = 25;
|
||||||
|
var wordId = 26;
|
||||||
|
var word_sessionIdId = 27;
|
||||||
|
var word_statusId = 28;
|
||||||
|
|
||||||
|
var battery;
|
||||||
|
var batteryData = [];
|
||||||
|
|
||||||
|
var light;
|
||||||
|
var lightData = [];
|
||||||
|
|
||||||
|
var pressure;
|
||||||
|
var pressureData = [];
|
||||||
|
|
||||||
|
var proximity;
|
||||||
|
var proximityData = [];
|
||||||
|
|
||||||
|
var accelerometer;
|
||||||
|
var accelerometer_xData = [];
|
||||||
|
var accelerometer_yData = [];
|
||||||
|
var accelerometer_zData = [];
|
||||||
|
|
||||||
|
var magnetic;
|
||||||
|
var magnetic_xData = [];
|
||||||
|
var magnetic_yData = [];
|
||||||
|
var magnetic_zData = [];
|
||||||
|
|
||||||
|
var gyroscope;
|
||||||
|
var gyroscope_xData = [];
|
||||||
|
var gyroscope_yData = [];
|
||||||
|
var gyroscope_zData = [];
|
||||||
|
|
||||||
|
var gravity;
|
||||||
|
var gravity_xData = [];
|
||||||
|
var gravity_yData = [];
|
||||||
|
var gravity_zData = [];
|
||||||
|
|
||||||
|
var rotation;
|
||||||
|
var rotation_xData = [];
|
||||||
|
var rotation_yData = [];
|
||||||
|
var rotation_zData = [];
|
||||||
|
|
||||||
|
var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
|
||||||
|
|
||||||
|
$(window).load(function () {
|
||||||
|
|
||||||
|
battery = lineGraph("battery", batteryData);
|
||||||
|
light = lineGraph("light", lightData);
|
||||||
|
pressure = lineGraph("pressure", pressureData);
|
||||||
|
proximity = lineGraph("proximity", proximityData);
|
||||||
|
accelerometer = threeDlineGraph("accelerometer", accelerometer_xData, accelerometer_yData, accelerometer_zData);
|
||||||
|
magnetic = threeDlineGraph("magnetic", magnetic_xData, magnetic_yData, magnetic_zData);
|
||||||
|
gyroscope = threeDlineGraph("gyroscope", gyroscope_xData, gyroscope_yData, gyroscope_zData);
|
||||||
|
gravity = threeDlineGraph("gravity", gravity_xData, gravity_yData, gravity_zData);
|
||||||
|
rotation = threeDlineGraph("rotation", rotation_xData, rotation_yData, rotation_zData);
|
||||||
|
|
||||||
|
var websocketUrl = $("#div-chart").data("websocketurl");
|
||||||
|
connect(websocketUrl)
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).unload(function () {
|
||||||
|
disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
function threeDlineGraph(type, xChartData, yChartData, zChartData) {
|
||||||
|
var tNow = new Date().getTime() / 1000;
|
||||||
|
for (var i = 0; i < 30; i++) {
|
||||||
|
xChartData.push({
|
||||||
|
x: tNow - (30 - i) * 15,
|
||||||
|
y: parseFloat(0)
|
||||||
|
});
|
||||||
|
yChartData.push({
|
||||||
|
x: tNow - (30 - i) * 15,
|
||||||
|
y: parseFloat(0)
|
||||||
|
});
|
||||||
|
zChartData.push({
|
||||||
|
x: tNow - (30 - i) * 15,
|
||||||
|
y: parseFloat(0)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var graph = new Rickshaw.Graph({
|
||||||
|
element: document.getElementById("chart-" + type),
|
||||||
|
width: $("#div-chart").width() - 50,
|
||||||
|
height: 300,
|
||||||
|
renderer: "line",
|
||||||
|
padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2},
|
||||||
|
xScale: d3.time.scale(),
|
||||||
|
series: [
|
||||||
|
{'color': palette.color(), 'data': xChartData, 'name': "x - " + type},
|
||||||
|
{'color': palette.color(), 'data': yChartData, 'name': "y - " + type},
|
||||||
|
{'color': palette.color(), 'data': zChartData, 'name': "z - " + type}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
graph.render();
|
||||||
|
|
||||||
|
var xAxis = new Rickshaw.Graph.Axis.Time({
|
||||||
|
graph: graph
|
||||||
|
});
|
||||||
|
|
||||||
|
xAxis.render();
|
||||||
|
|
||||||
|
new Rickshaw.Graph.Legend({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById('legend-' + type)
|
||||||
|
});
|
||||||
|
|
||||||
|
var detail = new Rickshaw.Graph.HoverDetail({
|
||||||
|
graph: graph
|
||||||
|
});
|
||||||
|
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lineGraph(type, chartData) {
|
||||||
|
var tNow = new Date().getTime() / 1000;
|
||||||
|
for (var i = 0; i < 30; i++) {
|
||||||
|
chartData.push({
|
||||||
|
x: tNow - (30 - i) * 15,
|
||||||
|
y: parseFloat(0)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var graph = new Rickshaw.Graph({
|
||||||
|
element: document.getElementById("chart-" + type),
|
||||||
|
width: $("#div-chart").width() - 50,
|
||||||
|
height: 300,
|
||||||
|
renderer: "line",
|
||||||
|
padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2},
|
||||||
|
xScale: d3.time.scale(),
|
||||||
|
series: [{
|
||||||
|
'color': palette.color(),
|
||||||
|
'data': chartData,
|
||||||
|
'name': type
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
graph.render();
|
||||||
|
|
||||||
|
var xAxis = new Rickshaw.Graph.Axis.Time({
|
||||||
|
graph: graph
|
||||||
|
});
|
||||||
|
|
||||||
|
xAxis.render();
|
||||||
|
|
||||||
|
new Rickshaw.Graph.Axis.Y({
|
||||||
|
graph: graph,
|
||||||
|
orientation: 'left',
|
||||||
|
height: 300,
|
||||||
|
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
|
||||||
|
element: document.getElementById('y_axis')
|
||||||
|
});
|
||||||
|
|
||||||
|
new Rickshaw.Graph.Legend({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById('legend-' + type)
|
||||||
|
});
|
||||||
|
|
||||||
|
new Rickshaw.Graph.HoverDetail({
|
||||||
|
graph: graph,
|
||||||
|
formatter: function (series, x, y) {
|
||||||
|
var date = '<span class="date">' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
||||||
|
var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
|
||||||
|
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
//websocket connection
|
||||||
|
function connect(target) {
|
||||||
|
if ('WebSocket' in window) {
|
||||||
|
ws = new WebSocket(target);
|
||||||
|
} else if ('MozWebSocket' in window) {
|
||||||
|
ws = new MozWebSocket(target);
|
||||||
|
} else {
|
||||||
|
console.log('WebSocket is not supported by this browser.');
|
||||||
|
}
|
||||||
|
if (ws) {
|
||||||
|
ws.onmessage = function (event) {
|
||||||
|
var dataPoint = JSON.parse(event.data);
|
||||||
|
if (dataPoint) {
|
||||||
|
var time = parseInt(dataPoint[4]) / 1000;
|
||||||
|
switch (dataPoint[typeId]) {
|
||||||
|
case "battery":
|
||||||
|
graphUpdate(batteryData, time, dataPoint[batteryId], battery);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "light":
|
||||||
|
graphUpdate(lightData, time, dataPoint[lightId], light);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "pressure":
|
||||||
|
graphUpdate(pressureData, time, dataPoint[pressureId], pressure);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "proximity":
|
||||||
|
graphUpdate(proximityData, time, dataPoint[proximityId], proximity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "accelerometer":
|
||||||
|
dataUpdate(accelerometer_xData, time, dataPoint[accelerometer_xId]);
|
||||||
|
dataUpdate(accelerometer_yData, time, dataPoint[accelerometer_yId]);
|
||||||
|
dataUpdate(accelerometer_zData, time, dataPoint[accelerometer_zId]);
|
||||||
|
accelerometer.update();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "magnetic":
|
||||||
|
dataUpdate(magnetic_xData, time, dataPoint[magnetic_xId]);
|
||||||
|
dataUpdate(magnetic_yData, time, dataPoint[magnetic_yId]);
|
||||||
|
dataUpdate(magnetic_zData, time, dataPoint[magnetic_zId]);
|
||||||
|
magnetic.update();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "gyroscope":
|
||||||
|
dataUpdate(gyroscope_xData, time, dataPoint[gyroscope_xId]);
|
||||||
|
dataUpdate(gyroscope_yData, time, dataPoint[gyroscope_yId]);
|
||||||
|
dataUpdate(gyroscope_zData, time, dataPoint[gyroscope_zId]);
|
||||||
|
gyroscope.update();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "rotation":
|
||||||
|
dataUpdate(magnetic_xData, time, dataPoint[rotation_xId]);
|
||||||
|
dataUpdate(magnetic_yData, time, dataPoint[rotation_yId]);
|
||||||
|
dataUpdate(magnetic_zData, time, dataPoint[rotation_zId]);
|
||||||
|
rotation.update();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "gravity":
|
||||||
|
dataUpdate(gravity_xData, time, dataPoint[gravity_xId]);
|
||||||
|
dataUpdate(gravity_yData, time, dataPoint[gravity_yId]);
|
||||||
|
dataUpdate(gravity_zData, time, dataPoint[gravity_zId]);
|
||||||
|
gravity.update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function graphUpdate(chartData, xValue, yValue, graph) {
|
||||||
|
chartData.push({
|
||||||
|
x: parseInt(xValue),
|
||||||
|
y: parseFloat(yValue)
|
||||||
|
});
|
||||||
|
chartData.shift();
|
||||||
|
graph.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
function dataUpdate(chartData, xValue, yValue) {
|
||||||
|
chartData.push({
|
||||||
|
x: parseInt(xValue),
|
||||||
|
y: parseFloat(yValue)
|
||||||
|
});
|
||||||
|
chartData.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function disconnect() {
|
||||||
|
if (ws != null) {
|
||||||
|
ws.close();
|
||||||
|
ws = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -21,53 +21,32 @@ package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
|
|||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.DeviceData;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.FormParam;
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@API(name = "arduino", version = "1.0.0", context = "/arduino", tags = {"arduino"})
|
@API(name = "arduino", version = "1.0.0", context = "/arduino", tags = {"arduino"})
|
||||||
@DeviceType(value = "arduino")
|
@DeviceType(value = "arduino")
|
||||||
public interface ArduinoControllerService {
|
public interface ArduinoControllerService {
|
||||||
|
|
||||||
@Path("device/register/{deviceId}/{ip}/{port}")
|
|
||||||
@POST
|
|
||||||
Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
|
||||||
@PathParam("port") String devicePort, @Context HttpServletRequest request);
|
|
||||||
|
|
||||||
@Path("device/{deviceId}/bulb")
|
@Path("device/{deviceId}/bulb")
|
||||||
@POST
|
@POST
|
||||||
@Feature(code = "bulb", name = "Control Bulb", type = "operation", description = "Control Bulb on Arduino Uno")
|
@Feature(code = "bulb", name = "Control Bulb", type = "operation", description = "Control Bulb on Arduino Uno")
|
||||||
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state);
|
||||||
@FormParam("state") String state);
|
|
||||||
|
|
||||||
@Path("device/sensor")
|
|
||||||
@POST
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
Response pushData(DeviceData dataMsg);
|
|
||||||
|
|
||||||
@Path("device/{deviceId}/controls")
|
@Path("device/{deviceId}/controls")
|
||||||
@GET
|
@GET
|
||||||
Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol);
|
Response readControls(@PathParam("deviceId") String deviceId);
|
||||||
|
|
||||||
@Path("device/temperature")
|
|
||||||
@POST
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retreive Sensor data for the device type
|
* Retreive Sensor data for the device type
|
||||||
*/
|
*/
|
||||||
@Path("device/stats/{deviceId}/sensors/temperature")
|
@Path("device/stats/{deviceId}")
|
||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
|
|||||||
@ -24,22 +24,18 @@ import org.wso2.carbon.analytics.dataservice.commons.SORT;
|
|||||||
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
||||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.DeviceData;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.FormParam;
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -47,41 +43,22 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(ArduinoControllerServiceImpl.class);
|
private static Log log = LogFactory.getLog(ArduinoControllerServiceImpl.class);
|
||||||
private static Map<String, LinkedList<String>> internalControlsQueue = new HashMap<>();
|
private static Map<String, LinkedList<String>> internalControlsQueue = new HashMap<>();
|
||||||
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Path("device/register/{deviceId}/{ip}/{port}")
|
|
||||||
@POST
|
|
||||||
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
|
||||||
@PathParam("port") String devicePort, @Context HttpServletRequest request) {
|
|
||||||
String result;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: ");
|
|
||||||
}
|
|
||||||
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
|
|
||||||
deviceToIpMap.put(deviceId, deviceHttpEndpoint);
|
|
||||||
result = "Device-IP Registered";
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug(result);
|
|
||||||
}
|
|
||||||
return Response.ok(result).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Path("device/{deviceId}/bulb")
|
@Path("device/{deviceId}/bulb")
|
||||||
@POST
|
@POST
|
||||||
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
|
||||||
@FormParam("state") String state) {
|
try {
|
||||||
|
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
|
||||||
|
ArduinoConstants.DEVICE_TYPE))) {
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||||
|
}
|
||||||
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
||||||
String operation = "BULB:" + state.toUpperCase();
|
String operation = "BULB:" + state.toUpperCase();
|
||||||
log.info(operation);
|
|
||||||
if (deviceControlList == null) {
|
if (deviceControlList == null) {
|
||||||
deviceControlList = new LinkedList<>();
|
deviceControlList = new LinkedList<>();
|
||||||
deviceControlList.add(operation);
|
deviceControlList.add(operation);
|
||||||
@ -90,28 +67,21 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
deviceControlList.add(operation);
|
deviceControlList.add(operation);
|
||||||
}
|
}
|
||||||
return Response.status(Response.Status.OK.getStatusCode()).build();
|
return Response.status(Response.Status.OK.getStatusCode()).build();
|
||||||
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Path("device/sensor")
|
|
||||||
@POST
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
public Response pushData(DeviceData dataMsg) {
|
|
||||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
||||||
String deviceId = dataMsg.deviceId;
|
|
||||||
float pinData = dataMsg.value;
|
|
||||||
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
|
||||||
log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" +
|
|
||||||
deviceId + "] of owner [" + owner + "]");
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK.getStatusCode()).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Path("device/{deviceId}/controls")
|
@Path("device/{deviceId}/controls")
|
||||||
@GET
|
@GET
|
||||||
public Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol) {
|
public Response readControls(@PathParam("deviceId") String deviceId) {
|
||||||
|
try {
|
||||||
|
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
|
||||||
|
ArduinoConstants.DEVICE_TYPE))) {
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||||
|
}
|
||||||
String result;
|
String result;
|
||||||
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
|
||||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
@ -136,31 +106,24 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
return Response.status(Response.Status.NO_CONTENT.getStatusCode()).entity(result).build();
|
return Response.status(Response.Status.NO_CONTENT.getStatusCode()).entity(result).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Path("device/temperature")
|
@Path("device/stats/{deviceId}")
|
||||||
@POST
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
public Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request) {
|
|
||||||
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
||||||
String deviceId = dataMsg.deviceId;
|
|
||||||
float temperature = dataMsg.value;
|
|
||||||
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
|
||||||
log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId +
|
|
||||||
"] of owner [" + owner + "]");
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
return Response.status(Response.Status.OK.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Path("device/stats/{deviceId}/sensors/temperature")
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
public Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
|
public Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
|
||||||
@QueryParam("to") long to) {
|
@QueryParam("to") long to) {
|
||||||
|
try {
|
||||||
|
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
|
||||||
|
ArduinoConstants.DEVICE_TYPE))) {
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||||
|
}
|
||||||
String fromDate = String.valueOf(from);
|
String fromDate = String.valueOf(from);
|
||||||
String toDate = String.valueOf(to);
|
String toDate = String.valueOf(to);
|
||||||
String query = "deviceId:" + deviceId + " AND deviceType:" +
|
String query = "deviceId:" + deviceId + " AND deviceType:" +
|
||||||
@ -177,6 +140,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
|
|||||||
log.error(errorMsg);
|
log.error(errorMsg);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
|
||||||
}
|
}
|
||||||
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,6 @@ import javax.ws.rs.core.Response;
|
|||||||
|
|
||||||
@Path("enrollment")
|
@Path("enrollment")
|
||||||
@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"})
|
@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"})
|
||||||
@DeviceType(value = "arduino")
|
|
||||||
public interface ArduinoManagerService {
|
public interface ArduinoManagerService {
|
||||||
|
|
||||||
@Path("devices/{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@ -61,9 +60,4 @@ public interface ArduinoManagerService {
|
|||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
Response downloadSketch(@QueryParam("deviceName") String customDeviceName);
|
Response downloadSketch(@QueryParam("deviceName") String customDeviceName);
|
||||||
|
|
||||||
@Path("devices/generate_link")
|
|
||||||
@GET
|
|
||||||
Response generateSketchLink(@QueryParam("deviceName") String deviceName);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
|
package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
||||||
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
||||||
@ -28,9 +31,9 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ZipUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
||||||
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
||||||
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
|
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
@ -46,6 +49,7 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -58,6 +62,7 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
|
|
||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
|
private static Log log = LogFactory.getLog(ArduinoManagerServiceImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Path("devices/{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@ -143,49 +148,38 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Path("devices/download")
|
@Path("/devices/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/zip")
|
||||||
public Response downloadSketch(@QueryParam("deviceName") String customDeviceName) {
|
public Response downloadSketch(@QueryParam("deviceName") String deviceName) {
|
||||||
try {
|
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName);
|
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
|
||||||
rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
|
||||||
return rb.build();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (JWTClientException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (UserStoreException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Path("devices/generate_link")
|
|
||||||
@GET
|
|
||||||
public Response generateSketchLink(@QueryParam("deviceName") String deviceName) {
|
|
||||||
try {
|
try {
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName);
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
||||||
return rb.build();
|
response.status(Response.Status.OK);
|
||||||
|
response.type("application/zip");
|
||||||
|
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
|
Response resp = response.build();
|
||||||
|
zipFile.getZipFile().delete();
|
||||||
|
return resp;
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
||||||
} catch (DeviceManagementException ex) {
|
} catch (DeviceManagementException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
} catch (JWTClientException ex) {
|
} catch (JWTClientException ex) {
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
log.error(ex.getMessage(), ex);
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
} catch (APIManagerException ex) {
|
} catch (APIManagerException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (DeviceControllerException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
} catch (UserStoreException ex) {
|
} catch (UserStoreException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,8 +204,7 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient();
|
JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient();
|
||||||
String scopes = "device_type_" + ArduinoConstants.DEVICE_TYPE + " device_" + deviceId;
|
String scopes = "device_type_" + ArduinoConstants.DEVICE_TYPE + " device_" + deviceId;
|
||||||
AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(),
|
AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(),
|
||||||
apiApplicationKey.getConsumerSecret(), owner,
|
apiApplicationKey.getConsumerSecret(), owner, scopes);
|
||||||
scopes);
|
|
||||||
//create token
|
//create token
|
||||||
String accessToken = accessTokenInfo.getAccessToken();
|
String accessToken = accessTokenInfo.getAccessToken();
|
||||||
String refreshToken = accessTokenInfo.getRefreshToken();
|
String refreshToken = accessTokenInfo.getRefreshToken();
|
||||||
@ -223,8 +216,7 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
|
|||||||
}
|
}
|
||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(),
|
ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(),
|
||||||
ArduinoConstants.DEVICE_TYPE, deviceId,
|
ArduinoConstants.DEVICE_TYPE, deviceId, deviceName, accessToken, refreshToken);
|
||||||
deviceName, accessToken, refreshToken);
|
|
||||||
zipFile.setDeviceId(deviceId);
|
zipFile.setDeviceId(deviceId);
|
||||||
return zipFile;
|
return zipFile;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class DeviceData {
|
|
||||||
@XmlElement(required = true) public String deviceId;
|
|
||||||
@XmlElement(required = true) public String reply;
|
|
||||||
@XmlElement public Long time;
|
|
||||||
@XmlElement public String key;
|
|
||||||
@XmlElement public float value;
|
|
||||||
}
|
|
||||||
@ -13,11 +13,16 @@ import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException
|
|||||||
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
|
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -63,21 +68,16 @@ public class APIUtil {
|
|||||||
return analyticsDataAPI;
|
return analyticsDataAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SensorRecord> getAllEventsForDevice(String tableName, String query, List<SortByField> sortByFields) throws AnalyticsException {
|
public static List<SensorRecord> getAllEventsForDevice(String tableName, String query,
|
||||||
|
List<SortByField> sortByFields) throws AnalyticsException {
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();
|
AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();
|
||||||
int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
|
int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
|
||||||
if (eventCount == 0) {
|
if (eventCount == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
AnalyticsDrillDownRequest drillDownRequest = new AnalyticsDrillDownRequest();
|
List<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount,
|
||||||
drillDownRequest.setQuery(query);
|
sortByFields);
|
||||||
drillDownRequest.setTableName(tableName);
|
|
||||||
drillDownRequest.setRecordCount(eventCount);
|
|
||||||
if (sortByFields != null) {
|
|
||||||
drillDownRequest.setSortByFields(sortByFields);
|
|
||||||
}
|
|
||||||
List<SearchResultEntry> resultEntries = analyticsDataAPI.drillDownSearch(tenantId, drillDownRequest);
|
|
||||||
List<String> recordIds = getRecordIds(resultEntries);
|
List<String> recordIds = getRecordIds(resultEntries);
|
||||||
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
||||||
Map<String, SensorRecord> sensorDatas = createSensorData(AnalyticsDataServiceUtils.listRecords(
|
Map<String, SensorRecord> sensorDatas = createSensorData(AnalyticsDataServiceUtils.listRecords(
|
||||||
@ -159,4 +159,16 @@ public class APIUtil {
|
|||||||
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
return threadLocalCarbonContext.getTenantDomain();
|
return threadLocalCarbonContext.getTenantDomain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
|
||||||
|
(DeviceAccessAuthorizationService) ctx.getOSGiService(DeviceAccessAuthorizationService.class, null);
|
||||||
|
if (deviceAccessAuthorizationService == null) {
|
||||||
|
String msg = "Device Authorization service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return deviceAccessAuthorizationService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -187,23 +187,4 @@ public class ArduinoServiceUtils {
|
|||||||
|
|
||||||
return completeResponse.toString();
|
return completeResponse.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean publishToDAS(String deviceId, float temperature) {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
String owner = ctx.getUsername();
|
|
||||||
Object metdaData[] = {owner, ArduinoConstants.DEVICE_TYPE, deviceId, System.currentTimeMillis()};
|
|
||||||
Object payloadData[] = {temperature};
|
|
||||||
EventsPublisherService deviceAnalyticsService = (EventsPublisherService) ctx
|
|
||||||
.getOSGiService(EventsPublisherService.class, null);
|
|
||||||
if (deviceAnalyticsService != null) {
|
|
||||||
try {
|
|
||||||
deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", metdaData,
|
|
||||||
new Object[0], payloadData);
|
|
||||||
} catch (DataPublisherConfigurationException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.arduino.service.impl.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.exception.IoTException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.IoTUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.IotDeviceManagementUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used to create a zip file that includes the necessary configuration required for the agent.
|
||||||
|
*/
|
||||||
|
public class ZipUtil {
|
||||||
|
|
||||||
|
private static final String HTTPS_PORT_PROPERTY = "httpsPort";
|
||||||
|
private static final String HTTP_PORT_PROPERTY = "httpPort";
|
||||||
|
|
||||||
|
private static final String LOCALHOST = "localhost";
|
||||||
|
private static final String HTTPS_PROTOCOL_APPENDER = "https://";
|
||||||
|
private static final String HTTP_PROTOCOL_APPENDER = "http://";
|
||||||
|
|
||||||
|
public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType,
|
||||||
|
String deviceId, String deviceName, String token,
|
||||||
|
String refreshToken) throws DeviceManagementException {
|
||||||
|
|
||||||
|
String sketchFolder = "repository" + File.separator + "resources" + File.separator + "sketches";
|
||||||
|
String archivesPath = CarbonUtils.getCarbonHome() + File.separator + sketchFolder + File.separator + "archives" +
|
||||||
|
File.separator + deviceId;
|
||||||
|
String templateSketchPath = sketchFolder + File.separator + deviceType;
|
||||||
|
String iotServerIP;
|
||||||
|
|
||||||
|
try {
|
||||||
|
iotServerIP = IoTUtil.getHostName();
|
||||||
|
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
|
||||||
|
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
|
||||||
|
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
|
||||||
|
String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort;
|
||||||
|
String apimEndpoint = httpsServerEP;
|
||||||
|
|
||||||
|
Map<String, String> contextParams = new HashMap<>();
|
||||||
|
contextParams.put("TENANT_DOMAIN", APIUtil.getTenantDomainOftheUser());
|
||||||
|
contextParams.put("DEVICE_OWNER", owner);
|
||||||
|
contextParams.put("DEVICE_ID", deviceId);
|
||||||
|
contextParams.put("DEVICE_NAME", deviceName);
|
||||||
|
contextParams.put("HTTPS_EP", httpsServerEP);
|
||||||
|
contextParams.put("HTTP_EP", httpServerEP);
|
||||||
|
contextParams.put("APIM_EP", apimEndpoint);
|
||||||
|
contextParams.put("DEVICE_TOKEN", token);
|
||||||
|
contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken);
|
||||||
|
|
||||||
|
ZipArchive zipFile;
|
||||||
|
zipFile = IotDeviceManagementUtil.getSketchArchive(archivesPath, templateSketchPath, contextParams);
|
||||||
|
return zipFile;
|
||||||
|
} catch (IoTException e) {
|
||||||
|
throw new DeviceManagementException(e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new DeviceManagementException("Zip File Creation Failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,80 +29,52 @@
|
|||||||
<APIVersion></APIVersion>
|
<APIVersion></APIVersion>
|
||||||
<!-- Device related APIs -->
|
<!-- Device related APIs -->
|
||||||
|
|
||||||
<Permission>
|
|
||||||
<name>Register Device</name>
|
|
||||||
<path>/device-mgt/user/device/register</path>
|
|
||||||
<url>/device/register/*/*/*</url>
|
|
||||||
<method>POST</method>
|
|
||||||
<scope>arduino_device</scope>
|
|
||||||
</Permission>
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>control bulb</name>
|
<name>control bulb</name>
|
||||||
<path>/device-mgt/user/device/bulb</path>
|
<path>device-mgt/user/operations</path>
|
||||||
<url>/device/*/bulb</url>
|
<url>/device/*/bulb</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>arduino_user</scope>
|
<scope>arduino_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
|
||||||
<name>get device temperature</name>
|
|
||||||
<path>/device-mgt/user/device/temperature</path>
|
|
||||||
<url>/device/*/temperature</url>
|
|
||||||
<method>GET</method>
|
|
||||||
<scope>arduino_user</scope>
|
|
||||||
</Permission>
|
|
||||||
<Permission>
|
|
||||||
<name>push data</name>
|
|
||||||
<path>/device-mgt/user/device/push-data</path>
|
|
||||||
<url>/device/sensor</url>
|
|
||||||
<method>POST</method>
|
|
||||||
<scope>arduino_device</scope>
|
|
||||||
</Permission>
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>get controls</name>
|
<name>get controls</name>
|
||||||
<path>/device-mgt/user/device/controls</path>
|
<path>device-mgt/user/operations</path>
|
||||||
<url>/device/*/controls</url>
|
<url>/device/*/controls</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>arduino_device</scope>
|
<scope>arduino_device</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
|
||||||
<name>push temperature</name>
|
|
||||||
<path>/device-mgt/user/device/temperature</path>
|
|
||||||
<url>/device/temperature</url>
|
|
||||||
<method>POST</method>
|
|
||||||
<scope>arduino_device</scope>
|
|
||||||
</Permission>
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>get temperature stats</name>
|
<name>get temperature stats</name>
|
||||||
<path>/device-mgt/user/device/</path>
|
<path>device-mgt/user/stats</path>
|
||||||
<url>/device/stats/*/sensors/temperature</url>
|
<url>/device/stats/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
<scope>arduino_device</scope>
|
<scope>arduino_device</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Get device</name>
|
<name>Get device</name>
|
||||||
<path>/device-mgt/user/devices/list</path>
|
<path>/device-mgt/user/devices/list</path>
|
||||||
<url>/devices/*</url>
|
<url>/enrollment/devices/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
<scope>arduino_user</scope>
|
<scope>arduino_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Remove device</name>
|
<name>Remove device</name>
|
||||||
<path>/device-mgt/user/devices/remove</path>
|
<path>/device-mgt/user/devices/remove</path>
|
||||||
<url>/devices/*</url>
|
<url>/enrollment/devices/*</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
<scope>arduino_user</scope>
|
<scope>arduino_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Download device</name>
|
<name>Download device</name>
|
||||||
<path>/device-mgt/user/devices/add</path>
|
<path>/device-mgt/user/devices</path>
|
||||||
<url>/devices/download</url>
|
<url>/enrollment/devices/download</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
<scope>arduino_user</scope>
|
<scope>arduino_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update device</name>
|
<name>Update device</name>
|
||||||
<path>/device-mgt/user/devices/update</path>
|
<path>/device-mgt/user/devices/update</path>
|
||||||
<url>/devices/*</url>
|
<url>/enrollment/devices/*</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
<scope>arduino_user</scope>
|
<scope>arduino_user</scope>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
|||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAO;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.feature.ArduinoFeatureManager;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.feature.ArduinoFeatureManager;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ArduinoManager implements DeviceManager {
|
public class ArduinoManager implements DeviceManager {
|
||||||
|
|
||||||
private static final ArduinoDAO arduinoDAO = new ArduinoDAO();
|
private static final ArduinoDAOUtil arduinoDAO = new ArduinoDAOUtil();
|
||||||
private static final Log log = LogFactory.getLog(ArduinoManager.class);
|
private static final Log log = LogFactory.getLog(ArduinoManager.class);
|
||||||
private ArduinoFeatureManager arduinoFeatureManager = new ArduinoFeatureManager();
|
private ArduinoFeatureManager arduinoFeatureManager = new ArduinoFeatureManager();
|
||||||
|
|
||||||
@ -70,12 +70,12 @@ public class ArduinoManager implements DeviceManager {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Enrolling a new Arduino device : " + device.getDeviceIdentifier());
|
log.debug("Enrolling a new Arduino device : " + device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
ArduinoDAO.beginTransaction();
|
ArduinoDAOUtil.beginTransaction();
|
||||||
status = arduinoDAO.getDeviceDAO().addDevice(device);
|
status = arduinoDAO.getDeviceDAO().addDevice(device);
|
||||||
ArduinoDAO.commitTransaction();
|
ArduinoDAOUtil.commitTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException e) {
|
} catch (ArduinoDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
ArduinoDAO.rollbackTransaction();
|
ArduinoDAOUtil.rollbackTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
@ -94,12 +94,12 @@ public class ArduinoManager implements DeviceManager {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Modifying the Arduino device enrollment data");
|
log.debug("Modifying the Arduino device enrollment data");
|
||||||
}
|
}
|
||||||
ArduinoDAO.beginTransaction();
|
ArduinoDAOUtil.beginTransaction();
|
||||||
status = arduinoDAO.getDeviceDAO().updateDevice(device);
|
status = arduinoDAO.getDeviceDAO().updateDevice(device);
|
||||||
ArduinoDAO.commitTransaction();
|
ArduinoDAOUtil.commitTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException e) {
|
} catch (ArduinoDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
ArduinoDAO.rollbackTransaction();
|
ArduinoDAOUtil.rollbackTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
@ -119,12 +119,12 @@ public class ArduinoManager implements DeviceManager {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Dis-enrolling Arduino device : " + deviceId);
|
log.debug("Dis-enrolling Arduino device : " + deviceId);
|
||||||
}
|
}
|
||||||
ArduinoDAO.beginTransaction();
|
ArduinoDAOUtil.beginTransaction();
|
||||||
status = arduinoDAO.getDeviceDAO().deleteDevice(deviceId.getId());
|
status = arduinoDAO.getDeviceDAO().deleteDevice(deviceId.getId());
|
||||||
ArduinoDAO.commitTransaction();
|
ArduinoDAOUtil.commitTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException e) {
|
} catch (ArduinoDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
ArduinoDAO.rollbackTransaction();
|
ArduinoDAOUtil.rollbackTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
|
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
@ -222,12 +222,12 @@ public class ArduinoManager implements DeviceManager {
|
|||||||
log.debug(
|
log.debug(
|
||||||
"updating the details of Arduino device : " + deviceIdentifier);
|
"updating the details of Arduino device : " + deviceIdentifier);
|
||||||
}
|
}
|
||||||
ArduinoDAO.beginTransaction();
|
ArduinoDAOUtil.beginTransaction();
|
||||||
status = arduinoDAO.getDeviceDAO().updateDevice(device);
|
status = arduinoDAO.getDeviceDAO().updateDevice(device);
|
||||||
ArduinoDAO.commitTransaction();
|
ArduinoDAOUtil.commitTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException e) {
|
} catch (ArduinoDeviceMgtPluginException e) {
|
||||||
try {
|
try {
|
||||||
ArduinoDAO.rollbackTransaction();
|
ArduinoDAOUtil.rollbackTransaction();
|
||||||
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
|
||||||
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
|
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
|
||||||
log.warn(msg, iotDAOEx);
|
log.warn(msg, iotDAOEx);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.impl.ArduinoDeviceDAOImpl;
|
|
||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
@ -30,13 +30,13 @@ import javax.sql.DataSource;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class ArduinoDAO {
|
public class ArduinoDAOUtil {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ArduinoDAO.class);
|
private static final Log log = LogFactory.getLog(ArduinoDAOUtil.class);
|
||||||
static DataSource dataSource;
|
static DataSource dataSource;
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
|
|
||||||
public ArduinoDAO() {
|
public ArduinoDAOUtil() {
|
||||||
initArduinoDAO();
|
initArduinoDAO();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +49,8 @@ public class ArduinoDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArduinoDeviceDAOImpl getDeviceDAO() {
|
public ArduinoDeviceDAO getDeviceDAO() {
|
||||||
return new ArduinoDeviceDAOImpl();
|
return new ArduinoDeviceDAO();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void beginTransaction() throws ArduinoDeviceMgtPluginException {
|
public static void beginTransaction() throws ArduinoDeviceMgtPluginException {
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.impl;
|
package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -24,7 +24,7 @@ import org.wso2.carbon.device.mgt.common.Device;
|
|||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util.ArduinoUtils;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util.ArduinoUtils;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAO;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -35,10 +35,10 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Implements CRUD for arduino Devices.
|
* Implements CRUD for arduino Devices.
|
||||||
*/
|
*/
|
||||||
public class ArduinoDeviceDAOImpl {
|
public class ArduinoDeviceDAO {
|
||||||
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ArduinoDeviceDAOImpl.class);
|
private static final Log log = LogFactory.getLog(ArduinoDeviceDAO.class);
|
||||||
|
|
||||||
public Device getDevice(String deviceId) throws ArduinoDeviceMgtPluginException {
|
public Device getDevice(String deviceId) throws ArduinoDeviceMgtPluginException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -46,7 +46,7 @@ public class ArduinoDeviceDAOImpl {
|
|||||||
Device device = null;
|
Device device = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
conn = ArduinoDAO.getConnection();
|
conn = ArduinoDAOUtil.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT ARDUINO_DEVICE_ID, DEVICE_NAME FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
|
"SELECT ARDUINO_DEVICE_ID, DEVICE_NAME FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
@ -67,7 +67,7 @@ public class ArduinoDeviceDAOImpl {
|
|||||||
throw new ArduinoDeviceMgtPluginException(msg, e);
|
throw new ArduinoDeviceMgtPluginException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
ArduinoUtils.cleanupResources(stmt, resultSet);
|
ArduinoUtils.cleanupResources(stmt, resultSet);
|
||||||
ArduinoDAO.closeConnection();
|
ArduinoDAOUtil.closeConnection();
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ public class ArduinoDeviceDAOImpl {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = ArduinoDAO.getConnection();
|
conn = ArduinoDAOUtil.getConnection();
|
||||||
String createDBQuery =
|
String createDBQuery =
|
||||||
"INSERT INTO ARDUINO_DEVICE(ARDUINO_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
|
"INSERT INTO ARDUINO_DEVICE(ARDUINO_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ public class ArduinoDeviceDAOImpl {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = ArduinoDAO.getConnection();
|
conn = ArduinoDAOUtil.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE ARDUINO_DEVICE SET DEVICE_NAME = ? WHERE ARDUINO_DEVICE_ID = ?";
|
"UPDATE ARDUINO_DEVICE SET DEVICE_NAME = ? WHERE ARDUINO_DEVICE_ID = ?";
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ public class ArduinoDeviceDAOImpl {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = ArduinoDAO.getConnection();
|
conn = ArduinoDAOUtil.getConnection();
|
||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
|
"DELETE FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
@ -170,7 +170,7 @@ public class ArduinoDeviceDAOImpl {
|
|||||||
Device device;
|
Device device;
|
||||||
List<Device> devices = new ArrayList<Device>();
|
List<Device> devices = new ArrayList<Device>();
|
||||||
try {
|
try {
|
||||||
conn = ArduinoDAO.getConnection();
|
conn = ArduinoDAOUtil.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT ARDUINO_DEVICE_ID, DEVICE_NAME FROM ARDUINO_DEVICE";
|
"SELECT ARDUINO_DEVICE_ID, DEVICE_NAME FROM ARDUINO_DEVICE";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
@ -190,7 +190,7 @@ public class ArduinoDeviceDAOImpl {
|
|||||||
throw new ArduinoDeviceMgtPluginException(msg, e);
|
throw new ArduinoDeviceMgtPluginException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
ArduinoUtils.cleanupResources(stmt, resultSet);
|
ArduinoUtils.cleanupResources(stmt, resultSet);
|
||||||
ArduinoDAO.closeConnection();
|
ArduinoDAOUtil.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
{{#zone "topCss"}}
|
||||||
|
{{css "css/graph.css"}}
|
||||||
|
{{/zone}}
|
||||||
|
<span id="details" data-devicename="{{device.name}}" data-deviceid="{{device.deviceIdentifier}}"
|
||||||
|
data-appcontext="{{@app.context}}"></span>
|
||||||
|
<div id="div-chart">
|
||||||
|
<div class="chartWrapper" id="chartWrapper">
|
||||||
|
<span id="span-title">Temperature</span>
|
||||||
|
<div id="y_axis" class="custom_y_axis"></div>
|
||||||
|
<div class="legend_container">
|
||||||
|
<div id="smoother" title="Smoothing"></div>
|
||||||
|
<div id="legend"></div>
|
||||||
|
</div>
|
||||||
|
<div id="chart" class="custom_rickshaw_graph" data-backend-api-url = {{backendApiUri}}></div>
|
||||||
|
<div id="x_axis" class="custom_x_axis"></div>
|
||||||
|
<div id="slider" class="custom_slider"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/d3.min.js"}}
|
||||||
|
{{js "js/rickshaw.min.js"}}
|
||||||
|
{{js "js/moment.min.js"}}
|
||||||
|
{{js "js/devicetype-graph.js"}}
|
||||||
|
{{/zone}}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
|
||||||
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||||
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
if (device && device.status != "error") {
|
||||||
|
return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/arduino/device/stats/" + deviceId};
|
||||||
|
} else {
|
||||||
|
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
@ -0,0 +1,470 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* graph */
|
||||||
|
|
||||||
|
.rickshaw_graph {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph svg {
|
||||||
|
display: block;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ticks */
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 0;
|
||||||
|
border-left: 1px dotted rgba(0, 0, 0, 0.2);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick .title {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
opacity: 0.5;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin-left: 3px;
|
||||||
|
bottom: -20px;
|
||||||
|
height: auto;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* annotations */
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline {
|
||||||
|
height: 1px;
|
||||||
|
border-top: 1px solid #e0e0e0;
|
||||||
|
margin-top: 10px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation {
|
||||||
|
position: absolute;
|
||||||
|
height: 6px;
|
||||||
|
width: 6px;
|
||||||
|
margin-left: -2px;
|
||||||
|
top: -3px;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_line {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: -6px;
|
||||||
|
width: 0;
|
||||||
|
border-left: 2px solid rgba(0, 0, 0, 0.3);
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_line.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range {
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: -6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range.active.offscreen {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content {
|
||||||
|
background: white;
|
||||||
|
color: black;
|
||||||
|
opacity: 0.9;
|
||||||
|
box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
|
||||||
|
border-radius: 3px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 20;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 6px 8px 8px;
|
||||||
|
top: 18px;
|
||||||
|
left: -11px;
|
||||||
|
width: 160px;
|
||||||
|
display: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content:before {
|
||||||
|
content: "\25b2";
|
||||||
|
position: absolute;
|
||||||
|
top: -11px;
|
||||||
|
color: white;
|
||||||
|
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation.active,
|
||||||
|
.rickshaw_annotation_timeline .annotation:hover {
|
||||||
|
background-color: rgba(0, 0, 0, 0.8);
|
||||||
|
cursor: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content:hover {
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation.active .content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation:hover .content {
|
||||||
|
display: block;
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_axis,
|
||||||
|
.rickshaw_graph .x_axis_d3 {
|
||||||
|
fill: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks .tick line,
|
||||||
|
.rickshaw_graph .x_ticks_d3 .tick {
|
||||||
|
stroke: rgba(0, 0, 0, 0.16);
|
||||||
|
stroke-width: 2px;
|
||||||
|
shape-rendering: crisp-edges;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid .tick,
|
||||||
|
.rickshaw_graph .x_grid_d3 .tick {
|
||||||
|
z-index: -1;
|
||||||
|
stroke: rgba(0, 0, 0, 0.20);
|
||||||
|
stroke-width: 1px;
|
||||||
|
stroke-dasharray: 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid .tick[data-y-value="0"] {
|
||||||
|
stroke-dasharray: 1 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid path,
|
||||||
|
.rickshaw_graph .x_grid_d3 path {
|
||||||
|
fill: none;
|
||||||
|
stroke: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks path,
|
||||||
|
.rickshaw_graph .x_ticks_d3 path {
|
||||||
|
fill: none;
|
||||||
|
stroke: #808080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks text,
|
||||||
|
.rickshaw_graph .x_ticks_d3 text {
|
||||||
|
opacity: 0.5;
|
||||||
|
font-size: 12px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick.glow .title,
|
||||||
|
.rickshaw_graph .y_ticks.glow text {
|
||||||
|
fill: black;
|
||||||
|
color: black;
|
||||||
|
text-shadow: -1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px -1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
0 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
0 -1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px 0 0 rgba(255, 255, 255, 0.1),
|
||||||
|
-1px 0 0 rgba(255, 255, 255, 0.1),
|
||||||
|
-1px -1px 0 rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick.inverse .title,
|
||||||
|
.rickshaw_graph .y_ticks.inverse text {
|
||||||
|
fill: white;
|
||||||
|
color: white;
|
||||||
|
text-shadow: -1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px -1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
0 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
0 -1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px 0 0 rgba(0, 0, 0, 0.8),
|
||||||
|
-1px 0 0 rgba(0, 0, 0, 0.8),
|
||||||
|
-1px -1px 0 rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_rickshaw_graph {
|
||||||
|
position: relative;
|
||||||
|
left: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_y_axis {
|
||||||
|
position: absolute;
|
||||||
|
width: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_slider {
|
||||||
|
left: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_x_axis {
|
||||||
|
position: relative;
|
||||||
|
left: 40px;
|
||||||
|
height: 30px;
|
||||||
|
width: 97%;
|
||||||
|
top: 20px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chartWrapper {
|
||||||
|
padding-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*detail*/
|
||||||
|
|
||||||
|
.rickshaw_graph .detail {
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
z-index: 2;
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
bottom: 0;
|
||||||
|
width: 1px;
|
||||||
|
transition: opacity 0.25s linear;
|
||||||
|
-moz-transition: opacity 0.25s linear;
|
||||||
|
-o-transition: opacity 0.25s linear;
|
||||||
|
-webkit-transition: opacity 0.25s linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail.inactive {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.active {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 6px;
|
||||||
|
opacity: 0.5;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
font-size: 12px;
|
||||||
|
position: absolute;
|
||||||
|
background: white;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label.left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label.right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0.25em;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
opacity: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.4);
|
||||||
|
color: white;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.4);
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
|
margin-top: -1em;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.active {
|
||||||
|
opacity: 1;
|
||||||
|
background: rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item:after {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
|
||||||
|
content: "";
|
||||||
|
|
||||||
|
border: 5px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.left:after {
|
||||||
|
top: 1em;
|
||||||
|
left: -5px;
|
||||||
|
margin-top: -5px;
|
||||||
|
border-right-color: rgba(0, 0, 0, 0.8);
|
||||||
|
border-left-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.right:after {
|
||||||
|
top: 1em;
|
||||||
|
right: -5px;
|
||||||
|
margin-top: -5px;
|
||||||
|
border-left-color: rgba(0, 0, 0, 0.8);
|
||||||
|
border-right-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .dot {
|
||||||
|
width: 4px;
|
||||||
|
height: 4px;
|
||||||
|
margin-left: -3px;
|
||||||
|
margin-top: -3.5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
position: absolute;
|
||||||
|
box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
|
||||||
|
box-sizing: content-box;
|
||||||
|
-moz-box-sizing: content-box;
|
||||||
|
background: white;
|
||||||
|
border-width: 2px;
|
||||||
|
border-style: solid;
|
||||||
|
display: none;
|
||||||
|
background-clip: padding-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .dot.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*legend*/
|
||||||
|
.rickshaw_legend {
|
||||||
|
font-family: Arial;
|
||||||
|
font-size: 12px;
|
||||||
|
color: white;
|
||||||
|
background: #404040;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 12px 5px;
|
||||||
|
border-radius: 2px;
|
||||||
|
position: relative;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend:hover {
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .swatch {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line {
|
||||||
|
clear: both;
|
||||||
|
line-height: 140%;
|
||||||
|
padding-right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line .swatch {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .label {
|
||||||
|
margin: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
display: inline;
|
||||||
|
font-size: inherit;
|
||||||
|
background-color: transparent;
|
||||||
|
color: inherit;
|
||||||
|
font-weight: normal;
|
||||||
|
line-height: normal;
|
||||||
|
padding: 0;
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .action:hover {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .action {
|
||||||
|
margin-right: 0.2em;
|
||||||
|
opacity: 0.2;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line.disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li {
|
||||||
|
padding: 0 0 0 2px;
|
||||||
|
min-width: 80px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li:active {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend {
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend_container {
|
||||||
|
float: right;
|
||||||
|
padding-right: 10px;
|
||||||
|
width: 0;
|
||||||
|
z-index: 1;
|
||||||
|
position: relative;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spaced {
|
||||||
|
margin-top: 20px !important;
|
||||||
|
}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
|
||||||
|
|
||||||
|
function drawGraph(from, to) {
|
||||||
|
var backendApiUrl = $("#chart").data("backend-api-url") + "?from=" + from + "&to=" + to;
|
||||||
|
|
||||||
|
var successCallback = function (data) {
|
||||||
|
if (data) {
|
||||||
|
drawLineGraph(JSON.parse(data));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
invokerUtil.get(backendApiUrl, successCallback, function (message) {
|
||||||
|
console.log(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawLineGraph(data) {
|
||||||
|
var chartWrapperElmId = "#div-chart";
|
||||||
|
var graphWidth = $(chartWrapperElmId).width() - 50;
|
||||||
|
if (data.length == 0 || data.length == undefined) {
|
||||||
|
$("#chart").html("<br/>No data available...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$("#chart").empty();
|
||||||
|
var graphConfig = {
|
||||||
|
element: document.getElementById("chart"),
|
||||||
|
width: graphWidth,
|
||||||
|
height: 400,
|
||||||
|
strokeWidth: 2,
|
||||||
|
renderer: 'line',
|
||||||
|
interpolation: "linear",
|
||||||
|
unstack: true,
|
||||||
|
stack: false,
|
||||||
|
xScale: d3.time.scale(),
|
||||||
|
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0.2},
|
||||||
|
series: []
|
||||||
|
};
|
||||||
|
|
||||||
|
var tzOffset = new Date().getTimezoneOffset() * 60;
|
||||||
|
|
||||||
|
var min = Number.MAX_VALUE;
|
||||||
|
var max = Number.MIN_VALUE;
|
||||||
|
var range_min = 99999, range_max = 0;
|
||||||
|
var max_val = parseInt(data[0].values.temperature);
|
||||||
|
var min_val = max_val;
|
||||||
|
var chartData = [];
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
var y_val = parseInt(data[i].values.temperature);
|
||||||
|
if (y_val > max_val) {
|
||||||
|
max_val = y_val;
|
||||||
|
} else if (y_val < min_val) {
|
||||||
|
min_val = y_val;
|
||||||
|
}
|
||||||
|
chartData.push(
|
||||||
|
{
|
||||||
|
x: parseInt(data[i].values.time) - tzOffset,
|
||||||
|
y: y_val
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (range_max < max_val) {
|
||||||
|
range_max = max_val;
|
||||||
|
}
|
||||||
|
if (range_min > min_val) {
|
||||||
|
range_min = min_val;
|
||||||
|
}
|
||||||
|
graphConfig['series'].push(
|
||||||
|
{
|
||||||
|
'color': palette.color(),
|
||||||
|
'data': chartData,
|
||||||
|
'name': $("#details").data("devicename"),
|
||||||
|
'scale': d3.scale.linear().domain([Math.min(min, min_val), Math.max(max, max_val)])
|
||||||
|
.nice()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (graphConfig['series'].length == 0) {
|
||||||
|
$(chartWrapperElmId).html("No data available...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var graph = new Rickshaw.Graph(graphConfig);
|
||||||
|
|
||||||
|
graph.render();
|
||||||
|
|
||||||
|
var xAxis = new Rickshaw.Graph.Axis.Time({
|
||||||
|
graph: graph
|
||||||
|
});
|
||||||
|
|
||||||
|
xAxis.render();
|
||||||
|
|
||||||
|
var yAxis = new Rickshaw.Graph.Axis.Y.Scaled({
|
||||||
|
graph: graph,
|
||||||
|
orientation: 'left',
|
||||||
|
element: document.getElementById("y_axis"),
|
||||||
|
width: 40,
|
||||||
|
height: 410,
|
||||||
|
'scale': d3.scale.linear().domain([Math.min(min, range_min), Math.max(max, range_max)]).nice()
|
||||||
|
});
|
||||||
|
|
||||||
|
yAxis.render();
|
||||||
|
|
||||||
|
var slider = new Rickshaw.Graph.RangeSlider.Preview({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById("slider")
|
||||||
|
});
|
||||||
|
|
||||||
|
var legend = new Rickshaw.Graph.Legend({
|
||||||
|
graph: graph,
|
||||||
|
element: document.getElementById('legend')
|
||||||
|
});
|
||||||
|
|
||||||
|
var hoverDetail = new Rickshaw.Graph.HoverDetail({
|
||||||
|
graph: graph,
|
||||||
|
formatter: function (series, x, y) {
|
||||||
|
var date = '<span class="date">' +
|
||||||
|
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
||||||
|
var swatch = '<span class="detail_swatch" style="background-color: ' +
|
||||||
|
series.color + '"></span>';
|
||||||
|
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
|
||||||
|
var order = new Rickshaw.Graph.Behavior.Series.Order({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
|
||||||
|
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
|
||||||
|
graph: graph,
|
||||||
|
legend: legend
|
||||||
|
});
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -15,7 +15,7 @@
|
|||||||
Operations
|
Operations
|
||||||
</div>
|
</div>
|
||||||
<div class="add-margin-top-4x">
|
<div class="add-margin-top-4x">
|
||||||
{{unit "iot.unit.device.operation-bar" device=device}}
|
{{unit "iot.unit.device.operation-bar" device=device backendApiUri=backendApiUri autoCompleteParams=autoCompleteParams}}
|
||||||
</div>
|
</div>
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@
|
|||||||
<div class="panel panel-default tab-pane active"
|
<div class="panel panel-default tab-pane active"
|
||||||
id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
|
id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
|
||||||
<div class="panel-heading">Device Statistics</div>
|
<div class="panel-heading">Device Statistics</div>
|
||||||
{{unit "iot.unit.device.stats" device=device}}
|
{{unit "cdmf.unit.device.type.arduino.realtime.analytics-view" device=device}}
|
||||||
</div>
|
</div>
|
||||||
<div class="panel panel-default tab-pane" id="event_log" role="tabpanel"
|
<div class="panel panel-default tab-pane" id="event_log" role="tabpanel"
|
||||||
aria-labelledby="event_log">
|
aria-labelledby="event_log">
|
||||||
|
|||||||
@ -20,22 +20,15 @@ function onRequest(context) {
|
|||||||
var log = new Log("device-view.js");
|
var log = new Log("device-view.js");
|
||||||
var deviceType = context.uriParams.deviceType;
|
var deviceType = context.uriParams.deviceType;
|
||||||
var deviceId = request.getParameter("id");
|
var deviceId = request.getParameter("id");
|
||||||
|
var autoCompleteParams = [
|
||||||
|
{"name" : "deviceId", "value" : deviceId}
|
||||||
|
];
|
||||||
|
|
||||||
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||||
var deviceModule = require("/app/modules/device.js").deviceModule;
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
var device = deviceModule.viewDevice(deviceType, deviceId);
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
|
||||||
if (device && device.status != "error") {
|
if (device && device.status != "error") {
|
||||||
var viewModel = {};
|
return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/arduino/", "autoCompleteParams" : autoCompleteParams};
|
||||||
var deviceInfo = device.properties.DEVICE_INFO;
|
|
||||||
if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) {
|
|
||||||
deviceInfo = parse(stringify(deviceInfo));
|
|
||||||
viewModel.system = device.properties.IMEI;
|
|
||||||
viewModel.machine = "Arduino";
|
|
||||||
viewModel.vendor = device.properties.VENDOR;
|
|
||||||
}
|
|
||||||
device.viewModel = viewModel;
|
|
||||||
return {"device": device};
|
|
||||||
} else {
|
} else {
|
||||||
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
||||||
exit();
|
exit();
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
@ -0,0 +1,471 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* graph */
|
||||||
|
|
||||||
|
.rickshaw_graph {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph svg {
|
||||||
|
display: block;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ticks */
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 0;
|
||||||
|
border-left: 1px dotted rgba(0, 0, 0, 0.2);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick .title {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
opacity: 0.5;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin-left: 3px;
|
||||||
|
bottom: -20px;
|
||||||
|
height: auto;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* annotations */
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline {
|
||||||
|
height: 1px;
|
||||||
|
border-top: 1px solid #e0e0e0;
|
||||||
|
margin-top: 10px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation {
|
||||||
|
position: absolute;
|
||||||
|
height: 6px;
|
||||||
|
width: 6px;
|
||||||
|
margin-left: -2px;
|
||||||
|
top: -3px;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_line {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: -6px;
|
||||||
|
width: 0;
|
||||||
|
border-left: 2px solid rgba(0, 0, 0, 0.3);
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_line.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range {
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: -6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .annotation_range.active.offscreen {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content {
|
||||||
|
background: white;
|
||||||
|
color: black;
|
||||||
|
opacity: 0.9;
|
||||||
|
box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
|
||||||
|
border-radius: 3px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 20;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 6px 8px 8px;
|
||||||
|
top: 18px;
|
||||||
|
left: -11px;
|
||||||
|
width: 160px;
|
||||||
|
display: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content:before {
|
||||||
|
content: "\25b2";
|
||||||
|
position: absolute;
|
||||||
|
top: -11px;
|
||||||
|
color: white;
|
||||||
|
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation.active,
|
||||||
|
.rickshaw_annotation_timeline .annotation:hover {
|
||||||
|
background-color: rgba(0, 0, 0, 0.8);
|
||||||
|
cursor: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation .content:hover {
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation.active .content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_annotation_timeline .annotation:hover .content {
|
||||||
|
display: block;
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_axis,
|
||||||
|
.rickshaw_graph .x_axis_d3 {
|
||||||
|
fill: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks .tick line,
|
||||||
|
.rickshaw_graph .x_ticks_d3 .tick {
|
||||||
|
stroke: rgba(0, 0, 0, 0.16);
|
||||||
|
stroke-width: 2px;
|
||||||
|
shape-rendering: crisp-edges;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid .tick,
|
||||||
|
.rickshaw_graph .x_grid_d3 .tick {
|
||||||
|
z-index: -1;
|
||||||
|
stroke: rgba(0, 0, 0, 0.20);
|
||||||
|
stroke-width: 1px;
|
||||||
|
stroke-dasharray: 1 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid .tick[data-y-value="0"] {
|
||||||
|
stroke-dasharray: 1 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_grid path,
|
||||||
|
.rickshaw_graph .x_grid_d3 path {
|
||||||
|
fill: none;
|
||||||
|
stroke: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks path,
|
||||||
|
.rickshaw_graph .x_ticks_d3 path {
|
||||||
|
fill: none;
|
||||||
|
stroke: #808080;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .y_ticks text,
|
||||||
|
.rickshaw_graph .x_ticks_d3 text {
|
||||||
|
opacity: 0.5;
|
||||||
|
font-size: 12px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick.glow .title,
|
||||||
|
.rickshaw_graph .y_ticks.glow text {
|
||||||
|
fill: black;
|
||||||
|
color: black;
|
||||||
|
text-shadow: -1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px -1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
0 1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
0 -1px 0 rgba(255, 255, 255, 0.1),
|
||||||
|
1px 0 0 rgba(255, 255, 255, 0.1),
|
||||||
|
-1px 0 0 rgba(255, 255, 255, 0.1),
|
||||||
|
-1px -1px 0 rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .x_tick.inverse .title,
|
||||||
|
.rickshaw_graph .y_ticks.inverse text {
|
||||||
|
fill: white;
|
||||||
|
color: white;
|
||||||
|
text-shadow: -1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px -1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
0 1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
0 -1px 0 rgba(0, 0, 0, 0.8),
|
||||||
|
1px 0 0 rgba(0, 0, 0, 0.8),
|
||||||
|
-1px 0 0 rgba(0, 0, 0, 0.8),
|
||||||
|
-1px -1px 0 rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_rickshaw_graph {
|
||||||
|
position: relative;
|
||||||
|
left: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_y_axis {
|
||||||
|
position: absolute;
|
||||||
|
width: 40px;
|
||||||
|
margin-top: -20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_slider {
|
||||||
|
left: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom_x_axis {
|
||||||
|
position: relative;
|
||||||
|
left: 40px;
|
||||||
|
height: 30px;
|
||||||
|
width: 97%;
|
||||||
|
top: 20px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chartWrapper {
|
||||||
|
padding-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*detail*/
|
||||||
|
|
||||||
|
.rickshaw_graph .detail {
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
z-index: 2;
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
bottom: 0;
|
||||||
|
width: 1px;
|
||||||
|
transition: opacity 0.25s linear;
|
||||||
|
-moz-transition: opacity 0.25s linear;
|
||||||
|
-o-transition: opacity 0.25s linear;
|
||||||
|
-webkit-transition: opacity 0.25s linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail.inactive {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.active {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 6px;
|
||||||
|
opacity: 0.5;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
font-size: 12px;
|
||||||
|
position: absolute;
|
||||||
|
background: white;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label.left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .x_label.right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0.25em;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
opacity: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.4);
|
||||||
|
color: white;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.4);
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
|
margin-top: -1em;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.active {
|
||||||
|
opacity: 1;
|
||||||
|
background: rgba(0, 0, 0, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item:after {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
|
||||||
|
content: "";
|
||||||
|
|
||||||
|
border: 5px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.left:after {
|
||||||
|
top: 1em;
|
||||||
|
left: -5px;
|
||||||
|
margin-top: -5px;
|
||||||
|
border-right-color: rgba(0, 0, 0, 0.8);
|
||||||
|
border-left-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .item.right:after {
|
||||||
|
top: 1em;
|
||||||
|
right: -5px;
|
||||||
|
margin-top: -5px;
|
||||||
|
border-left-color: rgba(0, 0, 0, 0.8);
|
||||||
|
border-right-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .dot {
|
||||||
|
width: 4px;
|
||||||
|
height: 4px;
|
||||||
|
margin-left: -3px;
|
||||||
|
margin-top: -3.5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
position: absolute;
|
||||||
|
box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
|
||||||
|
box-sizing: content-box;
|
||||||
|
-moz-box-sizing: content-box;
|
||||||
|
background: white;
|
||||||
|
border-width: 2px;
|
||||||
|
border-style: solid;
|
||||||
|
display: none;
|
||||||
|
background-clip: padding-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_graph .detail .dot.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*legend*/
|
||||||
|
.rickshaw_legend {
|
||||||
|
font-family: Arial;
|
||||||
|
font-size: 12px;
|
||||||
|
color: white;
|
||||||
|
background: #404040;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 12px 5px;
|
||||||
|
border-radius: 2px;
|
||||||
|
position: relative;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend:hover {
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .swatch {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line {
|
||||||
|
clear: both;
|
||||||
|
line-height: 140%;
|
||||||
|
padding-right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line .swatch {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .label {
|
||||||
|
margin: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
display: inline;
|
||||||
|
font-size: inherit;
|
||||||
|
background-color: transparent;
|
||||||
|
color: inherit;
|
||||||
|
font-weight: normal;
|
||||||
|
line-height: normal;
|
||||||
|
padding: 0;
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .action:hover {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .action {
|
||||||
|
margin-right: 0.2em;
|
||||||
|
opacity: 0.2;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend .line.disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li {
|
||||||
|
padding: 0 0 0 2px;
|
||||||
|
min-width: 80px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rickshaw_legend li:active {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend {
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend_container {
|
||||||
|
float: right;
|
||||||
|
padding-right: 10px;
|
||||||
|
width: 0;
|
||||||
|
z-index: 1;
|
||||||
|
position: relative;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spaced {
|
||||||
|
margin-top: 20px !important;
|
||||||
|
}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceAccelerometerData USING CarbonAnalytics OPTIONS(tab
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceAccelerometerSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_ACCELEROMETER_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceAccelerometerSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_ACCELEROMETER_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceAccelerometerSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceAccelerometerData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceAccelerometerSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceAccelerometerData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceBatteryData USING CarbonAnalytics OPTIONS(tableName
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceBatterySummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_BATTERY_SUMMARY", schema "level INT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceBatterySummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_BATTERY_SUMMARY", schema "level INT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceBatterySummaryData select level, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceBatteryData group by level, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceBatterySummaryData select level, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceBatteryData group by level, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceGPSData USING CarbonAnalytics OPTIONS(tableName "OR
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceGPSSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GPS_SUMMARY", schema "latitude DOUBLE,longitude DOUBLE, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceGPSSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GPS_SUMMARY", schema "latitude DOUBLE,longitude DOUBLE, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceGPSSummaryData select latitude, longitude, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGPSData group by latitude, longitude, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceGPSSummaryData select latitude, longitude, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGPSData group by latitude, longitude, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceGRAVITYData USING CarbonAnalytics OPTIONS(tableName
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceGRAVITYSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GRAVITY_SUMMARY", schema "x FLOAT, y FLOAT,z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceGRAVITYSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GRAVITY_SUMMARY", schema "x FLOAT, y FLOAT,z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceGRAVITYSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGRAVITYData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceGRAVITYSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGRAVITYData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceGYROSCOPEData USING CarbonAnalytics OPTIONS(tableNa
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceGYROSCOPESummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GYROSCOPE_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceGYROSCOPESummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GYROSCOPE_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceGYROSCOPESummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGYROSCOPEData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceGYROSCOPESummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGYROSCOPEData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceLightData USING CarbonAnalytics OPTIONS(tableName "
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceLightSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_LIGHT_SUMMARY", schema "light FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceLightSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_LIGHT_SUMMARY", schema "light FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceLightSummaryData select light, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceLightData group by light, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceLightSummaryData select light, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceLightData group by light, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceMagneticData USING CarbonAnalytics OPTIONS(tableNam
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceMagneticSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_MAGNETIC_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceMagneticSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_MAGNETIC_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceMagneticSummaryData select x, y , z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceMagneticData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceMagneticSummaryData select x, y , z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceMagneticData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DevicePRESSUREData USING CarbonAnalytics OPTIONS(tableNam
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DevicePRESSURESummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_PRESSURE_SUMMARY", schema "pressure FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DevicePRESSURESummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_PRESSURE_SUMMARY", schema "pressure FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DevicePRESSURESummaryData select pressure, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DevicePRESSUREData group by pressure, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DevicePRESSURESummaryData select pressure, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DevicePRESSUREData group by pressure, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,8 +24,7 @@ CREATE TEMPORARY TABLE DevicePROXIMITYData USING CarbonAnalytics OPTIONS(tableNa
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DevicePROXIMITYSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_PROXIMITY_SUMMARY", schema "proximity FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DevicePROXIMITYSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_PROXIMITY_SUMMARY", schema "proximity FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
|
insert into table DevicePROXIMITYSummaryData select proximity, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DevicePROXIMITYData group by proximity, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
insert overwrite table DevicePROXIMITYSummaryData select proximity, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DevicePROXIMITYData group by proximity, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ CREATE TEMPORARY TABLE DeviceROTATIONData USING CarbonAnalytics OPTIONS(tableNam
|
|||||||
|
|
||||||
CREATE TEMPORARY TABLE DeviceROTATIONSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_ROTATION_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
CREATE TEMPORARY TABLE DeviceROTATIONSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_ROTATION_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
|
||||||
|
|
||||||
insert overwrite table DeviceROTATIONSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceROTATIONData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
insert into table DeviceROTATIONSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceROTATIONData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
</Analytics>
|
</Analytics>
|
||||||
|
|||||||
@ -27,7 +27,7 @@ CREATE TEMPORARY TABLE WordcountSummaryData USING CarbonAnalytics OPTIONS (table
|
|||||||
primaryKeys "deviceType, deviceId, sessionId, owner");
|
primaryKeys "deviceType, deviceId, sessionId, owner");
|
||||||
|
|
||||||
|
|
||||||
insert overwrite table WordcountSummaryData select sessionId, word, count(*) as occurence, meta_deviceType as deviceType,
|
insert into table WordcountSummaryData select sessionId, word, count(*) as occurence, meta_deviceType as deviceType,
|
||||||
meta_deviceId as deviceId, meta_owner as owner from WordCountData group by sessionId, word, meta_deviceType, meta_deviceId, meta_owner;
|
meta_deviceId as deviceId, meta_owner as owner from WordCountData group by sessionId, word, meta_deviceType, meta_deviceId, meta_owner;
|
||||||
</Script>
|
</Script>
|
||||||
<CronExpression>0 * * * * ?</CronExpression>
|
<CronExpression>0 * * * * ?</CronExpression>
|
||||||
|
|||||||
@ -82,7 +82,7 @@ function submitForm(formId) {
|
|||||||
} else if (httpMethod == "PUT") {
|
} else if (httpMethod == "PUT") {
|
||||||
invokerUtil.put(uri, payload, successCallBack, errorCallBack, contentType);
|
invokerUtil.put(uri, payload, successCallBack, errorCallBack, contentType);
|
||||||
} else if (httpMethod == "DELETE") {
|
} else if (httpMethod == "DELETE") {
|
||||||
invokerUtil.get(uri, successCallBack, errorCallBack, contentType);
|
invokerUtil.delete(uri, successCallBack, errorCallBack, contentType);
|
||||||
} else {
|
} else {
|
||||||
title.html("An Error Occurred!");
|
title.html("An Error Occurred!");
|
||||||
statusIcon.attr("class", defaultStatusClasses + " fw-error");
|
statusIcon.attr("class", defaultStatusClasses + " fw-error");
|
||||||
|
|||||||
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.sensormgt;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
public class DeviceRecord implements Serializable {
|
|
||||||
private Map<String, SensorRecord> sensorDataList = new HashMap<>();
|
|
||||||
|
|
||||||
public DeviceRecord(String sensorName, String sensorValue, long time) {
|
|
||||||
sensorDataList.put(sensorName, new SensorRecord(sensorValue, time));
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public Map<String, SensorRecord> getSensorDataList() {
|
|
||||||
return sensorDataList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDeviceRecord(String sensorName, String sensorValue, long time) {
|
|
||||||
sensorDataList.put(sensorName, new SensorRecord(sensorValue, time));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,137 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.sensormgt;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to store latest sensor value readings against a device id in an in-memory map.
|
|
||||||
*/
|
|
||||||
public class SensorDataManager {
|
|
||||||
|
|
||||||
private static final SensorDataManager instance = new SensorDataManager();
|
|
||||||
private Map<String, DeviceRecord> deviceMap = new HashMap<>();
|
|
||||||
|
|
||||||
private SensorDataManager() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SensorDataManager getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store sensor record in a map.
|
|
||||||
*
|
|
||||||
* @param deviceId
|
|
||||||
* @param sensorName
|
|
||||||
* @param sensorValue
|
|
||||||
* @param time
|
|
||||||
* @return if success returns true
|
|
||||||
*/
|
|
||||||
public boolean setSensorRecord(String deviceId, String sensorName, String sensorValue, long time) {
|
|
||||||
DeviceRecord deviceRecord = deviceMap.get(deviceId);
|
|
||||||
if (deviceRecord == null) {
|
|
||||||
deviceRecord = new DeviceRecord(sensorName, sensorValue, time);
|
|
||||||
} else {
|
|
||||||
deviceRecord.addDeviceRecord(sensorName, sensorValue, time);
|
|
||||||
}
|
|
||||||
deviceMap.put(deviceId, deviceRecord);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns last updated sensor records list for a device
|
|
||||||
*
|
|
||||||
* @param deviceId
|
|
||||||
* @return list of sensor records
|
|
||||||
*/
|
|
||||||
public SensorRecord[] getSensorRecords(String deviceId) throws DeviceControllerException {
|
|
||||||
DeviceRecord deviceRecord = deviceMap.get(deviceId);
|
|
||||||
if (deviceRecord != null) {
|
|
||||||
Collection<SensorRecord> list = deviceRecord.getSensorDataList().values();
|
|
||||||
return list.toArray(new SensorRecord[list.size()]);
|
|
||||||
}
|
|
||||||
throw new DeviceControllerException("Error: No records found for the device ID: " + deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns last updated sensor record for a device's sensor
|
|
||||||
*
|
|
||||||
* @param deviceId
|
|
||||||
* @param sensorName
|
|
||||||
* @return sensor record
|
|
||||||
*/
|
|
||||||
public SensorRecord getSensorRecord(String deviceId, String sensorName) throws
|
|
||||||
DeviceControllerException {
|
|
||||||
DeviceRecord deviceRecord = deviceMap.get(deviceId);
|
|
||||||
if (deviceRecord != null) {
|
|
||||||
SensorRecord sensorRecord = deviceRecord.getSensorDataList().get(sensorName);
|
|
||||||
if (sensorRecord != null) {
|
|
||||||
return sensorRecord;
|
|
||||||
}
|
|
||||||
throw new DeviceControllerException("Error: No records found for the Device ID: " + deviceId +
|
|
||||||
" Sensor Name: " + sensorName);
|
|
||||||
}
|
|
||||||
throw new DeviceControllerException("Error: No records found for the device ID: " + deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns last updated sensor value for a device's sensor
|
|
||||||
*
|
|
||||||
* @param deviceId
|
|
||||||
* @param sensorName
|
|
||||||
* @return sensor reading
|
|
||||||
*/
|
|
||||||
public String getSensorRecordValue(String deviceId, String sensorName) throws DeviceControllerException {
|
|
||||||
DeviceRecord deviceRecord = deviceMap.get(deviceId);
|
|
||||||
if (deviceRecord != null) {
|
|
||||||
SensorRecord sensorRecord = deviceRecord.getSensorDataList().get(sensorName);
|
|
||||||
if (sensorRecord != null) {
|
|
||||||
return sensorRecord.getSensorValue();
|
|
||||||
}
|
|
||||||
throw new DeviceControllerException("Error: No records found for the Device ID: " + deviceId +
|
|
||||||
" Sensor Name: " + sensorName);
|
|
||||||
}
|
|
||||||
throw new DeviceControllerException("Error: No records found for the device ID: " + deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns last updated sensor value reading time for a device's sensor
|
|
||||||
*
|
|
||||||
* @param deviceId
|
|
||||||
* @param sensorName
|
|
||||||
* @return time in millis
|
|
||||||
*/
|
|
||||||
public long getSensorRecordTime(String deviceId, String sensorName) throws DeviceControllerException {
|
|
||||||
DeviceRecord deviceRecord = deviceMap.get(deviceId);
|
|
||||||
if (deviceRecord != null) {
|
|
||||||
SensorRecord sensorRecord = deviceRecord.getSensorDataList().get(sensorName);
|
|
||||||
if (sensorRecord != null) {
|
|
||||||
return sensorRecord.getTime();
|
|
||||||
}
|
|
||||||
throw new DeviceControllerException("Error: No records found for the Device ID: " + deviceId +
|
|
||||||
" Sensor Name: " + sensorName);
|
|
||||||
}
|
|
||||||
throw new DeviceControllerException("Error: No records found for the device ID: " + deviceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.sensormgt;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
public class SensorRecord implements Serializable {
|
|
||||||
//sensor value float, int, boolean all should be converted into string
|
|
||||||
private String sensorValue;
|
|
||||||
private long time;
|
|
||||||
|
|
||||||
public SensorRecord(String sensorValue, long time) {
|
|
||||||
this.sensorValue = sensorValue;
|
|
||||||
this.time = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public String getSensorValue() {
|
|
||||||
return sensorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement
|
|
||||||
public long getTime() {
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.util;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.exception.IoTException;
|
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ZipUtil {
|
|
||||||
|
|
||||||
private static final String HTTPS_PORT_PROPERTY = "httpsPort";
|
|
||||||
private static final String HTTP_PORT_PROPERTY = "httpPort";
|
|
||||||
|
|
||||||
private static final String LOCALHOST = "localhost";
|
|
||||||
private static final String HTTPS_PROTOCOL_APPENDER = "https://";
|
|
||||||
private static final String HTTP_PROTOCOL_APPENDER = "http://";
|
|
||||||
|
|
||||||
public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType,
|
|
||||||
String deviceId, String deviceName, String token,
|
|
||||||
String refreshToken)
|
|
||||||
throws DeviceManagementException {
|
|
||||||
|
|
||||||
String sep = File.separator;
|
|
||||||
String sketchFolder = "repository" + sep + "resources" + sep + "sketches";
|
|
||||||
String archivesPath = CarbonUtils.getCarbonHome() + sep + sketchFolder + sep + "archives" + sep + deviceId;
|
|
||||||
String templateSketchPath = sketchFolder + sep + deviceType;
|
|
||||||
String iotServerIP;
|
|
||||||
|
|
||||||
try {
|
|
||||||
iotServerIP = IoTUtil.getHostName();
|
|
||||||
} catch (IoTException e) {
|
|
||||||
throw new DeviceManagementException(e.getMessage());
|
|
||||||
}
|
|
||||||
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
|
|
||||||
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
|
|
||||||
|
|
||||||
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
|
|
||||||
String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort;
|
|
||||||
String apimEndpoint = httpsServerEP;
|
|
||||||
String mqttEndpoint = MqttConfig.getInstance().getMqttQueueEndpoint();
|
|
||||||
if (mqttEndpoint.contains(LOCALHOST)) {
|
|
||||||
mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP);
|
|
||||||
}
|
|
||||||
|
|
||||||
String xmppEndpoint = XmppConfig.getInstance().getXmppEndpoint();
|
|
||||||
|
|
||||||
int indexOfChar = xmppEndpoint.lastIndexOf(":");
|
|
||||||
if (indexOfChar != -1) {
|
|
||||||
xmppEndpoint = xmppEndpoint.substring(0, indexOfChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT();
|
|
||||||
|
|
||||||
Map<String, String> contextParams = new HashMap<>();
|
|
||||||
//TODO:refactor remove and move to device type impl
|
|
||||||
contextParams.put("SERVER_NAME", "wso2");
|
|
||||||
contextParams.put("DEVICE_OWNER", owner);
|
|
||||||
contextParams.put("DEVICE_ID", deviceId);
|
|
||||||
contextParams.put("DEVICE_NAME", deviceName);
|
|
||||||
contextParams.put("HTTPS_EP", httpsServerEP);
|
|
||||||
contextParams.put("HTTP_EP", httpServerEP);
|
|
||||||
contextParams.put("APIM_EP", apimEndpoint);
|
|
||||||
contextParams.put("MQTT_EP", mqttEndpoint);
|
|
||||||
contextParams.put("XMPP_EP", xmppEndpoint);
|
|
||||||
contextParams.put("DEVICE_TOKEN", token);
|
|
||||||
contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken);
|
|
||||||
|
|
||||||
ZipArchive zipFile;
|
|
||||||
try {
|
|
||||||
zipFile = IotDeviceManagementUtil.getSketchArchive(archivesPath, templateSketchPath, contextParams);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new DeviceManagementException("Zip File Creation Failed", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return zipFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -21,9 +21,6 @@ package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl;
|
|||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.DeviceData;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.FormParam;
|
import javax.ws.rs.FormParam;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
@ -32,38 +29,26 @@ import javax.ws.rs.Path;
|
|||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@API(name = "raspberrypi", version = "1.0.0", context = "/raspberrypi", tags = {"raspberrypi"})
|
@API(name = "raspberrypi", version = "1.0.0", context = "/raspberrypi", tags = {"raspberrypi"})
|
||||||
@DeviceType(value = "raspberrypi")
|
@DeviceType(value = "raspberrypi")
|
||||||
public interface RaspberryPiControllerService {
|
public interface RaspberryPiControllerService {
|
||||||
|
|
||||||
@Path("device/register/{deviceId}/{ip}/{port}")
|
|
||||||
@POST
|
|
||||||
Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
|
||||||
@PathParam("port") String devicePort, @Context HttpServletRequest request);
|
|
||||||
|
|
||||||
@Path("device/{deviceId}/bulb")
|
@Path("device/{deviceId}/bulb")
|
||||||
@POST
|
@POST
|
||||||
@Feature(code = "bulb", name = "Bulb On / Off", type = "operation",
|
@Feature(code = "bulb", name = "Bulb On / Off", type = "operation",
|
||||||
description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)")
|
description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)")
|
||||||
Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state);
|
Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state);
|
||||||
|
|
||||||
@Path("device/push_temperature")
|
|
||||||
@POST
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retreive Sensor data for the device type
|
* Retreive Sensor data for the device type
|
||||||
*/
|
*/
|
||||||
@Path("device/stats/{deviceId}/sensors/temperature")
|
@Path("device/stats/{deviceId}")
|
||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("username") String user,
|
Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
|
||||||
@QueryParam("from") long from, @QueryParam("to") long to);
|
@QueryParam("from") long from, @QueryParam("to") long to);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,30 +23,25 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.analytics.dataservice.commons.SORT;
|
import org.wso2.carbon.analytics.dataservice.commons.SORT;
|
||||||
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
|
||||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||||
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.DeviceData;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.FormParam;
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -56,88 +51,48 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
||||||
private RaspberryPiMQTTConnector raspberryPiMQTTConnector;
|
private RaspberryPiMQTTConnector raspberryPiMQTTConnector;
|
||||||
|
|
||||||
@Path("device/register/{deviceId}/{ip}/{port}")
|
|
||||||
@POST
|
|
||||||
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
|
||||||
@PathParam("port") String devicePort, @Context HttpServletRequest request) {
|
|
||||||
String result;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId);
|
|
||||||
}
|
|
||||||
String deviceHttpEndpoint = deviceIP + ":" + devicePort;
|
|
||||||
deviceToIpMap.put(deviceId, deviceHttpEndpoint);
|
|
||||||
result = "Device-IP Registered";
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug(result);
|
|
||||||
}
|
|
||||||
return Response.ok().entity(result).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("device/{deviceId}/bulb")
|
@Path("device/{deviceId}/bulb")
|
||||||
@POST
|
@POST
|
||||||
public Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state) {
|
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
|
||||||
|
try {
|
||||||
|
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
|
||||||
|
RaspberrypiConstants.DEVICE_TYPE))) {
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||||
|
}
|
||||||
String switchToState = state.toUpperCase();
|
String switchToState = state.toUpperCase();
|
||||||
if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals(
|
if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals(
|
||||||
RaspberrypiConstants.STATE_OFF)) {
|
RaspberrypiConstants.STATE_OFF)) {
|
||||||
log.error("The requested state change shoud be either - 'ON' or 'OFF'");
|
log.error("The requested state change shoud be either - 'ON' or 'OFF'");
|
||||||
return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
|
return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
|
||||||
}
|
}
|
||||||
String callUrlPattern = RaspberrypiConstants.BULB_CONTEXT + switchToState;
|
String mqttResource = RaspberrypiConstants.BULB_CONTEXT.replace("/", "");
|
||||||
try {
|
raspberryPiMQTTConnector.publishDeviceData(deviceId, mqttResource, switchToState);
|
||||||
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
|
||||||
if (deviceHTTPEndpoint == null) {
|
|
||||||
return Response.status(Response.Status.PRECONDITION_FAILED.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via ");
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
|
} catch (TransportHandlerException e) {
|
||||||
|
log.error("Failed to send switch-bulb request to device [" + deviceId + "]");
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("device/push_temperature")
|
@Path("device/stats/{deviceId}")
|
||||||
@POST
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
public Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request) {
|
|
||||||
String owner = dataMsg.owner;
|
|
||||||
String deviceId = dataMsg.deviceId;
|
|
||||||
String deviceIp = dataMsg.reply;
|
|
||||||
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);
|
|
||||||
return Response.status(Response.Status.PRECONDITION_FAILED.getStatusCode()).build();
|
|
||||||
} 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");
|
|
||||||
return Response.status(Response.Status.CONFLICT.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Received Pin Data Value: " + temperature + " degrees C");
|
|
||||||
}
|
|
||||||
if (!RaspberrypiServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
|
||||||
log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" +
|
|
||||||
deviceId + "] of owner [" + owner + "]");
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
|
|
||||||
}
|
|
||||||
return Response.ok().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("device/stats/{deviceId}/sensors/temperature")
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
public Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
|
public Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
|
||||||
@QueryParam("username") String user,
|
|
||||||
@QueryParam("from") long from, @QueryParam("to") long to) {
|
@QueryParam("from") long from, @QueryParam("to") long to) {
|
||||||
String fromDate = String.valueOf(from);
|
String fromDate = String.valueOf(from);
|
||||||
String toDate = String.valueOf(to);
|
String toDate = String.valueOf(to);
|
||||||
String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" +
|
String query = "deviceId:" + deviceId + " AND deviceType:" +
|
||||||
RaspberrypiConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
|
RaspberrypiConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
|
||||||
String sensorTableName = RaspberrypiConstants.TEMPERATURE_EVENT_TABLE;
|
String sensorTableName = RaspberrypiConstants.TEMPERATURE_EVENT_TABLE;
|
||||||
try {
|
try {
|
||||||
|
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
|
||||||
|
RaspberrypiConstants.DEVICE_TYPE))) {
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
||||||
|
}
|
||||||
List<SortByField> sortByFields = new ArrayList<>();
|
List<SortByField> sortByFields = new ArrayList<>();
|
||||||
SortByField sortByField = new SortByField("time", SORT.ASC, false);
|
SortByField sortByField = new SortByField("time", SORT.ASC, false);
|
||||||
sortByFields.add(sortByField);
|
sortByFields.add(sortByField);
|
||||||
@ -147,6 +102,9 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
|
|||||||
String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
|
String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
|
||||||
log.error(errorMsg);
|
log.error(errorMsg);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
|
||||||
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -58,15 +58,9 @@ public interface RaspberryPiManagerService {
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
Response getRaspberrypiDevices();
|
Response getRaspberrypiDevices();
|
||||||
|
|
||||||
@Path("devices/{sketch_type}/download")
|
@Path("devicesg/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
Response downloadSketch(@QueryParam("deviceName") String deviceName,
|
Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketch_type") String sketchType);
|
||||||
@PathParam("sketch_type") String sketchType);
|
|
||||||
|
|
||||||
@Path("devices/{sketch_type}/generate_link")
|
|
||||||
@GET
|
|
||||||
Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
|
||||||
@PathParam("sketch_type") String sketchType);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,8 +35,8 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
|
|||||||
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
|
||||||
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.ZipUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
||||||
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
|
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
@ -67,6 +67,7 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
|
|||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
|
|
||||||
|
@Override
|
||||||
@Path("devices/{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@DELETE
|
@DELETE
|
||||||
public Response removeDevice(@PathParam("device_id") String deviceId) {
|
public Response removeDevice(@PathParam("device_id") String deviceId) {
|
||||||
@ -86,6 +87,7 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Path("devices/{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@PUT
|
@PUT
|
||||||
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
|
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
|
||||||
@ -110,6 +112,7 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Path("devices/{device_id}")
|
@Path("devices/{device_id}")
|
||||||
@GET
|
@GET
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ -127,6 +130,7 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Path("devices")
|
@Path("devices")
|
||||||
@GET
|
@GET
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ -149,54 +153,39 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Path("devices/{sketch_type}/download")
|
@Path("devices/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces("application/zip")
|
||||||
public Response downloadSketch(@QueryParam("deviceName") String deviceName,
|
public Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketch_type") String sketchType) {
|
||||||
@PathParam("sketch_type") String sketchType) {
|
|
||||||
try {
|
try {
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
||||||
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
|
||||||
|
response.status(Response.Status.OK);
|
||||||
response.type("application/zip");
|
response.type("application/zip");
|
||||||
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
return response.build();
|
Response resp = response.build();
|
||||||
|
zipFile.getZipFile().delete();
|
||||||
|
return resp;
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
||||||
} catch (DeviceManagementException ex) {
|
} catch (DeviceManagementException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
} catch (JWTClientException ex) {
|
} catch (JWTClientException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
|
} catch (APIManagerException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
} catch (DeviceControllerException ex) {
|
} catch (DeviceControllerException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
log.error(ex.getMessage(), ex);
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (UserStoreException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("devices/{sketch_type}/generate_link")
|
|
||||||
@GET
|
|
||||||
public Response generateSketchLink(@QueryParam("deviceName") String deviceName,
|
|
||||||
@PathParam("sketch_type") String sketchType) {
|
|
||||||
try {
|
|
||||||
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
|
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
|
||||||
return rb.build();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
return Response.status(400).entity(ex.getMessage()).build();//bad request
|
|
||||||
} catch (DeviceManagementException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (JWTClientException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (DeviceControllerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
|
||||||
} catch (APIManagerException ex) {
|
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
} catch (UserStoreException ex) {
|
} catch (UserStoreException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
return Response.status(500).entity(ex.getMessage()).build();
|
return Response.status(500).entity(ex.getMessage()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,12 +204,12 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
|
|||||||
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
|
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
|
||||||
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
device.setName(name);
|
device.setName(name);
|
||||||
device.setType(RaspberrypiConstants.DEVICE_TYPE);
|
device.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
|
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
|
||||||
device.setEnrolmentInfo(enrolmentInfo);
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
|
return APIUtil.getDeviceManagementService().enrollDevice(device);
|
||||||
return added;
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user