vertx/src/main/java/eu/internetofus/common/vertx/Repository.java
/**
   * Search for a page.
   *
   * @param collectionName of the collections that contains the models.
   * @param query          to obtain the components of the page.
   * @param order          to provide the results.
   * @param offset         the index of the first elements to return.
   * @param limit          the number maximum of elements to return.
   * @param elementPath    the name of the element to unwind. It has to be the
   *                       values to access to component on the document.
   *
   * @return the future found page.
   */
Search for a page.
@param collectionName of the collections that contains the models.
@param query          to obtain the components of the page.
@param order          to provide the results.
@param offset         the index of the first elements to return.
@param limit          the number maximum of elements to return.
@param elementPath    the name of the element to unwind. It has to be the
values to access to component on the document.

@return the future found page.
Search for a page . @param collectionName of the collections that contains the models . @param query to obtain the components of the page . @param order to provide the results . @param offset the index of the first elements to return . @param limit the number maximum of elements to return . @param elementPath the name of the element to unwind . It has to be the values to access to component on the document . @return the future found page .
protected Future<JsonObject> aggregatePageObject(@NotNull final String collectionName,
      @NotNull final JsonObject query, @NotNull final JsonObject order, final int offset, final int limit,
      @NotNull final String elementPath) {
    final var splitted = AggregationBuilder.splitElementPath(elementPath);
    return this.countAggregation(collectionName, splitted, query).compose(total -> {
      final Promise<JsonObject> promise = Promise.promise();
      if (total == 0 || total < offset) {
        final var page = new JsonObject().put("offset", offset).put("total", total);
        promise.complete(page);
      } else {
        final var retrievePipeline = new AggregationBuilder().unwindPath(splitted).match(query)
            .sort(order, offset, limit).build();
        final var elements = new JsonArray();
        final var resultKey = splitted[splitted.length - 1];
        final var page = new JsonObject().put("offset", offset).put("total", total).put(resultKey, elements);
        this.pool.aggregate(collectionName, retrievePipeline).handler(value -> {
          var element = value.getJsonObject(splitted[0]);
          for (var i = 1; i < splitted.length; i++) {
            element = element.getJsonObject(splitted[i]);
          }
          elements.add(element);
        }).exceptionHandler(cause -> {
          promise.fail(cause);
        }).endHandler(finishedRetrieve -> {
          if (elements.isEmpty()) {
            page.remove(resultKey);
          }
          promise.complete(page);
        });
      }
      return promise.future();
    });
  }
protected Future < JsonObject > aggregatePageObject ( @ NotNull final String collectionName , @ NotNull final JsonObject query , @ NotNull final JsonObject order , final int offset , final int limit , @ NotNull final String elementPath ) { final var splitted = AggregationBuilder . splitElementPath ( elementPath ) ; return this . countAggregation ( collectionName , splitted , query ) . compose ( total -> { final Promise < JsonObject > promise = Promise . promise ( ) ; if ( total == 0 || total < offset ) { final var page = new JsonObject ( ) . put ( "offset" , offset ) . put ( "total" , total ) ; promise . complete ( page ) ; } else { final var retrievePipeline = new AggregationBuilder ( ) . unwindPath ( splitted ) . match ( query ) . sort ( order , offset , limit ) . build ( ) ; final var elements = new JsonArray ( ) ; final var resultKey = splitted [ splitted . length - 1 ] ; final var page = new JsonObject ( ) . put ( "offset" , offset ) . put ( "total" , total ) . put ( resultKey , elements ) ; this . pool . aggregate ( collectionName , retrievePipeline ) . handler ( value -> { var element = value . getJsonObject ( splitted [ 0 ] ) ; for ( var i = 1 ; i < splitted . length ; i ++ ) { element = element . getJsonObject ( splitted [ i ] ) ; } elements . add ( element ) ; } ) . exceptionHandler ( cause -> { promise . fail ( cause ) ; } ) . endHandler ( finishedRetrieve -> { if ( elements . isEmpty ( ) ) { page . remove ( resultKey ) ; } promise . complete ( page ) ; } ) ; } return promise . future ( ) ; } ) ; }
Search for a page.
Search for a page .