ElementModifyDataValidatorExpander

Expands:


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

if:

dataElement.component.getOption('enableJaxrs').defined and
    dataElement.component.getOption('enableValidation').defined and
    dataElement.getOption('includeJaxrsConnector').defined and
    dataElement.getOption('exposePutEndpoint').defined and
    !dataElement.dataCommands.{^ #this.name.equals('modify' + dataElement.name) }.empty
property value
element type DataElement
qualified name net.democritus.expander.rest.logic.validation.ElementModifyDataValidatorExpander
layer LOGIC_LAYER
technology EJB3
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.CityCommand;
import com.example.city.CityDataRef;
import com.example.city.CityLocalAgent;

import com.example.CountryDataRef;
import com.example.CountryFindByCodeEqDetails;
import com.example.CountryLocalAgent;
import com.example.city.CityFindByNameEq_UuidNeDetails;

import cities.validation.DatabaseValidator;
import cities.validation.ValidationResult;

import net.democritus.sys.Context;
import net.democritus.sys.SearchResult;
import net.democritus.sys.search.SearchDetails;
import net.palver.util.Options;

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

public class CityModifyDataValidator {

  private Context context;
  private DatabaseValidator databaseValidator;
  private CityCommonDataValidator commonValidator;

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

  public CityModifyDataValidator(Context context) {
    this.context = context;
    this.databaseValidator = new DatabaseValidator();
    this.commonValidator = new CityCommonDataValidator(context, databaseValidator);
  }

  public ValidationResult validate(CityCommand.ModifyCity inputModel) {
    Options.Option<CountryDataRef> country = validateCountryExists(inputModel);
    validateNameUnique(inputModel);
    // @anchor:validate:start
    // @anchor:validate:end
    // anchor:custom-validate:start
    // anchor:custom-validate:end

    return databaseValidator.getValidationResult();
  }

  private Options.Option<CountryDataRef> validateCountryExists(CityCommand.ModifyCity inputModel) {
    if (inputModel.getCountry() == null) {
      return Options.none();
    }

    CountryFindByCodeEqDetails finder = new CountryFindByCodeEqDetails();
    finder.setCode(inputModel.getCountry());
    SearchDetails<CountryFindByCodeEqDetails> searchDetails = SearchDetails.fetchNDataRef(finder, 1);
    SearchResult<CountryDataRef> searchResult = CountryLocalAgent.getCountryAgent(context).find(searchDetails);
    Options.Option<CountryDataRef> result = databaseValidator.existsDataRef(searchResult, "country");

    // @anchor:validate-country-exists:start
    // @anchor:validate-country-exists:end
    // anchor:custom-validate-country-exists:start
    // anchor:custom-validate-country-exists:end

    return result;
  }

  private Options.Option<CityDataRef> validateNameUnique(CityCommand.ModifyCity inputModel) {
    if (inputModel.getName() == null) {
      return Options.none();
    }

    CityFindByNameEq_UuidNeDetails details = new CityFindByNameEq_UuidNeDetails();
    details.setUuid(inputModel.getCityId());
    details.setName(inputModel.getName());
    SearchDetails<CityFindByNameEq_UuidNeDetails> searchDetails = SearchDetails.fetchNDataRef(details, 1);
    SearchResult<CityDataRef> searchResult = CityLocalAgent.getCityAgent(context).find(searchDetails);
    Options.Option<CityDataRef> result = databaseValidator.isUniqueDataRef(searchResult, "name");

    // @anchor:validate-name-unique:start
    // @anchor:validate-name-unique:end
    // anchor:custom-validate-name-unique:start
    // anchor:custom-validate-name-unique:end

    return result;
  }

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

}