ElementPutInputValidatorExpander
Expands:
$componentRoot.directory$/$artifactSubFolders$/$dataElement.packageName;format="toPath"$/validation/$dataElement.name;format="firstToLower"$
/$dataElement.name$PutInputValidator.java
if:
dataElement.component.getOption('enableJaxrs').defined and
dataElement.component.getOption('enableValidation').defined and
dataElement.getOption('includeJaxrsConnector').defined and
dataElement.getOption('exposePutEndpoint').defined
property | value |
---|---|
element type | DataElement |
qualified name | net.democritus.expander.rest.control.validation.ElementPutInputValidatorExpander |
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 com.example.city.validation.city;
import com.example.city.model.city.CityPutInputModel;
import cities.validation.InputValidation;
import cities.validation.ValidationFieldError;
import cities.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 CityPutInputValidator {
private List<ValidationFieldError> errors = new ArrayList<>();
private Context context;
// @anchor:fields:start
// @anchor:fields:end
// anchor:custom-fields:start
// anchor:custom-fields:end
public CityPutInputValidator(Context context) {
this.context = context;
}
public ValidationResult validate(CityPutInputModel inputModel) {
validateInput(inputModel);
return ValidationResult.success(errors);
}
private void validateInput(CityPutInputModel inputModel) {
InputValidation validation = InputValidation.init(inputModel, "jsonInput")
.isRequired();
errors.addAll(validation.getErrors());
if (validation.hasNoErrors()) {
validateName(inputModel);
validatePostalCode(inputModel);
validateCountry(inputModel);
// @anchor:validateInput:start
// @anchor:validateInput:end
// anchor:custom-validateInput:start
// anchor:custom-validateInput:end
}
}
private void validateName(CityPutInputModel inputModel) {
InputValidation validation = InputValidation.init(inputModel.getName(), "name")
.isRequired()
.isString()
// @anchor:validate-name:start
// @anchor:validate-name:end
// anchor:custom-validate-name:start
.maxStringLength(100)
// anchor:custom-validate-name:end
;
errors.addAll(validation.getErrors());
}
private void validatePostalCode(CityPutInputModel inputModel) {
InputValidation validation = InputValidation.init(inputModel.getPostalCode(), "postalCode")
.isRequired()
.isInteger()
// @anchor:validate-postalCode:start
// @anchor:validate-postalCode:end
// anchor:custom-validate-postalCode:start
// anchor:custom-validate-postalCode:end
;
errors.addAll(validation.getErrors());
}
private void validateCountry(CityPutInputModel inputModel) {
InputValidation validation = InputValidation.init(inputModel.getCountry(), "country")
.isRequired()
.isString()
// @anchor:validate-country:start
// @anchor:validate-country:end
// anchor:custom-validate-country:start
// anchor:custom-validate-country:end
;
errors.addAll(validation.getErrors());
}
// @anchor:methods:start
// @anchor:methods:end
// anchor:custom-methods:start
// anchor:custom-methods:end
}
Related Expanders
These expanders have the same isApplicable as ElementPutInputValidatorExpander
.