示例#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();
  }
示例#2
0
  @GET
  @Path("feature-non-compliant-devices-with-details")
  public Response getFeatureNonCompliantDevicesWithDetails(
      @QueryParam("non-compliant-feature") String nonCompliantFeature,
      @QueryParam("platform") String platform,
      @QueryParam("ownership") String ownership,
      @QueryParam("pagination-enabled") String paginationEnabled,
      @QueryParam("start-index") int startIndex,
      @QueryParam("result-count") int resultCount) {

    Message message = new Message();
    if (nonCompliantFeature == null || paginationEnabled == null) {

      message.setErrorMessage("Missing required query parameters.");
      message.setDescription(
          "non-compliant-feature with some text value and "
              + "pagination-enabled with value true or false are required.");
      return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();

    } else if ("true".equals(paginationEnabled)) {

      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 < 10) {
        message.setErrorMessage("Invalid request count.");
        message.setDescription("Requested result count should be equal to 10 or more than that.");
        return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
      }

      Map<String, Object> filters = new LinkedHashMap<>();
      if (platform != null) {
        if ("android".equals(platform) || "ios".equals(platform) || "windows".equals(platform)) {
          filters.put("PLATFORM", platform);
        } else {
          message.setErrorMessage("Invalid value for platform query parameter.");
          message.setDescription(
              "platform query parameter value could only be either android, ios or windows.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (ownership != null) {
        if ("BYOD".equals(ownership) || "COPE".equals(ownership)) {
          filters.put("OWNERSHIP", ownership);
        } else {
          message.setErrorMessage("Invalid value for ownership query parameter.");
          message.setDescription(
              "ownership query parameter value could only be either BYOD or COPE.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

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

      PaginationResult paginationResult =
          gadgetDataService.getFeatureNonCompliantDevicesWithDetails(
              nonCompliantFeature, filters, new PaginationRequest(startIndex, resultCount));

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

      Map<String, Object> featureNonCompliantDeviceDetailEntryDataWrapper;
      List<Map<String, Object>> featureNonCompliantDeviceDetailEntriesDataWrapper =
          new ArrayList<>();
      for (Object listElement : paginationResult.getData()) {
        Map entry = (Map<?, ?>) listElement;
        featureNonCompliantDeviceDetailEntryDataWrapper = new LinkedHashMap<>();
        featureNonCompliantDeviceDetailEntryDataWrapper.put("device-id", entry.get("device-id"));
        featureNonCompliantDeviceDetailEntryDataWrapper.put("platform", entry.get("platform"));
        featureNonCompliantDeviceDetailEntryDataWrapper.put("ownership", entry.get("ownership"));
        featureNonCompliantDeviceDetailEntryDataWrapper.put(
            "connectivity-details", entry.get("connectivity-details"));
        featureNonCompliantDeviceDetailEntriesDataWrapper.add(
            featureNonCompliantDeviceDetailEntryDataWrapper);
      }

      dashboardPaginationGadgetDataWrapper.setContext("feature-non-compliant-device-details");
      dashboardPaginationGadgetDataWrapper.setData(
          featureNonCompliantDeviceDetailEntriesDataWrapper);
      dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());

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

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

    } else if ("false".equals(paginationEnabled)) {

      Map<String, Object> filters = new LinkedHashMap<>();
      if (platform != null) {
        if ("android".equals(platform) || "ios".equals(platform) || "windows".equals(platform)) {
          filters.put("PLATFORM", platform);
        } else {
          message.setErrorMessage("Invalid value for platform query parameter.");
          message.setDescription(
              "platform query parameter value could only be either android, ios or windows.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (ownership != null) {
        if ("BYOD".equals(ownership) || "COPE".equals(ownership)) {
          filters.put("OWNERSHIP", ownership);
        } else {
          message.setErrorMessage("Invalid value for ownership query parameter.");
          message.setDescription(
              "ownership query parameter value could only be either BYOD or COPE.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService();
      DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();

      List<Map<String, Object>> featureNonCompliantDevicesWithDetails =
          gadgetDataService.getFeatureNonCompliantDevicesWithDetails(nonCompliantFeature, filters);

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

      dashboardGadgetDataWrapper.setContext("feature-non-compliant-device-details");
      dashboardGadgetDataWrapper.setData(featureNonCompliantDevicesWithDetails);

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

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

    } else {

      message.setErrorMessage("Invalid query parameter value.");
      message.setDescription(
          "Invalid value for "
              + "query parameter pagination-enabled. Should be either true or false.");
      return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
    }
  }
示例#3
0
  @GET
  @Path("filtered-devices-with-details")
  public Response getFilteredDevicesWithDetails(
      @QueryParam("connectivity-status") String connectivityStatus,
      @QueryParam("potential-vulnerability") String potentialVulnerability,
      @QueryParam("platform") String platform,
      @QueryParam("ownership") String ownership,
      @QueryParam("pagination-enabled") String paginationEnabled,
      @QueryParam("start-index") int startIndex,
      @QueryParam("result-count") int resultCount) {

    Message message = new Message();
    if (paginationEnabled == null) {

      message.setErrorMessage("Missing required query parameter.");
      message.setDescription(
          "Pagination-enabled query parameter with value true or false is required.");
      return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();

    } else if ("true".equals(paginationEnabled)) {

      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 < 10) {
        message.setErrorMessage("Invalid request count.");
        message.setDescription("Requested result count should be equal to 10 or more than that.");
        return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
      }

      Map<String, Object> filters = new LinkedHashMap<>();
      if (connectivityStatus != null) {
        if ("ACTIVE".equals(connectivityStatus)
            || "INACTIVE".equals(connectivityStatus)
            || "REMOVED".equals(connectivityStatus)) {
          filters.put("CONNECTIVITY_STATUS", connectivityStatus);
        } else {
          message.setErrorMessage("Invalid value for connectivity-status query parameter.");
          message.setDescription(
              "connectivity-status query parameter value could only be either ACTIVE, INACTIVE or REMOVED.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (potentialVulnerability != null) {
        if ("non-compliant".equals(potentialVulnerability)
            || "unmonitored".equals(potentialVulnerability)) {
          if ("non-compliant".equals(potentialVulnerability)) {
            filters.put("IS_COMPLIANT", 0);
          } else {
            filters.put("POLICY_ID", -1);
          }
        } else {
          message.setErrorMessage("Invalid value for potential-vulnerability query parameter.");
          message.setDescription(
              "potential-vulnerability query parameter value could only be either non-compliant or unmonitored.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (platform != null) {
        if ("android".equals(platform) || "ios".equals(platform) || "windows".equals(platform)) {
          filters.put("PLATFORM", platform);
        } else {
          message.setErrorMessage("Invalid value for platform query parameter.");
          message.setDescription(
              "platform query parameter value could only be either android, ios or windows.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (ownership != null) {
        if ("BYOD".equals(ownership) || "COPE".equals(ownership)) {
          filters.put("OWNERSHIP", ownership);
        } else {
          message.setErrorMessage("Invalid value for ownership query parameter.");
          message.setDescription(
              "ownership query parameter value could only be either BYOD or COPE.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

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

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

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

      Map<String, Object> deviceDetailEntryDataWrapper;
      List<Map<String, Object>> deviceDetailEntriesDataWrapper = new ArrayList<>();
      for (Object listElement : paginationResult.getData()) {
        Map entry = (Map<?, ?>) listElement;
        deviceDetailEntryDataWrapper = new LinkedHashMap<>();
        deviceDetailEntryDataWrapper.put("device-id", entry.get("device-id"));
        deviceDetailEntryDataWrapper.put("platform", entry.get("platform"));
        deviceDetailEntryDataWrapper.put("ownership", entry.get("ownership"));
        deviceDetailEntryDataWrapper.put("connectivity-details", entry.get("connectivity-details"));
        deviceDetailEntriesDataWrapper.add(deviceDetailEntryDataWrapper);
      }

      dashboardPaginationGadgetDataWrapper.setContext("filtered-device-details");
      dashboardPaginationGadgetDataWrapper.setData(deviceDetailEntriesDataWrapper);
      dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());

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

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

    } else if ("false".equals(paginationEnabled)) {

      Map<String, Object> filters = new LinkedHashMap<>();
      if (connectivityStatus != null) {
        if ("ACTIVE".equals(connectivityStatus)
            || "INACTIVE".equals(connectivityStatus)
            || "REMOVED".equals(connectivityStatus)) {
          filters.put("CONNECTIVITY_STATUS", connectivityStatus);
        } else {
          message.setErrorMessage("Invalid value for connectivity-status query parameter.");
          message.setDescription(
              "connectivity-status query parameter value could only be either ACTIVE, INACTIVE or REMOVED.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (potentialVulnerability != null) {
        if ("non-compliant".equals(potentialVulnerability)
            || "unmonitored".equals(potentialVulnerability)) {
          if ("non-compliant".equals(potentialVulnerability)) {
            filters.put("IS_COMPLIANT", 0);
          } else {
            filters.put("POLICY_ID", -1);
          }
        } else {
          message.setErrorMessage("Invalid value for potential-vulnerability query parameter.");
          message.setDescription(
              "potential-vulnerability query parameter value could only be either non-compliant or unmonitored.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (platform != null) {
        if ("android".equals(platform) || "ios".equals(platform) || "windows".equals(platform)) {
          filters.put("PLATFORM", platform);
        } else {
          message.setErrorMessage("Invalid value for platform query parameter.");
          message.setDescription(
              "platform query parameter value could only be either android, ios or windows.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      if (ownership != null) {
        if ("BYOD".equals(ownership) || "COPE".equals(ownership)) {
          filters.put("OWNERSHIP", ownership);
        } else {
          message.setErrorMessage("Invalid value for ownership query parameter.");
          message.setDescription(
              "ownership query parameter value could only be either BYOD or COPE.");
          return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
        }
      }

      GadgetDataService gadgetDataService = MDMAPIUtils.getGadgetDataService();
      DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();

      List<Map<String, Object>> devicesWithDetails =
          gadgetDataService.getDevicesWithDetails(filters);

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

      dashboardGadgetDataWrapper.setContext("device-details");
      dashboardGadgetDataWrapper.setData(devicesWithDetails);

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

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

    } else {

      message.setErrorMessage("Invalid query parameter value.");
      message.setDescription(
          "Invalid value for "
              + "query parameter pagination-enabled. Should be either true or false.");
      return Response.status(HttpStatus.SC_BAD_REQUEST).entity(message).build();
    }
  }