Search in sources :

Example 11 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class DutchCaribbeanArchiveAndArchiverPeriodFacetDescriptionTest method shouldContainJustRight.

private void shouldContainJustRight(GraphTraversal<Vertex, Vertex> traversal, long startYear, long endYear) {
    List<FacetValue> facetValues = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, startYear * 10_000, endYear * 10_000));
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), contains(likeVertex().withTimId("just_right")));
}
Also used : DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue)

Example 12 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class ChangeRangeFacetDescription method filter.

@Override
@SuppressWarnings("unchecked")
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
    Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof DateRangeFacetValue)) {
        return;
    }
    long lowerLimit = ((DateRangeFacetValue) facetValue).getLowerLimit();
    LocalDate lowerLimitDate = LocalDate.parse("" + lowerLimit, FORMATTER);
    long upperLimit = ((DateRangeFacetValue) facetValue).getUpperLimit();
    LocalDate upperLimitDate = LocalDate.parse(("" + upperLimit), FORMATTER);
    // Use range because the java.time.Period has no way to determine if a date falls in that Period.
    Range<LocalDate> period = Range.closed(lowerLimitDate, upperLimitDate);
    graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> {
        try {
            LocalDate localDate = getChangeLocalDate(o1);
            return ((Range<LocalDate>) o2).contains(localDate);
        } catch (IOException e) {
            LOG.error("Date {} cannot be parsed.", o1);
        }
        return false;
    }, period)));
}
Also used : ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Logger(org.slf4j.Logger) LocalPropertyValueGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.LocalPropertyValueGetter) Range(com.google.common.collect.Range) LoggerFactory(org.slf4j.LoggerFactory) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) IOException(java.io.IOException) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Instant(java.time.Instant) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ZoneId(java.time.ZoneId) ChangeRangeFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ChangeRangeFacetGetter) Objects(java.util.Objects) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) Change(nl.knaw.huygens.timbuctoo.model.Change) P(org.apache.tinkerpop.gremlin.process.traversal.P) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) IOException(java.io.IOException) Range(com.google.common.collect.Range) LocalDate(java.time.LocalDate)

Example 13 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class CharterPortaalFondsFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
    Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), getName())).findFirst();
    if (first.isPresent()) {
        FacetValue facetValue = first.get();
        if (facetValue instanceof ListFacetValue) {
            ListFacetValue listFacetValue = (ListFacetValue) facetValue;
            List<String> values = listFacetValue.getValues();
            if (values.isEmpty()) {
                return;
            }
            List<String> formattedVals = values.stream().map(val -> val.substring(val.indexOf("(") + 1, val.length() - 1)).collect(toList());
            graphTraversal.where(__.has(FONDS, P.within(formattedVals)));
        } else {
            LOG.error("Facet with name '{}' is not a ListFacet", getName());
        }
    }
}
Also used : Logger(org.slf4j.Logger) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) LoggerFactory(org.slf4j.LoggerFactory) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) Objects(java.util.Objects) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists(com.google.common.collect.Lists) Optional(java.util.Optional) P(org.apache.tinkerpop.gremlin.process.traversal.P) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)

Example 14 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class FacetParsingHelp method getValue.

static Optional<DateRangeFacetValue> getValue(String facetName, List<FacetValue> facets) {
    Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return Optional.empty();
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof DateRangeFacetValue)) {
        return Optional.empty();
    }
    DateRangeFacetValue casted = (DateRangeFacetValue) facetValue;
    // normalize input, make sure its always YYYY
    // the input from the client is YNNNN YYNNNN YYYNNNN etc. NNNN goes from 0000 to 9999 and means 1/10th milliYear
    // (1/10,000th of a year)
    casted.setLowerLimit(casted.getLowerLimit() / 10000);
    casted.setUpperLimit(casted.getUpperLimit() / 10000);
    return Optional.of(casted);
}
Also used : Objects(java.util.Objects) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Optional(java.util.Optional) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue)

Example 15 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class MultiValueListFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facetValues) {
    Optional<FacetValue> first = facetValues.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof ListFacetValue)) {
        return;
    }
    List<String> values = ((ListFacetValue) facetValue).getValues();
    if (values.isEmpty()) {
        return;
    }
    graphTraversal.where(__.<String>has(propertyName, P.test((o1, o2) -> o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(value -> ((String) o1).contains("\"" + value + "\"")), values)));
}
Also used : Objects(java.util.Objects) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) MultiValuePropertyGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.MultiValuePropertyGetter) Optional(java.util.Optional) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) P(org.apache.tinkerpop.gremlin.process.traversal.P) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) List(java.util.List)

Aggregations

FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)34 List (java.util.List)32 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)31 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)31 Lists (com.google.common.collect.Lists)27 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)25 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)25 Test (org.junit.Test)25 Before (org.junit.Before)23 Matchers.contains (org.hamcrest.Matchers.contains)22 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)19 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)18 DateRangeFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue)16 PropertyParser (nl.knaw.huygens.timbuctoo.search.description.PropertyParser)9 Objects (java.util.Objects)7 Optional (java.util.Optional)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 BDDMockito.given (org.mockito.BDDMockito.given)7 Mockito.mock (org.mockito.Mockito.mock)7