components/src/main/java/eu/internetofus/common/components/WeNetValidateContext.java
/**
   * Validate that a field contains a defined model.
   *
   * @param name   of the field to validate.
   * @param id     identifier of the model.
   * @param type   of model to search.
   * @param search function to get the model by its identifier.
   * @param <T>    type of model to check if it is defined.
   *
   * @return the future with the validation result.
   */
Validate that a field contains a defined model.
@param name   of the field to validate.
@param id     identifier of the model.
@param type   of model to search.
@param search function to get the model by its identifier.
@param     type of model to check if it is defined.

@return the future with the validation result.
Validate that a field contains a defined model . @param name of the field to validate . @param id identifier of the model . @param type of model to search . @param search function to get the model by its identifier . @param type of model to check if it is defined . @return the future with the validation result .
public <T> Future<T> validateDefinedModelByIdField(final String name, final String id, final Class<T> type,
      final Function<String, Future<T>> search) {
    final var key = this.generateKey(id, type);
    @SuppressWarnings("unchecked")
    final var model = (T) this.modelsCache.get(key);
    if (model == null) {
      return search.apply(id).transform(found -> {
        if (found.failed()) {
          return this.failField(name, "The '" + id + "' is not associated to any model.", found.cause());
        } else {
          final var result = found.result();
          this.idsCache.add(key);
          this.modelsCache.put(key, result);
          return Future.succeededFuture(result);
        }
      });
    } else {
      return Future.succeededFuture(model);
    }
  }
public < T > Future < T > validateDefinedModelByIdField ( final String name , final String id , final Class < T > type , final Function < String , Future < T > > search ) { final var key = this . generateKey ( id , type ) ; @ SuppressWarnings ( "unchecked" ) final var model = ( T ) this . modelsCache . get ( key ) ; if ( model == null ) { return search . apply ( id ) . transform ( found -> { if ( found . failed ( ) ) { return this . failField ( name , "The '" + id + "' is not associated to any model." , found . cause ( ) ) ; } else { final var result = found . result ( ) ; this . idsCache . add ( key ) ; this . modelsCache . put ( key , result ) ; return Future . succeededFuture ( result ) ; } } ) ; } else { return Future . succeededFuture ( model ) ; } }
Validate that a field contains a defined model.
Validate that a field contains a defined model .