Digital display manager changes and UI changes

NuwanSameera 9 years ago
parent 74f8dd9f0c
commit 4bf17c4238

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

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

@ -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">
<jaxrs:server id="DigitalDisplayManager" address="/manager">
<jaxrs:server id="DigitalDisplayManager" address="/">
<jaxrs:serviceBeans>
<bean id="DigitalDisplayManagerService"
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.api.DigitalDisplayManagerService">

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

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

@ -17,21 +17,21 @@
<h3 class="uppercase">What it Does</h3>
<hr>
<p class="grey margin-top">Connect a Digital Message Display to WSO2 IoT Server and manage
it.</p>
it.</p>
<br>
<h3 class="uppercase">What You Need</h3>
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">ITEM 01</span>&nbsp;&nbsp;&nbsp;Raspberry
Pi with SD Card(Internet
Enabled [Wifi or Ethernet]).
Pi with SD Card(Internet
Enabled [Wifi or Ethernet]).
</li>
<li class="padding-top-double"><span class="circle">ITEM 02</span>&nbsp;&nbsp;&nbsp;A Digital Display with HDMI
Cable.
Cable.
</li>
<li class="padding-top-double"><span class="circle">STEP 03</span>&nbsp;&nbsp;&nbsp;Proceed
to [Prepare] section.
to [Prepare] section.
</ul>
<br>
@ -61,7 +61,7 @@
<div class="buttons" style="padding-bottom: 0px">
<a class="btn btn-operations" onclick="downloadAgent()">Download Now</a> &nbsp;&nbsp;
<a href="#" id="download-device-download-link" class="btn btn-operations"> Copy Link </a>
&nbsp;&nbsp;
&nbsp;&nbsp;
</div>
</form>
</div>
@ -176,14 +176,14 @@
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Connect a monitor to your
RaspberryPi via HDMI cable.
RaspberryPi via HDMI cable.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Configure
RaspberryPi to connect
to the Internet.
RaspberryPi to connect
to the Internet.
</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Go ahead and [Download] the
Digital Display Agent.
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Go ahead and [Download Agent] the
Digital Display Agent.
</li>
<li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip downloaded agent.
</li>
@ -210,16 +210,16 @@
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;You can view
all your connected
devices at <a
all your connected
devices at <a
href="{{@app.context}}/devices">[Device
Management]</a>
page.
Management]</a>
page.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Select one of
connected devices and check for
available
control operations.
connected devices and check for
available
control operations.
</ul>
<br/>

@ -18,20 +18,20 @@
<hr>
<p class="grey margin-top">Connect an <a href="https://store.3drobotics.com/products/iris"
target="_blank">[IRIS+]</a> Drone to WSO2 IoT Server
and visualize statistics.</p>
and visualize statistics.</p>
<br>
<h3 class="uppercase">What You Need</h3>
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">ITEM 01</span>&nbsp;&nbsp;&nbsp;IRIS+
Drone.
Drone.
</li>
<li class="padding-top-double"><span class="circle">ITEM 02</span>&nbsp;&nbsp;&nbsp;USB to Micro USB cable or
Telemetry Radio receiver.
Telemetry Radio receiver.
</li>
<li class="padding-top-double"><span class="circle">STEP 03</span>&nbsp;&nbsp;&nbsp;Proceed
to [Prepare]
to [Prepare]
section.
</ul>
<br>
@ -164,17 +164,17 @@
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Connect your
IRIS+ Drone to your computer
using either USB to Micro USB
cable or
Telemetry Radio receiver.
IRIS+ Drone to your computer
using either USB to Micro USB
cable or
Telemetry Radio receiver.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Click on
[Download] button
above to get IRIS+ Drone agent.
[Download Agent] button
above to get IRIS+ Drone agent.
</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Use following
connection properties:
connection properties:
</li>
<div class="padding-top-double">
@ -243,23 +243,23 @@
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;You can view
all your connected
devices at <a
all your connected
devices at <a
href="{{@app.context}}/devices">[Device
Management]</a>
page.
Management]</a>
page.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Select one of
connected devices and check for
available
control operations and monitor
Real-Time data.
connected devices and check for
available
control operations and monitor
Real-Time data.
</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;You can also
view analytics of
the data published to
IoT-Server by navigating
to Device Analytics page.
view analytics of
the data published to
IoT-Server by navigating
to Device Analytics page.
</li>
</ul>
<br/>

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

@ -16,33 +16,33 @@
<h3 class="uppercase">What it Does</h3>
<hr>
<p class="grey margin-top">A Virtual Device that mimics the functionality of a real Firealarm.
Once run, the Virtual Firealarm will connect to WSO2 IoTServer and
push Temperature readings.</p>
Once run, the Virtual Firealarm will connect to WSO2 IoTServer and
push Temperature readings.</p>
<p>The device supports MQTT and XMPP Communications. It is configured to use MQTT by
default.</p>
default.</p>
<br>
<h3 class="uppercase">What You Need</h3>
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">STEP 01</span>&nbsp;&nbsp;&nbsp;Go ahead and [Download] the
Device.
Device.
</li>
<li class="padding-top-double"><span class="circle">STEP 02</span>&nbsp;&nbsp;&nbsp;Proceed
to [Prepare]
section.
to [Prepare]
section.
</li>
<li class="padding-top-double"><span class="circle">STEP 03</span>&nbsp;&nbsp;&nbsp;Read
[Try Out] section
to further experiment with the device.
[Try Out] section
to further experiment with the device.
</li>
</ul>
<br>
<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>
<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 class="modal-content">
@ -167,16 +167,16 @@
<hr>
<ul class="list-unstyled">
<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 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
folder in the terminal.
folder in the terminal.
</li>
<li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip the
downloaded Agent and
start terminal to run this
command: [sh start-device.sh]
downloaded Agent and
start terminal to run this
command: [sh start-device.sh]
</li>
</ul>
<br>
@ -199,23 +199,23 @@
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;You can view
all your connected
devices at <a
all your connected
devices at <a
href="{{@app.context}}/devices">[Device
Management]</a>
page.
Management]</a>
page.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Select one of
connected devices and check for
available
control operations and monitor
Real-Time data.
connected devices and check for
available
control operations and monitor
Real-Time data.
</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;You can also
view analytics of
the data published to
IoT-Server by navigating
to Device Analytics page.
view analytics of
the data published to
IoT-Server by navigating
to Device Analytics page.
</li>
</ul>
<br/>

Loading…
Cancel
Save