Search in sources :

Example 1 with Change

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);
}
Also used : Change(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change) JsonSubTypes(com.fasterxml.jackson.annotation.JsonSubTypes) RdfConstants(nl.knaw.huygens.timbuctoo.v5.util.RdfConstants) Spliterators(java.util.Spliterators) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Collectors(java.util.stream.Collectors) List(java.util.List) Lists(com.google.common.collect.Lists) Stream(java.util.stream.Stream) JsonTypeInfo(com.fasterxml.jackson.annotation.JsonTypeInfo) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Spliterator(java.util.Spliterator) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) JsonNode(com.fasterxml.jackson.databind.JsonNode) Change(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)

Example 2 with Change

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>>() {
    })));
}
Also used : Change(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) Map(java.util.Map)

Example 3 with Change

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))));
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) EditMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) Test(org.junit.Test)

Example 4 with Change

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()));
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) CreateMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog) Test(org.junit.Test)

Example 5 with Change

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))));
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) EditMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)36 Graph (nl.knaw.huygens.timbuctoo.v5.util.Graph)33 ChangeMatcher.likeChange (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange)32 Value (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)24 EditMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 TypeNameStore (nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)5 Change (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change)5 CustomProvenance (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance)5 ProvenanceChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ProvenanceChangeLog)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Map (java.util.Map)4 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)4 Stream (java.util.stream.Stream)3 CreateMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog)3 DeleteMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog)3 JsonSubTypes (com.fasterxml.jackson.annotation.JsonSubTypes)2 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2