Search in sources :

Example 1 with CollectionFilter

use of nl.knaw.huygens.timbuctoo.v5.graphql.collectionfilter.CollectionFilter in project timbuctoo by HuygensING.

the class PaginationArgumentsHelper method getPaginationArguments.

public PaginationArguments getPaginationArguments(DataFetchingEnvironment environment) {
    String cursor = "";
    int count = DEFAULT_COUNT;
    if (environment.containsArgument("cursor") && (environment.getArgument("cursor") instanceof String)) {
        cursor = new String(DECODER.decode((String) environment.getArgument("cursor")), Charsets.UTF_8);
    }
    if (environment.containsArgument("count")) {
        count = environment.getArgument("count");
    }
    ConfiguredFilter filter = null;
    for (Map.Entry<String, CollectionFilter> entry : collectionFilters.entrySet()) {
        if (environment.containsArgument(entry.getKey())) {
            String searchQuery = environment.getArgument(entry.getKey());
            String cursorArg = cursor;
            int countArg = count;
            String dataSetId = ((DatabaseResult) environment.getSource()).getDataSet().getMetadata().getCombinedId();
            String fieldName = environment.getFieldDefinition().getName();
            filter = () -> entry.getValue().query(dataSetId, fieldName, searchQuery, cursorArg, countArg);
            break;
        }
    }
    return PaginationArguments.create(count, cursor, Optional.ofNullable(filter));
}
Also used : CollectionFilter(nl.knaw.huygens.timbuctoo.v5.graphql.collectionfilter.CollectionFilter) DatabaseResult(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DatabaseResult) ConfiguredFilter(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ConfiguredFilter) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 CollectionFilter (nl.knaw.huygens.timbuctoo.v5.graphql.collectionfilter.CollectionFilter)1 ConfiguredFilter (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ConfiguredFilter)1 DatabaseResult (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DatabaseResult)1