Search in sources :

Example 1 with TypedValue

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();
    }
}
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 TypedValue

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;
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)

Example 3 with TypedValue

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;
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)

Example 4 with TypedValue

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, "");
}
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 5 with TypedValue

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())));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue) Test(org.junit.Test)

Aggregations

TypedValue (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)9 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)5 SubjectReference (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference)5 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)4 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)4 SummaryProp (nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp)4 Test (org.junit.Test)4 List (java.util.List)2 Optional (java.util.Optional)2 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)2 RdfConstants (nl.knaw.huygens.timbuctoo.v5.util.RdfConstants)2 Logger (org.slf4j.Logger)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 ExecutionResult (graphql.ExecutionResult)1 ExecutionResultImpl (graphql.ExecutionResultImpl)1 AsyncExecutionStrategy (graphql.execution.AsyncExecutionStrategy)1 ExecutionContext (graphql.execution.ExecutionContext)1 ExecutionStrategyParameters (graphql.execution.ExecutionStrategyParameters)1 NonNullableFieldWasNullException (graphql.execution.NonNullableFieldWasNullException)1