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;
|
||||||
@ -48,7 +56,7 @@ public class ArduinoManagerService {
|
|||||||
@Path("/device/register")
|
@Path("/device/register")
|
||||||
@PUT
|
@PUT
|
||||||
public boolean register(@QueryParam("deviceId") String deviceId,
|
public boolean register(@QueryParam("deviceId") String deviceId,
|
||||||
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -63,7 +71,7 @@ public class ArduinoManagerService {
|
|||||||
|
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.setDeviceIdentifier(deviceId);
|
device.setDeviceIdentifier(deviceId);
|
||||||
EnrolmentInfo enrolmentInfo=new EnrolmentInfo();
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
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);
|
||||||
@ -91,14 +99,15 @@ public class ArduinoManagerService {
|
|||||||
@Path("/device/remove/{device_id}")
|
@Path("/device/remove/{device_id}")
|
||||||
@DELETE
|
@DELETE
|
||||||
public void removeDevice(@PathParam("device_id") String deviceId,
|
public void removeDevice(@PathParam("device_id") String deviceId,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
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());
|
||||||
|
|
||||||
@ -118,8 +127,8 @@ public class ArduinoManagerService {
|
|||||||
@Path("/device/update/{device_id}")
|
@Path("/device/update/{device_id}")
|
||||||
@POST
|
@POST
|
||||||
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
||||||
@QueryParam("name") String name,
|
@QueryParam("name") String name,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -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,15 +195,17 @@ 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,
|
||||||
sketchType) {
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@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() + "\"");
|
||||||
return rb.build();
|
return rb.build();
|
||||||
} 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
|
||||||
@ -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,
|
||||||
sketchType) {
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@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) {
|
||||||
@ -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,10 +52,11 @@ 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,
|
||||||
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ public class DigitalDisplayManagerService {
|
|||||||
@Path("/device/remove/{device_id}")
|
@Path("/device/remove/{device_id}")
|
||||||
@DELETE
|
@DELETE
|
||||||
public void removeDevice(@PathParam("device_id") String deviceId,
|
public void removeDevice(@PathParam("device_id") String deviceId,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
@ -126,8 +129,8 @@ public class DigitalDisplayManagerService {
|
|||||||
@Path("/device/update/{device_id}")
|
@Path("/device/update/{device_id}")
|
||||||
@POST
|
@POST
|
||||||
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
||||||
@QueryParam("name") String name,
|
@QueryParam("name") String name,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -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,8 +198,9 @@ 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,
|
||||||
@PathParam("sketch_type") String
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
sketchType) {
|
@PathParam("sketch_type") String
|
||||||
|
sketchType) {
|
||||||
|
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
return Response.status(400).build();//bad request
|
return Response.status(400).build();//bad request
|
||||||
@ -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",
|
||||||
|
|||||||
@ -56,7 +56,7 @@ public class RaspberrypiManagerService {
|
|||||||
@Path("/device/register")
|
@Path("/device/register")
|
||||||
@PUT
|
@PUT
|
||||||
public boolean register(@QueryParam("deviceId") String deviceId,
|
public boolean register(@QueryParam("deviceId") String deviceId,
|
||||||
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -97,14 +97,15 @@ public class RaspberrypiManagerService {
|
|||||||
@Path("/device/remove/{device_id}")
|
@Path("/device/remove/{device_id}")
|
||||||
@DELETE
|
@DELETE
|
||||||
public void removeDevice(@PathParam("device_id") String deviceId,
|
public void removeDevice(@PathParam("device_id") String deviceId,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
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 {
|
||||||
@ -121,8 +122,8 @@ public class RaspberrypiManagerService {
|
|||||||
@Path("/device/update/{device_id}")
|
@Path("/device/update/{device_id}")
|
||||||
@POST
|
@POST
|
||||||
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
||||||
@QueryParam("name") String name,
|
@QueryParam("name") String name,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -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,8 +186,10 @@ 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,
|
||||||
sketchType) {
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@PathParam("sketch_type") String
|
||||||
|
sketchType) {
|
||||||
|
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
return Response.status(400).build();//bad request
|
return Response.status(400).build();//bad request
|
||||||
@ -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,8 +215,8 @@ 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}
|
||||||
|
|||||||
@ -90,7 +90,7 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
private static Log log = LogFactory.getLog(VirtualFireAlarmService.class);
|
private static Log log = LogFactory.getLog(VirtualFireAlarmService.class);
|
||||||
|
|
||||||
//TODO; replace this tenant domain
|
//TODO; replace this tenant domain
|
||||||
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
|
||||||
@ -131,7 +131,7 @@ public class VirtualFireAlarmService {
|
|||||||
@Path("manager/device/register")
|
@Path("manager/device/register")
|
||||||
@PUT
|
@PUT
|
||||||
public boolean register(@QueryParam("deviceId") String deviceId,
|
public boolean register(@QueryParam("deviceId") String deviceId,
|
||||||
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
@QueryParam("name") String name, @QueryParam("owner") String owner) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ public class VirtualFireAlarmService {
|
|||||||
@Path("manager/device/remove/{device_id}")
|
@Path("manager/device/remove/{device_id}")
|
||||||
@DELETE
|
@DELETE
|
||||||
public void removeDevice(@PathParam("device_id") String deviceId,
|
public void removeDevice(@PathParam("device_id") String deviceId,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
@ -203,8 +203,8 @@ public class VirtualFireAlarmService {
|
|||||||
@Path("manager/device/update/{device_id}")
|
@Path("manager/device/update/{device_id}")
|
||||||
@POST
|
@POST
|
||||||
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
||||||
@QueryParam("name") String name,
|
@QueryParam("name") String name,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
@ -302,14 +302,15 @@ 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,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@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() + "\"");
|
||||||
return rb.build();
|
return rb.build();
|
||||||
} 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
|
||||||
@ -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,
|
||||||
@PathParam("sketch_type") String sketchType) {
|
@QueryParam("deviceName") String customDeviceName,
|
||||||
|
@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()) {
|
|
||||||
status = xmppServerClient.createXMPPAccount(newXmppAccount);
|
|
||||||
|
|
||||||
|
if (XmppConfig.getInstance().isEnabled()) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@ -421,13 +417,13 @@ public class VirtualFireAlarmService {
|
|||||||
@Path("controller/register/{owner}/{deviceId}/{ip}")
|
@Path("controller/register/{owner}/{deviceId}/{ip}")
|
||||||
@POST
|
@POST
|
||||||
public String registerDeviceIP(@PathParam("owner") String owner,
|
public String registerDeviceIP(@PathParam("owner") String owner,
|
||||||
@PathParam("deviceId") String deviceId,
|
@PathParam("deviceId") String deviceId,
|
||||||
@PathParam("ip") String deviceIP,
|
@PathParam("ip") String deviceIP,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId +
|
log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId +
|
||||||
" of owner: " + owner);
|
" of owner: " + owner);
|
||||||
|
|
||||||
deviceToIpMap.put(deviceId, deviceIP);
|
deviceToIpMap.put(deviceId, deviceIP);
|
||||||
|
|
||||||
@ -447,15 +443,15 @@ public class VirtualFireAlarmService {
|
|||||||
@Path("controller/bulb/{state}")
|
@Path("controller/bulb/{state}")
|
||||||
@POST
|
@POST
|
||||||
public void switchBulb(@HeaderParam("owner") String owner,
|
public void switchBulb(@HeaderParam("owner") String owner,
|
||||||
@HeaderParam("deviceId") String deviceId,
|
@HeaderParam("deviceId") String deviceId,
|
||||||
@HeaderParam("protocol") String protocol,
|
@HeaderParam("protocol") String protocol,
|
||||||
@PathParam("state") String state,
|
@PathParam("state") String state,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DeviceValidator deviceValidator = new DeviceValidator();
|
DeviceValidator deviceValidator = new DeviceValidator();
|
||||||
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
|
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
|
||||||
VirtualFireAlarmConstants.DEVICE_TYPE))) {
|
VirtualFireAlarmConstants.DEVICE_TYPE))) {
|
||||||
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -483,8 +479,9 @@ 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 {
|
||||||
switch (protocolString) {
|
switch (protocolString) {
|
||||||
@ -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) {
|
||||||
@ -521,79 +520,9 @@ public class VirtualFireAlarmService {
|
|||||||
@Path("controller/readsonar")
|
@Path("controller/readsonar")
|
||||||
@GET
|
@GET
|
||||||
public String requestSonarReading(@HeaderParam("owner") String owner,
|
public String requestSonarReading(@HeaderParam("owner") String owner,
|
||||||
@HeaderParam("deviceId") String deviceId,
|
@HeaderParam("deviceId") String deviceId,
|
||||||
@HeaderParam("protocol") String protocol,
|
@HeaderParam("protocol") String protocol,
|
||||||
@Context HttpServletResponse response) {
|
@Context HttpServletResponse response) {
|
||||||
String replyMsg = "";
|
|
||||||
|
|
||||||
DeviceValidator deviceValidator = new DeviceValidator();
|
|
||||||
try {
|
|
||||||
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
|
|
||||||
VirtualFireAlarmConstants
|
|
||||||
.DEVICE_TYPE))) {
|
|
||||||
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
|
||||||
return "Unauthorized Access";
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
replyMsg = e.getErrorMessage();
|
|
||||||
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
||||||
return replyMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
String deviceIp = deviceToIpMap.get(deviceId);
|
|
||||||
|
|
||||||
if (deviceIp == null) {
|
|
||||||
replyMsg = "IP not registered for device: " + deviceId + " of owner: " + owner;
|
|
||||||
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
||||||
return replyMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
switch (protocol) {
|
|
||||||
case HTTP_PROTOCOL:
|
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + HTTP_PROTOCOL);
|
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.SONAR_CONTEXT, false);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MQTT_PROTOCOL:
|
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + MQTT_PROTOCOL);
|
|
||||||
sendCommandViaMQTT(owner, deviceId, VirtualFireAlarmConstants.SONAR_CONTEXT.replace("/", ""), "");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case XMPP_PROTOCOL:
|
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + XMPP_PROTOCOL);
|
|
||||||
replyMsg = sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.SONAR_CONTEXT, ".");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (protocol == null) {
|
|
||||||
log.info("Sending request to read sonar value at : " + deviceIp + " via " + HTTP_PROTOCOL);
|
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.SONAR_CONTEXT, false);
|
|
||||||
} else {
|
|
||||||
replyMsg = "Requested protocol '" + protocol + "' is not supported";
|
|
||||||
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
||||||
return replyMsg;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
replyMsg = e.getErrorMessage();
|
|
||||||
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
||||||
return replyMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setStatus(Response.Status.OK.getStatusCode());
|
|
||||||
replyMsg = "The current sonar reading of the device is " + replyMsg;
|
|
||||||
return replyMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Path("controller/readtemperature")
|
|
||||||
@GET
|
|
||||||
public String requestTemperature(@HeaderParam("owner") String owner,
|
|
||||||
@HeaderParam("deviceId") String deviceId,
|
|
||||||
@HeaderParam("protocol") String protocol,
|
|
||||||
@Context HttpServletResponse response) {
|
|
||||||
String replyMsg = "";
|
String replyMsg = "";
|
||||||
|
|
||||||
DeviceValidator deviceValidator = new DeviceValidator();
|
DeviceValidator deviceValidator = new DeviceValidator();
|
||||||
@ -621,24 +550,118 @@ 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 sonar value at : " + deviceIp + " via " +
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.TEMPERATURE_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 virtual-firealarm-temperature at : " + deviceIp + " via " + MQTT_PROTOCOL);
|
log.info("Sending request to read sonar value at : " + deviceIp + " via " +
|
||||||
sendCommandViaMQTT(owner, deviceId, VirtualFireAlarmConstants.TEMPERATURE_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 virtual-firealarm-temperature at : " + deviceIp + " via " + XMPP_PROTOCOL);
|
log.info("Sending request to read sonar value at : " + deviceIp + " via " +
|
||||||
replyMsg = sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.TEMPERATURE_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 virtual-firealarm-temperature at : " + deviceIp + " via " + HTTP_PROTOCOL);
|
log.info("Sending request to read sonar value at : " + deviceIp + " via " +
|
||||||
replyMsg = sendCommandViaHTTP(deviceIp, 9090, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false);
|
HTTP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaHTTP(deviceIp, 9090,
|
||||||
|
VirtualFireAlarmConstants.SONAR_CONTEXT,
|
||||||
|
false);
|
||||||
|
} else {
|
||||||
|
replyMsg = "Requested protocol '" + protocol + "' is not supported";
|
||||||
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
||||||
|
return replyMsg;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
replyMsg = e.getErrorMessage();
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
return replyMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
replyMsg = "The current sonar reading of the device is " + replyMsg;
|
||||||
|
return replyMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Path("controller/readtemperature")
|
||||||
|
@GET
|
||||||
|
public String requestTemperature(@HeaderParam("owner") String owner,
|
||||||
|
@HeaderParam("deviceId") String deviceId,
|
||||||
|
@HeaderParam("protocol") String protocol,
|
||||||
|
@Context HttpServletResponse response) {
|
||||||
|
String replyMsg = "";
|
||||||
|
|
||||||
|
DeviceValidator deviceValidator = new DeviceValidator();
|
||||||
|
try {
|
||||||
|
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
|
||||||
|
VirtualFireAlarmConstants
|
||||||
|
.DEVICE_TYPE))) {
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
return "Unauthorized Access";
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
replyMsg = e.getErrorMessage();
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
return replyMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
String deviceIp = deviceToIpMap.get(deviceId);
|
||||||
|
|
||||||
|
if (deviceIp == null) {
|
||||||
|
replyMsg = "IP not registered for device: " + deviceId + " of owner: " + owner;
|
||||||
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
||||||
|
return replyMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (protocol) {
|
||||||
|
case HTTP_PROTOCOL:
|
||||||
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
|
deviceIp + " via " + HTTP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaHTTP(deviceIp, 9090,
|
||||||
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
||||||
|
false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MQTT_PROTOCOL:
|
||||||
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
|
deviceIp + " via " + MQTT_PROTOCOL);
|
||||||
|
sendCommandViaMQTT(owner, deviceId,
|
||||||
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/",
|
||||||
|
""),
|
||||||
|
"");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case XMPP_PROTOCOL:
|
||||||
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
|
deviceIp + " via " + XMPP_PROTOCOL);
|
||||||
|
replyMsg = sendCommandViaXMPP(owner, deviceId,
|
||||||
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
||||||
|
".");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (protocol == null) {
|
||||||
|
log.info("Sending request to read virtual-firealarm-temperature at : " +
|
||||||
|
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());
|
||||||
@ -671,12 +694,14 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
if (registeredIp == null) {
|
if (registeredIp == null) {
|
||||||
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
||||||
deviceIp + " for device ID - " + deviceId);
|
deviceIp + " for device ID - " + deviceId);
|
||||||
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
||||||
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,12 +711,13 @@ 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[] =
|
||||||
System.currentTimeMillis()};
|
{dataMsg.owner, VirtualFireAlarmConstants.DEVICE_TYPE, dataMsg.deviceId,
|
||||||
|
System.currentTimeMillis()};
|
||||||
Object payloadData[] = {temperature};
|
Object payloadData[] = {temperature};
|
||||||
try {
|
try {
|
||||||
deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0",
|
deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0",
|
||||||
metdaData, new Object[0], payloadData);
|
metdaData, new Object[0], payloadData);
|
||||||
} catch (DataPublisherConfigurationException e) {
|
} catch (DataPublisherConfigurationException e) {
|
||||||
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
|
||||||
@ -783,7 +809,7 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
|
|
||||||
private String sendCommandViaXMPP(String deviceOwner, String deviceId, String resource,
|
private String sendCommandViaXMPP(String deviceOwner, String deviceId, String resource,
|
||||||
String state) throws DeviceManagementException {
|
String state) throws DeviceManagementException {
|
||||||
|
|
||||||
String replyMsg = "";
|
String replyMsg = "";
|
||||||
String scriptArguments = "";
|
String scriptArguments = "";
|
||||||
@ -868,7 +894,7 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
|
|
||||||
private boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource,
|
private boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource,
|
||||||
String state) throws DeviceManagementException {
|
String state) throws DeviceManagementException {
|
||||||
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
DeviceController deviceController = new DeviceController();
|
DeviceController deviceController = new DeviceController();
|
||||||
@ -876,7 +902,7 @@ public class VirtualFireAlarmService {
|
|||||||
try {
|
try {
|
||||||
result = deviceController.publishMqttControl(deviceOwner,
|
result = deviceController.publishMqttControl(deviceOwner,
|
||||||
VirtualFireAlarmConstants.DEVICE_TYPE,
|
VirtualFireAlarmConstants.DEVICE_TYPE,
|
||||||
deviceId, resource, state);
|
deviceId, resource, state);
|
||||||
} catch (DeviceControllerException e) {
|
} catch (DeviceControllerException e) {
|
||||||
String errorMsg = "Error whilst trying to publish to MQTT Queue";
|
String errorMsg = "Error whilst trying to publish to MQTT Queue";
|
||||||
log.error(errorMsg);
|
log.error(errorMsg);
|
||||||
@ -887,8 +913,8 @@ public class VirtualFireAlarmService {
|
|||||||
|
|
||||||
|
|
||||||
private String sendCommandViaHTTP(final String deviceIp, int deviceServerPort,
|
private String sendCommandViaHTTP(final String deviceIp, int deviceServerPort,
|
||||||
String callUrlPattern,
|
String callUrlPattern,
|
||||||
boolean fireAndForgot)
|
boolean fireAndForgot)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
|
|
||||||
if (deviceServerPort == 0) {
|
if (deviceServerPort == 0) {
|
||||||
@ -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);
|
||||||
@ -972,7 +1000,7 @@ public class VirtualFireAlarmService {
|
|||||||
/* This methods creates and returns a http connection object */
|
/* This methods creates and returns a http connection object */
|
||||||
|
|
||||||
private HttpURLConnection getHttpConnection(String urlString) throws
|
private HttpURLConnection getHttpConnection(String urlString) throws
|
||||||
DeviceManagementException {
|
DeviceManagementException {
|
||||||
|
|
||||||
URL connectionUrl = null;
|
URL connectionUrl = null;
|
||||||
HttpURLConnection httpConnection = null;
|
HttpURLConnection httpConnection = null;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user