use of nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue 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.datafetchers.dto.TypedValue in project timbuctoo by HuygensING.
the class EntityDescriptionFetcher method get.
@Override
public TypedValue get(DataFetchingEnvironment env) {
if (env.getSource() instanceof SubjectReference) {
SubjectReference source = env.getSource();
DataSet dataSet = source.getDataSet();
Optional<TypedValue> desc = summaryPropDataRetriever.createSummaryProperty(source, dataSet);
if (desc.isPresent()) {
return desc.get();
}
}
return null;
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue in project timbuctoo by HuygensING.
the class EntityTitleFetcher method get.
@Override
public TypedValue get(DataFetchingEnvironment env) {
if (env.getSource() instanceof SubjectReference) {
SubjectReference source = env.getSource();
DataSet dataSet = source.getDataSet();
Optional<TypedValue> summaryProperty = summaryPropDataRetriever.createSummaryProperty(source, dataSet);
if (summaryProperty.isPresent()) {
return summaryProperty.get();
}
// fallback to the uri if no summary props can be found for the title
return TypedValue.create(source.getSubjectUri(), STRING, dataSet);
}
return null;
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue 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.datafetchers.dto.TypedValue in project timbuctoo by HuygensING.
the class SummaryPropDataRetrieverTest method createSummaryPropertyReturnsAnEmptyOptionalWhenNoDefaultPropertiesAreConfigured.
@Test
public void createSummaryPropertyReturnsAnEmptyOptionalWhenNoDefaultPropertiesAreConfigured() {
SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", Lists.newArrayList());
QuadStore quadStore = mock(QuadStore.class);
Optional<TypedValue> found = instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
assertThat(found, not(is(present())));
}
Aggregations