private ValidationError validatePropertyInElement()

in src/main/java/com/epam/digital/data/platform/registry/regulation/validation/cli/validator/bpmn/BpmnFileInputsValidator.java [204:242]


  private ValidationError validatePropertyInElement(Activity activity, ElementTemplate.Property property,
                                                    File regulationFile, ValidationContext validationContext) {
    var getValuesFunction = GET_VALUES_FOR_VALIDATION_FUNCTIONS.get(
        property.getBinding().getType());
    var propertyValueSet = getValuesFunction.apply(activity, property);

    if (propertyValueSet.size() > 1) {
      return ValidationError.of(validationContext.getRegulationFileType(), regulationFile,
          String.format("In task %s in process %s there are several values for input parameter %s",
              activity.getId(), regulationFile.getName(), property.getBinding()));
    }

    String propertyValue = CollectionUtils.firstElement(propertyValueSet);

    if (property.getConstraints().isNotEmpty() && StringUtils.isBlank(propertyValue)) {
      return ValidationError.of(validationContext.getRegulationFileType(), regulationFile,
          String.format("In task %s in process %s input parameter %s is empty",
              activity.getId(), regulationFile.getName(), property.getBinding()));
    }

    String type = property.getConstraints().getType();
    if (!StringUtils.isBlank(type) && !StringUtils.isBlank(propertyValue)) {
      if (isExpression(propertyValue)){
        log.warn(String.format("Unable to validate property due to dynamic value: %s", propertyValue));
        return null;
      }
      var inputValidationFunction = INPUT_VALIDATION_FUNCTIONS.get(type);
      try {
        if (Objects.nonNull(inputValidationFunction) && !inputValidationFunction.apply(propertyValue)) {
          return ValidationError.of(validationContext.getRegulationFileType(), regulationFile,
              String.format("In task %s of process %s, the input parameter %s doesn't exist",
                  activity.getId(), regulationFile.getName(), property.getBinding()));
        }
      } catch (FileProcessingException e) {
        return ValidationError.of(validationContext.getRegulationFileType(), regulationFile, e.getMessage());
      }
    }
    return null;
  }