use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change in project timbuctoo by HuygensING.
the class ChangeLog method getProvenanceChanges.
protected Stream<Change> getProvenanceChanges(DataSet dataSet, String[] subjects, CustomProvenance provenance, Map<String, JsonNode> values) {
TypeNameStore typeNameStore = dataSet.getTypeNameStore();
Stream<Change> customProv = provenance.getFields().stream().filter(field -> field.getValueType() != null).flatMap(field -> {
String graphQlPred = typeNameStore.makeGraphQlnameForPredicate(field.getUri(), Direction.OUT, field.isList());
return Stream.of(subjects).map(subject -> new Change(subject, field.getUri(), getValues(dataSet, values.get(graphQlPred)), Stream.empty()));
});
Stream<Change> customProvNested = provenance.getFields().stream().filter(field -> field.getObject() != null).flatMap(field -> {
String graphQlPred = typeNameStore.makeGraphQlnameForPredicate(field.getUri(), Direction.OUT, field.isList());
JsonNode objectValues = values.get(graphQlPred);
if (objectValues.isArray()) {
Spliterator<JsonNode> spliterator = Spliterators.spliteratorUnknownSize(objectValues.iterator(), Spliterator.ORDERED);
return StreamSupport.stream(spliterator, false).flatMap(newObjectValues -> getChangesForProvObject(dataSet, newObjectValues, subjects, field));
}
return getChangesForProvObject(dataSet, objectValues, subjects, field);
});
return Stream.concat(customProv, customProvNested);
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change in project timbuctoo by HuygensING.
the class ChangeLog method getChangesForProvObject.
private Stream<Change> getChangesForProvObject(DataSet dataSet, JsonNode objectValues, String[] subjects, CustomProvenance.CustomProvenanceValueFieldInput field) {
String newSubject;
if (objectValues.get("uri") != null) {
newSubject = objectValues.get("uri").asText();
} else {
TypeNameStore typeNameStore = dataSet.getTypeNameStore();
String typeName = typeNameStore.makeGraphQlnameForPredicate(field.getObject().getType(), Direction.OUT, field.isList());
newSubject = RdfConstants.dataSetObjectUri(dataSet, typeName);
}
return Stream.concat(Stream.concat(Stream.of(subjects).map(subject -> new Change(subject, field.getUri(), new Change.Value(newSubject, null))), Stream.of(new Change(newSubject, RdfConstants.RDF_TYPE, new Change.Value(field.getObject().getType(), null)))), getProvenanceChanges(dataSet, new String[] { newSubject }, field.getObject(), OBJECT_MAPPER.convertValue(objectValues, new TypeReference<Map<String, JsonNode>>() {
})));
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change in project timbuctoo by HuygensING.
the class ChangeLogSerializationTest method editMutationChangeLogIsSerializable.
@Test
public void editMutationChangeLogIsSerializable() throws Exception {
String addedValue = "newValue";
Map<Object, Object> additions = Maps.newHashMap();
additions.put(FIELD, newArrayList(createPropertyInput(addedValue)));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("additions", additions);
EditMutationChangeLog preSerialization = new EditMutationChangeLog(new Graph("http://example.org/graph"), "http://example.org/subj", entity);
String serialized = OBJECT_MAPPER.writeValueAsString(preSerialization);
List<Change> postAdditions = OBJECT_MAPPER.readValue(serialized, ChangeLog.class).getAdditions(dataSet).collect(Collectors.toList());
assertThat(postAdditions, contains(likeChange().withValues(new Change.Value(addedValue, STRING))));
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change in project timbuctoo by HuygensING.
the class CreateMutationChangeLogTest method getAdditionsReturnsCreations.
@Test
public void getAdditionsReturnsCreations() throws Exception {
String addedValue = "newValue";
Map<Object, Object> creations = Maps.newHashMap();
creations.put(NAMES_FIELD, createPropertyInput(addedValue));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("creations", creations);
CreateMutationChangeLog instance = new CreateMutationChangeLog(new Graph(GRAPH), SUBJECT, TYPE_URI, entity);
List<Change> adds = instance.getAdditions(dataSet).collect(toList());
assertThat(adds.size(), is(2));
assertThat(adds.get(0), is(likeChange().withValues(new Value(TYPE_URI, null)).oldValuesIsEmpty()));
assertThat(adds.get(1), is(likeChange().withValues(new Value(addedValue, STRING)).oldValuesIsEmpty()));
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change in project timbuctoo by HuygensING.
the class EditMutationChangeLogTest method getDeletionsForListReturnsDeletions.
@Test
public void getDeletionsForListReturnsDeletions() throws Exception {
String existingValue1 = "existingValue1";
String existingValue2 = "existingValue2";
Map<Object, Object> deletions = Maps.newHashMap();
deletions.put(NAMES_FIELD, newArrayList(createPropertyInput(existingValue2)));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("deletions", deletions);
EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
valuesInQuadStore(NAMES_PRED, existingValue1, existingValue2);
List<Change> deletes = instance.getDeletions(dataSet).collect(toList());
assertThat(deletes.size(), is(1));
assertThat(deletes, contains(likeChange().valuesIsEmpty().withOldValues(new Value(existingValue2, STRING))));
}
Aggregations