components/src/test/java/eu/internetofus/common/components/CRUDContext.java
/**
   * Return the handler to replace (put) a value for an identifier defined on the
   * path.
   *
   * @return the handler to replace value by its identifier.
   */
Return the handler to replace (put) a value for an identifier defined on the
path.

@return the handler to replace value by its identifier.
Return the handler to replace ( put ) a value for an identifier defined on the path . @return the handler to replace value by its identifier .
public Handler<RoutingContext> postHandler() {
    return ctx -> {
      var newValue = this.getNewValueFrom(ctx);
      if (newValue != null) {
        final var response = ctx.response();
        var id = newValue.getString(this.idName);
        if (id == null) {
          var index = this.values.size() + 1;
          while (this.values.containsKey(String.valueOf(index))) {
            index++;
          }
          id = String.valueOf(index);
          newValue = newValue.put(this.idName, id);
        } else if (this.values.containsKey(id)) {
          response.setStatusCode(Status.BAD_REQUEST.getStatusCode());
          response.end(new ErrorMessage("bad_id", "The identifier is already defined").toBuffer());
          return;
        }
        if (CreateUpdateTsDetails.class.isAssignableFrom(this.modelType)) {
          final var now = TimeManager.now();
          newValue = newValue.put("_creationTs", now);
          newValue = newValue.put("_lastUpdateTs", now);
        }
        this.values.put(id, newValue);
        response.setStatusCode(Status.CREATED.getStatusCode());
        response.end(newValue.toBuffer());
      }
    };
  }
public Handler < RoutingContext > postHandler ( ) { return ctx -> { var newValue = this . getNewValueFrom ( ctx ) ; if ( newValue != null ) { final var response = ctx . response ( ) ; var id = newValue . getString ( this . idName ) ; if ( id == null ) { var index = this . values . size ( ) + 1 ; while ( this . values . containsKey ( String . valueOf ( index ) ) ) { index ++ ; } id = String . valueOf ( index ) ; newValue = newValue . put ( this . idName , id ) ; } else if ( this . values . containsKey ( id ) ) { response . setStatusCode ( Status . BAD_REQUEST . getStatusCode ( ) ) ; response . end ( new ErrorMessage ( "bad_id" , "The identifier is already defined" ) . toBuffer ( ) ) ; return ; } if ( CreateUpdateTsDetails . class . isAssignableFrom ( this . modelType ) ) { final var now = TimeManager . now ( ) ; newValue = newValue . put ( "_creationTs" , now ) ; newValue = newValue . put ( "_lastUpdateTs" , now ) ; } this . values . put ( id , newValue ) ; response . setStatusCode ( Status . CREATED . getStatusCode ( ) ) ; response . end ( newValue . toBuffer ( ) ) ; } } ; }
Return the handler to replace (put) a value for an identifier defined on the
 path.
Return the handler to replace ( put ) a value for an identifier defined on the path .