Search in sources :

Example 1 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp in project timbuctoo by HuygensING.

the class SummaryPropDataRetriever method createSummaryProperty.

public Optional<TypedValue> createSummaryProperty(SubjectReference source, DataSet dataSet) {
    QuadStore quadStore = dataSet.getQuadStore();
    final Optional<TypedValue> localConfiguredSummaryProp = getQuad(quadStore, source.getSubjectUri(), RdfConstants.RDF_TYPE).flatMap(collection -> getQuad(quadStore, collection.getObject(), summaryPropConfigPredicate)).flatMap(userConfigured -> {
        try {
            SummaryProp summaryProp = OBJECT_MAPPER.readValue(userConfigured.getObject(), SummaryProp.class);
            return getQuad(summaryProp.getPath(), source.getSubjectUri(), quadStore).map(quad -> createTypedValue(quad, dataSet));
        } catch (IOException e) {
            LOG.error("Cannot parse SummaryProp: '{}'", userConfigured.getObject());
        }
        return Optional.empty();
    });
    if (localConfiguredSummaryProp.isPresent()) {
        return localConfiguredSummaryProp;
    } else {
        // fallback to default summary props
        for (SummaryProp prop : defaultProperties) {
            Optional<CursorQuad> quad = getQuad(prop.getPath(), source.getSubjectUri(), quadStore);
            if (quad.isPresent()) {
                return Optional.of(createTypedValue(quad.get(), dataSet));
            }
        }
        return Optional.empty();
    }
}
Also used : CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) Logger(org.slf4j.Logger) RdfConstants(nl.knaw.huygens.timbuctoo.v5.util.RdfConstants) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) IOException(java.io.IOException) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)

Example 2 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp in project timbuctoo by HuygensING.

the class SummaryPropDataRetrieverTest method createSummaryPropertyIgnoresValueTypesIfThePathIsLongerThanOne.

@Test
public void createSummaryPropertyIgnoresValueTypesIfThePathIsLongerThanOne() {
    List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath("http://example.org/path", "http://example.org/path2"));
    SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", defaultProperties);
    QuadStore quadStore = mock(QuadStore.class);
    CursorQuad foundQuad1 = quadWithObject("http://example.org/objectFound1", Optional.of(RdfConstants.STRING));
    CursorQuad foundQuad2 = quadWithObject("http://example.org/objectFound2", Optional.empty());
    given(quadStore.getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "")).willReturn(Stream.of(foundQuad1, foundQuad2));
    CursorQuad quadThatShouldNotBeFound = quadWithObject("http://example.org/objectThatShouldNotBeRetrieved", Optional.empty());
    given(quadStore.getQuads("http://example.org/objectFound1", "http://example.org/path2", Direction.OUT, "")).willReturn(Stream.of(quadThatShouldNotBeFound));
    CursorQuad quadWithObjectUriOfPath2 = quadWithObject("http://example.org/objectOfPath2", Optional.empty());
    given(quadStore.getQuads("http://example.org/objectFound2", "http://example.org/path2", Direction.OUT, "")).willReturn(Stream.of(quadWithObjectUriOfPath2));
    Optional<TypedValue> summaryProperty = instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
    assertThat(summaryProperty, is(present()));
    assertThat(summaryProperty.get(), hasProperty("value", is("http://example.org/objectOfPath2")));
    verify(quadStore).getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "");
    verify(quadStore).getQuads("http://example.org/objectFound2", "http://example.org/path2", Direction.OUT, "");
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue) Test(org.junit.Test)

Example 3 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp in project timbuctoo by HuygensING.

the class SummaryPropDataRetrieverTest method retrieveDefaultPropertyUsesTheFirstQuadFound.

@Test
public void retrieveDefaultPropertyUsesTheFirstQuadFound() {
    List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath("http://example.org/path", "http://example.org/path2"));
    SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", defaultProperties);
    QuadStore quadStore = mock(QuadStore.class);
    CursorQuad foundQuad1 = quadWithObject("http://example.org/objectFound1", Optional.empty());
    CursorQuad foundQuad2 = quadWithObject("http://example.org/objectFound2", Optional.empty());
    given(quadStore.getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "")).willReturn(Stream.of(foundQuad1, foundQuad2));
    CursorQuad quadWithObjectUriOfPath2 = quadWithObject("http://example.org/objectOfPath2", Optional.empty());
    given(quadStore.getQuads("http://example.org/objectFound1", "http://example.org/path2", Direction.OUT, "")).willReturn(Stream.of(quadWithObjectUriOfPath2));
    instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
    verify(quadStore).getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "");
    verify(quadStore).getQuads("http://example.org/objectFound1", "http://example.org/path2", Direction.OUT, "");
    verify(quadStore, never()).getQuads("http://example.org/objectFound2", "http://example.org/path2", Direction.OUT, "");
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) Test(org.junit.Test)

Example 4 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp in project timbuctoo by HuygensING.

the class SummaryPropDataRetrieverTest method createSummaryPropertyWalksTheWholePathOfTheConfiguredDefaultProperty.

@Test
public void createSummaryPropertyWalksTheWholePathOfTheConfiguredDefaultProperty() {
    List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath("http://example.org/path", "http://example.org/path2"));
    SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", defaultProperties);
    CursorQuad foundQuad = quadWithObject("http://example.org/objectFound", Optional.empty());
    QuadStore quadStore = mock(QuadStore.class);
    given(quadStore.getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "")).willReturn(Stream.of(foundQuad));
    instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
    InOrder inOrder = inOrder(quadStore);
    inOrder.verify(quadStore).getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "");
    inOrder.verify(quadStore).getQuads("http://example.org/objectFound", "http://example.org/path2", Direction.OUT, "");
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) InOrder(org.mockito.InOrder) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) Test(org.junit.Test)

Example 5 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp in project timbuctoo by HuygensING.

the class SummaryPropDataRetrieverTest method createSummaryPropertyWalksTheUserConfiguredPathFirst.

@Test
public void createSummaryPropertyWalksTheUserConfiguredPathFirst() throws JsonProcessingException {
    List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath("http://example.org/path"));
    SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", defaultProperties);
    SummaryProp summaryProp = summaryPropertyWithPath("http://example.org/userPath");
    CursorQuad collectionQuad = quadWithObject("http://example.org/collection", Optional.empty());
    CursorQuad userConfiguredSummaryProp = quadWithObject(OBJECT_MAPPER.writeValueAsString(summaryProp), Optional.empty());
    QuadStore quadStore = mock(QuadStore.class);
    given(quadStore.getQuads("http://example.org/source", RdfConstants.RDF_TYPE, Direction.OUT, "")).willReturn(Stream.of(collectionQuad));
    given(quadStore.getQuads("http://example.org/collection", "http://example.org/userConfigured", Direction.OUT, "")).willReturn(Stream.of(userConfiguredSummaryProp));
    instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
    InOrder inOrder = inOrder(quadStore);
    // walk the path of the user configured SummaryProp
    inOrder.verify(quadStore).getQuads("http://example.org/source", "http://example.org/userPath", Direction.OUT, "");
    // walk the path of the default SummaryProp
    inOrder.verify(quadStore).getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "");
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) InOrder(org.mockito.InOrder) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) Test(org.junit.Test)

Aggregations

QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)8 SummaryProp (nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp)8 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)7 Test (org.junit.Test)7 TypedValue (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)4 InOrder (org.mockito.InOrder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 IOException (java.io.IOException)1 List (java.util.List)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)1 SubjectReference (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference)1 RdfConstants (nl.knaw.huygens.timbuctoo.v5.util.RdfConstants)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1