private TransferJob updateDefaultJobIfNeeded()

in src/main/java/com/google/gcs/sdrs/service/worker/rule/impl/StsRuleExecutor.java [394:454]


  private TransferJob updateDefaultJobIfNeeded(
      TransferJob existingTransferJob,
      RetentionRule defaultRule,
      List<String> prefixesToExclude,
      String description)
      throws IOException {

    if (existingTransferJob == null) {
      return null;
    }
    TransferSpec transferSpec = existingTransferJob.getTransferSpec();
    ObjectConditions objectConditions = transferSpec.getObjectConditions();
    if (objectConditions == null) {
      objectConditions = new ObjectConditions();
      transferSpec.setObjectConditions(objectConditions);
    }

    // make sure transfer options are set properly
    transferSpec.setTransferOptions(
        new TransferOptions()
            .setDeleteObjectsFromSourceAfterTransfer(true)
            .setOverwriteObjectsAlreadyExistingInSink(true));

    boolean retentionPeriodChanged = false;
    boolean prefixesToExcludeChanged = false;

    TransferJob updatedJob = existingTransferJob;

    // Check if retention period changed
    String existingRetention = objectConditions.getMinTimeElapsedSinceLastModification();
    String updatedRetention =
        StsUtil.convertRetentionInDaysToDuration(
            RetentionValue.convertValue(RetentionValue.parse(defaultRule.getRetentionValue())));

    if (existingRetention == null || !existingRetention.equals(updatedRetention)) {
      objectConditions.setMinTimeElapsedSinceLastModification(updatedRetention);
      retentionPeriodChanged = true;
    }

    // check if prefixes to exclude changed
    List<String> existingExcludePrefixList = objectConditions.getExcludePrefixes();
    List<String> updatedPrefixesToExclude = prefixesToExclude;

    if (!isSamePrefixList(existingExcludePrefixList, updatedPrefixesToExclude)) {
      objectConditions.setExcludePrefixes(updatedPrefixesToExclude);
      prefixesToExcludeChanged = true;
    }

    // only update if the retention period or prefix list has changed
    if (retentionPeriodChanged || prefixesToExcludeChanged) {
      // Build transfer job object
      updatedJob = new TransferJob();
      updatedJob.setName(existingTransferJob.getName());
      updatedJob.setDescription(description);
      updatedJob.setTransferSpec(transferSpec);
      updatedJob.setStatus("ENABLED");
      StsUtil.updateExistingJob(
          client, updatedJob, existingTransferJob.getName(), existingTransferJob.getProjectId());
    }
    return updatedJob;
  }