forked from community/device-mgt-plugins
parent
012fc028cf
commit
315177b787
30
components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceData.java → components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/dto/AndroidConfiguration.java
30
components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceData.java → components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/dto/AndroidConfiguration.java
46
components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorData.java → components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/AndroidConfiguration.java
46
components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorData.java → components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/AndroidConfiguration.java
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.virtualfirealarm.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;
|
||||
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<>();
|
||||
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("MQTT_EP", mqttEndpoint);
|
||||
contextParams.put("XMPP_EP", xmppEndpoint);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue