diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml
index f27cac0a5d..329fee5216 100644
--- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml
+++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml
@@ -129,6 +129,12 @@
provided
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.apimgt.webapp.publisher
+ provided
+
+
org.wso2.carbon
org.wso2.carbon.utils
@@ -214,6 +220,11 @@
org.wso2.carbon.apimgt.annotations
provided
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.apimgt.webapp.publisher
+ provided
+
diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java
index aab8a662d4..da05509b56 100644
--- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java
+++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java
@@ -18,30 +18,36 @@
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.device.DeviceType;
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.DeviceManagement;
+import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo;
+import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
+import org.wso2.carbon.apimgt.webapp.publisher.KeyGenerationUtil;
+import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException;
+import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants;
-import javax.jws.WebService;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.UUID;
-@WebService
+@DeviceType(value = "digital_display")
public class DigitalDisplayManagerService {
private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class);
@@ -50,12 +56,11 @@ public class DigitalDisplayManagerService {
@Context //injected response proxy supporting multiple thread
private HttpServletResponse response;
- @Path("/device/register")
+ @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) {
- log.info("Register call from " + owner);
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
@@ -73,19 +78,16 @@ public class DigitalDisplayManagerService {
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
- device.setEnrolmentInfo(enrolmentInfo);
+ enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
device.setName(name);
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
enrolmentInfo.setOwner(owner);
- enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
+ device.setEnrolmentInfo(enrolmentInfo);
boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device);
-
if (added) {
response.setStatus(Response.Status.OK.getStatusCode());
} else {
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
-
-
}
return added;
@@ -97,50 +99,43 @@ public class DigitalDisplayManagerService {
}
}
- @Path("/device/remove/{device_id}")
+ @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();
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
-
try {
boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(
deviceIdentifier);
if (removed) {
response.setStatus(Response.Status.OK.getStatusCode());
-
} else {
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
-
}
} catch (DeviceManagementException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} finally {
deviceManagement.endTenantFlow();
}
-
-
}
- @Path("/device/update/{device_id}")
+ @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);
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
-
try {
- Device device = deviceManagement.getDeviceManagementService().getDevice(
- deviceIdentifier);
+ Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
device.setDeviceIdentifier(deviceId);
// device.setDeviceTypeId(deviceTypeId);
@@ -149,31 +144,27 @@ 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) {
response.setStatus(Response.Status.OK.getStatusCode());
} else {
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
-
}
return updated;
} catch (DeviceManagementException e) {
- response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ log.error(e.getErrorMessage());
return false;
} finally {
deviceManagement.endTenantFlow();
}
-
}
- @Path("/device/{device_id}")
+ @Path("manager/device/{device_id}")
@GET
- @Consumes("application/json")
- @Produces("application/json")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
public Device getDevice(@PathParam("device_id") String deviceId) {
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
@@ -182,59 +173,77 @@ public class DigitalDisplayManagerService {
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
try {
- Device device = deviceManagement.getDeviceManagementService().getDevice(
- deviceIdentifier);
-
- return device;
- } catch (DeviceManagementException e) {
- response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
+ } catch (DeviceManagementException ex) {
+ log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex);
return null;
} finally {
deviceManagement.endTenantFlow();
}
-
}
- @Path("/device/{sketch_type}/download")
+ @Path("manager/device/{sketch_type}/download")
@GET
- @Produces("application/octet-stream")
+ @Produces(MediaType.APPLICATION_JSON)
public Response downloadSketch(@QueryParam("owner") String owner,
- @QueryParam("deviceName") String deviceName,
- @PathParam("sketch_type") String
- sketchType) {
+ @QueryParam("deviceName") String deviceName,
+ @PathParam("sketch_type") String
+ sketchType) {
+
+ try {
+ ZipArchive zipFile = createDownloadFile(owner, deviceName, sketchType);
+ Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
+ response.type("application/zip");
+ response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
+ return response.build();
+
+ } catch (IllegalArgumentException ex) {
+ return Response.status(400).entity(ex.getMessage()).build();//bad request
+ } catch (DeviceManagementException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (AccessTokenException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (DeviceControllerException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (IOException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ }
+ }
+ private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType)
+ throws DeviceManagementException, AccessTokenException, DeviceControllerException {
if (owner == null) {
- return Response.status(400).build();//bad request
+ throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
}
//create new device id
String deviceId = shortUUID();
+ KeyGenerationUtil.createApplicationKeys("digital_display");
+
+ TokenClient accessTokenClient = new TokenClient(DigitalDisplayConstants.DEVICE_TYPE);
+ AccessTokenInfo accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
+
//create token
- String token = UUID.randomUUID().toString();
- String refreshToken = UUID.randomUUID().toString();
+ String accessToken = accessTokenInfo.getAccess_token();
+ String refreshToken = accessTokenInfo.getRefresh_token();
//adding registering data
- boolean status = register(deviceId, deviceName, owner);
- if (!status) {
- return Response.status(500).entity(
- "Error occurred while registering the device with " + "id: " + deviceId
- + " owner:" + owner).build();
+ boolean status;
- }
+ //Register the device with CDMF
+ status = register(deviceId, deviceName, owner);
- ZipUtil ziputil = new ZipUtil();
- ZipArchive zipFile = null;
- try {
- zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, token,
- refreshToken);
- } catch (DeviceManagementException ex) {
- return Response.status(500).entity("Error occurred while creating zip file").build();
+ if (!status) {
+ String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner;
+ throw new DeviceManagementException(msg);
}
- Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
- rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
- return rb.build();
+ ZipUtil ziputil = new ZipUtil();
+ ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken,
+ refreshToken);
+ zipFile.setDeviceId(deviceId);
+ return zipFile;
}
private static String shortUUID() {
diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
index 09e7f4b066..8a58ec334c 100644
--- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -23,7 +23,7 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
-
+
diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml
index cd571f07d1..ed37125f12 100644
--- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml
+++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml
@@ -25,9 +25,7 @@
JAX-WS/JAX-RS MDM Android Endpoint
JAX-WS/JAX-RS Servlet
CXFServlet
-
- org.apache.cxf.transport.servlet.CXFServlet
-
+ org.apache.cxf.transport.servlet.CXFServlet
1
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs
index 56164fbb7e..f05daa49d2 100644
--- a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs
@@ -186,7 +186,7 @@
03 Download
Arduino-Sketch from
- [Download] link above.
+ [Download Sketch] link above.
04 Unzip the
downloaded
diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs
index d6d30c132a..5174fea69c 100644
--- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs
+++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs
@@ -17,21 +17,21 @@
What it Does
Connect a Digital Message Display to WSO2 IoT Server and manage
- it.
+ it.
What You Need
- ITEM 01 Raspberry
- Pi with SD Card(Internet
- Enabled [Wifi or Ethernet]).
+ Pi with SD Card(Internet
+ Enabled [Wifi or Ethernet]).
- ITEM 02 A Digital Display with HDMI
- Cable.
+ Cable.
- STEP 03 Proceed
- to [Prepare] section.
+ to [Prepare] section.
@@ -61,7 +61,7 @@
@@ -176,14 +176,14 @@