diff --git a/modules/samples/android_sense/artifact/deviceType.json b/modules/samples/android_sense/artifact/deviceType.json index f83f2baf..4bcf082a 100644 --- a/modules/samples/android_sense/artifact/deviceType.json +++ b/modules/samples/android_sense/artifact/deviceType.json @@ -9,7 +9,7 @@ "overview_name":"android_sense", "overview_url":"http://www.google.lk", "setupGuide_guideImage":"undefined", - "overview_actionLabel":"Download", + "overview_actionLabel":"Download Agent", "sketches_Sketches":"android_sense", "ingredients_ingredients":[ "Android device" diff --git a/modules/samples/arduino/artifact/deviceType.json b/modules/samples/arduino/artifact/deviceType.json index de4f9ee3..08c8aad2 100644 --- a/modules/samples/arduino/artifact/deviceType.json +++ b/modules/samples/arduino/artifact/deviceType.json @@ -9,7 +9,7 @@ "overview_name":"arduino", "overview_url":"http://www.google.lk", "setupGuide_guideImage":"undefined", - "overview_actionLabel":"Download", + "overview_actionLabel":"Download Agent", "sketches_Sketches":"arduino", "ingredients_ingredients":[ "Arduino Uno", diff --git a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoManagerService.java b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoManagerService.java index 06512681..9498df0f 100644 --- a/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoManagerService.java +++ b/modules/samples/arduino/src/org.wso2.carbon.device.mgt.iot.sample.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/arduino/service/impl/ArduinoManagerService.java @@ -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.DeviceManagementException; 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.util.ZipArchive; 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.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.Response; import java.nio.ByteBuffer; @@ -48,7 +56,7 @@ public class ArduinoManagerService { @Path("/device/register") @PUT 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); @@ -63,7 +71,7 @@ public class ArduinoManagerService { Device device = new Device(); device.setDeviceIdentifier(deviceId); - EnrolmentInfo enrolmentInfo=new EnrolmentInfo(); + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); enrolmentInfo.setDateOfEnrolment(new Date().getTime()); enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); @@ -91,14 +99,15 @@ public class ArduinoManagerService { @Path("/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); try { - boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(deviceIdentifier); + boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice( + deviceIdentifier); if (removed) { response.setStatus(Response.Status.OK.getStatusCode()); @@ -118,8 +127,8 @@ public class ArduinoManagerService { @Path("/device/update/{device_id}") @POST public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { + @QueryParam("name") String name, + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -127,7 +136,8 @@ public class ArduinoManagerService { deviceIdentifier.setId(deviceId); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); try { - Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); device.setDeviceIdentifier(deviceId); // device.setDeviceTypeId(deviceTypeId); @@ -136,7 +146,8 @@ public class ArduinoManagerService { device.setName(name); device.setType(ArduinoConstants.DEVICE_TYPE); - boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device); + boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( + device); if (updated) { @@ -168,7 +179,8 @@ public class ArduinoManagerService { deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); try { - Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); return device; } catch (DeviceManagementException e) { @@ -183,15 +195,17 @@ public class ArduinoManagerService { @Path("/device/{sketch_type}/download") @GET @Produces("application/octet-stream") - public Response downloadSketch(@QueryParam("owner") String owner, @PathParam("sketch_type") String - sketchType) { + public Response downloadSketch(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String + sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); rb.header("Content-Disposition", - "attachment; filename=\"" + zipFile.getFileName() + "\""); + "attachment; filename=\"" + zipFile.getFileName() + "\""); return rb.build(); } catch (IllegalArgumentException ex) { return Response.status(400).entity(ex.getMessage()).build();//bad request @@ -203,12 +217,14 @@ public class ArduinoManagerService { @Path("/device/{sketch_type}/generate_link") @GET - public Response generateSketchLink(@QueryParam("owner") String owner, @PathParam("sketch_type") String - sketchType) { + public Response generateSketchLink(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String + sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); return rb.build(); } 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) { throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); } @@ -232,9 +249,8 @@ public class ArduinoManagerService { String refreshToken = UUID.randomUUID().toString(); //adding registering data - boolean status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0, - 3), - owner); + String deviceName = customDeviceName + "_" + deviceId; + boolean status = register(deviceId, deviceName, owner); if (!status) { String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; @@ -244,7 +260,7 @@ public class ArduinoManagerService { ZipUtil ziputil = new ZipUtil(); 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); return zipFile; } diff --git a/modules/samples/digital_display/artifact/deviceType.json b/modules/samples/digital_display/artifact/deviceType.json index 2621b5d7..6aa3a481 100644 --- a/modules/samples/digital_display/artifact/deviceType.json +++ b/modules/samples/digital_display/artifact/deviceType.json @@ -9,7 +9,7 @@ "overview_name":"digital_display", "overview_url":"http://www.google.lk", "setupGuide_guideImage":"undefined", - "overview_actionLabel":"Download", + "overview_actionLabel":"Download Agent", "sketches_Sketches":"digital_display", "ingredients_ingredients":[ "Raspberry", diff --git a/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/digitaldisplay/service/impl/DigitalDisplayManagerService.java b/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/digitaldisplay/service/impl/DigitalDisplayManagerService.java index f9f679b4..780deb92 100644 --- a/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/digitaldisplay/service/impl/DigitalDisplayManagerService.java +++ b/modules/samples/digital_display/src/org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/digitaldisplay/service/impl/DigitalDisplayManagerService.java @@ -15,6 +15,7 @@ */ package org.wso2.carbon.device.mgt.iot.sample.digitaldisplay.service.impl; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.util.ZipArchive; 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.ws.rs.Consumes; @@ -50,10 +52,11 @@ public class DigitalDisplayManagerService { private final String SUPER_TENANT = "carbon.super"; @Context //injected response proxy supporting multiple thread private HttpServletResponse response; + @Path("/device/register") @PUT 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); @@ -98,7 +101,7 @@ public class DigitalDisplayManagerService { @Path("/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -126,8 +129,8 @@ public class DigitalDisplayManagerService { @Path("/device/update/{device_id}") @POST public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { + @QueryParam("name") String name, + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -145,7 +148,8 @@ public class DigitalDisplayManagerService { device.setName(name); device.setType(DigitalDisplayConstants.DEVICE_TYPE); - boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device); + boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( + device); if (updated) { @@ -177,7 +181,8 @@ public class DigitalDisplayManagerService { deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); try { - Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); return device; } catch (DeviceManagementException e) { @@ -193,8 +198,9 @@ public class DigitalDisplayManagerService { @GET @Produces("application/octet-stream") public Response downloadSketch(@QueryParam("owner") String owner, - @PathParam("sketch_type") String - sketchType) { + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String + sketchType) { if (owner == null) { return Response.status(400).build();//bad request @@ -208,9 +214,8 @@ public class DigitalDisplayManagerService { String refreshToken = UUID.randomUUID().toString(); //adding registering data - boolean status = register(deviceId, - owner + "s_" + sketchType + "_" + deviceId.substring(0, 3), - owner); + String deviceName = customDeviceName + "_" + deviceId; + boolean status = register(deviceId, customDeviceName, owner); if (!status) { return Response.status(500).entity( "Error occurred while registering the device with " + "id: " + deviceId @@ -221,8 +226,7 @@ public class DigitalDisplayManagerService { ZipUtil ziputil = new ZipUtil(); ZipArchive zipFile = null; try { - zipFile = ziputil.downloadSketch(owner, SUPER_TENANT,sketchType, deviceId, - token, refreshToken); + zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, customDeviceName, token, refreshToken); } catch (DeviceManagementException ex) { return Response.status(500).entity("Error occurred while creating zip file").build(); } diff --git a/modules/samples/firealarm/artifact/deviceType.json b/modules/samples/firealarm/artifact/deviceType.json index fb8138e7..54b3d78c 100644 --- a/modules/samples/firealarm/artifact/deviceType.json +++ b/modules/samples/firealarm/artifact/deviceType.json @@ -9,7 +9,7 @@ "overview_name":"firealarm", "overview_url":"http://www.google.lk", "setupGuide_guideImage":"undefined", - "overview_actionLabel":"Download", + "overview_actionLabel":"Download Agent", "sketches_Sketches":"firealarm", "ingredients_ingredients":[ "Raspberry Pi", diff --git a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmManagerService.java b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmManagerService.java index 5ce29421..ccc647d8 100644 --- a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmManagerService.java +++ b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmManagerService.java @@ -239,11 +239,12 @@ public class FireAlarmManagerService { @GET @Produces("application/octet-stream") public Response downloadSketch(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, @PathParam("sketch_type") String sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); @@ -263,11 +264,12 @@ public class FireAlarmManagerService { @Path("/device/{sketch_type}/generate_link") @GET public Response generateSketchLink(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, @PathParam("sketch_type") String sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); return rb.build(); } 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 { if (owner == null) { throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); @@ -305,15 +307,6 @@ public class FireAlarmManagerService { newXmppAccount.setAccountName(owner + "_" + deviceId); newXmppAccount.setUsername(deviceId); 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"); XmppServerClient xmppServerClient = new XmppServerClient(); @@ -325,15 +318,15 @@ public class FireAlarmManagerService { if (!status) { String msg = "XMPP Account was not created for device - " + deviceId + " of owner - " + - owner + - ". XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config.server.configs"; + owner + ". XMPP might have been disabled in org.wso2.carbon.device.mgt.iot.common.config.server.configs"; log.warn(msg); throw new DeviceManagementException(msg); } } - status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0, - 3), - owner); + + String deviceName = customDeviceName + "_" + deviceId; + status = register(deviceId, deviceName, owner); + if (!status) { String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; @@ -344,7 +337,7 @@ public class FireAlarmManagerService { ZipUtil ziputil = new ZipUtil(); 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); return zipFile; } diff --git a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmService.java b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmService.java index a3da1b6b..4d17b8cb 100644 --- a/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmService.java +++ b/modules/samples/firealarm/src/org.wso2.carbon.device.mgt.iot.sample.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/firealarm/service/impl/FireAlarmService.java @@ -279,11 +279,12 @@ public class FireAlarmService { @GET @Produces("application/octet-stream") public Response downloadSketch(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, @PathParam("sketch_type") String sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); @@ -303,11 +304,12 @@ public class FireAlarmService { @Path("manager/device/{sketch_type}/generate_link") @GET public Response generateSketchLink(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, @PathParam("sketch_type") String sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); return rb.build(); } 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 { if (owner == null) { throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); @@ -347,15 +349,6 @@ public class FireAlarmService { newXmppAccount.setAccountName(owner + "_" + deviceId); newXmppAccount.setUsername(deviceId); 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"); XmppServerClient xmppServerClient = new XmppServerClient(); @@ -373,9 +366,9 @@ public class FireAlarmService { throw new DeviceManagementException(msg); } } - status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0, - 3), - owner); + + String deviceName = customDeviceName + "_" + deviceId; + status = register(deviceId, deviceName, owner); if (!status) { String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; @@ -386,7 +379,7 @@ public class FireAlarmService { ZipUtil ziputil = new ZipUtil(); 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); return zipFile; } diff --git a/modules/samples/raspberrypi/artifact/deviceType.json b/modules/samples/raspberrypi/artifact/deviceType.json index b985e717..b6657955 100644 --- a/modules/samples/raspberrypi/artifact/deviceType.json +++ b/modules/samples/raspberrypi/artifact/deviceType.json @@ -9,7 +9,7 @@ "overview_name":"raspberrypi", "overview_url":"http://www.google.lk", "setupGuide_guideImage":"undefined", - "overview_actionLabel":"Download", + "overview_actionLabel":"Download Agent", "sketches_Sketches":"raspberrypi", "ingredients_ingredients":[ "Raspberry Pi", diff --git a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiManagerService.java b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiManagerService.java index 5c8d1187..dedf41bb 100644 --- a/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiManagerService.java +++ b/modules/samples/raspberrypi/src/org.wso2.carbon.device.mgt.iot.sample.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/raspberrypi/service/impl/RaspberrypiManagerService.java @@ -56,7 +56,7 @@ public class RaspberrypiManagerService { @Path("/device/register") @PUT 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); @@ -97,14 +97,15 @@ public class RaspberrypiManagerService { @Path("/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); try { - boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(deviceIdentifier); + boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice( + deviceIdentifier); if (removed) { response.setStatus(Response.Status.OK.getStatusCode()); } else { @@ -121,8 +122,8 @@ public class RaspberrypiManagerService { @Path("/device/update/{device_id}") @POST public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { + @QueryParam("name") String name, + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -130,7 +131,8 @@ public class RaspberrypiManagerService { deviceIdentifier.setId(deviceId); deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); try { - Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); device.setDeviceIdentifier(deviceId); // device.setDeviceTypeId(deviceTypeId); @@ -139,7 +141,8 @@ public class RaspberrypiManagerService { device.setName(name); device.setType(RaspberrypiConstants.DEVICE_TYPE); - boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device); + boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( + device); if (updated) { @@ -169,7 +172,8 @@ public class RaspberrypiManagerService { deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE); try { - Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); return device; } catch (DeviceManagementException ex) { @@ -182,8 +186,10 @@ public class RaspberrypiManagerService { @Path("/device/{sketch_type}/download") @GET @Produces("application/octet-stream") - public Response downloadSketch(@QueryParam("owner") String owner, @PathParam("sketch_type") String - sketchType) { + public Response downloadSketch(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String + sketchType) { if (owner == null) { return Response.status(400).build();//bad request @@ -197,9 +203,8 @@ public class RaspberrypiManagerService { String refreshToken = UUID.randomUUID().toString(); //adding registering data - boolean status = register(deviceId, - owner + "s_" + sketchType + "_" + deviceId.substring(0, 3), - owner); + String deviceName = customDeviceName + "_" + deviceId; + boolean status = register(deviceId, deviceName, owner); if (!status) { return Response.status(500).entity( "Error occurred while registering the device with " + "id: " + deviceId @@ -210,8 +215,8 @@ public class RaspberrypiManagerService { ZipUtil ziputil = new ZipUtil(); ZipArchive zipFile = null; try { - zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, - token,refreshToken); + zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, + token, refreshToken); } catch (DeviceManagementException ex) { return Response.status(500).entity("Error occurred while creating zip file").build(); } diff --git a/modules/samples/sensebot/artifact/deviceType.json b/modules/samples/sensebot/artifact/deviceType.json index a16e3c45..f1613d0c 100644 --- a/modules/samples/sensebot/artifact/deviceType.json +++ b/modules/samples/sensebot/artifact/deviceType.json @@ -9,7 +9,7 @@ "overview_name":"sensebot", "overview_url":"http://www.google.lk", "setupGuide_guideImage":"undefined", - "overview_actionLabel":"Download", + "overview_actionLabel":"Download Agent", "sketches_Sketches":"sensebot", "ingredients_ingredients":[ "Arduino Uno", diff --git a/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/sensebot/service/impl/SensebotManagerService.java b/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/sensebot/service/impl/SensebotManagerService.java index e3591289..ea036128 100644 --- a/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/sensebot/service/impl/SensebotManagerService.java +++ b/modules/samples/sensebot/src/org.wso2.carbon.device.mgt.iot.sample.sensebot.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/sensebot/service/impl/SensebotManagerService.java @@ -180,7 +180,7 @@ public class SensebotManagerService { @Path("/device/{sketch_type}/download") @GET @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) { if (owner == null) { @@ -195,9 +195,8 @@ public class SensebotManagerService { String refreshToken = UUID.randomUUID().toString(); //adding registering data - boolean status = register(deviceId, - owner + "s_" + sketchType + "_" + deviceId.substring(0, 3), - owner); + String deviceName = customDeviceName + "_" + deviceId; + boolean status = register(deviceId, deviceName, owner); if (!status) { return Response.status(500).entity( "Error occurred while registering the device with " + "id: " + deviceId @@ -208,7 +207,7 @@ public class SensebotManagerService { ZipUtil ziputil = new ZipUtil(); ZipArchive zipFile = null; try { - zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, + zipFile = ziputil.downloadSketch(owner,SUPER_TENANT, sketchType, deviceId, deviceName, token,refreshToken); } catch (DeviceManagementException ex) { return Response.status(500).entity("Error occurred while creating zip file").build(); diff --git a/modules/samples/virtual_firealarm/artifact/deviceType.json b/modules/samples/virtual_firealarm/artifact/deviceType.json index a9f467af..d9f36153 100644 --- a/modules/samples/virtual_firealarm/artifact/deviceType.json +++ b/modules/samples/virtual_firealarm/artifact/deviceType.json @@ -9,7 +9,7 @@ "overview_name":"virtual_firealarm", "overview_url":"http://www.google.lk", "setupGuide_guideImage":"undefined", - "overview_actionLabel":"Download", + "overview_actionLabel":"Download Agent", "sketches_Sketches":"virtual_firealarm", "ingredients_ingredients":[ "Virtual Agent that simulates an actual firealarm" diff --git a/modules/samples/virtual_firealarm/sketch/deviceConfig.properties b/modules/samples/virtual_firealarm/sketch/deviceConfig.properties index 4af8602c..7fefece7 100644 --- a/modules/samples/virtual_firealarm/sketch/deviceConfig.properties +++ b/modules/samples/virtual_firealarm/sketch/deviceConfig.properties @@ -18,8 +18,10 @@ #[Device-Configurations] owner=${DEVICE_OWNER} deviceId=${DEVICE_ID} -server-ep=${SERVER_EP} -service-ep=${SERVICE_EP} +device-name=${DEVICE_NAME} +controller-context=/virtual_firealarm/controller +https-ep=${HTTPS_EP} +http-ep=${HTTP_EP} apim-ep=${APIM_EP} mqtt-ep=${MQTT_EP} xmpp-ep=${XMPP_EP} diff --git a/modules/samples/virtual_firealarm/src/org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/virtual/firealarm/service/impl/VirtualFireAlarmService.java b/modules/samples/virtual_firealarm/src/org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/virtual/firealarm/service/impl/VirtualFireAlarmService.java index d75a3236..9b891606 100644 --- a/modules/samples/virtual_firealarm/src/org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/virtual/firealarm/service/impl/VirtualFireAlarmService.java +++ b/modules/samples/virtual_firealarm/src/org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/sample/virtual/firealarm/service/impl/VirtualFireAlarmService.java @@ -90,7 +90,7 @@ public class VirtualFireAlarmService { 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"; @Context //injected response proxy supporting multiple thread @@ -131,7 +131,7 @@ public class VirtualFireAlarmService { @Path("manager/device/register") @PUT 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); @@ -176,7 +176,7 @@ public class VirtualFireAlarmService { @Path("manager/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -203,8 +203,8 @@ public class VirtualFireAlarmService { @Path("manager/device/update/{device_id}") @POST public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { + @QueryParam("name") String name, + @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -302,14 +302,15 @@ public class VirtualFireAlarmService { @GET @Produces("application/octet-stream") public Response downloadSketch(@QueryParam("owner") String owner, - @PathParam("sketch_type") String sketchType) { + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); rb.header("Content-Disposition", - "attachment; filename=\"" + zipFile.getFileName() + "\""); + "attachment; filename=\"" + zipFile.getFileName() + "\""); return rb.build(); } catch (IllegalArgumentException ex) { return Response.status(400).entity(ex.getMessage()).build();//bad request @@ -326,11 +327,12 @@ public class VirtualFireAlarmService { @Path("manager/device/{sketch_type}/generate_link") @GET public Response generateSketchLink(@QueryParam("owner") String owner, - @PathParam("sketch_type") String sketchType) { + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String sketchType) { ZipArchive zipFile = null; try { - zipFile = createDownloadFile(owner, sketchType); + zipFile = createDownloadFile(owner, customDeviceName, sketchType); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); return rb.build(); } 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 { if (owner == null) { throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); @@ -356,7 +358,6 @@ public class VirtualFireAlarmService { TokenClient accessTokenClient = new TokenClient(VirtualFireAlarmConstants.DEVICE_TYPE); AccessTokenInfo accessTokenInfo = null; - accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); //create token @@ -368,35 +369,30 @@ public class VirtualFireAlarmService { newXmppAccount.setAccountName(owner + "_" + deviceId); newXmppAccount.setUsername(deviceId); 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"); XmppServerClient xmppServerClient = new XmppServerClient(); xmppServerClient.initControlQueue(); boolean status; - if(XmppConfig.getInstance().isEnabled()) { - status = xmppServerClient.createXMPPAccount(newXmppAccount); + if (XmppConfig.getInstance().isEnabled()) { + status = xmppServerClient.createXMPPAccount(newXmppAccount); if (!status) { String msg = "XMPP Account was not created for device - " + deviceId + " of 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); throw new DeviceManagementException(msg); } } - status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0, - 3), - owner); + + //Register the device with CDMF + String deviceName = customDeviceName + "_" + deviceId; + status = register(deviceId, deviceName, owner); +// status = register(deviceId, owner + "s_" + sketchType + "_" + deviceId.substring(0, 3), +// owner); if (!status) { String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; @@ -406,8 +402,8 @@ public class VirtualFireAlarmService { ZipUtil ziputil = new ZipUtil(); 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); return zipFile; } @@ -421,13 +417,13 @@ public class VirtualFireAlarmService { @Path("controller/register/{owner}/{deviceId}/{ip}") @POST public String registerDeviceIP(@PathParam("owner") String owner, - @PathParam("deviceId") String deviceId, - @PathParam("ip") String deviceIP, - @Context HttpServletResponse response) { + @PathParam("deviceId") String deviceId, + @PathParam("ip") String deviceIP, + @Context HttpServletResponse response) { String result; log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + - " of owner: " + owner); + " of owner: " + owner); deviceToIpMap.put(deviceId, deviceIP); @@ -447,15 +443,15 @@ public class VirtualFireAlarmService { @Path("controller/bulb/{state}") @POST public void switchBulb(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, - @HeaderParam("protocol") String protocol, - @PathParam("state") String state, - @Context HttpServletResponse response) { + @HeaderParam("deviceId") String deviceId, + @HeaderParam("protocol") String protocol, + @PathParam("state") String state, + @Context HttpServletResponse response) { try { DeviceValidator deviceValidator = new DeviceValidator(); if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId, - VirtualFireAlarmConstants.DEVICE_TYPE))) { + VirtualFireAlarmConstants.DEVICE_TYPE))) { response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); return; } @@ -483,8 +479,9 @@ public class VirtualFireAlarmService { String protocolString = protocol.toUpperCase(); String callUrlPattern = VirtualFireAlarmConstants.BULB_CONTEXT + switchToState; - log.info("Sending command: '" + callUrlPattern + "' to virtual-firealarm at: " + deviceIP + " " + - "via" + " " + protocolString); + log.info("Sending command: '" + callUrlPattern + "' to virtual-firealarm at: " + deviceIP + + " " + + "via" + " " + protocolString); try { switch (protocolString) { @@ -492,11 +489,13 @@ public class VirtualFireAlarmService { sendCommandViaHTTP(deviceIP, 9090, callUrlPattern, true); break; case MQTT_PROTOCOL: - sendCommandViaMQTT(owner, deviceId, VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""), + sendCommandViaMQTT(owner, deviceId, + VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""), switchToState); break; case XMPP_PROTOCOL: - sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.BULB_CONTEXT, switchToState); + sendCommandViaXMPP(owner, deviceId, VirtualFireAlarmConstants.BULB_CONTEXT, + switchToState); break; default: if (protocolString == null) { @@ -521,16 +520,16 @@ public class VirtualFireAlarmService { @Path("controller/readsonar") @GET public String requestSonarReading(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, - @HeaderParam("protocol") String protocol, - @Context HttpServletResponse response) { + @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))) { + VirtualFireAlarmConstants + .DEVICE_TYPE))) { response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); return "Unauthorized Access"; } @@ -551,24 +550,34 @@ public class VirtualFireAlarmService { 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); + 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("/", ""), ""); + 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, "."); + 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); + 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()); @@ -591,9 +600,9 @@ public class VirtualFireAlarmService { @Path("controller/readtemperature") @GET public String requestTemperature(@HeaderParam("owner") String owner, - @HeaderParam("deviceId") String deviceId, - @HeaderParam("protocol") String protocol, - @Context HttpServletResponse response) { + @HeaderParam("deviceId") String deviceId, + @HeaderParam("protocol") String protocol, + @Context HttpServletResponse response) { String replyMsg = ""; DeviceValidator deviceValidator = new DeviceValidator(); @@ -621,24 +630,38 @@ public class VirtualFireAlarmService { 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); + 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("/", ""), ""); + 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, "."); + 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); + log.info("Sending request to read virtual-firealarm-temperature at : " + + deviceIp + " via " + HTTP_PROTOCOL); + replyMsg = sendCommandViaHTTP(deviceIp, 9090, + VirtualFireAlarmConstants + .TEMPERATURE_CONTEXT, + false); } else { replyMsg = "Requested protocol '" + protocol + "' is not supported"; response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); @@ -671,12 +694,14 @@ public class VirtualFireAlarmService { if (registeredIp == null) { 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()); return; } else if (!registeredIp.equals(deviceIp)) { log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + - deviceId + " is already registered under some other IP. Re-registration " + "required"); + deviceId + + " is already registered under some other IP. Re-registration " + + "required"); response.setStatus(Response.Status.CONFLICT.getStatusCode()); return; } @@ -686,12 +711,13 @@ public class VirtualFireAlarmService { ctx.setTenantDomain(SUPER_TENANT, true); DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx .getOSGiService(DeviceAnalyticsService.class, null); - Object metdaData[] = {dataMsg.owner, VirtualFireAlarmConstants.DEVICE_TYPE, dataMsg.deviceId, - System.currentTimeMillis()}; + Object metdaData[] = + {dataMsg.owner, VirtualFireAlarmConstants.DEVICE_TYPE, dataMsg.deviceId, + System.currentTimeMillis()}; Object payloadData[] = {temperature}; try { deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", - metdaData, new Object[0], payloadData); + metdaData, new Object[0], payloadData); } catch (DataPublisherConfigurationException e) { response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); @@ -783,7 +809,7 @@ public class VirtualFireAlarmService { private String sendCommandViaXMPP(String deviceOwner, String deviceId, String resource, - String state) throws DeviceManagementException { + String state) throws DeviceManagementException { String replyMsg = ""; String scriptArguments = ""; @@ -868,7 +894,7 @@ public class VirtualFireAlarmService { private boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource, - String state) throws DeviceManagementException { + String state) throws DeviceManagementException { boolean result = false; DeviceController deviceController = new DeviceController(); @@ -876,7 +902,7 @@ public class VirtualFireAlarmService { try { result = deviceController.publishMqttControl(deviceOwner, VirtualFireAlarmConstants.DEVICE_TYPE, - deviceId, resource, state); + deviceId, resource, state); } catch (DeviceControllerException e) { String errorMsg = "Error whilst trying to publish to MQTT Queue"; log.error(errorMsg); @@ -887,8 +913,8 @@ public class VirtualFireAlarmService { private String sendCommandViaHTTP(final String deviceIp, int deviceServerPort, - String callUrlPattern, - boolean fireAndForgot) + String callUrlPattern, + boolean fireAndForgot) throws DeviceManagementException { if (deviceServerPort == 0) { @@ -896,7 +922,9 @@ public class VirtualFireAlarmService { } String responseMsg = ""; - String urlString = VirtualFireAlarmConstants.URL_PREFIX + deviceIp + ":" + deviceServerPort + callUrlPattern; + String urlString = + VirtualFireAlarmConstants.URL_PREFIX + deviceIp + ":" + deviceServerPort + + callUrlPattern; if (log.isDebugEnabled()) { log.debug(urlString); @@ -972,7 +1000,7 @@ public class VirtualFireAlarmService { /* This methods creates and returns a http connection object */ private HttpURLConnection getHttpConnection(String urlString) throws - DeviceManagementException { + DeviceManagementException { URL connectionUrl = null; HttpURLConnection httpConnection = null;