private boolean validateLIKEConstraint()

in myriad-scheduler/src/main/java/org/apache/myriad/api/ClustersResource.java [220:245]


  private boolean validateLIKEConstraint(String constraint, ResponseBuilder response) {
    if (constraint.isEmpty()) {
      String message = String.format("The value provided for 'constraints' is empty. Format: %s", LIKE_CONSTRAINT_FORMAT);
      response.status(Status.BAD_REQUEST).entity(message);
      LOGGER.error(message);
      return false;
    }

    String[] splits = constraint.split(" LIKE "); // "<key> LIKE <val_regex>"
    if (splits.length != 2) {
      String message = String.format("Invalid format for LIKE operator in constraint: %s. Format: %s", constraint,
          LIKE_CONSTRAINT_FORMAT);
      response.status(Status.BAD_REQUEST).entity(message);
      LOGGER.error(message);
      return false;
    }
    try {
      Pattern.compile(splits[1]);
    } catch (PatternSyntaxException e) {
      String message = String.format("Invalid regex for LIKE operator in constraint: %s", constraint);
      response.status(Status.BAD_REQUEST).entity(message);
      LOGGER.error(message, e);
      return false;
    }
    return true;
  }