change digital display files

NuwanSameera 9 years ago
parent 65da5afe80
commit bfeb8e5500

@ -11,9 +11,7 @@ import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayCon
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.
@ -48,15 +46,15 @@ public class DigitalDisplayControllerService {
*/
@Path("/restart-browser")
@POST
public void restartBrowser(@QueryParam("deviceId") String deviceId ,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
public void restartBrowser(@FormParam("deviceId") String deviceId ,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Restrat Browser : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId +":" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT,"");
sendCommandViaMQTT(owner,deviceId,sessionId +"::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + ":","");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -79,15 +77,15 @@ public class DigitalDisplayControllerService {
*/
@Path("/close-browser")
@POST
public void closeBrowser(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
public void closeBrowser(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Close Browser : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId +":" + DigitalDisplayConstants.CLOSE_BROWSER_CONSTANT ,"");
sendCommandViaMQTT(owner,deviceId,sessionId +"::" + DigitalDisplayConstants.CLOSE_BROWSER_CONSTANT + ":" ,"");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -109,15 +107,15 @@ public class DigitalDisplayControllerService {
*/
@Path("/terminate-display")
@POST
public void terminateDisplay(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
public void terminateDisplay(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Terminate Display : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId +":" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT,"");
sendCommandViaMQTT(owner,deviceId,sessionId +"::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT +":" ,"");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -139,15 +137,15 @@ public class DigitalDisplayControllerService {
*/
@Path("/restart-display")
@POST
public void restartDisplay(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
public void restartDisplay(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Restrat Display : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId +":" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT ,"");
sendCommandViaMQTT(owner,deviceId,sessionId +"::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + ":" ,"");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -171,21 +169,20 @@ public class DigitalDisplayControllerService {
* @param newValue page is used to replace path
*/
@Path("/edit-content")
@PUT
@Produces(MediaType.APPLICATION_JSON)
public void editContent(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("path") String path,
@QueryParam("attribute") String attribute,
@QueryParam("new-value") String newValue,
@QueryParam("sessionId") String sessionId,
@POST
public void editContent(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("path") String path,
@FormParam("attribute") String attribute,
@FormParam("new-value") String newValue,
@FormParam("sessionId") String sessionId,
@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,sessionId + ":" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT,params);
String params = path + "|" + attribute + "|" + newValue;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT +":" ,params);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -210,20 +207,20 @@ public class DigitalDisplayControllerService {
*/
@Path("/add-resource")
@POST
public void addNewResource(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("type") String type,
@QueryParam("time") String time,
@QueryParam("path") String path,
@QueryParam("sessionId") String sessionId,
public void addNewResource(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("type") String type,
@FormParam("time") String time,
@FormParam("path") String path,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Add Sequence : " + deviceId);
try {
String params = type + File.separator + time + File.separator + path;
sendCommandViaMQTT(owner,deviceId,sessionId + ":" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params);
String params = type + "|" + time + "|" + path;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT +":" ,params);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -248,22 +245,22 @@ public class DigitalDisplayControllerService {
*/
@Path("/add-resource-before")
@POST
public void addNewResourceBefore(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
@QueryParam("type") String type,
@QueryParam("time") String time,
@QueryParam("path") String path,
@QueryParam("next-page") String nextPage,
public void addNewResourceBefore(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@FormParam("type") String type,
@FormParam("time") String time,
@FormParam("path") String path,
@FormParam("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,sessionId + ":" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params);
String params = type + "|" + time + "|" + path +
"|" + "before=" + nextPage;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT +":" ,params);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -289,22 +286,22 @@ public class DigitalDisplayControllerService {
*/
@Path("/add-resource-next")
@POST
public void addNewResourceAfter(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("type") String type,
@QueryParam("time") String time,
@QueryParam("path") String path,
@QueryParam("before-page") String beforePage,
@QueryParam("sessionId") String sessionId,
public void addNewResourceAfter(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("type") String type,
@FormParam("time") String time,
@FormParam("path") String path,
@FormParam("before-page") String beforePage,
@FormParam("sessionId") String sessionId,
@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,sessionId + ":" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params);
String params = type + "|" + time + "|" + path +
"|" + "after=" + beforePage;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT + ":",params);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -325,19 +322,18 @@ public class DigitalDisplayControllerService {
* @param path path of the page no need to delete
*/
@Path("/remove-resource")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void removeResource(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("path") String path,
@QueryParam("sessionId") String sessionId,
@POST
public void removeResource(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("path") String path,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Remove Resource : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId + ":" +
DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT,path);
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + ":",path);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -359,18 +355,17 @@ public class DigitalDisplayControllerService {
* @param directoryName path of the folder need to delete
*/
@Path("/remove-directory")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void removeDirectory(@QueryParam("directory-name") String directoryName,
@QueryParam("deviceId") String deviceId ,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
@POST
public void removeDirectory(@FormParam("directory-name") String directoryName,
@FormParam("deviceId") String deviceId ,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Remove Directory : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId + ":" +
DigitalDisplayConstants.REMOVE_DIRECTORY_CONSTANT,directoryName);
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.REMOVE_DIRECTORY_CONSTANT + ":",directoryName);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -393,19 +388,18 @@ public class DigitalDisplayControllerService {
* @param response response type of the method
*/
@Path("/remove-content")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void removeContent(@QueryParam("directory_name") String directoryName,
@QueryParam("content") String content,
@QueryParam("deviceId") String deviceId ,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
@POST
public void removeContent(@FormParam("directory-name") String directoryName,
@FormParam("content") String content,
@FormParam("deviceId") String deviceId ,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Remove Content : " + deviceId);
try {
String param = directoryName + File.separator + content;
sendCommandViaMQTT(owner,deviceId,sessionId + ":" + DigitalDisplayConstants.REMOVE_CONTENT_CONSTANT,param);
String param = directoryName + "|" + content;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" + DigitalDisplayConstants.REMOVE_CONTENT_CONSTANT + ":",param);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -427,15 +421,15 @@ public class DigitalDisplayControllerService {
*/
@Path("/shutdown-display")
@POST
public void shutDownDisplay(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
public void shutDownDisplay(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Shut down display : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId + ":" + DigitalDisplayConstants.SHUTDOWN_DISPLAY_CONSTANT,"");
sendCommandViaMQTT(owner,deviceId,sessionId + "::" + DigitalDisplayConstants.SHUTDOWN_DISPLAY_CONSTANT + ":" ,"");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -457,9 +451,9 @@ public class DigitalDisplayControllerService {
*/
@Path("/get-status")
@GET
public void getStatus(@QueryParam("deviceId") String deviceId,
@QueryParam("owner") String owner,
@QueryParam("sessionId") String sessionId,
public void getStatus(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
log.info("Status : " + deviceId);

@ -21,9 +21,6 @@ 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";
@ -35,7 +32,6 @@ public class DigitalDisplayConstants {
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";
}

@ -1,3 +1,4 @@
{{unit "cdmf.unit.lib.service-invoker-utility"}}
{{unit "cdmf.unit.lib.handlebars"}}
{{#defineZone "device-detail-top"}}
@ -27,34 +28,34 @@
{{#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;">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>
<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 "iot.unit.device.operation" device=device}}
{{unit "iot.unit.device.digitaldisplay.operation" device=device}}
</div>
</div>
</div>
</div>
<div class="media">
<div class="media-left col-xs-12 col-sm-2 col-md-2 col-lg-2">
<ul class="list-group" role="tablist">
<li class="active"><a class="list-group-item" href="#device_details" role="tab" data-toggle="tab" aria-controls="device_details">Device Details</a></li>
<li><a class="list-group-item" href="#policy_compliance" role="tab" data-toggle="tab" aria-controls="policy_compliance">Policy Compliance</a></li>
<li><a class="list-group-item" href="#device_location" role="tab" data-toggle="tab" aria-controls="device_location">Device Location</a></li>
<li><a class="list-group-item" href="#event_log" role="tab" data-toggle="tab" aria-controls="event_log">Operations Log</a></li>
</ul>
</div>
<div class="media">
<div class="media-left col-xs-12 col-sm-2 col-md-2 col-lg-2">
<ul class="list-group" role="tablist">
<li class="active"><a class="list-group-item" href="#device_details" role="tab" data-toggle="tab" aria-controls="device_details">Device Details</a></li>
<li><a class="list-group-item" href="#policy_compliance" role="tab" data-toggle="tab" aria-controls="policy_compliance">Policy Compliance</a></li>
<li><a class="list-group-item" href="#device_location" role="tab" data-toggle="tab" aria-controls="device_location">Device Location</a></li>
<li><a class="list-group-item" href="#event_log" role="tab" data-toggle="tab" aria-controls="event_log">Operations Log</a></li>
</ul>
</div>
{{#defineZone "device-detail-properties"}}
<div class="media-body add-padding-left-5x remove-padding-xs tab-content">
<div class="panel-group tab-content">
@ -126,4 +127,4 @@
<script id="policy-view" src="{{@unit.publicUri}}/templates/policy-compliance.hbs" data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}" type="text/x-handlebars-template" ></script>
<script id="applications-list" src="{{@unit.publicUri}}/templates/applications-list.hbs" data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}" type="text/x-handlebars-template" ></script>
<script id="operations-log" src="{{@unit.publicUri}}/templates/operations-log.hbs" data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}" type="text/x-handlebars-template" ></script>
{{/zone}}
{{/zone}}

@ -0,0 +1,88 @@
<style>
::-webkit-input-placeholder { color:#f00; }
::-moz-placeholder { color:#f00; } /* firefox 19+ */
:-ms-input-placeholder { color:#f00; } /* ie */
input:-moz-placeholder { color:#f00; }
</style>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h2 class="sub-title panel-title">
<a data-toggle="collapse"
href="#collapseOne" aria-expanded="true"
aria-controls="collapseOne">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-arrow fw-down fw-stack-1x"></i>
</span>
Device Operations
</a>
</h2>
</div>
<div id="collapseOne" class="panel-collapse collapse in"
role="tabpanel" aria-labelledby="headingOne">
<div id="device-location" class="panel-body">
{{#if control_operations}}
{{#each control_operations}}
<form action="{{@app.context}}/api/operations/{{../../device.type}}/{{operation}}" method="post">
<div class="row">
<div class="wr-input-control">
<label class="wr-input-label">{{name}}</label>
<input type="hidden" name="owner"
value={{../../device.owner}}>
<input type="hidden" name="deviceId"
value={{../../device.deviceIdentifier}}>
{{#if editcontent}}
<input type="number" name="path"
placeholder="path">
<input type="number" name="attribute"
placeholder="attribute">
<input type="number" name="new-value"
placeholder="new-value">
{{/if}}
{{#if add}}
<input type="number" name="type"
placeholder="type">
<input type="number" name="time"
placeholder="time">
<input type="number" name="path"
placeholder="path">
{{/if}}
{{#if before}}
<input type="number" name="next-page"
placeholder="next-page">
{{/if}}
{{#if after}}
<input type="number" name="before-page"
placeholder="before-page">
{{/if}}
{{#if removeresource}}
<input type="number" name="path"
placeholder="path">
{{/if}}
{{#if remove}}
<input type="number" name="directory-name"
placeholder="directory-name">
{{/if}}
{{#if content}}
<input type="number" name="content"
placeholder="content">
{{/if}}
<button class="wr-btn">&nbsp;&nbsp;&nbsp;&nbsp;Send
to Device&nbsp;&nbsp;&nbsp;&nbsp;</button>
<label id="lblSending" class="wr-input-label hidden"><i class="fw fw-lifecycle fw-spin fw-2x"></i> Sending..</label>
<label id="lblSent" class="wr-input-label hidden"><i class="fw fw-check fw-2x"></i> Sent</label>
<label id="lblLastState" class="wr-input-label wr-input-label-status"></label>
</div>
</div>
</form>
{{/each}}
{{/if}}
</div>
</div>
</div>

@ -0,0 +1,6 @@
function onRequest(context) {
var operationModule = require("/app/modules/operation.js").operationModule;
var device = context.unit.params.device;
var control_operations = operationModule.getControlOperations(device.type);
return {"control_operations": control_operations, "device": device};
}
Loading…
Cancel
Save