vertx/src/main/java/eu/internetofus/common/vertx/ModelResources.java
/**
   * Retrieve an element of a field defined into a model.
   *
   * @param element       context of the field to retrieve.
   * @param searcher      the function used to obtain a model from an identifier.
   * @param getField      return the field value associated to a model.
   * @param searchElement return the index of the element that has the specified
   *                      identifier.
   * @param context       of the request.
   * @param success       function to call if can retrieve the element.
   *
   * @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.
   */
Retrieve an element of a field defined into a model.
@param element       context of the field to retrieve.
@param searcher      the function used to obtain a model from an identifier.
@param getField      return the field value associated to a model.
@param searchElement return the index of the element that has the specified
identifier.
@param context       of the request.
@param success       function to call if can retrieve the element.

@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.
Retrieve an element of a field defined into a model . @param element context of the field to retrieve . @param searcher the function used to obtain a model from an identifier . @param getField return the field value associated to a model . @param searchElement return the index of the element that has the specified identifier . @param context of the request . @param success function to call if can retrieve the element . @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 <T extends Model, E extends Model, IT, IE, C extends ValidateContext<C>> void retrieveModelFieldElementChain(
      @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 BiFunction<List<E>, IE, Integer> searchElement, @NotNull final ServiceContext context,
      @NotNull final Runnable success) {
    retrieveModelChain(element.model, searcher, context, () -> {
      element.model.value = (T) Model.fromJsonObject(element.model.target.toJsonObject(),
          element.model.target.getClass());
      element.field = getField.apply(element.model.value);
      if (element.field != null) {
        element.index = searchElement.apply(element.field, element.id);
        if (element.index > -1) {
          element.target = element.field.get(element.index);
          Logger.trace("Retrieve {} from {}.\n{}", element, element.model, context);
          success.run();
          return;
        }
      }
      Logger.trace("Not found {} in {}.\n{}", element, element.model, context);
      ServiceResponseHandlers.responseWithErrorMessage(context.resultHandler, Status.NOT_FOUND,
          "not_found_" + element.model.name + "_" + element.name,
          "On '" + element.model + "' does not found '" + element + "' .");
    });
  }
@ SuppressWarnings ( "unchecked" ) static public < T extends Model , E extends Model , IT , IE , C extends ValidateContext < C > > void retrieveModelFieldElementChain ( @ 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 BiFunction < List < E > , IE , Integer > searchElement , @ NotNull final ServiceContext context , @ NotNull final Runnable success ) { retrieveModelChain ( element . model , searcher , context , ( ) -> { element . model . value = ( T ) Model . fromJsonObject ( element . model . target . toJsonObject ( ) , element . model . target . getClass ( ) ) ; element . field = getField . apply ( element . model . value ) ; if ( element . field != null ) { element . index = searchElement . apply ( element . field , element . id ) ; if ( element . index > - 1 ) { element . target = element . field . get ( element . index ) ; Logger . trace ( "Retrieve {} from {}.\n{}" , element , element . model , context ) ; success . run ( ) ; return ; } } Logger . trace ( "Not found {} in {}.\n{}" , element , element . model , context ) ; ServiceResponseHandlers . responseWithErrorMessage ( context . resultHandler , Status . NOT_FOUND , "not_found_" + element . model . name + "_" + element . name , "On '" + element . model + "' does not found '" + element + "' ." ) ; } ) ; }
Retrieve an element of a field defined into a model.
Retrieve an element of a field defined into a model .