vertx/src/main/java/eu/internetofus/common/vertx/ModelResources.java
/**
   * Create an element of a field defined into a model.
   *
   * @param valueToCreate      to create the model field element.
   * @param element            to create.
   * @param searcher           the function used to obtain a model from an
   *                           identifier.
   * @param getField           return the field value associated to a model.
   * @param setField           change the value for the field.
   * @param storerCreatedModel the function to store the updated model.
   * @param context            of the request.
   * @param success            to inform to the upgrade value
   *
   * @param <T>                type of model that contains the fields.
   * @param <IT>               type of the model identifier.
   * @param <E>                type of the field.
   * @param <IE>               type of the field identifier.
   * @param <C>                type of validation context to use.
   */
Create an element of a field defined into a model.
@param valueToCreate      to create the model field element.
@param element            to create.
@param searcher           the function used to obtain a model from an
identifier.
@param getField           return the field value associated to a model.
@param setField           change the value for the field.
@param storerCreatedModel the function to store the updated model.
@param context            of the request.
@param success            to inform to the upgrade value

@param                 type of model that contains the fields.
@param                type of the model identifier.
@param                 type of the field.
@param                type of the field identifier.
@param                 type of validation context to use.
Create an element of a field defined into a model . @param valueToCreate to create the model field element . @param element to create . @param searcher the function used to obtain a model from an identifier . @param getField return the field value associated to a model . @param setField change the value for the field . @param storerCreatedModel the function to store the updated model . @param context of the request . @param success to inform to the upgrade value @param type of model that contains the fields . @param type of the model identifier . @param type of the field . @param type of the field identifier . @param type of validation context to use .
@SuppressWarnings("unchecked")
  static public <C extends ValidateContext<C>, T extends Model & Updateable<T, C>, IT, E extends Model & Validable<C>, IE> void createModelFieldElementChain(
      final JsonObject valueToCreate, @NotNull final ModelFieldContext<T, IT, E, IE, C> element,
      @NotNull final BiConsumer<IT, Handler<AsyncResult<T>>> searcher, @NotNull final Function<T, List<E>> getField,
      @NotNull final BiConsumer<T, List<E>> setField,
      final BiConsumer<T, Handler<AsyncResult<Void>>> storerCreatedModel, final ServiceContext context,
      @NotNull final Runnable success) {
    toModel(valueToCreate, element, context, () -> {
      validate(element, context, () -> {
        if (element.value instanceof CreateUpdateTsDetails) {
          final var now = TimeManager.now();
          final var timestamp = (CreateUpdateTsDetails) element.value;
          timestamp._creationTs = now;
          timestamp._lastUpdateTs = now;
        }
        retrieveModelChain(element.model, searcher, context, () -> {
          element.model.source = (T) Model.fromJsonObject(element.model.target.toJsonObject(),
              element.model.target.getClass());
          element.field = getField.apply(element.model.source);
          if (element.field == null) {
            element.field = new ArrayList<E>();
            setField.accept(element.model.source, element.field);
          }
          element.index = element.field.size();
          element.field.add(element.value);
          update(element.model, context, true, () -> {
            element.value = getField.apply(element.model.value).get(element.index);
            updateModelChain(element.model, storerCreatedModel, context, success);
          });
        });
      });
    });
  }
@ SuppressWarnings ( "unchecked" ) static public < C extends ValidateContext < C > , T extends Model & Updateable < T , C > , IT , E extends Model & Validable < C > , IE > void createModelFieldElementChain ( final JsonObject valueToCreate , @ NotNull final ModelFieldContext < T , IT , E , IE , C > element , @ NotNull final BiConsumer < IT , Handler < AsyncResult < T > > > searcher , @ NotNull final Function < T , List < E > > getField , @ NotNull final BiConsumer < T , List < E > > setField , final BiConsumer < T , Handler < AsyncResult < Void > > > storerCreatedModel , final ServiceContext context , @ NotNull final Runnable success ) { toModel ( valueToCreate , element , context , ( ) -> { validate ( element , context , ( ) -> { if ( element . value instanceof CreateUpdateTsDetails ) { final var now = TimeManager . now ( ) ; final var timestamp = ( CreateUpdateTsDetails ) element . value ; timestamp . _creationTs = now ; timestamp . _lastUpdateTs = now ; } retrieveModelChain ( element . model , searcher , context , ( ) -> { element . model . source = ( T ) Model . fromJsonObject ( element . model . target . toJsonObject ( ) , element . model . target . getClass ( ) ) ; element . field = getField . apply ( element . model . source ) ; if ( element . field == null ) { element . field = new ArrayList < E > ( ) ; setField . accept ( element . model . source , element . field ) ; } element . index = element . field . size ( ) ; element . field . add ( element . value ) ; update ( element . model , context , true , ( ) -> { element . value = getField . apply ( element . model . value ) . get ( element . index ) ; updateModelChain ( element . model , storerCreatedModel , context , success ) ; } ) ; } ) ; } ) ; } ) ; }
Create an element of a field defined into a model.
Create an element of a field defined into a model .