Example #1
0
  @GET
  @Path("overview-of-devices")
  public Response getOverviewDeviceCounts() {
    GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService();
    DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();

    // creating TotalDeviceCount Data Wrapper
    int totalDeviceCount = gadgetDataService.getTotalDeviceCount();
    if (totalDeviceCount == -1) {
      return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
    }
    Map<String, Object> totalDeviceCountDataWrapper = new LinkedHashMap<>();
    totalDeviceCountDataWrapper.put("group", "total");
    totalDeviceCountDataWrapper.put("label", "Total");
    totalDeviceCountDataWrapper.put("count", totalDeviceCount);

    // creating ActiveDeviceCount Data Wrapper
    int activeDeviceCount = gadgetDataService.getActiveDeviceCount();
    if (activeDeviceCount == -1) {
      return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
    }
    Map<String, Object> activeDeviceCountDataWrapper = new LinkedHashMap<>();
    activeDeviceCountDataWrapper.put("group", "active");
    activeDeviceCountDataWrapper.put("label", "Active");
    activeDeviceCountDataWrapper.put("count", activeDeviceCount);

    // creating inactiveDeviceCount Data Wrapper
    int inactiveDeviceCount = gadgetDataService.getInactiveDeviceCount();
    if (inactiveDeviceCount == -1) {
      return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
    }
    Map<String, Object> inactiveDeviceCountDataWrapper = new LinkedHashMap<>();
    inactiveDeviceCountDataWrapper.put("group", "inactive");
    inactiveDeviceCountDataWrapper.put("label", "Inactive");
    inactiveDeviceCountDataWrapper.put("count", inactiveDeviceCount);

    // creating removedDeviceCount Data Wrapper
    int removedDeviceCount = gadgetDataService.getRemovedDeviceCount();
    if (removedDeviceCount == -1) {
      return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
    }
    Map<String, Object> removedDeviceCountDataWrapper = new LinkedHashMap<>();
    removedDeviceCountDataWrapper.put("group", "removed");
    removedDeviceCountDataWrapper.put("label", "Removed");
    removedDeviceCountDataWrapper.put("count", removedDeviceCount);

    List<Map<String, Object>> overviewDeviceCountsDataWrapper = new ArrayList<>();
    overviewDeviceCountsDataWrapper.add(totalDeviceCountDataWrapper);
    overviewDeviceCountsDataWrapper.add(activeDeviceCountDataWrapper);
    overviewDeviceCountsDataWrapper.add(inactiveDeviceCountDataWrapper);
    overviewDeviceCountsDataWrapper.add(removedDeviceCountDataWrapper);

    dashboardGadgetDataWrapper.setContext("connectivity-status");
    dashboardGadgetDataWrapper.setData(overviewDeviceCountsDataWrapper);

    List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
    responsePayload.add(dashboardGadgetDataWrapper);

    return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
  }