forked from community/device-mgt-plugins
Merge pull request #28 from charithag/master
Add NuwanSameera's and menaka's changes
commit
0c61ab4ad4
@ -0,0 +1,233 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>device-mgt-iot-digitaldisplay</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot.digitaldisplay.api</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<name>WSO2 Carbon - IoT Server DigitalDisplay API</name>
|
||||||
|
<description>WSO2 Carbon - Digital Display Service API Implementation</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- CDM -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.analytics</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2-client</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-codec.wso2</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--CXF -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-transports-http</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--MQTT -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
<artifactId>mqtt-client</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--IOT -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpasyncclient</artifactId>
|
||||||
|
<version>4.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot.digitaldisplay</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--JAX-RS -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-core-asl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax</groupId>
|
||||||
|
<artifactId>javaee-web-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-httpclient.wso2</groupId>
|
||||||
|
<artifactId>commons-httpclient</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.queuing</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.base</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||||
|
<artifactId>smack</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||||
|
<artifactId>smackx</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jaxen</groupId>
|
||||||
|
<artifactId>jaxen</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-fileupload.wso2</groupId>
|
||||||
|
<artifactId>commons-fileupload</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.ant.wso2</groupId>
|
||||||
|
<artifactId>ant</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.ant.wso2</groupId>
|
||||||
|
<artifactId>ant</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-httpclient.wso2</groupId>
|
||||||
|
<artifactId>commons-httpclient</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.eclipse.equinox</groupId>
|
||||||
|
<artifactId>javax.servlet</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||||
|
<artifactId>smack</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.igniterealtime.smack.wso2</groupId>
|
||||||
|
<artifactId>smackx</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<source>${wso2.maven.compiler.source}</source>
|
||||||
|
<target>${wso2.maven.compiler.target}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<warName>digital_display</warName>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,505 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.exception.DigitalDisplayException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.CommunicationHandlerException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util.DigitalDisplayMqttCommunicationHandler;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants;
|
||||||
|
|
||||||
|
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.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nuwan on 11/13/15.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DigitalDisplayControllerService {
|
||||||
|
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DigitalDisplayControllerService.class);
|
||||||
|
|
||||||
|
private static DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler;
|
||||||
|
|
||||||
|
public void setDigitalDisplayMqttCommunicationHandler(DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler){
|
||||||
|
DigitalDisplayControllerService.digitalDisplayMqttCommunicationHandler = digitalDisplayMqttCommunicationHandler;
|
||||||
|
|
||||||
|
digitalDisplayMqttCommunicationHandler.connect();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalDisplayMqttCommunicationHandler getDigitalDisplayMqttCommunicationHandler(){
|
||||||
|
return DigitalDisplayControllerService.digitalDisplayMqttCommunicationHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart the running browser in the given digital display.
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
*/
|
||||||
|
@Path("/restart-browser")
|
||||||
|
@POST
|
||||||
|
public void restartBrowser(@QueryParam("deviceId") String deviceId ,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Restrat Browser : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT,"");
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the running browser in the given digital display.
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
*/
|
||||||
|
@Path("/close-browser")
|
||||||
|
@POST
|
||||||
|
public void closeBrowser(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Close Browser : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.CLOSE_BROWSER_CONSTANT ,"");
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminate all running processes. If this execute we have to reboot digital display manually.
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
*/
|
||||||
|
@Path("/terminate-display")
|
||||||
|
@POST
|
||||||
|
public void terminateDisplay(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Terminate Display : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT,"");
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart python server in given digital display
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
*/
|
||||||
|
@Path("/restart-display")
|
||||||
|
@POST
|
||||||
|
public void restartDisplay(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Restrat Display : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT ,"");
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search through the sequence and edit requested resource
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
* @param path page no need to change
|
||||||
|
* @param attribute this can be path,time or type
|
||||||
|
* @param newValue page is used to replace path
|
||||||
|
*/
|
||||||
|
@Path("/edit-content/{path}/{attribute}/{new-value}")
|
||||||
|
@PUT
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public void editContent(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@PathParam("path") String path,
|
||||||
|
@PathParam("attribute") String attribute,
|
||||||
|
@PathParam("new-value") String newValue,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Edit Content Display Id - " + deviceId + " by " + owner);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String params = path + File.separator + attribute + File.separator + newValue;
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT,params);
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new resource end to the existing sequence
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
* @param type type of new resource
|
||||||
|
* @param time new resource visible time
|
||||||
|
* @param path URL of the new resource
|
||||||
|
*/
|
||||||
|
@Path("/add-resource/{type}/{time}/{path}")
|
||||||
|
@POST
|
||||||
|
public void addNewResource(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@PathParam("type") String type,
|
||||||
|
@PathParam("time") String time,
|
||||||
|
@PathParam("path") String path,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Add Sequence : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String params = type + File.separator + time + File.separator + path;
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" +
|
||||||
|
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params);
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new resource to sequence before given page no
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
* @param type type of the new resource
|
||||||
|
* @param time new resource visible time
|
||||||
|
* @param path URL of the new resource
|
||||||
|
* @param nextPage next page no of after adding new resource
|
||||||
|
*/
|
||||||
|
@Path("/add-resource-before/{type}/{time}/{path}/{next-page}")
|
||||||
|
@POST
|
||||||
|
public void addNewResourceBefore(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@PathParam("type") String type,
|
||||||
|
@PathParam("time") String time,
|
||||||
|
@PathParam("path") String path,
|
||||||
|
@PathParam("next-page") String nextPage,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Add Sequence : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String params = type + File.separator + time + File.separator + path +
|
||||||
|
File.separator + "before=" + nextPage;
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" +
|
||||||
|
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params);
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new resource to sequence after given page
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
* @param type type of the new resource
|
||||||
|
* @param time new resource visible time
|
||||||
|
* @param path URL of the new resource
|
||||||
|
* @param beforePage before page no of after adding new resource
|
||||||
|
*/
|
||||||
|
@Path("/add-resource-next/{type}/{time}/{path}/{before-page}")
|
||||||
|
@POST
|
||||||
|
public void addNewResourceAfter(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@PathParam("type") String type,
|
||||||
|
@PathParam("time") String time,
|
||||||
|
@PathParam("path") String path,
|
||||||
|
@PathParam("before-page") String beforePage,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Add Sequence : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String params = type + File.separator + time + File.separator + path +
|
||||||
|
File.separator + "after=" + beforePage;
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" +
|
||||||
|
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params);
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a resource in sequence
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
* @param path path of the page no need to delete
|
||||||
|
*/
|
||||||
|
@Path("/remove-resource/{path}")
|
||||||
|
@DELETE
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public void removeResource(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@PathParam("path") String path,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Remove Resource : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" +
|
||||||
|
DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT,path);
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove directory and whole content
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
* @param directoryName path of the folder need to delete
|
||||||
|
*/
|
||||||
|
@Path("/remove-directory/{directory-name}")
|
||||||
|
@DELETE
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public void removeDirectory(@PathParam("directory-name") String directoryName,
|
||||||
|
@QueryParam("deviceId") String deviceId ,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Remove Directory : " + deviceId);
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" +
|
||||||
|
DigitalDisplayConstants.REMOVE_DIRECTORY_CONSTANT,directoryName);
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove content from www folder
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param directoryName path of directory of request file contain
|
||||||
|
* @param content file name of need to delete
|
||||||
|
* @param response response type of the method
|
||||||
|
*/
|
||||||
|
@Path("/remove-content/{directory_name}/{content}")
|
||||||
|
@DELETE
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public void removeContent(@PathParam("directory_name") String directoryName,
|
||||||
|
@PathParam("content") String content,
|
||||||
|
@QueryParam("deviceId") String deviceId ,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Remove Content : " + deviceId);
|
||||||
|
try {
|
||||||
|
String param = directoryName + File.separator + content;
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.REMOVE_CONTENT_CONSTANT,param);
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop specific display
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
*/
|
||||||
|
@Path("/shutdown-display")
|
||||||
|
@POST
|
||||||
|
public void shutDownDisplay(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Shut down display : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.SHUTDOWN_DISPLAY_CONSTANT,"");
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check specific digital display power ON of OFF
|
||||||
|
*
|
||||||
|
* @param deviceId id of the controlling digital display
|
||||||
|
* @param owner owner of the digital display
|
||||||
|
* @param randomId web socket id of the method invoke client
|
||||||
|
* @param response response type of the method
|
||||||
|
*/
|
||||||
|
@Path("/get-status")
|
||||||
|
@GET
|
||||||
|
public void getStatus(@QueryParam("deviceId") String deviceId,
|
||||||
|
@QueryParam("owner") String owner,
|
||||||
|
@QueryParam("randomId") String randomId,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
|
||||||
|
log.info("Status : " + deviceId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.GET_STATUS_CONSTANT,"");
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
||||||
|
}catch (DigitalDisplayException e){
|
||||||
|
log.error(e);
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message via MQTT protocol
|
||||||
|
*
|
||||||
|
* @param deviceOwner owner of target digital display
|
||||||
|
* @param deviceId id of the target digital display
|
||||||
|
* @param operation operation need to execute
|
||||||
|
* @param param parameters need to given operation
|
||||||
|
* @throws DeviceManagementException
|
||||||
|
* @throws DigitalDisplayException
|
||||||
|
*/
|
||||||
|
private void sendCommandViaMQTT(String deviceOwner, String deviceId, String operation,
|
||||||
|
String param) throws DeviceManagementException, DigitalDisplayException {
|
||||||
|
|
||||||
|
log.info(deviceOwner);
|
||||||
|
String topic = String.format(DigitalDisplayConstants.PUBLISH_TOPIC , deviceOwner , deviceId);
|
||||||
|
String payload = operation + ":" + param;
|
||||||
|
|
||||||
|
try {
|
||||||
|
digitalDisplayMqttCommunicationHandler.publishToDigitalDisplay(topic, payload, 2, true);
|
||||||
|
} catch (CommunicationHandlerException e) {
|
||||||
|
String errorMessage = "Error publishing data to device with ID " + deviceId;
|
||||||
|
throw new DigitalDisplayException(errorMessage,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,241 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
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.digitaldisplay.constants.DigitalDisplayConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
|
||||||
|
|
||||||
|
import javax.jws.WebService;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@WebService
|
||||||
|
public class DigitalDisplayManagerService {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class);
|
||||||
|
//TODO; replace this tenant domain
|
||||||
|
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 ) {
|
||||||
|
|
||||||
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
||||||
|
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
try {
|
||||||
|
if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
|
||||||
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Device device = new Device();
|
||||||
|
device.setDeviceIdentifier(deviceId);
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
|
||||||
|
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
device.setName(name);
|
||||||
|
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
enrolmentInfo.setOwner(owner);
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device);
|
||||||
|
|
||||||
|
if (added) {
|
||||||
|
response.setStatus(Response.Status.OK.getStatusCode());
|
||||||
|
} else {
|
||||||
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return added;
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
deviceManagement.endTenantFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/device/remove/{device_id}")
|
||||||
|
@DELETE
|
||||||
|
public void removeDevice(@PathParam("device_id") String deviceId,
|
||||||
|
@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}")
|
||||||
|
@POST
|
||||||
|
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
||||||
|
@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.setDeviceIdentifier(deviceId);
|
||||||
|
|
||||||
|
// device.setDeviceTypeId(deviceTypeId);
|
||||||
|
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||||
|
|
||||||
|
device.setName(name);
|
||||||
|
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
|
||||||
|
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());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
deviceManagement.endTenantFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/device/{device_id}")
|
||||||
|
@GET
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Device getDevice(@PathParam("device_id") String deviceId) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return device;
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
deviceManagement.endTenantFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/device/{sketch_type}/download")
|
||||||
|
@GET
|
||||||
|
@Produces("application/octet-stream")
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
//create new device id
|
||||||
|
String deviceId = shortUUID();
|
||||||
|
|
||||||
|
//create token
|
||||||
|
String token = UUID.randomUUID().toString();
|
||||||
|
String refreshToken = UUID.randomUUID().toString();
|
||||||
|
//adding registering data
|
||||||
|
|
||||||
|
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
|
||||||
|
+ " owner:" + owner).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipUtil ziputil = new ZipUtil();
|
||||||
|
ZipArchive zipFile = null;
|
||||||
|
try {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
|
||||||
|
rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
|
||||||
|
return rb.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String shortUUID() {
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
|
||||||
|
return Long.toString(l, Character.MAX_RADIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.dto;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
@XmlRootElement
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class DeviceJSON {
|
||||||
|
@XmlElement(required = true) public String owner;
|
||||||
|
@XmlElement(required = true) public String deviceId;
|
||||||
|
@XmlElement(required = true) public String reply;
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nuwan on 12/2/15.
|
||||||
|
*/
|
||||||
|
public class DigitalDisplayException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2736466230451105441L;
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalDisplayException(String msg, DigitalDisplayException nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalDisplayException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalDisplayException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalDisplayException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalDisplayException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport;
|
||||||
|
|
||||||
|
public interface CommunicationHandler<T> {
|
||||||
|
int DEFAULT_TIMEOUT_INTERVAL = 5000; // millis ~ 10 sec
|
||||||
|
|
||||||
|
void connect();
|
||||||
|
|
||||||
|
boolean isConnected();
|
||||||
|
|
||||||
|
void processIncomingMessage(T message, String... messageParams);
|
||||||
|
|
||||||
|
void processIncomingMessage();
|
||||||
|
|
||||||
|
void disconnect();
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport;
|
||||||
|
|
||||||
|
public class CommunicationHandlerException extends Exception {
|
||||||
|
private static final long serialVersionUID = 2736466230451105440L;
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunicationHandlerException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunicationHandlerException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunicationHandlerException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunicationHandlerException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunicationHandlerException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,345 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains the IoT-Server specific implementation for all the MQTT functionality.
|
||||||
|
* This includes connecting to a MQTT Broker & subscribing to the appropriate MQTT-topic, action
|
||||||
|
* plan upon losing connection or successfully delivering a message to the broker and processing
|
||||||
|
* incoming messages. Makes use of the 'Paho-MQTT' library provided by Eclipse Org.
|
||||||
|
* <p/>
|
||||||
|
* It is an abstract class that implements the common interface "CommunicationHandler" and the
|
||||||
|
* "MqttCallback". Whilst providing some methods which handle key MQTT relevant tasks, this class
|
||||||
|
* implements only the most generic methods of the "CommunicationHandler" interface. The rest of
|
||||||
|
* the methods are left for any extended concrete-class to implement as per its need.
|
||||||
|
*/
|
||||||
|
public abstract class MQTTCommunicationHandler
|
||||||
|
implements MqttCallback, CommunicationHandler<MqttMessage> {
|
||||||
|
private static final Log log = LogFactory.getLog(MQTTCommunicationHandler.class);
|
||||||
|
|
||||||
|
public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0;
|
||||||
|
|
||||||
|
private MqttClient client;
|
||||||
|
private String clientId;
|
||||||
|
private MqttConnectOptions options;
|
||||||
|
private String clientWillTopic;
|
||||||
|
|
||||||
|
protected String mqttBrokerEndPoint;
|
||||||
|
protected int timeoutInterval;
|
||||||
|
protected String subscribeTopic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the MQTTCommunicationHandler which takes in the owner, type of the device
|
||||||
|
* and the MQTT Broker URL and the topic to subscribe.
|
||||||
|
*
|
||||||
|
* @param deviceOwner the owner of the device.
|
||||||
|
* @param deviceType the CDMF Device-Type of the device.
|
||||||
|
* @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint.
|
||||||
|
* @param subscribeTopic the MQTT topic to which the client is to be subscribed
|
||||||
|
*/
|
||||||
|
protected MQTTCommunicationHandler(String deviceOwner, String deviceType,
|
||||||
|
String mqttBrokerEndPoint,
|
||||||
|
String subscribeTopic) {
|
||||||
|
this.clientId = deviceOwner + ":" + deviceType;
|
||||||
|
this.subscribeTopic = subscribeTopic;
|
||||||
|
this.clientWillTopic = deviceType + File.separator + "disconnection";
|
||||||
|
this.mqttBrokerEndPoint = mqttBrokerEndPoint;
|
||||||
|
this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
this.initSubscriber();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the MQTTCommunicationHandler which takes in the owner, type of the device
|
||||||
|
* and the MQTT Broker URL and the topic to subscribe. Additionally this constructor takes in
|
||||||
|
* the reconnection-time interval between successive attempts to connect to the broker.
|
||||||
|
*
|
||||||
|
* @param deviceOwner the owner of the device.
|
||||||
|
* @param deviceType the CDMF Device-Type of the device.
|
||||||
|
* @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint.
|
||||||
|
* @param subscribeTopic the MQTT topic to which the client is to be subscribed
|
||||||
|
* @param intervalInMillis the time interval in MILLI-SECONDS between successive
|
||||||
|
* attempts to connect to the broker.
|
||||||
|
*/
|
||||||
|
protected MQTTCommunicationHandler(String deviceOwner, String deviceType,
|
||||||
|
String mqttBrokerEndPoint, String subscribeTopic,
|
||||||
|
int intervalInMillis) {
|
||||||
|
this.clientId = deviceOwner + ":" + deviceType;
|
||||||
|
this.subscribeTopic = subscribeTopic;
|
||||||
|
this.clientWillTopic = deviceType + File.separator + "disconnection";
|
||||||
|
this.mqttBrokerEndPoint = mqttBrokerEndPoint;
|
||||||
|
this.timeoutInterval = intervalInMillis;
|
||||||
|
this.initSubscriber();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeoutInterval(int timeoutInterval) {
|
||||||
|
this.timeoutInterval = timeoutInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the MQTT-Client. Creates a client using the given MQTT-broker endpoint and the
|
||||||
|
* clientId (which is constructed by a concatenation of [deviceOwner]:[deviceType]). Also sets
|
||||||
|
* the client's options parameter with the clientWillTopic (in-case of connection failure) and
|
||||||
|
* other info. Also sets the call-back this current class.
|
||||||
|
*/
|
||||||
|
private void initSubscriber() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
client = new MqttClient(this.mqttBrokerEndPoint, clientId, null);
|
||||||
|
log.info("MQTT subscriber was created with ClientID : " + clientId);
|
||||||
|
} catch (MqttException ex) {
|
||||||
|
String errorMsg = "MQTT Client Error\n" + "\tReason: " + ex.getReasonCode() +
|
||||||
|
"\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " +
|
||||||
|
ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() +
|
||||||
|
"\n\tException: " + ex;
|
||||||
|
log.error(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
options = new MqttConnectOptions();
|
||||||
|
options.setCleanSession(false);
|
||||||
|
options.setWill(clientWillTopic, "Connection-Lost".getBytes(StandardCharsets.UTF_8), 2,
|
||||||
|
true);
|
||||||
|
client.setCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the connection to the MQTT-Broker persists.
|
||||||
|
*
|
||||||
|
* @return true if the client is connected to the MQTT-Broker, else false.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isConnected() {
|
||||||
|
return client.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connects to the MQTT-Broker and if successfully established connection.
|
||||||
|
*
|
||||||
|
* @throws CommunicationHandlerException in the event of 'Connecting to' the MQTT broker fails.
|
||||||
|
*/
|
||||||
|
protected void connectToQueue() throws CommunicationHandlerException {
|
||||||
|
try {
|
||||||
|
client.connect(options);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Subscriber connected to queue at: " + this.mqttBrokerEndPoint);
|
||||||
|
}
|
||||||
|
} catch (MqttSecurityException ex) {
|
||||||
|
String errorMsg = "MQTT Security Exception when connecting to queue\n" + "\tReason: " +
|
||||||
|
" " +
|
||||||
|
ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() +
|
||||||
|
"\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " +
|
||||||
|
ex.getCause() + "\n\tException: " + ex;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(errorMsg);
|
||||||
|
}
|
||||||
|
throw new CommunicationHandlerException(errorMsg, ex);
|
||||||
|
|
||||||
|
} catch (MqttException ex) {
|
||||||
|
String errorMsg = "MQTT Exception when connecting to queue\n" + "\tReason: " +
|
||||||
|
ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() +
|
||||||
|
"\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " +
|
||||||
|
ex.getCause() + "\n\tException: " + ex;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(errorMsg);
|
||||||
|
}
|
||||||
|
throw new CommunicationHandlerException(errorMsg, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribes to the MQTT-Topic specific to this MQTT Client. (The MQTT-Topic specific to the
|
||||||
|
* device is taken in as a constructor parameter of this class) .
|
||||||
|
*
|
||||||
|
* @throws CommunicationHandlerException in the event of 'Subscribing to' the MQTT broker
|
||||||
|
* fails.
|
||||||
|
*/
|
||||||
|
protected void subscribeToQueue() throws CommunicationHandlerException {
|
||||||
|
try {
|
||||||
|
client.subscribe(subscribeTopic, 0);
|
||||||
|
log.info("Subscriber '" + clientId + "' subscribed to topic: " + subscribeTopic);
|
||||||
|
} catch (MqttException ex) {
|
||||||
|
String errorMsg = "MQTT Exception when trying to subscribe to topic: " +
|
||||||
|
subscribeTopic + "\n\tReason: " + ex.getReasonCode() +
|
||||||
|
"\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " +
|
||||||
|
ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() +
|
||||||
|
"\n\tException: " + ex;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new CommunicationHandlerException(errorMsg, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to publish reply-messages for the control signals received.
|
||||||
|
* Invocation of this method calls its overloaded-method with a QoS equal to that of the
|
||||||
|
* default value.
|
||||||
|
*
|
||||||
|
* @param topic the topic to which the reply message is to be published.
|
||||||
|
* @param payLoad the reply-message (payload) of the MQTT publish action.
|
||||||
|
*/
|
||||||
|
protected void publishToQueue(String topic, String payLoad)
|
||||||
|
throws CommunicationHandlerException {
|
||||||
|
publishToQueue(topic, payLoad, DEFAULT_MQTT_QUALITY_OF_SERVICE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an overloaded method that publishes MQTT reply-messages for control signals
|
||||||
|
* received form the IoT-Server.
|
||||||
|
*
|
||||||
|
* @param topic the topic to which the reply message is to be published
|
||||||
|
* @param payLoad the reply-message (payload) of the MQTT publish action.
|
||||||
|
* @param qos the Quality-of-Service of the current publish action.
|
||||||
|
* Could be 0(At-most once), 1(At-least once) or 2(Exactly once)
|
||||||
|
*/
|
||||||
|
protected void publishToQueue(String topic, String payLoad, int qos, boolean retained)
|
||||||
|
throws CommunicationHandlerException {
|
||||||
|
try {
|
||||||
|
client.publish(topic, payLoad.getBytes(StandardCharsets.UTF_8), qos, retained);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Message: " + payLoad + " to MQTT topic [" + topic +
|
||||||
|
"] published successfully");
|
||||||
|
}
|
||||||
|
} catch (MqttException ex) {
|
||||||
|
String errorMsg =
|
||||||
|
"MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " +
|
||||||
|
ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() +
|
||||||
|
"\n\tCause: " + ex.getCause() + "\n\tException: " + ex;
|
||||||
|
log.info(ex);
|
||||||
|
throw new CommunicationHandlerException(errorMsg, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void publishToQueue(String topic, MqttMessage message)
|
||||||
|
throws CommunicationHandlerException {
|
||||||
|
try {
|
||||||
|
client.publish(topic, message);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Message: " + message.toString() + " to MQTT topic [" + topic +
|
||||||
|
"] published successfully");
|
||||||
|
}
|
||||||
|
} catch (MqttException ex) {
|
||||||
|
String errorMsg =
|
||||||
|
"MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " +
|
||||||
|
ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() +
|
||||||
|
"\n\tCause: " + ex.getCause() + "\n\tException: " + ex;
|
||||||
|
log.info(errorMsg);
|
||||||
|
throw new CommunicationHandlerException(errorMsg, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback method which is triggered once the MQTT client losers its connection to the broker.
|
||||||
|
* Spawns a new thread that executes necessary actions to try and reconnect to the endpoint.
|
||||||
|
*
|
||||||
|
* @param throwable a Throwable Object containing the details as to why the failure occurred.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void connectionLost(Throwable throwable) {
|
||||||
|
log.warn("Lost Connection for client: " + this.clientId +
|
||||||
|
" to " + this.mqttBrokerEndPoint + ".\nThis was due to - " +
|
||||||
|
throwable.getMessage());
|
||||||
|
|
||||||
|
|
||||||
|
Thread reconnectThread = new Thread() {
|
||||||
|
public void run() {
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reconnectThread.setDaemon(true);
|
||||||
|
reconnectThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback method which is triggered upon receiving a MQTT Message from the broker. Spawns a
|
||||||
|
* new thread that executes any actions to be taken with the received message.
|
||||||
|
*
|
||||||
|
* @param topic the MQTT-Topic to which the received message was published to and the
|
||||||
|
* client was subscribed to.
|
||||||
|
* @param mqttMessage the actual MQTT-Message that was received from the broker.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void messageArrived(final String topic, final MqttMessage mqttMessage) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.info("Got an MQTT message '" + mqttMessage.toString() + "' for topic '" + topic +
|
||||||
|
"'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread messageProcessorThread = new Thread() {
|
||||||
|
public void run() {
|
||||||
|
processIncomingMessage(mqttMessage, topic);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
messageProcessorThread.setDaemon(true);
|
||||||
|
messageProcessorThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback method which gets triggered upon successful completion of a message delivery to
|
||||||
|
* the broker.
|
||||||
|
*
|
||||||
|
* @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the
|
||||||
|
* specific message delivery.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||||
|
String message = "";
|
||||||
|
try {
|
||||||
|
if (iMqttDeliveryToken.isComplete()) {
|
||||||
|
if (iMqttDeliveryToken.getMessage() != null){
|
||||||
|
message = iMqttDeliveryToken.getMessage().toString();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("MQTT Message not delivered");
|
||||||
|
}
|
||||||
|
} catch (MqttException e) {
|
||||||
|
log.error(
|
||||||
|
"Error occurred whilst trying to read the message from the MQTT delivery token.");
|
||||||
|
}
|
||||||
|
String topic = iMqttDeliveryToken.getTopics()[0];
|
||||||
|
String client = iMqttDeliveryToken.getClient().getClientId();
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Message - '" + message + "' of client [" + client + "] for the topic (" +
|
||||||
|
topic + ") was delivered successfully.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the connection to the MQTT Broker.
|
||||||
|
*/
|
||||||
|
public void closeConnection() throws MqttException {
|
||||||
|
if (client != null && isConnected()) {
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,145 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.CommunicationHandlerException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.MQTTCommunicationHandler;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.websocket.DigitalDisplayWebSocketServerEndPoint;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nuwan on 11/16/15.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DigitalDisplayMqttCommunicationHandler extends MQTTCommunicationHandler {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DigitalDisplayMqttCommunicationHandler.class);
|
||||||
|
|
||||||
|
private static final String subscribeTopic =
|
||||||
|
"wso2"+ File.separator+"iot"+File.separator+"+"+File.separator+
|
||||||
|
DigitalDisplayConstants.DEVICE_TYPE+File.separator+"+"+File.separator+
|
||||||
|
"digital_display_publisher";
|
||||||
|
|
||||||
|
private static String iotServerSubscriber = UUID.randomUUID().toString().substring(0,5);
|
||||||
|
|
||||||
|
private ScheduledFuture<?> dataPushServiceHandler;
|
||||||
|
|
||||||
|
private DigitalDisplayMqttCommunicationHandler() {
|
||||||
|
super(iotServerSubscriber, DigitalDisplayConstants.DEVICE_TYPE,
|
||||||
|
MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScheduledFuture<?> getDataPushServiceHandler() {
|
||||||
|
return dataPushServiceHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect() {
|
||||||
|
Runnable connect = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (!isConnected()){
|
||||||
|
try {
|
||||||
|
log.info("Trying to Connect..");
|
||||||
|
connectToQueue();
|
||||||
|
subscribeToQueue();
|
||||||
|
|
||||||
|
} catch (CommunicationHandlerException e) {
|
||||||
|
log.warn("Connection/Subscription to MQTT Broker at: " +
|
||||||
|
mqttBrokerEndPoint + " failed");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(timeoutInterval);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
log.error("MQTT-Subscriber: Thread Sleep Interrupt Exception");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Connected..");
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Thread connectorThread = new Thread(connect);
|
||||||
|
connectorThread.setDaemon(true);
|
||||||
|
connectorThread.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processIncomingMessage(MqttMessage message, String... messageParams) {
|
||||||
|
|
||||||
|
String topic = messageParams[0];
|
||||||
|
|
||||||
|
String ownerAndId = topic.replace("wso2"+File.separator+"iot"+File.separator,"");
|
||||||
|
ownerAndId = ownerAndId.replace(File.separator+ DigitalDisplayConstants.DEVICE_TYPE+File.separator,":");
|
||||||
|
ownerAndId = ownerAndId.replace(File.separator+"digital_display_publisher","");
|
||||||
|
|
||||||
|
String owner = ownerAndId.split(":")[0];
|
||||||
|
String deviceId = ownerAndId.split(":")[1];
|
||||||
|
|
||||||
|
String [] messageData = message.toString().split(":");
|
||||||
|
|
||||||
|
|
||||||
|
log.info("Received MQTT message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}");
|
||||||
|
|
||||||
|
if(messageData.length == 3){
|
||||||
|
String randomId = messageData[0];
|
||||||
|
String requestMessage = messageData[1];
|
||||||
|
String result = messageData[2];
|
||||||
|
log.info("Return result " + result + " for Request " + requestMessage);
|
||||||
|
DigitalDisplayWebSocketServerEndPoint.sendMessage(randomId, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processIncomingMessage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void publishToDigitalDisplay(String topic, String payLoad, int qos, boolean retained) throws CommunicationHandlerException {
|
||||||
|
log.info(topic + " " + payLoad);
|
||||||
|
publishToQueue(topic, payLoad, qos, retained);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect() {
|
||||||
|
Runnable stopConnection = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
while (isConnected()) {
|
||||||
|
try {
|
||||||
|
dataPushServiceHandler.cancel(true);
|
||||||
|
closeConnection();
|
||||||
|
|
||||||
|
} catch (MqttException e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.warn("Unable to 'STOP' MQTT connection at broker at: " +
|
||||||
|
mqttBrokerEndPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(timeoutInterval);
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
log.error("MQTT-Terminator: Thread Sleep Interrupt Exception");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Thread terminatorThread = new Thread(stopConnection);
|
||||||
|
terminatorThread.setDaemon(true);
|
||||||
|
terminatorThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.websocket;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.websocket.OnClose;
|
||||||
|
import javax.websocket.OnError;
|
||||||
|
import javax.websocket.OnOpen;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
|
@ServerEndpoint(value = "/digital-display-server-end-point")
|
||||||
|
@Singleton
|
||||||
|
public class DigitalDisplayWebSocketServerEndPoint {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DigitalDisplayWebSocketServerEndPoint.class);
|
||||||
|
|
||||||
|
private static Map<String,Session> clientSessions = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be invoked when a client requests for a
|
||||||
|
* WebSocket connection.
|
||||||
|
*
|
||||||
|
* @param userSession the userSession which is opened.
|
||||||
|
*/
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(Session userSession){
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
log.info("Generated Random Id " + uuid.toString());
|
||||||
|
log.info(" Connected with Session Id : " + userSession.getId());
|
||||||
|
clientSessions.put(uuid.toString() , userSession);
|
||||||
|
userSession.getAsyncRemote().sendText("RandomID:" + uuid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be invoked when a client closes a WebSocket
|
||||||
|
* connection.
|
||||||
|
*
|
||||||
|
* @param userSession the userSession which is opened.
|
||||||
|
*/
|
||||||
|
@OnClose
|
||||||
|
public void onClose(Session userSession){
|
||||||
|
log.info("Client disconnected - Session Id : " + userSession.getId());
|
||||||
|
clientSessions.values().remove(userSession);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnError
|
||||||
|
public void onError(Throwable t){
|
||||||
|
log.error("Error occurred " + t );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be invoked when a message received from device
|
||||||
|
* to send client.
|
||||||
|
*
|
||||||
|
* @param randomId the client of message to be sent.
|
||||||
|
* @param message the message sent by device to client
|
||||||
|
*/
|
||||||
|
public static void sendMessage(String randomId , String message){
|
||||||
|
if(clientSessions.keySet().contains(randomId)){
|
||||||
|
clientSessions.get(randomId).getAsyncRemote().sendText(message);
|
||||||
|
log.info("Message : " + message + " send to Session Id : " + randomId);
|
||||||
|
}else {
|
||||||
|
log.error("Client already disconnected.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright 2005-2013 WSO2, Inc. (http://wso2.com)
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
|
||||||
|
-->
|
||||||
|
<Classloading xmlns="http://wso2.org/projects/as/classloading">
|
||||||
|
|
||||||
|
<!-- Parent-first or child-first. Default behaviour is child-first.-->
|
||||||
|
<ParentFirst>false</ParentFirst>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
|
||||||
|
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
|
||||||
|
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
|
||||||
|
-->
|
||||||
|
<Environments>CXF,Carbon</Environments>
|
||||||
|
</Classloading>
|
@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright 2011-2012 WSO2, Inc. (http://wso2.com)
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
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="DigitalDisplayController" address="/controller">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<bean id="DigitalDisplayManagerControllerService"
|
||||||
|
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.api.DigitalDisplayControllerService">
|
||||||
|
<property name="digitalDisplayMqttCommunicationHandler" ref="communicationHandler"/>
|
||||||
|
</bean>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
|
||||||
|
<jaxrs:server id="DigitalDisplayManager" address="/manager">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<bean id="DigitalDisplayManagerService"
|
||||||
|
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.api.DigitalDisplayManagerService">
|
||||||
|
</bean>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
|
|
||||||
|
<bean
|
||||||
|
id="communicationHandler"
|
||||||
|
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util.DigitalDisplayMqttCommunicationHandler" >
|
||||||
|
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
</beans>
|
||||||
|
|
@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
|
~ in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<display-name>Digital-Display-Agent-Webapp</display-name>
|
||||||
|
<servlet>
|
||||||
|
<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>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
</web-app>
|
@ -0,0 +1,108 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>device-mgt-iot-digitaldisplay</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot.digitaldisplay</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - IoT Server DigitalDisplay Management Plugin</name>
|
||||||
|
<description>WSO2 Carbon - Digital Display Management/Control Plugin Implementation</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.7</source>
|
||||||
|
<target>1.7</target>
|
||||||
|
</configuration>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>1.4.0</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.iot.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>IoT Server Impl Bundle</Bundle-Description>
|
||||||
|
<Private-Package>org.wso2.carbon.device.mgt.iot.digitaldisplay.internal</Private-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.osgi.framework,
|
||||||
|
org.osgi.service.component,
|
||||||
|
org.apache.commons.logging,
|
||||||
|
javax.xml.bind.*,
|
||||||
|
javax.naming,
|
||||||
|
javax.sql,
|
||||||
|
javax.xml.bind.annotation.*,
|
||||||
|
javax.xml.parsers,
|
||||||
|
javax.net,
|
||||||
|
javax.net.ssl,
|
||||||
|
org.w3c.dom,
|
||||||
|
org.wso2.carbon.device.mgt.common.*,
|
||||||
|
org.wso2.carbon.device.mgt.common,
|
||||||
|
org.wso2.carbon.context.*,
|
||||||
|
org.wso2.carbon.ndatasource.core,
|
||||||
|
org.wso2.carbon.device.mgt.iot.*,
|
||||||
|
</Import-Package>
|
||||||
|
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.device.mgt.iot.digitaldisplay.internal,
|
||||||
|
org.wso2.carbon.device.mgt.iot.digitaldisplay.*
|
||||||
|
</Export-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.osgi</groupId>
|
||||||
|
<artifactId>org.eclipse.osgi</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.osgi</groupId>
|
||||||
|
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.constants;
|
||||||
|
|
||||||
|
public class DigitalDisplayConstants {
|
||||||
|
|
||||||
|
public final static String DEVICE_TYPE = "digital_display";
|
||||||
|
public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME";
|
||||||
|
public final static String DEVICE_PLUGIN_DEVICE_ID = "DIGITAL_DISPLAY_DEVICE_ID";
|
||||||
|
|
||||||
|
public final static String MQTT_BROKER_END_POINT = "tcp://204.232.188.214:1883";
|
||||||
|
|
||||||
|
public final static String SHUTDOWN_DISPLAY_CONSTANT = "shutdown_display";
|
||||||
|
public final static String RESTART_DISPLAY_CONSTANT = "restart_display";
|
||||||
|
public final static String REMOVE_DIRECTORY_CONSTANT = "remove_dir_and_content";
|
||||||
|
public final static String REMOVE_CONTENT_CONSTANT = "remove_content";
|
||||||
|
public final static String CLOSE_BROWSER_CONSTANT = "close_browser";
|
||||||
|
public final static String RESTART_BROWSER_CONSTANT = "restart_browser";
|
||||||
|
public final static String TERMINATE_DISPLAY_CONSTANT = "terminate_display";
|
||||||
|
public final static String EDIT_SEQUENCE_CONSTANT = "edit_content_config";
|
||||||
|
public final static String ADD_NEW_RESOURCE_CONSTANT = "add_new_resource";
|
||||||
|
public final static String REMOVE_RESOURCE_CONSTANT = "remove_resources";
|
||||||
|
public final static String GET_STATUS_CONSTANT = "get_status";
|
||||||
|
|
||||||
|
public final static String PUBLISH_TOPIC = "wso2/iot/%s/digital_display/%s/digital_display_subscriber";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,277 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.*;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.DigitalDisplayDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactoryInterface;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This represents the DigitalDisplay implementation of DeviceManagerService.
|
||||||
|
*/
|
||||||
|
public class DigitalDisplayManager implements DeviceManager {
|
||||||
|
|
||||||
|
private static final IotDeviceManagementDAOFactoryInterface iotDeviceManagementDAOFactory = new DigitalDisplayDAO();
|
||||||
|
private static final Log log = LogFactory.getLog(DigitalDisplayManager.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureManager getFeatureManager() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
//TODO implement this
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||||
|
//TODO implement this
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device);
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Enrolling a new DigitalDisplay device : " + device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
|
DigitalDisplayDAO.beginTransaction();
|
||||||
|
status = iotDeviceManagementDAOFactory.getIotDeviceDAO().addIotDevice(
|
||||||
|
iotDevice);
|
||||||
|
DigitalDisplayDAO.commitTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
DigitalDisplayDAO.rollbackTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException iotDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
||||||
|
log.warn(msg, iotDAOEx);
|
||||||
|
}
|
||||||
|
String msg = "Error while enrolling the DigitalDisplay device : " + device.getDeviceIdentifier();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device);
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Modifying the DigitalDisplay device enrollment data");
|
||||||
|
}
|
||||||
|
DigitalDisplayDAO.beginTransaction();
|
||||||
|
status = iotDeviceManagementDAOFactory.getIotDeviceDAO()
|
||||||
|
.updateIotDevice(iotDevice);
|
||||||
|
DigitalDisplayDAO.commitTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
DigitalDisplayDAO.rollbackTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException iotDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
|
||||||
|
log.warn(msg, iotDAOEx);
|
||||||
|
}
|
||||||
|
String msg = "Error while updating the enrollment of the DigitalDisplay device : " +
|
||||||
|
device.getDeviceIdentifier();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Dis-enrolling DigitalDisplay device : " + deviceId);
|
||||||
|
}
|
||||||
|
DigitalDisplayDAO.beginTransaction();
|
||||||
|
status = iotDeviceManagementDAOFactory.getIotDeviceDAO()
|
||||||
|
.deleteIotDevice(deviceId.getId());
|
||||||
|
DigitalDisplayDAO.commitTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
DigitalDisplayDAO.rollbackTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException iotDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
|
||||||
|
log.warn(msg, iotDAOEx);
|
||||||
|
}
|
||||||
|
String msg = "Error while removing the DigitalDisplay device : " + deviceId.getId();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
boolean isEnrolled = false;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Checking the enrollment of DigitalDisplay device : " + deviceId.getId());
|
||||||
|
}
|
||||||
|
IotDevice iotDevice =
|
||||||
|
iotDeviceManagementDAOFactory.getIotDeviceDAO().getIotDevice(
|
||||||
|
deviceId.getId());
|
||||||
|
if (iotDevice != null) {
|
||||||
|
isEnrolled = true;
|
||||||
|
}
|
||||||
|
} catch (IotDeviceManagementDAOException e) {
|
||||||
|
String msg = "Error while checking the enrollment status of DigitalDisplay device : " +
|
||||||
|
deviceId.getId();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return isEnrolled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
Device device;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the details of DigitalDisplay device : " + deviceId.getId());
|
||||||
|
}
|
||||||
|
IotDevice iotDevice = iotDeviceManagementDAOFactory.getIotDeviceDAO().
|
||||||
|
getIotDevice(deviceId.getId());
|
||||||
|
device = IotDeviceManagementUtil.convertToDevice(iotDevice);
|
||||||
|
} catch (IotDeviceManagementDAOException e) {
|
||||||
|
String msg = "Error while fetching the DigitalDisplay device : " + deviceId.getId();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
||||||
|
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public License getLicense(String s) throws LicenseManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addLicense(License license) throws LicenseManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requireDeviceAuthorization() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device);
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(
|
||||||
|
"updating the details of DigitalDisplay device : " + deviceIdentifier);
|
||||||
|
}
|
||||||
|
DigitalDisplayDAO.beginTransaction();
|
||||||
|
status = iotDeviceManagementDAOFactory.getIotDeviceDAO()
|
||||||
|
.updateIotDevice(iotDevice);
|
||||||
|
DigitalDisplayDAO.commitTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
DigitalDisplayDAO.rollbackTransaction();
|
||||||
|
} catch (IotDeviceManagementDAOException iotDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
|
||||||
|
log.warn(msg, iotDAOEx);
|
||||||
|
}
|
||||||
|
String msg =
|
||||||
|
"Error while updating the DigitalDisplay device : " + deviceIdentifier;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||||
|
List<Device> devices = null;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetching the details of all DigitalDisplay devices");
|
||||||
|
}
|
||||||
|
List<IotDevice> iotDevices =
|
||||||
|
iotDeviceManagementDAOFactory.getIotDeviceDAO().getAllIotDevices();
|
||||||
|
if (iotDevices != null) {
|
||||||
|
devices = new ArrayList<Device>();
|
||||||
|
for (IotDevice iotDevice : iotDevices) {
|
||||||
|
devices.add(IotDeviceManagementUtil.convertToDevice(iotDevice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IotDeviceManagementDAOException e) {
|
||||||
|
String msg = "Error while fetching all DigitalDisplay devices.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DigitalDisplayManagerService implements DeviceManagementService{
|
||||||
|
private DeviceManager deviceManager;
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return DigitalDisplayConstants.DEVICE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProviderTenantDomain() {
|
||||||
|
return "carbon.super";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSharedWithAllTenants() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getSharedTenantsDomain() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws DeviceManagementException {
|
||||||
|
deviceManager= new DigitalDisplayManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceManager getDeviceManager() {
|
||||||
|
return deviceManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApplicationManager getApplicationManager() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyOperationToDevices(Operation operation, List<DeviceIdentifier> list) throws DeviceManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Application[] getApplications(String domain, int pageNumber, int size)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
return new Application[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
|
||||||
|
String status) throws ApplicationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getApplicationStatus(DeviceIdentifier deviceId, Application application)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> list) throws ApplicationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installApplicationForUsers(Operation operation, List<String> list) throws ApplicationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installApplicationForUserRoles(Operation operation, List<String> list) throws ApplicationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactoryInterface;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.impl.DigitalDisplayDeviceDAOImpl;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DigitalDisplayDAO extends IotDeviceManagementDAOFactory
|
||||||
|
implements IotDeviceManagementDAOFactoryInterface {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DigitalDisplayDAO.class);
|
||||||
|
static DataSource dataSource; // package local variable
|
||||||
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
|
|
||||||
|
public DigitalDisplayDAO() {
|
||||||
|
initDigitalDisplayDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IotDeviceDAO getIotDeviceDAO() {
|
||||||
|
return new DigitalDisplayDeviceDAOImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initDigitalDisplayDAO(){
|
||||||
|
dataSource = getDataSourceMap().get(DigitalDisplayConstants.DEVICE_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void beginTransaction() throws IotDeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = dataSource.getConnection();
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
currentConnection.set(conn);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new IotDeviceManagementDAOException("Error occurred while retrieving datasource connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection() throws IotDeviceManagementDAOException {
|
||||||
|
if (currentConnection.get() == null) {
|
||||||
|
try {
|
||||||
|
currentConnection.set(dataSource.getConnection());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new IotDeviceManagementDAOException("Error occurred while retrieving data source connection",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentConnection.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commitTransaction() throws IotDeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.commit();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
||||||
|
"has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new IotDeviceManagementDAOException("Error occurred while committing the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void closeConnection() throws IotDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection con = currentConnection.get();
|
||||||
|
if(con != null){
|
||||||
|
try {
|
||||||
|
con.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while close the connection");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentConnection.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void rollbackTransaction() throws IotDeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.rollback();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
|
||||||
|
"has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new IotDeviceManagementDAOException("Error occurred while rollback the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,238 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.DigitalDisplayDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.util.IotDeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements IotDeviceDAO for digital display Devices.
|
||||||
|
*/
|
||||||
|
public class DigitalDisplayDeviceDAOImpl implements IotDeviceDAO {
|
||||||
|
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DigitalDisplayDeviceDAOImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IotDevice getIotDevice(String iotDeviceId)
|
||||||
|
throws IotDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
IotDevice iotDevice = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
conn = DigitalDisplayDAO.getConnection();
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME" +
|
||||||
|
" FROM DIGITAL_DISPLAY_DEVICE WHERE DIGITAL_DISPLAY_DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
|
stmt.setString(1, iotDeviceId);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
|
if (resultSet.next()) {
|
||||||
|
iotDevice = new IotDevice();
|
||||||
|
iotDevice.setIotDeviceName(resultSet.getString(
|
||||||
|
DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
||||||
|
Map<String, String> propertyMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
iotDevice.setDeviceProperties(propertyMap);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Digital Display device " + iotDeviceId + " data has been fetched from " +
|
||||||
|
"Digital Display database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while fetching Digital Display device : '" + iotDeviceId + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new IotDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
|
DigitalDisplayDAO.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return iotDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addIotDevice(IotDevice iotDevice)
|
||||||
|
throws IotDeviceManagementDAOException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = DigitalDisplayDAO.getConnection();
|
||||||
|
String createDBQuery =
|
||||||
|
"INSERT INTO DIGITAL_DISPLAY_DEVICE(DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
|
stmt.setString(1, iotDevice.getIotDeviceId());
|
||||||
|
stmt.setString(2,iotDevice.getIotDeviceName());
|
||||||
|
if (iotDevice.getDeviceProperties() == null) {
|
||||||
|
iotDevice.setDeviceProperties(new HashMap<String, String>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Digital Display device " + iotDevice.getIotDeviceId() + " data has been" +
|
||||||
|
" added to the Digital Display database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while adding the Digital Display device '" +
|
||||||
|
iotDevice.getIotDeviceId() + "' to the Digital Display db.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new IotDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
IotDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateIotDevice(IotDevice iotDevice)
|
||||||
|
throws IotDeviceManagementDAOException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = DigitalDisplayDAO.getConnection();
|
||||||
|
String updateDBQuery =
|
||||||
|
"UPDATE DIGITAL_DISPLAY_DEVICE SET DEVICE_NAME = ? WHERE DIGITAL_DISPLAY_DEVICE_ID = ?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
|
|
||||||
|
if (iotDevice.getDeviceProperties() == null) {
|
||||||
|
iotDevice.setDeviceProperties(new HashMap<String, String>());
|
||||||
|
}
|
||||||
|
stmt.setString(1, iotDevice.getIotDeviceName());
|
||||||
|
|
||||||
|
stmt.setString(2, iotDevice.getIotDeviceId());
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Digital Display device " + iotDevice.getIotDeviceId() + " data has been" +
|
||||||
|
" modified.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while modifying the Digital Display device '" +
|
||||||
|
iotDevice.getIotDeviceId() + "' data.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new IotDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
IotDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteIotDevice(String iotDeviceId)
|
||||||
|
throws IotDeviceManagementDAOException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = DigitalDisplayDAO.getConnection();
|
||||||
|
String deleteDBQuery =
|
||||||
|
"DELETE FROM DIGITAL_DISPLAY_DEVICE WHERE DIGITAL_DISPLAY_DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
|
stmt.setString(1, iotDeviceId);
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Digital Display device " + iotDeviceId + " data has deleted" +
|
||||||
|
" from the Digital Display database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while deleting Digital Display device " + iotDeviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new IotDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
IotDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IotDevice> getAllIotDevices()
|
||||||
|
throws IotDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
IotDevice iotDevice;
|
||||||
|
List<IotDevice> iotDevices = new ArrayList<IotDevice>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = DigitalDisplayDAO.getConnection();
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME " +
|
||||||
|
"FROM DIGITAL_DISPLAY_DEVICE";
|
||||||
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
iotDevice = new IotDevice();
|
||||||
|
iotDevice.setIotDeviceId(resultSet.getString(DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_ID));
|
||||||
|
iotDevice.setIotDeviceName(resultSet.getString(DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
||||||
|
|
||||||
|
Map<String, String> propertyMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
iotDevice.setDeviceProperties(propertyMap);
|
||||||
|
iotDevices.add(iotDevice);
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("All Digital Display device details have fetched from Digital Display database.");
|
||||||
|
}
|
||||||
|
return iotDevices;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while fetching all Digital Display device data'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new IotDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
|
DigitalDisplayDAO.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.util;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains utility methods used by Digital Display plugin.
|
||||||
|
*/
|
||||||
|
public class DigitalDisplayUtils {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DigitalDisplayUtils.class);
|
||||||
|
|
||||||
|
public static String getDeviceProperty(Map<String, String> deviceProperties, String property) {
|
||||||
|
|
||||||
|
String deviceProperty = deviceProperties.get(property);
|
||||||
|
|
||||||
|
if (deviceProperty == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return deviceProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.digitaldisplay.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.ServiceRegistration;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.DigitalDisplayManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.device.mgt.iot.digitaldisplay.internal.DigitalDisplayManagementServiceComponent"
|
||||||
|
* immediate="true"
|
||||||
|
* @scr.reference name="org.wso2.carbon.device.mgt.iot.service.DeviceTypeService"
|
||||||
|
* interface="org.wso2.carbon.device.mgt.iot.service.DeviceTypeService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setDeviceTypeService"
|
||||||
|
* unbind="unsetDeviceTypeService"
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DigitalDisplayManagementServiceComponent {
|
||||||
|
|
||||||
|
|
||||||
|
private ServiceRegistration digitalDisplayServiceRegRef;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DigitalDisplayManagementServiceComponent.class);
|
||||||
|
|
||||||
|
protected void activate(ComponentContext ctx) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Activating Digital Display Management Service Component");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
BundleContext bundleContext = ctx.getBundleContext();
|
||||||
|
|
||||||
|
|
||||||
|
digitalDisplayServiceRegRef =
|
||||||
|
bundleContext.registerService(DeviceManagementService.class.getName(), new
|
||||||
|
DigitalDisplayManagerService(),
|
||||||
|
null);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Digital Display Management Service Component has been successfully activated");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Error occurred while activating Digital Display Management Service Component", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext ctx) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("De-activating DigitalDisplay Management Service Component");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (digitalDisplayServiceRegRef != null) {
|
||||||
|
digitalDisplayServiceRegRef.unregister();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(
|
||||||
|
"DigitalDisplay Management Service Component has been successfully de-activated");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Error occurred while de-activating Iot Device Management bundle", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void setDeviceTypeService(DeviceTypeService deviceTypeService) {
|
||||||
|
/* This is to avoid this component getting initialized before the
|
||||||
|
common registered */
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Data source service set to mobile service component");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetDeviceTypeService(DeviceTypeService deviceTypeService) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>device-mgt-iot-digitaldisplay</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - IoT Device DigitalDisplay Management Component</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.device.mgt.iot.digitaldisplay</module>
|
||||||
|
<module>org.wso2.carbon.device.mgt.iot.digitaldisplay.api</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
<version>1.7.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>generate-scr-scrdescriptor</id>
|
||||||
|
<goals>
|
||||||
|
<goal>scr</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,129 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>device-mgt-iot-digitaldisplay-feature</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot.digitaldisplay.feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - IoT Server DigitalDisplay Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
<description>This feature contains the DigitalDisplay Device type specific implementations for the IoT Server
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot.digitaldisplay</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot.digitaldisplay.api</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<type>war</type>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>src/main/resources</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>build.properties</include>
|
||||||
|
<include>p2.inf</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-jaxrs-war</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.iot.digitaldisplay.api
|
||||||
|
</artifactId>
|
||||||
|
<type>war</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<outputDirectory>${basedir}/src/main/resources/webapps/</outputDirectory>
|
||||||
|
<destFileName>digital_display.war</destFileName>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.wso2.maven</groupId>
|
||||||
|
<artifactId>carbon-p2-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>p2-feature-generation</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>p2-feature-gen</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<id>org.wso2.carbon.device.mgt.iot.digitaldisplay</id>
|
||||||
|
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||||
|
<adviceFile>
|
||||||
|
<properties>
|
||||||
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
|
</properties>
|
||||||
|
</adviceFile>
|
||||||
|
<bundles>
|
||||||
|
<bundleDef>
|
||||||
|
org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.iot.digitaldisplay:${carbon.iot.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
</bundles>
|
||||||
|
<importFeatures>
|
||||||
|
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
|
||||||
|
</importFeatureDef>
|
||||||
|
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}
|
||||||
|
</importFeatureDef>
|
||||||
|
</importFeatures>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,29 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
#[Device-Configurations]
|
||||||
|
owner=${DEVICE_OWNER}
|
||||||
|
deviceId=${DEVICE_ID}
|
||||||
|
device-name=${DEVICE_NAME}
|
||||||
|
controller-context=/digital_display/controller
|
||||||
|
mqtt-ep=${MQTT_EP}
|
||||||
|
auth-method=token
|
||||||
|
auth-token=${DEVICE_TOKEN}
|
||||||
|
refresh-token=${DEVICE_REFRESH_TOKEN}
|
||||||
|
push-interval=15
|
||||||
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
templates=deviceConfig.properties
|
||||||
|
zipfilename=DigitalDisplayAgent.zip
|
@ -0,0 +1,190 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "----------------------------------------------------------------"
|
||||||
|
echo "| WSO2 IOT Sample "
|
||||||
|
echo "| Virtual RaspiAlarm "
|
||||||
|
echo "| ---------------- "
|
||||||
|
echo "| ....initializing startup-script "
|
||||||
|
echo "----------------------------------------------------------------"
|
||||||
|
|
||||||
|
#while true; do
|
||||||
|
# read -p "What is the network-interface of your device that the Agent should use (find from ifconfig. ex: wlan0,en0,eth0..) > " interface
|
||||||
|
#
|
||||||
|
# echo "Setting the network-interface to " $interface
|
||||||
|
# sed s/^network-interface=.*/network-interface=$interface/ deviceConfig.properties > myTmp
|
||||||
|
# mv -f myTmp deviceConfig.properties
|
||||||
|
# break;
|
||||||
|
#done
|
||||||
|
#
|
||||||
|
#while true; do
|
||||||
|
# read -p "Whats the time-interval (in seconds) between successive Data-Pushes to the WSO2-IoT-Server (ex: '60' indicates 1 minute) > " interval
|
||||||
|
#
|
||||||
|
# if [ $interval -eq $interval 2>/dev/null ]
|
||||||
|
# then
|
||||||
|
# echo "Setting data-push interval to " $interval " seconds."
|
||||||
|
# sed s/^push-interval=.*/push-interval=$interval/ deviceConfig.properties > myTmp
|
||||||
|
# mv -f myTmp deviceConfig.properties
|
||||||
|
# break;
|
||||||
|
# else
|
||||||
|
# echo "Input needs to be an integer indicating the number seconds between successive data-pushes."
|
||||||
|
# fi
|
||||||
|
#done
|
||||||
|
|
||||||
|
|
||||||
|
#java -jar wso2-firealarm-virtual-agent-advanced.jar
|
||||||
|
|
||||||
|
#while true; do
|
||||||
|
# read -p "Do you wish to run 'apt-get update' and continue? [Yes/No] " yn
|
||||||
|
# case $yn in
|
||||||
|
# [Yy]* ) sudo apt-get update;
|
||||||
|
# break;;
|
||||||
|
# [Nn]* ) echo "Continuing without apt-get update...";
|
||||||
|
# break;;
|
||||||
|
# * ) echo "Please answer yes or no.";
|
||||||
|
# esac
|
||||||
|
#done
|
||||||
|
#
|
||||||
|
#if [ $? -ne 0 ]; then
|
||||||
|
# echo "apt-get update failed.... Some dependencies may not get installed"
|
||||||
|
# echo "If an already installed version of the package exists, try running:"
|
||||||
|
# echo "----------------------------------------------------------------"
|
||||||
|
# echo "sudo -i"
|
||||||
|
# echo "cd /var/lib/dpkg/info"
|
||||||
|
# echo "rm -rf wso2-raspi-alarm*"
|
||||||
|
# echo "dpkg --remove --force-remove-reinstreq wso2-raspi-alarm"
|
||||||
|
# echo "exit"
|
||||||
|
# echo "----------------------------------------------------------------"
|
||||||
|
# echo "Retry Installation...."
|
||||||
|
# break;
|
||||||
|
#fi
|
||||||
|
#
|
||||||
|
#echo "Installing 'gdebi' package..."
|
||||||
|
#sudo apt-get install gdebi # installation of gdebi
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#if [ $? -ne 0 ]; then
|
||||||
|
# echo "gdebi installation failed.... dependencies will not be installed without gdebi"
|
||||||
|
# read -p "Do you wish to continue without gdebi? [Yes/No] " yn
|
||||||
|
# case $yn in
|
||||||
|
# [Yy]* ) echo "Continueing without gdebi.....";;
|
||||||
|
# [Nn]* ) echo "Try to resolve errors and re-run the script.";
|
||||||
|
# exit;;
|
||||||
|
# * ) exit;;
|
||||||
|
# esac
|
||||||
|
#fi
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#for f in ./wso2-raspi-alarm_1.0_armhf.deb; do
|
||||||
|
# ## Check if the glob gets expanded to existing files.
|
||||||
|
# ## If not, f here will be exactly the pattern above
|
||||||
|
# ## and the exists test will evaluate to false.
|
||||||
|
# # [ -e "$f" ] && echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing" || echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path"; exit;
|
||||||
|
# if [ -e "$f" ]; then
|
||||||
|
# echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing now...."
|
||||||
|
# else
|
||||||
|
# echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path. \nExiting installation...";
|
||||||
|
# exit;
|
||||||
|
# fi
|
||||||
|
# ## This is all we needed to know, so we can break after the first iteration
|
||||||
|
# break
|
||||||
|
#done
|
||||||
|
#
|
||||||
|
#echo "Installing the 'wso2-raspi-alarm deb package'"
|
||||||
|
#sudo gdebi wso2-raspi-alarm_1.0_armhf.deb
|
||||||
|
#
|
||||||
|
#if [ $? -ne 0 ]; then
|
||||||
|
# echo "Installation Failed...."
|
||||||
|
# exit;
|
||||||
|
#fi
|
||||||
|
|
||||||
|
#sudo killall -9 python
|
||||||
|
#
|
||||||
|
#for f in ./RaspberryAgent.zip; do
|
||||||
|
# ## Check if the glob gets expanded to existing files.
|
||||||
|
# ## If not, f here will be exactly the pattern above
|
||||||
|
# ## and the exists test will evaluate to false.
|
||||||
|
# # [ -e "$f" ] && echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing" || echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path"; exit;
|
||||||
|
# if [ -e "$f" ]; then
|
||||||
|
# echo "Agent files found......"
|
||||||
|
# sudo rm -rf /usr/local/src/RaspberryAgent
|
||||||
|
# sudo unzip RaspberryAgent.zip -d /usr/local/src/
|
||||||
|
# else
|
||||||
|
# echo "'RaspberryAgent.zip' file does not exist in current path. \nInstalling without upgrading agent...";
|
||||||
|
# fi
|
||||||
|
# ## This is all we needed to know, so we can break after the first iteration
|
||||||
|
# break
|
||||||
|
#done
|
||||||
|
#
|
||||||
|
#for f in /usr/local/src/RaspberryAgent/rc.local; do
|
||||||
|
# ## Check if the glob gets expanded to existing files.
|
||||||
|
# ## If not, f here will be exactly the pattern above
|
||||||
|
# ## and the exists test will evaluate to false.
|
||||||
|
# if [ -e "$f" ]; then
|
||||||
|
# echo "Copying boot script"
|
||||||
|
# sudo mv /usr/local/src/RaspberryAgent/rc.local /etc/rc.local
|
||||||
|
# sudo chmod +x /etc/rc.local
|
||||||
|
# else
|
||||||
|
# echo "Unable to set agent statup on boot";
|
||||||
|
# fi
|
||||||
|
# ## This is all we needed to know, so we can break after the first iteration
|
||||||
|
# break
|
||||||
|
#done
|
||||||
|
#
|
||||||
|
#for f in ./deviceConfigs.cfg; do
|
||||||
|
# ## Check if the glob gets expanded to existing files.
|
||||||
|
# ## If not, f here will be exactly the pattern above
|
||||||
|
# ## and the exists test will evaluate to false.
|
||||||
|
# if [ -e "$f" ]; then
|
||||||
|
# echo "Configuration file found......"
|
||||||
|
# else
|
||||||
|
# echo "'deviceConfigs.cfg' file does not exist in current path. \nExiting installation...";
|
||||||
|
# exit;
|
||||||
|
# fi
|
||||||
|
# ## This is all we needed to know, so we can break after the first iteration
|
||||||
|
# break
|
||||||
|
#done
|
||||||
|
#
|
||||||
|
#echo "Altering Configuration file"
|
||||||
|
#sed -i 's|[/,]||g' deviceConfigs.cfg
|
||||||
|
#
|
||||||
|
#echo "Copying configurations file to /usr/local/src/RaspberryAgent"
|
||||||
|
#sudo cp ./deviceConfigs.cfg /usr/local/src/RaspberryAgent/
|
||||||
|
#
|
||||||
|
#if [ $? -ne 0 ]; then
|
||||||
|
# echo "Copying configuration file failed...."
|
||||||
|
# exit;
|
||||||
|
#fi
|
||||||
|
#
|
||||||
|
#while true; do
|
||||||
|
# read -p "Whats the time-interval (in seconds) between successive Data-Pushes to the WSO2-DC (ex: '60' indicates 1 minute) > " input
|
||||||
|
#
|
||||||
|
# if [ $input -eq $input 2>/dev/null ]
|
||||||
|
# then
|
||||||
|
# echo "Setting data-push interval to $input seconds."
|
||||||
|
# echo $input > /usr/local/src/RaspberryAgent/time-interval
|
||||||
|
# break;
|
||||||
|
# else
|
||||||
|
# echo "Input needs to be an integer indicating the number seconds between successive data-pushes."
|
||||||
|
# fi
|
||||||
|
#done
|
||||||
|
#
|
||||||
|
#cd /usr/local/src/RaspberryAgent/
|
||||||
|
#sudo chmod +x RaspberryStats.py
|
||||||
|
#sudo nohup ./RaspberryStats.py -i $input </dev/null &
|
||||||
|
#
|
||||||
|
#if [ $? -ne 0 ]; then
|
||||||
|
# echo "Could not start the service..."
|
||||||
|
# exit;
|
||||||
|
#else
|
||||||
|
# echo "Running the RaspberryAgent service...."
|
||||||
|
#fi
|
||||||
|
#
|
||||||
|
#echo "--------------------------------------------------------------------------"
|
||||||
|
#echo "| Successfully Started "
|
||||||
|
#echo "| -------------------------- "
|
||||||
|
#echo "| cd to /usr/local/src/RaspberryAgent"
|
||||||
|
#echo "| run 'sudo nohup ./RaspberryStats.py -i time </dev/null &'to start service manually."
|
||||||
|
#echo "| Relapce time with the time-interval (in seconds) between successive Data-Pushes to the WSO2-DC (ex: '60' indicates 1 minute)"
|
||||||
|
#echo "| Find logs at: /usr/local/src/RaspberryAgent/logs/RaspberryStats.log"
|
||||||
|
#echo "---------------------------------------------------------------------------"
|
||||||
|
|
@ -0,0 +1 @@
|
|||||||
|
custom = true
|
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
-- -----------------------------------------------------
|
||||||
|
-- Table `DIGITAL_DISPLAY_DEVICE`
|
||||||
|
-- -----------------------------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS `DIGITAL_DISPLAY_DEVICE` (
|
||||||
|
`DIGITAL_DISPLAY_DEVICE_ID` VARCHAR(45) NOT NULL ,
|
||||||
|
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`DIGITAL_DISPLAY_DEVICE_ID`) );
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
-- -----------------------------------------------------
|
||||||
|
-- Table `DIGITAL_DISPLAY_DEVICE`
|
||||||
|
-- -----------------------------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS `DIGITAL_DISPLAY_DEVICE` (
|
||||||
|
`DIGITAL_DISPLAY_DEVICE_ID` VARCHAR(45) NOT NULL ,
|
||||||
|
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`DIGITAL_DISPLAY_DEVICE_ID`) )
|
||||||
|
ENGINE = InnoDB;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
|||||||
|
<div id="device_overview">
|
||||||
|
<div class="media-left media-middle asset-image col-xs-2 col-sm-2 col-md-2 col-lg-2">
|
||||||
|
{{unit "cdmf.unit.device.overview.digital-display-image"}}
|
||||||
|
</div>
|
||||||
|
<div class="media-body asset-desc add-padding-left-5x">
|
||||||
|
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">Device Overview - Digital Display</div>
|
||||||
|
{{#defineZone "device-detail-properties"}}
|
||||||
|
<table class="table table-responsive table-striped" id="members">
|
||||||
|
<tbody>
|
||||||
|
<tr role="row" class="even"><td class="sorting_1" style="padding:10px 15px; width: 1%;;">Device</td><td style="padding:10px 15px;">{{device.viewModel.vendor}} {{device.properties.model}}</td></tr>
|
||||||
|
<tr role="row" class="odd"><td class="sorting_1" style="padding:10px 15px;">Model</td><td style="padding:10px 15px;">{{device.viewModel.model}}</td></tr>
|
||||||
|
<tr role="row" class="even"><td class="sorting_1" style="padding:10px 15px;">IMEI</td><td style="padding:10px 15px;">{{device.viewModel.imei}}</td></tr>
|
||||||
|
{{#if device.viewModel.udid}}
|
||||||
|
<tr role="row" class="even"><td class="sorting_1" style="padding:10px 15px;">UDID</td><td style="padding:10px 15px;">{{device.viewModel.udid}}</td></tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if device.viewModel.phoneNumber}}
|
||||||
|
<tr role="row" class="even"><td class="sorting_1" style="padding:10px 15px;">Phone Number</td><td style="padding:10px 15px;">{{device.viewModel.phoneNumber}}</td></tr>
|
||||||
|
{{/if}}
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Status</td>
|
||||||
|
<td style="padding:10px 15px;">
|
||||||
|
{{#equal device.status "ACTIVE"}}<span><i class="fw fw-ok icon-success"></i> Active</span>{{/equal}}
|
||||||
|
{{#equal device.status "INACTIVE"}}<span><i class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
|
||||||
|
{{#equal device.status "BLOCKED"}}<span><i class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
|
||||||
|
{{#equal device.status "REMOVED"}}<span><i class="fw fw-delete icon-danger"></i> Removed</span>{{/equal}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{/defineZone}}
|
||||||
|
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">Operations</div>
|
||||||
|
<div class="add-margin-top-4x">
|
||||||
|
{{unit "cdmf.unit.device.iot-operation" deviceType=device.type}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,25 @@
|
|||||||
|
function onRequest (context) {
|
||||||
|
var log = new Log("detail.js");
|
||||||
|
var deviceType = request.getParameter("type");
|
||||||
|
var deviceId = request.getParameter("id");
|
||||||
|
|
||||||
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||||
|
var deviceModule = require("/modules/device.js").deviceModule;
|
||||||
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
|
||||||
|
if (device) {
|
||||||
|
var viewModel = {};
|
||||||
|
var deviceInfo = device.properties.DEVICE_INFO;
|
||||||
|
if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) {
|
||||||
|
deviceInfo = parse(stringify(deviceInfo));
|
||||||
|
viewModel.system = device.properties.IMEI;
|
||||||
|
viewModel.machine = "Digital Display";
|
||||||
|
viewModel.vendor = device.properties.VENDOR;
|
||||||
|
}
|
||||||
|
device.viewModel = viewModel;
|
||||||
|
}
|
||||||
|
context.device = device;
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
instructions.configure = \
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/sketches/);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/sketches/digitaldisplay/);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/agent/,target:${installFolder}/../../resources/sketches/digitaldisplay/,overwrite:true);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/digitaldisplay,overwrite:true);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/jaggerryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\
|
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>device-mgt-iot-digitaldisplay-feature</artifactId>
|
||||||
|
<version>1.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - IoT Server DigitalDisplay Device Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.device.mgt.iot.digitaldisplay.feature</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
</project>
|
Loading…
Reference in new issue