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