private RetentionRule getExistingRule()

in src/main/java/com/google/gcs/sdrs/service/impl/RetentionRulesServiceImpl.java [111:141]


  private RetentionRule getExistingRule(
      List<RetentionRule> rules, RetentionRuleCreateRequest ruleRequest) throws SQLException {
    if (rules != null) {
      for (RetentionRule rule : rules) {
        String dataStorageName = ruleRequest.getDataStorageName();
        if (dataStorageName.equals(rule.getDataStorageName())) {
          if (rule.getIsActive()) {
            throw new SQLException(
                String.format(
                    "A %s rule already exists with project id: %s, data storage name: %s",
                    rule.getType().toString(), rule.getProjectId(), rule.getDataStorageName()));
          } else {
            return rule;
          }
        }

        if (rule.getIsActive()
            && (dataStorageName.contains(rule.getDataStorageName())
                || rule.getDataStorageName().contains(dataStorageName))) {
          throw new SQLException(
              String.format(
                  "A %s rule for %s already exists with project id: %s. The request for %s is not allowed for violating non-nesting rule",
                  rule.getType().toString(),
                  rule.getDataStorageName(),
                  rule.getProjectId(),
                  dataStorageName));
        }
      }
    }
    return null;
  }