Search in sources :

Example 71 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class GraphQlToRdfPatchTest method addsQuadsForEachAdditionsToEntity.

@Test
public void addsQuadsForEachAdditionsToEntity() throws Exception {
    String addedValue = "newValue";
    String addedValue2 = "newValue2";
    addAdditionsToChangeLog(new Change(new Graph(GRAPH), SUBJECT, PRED1, newArrayList(new Value(addedValue, STRING)), null), new Change(new Graph(GRAPH), SUBJECT, PRED2, newArrayList(new Value(addedValue2, STRING)), null));
    GraphQlToRdfPatch instance = new GraphQlToRdfPatch(GRAPH, SUBJECT, USER_URI, changeLog);
    instance.sendQuads(serializer, s -> {
    }, dataSet);
    verify(serializer).addDelQuad(true, SUBJECT, PRED1, addedValue, STRING, null, GRAPH);
    verify(serializer).addDelQuad(true, SUBJECT, PRED2, addedValue2, STRING, null, GRAPH);
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 72 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class GraphQlToRdfPatchTest method addsQuadsForEachValueInAnAddition.

@Test
public void addsQuadsForEachValueInAnAddition() throws Exception {
    String addedValue = "newValue";
    String addedValue2 = "newValue2";
    addAdditionsToChangeLog(new Change(new Graph(GRAPH), SUBJECT, PRED1, newArrayList(new Value(addedValue, STRING), new Value(addedValue2, STRING)), null));
    GraphQlToRdfPatch instance = new GraphQlToRdfPatch(GRAPH, SUBJECT, USER_URI, changeLog);
    instance.sendQuads(serializer, s -> {
    }, dataSet);
    verify(serializer).addDelQuad(true, SUBJECT, PRED1, addedValue, STRING, null, GRAPH);
    verify(serializer).addDelQuad(true, SUBJECT, PRED1, addedValue2, STRING, null, GRAPH);
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 73 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class ProvenanceChangeLogTest method getProvenanceForField.

@Test
public void getProvenanceForField() throws Exception {
    CustomProvenance customProvenance = CustomProvenance.getCustomProvenance(ImmutableMap.of("fields", Lists.newArrayList(ImmutableMap.of("uri", NAME_URI, "isList", false, "valueType", STRING))));
    when(dataSet.getCustomProvenance()).thenReturn(customProvenance);
    String value = "value";
    Map<Object, Object> provenance = Maps.newHashMap();
    provenance.put(NAME_FIELD, createPropertyInput(value));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("provenance", provenance);
    ProvenanceChangeLog instance = new ProvenanceChangeLog(entity);
    List<Change> provChanges = instance.getProvenance(dataSet, SUBJECT).collect(toList());
    assertThat(provChanges.size(), is(1));
    assertThat(provChanges.get(0), is(likeChange().withSubject(SUBJECT).withPredicate(NAME_URI).withValues(new Value(value, STRING)).oldValuesIsEmpty()));
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) ProvenanceChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ProvenanceChangeLog) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) CustomProvenance(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance) Test(org.junit.Test)

Example 74 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class ProvenanceChangeLogTest method getProvenanceForObjectFieldWihoutUri.

@Test
public void getProvenanceForObjectFieldWihoutUri() throws Exception {
    CustomProvenance customProvenance = CustomProvenance.getCustomProvenance(ImmutableMap.of("fields", Lists.newArrayList(ImmutableMap.of("uri", NAME_URI, "isList", false, "object", ImmutableMap.of("type", TYPE_URI, "fields", Lists.newArrayList(ImmutableMap.of("uri", FIRST_NAME_URI, "isList", false, "valueType", STRING)))))));
    when(dataSet.getCustomProvenance()).thenReturn(customProvenance);
    String value = "value";
    Map<Object, Object> name = Maps.newHashMap();
    name.put(FIRST_NAME_FIELD, createPropertyInput(value));
    Map<Object, Object> provenance = Maps.newHashMap();
    provenance.put(NAME_FIELD, name);
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("provenance", provenance);
    ProvenanceChangeLog instance = new ProvenanceChangeLog(entity);
    List<Change> provChanges = instance.getProvenance(dataSet, SUBJECT).collect(toList());
    assertThat(provChanges.get(1).getSubject(), startsWith("http://example.org/datasets/rootType/schema_Person/"));
    assertThat(provChanges.get(2).getSubject(), startsWith("http://example.org/datasets/rootType/schema_Person/"));
}
Also used : ProvenanceChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ProvenanceChangeLog) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) CustomProvenance(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance) Test(org.junit.Test)

Example 75 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class SummaryPropDataRetriever method getDataQuad.

private Optional<CursorQuad> getDataQuad(List<DirectionalStep> path, String uri, QuadStore quadStore) {
    /*
     * A collect of the data might look a bit nicer, but that will cause all the data to be loaded from the database.
     * This way only the data needed is retrieved.
     * See https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps for more info.
     */
    Optional<CursorQuad> foundQuad;
    DirectionalStep firstStep = path.get(0);
    try (Stream<CursorQuad> quads = quadStore.getQuads(uri, firstStep.getStep(), firstStep.getDirection(), "")) {
        foundQuad = quads.map(quad -> {
            if (path.size() > 1) {
                /*
           * make sure paths are not further retrieved, when the object has a value type
           * this could lead to false positives if the value of the property is a uri used as part of the path
           */
                if (quad.getValuetype().isPresent()) {
                    return Optional.<CursorQuad>empty();
                }
                return getDataQuad(path.subList(1, path.size()), quad.getObject(), quadStore);
            } else {
                return Optional.of(quad);
            }
        }).filter(Optional::isPresent).findFirst().map(Optional::get);
    }
    return foundQuad;
}
Also used : CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) DirectionalStep(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.DirectionalStep)

Aggregations

Test (org.junit.Test)42 Value (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)32 Graph (nl.knaw.huygens.timbuctoo.v5.util.Graph)22 ChangeMatcher.likeChange (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange)18 Map (java.util.Map)15 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)15 ExecutionException (java.util.concurrent.ExecutionException)12 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)11 PredicateMutation (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation)11 EditMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog)10 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)9 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)9 List (java.util.List)8 IOException (java.io.IOException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)6 CustomProvenance (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance)6 Optional (java.util.Optional)5