ElementPostInputValidatorExpander

Expands:


    $componentRoot.directory$/$artifactSubFolders$/$dataElement.packageName;format="toPath"$/validation/$dataElement.name;format="firstToLower"$
  /$dataElement.name$PostInputValidator.java

if:

dataElement.component.getOption('enableJaxrs').defined and
    dataElement.component.getOption('enableValidation').defined and
    dataElement.getOption('includeJaxrsConnector').defined and
    dataElement.getOption('exposePostEndpoint').defined
property value
element type DataElement
qualified name net.democritus.expander.rest.control.validation.ElementPostInputValidatorExpander
layer CONTROL_LAYER
technology JAXRS
sourceType JAVA
phase expansion
features  

Example

Some example of the content generated by the expander:

// expanded with nsx-expanders:4.16.3, expansionResource net.democritus:rest-expanders:2.4.2
package net.animals.validation.catBreed;

import net.animals.model.catBreed.CatBreedPostInputModel;

import animals.validation.InputValidation;
import animals.validation.ValidationFieldError;
import animals.validation.ValidationResult;

import net.democritus.sys.Context;

import java.util.ArrayList;
import java.util.List;

// @anchor:imports:start
// @anchor:imports:end
// anchor:custom-imports:start
// anchor:custom-imports:end

public class CatBreedPostInputValidator {

  private List<ValidationFieldError> errors = new ArrayList<>();
  private Context context;

  // @anchor:fields:start
  // @anchor:fields:end
  // anchor:custom-fields:start
  // anchor:custom-fields:end

  public CatBreedPostInputValidator(Context context) {
    this.context = context;
  }

  public ValidationResult validate(CatBreedPostInputModel inputModel) {
    validateInput(inputModel);

    return ValidationResult.success(errors);
  }

  private void validateInput(CatBreedPostInputModel inputModel) {
    InputValidation validation = InputValidation.init(inputModel, "jsonInput")
        .isRequired();

    errors.addAll(validation.getErrors());

    if (validation.hasNoErrors()) {
      validateName(inputModel);
      validateCountry(inputModel);
      validateOrigin(inputModel);
      validateCoatLength(inputModel);
      // @anchor:validateInput:start
      // @anchor:validateInput:end
      // anchor:custom-validateInput:start
      // anchor:custom-validateInput:end
    }
  }

  private void validateName(CatBreedPostInputModel inputModel) {
    InputValidation validation = InputValidation.init(inputModel.getName(), "name")
        .isString()
        // @anchor:validate-name:start
        // @anchor:validate-name:end
        // anchor:custom-validate-name:start
        // anchor:custom-validate-name:end
        ;

    errors.addAll(validation.getErrors());
  }

  private void validateCountry(CatBreedPostInputModel inputModel) {
    InputValidation validation = InputValidation.init(inputModel.getCountry(), "country")
        .isString()
        // @anchor:validate-country:start
        // @anchor:validate-country:end
        // anchor:custom-validate-country:start
        // anchor:custom-validate-country:end
        ;

    errors.addAll(validation.getErrors());
  }

  private void validateOrigin(CatBreedPostInputModel inputModel) {
    InputValidation validation = InputValidation.init(inputModel.getOrigin(), "origin")
        .isString()
        // @anchor:validate-origin:start
        // @anchor:validate-origin:end
        // anchor:custom-validate-origin:start
        // anchor:custom-validate-origin:end
        ;

    errors.addAll(validation.getErrors());
  }

  private void validateCoatLength(CatBreedPostInputModel inputModel) {
    InputValidation validation = InputValidation.init(inputModel.getCoatLength(), "coatLength")
        .isString()
        // @anchor:validate-coatLength:start
        // @anchor:validate-coatLength:end
        // anchor:custom-validate-coatLength:start
        // anchor:custom-validate-coatLength:end
        ;

    errors.addAll(validation.getErrors());
  }

  // @anchor:methods:start
  // @anchor:methods:end
  // anchor:custom-methods:start
  // anchor:custom-methods:end

}

These expanders have the same isApplicable as ElementPostInputValidatorExpander.