vertx/src/main/java/eu/internetofus/common/vertx/ModelResources.java
/**
   * Create the handler to manage the retrieve of a model.
   *
   * @param model    context of the model to retrieve.
   * @param searcher the function used to obtain the model.
   * @param context  of the request.
   * @param success  function to call if the model can be retrieved.
   *
   * @param <T>      type of model to retrieve.
   * @param <I>      type for the model identifier.
   * @param <C>      type of validation context to use.
   */
Create the handler to manage the retrieve of a model.
@param model    context of the model to retrieve.
@param searcher the function used to obtain the model.
@param context  of the request.
@param success  function to call if the model can be retrieved.

@param       type of model to retrieve.
@param       type for the model identifier.
@param       type of validation context to use.
Create the handler to manage the retrieve of a model . @param model context of the model to retrieve . @param searcher the function used to obtain the model . @param context of the request . @param success function to call if the model can be retrieved . @param type of model to retrieve . @param type for the model identifier . @param type of validation context to use .
static public <T extends Model, I, C extends ValidateContext<C>> void retrieveModelChain(
      @NotNull final ModelContext<T, I, C> model, @NotNull final BiConsumer<I, Handler<AsyncResult<T>>> searcher,
      @NotNull final ServiceContext context, @NotNull final Runnable success) {
    searcher.accept(model.id, retrieve -> {
      model.target = retrieve.result();
      if (retrieve.failed() || model.target == null) {
        final var cause = retrieve.cause();
        Logger.trace(cause, "Not found {}.\n{}", model, context);
        ServiceResponseHandlers.responseWithErrorMessage(context.resultHandler, Status.NOT_FOUND,
            "not_found_" + model.name, "Does not exist a '" + model.name + "' associated to '" + model.id + "'.");
      } else {
        Logger.trace("Found {}.\n{}", model, context);
        success.run();
      }
    });
  }
static public < T extends Model , I , C extends ValidateContext < C > > void retrieveModelChain ( @ NotNull final ModelContext < T , I , C > model , @ NotNull final BiConsumer < I , Handler < AsyncResult < T > > > searcher , @ NotNull final ServiceContext context , @ NotNull final Runnable success ) { searcher . accept ( model . id , retrieve -> { model . target = retrieve . result ( ) ; if ( retrieve . failed ( ) || model . target == null ) { final var cause = retrieve . cause ( ) ; Logger . trace ( cause , "Not found {}.\n{}" , model , context ) ; ServiceResponseHandlers . responseWithErrorMessage ( context . resultHandler , Status . NOT_FOUND , "not_found_" + model . name , "Does not exist a '" + model . name + "' associated to '" + model . id + "'." ) ; } else { Logger . trace ( "Found {}.\n{}" , model , context ) ; success . run ( ) ; } } ) ; }
Create the handler to manage the retrieve of a model.
Create the handler to manage the retrieve of a model .