Example #1
0
  @GET
  @Path("non-compliant-by-feature")
  public Response getNonCompliantDeviceCountsByFeatures(
      @QueryParam("start-index") int startIndex, @QueryParam("result-count") int resultCount) {
    Message message = new Message();
    if (startIndex < 0) {
      message.setErrorMessage("Invalid start index.");
      message.setDescription("Start index cannot be less than 0.");
      return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
    }

    if (resultCount < 5) {
      message.setErrorMessage("Invalid request count.");
      message.setDescription("Requested result count should be 5 or more than that.");
      return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
    }

    GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService();
    DashboardPaginationGadgetDataWrapper dashboardPaginationGadgetDataWrapper =
        new DashboardPaginationGadgetDataWrapper();

    PaginationResult paginationResult =
        gadgetDataService.getNonCompliantDeviceCountsByFeatures(
            new PaginationRequest(startIndex, resultCount));

    if (paginationResult == null) {
      return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
    }

    Map<String, Object> nonCompliantDeviceCountByFeatureDataWrapper;
    List<Map<String, Object>> nonCompliantDeviceCountsByFeaturesDataWrapper = new ArrayList<>();
    for (Object listElement : paginationResult.getData()) {
      Map entry = (Map<?, ?>) listElement;
      nonCompliantDeviceCountByFeatureDataWrapper = new LinkedHashMap<>();
      nonCompliantDeviceCountByFeatureDataWrapper.put("group", entry.get("FEATURE_CODE"));
      nonCompliantDeviceCountByFeatureDataWrapper.put("label", entry.get("FEATURE_CODE"));
      nonCompliantDeviceCountByFeatureDataWrapper.put("count", entry.get("DEVICE_COUNT"));
      nonCompliantDeviceCountsByFeaturesDataWrapper.add(
          nonCompliantDeviceCountByFeatureDataWrapper);
    }

    dashboardPaginationGadgetDataWrapper.setContext("non-compliant-feature");
    dashboardPaginationGadgetDataWrapper.setData(nonCompliantDeviceCountsByFeaturesDataWrapper);
    dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());

    List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
    responsePayload.add(dashboardPaginationGadgetDataWrapper);

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