vertx/src/main/java/eu/internetofus/common/vertx/ModelResources.java
/**
   * The method to call when is creating a model.
   *
   * @param value   of the model to verify.
   * @param model   to create.
   * @param storer  the function used to store the model.
   * @param context of the request.
   * @param success component to manage the created model.
   *
   * @param <T>     type of model to create.
   * @param <I>     type of the model identifier.
   * @param <C>     type of validation context to use.
   */
The method to call when is creating a model.
@param value   of the model to verify.
@param model   to create.
@param storer  the function used to store the model.
@param context of the request.
@param success component to manage the created model.

@param      type of model to create.
@param      type of the model identifier.
@param      type of validation context to use.
The method to call when is creating a model . @param value of the model to verify . @param model to create . @param storer the function used to store the model . @param context of the request . @param success component to manage the created model . @param type of model to create . @param type of the model identifier . @param type of validation context to use .
static public <C extends ValidateContext<C>, T extends Model & Validable<C>, I> void createModelChain(
      final JsonObject value, @NotNull final ModelContext<T, I, C> model,
      @NotNull final BiConsumer<T, Handler<AsyncResult<T>>> storer, @NotNull final ServiceContext context,
      @NotNull final Runnable success) {
    toModel(value, model, context, () -> {
      validate(model, context, () -> {
        if (model.value instanceof CreateUpdateTsDetails) {
          final var now = TimeManager.now();
          final var timestamp = (CreateUpdateTsDetails) model.value;
          timestamp._creationTs = now;
          timestamp._lastUpdateTs = now;
        }
        storer.accept(model.value, stored -> {
          if (stored.failed()) {
            final var cause = stored.cause();
            Logger.trace(cause, "Cannot store {}.\n{}", model, context);
            ServiceResponseHandlers.responseFailedWith(context.resultHandler, Status.BAD_REQUEST, cause);
          } else {
            model.value = stored.result();
            Logger.trace("Stored {}.\n{}", model, context);
            success.run();
          }
        });
      });
    });
  }
static public < C extends ValidateContext < C > , T extends Model & Validable < C > , I > void createModelChain ( final JsonObject value , @ NotNull final ModelContext < T , I , C > model , @ NotNull final BiConsumer < T , Handler < AsyncResult < T > > > storer , @ NotNull final ServiceContext context , @ NotNull final Runnable success ) { toModel ( value , model , context , ( ) -> { validate ( model , context , ( ) -> { if ( model . value instanceof CreateUpdateTsDetails ) { final var now = TimeManager . now ( ) ; final var timestamp = ( CreateUpdateTsDetails ) model . value ; timestamp . _creationTs = now ; timestamp . _lastUpdateTs = now ; } storer . accept ( model . value , stored -> { if ( stored . failed ( ) ) { final var cause = stored . cause ( ) ; Logger . trace ( cause , "Cannot store {}.\n{}" , model , context ) ; ServiceResponseHandlers . responseFailedWith ( context . resultHandler , Status . BAD_REQUEST , cause ) ; } else { model . value = stored . result ( ) ; Logger . trace ( "Stored {}.\n{}" , model , context ) ; success . run ( ) ; } } ) ; } ) ; } ) ; }
The method to call when is creating a model.
The method to call when is creating a model .