application-manager-new
ayyoob 9 years ago
commit cfd1497ecc

@ -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"

@ -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",

@ -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;
@ -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);
@ -98,7 +106,8 @@ public class ArduinoManagerService {
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());
@ -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,12 +195,14 @@ public class ArduinoManagerService {
@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) {
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() + "\"");
@ -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
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;
}

@ -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",

@ -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,6 +52,7 @@ 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,
@ -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,6 +198,7 @@ public class DigitalDisplayManagerService {
@GET
@Produces("application/octet-stream")
public Response downloadSketch(@QueryParam("owner") String owner,
@QueryParam("deviceName") String customDeviceName,
@PathParam("sketch_type") String
sketchType) {
@ -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();
}

@ -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",

@ -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;
}

@ -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;
}

@ -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",

@ -104,7 +104,8 @@ public class RaspberrypiManagerService {
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 {
@ -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,7 +186,9 @@ public class RaspberrypiManagerService {
@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) {
@ -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();
}

@ -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",

@ -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();

@ -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"

@ -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}

@ -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
@ -302,11 +302,12 @@ public class VirtualFireAlarmService {
@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() + "\"");
@ -326,11 +327,12 @@ public class VirtualFireAlarmService {
@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) {
@ -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;
}
@ -483,7 +479,8 @@ public class VirtualFireAlarmService {
String protocolString = protocol.toUpperCase();
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);
try {
@ -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) {
@ -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());
@ -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());
@ -676,7 +699,9 @@ public class VirtualFireAlarmService {
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,7 +711,8 @@ 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,
Object metdaData[] =
{dataMsg.owner, VirtualFireAlarmConstants.DEVICE_TYPE, dataMsg.deviceId,
System.currentTimeMillis()};
Object payloadData[] = {temperature};
try {
@ -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);

Loading…
Cancel
Save