Update operation features with endpoints

charithag 9 years ago
parent 9cfb57e983
commit afcabb7fbc

@ -1,27 +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.api;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.device.DeviceType;
import org.wso2.carbon.apimgt.annotations.device.feature.Feature;
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 org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.device.feature.Feature;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
/**
* Created by nuwan on 11/13/15.
*/
@API( name="digital_display", version="1.0.0", context="/digital_display")
@DeviceType( value = "digital_display")
@API(name = "digital_display", version = "1.0.0", context = "/digital_display")
@DeviceType(value = "digital_display")
public class DigitalDisplayControllerService {
@ -29,44 +47,44 @@ public class DigitalDisplayControllerService {
private static DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler;
public void setDigitalDisplayMqttCommunicationHandler(DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler){
public DigitalDisplayMqttCommunicationHandler getDigitalDisplayMqttCommunicationHandler() {
return DigitalDisplayControllerService.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 deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param response response type of the method
*/
@Path("/restart-browser")
@POST
@Feature( code="DISPLAY_BROWSERRESTART", name="Restart Browser",
description="Restart Browser in Digital Display")
public void restartBrowser(@FormParam("deviceId") String deviceId ,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@Feature(code = "DISPLAY_BROWSERRESTART", name = "Restart Browser",
description = "Restart Browser in Digital Display")
public void restartBrowser(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("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);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}catch (DigitalDisplayException e){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
@ -77,29 +95,29 @@ public class DigitalDisplayControllerService {
/**
* 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 deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param response response type of the method
*/
@Path("/close-browser")
@POST
@Feature( code="DISPLAY_BROWSERCLOSE", name="Close Browser",
description="Close Browser in Digital Display")
public void closeBrowser(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@Feature(code = "DISPLAY_BROWSERCLOSE", name = "Close Browser",
description = "Close Browser in Digital Display")
public void closeBrowser(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("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);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}catch (DigitalDisplayException e){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -109,29 +127,29 @@ public class DigitalDisplayControllerService {
/**
* 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 deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param response response type of the method
*/
@Path("/terminate-display")
@POST
@Feature( code="DISPLAY_TERMINATE", name="Terminate Display",
description="Terminate all running processe in Digital Display")
public void terminateDisplay(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@Feature(code = "DISPLAY_TERMINATE", name = "Terminate Display",
description = "Terminate all running processe in Digital Display")
public void terminateDisplay(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("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);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}catch (DigitalDisplayException e){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -141,29 +159,29 @@ public class DigitalDisplayControllerService {
/**
* Restart python server in given digital display
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param response response type of the method
*/
@Path("/restart-display")
@POST
@Feature( code="DISPLAY_RESTART", name="Restart Display",
description="Restart Digital Display")
public void restartDisplay(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@Feature(code = "DISPLAY_RESTART", name = "Restart Display",
description = "Restart Digital Display")
public void restartDisplay(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("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);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}catch (DigitalDisplayException e){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -173,36 +191,36 @@ public class DigitalDisplayControllerService {
/**
* Search through the sequence and edit requested resource
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param path page no need to change
* @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
* @param newValue page is used to replace path
*/
@Path("/edit-content")
@POST
@Feature( code="DISPLAY_EDITCONTENT", name="Edit Content",
description="Search through the sequence and edit requested resource in Digital Display")
public void editContent(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@Feature(code = "DISPLAY_EDITCONTENT", name = "Edit Content",
description = "Search through the sequence and edit requested resource in Digital Display")
public void editContent(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("path") String path,
@FormParam("attribute") String attribute,
@FormParam("new-value") String newValue,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
log.info("Edit Content Display Id - " + deviceId + " by " + owner);
try {
String params = path + "|" + attribute + "|" + newValue;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT +":" ,params);
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + 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){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -212,37 +230,37 @@ public class DigitalDisplayControllerService {
/**
* Add new resource end to the existing sequence
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId 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
* @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")
@POST
@Feature( code="DISPLAY_ADDRESOURCE", name="Add Resource",
description="Add new resource end to the existing sequence in Digital Display")
public void addNewResource(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@Feature(code = "DISPLAY_ADDRESOURCE", name = "Add Resource",
description = "Add new resource end to the existing sequence in Digital Display")
public void addNewResource(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("type") String type,
@FormParam("time") String time,
@FormParam("path") String path,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
log.info("Add Sequence : " + deviceId);
try {
String params = type + "|" + time + "|" + path;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT +":" ,params);
sendCommandViaMQTT(owner, deviceId, sessionId + "::" +
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){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -251,40 +269,40 @@ public class DigitalDisplayControllerService {
/**
* 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 deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId 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
* @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")
@POST
@Feature( code="DISPLAY_ADDRESOURCE_BEFORE", name="Add Resource Before",
description="Add new resource to sequence before given page no. in Digital Display")
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){
@Feature(code = "DISPLAY_ADDRESOURCE_BEFORE", name = "Add Resource Before",
description = "Add new resource to sequence before given page no. in Digital Display")
public void addNewResourceBefore(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("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 + "|" + time + "|" + path +
"|" + "before=" + nextPage;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT +":" ,params);
"|" + "before=" + nextPage;
sendCommandViaMQTT(owner, deviceId, sessionId + "::" +
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){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -294,40 +312,40 @@ public class DigitalDisplayControllerService {
/**
* Add new resource to sequence after given page
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId 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 deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId 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")
@POST
@Feature( code="DISPLAY_ADDRESOURCE_NEXT", name="Add Resource Next",
description="Add new resource to sequence after given page in Digital Display")
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){
@Feature(code = "DISPLAY_ADDRESOURCE_NEXT", name = "Add Resource Next",
description = "Add new resource to sequence after given page in Digital Display")
public void addNewResourceAfter(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("type") String type,
@FormParam("time") String time,
@FormParam("path") String path,
@FormParam("before-page") String beforePage,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
log.info("Add Sequence : " + deviceId);
try {
String params = type + "|" + time + "|" + path +
"|" + "after=" + beforePage;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT + ":",params);
"|" + "after=" + beforePage;
sendCommandViaMQTT(owner, deviceId, sessionId + "::" +
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){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -336,32 +354,32 @@ public class DigitalDisplayControllerService {
/**
* Delete a resource in sequence
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId 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
* @param response response type of the method
* @param path path of the page no need to delete
*/
@Path("/remove-resource")
@POST
@Feature( code="DISPLAY_REMOVE_RESOURCE", name="Remove Resource",
description="Delete a resource from sequence in Digital Display")
public void removeResource(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@Feature(code = "DISPLAY_REMOVE_RESOURCE", name = "Remove Resource",
description = "Delete a resource from sequence in Digital Display")
public void removeResource(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("path") String path,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@HeaderParam("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);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}catch (DigitalDisplayException e){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -371,31 +389,31 @@ public class DigitalDisplayControllerService {
/**
* Remove directory and whole content
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId 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")
@POST
@Feature( code="DISPLAY_REMOVE_DIR", name="Remove Directory",
description="Remove directory and whole content in Digital Display")
@Feature(code = "DISPLAY_REMOVE_DIR", name = "Remove Directory",
description = "Remove directory and whole content in Digital Display")
public void removeDirectory(@FormParam("directory-name") String directoryName,
@FormParam("deviceId") String deviceId ,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("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);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}catch (DigitalDisplayException e){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -405,33 +423,33 @@ public class DigitalDisplayControllerService {
/**
* Remove content from www folder
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId 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
* @param content file name of need to delete
* @param response response type of the method
*/
@Path("/remove-content")
@POST
@Feature( code="DISPLAY_REMOVE_CONTENT", name="Remove Content",
description="Remove content from www folder in Digital Display")
@Feature(code = "DISPLAY_REMOVE_CONTENT", name = "Remove Content",
description = "Remove content from www folder in Digital Display")
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){
@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
log.info("Remove Content : " + deviceId);
try {
String param = directoryName + "|" + content;
sendCommandViaMQTT(owner,deviceId,sessionId + "::" + DigitalDisplayConstants.REMOVE_CONTENT_CONSTANT + ":",param);
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + 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){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -441,29 +459,29 @@ public class DigitalDisplayControllerService {
/**
* Stop specific display
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param response response type of the method
*/
@Path("/shutdown-display")
@POST
@Feature( code="DISPLAY_SHUTDOWN", name="Shut Down",
description="Stop specific display in Digital Display")
public void shutDownDisplay(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@Feature(code = "DISPLAY_SHUTDOWN", name = "Shut Down",
description = "Stop specific display in Digital Display")
public void shutDownDisplay(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("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);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}catch (DigitalDisplayException e){
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -473,30 +491,30 @@ public class DigitalDisplayControllerService {
/**
* Check specific digital display power ON of OFF
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param response response type of the method
*/
@Path("/get-status")
@GET
@Feature( code="DISPLAY_GET_STATUS", name="Get Status",
description="Check specific digital display power ON of OFF")
public void getStatus(@FormParam("deviceId") String deviceId,
@FormParam("owner") String owner,
@FormParam("sessionId") String sessionId,
@Context HttpServletResponse response){
@POST
@Feature(code = "DISPLAY_GET_STATUS", name = "Get Status",
description = "Check specific digital display power ON of OFF")
public void getStatus(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
log.info("Status : " + deviceId);
try {
sendCommandViaMQTT(owner,deviceId,sessionId + ":" + DigitalDisplayConstants.GET_STATUS_CONSTANT,"");
sendCommandViaMQTT(owner, deviceId, sessionId + ":" + 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);
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@ -506,24 +524,25 @@ public class DigitalDisplayControllerService {
* 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
* @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 {
String param)
throws DeviceManagementException, DigitalDisplayException {
log.info(deviceOwner);
String topic = String.format(DigitalDisplayConstants.PUBLISH_TOPIC , deviceOwner , deviceId);
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);
throw new DigitalDisplayException(errorMessage, e);
}
}

@ -11,7 +11,7 @@
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -58,6 +58,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
@ -566,14 +567,14 @@ public class VirtualFireAlarmService {
* @param state
* @param response
*/
@Path("controller/bulb/{state}")
@Path("controller/bulb")
@POST
@Feature( code="VIRTUALFIREALARM_BULBCONTROL", name="Control Bulb",
description="Switch on/off Virtual Fire Alarm Bulb")
public void switchBulb(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol,
@PathParam("state") String state,
@FormParam("state") String state,
@Context HttpServletResponse response) {
try {

@ -6,7 +6,7 @@
Operations
</div>
<div class="add-margin-top-4x">
{{unit "iot.unit.device.digitaldisplay.operation" device=device}}
{{unit "iot.unit.device.operation" device=device}}
</div>
{{/zone}}
{{#zone "device-detail-properties"}}

@ -1,10 +1,28 @@
/*
* 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.
*/
function onRequest(context) {
var log = new Log("detail.js");
var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("id");
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/modules/device.js").deviceModule;
var deviceModule = require("/app/modules/device.js").deviceModule;
var device = deviceModule.viewDevice(deviceType, deviceId);
if (device && device.status != "error") {

@ -1,88 +0,0 @@
<style>
::-webkit-input-placeholder { color:#161616; }
::-moz-placeholder { color:#161616; }
:-ms-input-placeholder { color:#161616; }
input:-moz-placeholder { color:#161616; }
</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="text" name="path"
placeholder="page no">
<input type="text" name="attribute"
placeholder="attribute">
<input type="text" name="new-value"
placeholder="new-value">
{{/if}}
{{#if add}}
<input type="text" name="type"
placeholder="type">
<input type="text" name="time"
placeholder="time">
<input type="text" name="path"
placeholder="page no">
{{/if}}
{{#if before}}
<input type="text" name="next-page"
placeholder="next-page">
{{/if}}
{{#if after}}
<input type="text" name="before-page"
placeholder="before-page">
{{/if}}
{{#if removeresource}}
<input type="text" name="path"
placeholder="page no">
{{/if}}
{{#if remove}}
<input type="text" name="directory-name"
placeholder="directory-name">
{{/if}}
{{#if content}}
<input type="text" 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>

@ -1,6 +0,0 @@
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};
}

@ -1,10 +1,28 @@
{{#if control_operations}}
<style>
::-webkit-input-placeholder {
color: #B8B8B8;
}
::-moz-placeholder {
color: #B8B8B8;
}
:-ms-input-placeholder {
color: #B8B8B8;
}
input:-moz-placeholder {
color: #B8B8B8;
}
</style>
{{#each control_operations}}
<form action="{{@app.context}}/api/operations/{{../device.type}}/{{operation}}?deviceId={{../device.deviceIdentifier}}"
method="post" class="form-inline">
method="post" class="form-inline" style="padding-bottom: 20px;">
<label class="wr-input-label">{{name}}</label>
<input type="number" name="value"
placeholder="{{description}}">
{{#each params}}
<input type="text" name="{{this}}" placeholder="{{this}}">
{{/each}}
<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
@ -16,3 +34,7 @@
</form>
{{/each}}
{{/if}}
{{#zone "bottomJs"}}
{{js "js/operation.js"}}
{{/zone}}

@ -0,0 +1,42 @@
/*
* 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.
*/
$("form").on('submit', function (e) {
var postOperationRequest = $.ajax({
url: $(this).attr("action") + '&' + $(this).serialize(),
method: "post"
});
var lblSending = $('#lblSending', this);
lblSending.removeClass('hidden');
var lblSent = $('#lblSent', this);
postOperationRequest.done(function (data) {
lblSending.addClass('hidden');
lblSent.removeClass('hidden');
setTimeout(function () {
lblSent.addClass('hidden');
}, 3000);
});
postOperationRequest.fail(function (jqXHR, textStatus) {
lblSending.addClass('hidden');
lblSent.addClass('hidden');
});
e.preventDefault();
});

@ -6,12 +6,12 @@
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
* "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.
*/
@ -83,33 +83,6 @@ $(document).ready(function () {
updateGraphs();
});
$("form").on('submit', function (e) {
var postOperationRequest = $.ajax({
url: $(this).attr("action") + '&' + $(this).serialize(),
method: "post"
});
var lblSending = $('#lblSending', this);
lblSending.removeClass('hidden');
var lblSent = $('#lblSent', this);
var sentValue = $(this).find('input[name="value"]').val();
postOperationRequest.done(function (data) {
lblSending.addClass('hidden');
lblSent.removeClass('hidden');
setTimeout(function () {
lblSent.addClass('hidden');
}, 3000);
$('#lblLastState').text('Current value: ' + (sentValue == '1' ? 'On' : 'Off'));
});
postOperationRequest.fail(function (jqXHR, textStatus) {
lblSending.addClass('hidden');
lblSent.addClass('hidden');
});
e.preventDefault();
});
function updateGraphs() {
var tv = 5000;

Loading…
Cancel
Save