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();
}
}
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, "");
}
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, "");
}
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, "");
}
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, "");
}
Aggregations