mirror of
https://repository.entgra.net/community/product-iots.git
synced 2025-09-16 23:32:19 +00:00
Merge branch 'master' of https://github.com/wso2-incubator/product-device-cloud
This commit is contained in:
commit
cfd1497ecc
@ -9,7 +9,7 @@
|
|||||||
"overview_name":"android_sense",
|
"overview_name":"android_sense",
|
||||||
"overview_url":"http://www.google.lk",
|
"overview_url":"http://www.google.lk",
|
||||||
"setupGuide_guideImage":"undefined",
|
"setupGuide_guideImage":"undefined",
|
||||||
"overview_actionLabel":"Download",
|
"overview_actionLabel":"Download Agent",
|
||||||
"sketches_Sketches":"android_sense",
|
"sketches_Sketches":"android_sense",
|
||||||
"ingredients_ingredients":[
|
"ingredients_ingredients":[
|
||||||
"Android device"
|
"Android device"
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
"overview_name":"arduino",
|
"overview_name":"arduino",
|
||||||
"overview_url":"http://www.google.lk",
|
"overview_url":"http://www.google.lk",
|
||||||
"setupGuide_guideImage":"undefined",
|
"setupGuide_guideImage":"undefined",
|
||||||
"overview_actionLabel":"Download",
|
"overview_actionLabel":"Download Agent",
|
||||||
"sketches_Sketches":"arduino",
|
"sketches_Sketches":"arduino",
|
||||||
"ingredients_ingredients":[
|
"ingredients_ingredients":[
|
||||||
"Arduino Uno",
|
"Arduino Uno",
|
||||||
|
|||||||
@ -22,13 +22,21 @@ import org.wso2.carbon.device.mgt.common.Device;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
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.sample.arduino.plugin.constants.ArduinoConstants;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.common.DeviceManagement;
|
import org.wso2.carbon.device.mgt.iot.common.DeviceManagement;
|
||||||
import org.wso2.carbon.device.mgt.iot.common.util.ZipArchive;
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipArchive;
|
||||||
import org.wso2.carbon.device.mgt.iot.common.util.ZipUtil;
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.sample.arduino.plugin.constants.ArduinoConstants;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -98,7 +106,8 @@ public class ArduinoManagerService {
|
|||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
||||||
try {
|
try {
|
||||||
boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(deviceIdentifier);
|
boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(
|
||||||
|
deviceIdentifier);
|
||||||
if (removed) {
|
if (removed) {
|
||||||
response.setStatus(Response.Status.OK.getStatusCode());
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
|
||||||
@ -127,7 +136,8 @@ public class ArduinoManagerService {
|
|||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
||||||
try {
|
try {
|
||||||
Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
|
Device device = deviceManagement.getDeviceManagementService().getDevice(
|
||||||
|
deviceIdentifier);
|
||||||
device.setDeviceIdentifier(deviceId);
|
device.setDeviceIdentifier(deviceId);
|
||||||
|
|
||||||
// device.setDeviceTypeId(deviceTypeId);
|
// device.setDeviceTypeId(deviceTypeId);
|
||||||
@ -136,7 +146,8 @@ public class ArduinoManagerService {
|
|||||||
device.setName(name);
|
device.setName(name);
|
||||||
device.setType(ArduinoConstants.DEVICE_TYPE);
|
device.setType(ArduinoConstants.DEVICE_TYPE);
|
||||||
|
|
||||||
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device);
|
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(
|
||||||
|
device);
|
||||||
|
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
@ -168,7 +179,8 @@ public class ArduinoManagerService {
|
|||||||
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
|
Device device = deviceManagement.getDeviceManagementService().getDevice(
|
||||||
|
deviceIdentifier);
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
@ -183,12 +195,14 @@ public class ArduinoManagerService {
|
|||||||
@Path("/device/{sketch_type}/download")
|
@Path("/device/{sketch_type}/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
public Response downloadSketch(@QueryParam("owner") String owner, @PathParam("sketch_type") String
|
public Response downloadSketch(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@PathParam("sketch_type") String
|
||||||
sketchType) {
|
sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
||||||
rb.header("Content-Disposition",
|
rb.header("Content-Disposition",
|
||||||
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
@ -203,12 +217,14 @@ public class ArduinoManagerService {
|
|||||||
|
|
||||||
@Path("/device/{sketch_type}/generate_link")
|
@Path("/device/{sketch_type}/generate_link")
|
||||||
@GET
|
@GET
|
||||||
public Response generateSketchLink(@QueryParam("owner") String owner, @PathParam("sketch_type") String
|
public Response generateSketchLink(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@PathParam("sketch_type") String
|
||||||
sketchType) {
|
sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
return rb.build();
|
return rb.build();
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
@ -219,7 +235,8 @@ public class ArduinoManagerService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String owner, String sketchType) throws DeviceManagementException{
|
private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType)
|
||||||
|
throws DeviceManagementException {
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
||||||
}
|
}
|
||||||
@ -232,9 +249,8 @@ public class ArduinoManagerService {
|
|||||||
String refreshToken = UUID.randomUUID().toString();
|
String refreshToken = UUID.randomUUID().toString();
|
||||||
//adding registering data
|
//adding registering data
|
||||||
|
|
||||||
boolean status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0,
|
String deviceName = customDeviceName + "_" + deviceId;
|
||||||
3),
|
boolean status = register(deviceId, deviceName, owner);
|
||||||
owner);
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
||||||
+ " owner:" + owner;
|
+ " owner:" + owner;
|
||||||
@ -244,7 +260,7 @@ public class ArduinoManagerService {
|
|||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
|
|
||||||
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, token, refreshToken);
|
zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, token, refreshToken);
|
||||||
zipFile.setDeviceId(deviceId);
|
zipFile.setDeviceId(deviceId);
|
||||||
return zipFile;
|
return zipFile;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
"overview_name":"digital_display",
|
"overview_name":"digital_display",
|
||||||
"overview_url":"http://www.google.lk",
|
"overview_url":"http://www.google.lk",
|
||||||
"setupGuide_guideImage":"undefined",
|
"setupGuide_guideImage":"undefined",
|
||||||
"overview_actionLabel":"Download",
|
"overview_actionLabel":"Download Agent",
|
||||||
"sketches_Sketches":"digital_display",
|
"sketches_Sketches":"digital_display",
|
||||||
"ingredients_ingredients":[
|
"ingredients_ingredients":[
|
||||||
"Raspberry",
|
"Raspberry",
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl;
|
package org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl;
|
||||||
|
|
||||||
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.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
@ -24,7 +25,8 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|||||||
import org.wso2.carbon.device.mgt.iot.common.DeviceManagement;
|
import org.wso2.carbon.device.mgt.iot.common.DeviceManagement;
|
||||||
import org.wso2.carbon.device.mgt.iot.common.util.ZipArchive;
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipArchive;
|
||||||
import org.wso2.carbon.device.mgt.iot.common.util.ZipUtil;
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipUtil;
|
||||||
import org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.plugin.constants.DigitalDisplayConstants;
|
import org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.plugin.constants
|
||||||
|
.DigitalDisplayConstants;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@ -50,6 +52,7 @@ public class DigitalDisplayManagerService {
|
|||||||
private final String SUPER_TENANT = "carbon.super";
|
private final String SUPER_TENANT = "carbon.super";
|
||||||
@Context //injected response proxy supporting multiple thread
|
@Context //injected response proxy supporting multiple thread
|
||||||
private HttpServletResponse response;
|
private HttpServletResponse response;
|
||||||
|
|
||||||
@Path("/device/register")
|
@Path("/device/register")
|
||||||
@PUT
|
@PUT
|
||||||
public boolean register(@QueryParam("deviceId") String deviceId,
|
public boolean register(@QueryParam("deviceId") String deviceId,
|
||||||
@ -145,7 +148,8 @@ public class DigitalDisplayManagerService {
|
|||||||
device.setName(name);
|
device.setName(name);
|
||||||
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
|
||||||
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device);
|
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(
|
||||||
|
device);
|
||||||
|
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
@ -177,7 +181,8 @@ public class DigitalDisplayManagerService {
|
|||||||
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
|
Device device = deviceManagement.getDeviceManagementService().getDevice(
|
||||||
|
deviceIdentifier);
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
@ -193,6 +198,7 @@ public class DigitalDisplayManagerService {
|
|||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
public Response downloadSketch(@QueryParam("owner") String owner,
|
public Response downloadSketch(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
@PathParam("sketch_type") String
|
@PathParam("sketch_type") String
|
||||||
sketchType) {
|
sketchType) {
|
||||||
|
|
||||||
@ -208,9 +214,8 @@ public class DigitalDisplayManagerService {
|
|||||||
String refreshToken = UUID.randomUUID().toString();
|
String refreshToken = UUID.randomUUID().toString();
|
||||||
//adding registering data
|
//adding registering data
|
||||||
|
|
||||||
boolean status = register(deviceId,
|
String deviceName = customDeviceName + "_" + deviceId;
|
||||||
owner + "s_" + sketchType + "_" + deviceId.substring(0, 3),
|
boolean status = register(deviceId, customDeviceName, owner);
|
||||||
owner);
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
return Response.status(500).entity(
|
return Response.status(500).entity(
|
||||||
"Error occurred while registering the device with " + "id: " + deviceId
|
"Error occurred while registering the device with " + "id: " + deviceId
|
||||||
@ -221,8 +226,7 @@ public class DigitalDisplayManagerService {
|
|||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = ziputil.downloadSketch(owner, SUPER_TENANT,sketchType, deviceId,
|
zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, customDeviceName, token, refreshToken);
|
||||||
token, refreshToken);
|
|
||||||
} catch (DeviceManagementException ex) {
|
} catch (DeviceManagementException ex) {
|
||||||
return Response.status(500).entity("Error occurred while creating zip file").build();
|
return Response.status(500).entity("Error occurred while creating zip file").build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
"overview_name":"firealarm",
|
"overview_name":"firealarm",
|
||||||
"overview_url":"http://www.google.lk",
|
"overview_url":"http://www.google.lk",
|
||||||
"setupGuide_guideImage":"undefined",
|
"setupGuide_guideImage":"undefined",
|
||||||
"overview_actionLabel":"Download",
|
"overview_actionLabel":"Download Agent",
|
||||||
"sketches_Sketches":"firealarm",
|
"sketches_Sketches":"firealarm",
|
||||||
"ingredients_ingredients":[
|
"ingredients_ingredients":[
|
||||||
"Raspberry Pi",
|
"Raspberry Pi",
|
||||||
|
|||||||
@ -239,11 +239,12 @@ public class FireAlarmManagerService {
|
|||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
public Response downloadSketch(@QueryParam("owner") String owner,
|
public Response downloadSketch(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
||||||
rb.header("Content-Disposition",
|
rb.header("Content-Disposition",
|
||||||
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
@ -263,11 +264,12 @@ public class FireAlarmManagerService {
|
|||||||
@Path("/device/{sketch_type}/generate_link")
|
@Path("/device/{sketch_type}/generate_link")
|
||||||
@GET
|
@GET
|
||||||
public Response generateSketchLink(@QueryParam("owner") String owner,
|
public Response generateSketchLink(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
return rb.build();
|
return rb.build();
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
@ -282,7 +284,7 @@ public class FireAlarmManagerService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String owner, String sketchType)
|
private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType)
|
||||||
throws DeviceManagementException, AccessTokenException, DeviceControllerException {
|
throws DeviceManagementException, AccessTokenException, DeviceControllerException {
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
||||||
@ -305,15 +307,6 @@ public class FireAlarmManagerService {
|
|||||||
newXmppAccount.setAccountName(owner + "_" + deviceId);
|
newXmppAccount.setAccountName(owner + "_" + deviceId);
|
||||||
newXmppAccount.setUsername(deviceId);
|
newXmppAccount.setUsername(deviceId);
|
||||||
newXmppAccount.setPassword(accessToken);
|
newXmppAccount.setPassword(accessToken);
|
||||||
|
|
||||||
String xmppEndPoint = XmppConfig.getInstance().getXmppControlQueue().getServerURL();
|
|
||||||
|
|
||||||
int indexOfChar = xmppEndPoint.lastIndexOf('/');
|
|
||||||
|
|
||||||
if (indexOfChar != -1) {
|
|
||||||
xmppEndPoint = xmppEndPoint.substring((indexOfChar + 1), xmppEndPoint.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
newXmppAccount.setEmail(deviceId + "@wso2.com");
|
newXmppAccount.setEmail(deviceId + "@wso2.com");
|
||||||
|
|
||||||
XmppServerClient xmppServerClient = new XmppServerClient();
|
XmppServerClient xmppServerClient = new XmppServerClient();
|
||||||
@ -325,15 +318,15 @@ public class FireAlarmManagerService {
|
|||||||
if (!status) {
|
if (!status) {
|
||||||
String msg =
|
String msg =
|
||||||
"XMPP Account was not created for device - " + deviceId + " of owner - " +
|
"XMPP Account was not created for device - " + deviceId + " of owner - " +
|
||||||
owner +
|
owner + ". XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config.server.configs";
|
||||||
". XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config.server.configs";
|
|
||||||
log.warn(msg);
|
log.warn(msg);
|
||||||
throw new DeviceManagementException(msg);
|
throw new DeviceManagementException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0,
|
|
||||||
3),
|
String deviceName = customDeviceName + "_" + deviceId;
|
||||||
owner);
|
status = register(deviceId, deviceName, owner);
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
||||||
+ " owner:" + owner;
|
+ " owner:" + owner;
|
||||||
@ -344,7 +337,7 @@ public class FireAlarmManagerService {
|
|||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
|
|
||||||
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, accessToken, refreshToken);
|
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, refreshToken);
|
||||||
zipFile.setDeviceId(deviceId);
|
zipFile.setDeviceId(deviceId);
|
||||||
return zipFile;
|
return zipFile;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -279,11 +279,12 @@ public class FireAlarmService {
|
|||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
public Response downloadSketch(@QueryParam("owner") String owner,
|
public Response downloadSketch(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
||||||
rb.header("Content-Disposition",
|
rb.header("Content-Disposition",
|
||||||
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
@ -303,11 +304,12 @@ public class FireAlarmService {
|
|||||||
@Path("manager/device/{sketch_type}/generate_link")
|
@Path("manager/device/{sketch_type}/generate_link")
|
||||||
@GET
|
@GET
|
||||||
public Response generateSketchLink(@QueryParam("owner") String owner,
|
public Response generateSketchLink(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
return rb.build();
|
return rb.build();
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
@ -322,7 +324,7 @@ public class FireAlarmService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String owner, String sketchType)
|
private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType)
|
||||||
throws DeviceManagementException, AccessTokenException, DeviceControllerException {
|
throws DeviceManagementException, AccessTokenException, DeviceControllerException {
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
||||||
@ -347,15 +349,6 @@ public class FireAlarmService {
|
|||||||
newXmppAccount.setAccountName(owner + "_" + deviceId);
|
newXmppAccount.setAccountName(owner + "_" + deviceId);
|
||||||
newXmppAccount.setUsername(deviceId);
|
newXmppAccount.setUsername(deviceId);
|
||||||
newXmppAccount.setPassword(accessToken);
|
newXmppAccount.setPassword(accessToken);
|
||||||
|
|
||||||
String xmppEndPoint = XmppConfig.getInstance().getXmppControlQueue().getServerURL();
|
|
||||||
|
|
||||||
int indexOfChar = xmppEndPoint.lastIndexOf('/');
|
|
||||||
|
|
||||||
if (indexOfChar != -1) {
|
|
||||||
xmppEndPoint = xmppEndPoint.substring((indexOfChar + 1), xmppEndPoint.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
newXmppAccount.setEmail(deviceId + "@wso2.com");
|
newXmppAccount.setEmail(deviceId + "@wso2.com");
|
||||||
|
|
||||||
XmppServerClient xmppServerClient = new XmppServerClient();
|
XmppServerClient xmppServerClient = new XmppServerClient();
|
||||||
@ -373,9 +366,9 @@ public class FireAlarmService {
|
|||||||
throw new DeviceManagementException(msg);
|
throw new DeviceManagementException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0,
|
|
||||||
3),
|
String deviceName = customDeviceName + "_" + deviceId;
|
||||||
owner);
|
status = register(deviceId, deviceName, owner);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
||||||
+ " owner:" + owner;
|
+ " owner:" + owner;
|
||||||
@ -386,7 +379,7 @@ public class FireAlarmService {
|
|||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
|
|
||||||
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, accessToken, refreshToken);
|
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, refreshToken);
|
||||||
zipFile.setDeviceId(deviceId);
|
zipFile.setDeviceId(deviceId);
|
||||||
return zipFile;
|
return zipFile;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
"overview_name":"raspberrypi",
|
"overview_name":"raspberrypi",
|
||||||
"overview_url":"http://www.google.lk",
|
"overview_url":"http://www.google.lk",
|
||||||
"setupGuide_guideImage":"undefined",
|
"setupGuide_guideImage":"undefined",
|
||||||
"overview_actionLabel":"Download",
|
"overview_actionLabel":"Download Agent",
|
||||||
"sketches_Sketches":"raspberrypi",
|
"sketches_Sketches":"raspberrypi",
|
||||||
"ingredients_ingredients":[
|
"ingredients_ingredients":[
|
||||||
"Raspberry Pi",
|
"Raspberry Pi",
|
||||||
|
|||||||
@ -104,7 +104,8 @@ public class RaspberrypiManagerService {
|
|||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
try {
|
try {
|
||||||
boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(deviceIdentifier);
|
boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(
|
||||||
|
deviceIdentifier);
|
||||||
if (removed) {
|
if (removed) {
|
||||||
response.setStatus(Response.Status.OK.getStatusCode());
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
} else {
|
} else {
|
||||||
@ -130,7 +131,8 @@ public class RaspberrypiManagerService {
|
|||||||
deviceIdentifier.setId(deviceId);
|
deviceIdentifier.setId(deviceId);
|
||||||
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
try {
|
try {
|
||||||
Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
|
Device device = deviceManagement.getDeviceManagementService().getDevice(
|
||||||
|
deviceIdentifier);
|
||||||
device.setDeviceIdentifier(deviceId);
|
device.setDeviceIdentifier(deviceId);
|
||||||
|
|
||||||
// device.setDeviceTypeId(deviceTypeId);
|
// device.setDeviceTypeId(deviceTypeId);
|
||||||
@ -139,7 +141,8 @@ public class RaspberrypiManagerService {
|
|||||||
device.setName(name);
|
device.setName(name);
|
||||||
device.setType(RaspberrypiConstants.DEVICE_TYPE);
|
device.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
|
|
||||||
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device);
|
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(
|
||||||
|
device);
|
||||||
|
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
@ -169,7 +172,8 @@ public class RaspberrypiManagerService {
|
|||||||
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
|
Device device = deviceManagement.getDeviceManagementService().getDevice(
|
||||||
|
deviceIdentifier);
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
} catch (DeviceManagementException ex) {
|
} catch (DeviceManagementException ex) {
|
||||||
@ -182,7 +186,9 @@ public class RaspberrypiManagerService {
|
|||||||
@Path("/device/{sketch_type}/download")
|
@Path("/device/{sketch_type}/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
public Response downloadSketch(@QueryParam("owner") String owner, @PathParam("sketch_type") String
|
public Response downloadSketch(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@PathParam("sketch_type") String
|
||||||
sketchType) {
|
sketchType) {
|
||||||
|
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
@ -197,9 +203,8 @@ public class RaspberrypiManagerService {
|
|||||||
String refreshToken = UUID.randomUUID().toString();
|
String refreshToken = UUID.randomUUID().toString();
|
||||||
//adding registering data
|
//adding registering data
|
||||||
|
|
||||||
boolean status = register(deviceId,
|
String deviceName = customDeviceName + "_" + deviceId;
|
||||||
owner + "s_" + sketchType + "_" + deviceId.substring(0, 3),
|
boolean status = register(deviceId, deviceName, owner);
|
||||||
owner);
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
return Response.status(500).entity(
|
return Response.status(500).entity(
|
||||||
"Error occurred while registering the device with " + "id: " + deviceId
|
"Error occurred while registering the device with " + "id: " + deviceId
|
||||||
@ -210,7 +215,7 @@ public class RaspberrypiManagerService {
|
|||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId,
|
zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName,
|
||||||
token, refreshToken);
|
token, refreshToken);
|
||||||
} catch (DeviceManagementException ex) {
|
} catch (DeviceManagementException ex) {
|
||||||
return Response.status(500).entity("Error occurred while creating zip file").build();
|
return Response.status(500).entity("Error occurred while creating zip file").build();
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
"overview_name":"sensebot",
|
"overview_name":"sensebot",
|
||||||
"overview_url":"http://www.google.lk",
|
"overview_url":"http://www.google.lk",
|
||||||
"setupGuide_guideImage":"undefined",
|
"setupGuide_guideImage":"undefined",
|
||||||
"overview_actionLabel":"Download",
|
"overview_actionLabel":"Download Agent",
|
||||||
"sketches_Sketches":"sensebot",
|
"sketches_Sketches":"sensebot",
|
||||||
"ingredients_ingredients":[
|
"ingredients_ingredients":[
|
||||||
"Arduino Uno",
|
"Arduino Uno",
|
||||||
|
|||||||
@ -180,7 +180,7 @@ public class SensebotManagerService {
|
|||||||
@Path("/device/{sketch_type}/download")
|
@Path("/device/{sketch_type}/download")
|
||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
public Response downloadSketch(@QueryParam("owner") String owner, @PathParam("sketch_type") String
|
public Response downloadSketch(@QueryParam("owner") String owner, @QueryParam("deviceName") String customDeviceName, @PathParam("sketch_type") String
|
||||||
sketchType) {
|
sketchType) {
|
||||||
|
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
@ -195,9 +195,8 @@ public class SensebotManagerService {
|
|||||||
String refreshToken = UUID.randomUUID().toString();
|
String refreshToken = UUID.randomUUID().toString();
|
||||||
//adding registering data
|
//adding registering data
|
||||||
|
|
||||||
boolean status = register(deviceId,
|
String deviceName = customDeviceName + "_" + deviceId;
|
||||||
owner + "s_" + sketchType + "_" + deviceId.substring(0, 3),
|
boolean status = register(deviceId, deviceName, owner);
|
||||||
owner);
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
return Response.status(500).entity(
|
return Response.status(500).entity(
|
||||||
"Error occurred while registering the device with " + "id: " + deviceId
|
"Error occurred while registering the device with " + "id: " + deviceId
|
||||||
@ -208,7 +207,7 @@ public class SensebotManagerService {
|
|||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId,
|
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, deviceName,
|
||||||
token,refreshToken);
|
token,refreshToken);
|
||||||
} catch (DeviceManagementException ex) {
|
} catch (DeviceManagementException ex) {
|
||||||
return Response.status(500).entity("Error occurred while creating zip file").build();
|
return Response.status(500).entity("Error occurred while creating zip file").build();
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
"overview_name":"virtual_firealarm",
|
"overview_name":"virtual_firealarm",
|
||||||
"overview_url":"http://www.google.lk",
|
"overview_url":"http://www.google.lk",
|
||||||
"setupGuide_guideImage":"undefined",
|
"setupGuide_guideImage":"undefined",
|
||||||
"overview_actionLabel":"Download",
|
"overview_actionLabel":"Download Agent",
|
||||||
"sketches_Sketches":"virtual_firealarm",
|
"sketches_Sketches":"virtual_firealarm",
|
||||||
"ingredients_ingredients":[
|
"ingredients_ingredients":[
|
||||||
"Virtual Agent that simulates an actual firealarm"
|
"Virtual Agent that simulates an actual firealarm"
|
||||||
|
|||||||
@ -18,8 +18,10 @@
|
|||||||
#[Device-Configurations]
|
#[Device-Configurations]
|
||||||
owner=${DEVICE_OWNER}
|
owner=${DEVICE_OWNER}
|
||||||
deviceId=${DEVICE_ID}
|
deviceId=${DEVICE_ID}
|
||||||
server-ep=${SERVER_EP}
|
device-name=${DEVICE_NAME}
|
||||||
service-ep=${SERVICE_EP}
|
controller-context=/virtual_firealarm/controller
|
||||||
|
https-ep=${HTTPS_EP}
|
||||||
|
http-ep=${HTTP_EP}
|
||||||
apim-ep=${APIM_EP}
|
apim-ep=${APIM_EP}
|
||||||
mqtt-ep=${MQTT_EP}
|
mqtt-ep=${MQTT_EP}
|
||||||
xmpp-ep=${XMPP_EP}
|
xmpp-ep=${XMPP_EP}
|
||||||
|
|||||||
@ -302,11 +302,12 @@ public class VirtualFireAlarmService {
|
|||||||
@GET
|
@GET
|
||||||
@Produces("application/octet-stream")
|
@Produces("application/octet-stream")
|
||||||
public Response downloadSketch(@QueryParam("owner") String owner,
|
public Response downloadSketch(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
||||||
rb.header("Content-Disposition",
|
rb.header("Content-Disposition",
|
||||||
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
"attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
@ -326,11 +327,12 @@ public class VirtualFireAlarmService {
|
|||||||
@Path("manager/device/{sketch_type}/generate_link")
|
@Path("manager/device/{sketch_type}/generate_link")
|
||||||
@GET
|
@GET
|
||||||
public Response generateSketchLink(@QueryParam("owner") String owner,
|
public Response generateSketchLink(@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@PathParam("sketch_type") String sketchType) {
|
||||||
|
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
try {
|
try {
|
||||||
zipFile = createDownloadFile(owner, sketchType);
|
zipFile = createDownloadFile(owner, customDeviceName, sketchType);
|
||||||
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
|
||||||
return rb.build();
|
return rb.build();
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
@ -345,7 +347,7 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZipArchive createDownloadFile(String owner, String sketchType)
|
private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType)
|
||||||
throws DeviceManagementException, AccessTokenException, DeviceControllerException {
|
throws DeviceManagementException, AccessTokenException, DeviceControllerException {
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
|
||||||
@ -356,7 +358,6 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
TokenClient accessTokenClient = new TokenClient(VirtualFireAlarmConstants.DEVICE_TYPE);
|
TokenClient accessTokenClient = new TokenClient(VirtualFireAlarmConstants.DEVICE_TYPE);
|
||||||
AccessTokenInfo accessTokenInfo = null;
|
AccessTokenInfo accessTokenInfo = null;
|
||||||
|
|
||||||
accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
|
accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
|
||||||
|
|
||||||
//create token
|
//create token
|
||||||
@ -368,35 +369,30 @@ public class VirtualFireAlarmService {
|
|||||||
newXmppAccount.setAccountName(owner + "_" + deviceId);
|
newXmppAccount.setAccountName(owner + "_" + deviceId);
|
||||||
newXmppAccount.setUsername(deviceId);
|
newXmppAccount.setUsername(deviceId);
|
||||||
newXmppAccount.setPassword(accessToken);
|
newXmppAccount.setPassword(accessToken);
|
||||||
|
|
||||||
String xmppEndPoint = XmppConfig.getInstance().getXmppControlQueue().getServerURL();
|
|
||||||
|
|
||||||
int indexOfChar = xmppEndPoint.lastIndexOf('/');
|
|
||||||
|
|
||||||
if (indexOfChar != -1) {
|
|
||||||
xmppEndPoint = xmppEndPoint.substring((indexOfChar + 1), xmppEndPoint.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
newXmppAccount.setEmail(deviceId + "@wso2.com");
|
newXmppAccount.setEmail(deviceId + "@wso2.com");
|
||||||
|
|
||||||
XmppServerClient xmppServerClient = new XmppServerClient();
|
XmppServerClient xmppServerClient = new XmppServerClient();
|
||||||
xmppServerClient.initControlQueue();
|
xmppServerClient.initControlQueue();
|
||||||
boolean status;
|
boolean status;
|
||||||
|
|
||||||
if (XmppConfig.getInstance().isEnabled()) {
|
if (XmppConfig.getInstance().isEnabled()) {
|
||||||
status = xmppServerClient.createXMPPAccount(newXmppAccount);
|
status = xmppServerClient.createXMPPAccount(newXmppAccount);
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
String msg =
|
String msg =
|
||||||
"XMPP Account was not created for device - " + deviceId + " of owner - " +
|
"XMPP Account was not created for device - " + deviceId + " of owner - " +
|
||||||
owner +
|
owner +
|
||||||
". XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config.server.configs";
|
".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot" +
|
||||||
|
".common.config.server.configs";
|
||||||
log.warn(msg);
|
log.warn(msg);
|
||||||
throw new DeviceManagementException(msg);
|
throw new DeviceManagementException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0,
|
|
||||||
3),
|
//Register the device with CDMF
|
||||||
owner);
|
String deviceName = customDeviceName + "_" + deviceId;
|
||||||
|
status = register(deviceId, deviceName, owner);
|
||||||
|
// status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0, 3),
|
||||||
|
// owner);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
String msg = "Error occurred while registering the device with " + "id: " + deviceId
|
||||||
+ " owner:" + owner;
|
+ " owner:" + owner;
|
||||||
@ -406,8 +402,8 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
ZipUtil ziputil = new ZipUtil();
|
ZipUtil ziputil = new ZipUtil();
|
||||||
ZipArchive zipFile = null;
|
ZipArchive zipFile = null;
|
||||||
|
zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName,
|
||||||
zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, accessToken, refreshToken);
|
accessToken, refreshToken);
|
||||||
zipFile.setDeviceId(deviceId);
|
zipFile.setDeviceId(deviceId);
|
||||||
return zipFile;
|
return zipFile;
|
||||||
}
|
}
|
||||||
@ -483,7 +479,8 @@ public class VirtualFireAlarmService {
|
|||||||
String protocolString = protocol.toUpperCase();
|
String protocolString = protocol.toUpperCase();
|
||||||
String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState;
|
String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState;
|
||||||
|
|
||||||
log.info("Sending command: '" + callUrlPattern + "' to virtual-firealarm at: " + deviceIP + " " +
|
log.info("Sending command: '" + callUrlPattern + "' to virtual-firealarm at: " + deviceIP +
|
||||||
|
" " +
|
||||||
"via" + " " + protocolString);
|
"via" + " " + protocolString);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -492,11 +489,13 @@ public class VirtualFireAlarmService {
|
|||||||
sendCommandViaHTTP(deviceIP, 9090, callUrlPattern, true);
|
sendCommandViaHTTP(deviceIP, 9090, callUrlPattern, true);
|
||||||
break;
|
break;
|
||||||
case MQTT_PROTOCOL:
|
case MQTT_PROTOCOL:
|
||||||
sendCommandViaMQTT(owner, deviceId, VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""),
|
sendCommandViaMQTT(owner, deviceId,
|
||||||
|
VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""),
|
||||||
switchToState);
|
switchToState);
|
||||||
break;
|
break;
|
||||||
case XMPP_PROTOCOL:
|
case XMPP_PROTOCOL:
|
||||||
sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.BULB_CONTEXT, switchToState);
|
sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.BULB_CONTEXT,
|
||||||
|
switchToState);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (protocolString == null) {
|
if (protocolString == null) {
|
||||||
@ -551,24 +550,34 @@ public class VirtualFireAlarmService {
|
|||||||
try {
|
try {
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case HTTP_PROTOCOL:
|
case HTTP_PROTOCOL:
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + HTTP_PROTOCOL);
|
log.info("Sending request to read sonar value at : " + deviceIp + " via " +
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.SONAR_CONTEXT, false);
|
HTTP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaHTTP(deviceIp, 9090,
|
||||||
|
VirtualFireAlarmConstants.SONAR_CONTEXT, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MQTT_PROTOCOL:
|
case MQTT_PROTOCOL:
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + MQTT_PROTOCOL);
|
log.info("Sending request to read sonar value at : " + deviceIp + " via " +
|
||||||
sendCommandViaMQTT(owner, deviceId, VirtualFireAlarmConstants.SONAR_CONTEXT.replace("/", ""), "");
|
MQTT_PROTOCOL);
|
||||||
|
sendCommandViaMQTT(owner, deviceId,
|
||||||
|
VirtualFireAlarmConstants.SONAR_CONTEXT.replace("/", ""),
|
||||||
|
"");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XMPP_PROTOCOL:
|
case XMPP_PROTOCOL:
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + XMPP_PROTOCOL);
|
log.info("Sending request to read sonar value at : " + deviceIp + " via " +
|
||||||
replyMsg = sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.SONAR_CONTEXT, ".");
|
XMPP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaXMPP(owner, deviceId,
|
||||||
|
VirtualFireAlarmConstants.SONAR_CONTEXT, ".");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (protocol == null) {
|
if (protocol == null) {
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + HTTP_PROTOCOL);
|
log.info("Sending request to read sonar value at : " + deviceIp + " via " +
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.SONAR_CONTEXT, false);
|
HTTP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaHTTP(deviceIp, 9090,
|
||||||
|
VirtualFireAlarmConstants.SONAR_CONTEXT,
|
||||||
|
false);
|
||||||
} else {
|
} else {
|
||||||
replyMsg = "Requested protocol '" + protocol + "' is not supported";
|
replyMsg = "Requested protocol '" + protocol + "' is not supported";
|
||||||
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
||||||
@ -621,24 +630,38 @@ public class VirtualFireAlarmService {
|
|||||||
try {
|
try {
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case HTTP_PROTOCOL:
|
case HTTP_PROTOCOL:
|
||||||
log.info("Sending request to read virtual-firealarm-temperature at : " + deviceIp + " via " + HTTP_PROTOCOL);
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false);
|
deviceIp + " via " + HTTP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaHTTP(deviceIp, 9090,
|
||||||
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
||||||
|
false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MQTT_PROTOCOL:
|
case MQTT_PROTOCOL:
|
||||||
log.info("Sending request to read virtual-firealarm-temperature at : " + deviceIp + " via " + MQTT_PROTOCOL);
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
sendCommandViaMQTT(owner, deviceId, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", ""), "");
|
deviceIp + " via " + MQTT_PROTOCOL);
|
||||||
|
sendCommandViaMQTT(owner, deviceId,
|
||||||
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/",
|
||||||
|
""),
|
||||||
|
"");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XMPP_PROTOCOL:
|
case XMPP_PROTOCOL:
|
||||||
log.info("Sending request to read virtual-firealarm-temperature at : " + deviceIp + " via " + XMPP_PROTOCOL);
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
replyMsg = sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, ".");
|
deviceIp + " via " + XMPP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaXMPP(owner, deviceId,
|
||||||
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
||||||
|
".");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (protocol == null) {
|
if (protocol == null) {
|
||||||
log.info("Sending request to read virtual-firealarm-temperature at : " + deviceIp + " via " + HTTP_PROTOCOL);
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false);
|
deviceIp + " via " + HTTP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaHTTP(deviceIp, 9090,
|
||||||
|
VirtualFireAlarmConstants
|
||||||
|
.TEMPERATURE_CONTEXT,
|
||||||
|
false);
|
||||||
} else {
|
} else {
|
||||||
replyMsg = "Requested protocol '" + protocol + "' is not supported";
|
replyMsg = "Requested protocol '" + protocol + "' is not supported";
|
||||||
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
||||||
@ -676,7 +699,9 @@ public class VirtualFireAlarmService {
|
|||||||
return;
|
return;
|
||||||
} else if (!registeredIp.equals(deviceIp)) {
|
} else if (!registeredIp.equals(deviceIp)) {
|
||||||
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " +
|
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " +
|
||||||
deviceId + " is already registered under some other IP. Re-registration " + "required");
|
deviceId +
|
||||||
|
" is already registered under some other IP. Re-registration " +
|
||||||
|
"required");
|
||||||
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -686,7 +711,8 @@ public class VirtualFireAlarmService {
|
|||||||
ctx.setTenantDomain(SUPER_TENANT, true);
|
ctx.setTenantDomain(SUPER_TENANT, true);
|
||||||
DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx
|
DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx
|
||||||
.getOSGiService(DeviceAnalyticsService.class, null);
|
.getOSGiService(DeviceAnalyticsService.class, null);
|
||||||
Object metdaData[] = {dataMsg.owner, VirtualFireAlarmConstants.DEVICE_TYPE, dataMsg.deviceId,
|
Object metdaData[] =
|
||||||
|
{dataMsg.owner, VirtualFireAlarmConstants.DEVICE_TYPE, dataMsg.deviceId,
|
||||||
System.currentTimeMillis()};
|
System.currentTimeMillis()};
|
||||||
Object payloadData[] = {temperature};
|
Object payloadData[] = {temperature};
|
||||||
try {
|
try {
|
||||||
@ -896,7 +922,9 @@ public class VirtualFireAlarmService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String responseMsg = "";
|
String responseMsg = "";
|
||||||
String urlString = VirtualFireAlarmConstants.URL_PREFIX + deviceIp + ":" + deviceServerPort + callUrlPattern;
|
String urlString =
|
||||||
|
VirtualFireAlarmConstants.URL_PREFIX + deviceIp + ":" + deviceServerPort +
|
||||||
|
callUrlPattern;
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(urlString);
|
log.debug(urlString);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user