Digital display manager changes and UI changes

NuwanSameera 9 years ago
parent 74f8dd9f0c
commit 4bf17c4238

@ -129,6 +129,12 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId> <artifactId>org.wso2.carbon.utils</artifactId>
@ -214,6 +220,11 @@
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId> <artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>

@ -18,30 +18,36 @@
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api; 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.Log;
import org.apache.commons.logging.LogFactory; 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.apimgt.annotations.device.DeviceType;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.iot.DeviceManagement; 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.ZipArchive;
import org.wso2.carbon.device.mgt.iot.util.ZipUtil; import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants;
import javax.jws.WebService;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
@WebService @DeviceType(value = "digital_display")
public class DigitalDisplayManagerService { public class DigitalDisplayManagerService {
private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class); private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class);
@ -50,12 +56,11 @@ public class DigitalDisplayManagerService {
@Context //injected response proxy supporting multiple thread @Context //injected response proxy supporting multiple thread
private HttpServletResponse response; private HttpServletResponse response;
@Path("/device/register") @Path("manager/device/register")
@PUT @PUT
public boolean register(@QueryParam("deviceId") String deviceId, public boolean register(@QueryParam("deviceId") String deviceId,
@QueryParam("name") String name, @QueryParam("owner") String owner ) { @QueryParam("name") String name, @QueryParam("owner") String owner) {
log.info("Register call from " + owner);
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
@ -73,19 +78,16 @@ public class DigitalDisplayManagerService {
enrolmentInfo.setDateOfEnrolment(new Date().getTime()); enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
device.setEnrolmentInfo(enrolmentInfo); enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
device.setName(name); device.setName(name);
device.setType(DigitalDisplayConstants.DEVICE_TYPE); device.setType(DigitalDisplayConstants.DEVICE_TYPE);
enrolmentInfo.setOwner(owner); enrolmentInfo.setOwner(owner);
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); device.setEnrolmentInfo(enrolmentInfo);
boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device); boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device);
if (added) { if (added) {
response.setStatus(Response.Status.OK.getStatusCode()); response.setStatus(Response.Status.OK.getStatusCode());
} else { } else {
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
} }
return added; return added;
@ -97,7 +99,7 @@ public class DigitalDisplayManagerService {
} }
} }
@Path("/device/remove/{device_id}") @Path("manager/device/remove/{device_id}")
@DELETE @DELETE
public void removeDevice(@PathParam("device_id") String deviceId, public void removeDevice(@PathParam("device_id") String deviceId,
@Context HttpServletResponse response) { @Context HttpServletResponse response) {
@ -106,27 +108,22 @@ public class DigitalDisplayManagerService {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
try { try {
boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice( boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(
deviceIdentifier); deviceIdentifier);
if (removed) { if (removed) {
response.setStatus(Response.Status.OK.getStatusCode()); response.setStatus(Response.Status.OK.getStatusCode());
} else { } else {
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} finally { } finally {
deviceManagement.endTenantFlow(); deviceManagement.endTenantFlow();
} }
} }
@Path("/device/update/{device_id}") @Path("manager/device/update/{device_id}")
@POST @POST
public boolean updateDevice(@PathParam("device_id") String deviceId, public boolean updateDevice(@PathParam("device_id") String deviceId,
@QueryParam("name") String name, @QueryParam("name") String name,
@ -137,10 +134,8 @@ public class DigitalDisplayManagerService {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
try { try {
Device device = deviceManagement.getDeviceManagementService().getDevice( Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
deviceIdentifier);
device.setDeviceIdentifier(deviceId); device.setDeviceIdentifier(deviceId);
// device.setDeviceTypeId(deviceTypeId); // device.setDeviceTypeId(deviceTypeId);
@ -149,31 +144,27 @@ public class DigitalDisplayManagerService {
device.setName(name); device.setName(name);
device.setType(DigitalDisplayConstants.DEVICE_TYPE); device.setType(DigitalDisplayConstants.DEVICE_TYPE);
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device);
device);
if (updated) { if (updated) {
response.setStatus(Response.Status.OK.getStatusCode()); response.setStatus(Response.Status.OK.getStatusCode());
} else { } else {
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
} }
return updated; return updated;
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); log.error(e.getErrorMessage());
return false; return false;
} finally { } finally {
deviceManagement.endTenantFlow(); deviceManagement.endTenantFlow();
} }
} }
@Path("/device/{device_id}") @Path("manager/device/{device_id}")
@GET @GET
@Consumes("application/json") @Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json") @Produces(MediaType.APPLICATION_JSON)
public Device getDevice(@PathParam("device_id") String deviceId) { public Device getDevice(@PathParam("device_id") String deviceId) {
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
@ -182,59 +173,77 @@ public class DigitalDisplayManagerService {
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
try { try {
Device device = deviceManagement.getDeviceManagementService().getDevice( return deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier);
deviceIdentifier); } catch (DeviceManagementException ex) {
log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex);
return device;
} catch (DeviceManagementException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return null; return null;
} finally { } finally {
deviceManagement.endTenantFlow(); deviceManagement.endTenantFlow();
} }
} }
@Path("/device/{sketch_type}/download") @Path("manager/device/{sketch_type}/download")
@GET @GET
@Produces("application/octet-stream") @Produces(MediaType.APPLICATION_JSON)
public Response downloadSketch(@QueryParam("owner") String owner, public Response downloadSketch(@QueryParam("owner") String owner,
@QueryParam("deviceName") String deviceName, @QueryParam("deviceName") String deviceName,
@PathParam("sketch_type") String @PathParam("sketch_type") String
sketchType) { 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) { if (owner == null) {
return Response.status(400).build();//bad request throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
} }
//create new device id //create new device id
String deviceId = shortUUID(); String deviceId = shortUUID();
KeyGenerationUtil.createApplicationKeys("digital_display");
TokenClient accessTokenClient = new TokenClient(DigitalDisplayConstants.DEVICE_TYPE);
AccessTokenInfo accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
//create token //create token
String token = UUID.randomUUID().toString(); String accessToken = accessTokenInfo.getAccess_token();
String refreshToken = UUID.randomUUID().toString(); String refreshToken = accessTokenInfo.getRefresh_token();
//adding registering data //adding registering data
boolean status = register(deviceId, deviceName, owner); boolean status;
if (!status) {
return Response.status(500).entity(
"Error occurred while registering the device with " + "id: " + deviceId
+ " owner:" + owner).build();
//Register the device with CDMF
status = register(deviceId, deviceName, owner);
if (!status) {
String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner;
throw new DeviceManagementException(msg);
} }
ZipUtil ziputil = new ZipUtil(); ZipUtil ziputil = new ZipUtil();
ZipArchive zipFile = null; ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken,
try {
zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, token,
refreshToken); refreshToken);
} catch (DeviceManagementException ex) { zipFile.setDeviceId(deviceId);
return Response.status(500).entity("Error occurred while creating zip file").build(); return zipFile;
}
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
return rb.build();
} }
private static String shortUUID() { private static String shortUUID() {

@ -23,7 +23,7 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 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"> http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<jaxrs:server id="DigitalDisplayManager" address="/manager"> <jaxrs:server id="DigitalDisplayManager" address="/">
<jaxrs:serviceBeans> <jaxrs:serviceBeans>
<bean id="DigitalDisplayManagerService" <bean id="DigitalDisplayManagerService"
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.api.DigitalDisplayManagerService"> class="org.wso2.carbon.device.mgt.iot.digitaldisplay.api.DigitalDisplayManagerService">

@ -25,9 +25,7 @@
<description>JAX-WS/JAX-RS MDM Android Endpoint</description> <description>JAX-WS/JAX-RS MDM Android Endpoint</description>
<display-name>JAX-WS/JAX-RS Servlet</display-name> <display-name>JAX-WS/JAX-RS Servlet</display-name>
<servlet-name>CXFServlet</servlet-name> <servlet-name>CXFServlet</servlet-name>
<servlet-class> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>

@ -186,7 +186,7 @@
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Download <li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Download
Arduino-Sketch from Arduino-Sketch from
[Download] link above. [Download Sketch] link above.
</li> </li>
<li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip the <li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip the
downloaded downloaded

@ -182,7 +182,7 @@
RaspberryPi to connect RaspberryPi to connect
to the Internet. to the Internet.
</li> </li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Go ahead and [Download] the <li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Go ahead and [Download Agent] the
Digital Display Agent. Digital Display Agent.
</li> </li>
<li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip downloaded agent. <li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip downloaded agent.

@ -170,7 +170,7 @@
Telemetry Radio receiver. Telemetry Radio receiver.
</li> </li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Click on <li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Click on
[Download] button [Download Agent] button
above to get IRIS+ Drone agent. above to get IRIS+ Drone agent.
</li> </li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Use following <li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Use following

@ -183,7 +183,7 @@
</li> </li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Download <li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Download
RaspberryPi Agent RaspberryPi Agent
via [Download] button above. via [Download Agent] button above.
(Alternatively you can use the (Alternatively you can use the
"curl" command to directly "curl" command to directly
download the Agent to your download the Agent to your

@ -42,7 +42,7 @@
<a href="/api-store/apis/info?name={{@uriParams.deviceType}}&version=1.0.0&provider=admin" class="btn-operations" <a href="/api-store/apis/info?name={{@uriParams.deviceType}}&version=1.0.0&provider=admin" class="btn-operations"
target="_blank"><i class="fw fw-api"></i> View API</i> &nbsp;</a> target="_blank"><i class="fw fw-api"></i> View API</i> &nbsp;</a>
<a href="#" class="download-link btn-operations"><i class="fw fw-download"></i>Download</a> <a href="#" class="download-link btn-operations"><i class="fw fw-download"></i>Download Agent</a>
<div id="download-device-modal-content" class="hide"> <div id="download-device-modal-content" class="hide">
<div class="modal-content"> <div class="modal-content">
@ -167,7 +167,7 @@
<hr> <hr>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Download your VirtualFireAlarm <li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Download your VirtualFireAlarm
using [Download] button above. using [Download Agent] button above.
</li> </li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Unzip the downloaded Agent.</li> <li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Unzip the downloaded Agent.</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Move into the unzipped Agent <li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Move into the unzipped Agent

Loading…
Cancel
Save