diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml index f27cac0a5d..329fee5216 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/pom.xml @@ -129,6 +129,12 @@ provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.webapp.publisher + provided + + org.wso2.carbon org.wso2.carbon.utils @@ -214,6 +220,11 @@ org.wso2.carbon.apimgt.annotations provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.webapp.publisher + provided + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.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.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java index aab8a662d4..da05509b56 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.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.mgt.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java @@ -18,30 +18,36 @@ package org.wso2.carbon.device.mgt.iot.digitaldisplay.api; +import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.device.DeviceType; import org.wso2.carbon.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.apimgt.AccessTokenInfo; +import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; +import org.wso2.carbon.apimgt.webapp.publisher.KeyGenerationUtil; +import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipUtil; import org.wso2.carbon.device.mgt.iot.digitaldisplay.constants.DigitalDisplayConstants; -import javax.jws.WebService; 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.IOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.UUID; -@WebService +@DeviceType(value = "digital_display") public class DigitalDisplayManagerService { private static Log log = LogFactory.getLog(DigitalDisplayManagerService.class); @@ -50,12 +56,11 @@ public class DigitalDisplayManagerService { @Context //injected response proxy supporting multiple thread private HttpServletResponse response; - @Path("/device/register") + @Path("manager/device/register") @PUT public boolean register(@QueryParam("deviceId") String deviceId, - @QueryParam("name") String name, @QueryParam("owner") String owner ) { + @QueryParam("name") String name, @QueryParam("owner") String owner) { - log.info("Register call from " + owner); DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -73,19 +78,16 @@ public class DigitalDisplayManagerService { enrolmentInfo.setDateOfEnrolment(new Date().getTime()); enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); - device.setEnrolmentInfo(enrolmentInfo); + enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); device.setName(name); device.setType(DigitalDisplayConstants.DEVICE_TYPE); enrolmentInfo.setOwner(owner); - enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); + device.setEnrolmentInfo(enrolmentInfo); boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device); - if (added) { response.setStatus(Response.Status.OK.getStatusCode()); } else { response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); - - } return added; @@ -97,50 +99,43 @@ public class DigitalDisplayManagerService { } } - @Path("/device/remove/{device_id}") + @Path("manager/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId, - @Context HttpServletResponse response) { + @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}") + @Path("manager/device/update/{device_id}") @POST public boolean updateDevice(@PathParam("device_id") String deviceId, - @QueryParam("name") String name, - @Context HttpServletResponse response) { + @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 device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); device.setDeviceIdentifier(deviceId); // device.setDeviceTypeId(deviceTypeId); @@ -149,31 +144,27 @@ public class DigitalDisplayManagerService { device.setName(name); device.setType(DigitalDisplayConstants.DEVICE_TYPE); - boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( - device); - + 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()); + log.error(e.getErrorMessage()); return false; } finally { deviceManagement.endTenantFlow(); } - } - @Path("/device/{device_id}") + @Path("manager/device/{device_id}") @GET - @Consumes("application/json") - @Produces("application/json") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) public Device getDevice(@PathParam("device_id") String deviceId) { DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); @@ -182,59 +173,77 @@ public class DigitalDisplayManagerService { 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 deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + } catch (DeviceManagementException ex) { + log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex); return null; } finally { deviceManagement.endTenantFlow(); } - } - @Path("/device/{sketch_type}/download") + @Path("manager/device/{sketch_type}/download") @GET - @Produces("application/octet-stream") + @Produces(MediaType.APPLICATION_JSON) public Response downloadSketch(@QueryParam("owner") String owner, - @QueryParam("deviceName") String deviceName, - @PathParam("sketch_type") String - sketchType) { + @QueryParam("deviceName") String deviceName, + @PathParam("sketch_type") String + sketchType) { + + try { + ZipArchive zipFile = createDownloadFile(owner, deviceName, sketchType); + Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile())); + response.type("application/zip"); + response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); + return response.build(); + + } catch (IllegalArgumentException ex) { + return Response.status(400).entity(ex.getMessage()).build();//bad request + } catch (DeviceManagementException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (AccessTokenException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (DeviceControllerException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } catch (IOException ex) { + return Response.status(500).entity(ex.getMessage()).build(); + } + } + private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType) + throws DeviceManagementException, AccessTokenException, DeviceControllerException { if (owner == null) { - return Response.status(400).build();//bad request + throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!"); } //create new device id String deviceId = shortUUID(); + KeyGenerationUtil.createApplicationKeys("digital_display"); + + TokenClient accessTokenClient = new TokenClient(DigitalDisplayConstants.DEVICE_TYPE); + AccessTokenInfo accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); + //create token - String token = UUID.randomUUID().toString(); - String refreshToken = UUID.randomUUID().toString(); + String accessToken = accessTokenInfo.getAccess_token(); + String refreshToken = accessTokenInfo.getRefresh_token(); //adding registering data - boolean status = register(deviceId, deviceName, owner); - if (!status) { - return Response.status(500).entity( - "Error occurred while registering the device with " + "id: " + deviceId - + " owner:" + owner).build(); + boolean status; - } + //Register the device with CDMF + status = register(deviceId, deviceName, owner); - ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = null; - try { - zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, token, - refreshToken); - } catch (DeviceManagementException ex) { - return Response.status(500).entity("Error occurred while creating zip file").build(); + if (!status) { + String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner; + throw new DeviceManagementException(msg); } - Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); - rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); - return rb.build(); + ZipUtil ziputil = new ZipUtil(); + ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, + refreshToken); + zipFile.setDeviceId(deviceId); + return zipFile; } private static String shortUUID() { diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 09e7f4b066..8a58ec334c 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml index cd571f07d1..ed37125f12 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -25,9 +25,7 @@ JAX-WS/JAX-RS MDM Android Endpoint JAX-WS/JAX-RS Servlet CXFServlet - - org.apache.cxf.transport.servlet.CXFServlet - + org.apache.cxf.transport.servlet.CXFServlet 1 diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs index 56164fbb7e..f05daa49d2 100644 --- a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs +++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/type-view.hbs @@ -186,7 +186,7 @@
  • 03   Download Arduino-Sketch from - [Download] link above. + [Download Sketch] link above.
  • 04   Unzip the downloaded diff --git a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs index d6d30c132a..5174fea69c 100644 --- a/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs +++ b/features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs @@ -17,21 +17,21 @@

    What it Does


    Connect a Digital Message Display to WSO2 IoT Server and manage - it.

    + it.


    What You Need


    • ITEM 01   Raspberry - Pi with SD Card(Internet - Enabled [Wifi or Ethernet]). + Pi with SD Card(Internet + Enabled [Wifi or Ethernet]).
    • ITEM 02   A Digital Display with HDMI - Cable. + Cable.
    • STEP 03   Proceed - to [Prepare] section. + to [Prepare] section.

    @@ -61,7 +61,7 @@
    Download Now    Copy Link -    +   
    @@ -176,14 +176,14 @@
    • 01   Connect a monitor to your - RaspberryPi via HDMI cable. + RaspberryPi via HDMI cable.
    • 02   Configure - RaspberryPi to connect - to the Internet. + RaspberryPi to connect + to the Internet.
    • -
    • 03   Go ahead and [Download] the - Digital Display Agent. +
    • 03   Go ahead and [Download Agent] the + Digital Display Agent.
    • 04   Unzip downloaded agent.
    • @@ -210,16 +210,16 @@
      • 01   You can view - all your connected - devices at [Device - Management] - page. + Management] + page.
      • 02   Select one of - connected devices and check for - available - control operations. + connected devices and check for + available + control operations.

      diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs index 0748cdb853..5841dd6bd2 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/type-view.hbs @@ -18,20 +18,20 @@

      Connect an [IRIS+] Drone to WSO2 IoT Server - and visualize statistics.

      + and visualize statistics.


      What You Need


      • ITEM 01   IRIS+ - Drone. + Drone.
      • ITEM 02   USB to Micro USB cable or - Telemetry Radio receiver. + Telemetry Radio receiver.
      • STEP 03   Proceed - to [Prepare] + to [Prepare] section.

      @@ -164,17 +164,17 @@
      • 01   Connect your - IRIS+ Drone to your computer - using either USB to Micro USB - cable or - Telemetry Radio receiver. + IRIS+ Drone to your computer + using either USB to Micro USB + cable or + Telemetry Radio receiver.
      • 02   Click on - [Download] button - above to get IRIS+ Drone agent. + [Download Agent] button + above to get IRIS+ Drone agent.
      • 03   Use following - connection properties: + connection properties:
      • @@ -243,23 +243,23 @@
        • 01   You can view - all your connected - devices at [Device - Management] - page. + Management] + page.
        • 02   Select one of - connected devices and check for - available - control operations and monitor - Real-Time data. + connected devices and check for + available + control operations and monitor + Real-Time data.
        • 03   You can also - view analytics of - the data published to - IoT-Server by navigating - to Device Analytics page. + view analytics of + the data published to + IoT-Server by navigating + to Device Analytics page.

        diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs index 1a5fb8eea3..01957314d4 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/type-view.hbs @@ -183,7 +183,7 @@
      • 03   Download RaspberryPi Agent - via [Download] button above. + via [Download Agent] button above. (Alternatively you can use the "curl" command to directly download the Agent to your diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs index f20111f212..df161035cd 100644 --- a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/type-view.hbs @@ -16,33 +16,33 @@

        What it Does


        A Virtual Device that mimics the functionality of a real Firealarm. - Once run, the Virtual Firealarm will connect to WSO2 IoTServer and - push Temperature readings.

        + Once run, the Virtual Firealarm will connect to WSO2 IoTServer and + push Temperature readings.

        The device supports MQTT and XMPP Communications. It is configured to use MQTT by - default.

        + default.


        What You Need


        • STEP 01   Go ahead and [Download] the - Device. + Device.
        • STEP 02   Proceed - to [Prepare] - section. + to [Prepare] + section.
        • STEP 03   Read - [Try Out] section - to further experiment with the device. + [Try Out] section + to further experiment with the device.

        View API   - Download + Download Agent