diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java index e5045e69ea..39fcc7f252 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -61,6 +61,7 @@ public class AndroidSenseService { private static final String PRESSURE_STREAM_DEFINITION = "org.wso2.iot.devices.pressure"; private static final String GRAVITY_STREAM_DEFINITION = "org.wso2.iot.devices.gravity"; private static final String ROTATION_STREAM_DEFINITION = "org.wso2.iot.devices.rotation"; + private static final String PROXIMITY_STREAM_DEFINITION = "org.wso2.iot.device.proximity"; private static final String SENSOR_ACCELEROMETER = "accelerometer"; private static final String SENSOR_GYROSCOPE = "gyroscope"; @@ -69,6 +70,7 @@ public class AndroidSenseService { private static final String SENSOR_ROTATION = "rotation"; private static final String SENSOR_LIGHT = "light"; private static final String SENSOR_GPS = "gps"; + private static final String SENSOR_PROXIMITY = "proximity"; ///////////////////////////////////////////////////////////////////////////////////////////// private static final String SENSOR_BATTERY = "battery"; @@ -257,7 +259,7 @@ public class AndroidSenseService { streamDef = LIGHT_STREAM_DEFINITION; sensorName = SENSOR_LIGHT; payloadData = new Object[] { Float.parseFloat(sensor.value) }; - }else if(androidSensorId == 1){ + } else if (androidSensorId == 1){ streamDef = ACCELEROMETER_STREAM_DEFINITION; String value = sensor.value; String valuesM[] = value.split(","); @@ -266,6 +268,41 @@ public class AndroidSenseService { .parseFloat(valuesM[0]); payloadData = gValuesF; sensorName = SENSOR_ACCELEROMETER; + } else if (androidSensorId == 4) { + streamDef = GYROSCOPE_STREAM_DEFINITION; + String value = sensor.value; + String valuesG[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float + .parseFloat(valuesG[0]); + payloadData = gValuesF; + sensorName = SENSOR_GYROSCOPE; + } else if (androidSensorId == 9) { + streamDef = GRAVITY_STREAM_DEFINITION; + String value = sensor.value; + String valuesG[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float + .parseFloat(valuesG[0]); + payloadData = gValuesF; + sensorName = SENSOR_GRVITY; + } else if (androidSensorId == 11) { + streamDef = ROTATION_STREAM_DEFINITION; + String value = sensor.value; + String valuesG[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float + .parseFloat(valuesG[0]); + payloadData = gValuesF; + sensorName = SENSOR_ROTATION; + } else if (androidSensorId == 8) { + streamDef = PROXIMITY_STREAM_DEFINITION; + sensorName = SENSOR_PROXIMITY; + payloadData = new Object[] { Float.parseFloat(sensor.value) }; + } else if (androidSensorId == 6) { + streamDef = PRESSURE_STREAM_DEFINITION; + sensorName = SENSOR_PRESSURE; + payloadData = new Object[] { Float.parseFloat(sensor.value) }; } //Add the remaining sensor types. @@ -392,5 +429,100 @@ public class AndroidSenseService { return sensorRecord; } + @Path("controller/readrotation") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readRotation(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + @Path("controller/readproximity") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readProximity(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + @Path("controller/readgyroscope") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readGyroscope(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + @Path("controller/readpressure") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readPressure(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + @Path("controller/readgravity") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readGravity(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + } diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/pom.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/pom.xml new file mode 100644 index 0000000000..76b4bbbfef --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/pom.xml @@ -0,0 +1,233 @@ + + + + + device-mgt-iot-digitaldisplay + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.digitaldisplay.api + 1.9.2-SNAPSHOT + war + WSO2 Carbon - IoT Server DigitalDisplay API + WSO2 Carbon - Digital Display Service API Implementation + http://wso2.org + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.certificate.mgt.core + provided + + + commons-codec.wso2 + commons-codec + + + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + provided + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-transports-http + provided + + + + + org.eclipse.paho + mqtt-client + provided + + + + + org.apache.httpcomponents + httpasyncclient + 4.1 + provided + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot + provided + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay + provided + + + + + org.codehaus.jackson + jackson-core-asl + + + org.codehaus.jackson + jackson-jaxrs + + + javax + javaee-web-api + provided + + + javax.ws.rs + jsr311-api + provided + + + + commons-httpclient.wso2 + commons-httpclient + provided + + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.bouncycastle.wso2 + bcprov-jdk15on + + + org.wso2.carbon + org.wso2.carbon.user.api + + + org.wso2.carbon + org.wso2.carbon.queuing + + + org.wso2.carbon + org.wso2.carbon.base + + + org.apache.axis2.wso2 + axis2 + + + org.igniterealtime.smack.wso2 + smack + + + org.igniterealtime.smack.wso2 + smackx + + + jaxen + jaxen + + + commons-fileupload.wso2 + commons-fileupload + + + org.apache.ant.wso2 + ant + + + org.apache.ant.wso2 + ant + + + commons-httpclient.wso2 + commons-httpclient + + + org.eclipse.equinox + javax.servlet + + + org.wso2.carbon + org.wso2.carbon.registry.api + + + + + + commons-codec + commons-codec + + + + org.igniterealtime.smack.wso2 + smack + provided + + + org.igniterealtime.smack.wso2 + smackx + provided + + + + + + + + maven-compiler-plugin + + UTF-8 + ${wso2.maven.compiler.source} + ${wso2.maven.compiler.target} + + + + maven-war-plugin + + digital_display + + + + + + \ No newline at end of file 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 new file mode 100644 index 0000000000..db5f68aeb1 --- /dev/null +++ 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 @@ -0,0 +1,505 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.exception.DigitalDisplayException; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.CommunicationHandlerException; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util.DigitalDisplayMqttCommunicationHandler; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; + +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.File; + +/** + * Created by nuwan on 11/13/15. + */ + +public class DigitalDisplayControllerService { + + + private static Log log = LogFactory.getLog(DigitalDisplayControllerService.class); + + private static DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler; + + public void setDigitalDisplayMqttCommunicationHandler(DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler){ + DigitalDisplayControllerService.digitalDisplayMqttCommunicationHandler = digitalDisplayMqttCommunicationHandler; + + digitalDisplayMqttCommunicationHandler.connect(); + + } + + public DigitalDisplayMqttCommunicationHandler getDigitalDisplayMqttCommunicationHandler(){ + return DigitalDisplayControllerService.digitalDisplayMqttCommunicationHandler; + } + + + /** + * Restart the running browser in the given digital display. + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + */ + @Path("/restart-browser") + @POST + public void restartBrowser(@QueryParam("deviceId") String deviceId , + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Restrat Browser : " + deviceId); + + try { + sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT,""); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + + } + + } + + /** + * Close the running browser in the given digital display. + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + */ + @Path("/close-browser") + @POST + public void closeBrowser(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Close Browser : " + deviceId); + + try { + sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.CLOSE_BROWSER_CONSTANT ,""); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Terminate all running processes. If this execute we have to reboot digital display manually. + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + */ + @Path("/terminate-display") + @POST + public void terminateDisplay(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Terminate Display : " + deviceId); + + try { + sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT,""); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Restart python server in given digital display + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + */ + @Path("/restart-display") + @POST + public void restartDisplay(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Restrat Display : " + deviceId); + + try { + sendCommandViaMQTT(owner,deviceId,randomId +":" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT ,""); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Search through the sequence and edit requested resource + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + * @param path page no need to change + * @param attribute this can be path,time or type + * @param newValue page is used to replace path + */ + @Path("/edit-content/{path}/{attribute}/{new-value}") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void editContent(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @PathParam("path") String path, + @PathParam("attribute") String attribute, + @PathParam("new-value") String newValue, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Edit Content Display Id - " + deviceId + " by " + owner); + + try { + String params = path + File.separator + attribute + File.separator + newValue; + sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT,params); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Add new resource end to the existing sequence + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + * @param type type of new resource + * @param time new resource visible time + * @param path URL of the new resource + */ + @Path("/add-resource/{type}/{time}/{path}") + @POST + public void addNewResource(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @PathParam("type") String type, + @PathParam("time") String time, + @PathParam("path") String path, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Add Sequence : " + deviceId); + + try { + String params = type + File.separator + time + File.separator + path; + sendCommandViaMQTT(owner,deviceId,randomId + ":" + + DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + } + + /** + * Add new resource to sequence before given page no + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + * @param type type of the new resource + * @param time new resource visible time + * @param path URL of the new resource + * @param nextPage next page no of after adding new resource + */ + @Path("/add-resource-before/{type}/{time}/{path}/{next-page}") + @POST + public void addNewResourceBefore(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @PathParam("type") String type, + @PathParam("time") String time, + @PathParam("path") String path, + @PathParam("next-page") String nextPage, + @Context HttpServletResponse response){ + + log.info("Add Sequence : " + deviceId); + + try { + String params = type + File.separator + time + File.separator + path + + File.separator + "before=" + nextPage; + sendCommandViaMQTT(owner,deviceId,randomId + ":" + + DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + } + + + /** + * Add new resource to sequence after given page + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + * @param type type of the new resource + * @param time new resource visible time + * @param path URL of the new resource + * @param beforePage before page no of after adding new resource + */ + @Path("/add-resource-next/{type}/{time}/{path}/{before-page}") + @POST + public void addNewResourceAfter(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @PathParam("type") String type, + @PathParam("time") String time, + @PathParam("path") String path, + @PathParam("before-page") String beforePage, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Add Sequence : " + deviceId); + + try { + String params = type + File.separator + time + File.separator + path + + File.separator + "after=" + beforePage; + sendCommandViaMQTT(owner,deviceId,randomId + ":" + + DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT,params); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + } + + /** + * Delete a resource in sequence + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + * @param path path of the page no need to delete + */ + @Path("/remove-resource/{path}") + @DELETE + @Produces(MediaType.APPLICATION_JSON) + public void removeResource(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @PathParam("path") String path, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Remove Resource : " + deviceId); + + try { + sendCommandViaMQTT(owner,deviceId,randomId + ":" + + DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT,path); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Remove directory and whole content + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + * @param directoryName path of the folder need to delete + */ + @Path("/remove-directory/{directory-name}") + @DELETE + @Produces(MediaType.APPLICATION_JSON) + public void removeDirectory(@PathParam("directory-name") String directoryName, + @QueryParam("deviceId") String deviceId , + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Remove Directory : " + deviceId); + try { + sendCommandViaMQTT(owner,deviceId,randomId + ":" + + DigitalDisplayConstants.REMOVE_DIRECTORY_CONSTANT,directoryName); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Remove content from www folder + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param directoryName path of directory of request file contain + * @param content file name of need to delete + * @param response response type of the method + */ + @Path("/remove-content/{directory_name}/{content}") + @DELETE + @Produces(MediaType.APPLICATION_JSON) + public void removeContent(@PathParam("directory_name") String directoryName, + @PathParam("content") String content, + @QueryParam("deviceId") String deviceId , + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Remove Content : " + deviceId); + try { + String param = directoryName + File.separator + content; + sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.REMOVE_CONTENT_CONSTANT,param); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Stop specific display + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + */ + @Path("/shutdown-display") + @POST + public void shutDownDisplay(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Shut down display : " + deviceId); + + try { + sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.SHUTDOWN_DISPLAY_CONSTANT,""); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Check specific digital display power ON of OFF + * + * @param deviceId id of the controlling digital display + * @param owner owner of the digital display + * @param randomId web socket id of the method invoke client + * @param response response type of the method + */ + @Path("/get-status") + @GET + public void getStatus(@QueryParam("deviceId") String deviceId, + @QueryParam("owner") String owner, + @QueryParam("randomId") String randomId, + @Context HttpServletResponse response){ + + log.info("Status : " + deviceId); + + try { + sendCommandViaMQTT(owner,deviceId,randomId + ":" + DigitalDisplayConstants.GET_STATUS_CONSTANT,""); + response.setStatus(Response.Status.OK.getStatusCode()); + } catch (DeviceManagementException e) { + log.error(e); + response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); + }catch (DigitalDisplayException e){ + log.error(e); + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + } + + /** + * Send message via MQTT protocol + * + * @param deviceOwner owner of target digital display + * @param deviceId id of the target digital display + * @param operation operation need to execute + * @param param parameters need to given operation + * @throws DeviceManagementException + * @throws DigitalDisplayException + */ + private void sendCommandViaMQTT(String deviceOwner, String deviceId, String operation, + String param) throws DeviceManagementException, DigitalDisplayException { + + log.info(deviceOwner); + String topic = String.format(DigitalDisplayConstants.PUBLISH_TOPIC , deviceOwner , deviceId); + String payload = operation + ":" + param; + + try { + digitalDisplayMqttCommunicationHandler.publishToDigitalDisplay(topic, payload, 2, true); + } catch (CommunicationHandlerException e) { + String errorMessage = "Error publishing data to device with ID " + deviceId; + throw new DigitalDisplayException(errorMessage,e); + } + } + +} 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/DigitalDisplayManagerService.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/DigitalDisplayManagerService.java new file mode 100644 index 0000000000..3a4e9063dd --- /dev/null +++ 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/DigitalDisplayManagerService.java @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.iot.DeviceManagement; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; +import org.wso2.carbon.device.mgt.iot.util.ZipArchive; +import org.wso2.carbon.device.mgt.iot.util.ZipUtil; + +import javax.jws.WebService; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Date; +import java.util.UUID; + +@WebService +public class DigitalDisplayManagerService { + + private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class); + //TODO; replace this tenant domain + private final String SUPER_TENANT = "carbon.super"; + @Context //injected response proxy supporting multiple thread + private HttpServletResponse response; + + @Path("/device/register") + @PUT + public boolean register(@QueryParam("deviceId") String deviceId, + @QueryParam("name") String name, @QueryParam("owner") String owner ) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + try { + if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) { + response.setStatus(Response.Status.CONFLICT.getStatusCode()); + return false; + } + + Device device = new Device(); + device.setDeviceIdentifier(deviceId); + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); + enrolmentInfo.setDateOfEnrolment(new Date().getTime()); + enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); + enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); + device.setEnrolmentInfo(enrolmentInfo); + device.setName(name); + device.setType(DigitalDisplayConstants.DEVICE_TYPE); + enrolmentInfo.setOwner(owner); + enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); + boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device); + + if (added) { + response.setStatus(Response.Status.OK.getStatusCode()); + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + + + } + + return added; + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return false; + } finally { + deviceManagement.endTenantFlow(); + } + } + + @Path("/device/remove/{device_id}") + @DELETE + public void removeDevice(@PathParam("device_id") String deviceId, + @Context HttpServletResponse response) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + + try { + boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice( + deviceIdentifier); + if (removed) { + response.setStatus(Response.Status.OK.getStatusCode()); + + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + + } + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } finally { + deviceManagement.endTenantFlow(); + } + + + } + + @Path("/device/update/{device_id}") + @POST + public boolean updateDevice(@PathParam("device_id") String deviceId, + @QueryParam("name") String name, + @Context HttpServletResponse response) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + + try { + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); + device.setDeviceIdentifier(deviceId); + + // device.setDeviceTypeId(deviceTypeId); + device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); + + device.setName(name); + device.setType(DigitalDisplayConstants.DEVICE_TYPE); + + boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( + device); + + + if (updated) { + response.setStatus(Response.Status.OK.getStatusCode()); + + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + + } + return updated; + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return false; + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("/device/{device_id}") + @GET + @Consumes("application/json") + @Produces("application/json") + public Device getDevice(@PathParam("device_id") String deviceId) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); + + try { + Device device = deviceManagement.getDeviceManagementService().getDevice( + deviceIdentifier); + + return device; + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return null; + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("/device/{sketch_type}/download") + @GET + @Produces("application/octet-stream") + public Response downloadSketch(@QueryParam("owner") String owner, + @QueryParam("deviceName") String customDeviceName, + @PathParam("sketch_type") String + sketchType) { + + if (owner == null) { + return Response.status(400).build();//bad request + } + + //create new device id + String deviceId = shortUUID(); + + //create token + String token = UUID.randomUUID().toString(); + String refreshToken = UUID.randomUUID().toString(); + //adding registering data + + String deviceName = customDeviceName + "_" + deviceId; + boolean status = register(deviceId, customDeviceName, owner); + if (!status) { + return Response.status(500).entity( + "Error occurred while registering the device with " + "id: " + deviceId + + " owner:" + owner).build(); + + } + + ZipUtil ziputil = new ZipUtil(); + ZipArchive zipFile = null; + try { + zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, customDeviceName, token, refreshToken); + } catch (DeviceManagementException ex) { + return Response.status(500).entity("Error occurred while creating zip file").build(); + } + + Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); + rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); + return rb.build(); + } + + private static String shortUUID() { + UUID uuid = UUID.randomUUID(); + long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); + return Long.toString(l, Character.MAX_RADIX); + } + +} 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/dto/DeviceJSON.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/dto/DeviceJSON.java new file mode 100644 index 0000000000..08979a267b --- /dev/null +++ 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/dto/DeviceJSON.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.dto; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement + +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeviceJSON { + @XmlElement(required = true) public String owner; + @XmlElement(required = true) public String deviceId; + @XmlElement(required = true) public String reply; +} 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/exception/DigitalDisplayException.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/exception/DigitalDisplayException.java new file mode 100644 index 0000000000..d5c33a6346 --- /dev/null +++ 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/exception/DigitalDisplayException.java @@ -0,0 +1,44 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.exception; + +/** + * Created by nuwan on 12/2/15. + */ +public class DigitalDisplayException extends Exception { + + private static final long serialVersionUID = 2736466230451105441L; + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public DigitalDisplayException(String msg, DigitalDisplayException nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public DigitalDisplayException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public DigitalDisplayException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public DigitalDisplayException() { + super(); + } + + public DigitalDisplayException(Throwable cause) { + super(cause); + } + + +} 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/transport/CommunicationHandler.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/transport/CommunicationHandler.java new file mode 100644 index 0000000000..9c165fef62 --- /dev/null +++ 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/transport/CommunicationHandler.java @@ -0,0 +1,15 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport; + +public interface CommunicationHandler { + int DEFAULT_TIMEOUT_INTERVAL = 5000; // millis ~ 10 sec + + void connect(); + + boolean isConnected(); + + void processIncomingMessage(T message, String... messageParams); + + void processIncomingMessage(); + + void disconnect(); +} 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/transport/CommunicationHandlerException.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/transport/CommunicationHandlerException.java new file mode 100644 index 0000000000..447ae6f1b1 --- /dev/null +++ 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/transport/CommunicationHandlerException.java @@ -0,0 +1,38 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport; + +public class CommunicationHandlerException extends Exception { + private static final long serialVersionUID = 2736466230451105440L; + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public CommunicationHandlerException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public CommunicationHandlerException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public CommunicationHandlerException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public CommunicationHandlerException() { + super(); + } + + public CommunicationHandlerException(Throwable cause) { + super(cause); + } +} 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/transport/MQTTCommunicationHandler.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/transport/MQTTCommunicationHandler.java new file mode 100644 index 0000000000..c441f892c5 --- /dev/null +++ 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/transport/MQTTCommunicationHandler.java @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.paho.client.mqttv3.*; + +import java.io.File; +import java.nio.charset.StandardCharsets; + +/** + * This class contains the IoT-Server specific implementation for all the MQTT functionality. + * This includes connecting to a MQTT Broker & subscribing to the appropriate MQTT-topic, action + * plan upon losing connection or successfully delivering a message to the broker and processing + * incoming messages. Makes use of the 'Paho-MQTT' library provided by Eclipse Org. + *

+ * It is an abstract class that implements the common interface "CommunicationHandler" and the + * "MqttCallback". Whilst providing some methods which handle key MQTT relevant tasks, this class + * implements only the most generic methods of the "CommunicationHandler" interface. The rest of + * the methods are left for any extended concrete-class to implement as per its need. + */ +public abstract class MQTTCommunicationHandler + implements MqttCallback, CommunicationHandler { + private static final Log log = LogFactory.getLog(MQTTCommunicationHandler.class); + + public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0; + + private MqttClient client; + private String clientId; + private MqttConnectOptions options; + private String clientWillTopic; + + protected String mqttBrokerEndPoint; + protected int timeoutInterval; + protected String subscribeTopic; + + /** + * Constructor for the MQTTCommunicationHandler which takes in the owner, type of the device + * and the MQTT Broker URL and the topic to subscribe. + * + * @param deviceOwner the owner of the device. + * @param deviceType the CDMF Device-Type of the device. + * @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint. + * @param subscribeTopic the MQTT topic to which the client is to be subscribed + */ + protected MQTTCommunicationHandler(String deviceOwner, String deviceType, + String mqttBrokerEndPoint, + String subscribeTopic) { + this.clientId = deviceOwner + ":" + deviceType; + this.subscribeTopic = subscribeTopic; + this.clientWillTopic = deviceType + File.separator + "disconnection"; + this.mqttBrokerEndPoint = mqttBrokerEndPoint; + this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL; + this.initSubscriber(); + } + + /** + * Constructor for the MQTTCommunicationHandler which takes in the owner, type of the device + * and the MQTT Broker URL and the topic to subscribe. Additionally this constructor takes in + * the reconnection-time interval between successive attempts to connect to the broker. + * + * @param deviceOwner the owner of the device. + * @param deviceType the CDMF Device-Type of the device. + * @param mqttBrokerEndPoint the IP/URL of the MQTT broker endpoint. + * @param subscribeTopic the MQTT topic to which the client is to be subscribed + * @param intervalInMillis the time interval in MILLI-SECONDS between successive + * attempts to connect to the broker. + */ + protected MQTTCommunicationHandler(String deviceOwner, String deviceType, + String mqttBrokerEndPoint, String subscribeTopic, + int intervalInMillis) { + this.clientId = deviceOwner + ":" + deviceType; + this.subscribeTopic = subscribeTopic; + this.clientWillTopic = deviceType + File.separator + "disconnection"; + this.mqttBrokerEndPoint = mqttBrokerEndPoint; + this.timeoutInterval = intervalInMillis; + this.initSubscriber(); + } + + public void setTimeoutInterval(int timeoutInterval) { + this.timeoutInterval = timeoutInterval; + } + + /** + * Initializes the MQTT-Client. Creates a client using the given MQTT-broker endpoint and the + * clientId (which is constructed by a concatenation of [deviceOwner]:[deviceType]). Also sets + * the client's options parameter with the clientWillTopic (in-case of connection failure) and + * other info. Also sets the call-back this current class. + */ + private void initSubscriber() { + try { + + client = new MqttClient(this.mqttBrokerEndPoint, clientId, null); + log.info("MQTT subscriber was created with ClientID : " + clientId); + } catch (MqttException ex) { + String errorMsg = "MQTT Client Error\n" + "\tReason: " + ex.getReasonCode() + + "\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " + + ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() + + "\n\tException: " + ex; + log.error(errorMsg); + } + + options = new MqttConnectOptions(); + options.setCleanSession(false); + options.setWill(clientWillTopic, "Connection-Lost".getBytes(StandardCharsets.UTF_8), 2, + true); + client.setCallback(this); + } + + /** + * Checks whether the connection to the MQTT-Broker persists. + * + * @return true if the client is connected to the MQTT-Broker, else false. + */ + @Override + public boolean isConnected() { + return client.isConnected(); + } + + + /** + * Connects to the MQTT-Broker and if successfully established connection. + * + * @throws CommunicationHandlerException in the event of 'Connecting to' the MQTT broker fails. + */ + protected void connectToQueue() throws CommunicationHandlerException { + try { + client.connect(options); + + if (log.isDebugEnabled()) { + log.debug("Subscriber connected to queue at: " + this.mqttBrokerEndPoint); + } + } catch (MqttSecurityException ex) { + String errorMsg = "MQTT Security Exception when connecting to queue\n" + "\tReason: " + + " " + + ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() + + "\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " + + ex.getCause() + "\n\tException: " + ex; + if (log.isDebugEnabled()) { + log.debug(errorMsg); + } + throw new CommunicationHandlerException(errorMsg, ex); + + } catch (MqttException ex) { + String errorMsg = "MQTT Exception when connecting to queue\n" + "\tReason: " + + ex.getReasonCode() + "\n\tMessage: " + ex.getMessage() + + "\n\tLocalMsg: " + ex.getLocalizedMessage() + "\n\tCause: " + + ex.getCause() + "\n\tException: " + ex; + if (log.isDebugEnabled()) { + log.debug(errorMsg); + } + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + /** + * Subscribes to the MQTT-Topic specific to this MQTT Client. (The MQTT-Topic specific to the + * device is taken in as a constructor parameter of this class) . + * + * @throws CommunicationHandlerException in the event of 'Subscribing to' the MQTT broker + * fails. + */ + protected void subscribeToQueue() throws CommunicationHandlerException { + try { + client.subscribe(subscribeTopic, 0); + log.info("Subscriber '" + clientId + "' subscribed to topic: " + subscribeTopic); + } catch (MqttException ex) { + String errorMsg = "MQTT Exception when trying to subscribe to topic: " + + subscribeTopic + "\n\tReason: " + ex.getReasonCode() + + "\n\tMessage: " + ex.getMessage() + "\n\tLocalMsg: " + + ex.getLocalizedMessage() + "\n\tCause: " + ex.getCause() + + "\n\tException: " + ex; + if (log.isDebugEnabled()) { + log.debug(errorMsg); + } + + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + + /** + * This method is used to publish reply-messages for the control signals received. + * Invocation of this method calls its overloaded-method with a QoS equal to that of the + * default value. + * + * @param topic the topic to which the reply message is to be published. + * @param payLoad the reply-message (payload) of the MQTT publish action. + */ + protected void publishToQueue(String topic, String payLoad) + throws CommunicationHandlerException { + publishToQueue(topic, payLoad, DEFAULT_MQTT_QUALITY_OF_SERVICE, false); + } + + /** + * This is an overloaded method that publishes MQTT reply-messages for control signals + * received form the IoT-Server. + * + * @param topic the topic to which the reply message is to be published + * @param payLoad the reply-message (payload) of the MQTT publish action. + * @param qos the Quality-of-Service of the current publish action. + * Could be 0(At-most once), 1(At-least once) or 2(Exactly once) + */ + protected void publishToQueue(String topic, String payLoad, int qos, boolean retained) + throws CommunicationHandlerException { + try { + client.publish(topic, payLoad.getBytes(StandardCharsets.UTF_8), qos, retained); + if (log.isDebugEnabled()) { + log.debug("Message: " + payLoad + " to MQTT topic [" + topic + + "] published successfully"); + } + } catch (MqttException ex) { + String errorMsg = + "MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " + + ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() + + "\n\tCause: " + ex.getCause() + "\n\tException: " + ex; + log.info(ex); + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + + protected void publishToQueue(String topic, MqttMessage message) + throws CommunicationHandlerException { + try { + client.publish(topic, message); + if (log.isDebugEnabled()) { + log.debug("Message: " + message.toString() + " to MQTT topic [" + topic + + "] published successfully"); + } + } catch (MqttException ex) { + String errorMsg = + "MQTT Client Error" + "\n\tReason: " + ex.getReasonCode() + "\n\tMessage: " + + ex.getMessage() + "\n\tLocalMsg: " + ex.getLocalizedMessage() + + "\n\tCause: " + ex.getCause() + "\n\tException: " + ex; + log.info(errorMsg); + throw new CommunicationHandlerException(errorMsg, ex); + } + } + + + /** + * Callback method which is triggered once the MQTT client losers its connection to the broker. + * Spawns a new thread that executes necessary actions to try and reconnect to the endpoint. + * + * @param throwable a Throwable Object containing the details as to why the failure occurred. + */ + @Override + public void connectionLost(Throwable throwable) { + log.warn("Lost Connection for client: " + this.clientId + + " to " + this.mqttBrokerEndPoint + ".\nThis was due to - " + + throwable.getMessage()); + + + Thread reconnectThread = new Thread() { + public void run() { + connect(); + } + }; + reconnectThread.setDaemon(true); + reconnectThread.start(); + } + + /** + * Callback method which is triggered upon receiving a MQTT Message from the broker. Spawns a + * new thread that executes any actions to be taken with the received message. + * + * @param topic the MQTT-Topic to which the received message was published to and the + * client was subscribed to. + * @param mqttMessage the actual MQTT-Message that was received from the broker. + */ + @Override + public void messageArrived(final String topic, final MqttMessage mqttMessage) { + if (log.isDebugEnabled()) { + log.info("Got an MQTT message '" + mqttMessage.toString() + "' for topic '" + topic + + "'."); + } + + Thread messageProcessorThread = new Thread() { + public void run() { + processIncomingMessage(mqttMessage, topic); + } + }; + messageProcessorThread.setDaemon(true); + messageProcessorThread.start(); + } + + /** + * Callback method which gets triggered upon successful completion of a message delivery to + * the broker. + * + * @param iMqttDeliveryToken the MQTT-DeliveryToken which includes the details about the + * specific message delivery. + */ + @Override + public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { + String message = ""; + try { + if (iMqttDeliveryToken.isComplete()) { + if (iMqttDeliveryToken.getMessage() != null){ + message = iMqttDeliveryToken.getMessage().toString(); + } + } else { + log.error("MQTT Message not delivered"); + } + } catch (MqttException e) { + log.error( + "Error occurred whilst trying to read the message from the MQTT delivery token."); + } + String topic = iMqttDeliveryToken.getTopics()[0]; + String client = iMqttDeliveryToken.getClient().getClientId(); + + if (log.isDebugEnabled()) { + log.debug("Message - '" + message + "' of client [" + client + "] for the topic (" + + topic + ") was delivered successfully."); + } + } + + /** + * Closes the connection to the MQTT Broker. + */ + public void closeConnection() throws MqttException { + if (client != null && isConnected()) { + client.disconnect(); + } + } +} + 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/util/DigitalDisplayMqttCommunicationHandler.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/util/DigitalDisplayMqttCommunicationHandler.java new file mode 100644 index 0000000000..3c545a58fb --- /dev/null +++ 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/util/DigitalDisplayMqttCommunicationHandler.java @@ -0,0 +1,145 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.CommunicationHandlerException; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.MQTTCommunicationHandler; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.websocket.DigitalDisplayWebSocketServerEndPoint; + +import java.io.File; +import java.util.UUID; +import java.util.concurrent.ScheduledFuture; + + +/** + * Created by nuwan on 11/16/15. + */ + +public class DigitalDisplayMqttCommunicationHandler extends MQTTCommunicationHandler { + + private static Log log = LogFactory.getLog(DigitalDisplayMqttCommunicationHandler.class); + + private static final String subscribeTopic = + "wso2"+ File.separator+"iot"+File.separator+"+"+File.separator+ + DigitalDisplayConstants.DEVICE_TYPE+File.separator+"+"+File.separator+ + "digital_display_publisher"; + + private static String iotServerSubscriber = UUID.randomUUID().toString().substring(0,5); + + private ScheduledFuture dataPushServiceHandler; + + private DigitalDisplayMqttCommunicationHandler() { + super(iotServerSubscriber, DigitalDisplayConstants.DEVICE_TYPE, + MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic); + } + + public ScheduledFuture getDataPushServiceHandler() { + return dataPushServiceHandler; + } + + @Override + public void connect() { + Runnable connect = new Runnable() { + @Override + public void run() { + while (!isConnected()){ + try { + log.info("Trying to Connect.."); + connectToQueue(); + subscribeToQueue(); + + } catch (CommunicationHandlerException e) { + log.warn("Connection/Subscription to MQTT Broker at: " + + mqttBrokerEndPoint + " failed"); + + try { + Thread.sleep(timeoutInterval); + } catch (InterruptedException ex) { + log.error("MQTT-Subscriber: Thread Sleep Interrupt Exception"); + } + } + } + + log.info("Connected.."); + + } + }; + + Thread connectorThread = new Thread(connect); + connectorThread.setDaemon(true); + connectorThread.start(); + + } + + @Override + public void processIncomingMessage(MqttMessage message, String... messageParams) { + + String topic = messageParams[0]; + + String ownerAndId = topic.replace("wso2"+File.separator+"iot"+File.separator,""); + ownerAndId = ownerAndId.replace(File.separator+ DigitalDisplayConstants.DEVICE_TYPE+File.separator,":"); + ownerAndId = ownerAndId.replace(File.separator+"digital_display_publisher",""); + + String owner = ownerAndId.split(":")[0]; + String deviceId = ownerAndId.split(":")[1]; + + String [] messageData = message.toString().split(":"); + + + log.info("Received MQTT message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}"); + + if(messageData.length == 3){ + String randomId = messageData[0]; + String requestMessage = messageData[1]; + String result = messageData[2]; + log.info("Return result " + result + " for Request " + requestMessage); + DigitalDisplayWebSocketServerEndPoint.sendMessage(randomId, result); + } + + } + + @Override + public void processIncomingMessage() { + + } + + public void publishToDigitalDisplay(String topic, String payLoad, int qos, boolean retained) throws CommunicationHandlerException { + log.info(topic + " " + payLoad); + publishToQueue(topic, payLoad, qos, retained); + } + + @Override + public void disconnect() { + Runnable stopConnection = new Runnable() { + public void run() { + while (isConnected()) { + try { + dataPushServiceHandler.cancel(true); + closeConnection(); + + } catch (MqttException e) { + if (log.isDebugEnabled()) { + log.warn("Unable to 'STOP' MQTT connection at broker at: " + + mqttBrokerEndPoint); + } + + try { + Thread.sleep(timeoutInterval); + } catch (InterruptedException e1) { + log.error("MQTT-Terminator: Thread Sleep Interrupt Exception"); + } + } + } + } + }; + + Thread terminatorThread = new Thread(stopConnection); + terminatorThread.setDaemon(true); + terminatorThread.start(); + } + +} 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/websocket/DigitalDisplayWebSocketServerEndPoint.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/websocket/DigitalDisplayWebSocketServerEndPoint.java new file mode 100644 index 0000000000..da49ebe17b --- /dev/null +++ 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/websocket/DigitalDisplayWebSocketServerEndPoint.java @@ -0,0 +1,74 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.api.websocket; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.inject.Singleton; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + + +@ServerEndpoint(value = "/digital-display-server-end-point") +@Singleton +public class DigitalDisplayWebSocketServerEndPoint { + + private static Log log = LogFactory.getLog(DigitalDisplayWebSocketServerEndPoint.class); + + private static Map clientSessions = new HashMap<>(); + + /** + * This method will be invoked when a client requests for a + * WebSocket connection. + * + * @param userSession the userSession which is opened. + */ + @OnOpen + public void onOpen(Session userSession){ + UUID uuid = UUID.randomUUID(); + log.info("Generated Random Id " + uuid.toString()); + log.info(" Connected with Session Id : " + userSession.getId()); + clientSessions.put(uuid.toString() , userSession); + userSession.getAsyncRemote().sendText("RandomID:" + uuid.toString()); + } + + /** + * This method will be invoked when a client closes a WebSocket + * connection. + * + * @param userSession the userSession which is opened. + */ + @OnClose + public void onClose(Session userSession){ + log.info("Client disconnected - Session Id : " + userSession.getId()); + clientSessions.values().remove(userSession); + + } + + @OnError + public void onError(Throwable t){ + log.error("Error occurred " + t ); + } + + /** + * This method will be invoked when a message received from device + * to send client. + * + * @param randomId the client of message to be sent. + * @param message the message sent by device to client + */ + public static void sendMessage(String randomId , String message){ + if(clientSessions.keySet().contains(randomId)){ + clientSessions.get(randomId).getAsyncRemote().sendText(message); + log.info("Message : " + message + " send to Session Id : " + randomId); + }else { + log.error("Client already disconnected."); + } + } + +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 0000000000..fa44619195 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,33 @@ + + + + + + + + + false + + + CXF,Carbon + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 0000000000..cf04c1c49c --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..5d7b23a701 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,38 @@ + + + + Digital-Display-Agent-Webapp + + JAX-WS/JAX-RS MDM Android Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + 1 + + + CXFServlet + /* + + + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/pom.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/pom.xml new file mode 100644 index 0000000000..353353ad25 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/pom.xml @@ -0,0 +1,108 @@ + + + + + device-mgt-iot-digitaldisplay + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.digitaldisplay + 1.9.2-SNAPSHOT + bundle + WSO2 Carbon - IoT Server DigitalDisplay Management Plugin + WSO2 Carbon - Digital Display Management/Control Plugin Implementation + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + maven-compiler-plugin + + 1.7 + 1.7 + + 2.3.2 + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.iot.device.mgt.version} + IoT Server Impl Bundle + org.wso2.carbon.device.mgt.iot.digitaldisplay.internal + + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + javax.xml.bind.*, + javax.naming, + javax.sql, + javax.xml.bind.annotation.*, + javax.xml.parsers, + javax.net, + javax.net.ssl, + org.w3c.dom, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.common, + org.wso2.carbon.context.*, + org.wso2.carbon.ndatasource.core, + org.wso2.carbon.device.mgt.iot.*, + + + + !org.wso2.carbon.device.mgt.iot.digitaldisplay.internal, + org.wso2.carbon.device.mgt.iot.digitaldisplay.* + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + + org.wso2.carbon + org.wso2.carbon.logging + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot + + + + + \ No newline at end of file diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/constants/DigitalDisplayConstants.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/constants/DigitalDisplayConstants.java new file mode 100644 index 0000000000..d73335ca73 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/constants/DigitalDisplayConstants.java @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.constants; + +public class DigitalDisplayConstants { + + public final static String DEVICE_TYPE = "digital_display"; + public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME"; + public final static String DEVICE_PLUGIN_DEVICE_ID = "DIGITAL_DISPLAY_DEVICE_ID"; + + public final static String MQTT_BROKER_END_POINT = "tcp://204.232.188.214:1883"; + + public final static String SHUTDOWN_DISPLAY_CONSTANT = "shutdown_display"; + public final static String RESTART_DISPLAY_CONSTANT = "restart_display"; + public final static String REMOVE_DIRECTORY_CONSTANT = "remove_dir_and_content"; + public final static String REMOVE_CONTENT_CONSTANT = "remove_content"; + public final static String CLOSE_BROWSER_CONSTANT = "close_browser"; + public final static String RESTART_BROWSER_CONSTANT = "restart_browser"; + public final static String TERMINATE_DISPLAY_CONSTANT = "terminate_display"; + public final static String EDIT_SEQUENCE_CONSTANT = "edit_content_config"; + public final static String ADD_NEW_RESOURCE_CONSTANT = "add_new_resource"; + public final static String REMOVE_RESOURCE_CONSTANT = "remove_resources"; + public final static String GET_STATUS_CONSTANT = "get_status"; + + public final static String PUBLISH_TOPIC = "wso2/iot/%s/digital_display/%s/digital_display_subscriber"; + +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/DigitalDisplayManager.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/DigitalDisplayManager.java new file mode 100644 index 0000000000..e78d672c50 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/DigitalDisplayManager.java @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.DigitalDisplayDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactoryInterface; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil; + +import java.util.ArrayList; +import java.util.List; + + +/** + * This represents the DigitalDisplay implementation of DeviceManagerService. + */ +public class DigitalDisplayManager implements DeviceManager { + + private static final IotDeviceManagementDAOFactoryInterface iotDeviceManagementDAOFactory = new DigitalDisplayDAO(); + private static final Log log = LogFactory.getLog(DigitalDisplayManager.class); + + + + @Override + public FeatureManager getFeatureManager() { + return null; + } + + @Override + public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + throws DeviceManagementException { + //TODO implement this + return false; + } + + @Override + public TenantConfiguration getConfiguration() throws DeviceManagementException { + //TODO implement this + return null; + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Enrolling a new DigitalDisplay device : " + device.getDeviceIdentifier()); + } + DigitalDisplayDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO().addIotDevice( + iotDevice); + DigitalDisplayDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + DigitalDisplayDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while enrolling the DigitalDisplay device : " + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Modifying the DigitalDisplay device enrollment data"); + } + DigitalDisplayDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .updateIotDevice(iotDevice); + DigitalDisplayDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + DigitalDisplayDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the update device transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while updating the enrollment of the DigitalDisplay device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling DigitalDisplay device : " + deviceId); + } + DigitalDisplayDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .deleteIotDevice(deviceId.getId()); + DigitalDisplayDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + DigitalDisplayDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while removing the DigitalDisplay device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean isEnrolled = false; + try { + if (log.isDebugEnabled()) { + log.debug("Checking the enrollment of DigitalDisplay device : " + deviceId.getId()); + } + IotDevice iotDevice = + iotDeviceManagementDAOFactory.getIotDeviceDAO().getIotDevice( + deviceId.getId()); + if (iotDevice != null) { + isEnrolled = true; + } + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while checking the enrollment status of DigitalDisplay device : " + + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return isEnrolled; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + Device device; + try { + if (log.isDebugEnabled()) { + log.debug("Getting the details of DigitalDisplay device : " + deviceId.getId()); + } + IotDevice iotDevice = iotDeviceManagementDAOFactory.getIotDeviceDAO(). + getIotDevice(deviceId.getId()); + device = IotDeviceManagementUtil.convertToDevice(iotDevice); + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while fetching the DigitalDisplay device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return device; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; + } + + public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + + @Override + public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, + EnrolmentInfo.Status status) throws DeviceManagementException { + return false; + } + + @Override + public License getLicense(String s) throws LicenseManagementException { + return null; + } + + @Override + public void addLicense(License license) throws LicenseManagementException { + + } + + @Override + public boolean requireDeviceAuthorization() { + return true; + } + + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug( + "updating the details of DigitalDisplay device : " + deviceIdentifier); + } + DigitalDisplayDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .updateIotDevice(iotDevice); + DigitalDisplayDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + DigitalDisplayDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the update device info transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = + "Error while updating the DigitalDisplay device : " + deviceIdentifier; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + List devices = null; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all DigitalDisplay devices"); + } + List iotDevices = + iotDeviceManagementDAOFactory.getIotDeviceDAO().getAllIotDevices(); + if (iotDevices != null) { + devices = new ArrayList(); + for (IotDevice iotDevice : iotDevices) { + devices.add(IotDeviceManagementUtil.convertToDevice(iotDevice)); + } + } + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while fetching all DigitalDisplay devices."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return devices; + } + +} \ No newline at end of file diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/DigitalDisplayManagerService.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/DigitalDisplayManagerService.java new file mode 100644 index 0000000000..a6c92ce138 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/DigitalDisplayManagerService.java @@ -0,0 +1,90 @@ +package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; + +import java.util.List; + +public class DigitalDisplayManagerService implements DeviceManagementService{ + private DeviceManager deviceManager; + @Override + public String getType() { + return DigitalDisplayConstants.DEVICE_TYPE; + } + + @Override + public String getProviderTenantDomain() { + return "carbon.super"; + } + + @Override + public boolean isSharedWithAllTenants() { + return true; + } + + @Override + public String[] getSharedTenantsDomain() { + return new String[0]; + } + + @Override + public void init() throws DeviceManagementException { + deviceManager= new DigitalDisplayManager(); + } + + @Override + public DeviceManager getDeviceManager() { + return deviceManager; + } + + @Override + public ApplicationManager getApplicationManager() { + return null; + } + + @Override + public void notifyOperationToDevices(Operation operation, List list) throws DeviceManagementException { + + } + + @Override + public Application[] getApplications(String domain, int pageNumber, int size) + throws ApplicationManagementException { + return new Application[0]; + } + + @Override + public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, + String status) throws ApplicationManagementException { + + } + + @Override + public String getApplicationStatus(DeviceIdentifier deviceId, Application application) + throws ApplicationManagementException { + return null; + } + + @Override + public void installApplicationForDevices(Operation operation, List list) throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUsers(Operation operation, List list) throws ApplicationManagementException { + + } + + @Override + public void installApplicationForUserRoles(Operation operation, List list) throws ApplicationManagementException { + + } + +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/dao/DigitalDisplayDAO.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/dao/DigitalDisplayDAO.java new file mode 100644 index 0000000000..10f5e1fd17 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/dao/DigitalDisplayDAO.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +*/ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactoryInterface; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.impl.DigitalDisplayDeviceDAOImpl; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + +public class DigitalDisplayDAO extends IotDeviceManagementDAOFactory + implements IotDeviceManagementDAOFactoryInterface { + + private static final Log log = LogFactory.getLog(DigitalDisplayDAO.class); + static DataSource dataSource; // package local variable + private static ThreadLocal currentConnection = new ThreadLocal(); + + public DigitalDisplayDAO() { + initDigitalDisplayDAO(); + } + + @Override + public IotDeviceDAO getIotDeviceDAO() { + return new DigitalDisplayDeviceDAOImpl(); + } + + public static void initDigitalDisplayDAO(){ + dataSource = getDataSourceMap().get(DigitalDisplayConstants.DEVICE_TYPE); + } + + public static void beginTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = dataSource.getConnection(); + conn.setAutoCommit(false); + currentConnection.set(conn); + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); + } + } + + public static Connection getConnection() throws IotDeviceManagementDAOException { + if (currentConnection.get() == null) { + try { + currentConnection.set(dataSource.getConnection()); + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while retrieving data source connection", + e); + } + } + return currentConnection.get(); + } + + public static void commitTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.commit(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence commit " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while committing the transaction", e); + } finally { + closeConnection(); + } + } + + public static void closeConnection() throws IotDeviceManagementDAOException { + + Connection con = currentConnection.get(); + if(con != null){ + try { + con.close(); + } catch (SQLException e) { + log.error("Error occurred while close the connection"); + } + } + currentConnection.remove(); + } + + public static void rollbackTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.rollback(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence rollback " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while rollback the transaction", e); + } finally { + closeConnection(); + } + } +} \ No newline at end of file diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/dao/impl/DigitalDisplayDeviceDAOImpl.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/dao/impl/DigitalDisplayDeviceDAOImpl.java new file mode 100644 index 0000000000..fb29027063 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/dao/impl/DigitalDisplayDeviceDAOImpl.java @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.dao.DigitalDisplayDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.util.IotDeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Implements IotDeviceDAO for digital display Devices. + */ +public class DigitalDisplayDeviceDAOImpl implements IotDeviceDAO { + + + private static final Log log = LogFactory.getLog(DigitalDisplayDeviceDAOImpl.class); + + @Override + public IotDevice getIotDevice(String iotDeviceId) + throws IotDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + IotDevice iotDevice = null; + ResultSet resultSet = null; + try { + conn = DigitalDisplayDAO.getConnection(); + String selectDBQuery = + "SELECT DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME" + + " FROM DIGITAL_DISPLAY_DEVICE WHERE DIGITAL_DISPLAY_DEVICE_ID = ?"; + stmt = conn.prepareStatement(selectDBQuery); + stmt.setString(1, iotDeviceId); + resultSet = stmt.executeQuery(); + + if (resultSet.next()) { + iotDevice = new IotDevice(); + iotDevice.setIotDeviceName(resultSet.getString( + DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_NAME)); + Map propertyMap = new HashMap(); + + + + iotDevice.setDeviceProperties(propertyMap); + + if (log.isDebugEnabled()) { + log.debug("Digital Display device " + iotDeviceId + " data has been fetched from " + + "Digital Display database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while fetching Digital Display device : '" + iotDeviceId + "'"; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); + DigitalDisplayDAO.closeConnection(); + } + + return iotDevice; + } + + @Override + public boolean addIotDevice(IotDevice iotDevice) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = DigitalDisplayDAO.getConnection(); + String createDBQuery = + "INSERT INTO DIGITAL_DISPLAY_DEVICE(DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)"; + + stmt = conn.prepareStatement(createDBQuery); + stmt.setString(1, iotDevice.getIotDeviceId()); + stmt.setString(2,iotDevice.getIotDeviceName()); + if (iotDevice.getDeviceProperties() == null) { + iotDevice.setDeviceProperties(new HashMap()); + } + + + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Digital Display device " + iotDevice.getIotDeviceId() + " data has been" + + " added to the Digital Display database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while adding the Digital Display device '" + + iotDevice.getIotDeviceId() + "' to the Digital Display db."; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean updateIotDevice(IotDevice iotDevice) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = DigitalDisplayDAO.getConnection(); + String updateDBQuery = + "UPDATE DIGITAL_DISPLAY_DEVICE SET DEVICE_NAME = ? WHERE DIGITAL_DISPLAY_DEVICE_ID = ?"; + + stmt = conn.prepareStatement(updateDBQuery); + + if (iotDevice.getDeviceProperties() == null) { + iotDevice.setDeviceProperties(new HashMap()); + } + stmt.setString(1, iotDevice.getIotDeviceName()); + + stmt.setString(2, iotDevice.getIotDeviceId()); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Digital Display device " + iotDevice.getIotDeviceId() + " data has been" + + " modified."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while modifying the Digital Display device '" + + iotDevice.getIotDeviceId() + "' data."; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean deleteIotDevice(String iotDeviceId) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = DigitalDisplayDAO.getConnection(); + String deleteDBQuery = + "DELETE FROM DIGITAL_DISPLAY_DEVICE WHERE DIGITAL_DISPLAY_DEVICE_ID = ?"; + stmt = conn.prepareStatement(deleteDBQuery); + stmt.setString(1, iotDeviceId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Digital Display device " + iotDeviceId + " data has deleted" + + " from the Digital Display database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while deleting Digital Display device " + iotDeviceId; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public List getAllIotDevices() + throws IotDeviceManagementDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + IotDevice iotDevice; + List iotDevices = new ArrayList(); + + try { + conn = DigitalDisplayDAO.getConnection(); + String selectDBQuery = + "SELECT DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME " + + "FROM DIGITAL_DISPLAY_DEVICE"; + stmt = conn.prepareStatement(selectDBQuery); + resultSet = stmt.executeQuery(); + while (resultSet.next()) { + iotDevice = new IotDevice(); + iotDevice.setIotDeviceId(resultSet.getString(DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_ID)); + iotDevice.setIotDeviceName(resultSet.getString(DigitalDisplayConstants.DEVICE_PLUGIN_DEVICE_NAME)); + + Map propertyMap = new HashMap(); + + iotDevice.setDeviceProperties(propertyMap); + iotDevices.add(iotDevice); + } + if (log.isDebugEnabled()) { + log.debug("All Digital Display device details have fetched from Digital Display database."); + } + return iotDevices; + } catch (SQLException e) { + String msg = "Error occurred while fetching all Digital Display device data'"; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); + DigitalDisplayDAO.closeConnection(); + } + + } + + } \ No newline at end of file diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/util/DigitalDisplayUtils.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/util/DigitalDisplayUtils.java new file mode 100644 index 0000000000..5d39df7db4 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/impl/util/DigitalDisplayUtils.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Map; + +/** + * Contains utility methods used by Digital Display plugin. + */ +public class DigitalDisplayUtils { + + private static Log log = LogFactory.getLog(DigitalDisplayUtils.class); + + public static String getDeviceProperty(Map deviceProperties, String property) { + + String deviceProperty = deviceProperties.get(property); + + if (deviceProperty == null) { + return ""; + } + + return deviceProperty; + } + + +} diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/internal/DigitalDisplayManagementServiceComponent.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/internal/DigitalDisplayManagementServiceComponent.java new file mode 100644 index 0000000000..baab247ecf --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/internal/DigitalDisplayManagementServiceComponent.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.digitaldisplay.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.iot.digitaldisplay.impl.DigitalDisplayManagerService; +import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService; + +/** + * @scr.component name="org.wso2.carbon.device.mgt.iot.digitaldisplay.internal.DigitalDisplayManagementServiceComponent" + * immediate="true" + * @scr.reference name="org.wso2.carbon.device.mgt.iot.service.DeviceTypeService" + * interface="org.wso2.carbon.device.mgt.iot.service.DeviceTypeService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDeviceTypeService" + * unbind="unsetDeviceTypeService" + */ + +public class DigitalDisplayManagementServiceComponent { + + + private ServiceRegistration digitalDisplayServiceRegRef; + + + + private static final Log log = LogFactory.getLog(DigitalDisplayManagementServiceComponent.class); + + protected void activate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("Activating Digital Display Management Service Component"); + } + try { + BundleContext bundleContext = ctx.getBundleContext(); + + + digitalDisplayServiceRegRef = + bundleContext.registerService(DeviceManagementService.class.getName(), new + DigitalDisplayManagerService(), + null); + + + + if (log.isDebugEnabled()) { + log.debug("Digital Display Management Service Component has been successfully activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Digital Display Management Service Component", e); + } + } + + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("De-activating DigitalDisplay Management Service Component"); + } + try { + if (digitalDisplayServiceRegRef != null) { + digitalDisplayServiceRegRef.unregister(); + } + + if (log.isDebugEnabled()) { + log.debug( + "DigitalDisplay Management Service Component has been successfully de-activated"); + } + } catch (Throwable e) { + log.error("Error occurred while de-activating Iot Device Management bundle", e); + } + } + + + protected void setDeviceTypeService(DeviceTypeService deviceTypeService) { + /* This is to avoid this component getting initialized before the + common registered */ + if (log.isDebugEnabled()) { + log.debug("Data source service set to mobile service component"); + } + } + + protected void unsetDeviceTypeService(DeviceTypeService deviceTypeService) { + //do nothing + } + + + + +} diff --git a/components/device-mgt-iot-digitaldisplay/pom.xml b/components/device-mgt-iot-digitaldisplay/pom.xml new file mode 100644 index 0000000000..945e867aa8 --- /dev/null +++ b/components/device-mgt-iot-digitaldisplay/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + + org.wso2.carbon.devicemgt-plugins + carbon-device-mgt-plugins-parent + 1.9.2-SNAPSHOT + ../../pom.xml + + + device-mgt-iot-digitaldisplay + 1.9.2-SNAPSHOT + pom + WSO2 Carbon - IoT Device DigitalDisplay Management Component + http://wso2.org + + + org.wso2.carbon.device.mgt.iot.digitaldisplay + org.wso2.carbon.device.mgt.iot.digitaldisplay.api + + + + + + + org.apache.felix + maven-scr-plugin + 1.7.2 + + + generate-scr-scrdescriptor + + scr + + + + + + + + + \ No newline at end of file diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/pom.xml b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/pom.xml new file mode 100644 index 0000000000..e73df653a8 --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/pom.xml @@ -0,0 +1,129 @@ + + + + + org.wso2.carbon.devicemgt-plugins + device-mgt-iot-digitaldisplay-feature + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.digitaldisplay.feature + pom + 1.9.2-SNAPSHOT + WSO2 Carbon - IoT Server DigitalDisplay Feature + http://wso2.org + This feature contains the DigitalDisplay Device type specific implementations for the IoT Server + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay + 1.9.2-SNAPSHOT + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay.api + 1.9.2-SNAPSHOT + war + + + + + + + + maven-resources-plugin + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-jaxrs-war + package + + copy + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay.api + + war + true + ${basedir}/src/main/resources/webapps/ + digital_display.war + + + + + + + + + org.wso2.maven + carbon-p2-plugin + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.device.mgt.iot.digitaldisplay + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.iot.digitaldisplay:${carbon.iot.device.mgt.version} + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version} + + + + + + + + + + \ 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/agent/deviceConfig.properties b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/deviceConfig.properties new file mode 100644 index 0000000000..a189416d5f --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/deviceConfig.properties @@ -0,0 +1,29 @@ +# +# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +#[Device-Configurations] +owner=${DEVICE_OWNER} +deviceId=${DEVICE_ID} +device-name=${DEVICE_NAME} +controller-context=/digital_display/controller +mqtt-ep=${MQTT_EP} +auth-method=token +auth-token=${DEVICE_TOKEN} +refresh-token=${DEVICE_REFRESH_TOKEN} +push-interval=15 + + diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/sketch.properties b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/sketch.properties new file mode 100644 index 0000000000..e794c19425 --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/sketch.properties @@ -0,0 +1,2 @@ +templates=deviceConfig.properties +zipfilename=DigitalDisplayAgent.zip diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/start-device.sh b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/start-device.sh new file mode 100755 index 0000000000..e9dd87c48c --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/agent/start-device.sh @@ -0,0 +1,190 @@ +#!/bin/bash + +echo "----------------------------------------------------------------" +echo "| WSO2 IOT Sample " +echo "| Virtual RaspiAlarm " +echo "| ---------------- " +echo "| ....initializing startup-script " +echo "----------------------------------------------------------------" + +#while true; do +# read -p "What is the network-interface of your device that the Agent should use (find from ifconfig. ex: wlan0,en0,eth0..) > " interface +# +# echo "Setting the network-interface to " $interface +# sed s/^network-interface=.*/network-interface=$interface/ deviceConfig.properties > myTmp +# mv -f myTmp deviceConfig.properties +# break; +#done +# +#while true; do +# read -p "Whats the time-interval (in seconds) between successive Data-Pushes to the WSO2-IoT-Server (ex: '60' indicates 1 minute) > " interval +# +# if [ $interval -eq $interval 2>/dev/null ] +# then +# echo "Setting data-push interval to " $interval " seconds." +# sed s/^push-interval=.*/push-interval=$interval/ deviceConfig.properties > myTmp +# mv -f myTmp deviceConfig.properties +# break; +# else +# echo "Input needs to be an integer indicating the number seconds between successive data-pushes." +# fi +#done + + +#java -jar wso2-firealarm-virtual-agent-advanced.jar + +#while true; do +# read -p "Do you wish to run 'apt-get update' and continue? [Yes/No] " yn +# case $yn in +# [Yy]* ) sudo apt-get update; +# break;; +# [Nn]* ) echo "Continuing without apt-get update..."; +# break;; +# * ) echo "Please answer yes or no."; +# esac +#done +# +#if [ $? -ne 0 ]; then +# echo "apt-get update failed.... Some dependencies may not get installed" +# echo "If an already installed version of the package exists, try running:" +# echo "----------------------------------------------------------------" +# echo "sudo -i" +# echo "cd /var/lib/dpkg/info" +# echo "rm -rf wso2-raspi-alarm*" +# echo "dpkg --remove --force-remove-reinstreq wso2-raspi-alarm" +# echo "exit" +# echo "----------------------------------------------------------------" +# echo "Retry Installation...." +# break; +#fi +# +#echo "Installing 'gdebi' package..." +#sudo apt-get install gdebi # installation of gdebi +# +# +#if [ $? -ne 0 ]; then +# echo "gdebi installation failed.... dependencies will not be installed without gdebi" +# read -p "Do you wish to continue without gdebi? [Yes/No] " yn +# case $yn in +# [Yy]* ) echo "Continueing without gdebi.....";; +# [Nn]* ) echo "Try to resolve errors and re-run the script."; +# exit;; +# * ) exit;; +# esac +#fi +# +# +#for f in ./wso2-raspi-alarm_1.0_armhf.deb; do +# ## Check if the glob gets expanded to existing files. +# ## If not, f here will be exactly the pattern above +# ## and the exists test will evaluate to false. +# # [ -e "$f" ] && echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing" || echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path"; exit; +# if [ -e "$f" ]; then +# echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing now...." +# else +# echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path. \nExiting installation..."; +# exit; +# fi +# ## This is all we needed to know, so we can break after the first iteration +# break +#done +# +#echo "Installing the 'wso2-raspi-alarm deb package'" +#sudo gdebi wso2-raspi-alarm_1.0_armhf.deb +# +#if [ $? -ne 0 ]; then +# echo "Installation Failed...." +# exit; +#fi + +#sudo killall -9 python +# +#for f in ./RaspberryAgent.zip; do +# ## Check if the glob gets expanded to existing files. +# ## If not, f here will be exactly the pattern above +# ## and the exists test will evaluate to false. +# # [ -e "$f" ] && echo "'wso2-raspi-alarm_1.0_armhf.deb' file found and installing" || echo "'wso2-raspi-alarm_1.0_armhf.deb' file does not exist in current path"; exit; +# if [ -e "$f" ]; then +# echo "Agent files found......" +# sudo rm -rf /usr/local/src/RaspberryAgent +# sudo unzip RaspberryAgent.zip -d /usr/local/src/ +# else +# echo "'RaspberryAgent.zip' file does not exist in current path. \nInstalling without upgrading agent..."; +# fi +# ## This is all we needed to know, so we can break after the first iteration +# break +#done +# +#for f in /usr/local/src/RaspberryAgent/rc.local; do +# ## Check if the glob gets expanded to existing files. +# ## If not, f here will be exactly the pattern above +# ## and the exists test will evaluate to false. +# if [ -e "$f" ]; then +# echo "Copying boot script" +# sudo mv /usr/local/src/RaspberryAgent/rc.local /etc/rc.local +# sudo chmod +x /etc/rc.local +# else +# echo "Unable to set agent statup on boot"; +# fi +# ## This is all we needed to know, so we can break after the first iteration +# break +#done +# +#for f in ./deviceConfigs.cfg; do +# ## Check if the glob gets expanded to existing files. +# ## If not, f here will be exactly the pattern above +# ## and the exists test will evaluate to false. +# if [ -e "$f" ]; then +# echo "Configuration file found......" +# else +# echo "'deviceConfigs.cfg' file does not exist in current path. \nExiting installation..."; +# exit; +# fi +# ## This is all we needed to know, so we can break after the first iteration +# break +#done +# +#echo "Altering Configuration file" +#sed -i 's|[/,]||g' deviceConfigs.cfg +# +#echo "Copying configurations file to /usr/local/src/RaspberryAgent" +#sudo cp ./deviceConfigs.cfg /usr/local/src/RaspberryAgent/ +# +#if [ $? -ne 0 ]; then +# echo "Copying configuration file failed...." +# exit; +#fi +# +#while true; do +# read -p "Whats the time-interval (in seconds) between successive Data-Pushes to the WSO2-DC (ex: '60' indicates 1 minute) > " input +# +# if [ $input -eq $input 2>/dev/null ] +# then +# echo "Setting data-push interval to $input seconds." +# echo $input > /usr/local/src/RaspberryAgent/time-interval +# break; +# else +# echo "Input needs to be an integer indicating the number seconds between successive data-pushes." +# fi +#done +# +#cd /usr/local/src/RaspberryAgent/ +#sudo chmod +x RaspberryStats.py +#sudo nohup ./RaspberryStats.py -i $input +

+ {{unit "cdmf.unit.device.overview.digital-display-image"}} +
+
+
Device Overview - Digital Display
+ {{#defineZone "device-detail-properties"}} + + + + + + {{#if device.viewModel.udid}} + + {{/if}} + {{#if device.viewModel.phoneNumber}} + + {{/if}} + + + + + +
Device{{device.viewModel.vendor}} {{device.properties.model}}
Model{{device.viewModel.model}}
IMEI{{device.viewModel.imei}}
UDID{{device.viewModel.udid}}
Phone Number{{device.viewModel.phoneNumber}}
Status + {{#equal device.status "ACTIVE"}} Active{{/equal}} + {{#equal device.status "INACTIVE"}} Inactive{{/equal}} + {{#equal device.status "BLOCKED"}} Blocked{{/equal}} + {{#equal device.status "REMOVED"}} Removed{{/equal}} +
+ {{/defineZone}} +
Operations
+
+ {{unit "cdmf.unit.device.iot-operation" deviceType=device.type}} +
+
+ \ 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/jaggerryapps/devicemgt/app/units/iot.unit.device.digitaldisplay-overview/digitaldisplay-overview.js b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggerryapps/devicemgt/app/units/iot.unit.device.digitaldisplay-overview/digitaldisplay-overview.js new file mode 100644 index 0000000000..b9bffdecd8 --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggerryapps/devicemgt/app/units/iot.unit.device.digitaldisplay-overview/digitaldisplay-overview.js @@ -0,0 +1,25 @@ +function onRequest (context) { + var log = new Log("detail.js"); + var deviceType = request.getParameter("type"); + var deviceId = request.getParameter("id"); + + if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { + var deviceModule = require("/modules/device.js").deviceModule; + var device = deviceModule.viewDevice(deviceType, deviceId); + + if (device) { + var viewModel = {}; + var deviceInfo = device.properties.DEVICE_INFO; + if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) { + deviceInfo = parse(stringify(deviceInfo)); + viewModel.system = device.properties.IMEI; + viewModel.machine = "Digital Display"; + viewModel.vendor = device.properties.VENDOR; + } + device.viewModel = viewModel; + } + context.device = device; + + return context; + } +} \ 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/jaggerryapps/devicemgt/app/units/iot.unit.device.digitaldisplay-overview/digitaldisplay-overview.json b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggerryapps/devicemgt/app/units/iot.unit.device.digitaldisplay-overview/digitaldisplay-overview.json new file mode 100644 index 0000000000..688e939808 --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggerryapps/devicemgt/app/units/iot.unit.device.digitaldisplay-overview/digitaldisplay-overview.json @@ -0,0 +1,3 @@ +{ + "version": "1.0.0" +} \ 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/p2.inf b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..3cd8cd0fb9 --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/p2.inf @@ -0,0 +1,9 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/sketches/);\ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/sketches/digitaldisplay/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/agent/,target:${installFolder}/../../resources/sketches/digitaldisplay/,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/digitaldisplay,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.digitaldisplay_${feature.version}/jaggerryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\ diff --git a/features/device-mgt-iot-digitaldisplay-feature/pom.xml b/features/device-mgt-iot-digitaldisplay-feature/pom.xml new file mode 100644 index 0000000000..a06cd450ef --- /dev/null +++ b/features/device-mgt-iot-digitaldisplay-feature/pom.xml @@ -0,0 +1,24 @@ + + + + + org.wso2.carbon.devicemgt-plugins + carbon-device-mgt-plugins-parent + 1.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + device-mgt-iot-digitaldisplay-feature + 1.9.2-SNAPSHOT + pom + WSO2 Carbon - IoT Server DigitalDisplay Device Feature + http://wso2.org + + + org.wso2.carbon.device.mgt.iot.digitaldisplay.feature + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index bece7c29fd..450af4c8f9 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ components/device-mgt-iot-virtualfirealarm + components/device-mgt-iot-digitaldisplay components/device-mgt-iot-androidsense components/device-mgt-iot-droneanalyzer @@ -61,6 +62,7 @@ features/device-mgt-iot-virtualfirealarm-feature + features/device-mgt-iot-digitaldisplay-feature features/device-mgt-iot-androidsense-feature features/device-mgt-iot-droneanalyzer-feature @@ -420,6 +422,18 @@ + + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.digitaldisplay + ${carbon.iot.device.mgt.version} + provided + + + org.json.wso2 json