From afcabb7fbcd2add1e89ff3e207e7811106f270b3 Mon Sep 17 00:00:00 2001 From: charithag Date: Sat, 19 Dec 2015 14:30:11 +0530 Subject: [PATCH] Update operation features with endpoints --- .../api/DigitalDisplayControllerService.java | 413 +++++++++--------- .../service/VirtualFireAlarmService.java | 7 +- .../device-view.hbs | 2 +- .../device-view.js | 20 +- .../operation.hbs | 88 ---- .../operation.js | 6 - .../operation.json | 3 - .../iot.unit.device.operation/operation.hbs | 28 +- .../public/js/operation.js | 42 ++ .../public/js/device-stats.js | 33 +- 10 files changed, 310 insertions(+), 332 deletions(-) delete mode 100644 features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.hbs delete mode 100644 features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.js delete mode 100644 features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.json create mode 100644 features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation/public/js/operation.js diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java index 60d3028930..8a84572a22 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayControllerService.java @@ -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); } } diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index 0d884fe441..82ffcd49ee 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -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 { diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.hbs b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.hbs index c16ce0ae5a..0c3a0c125d 100644 --- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.hbs +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.hbs @@ -6,7 +6,7 @@ Operations
- {{unit "iot.unit.device.digitaldisplay.operation" device=device}} + {{unit "iot.unit.device.operation" device=device}}
{{/zone}} {{#zone "device-detail-properties"}} diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.js b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.js index df879ddf0f..a102cd7422 100644 --- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.js +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.device-view/device-view.js @@ -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") { diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.hbs b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.hbs deleted file mode 100644 index 7535b81a9b..0000000000 --- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.hbs +++ /dev/null @@ -1,88 +0,0 @@ - - - -
- -
-
- {{#if control_operations}} - {{#each control_operations}} -
-
-
- - - - - {{#if editcontent}} - - - - {{/if}} - - {{#if add}} - - - - {{/if}} - - {{#if before}} - - {{/if}} - {{#if after}} - - {{/if}} - {{#if removeresource}} - - {{/if}} - {{#if remove}} - - {{/if}} - {{#if content}} - - {{/if}} - - - - - -
-
-
- {{/each}} - {{/if}} -
-
-
diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.js b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.js deleted file mode 100644 index 47e5aff43d..0000000000 --- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.js +++ /dev/null @@ -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}; -} \ No newline at end of file diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.json b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.json deleted file mode 100644 index 688e939808..0000000000 --- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.digitaldisplay.operation/operation.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version": "1.0.0" -} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation/operation.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation/operation.hbs index dbc53dea0a..ca1b51de2c 100644 --- a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation/operation.hbs +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation/operation.hbs @@ -1,10 +1,28 @@ {{#if control_operations}} + {{#each control_operations}}
+ method="post" class="form-inline" style="padding-bottom: 20px;"> - + {{#each params}} + + {{/each}}