public List validateRetentionJobs()

in src/main/java/com/google/gcs/sdrs/service/worker/rule/impl/StsRuleValidator.java [92:135]


  public List<RetentionJobValidation> validateRetentionJobs(List<RetentionJob> jobs) {

    if (jobs.size() == 0) {
      return new ArrayList<>();
    }

    HashMap<String, Set<Integer>> jobIdStsIdMap = new HashMap<>();

    // Get the first project ID. All jobs to validate must have the same project ID.
    String projectId = jobs.get(0).getRetentionRuleProjectId();
    for (RetentionJob job : jobs) {
      if (!job.getRetentionRuleProjectId().equalsIgnoreCase(projectId)) {
        String message =
            String.format(
                "The list of jobs to validate contains multiple Project IDs:"
                    + "%s, %s. All retention jobs to validate must have the same project ID",
                projectId, job.getRetentionRuleProjectId());
        logger.error(message);
        throw new IllegalArgumentException(message);
      }
      // the job name that is required in the request has a different format than the response
      String stsJobId = job.getName().substring(job.getName().indexOf("/") + 1);
      if (jobIdStsIdMap.containsKey(stsJobId)) {
        jobIdStsIdMap.get(stsJobId).add(job.getId());
      } else {
        Set<Integer> retentionJobIdSet = new HashSet<>();
        retentionJobIdSet.add(job.getId());
        jobIdStsIdMap.put(stsJobId, retentionJobIdSet);
      }
    }

    List<Operation> jobOperations = StsUtil.getStsJobOperations(client, projectId, jobs);
    List<RetentionJobValidation> validationRecords = new ArrayList<>();
    for (Operation operation : jobOperations) {
      String stsJobId = extractStsJobId(operation.getName());
      jobIdStsIdMap.get(stsJobId).stream()
          .forEach(
              jobId -> {
                validationRecords.add(convertOperationToJobValidation(operation, jobId));
              });
    }

    return validationRecords;
  }