Search in sources :

Example 1 with CustomProvenance

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance 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 CustomProvenance

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance in project timbuctoo by HuygensING.

the class DerivedInputTypeSchemaGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    graphQlNameGenerator = mock(GraphQlNameGenerator.class);
    when(graphQlNameGenerator.createObjectTypeName(ROOT_TYPE, TYPE_URI)).thenReturn(TYPE);
    derivedSchemaContainer = mock(DerivedSchemaContainer.class);
    when(derivedSchemaContainer.propertyInputType(anyList())).thenReturn("PropertyInput");
    readOnlyChecker = new ReadOnlyChecker() {

        @Override
        public boolean isReadonlyPredicate(String predicateIri) {
            return READ_ONLY_PRED.equals(predicateIri);
        }

        @Override
        public boolean isReadonlyType(String typeUri) {
            return READ_ONLY_TYPE.equals(typeUri);
        }
    };
    instanceNoProv = new DerivedInputTypeSchemaGenerator(TYPE_URI, ROOT_TYPE, graphQlNameGenerator, derivedSchemaContainer, readOnlyChecker, new CustomProvenance(Collections.emptyList()));
    instanceProv = new DerivedInputTypeSchemaGenerator(TYPE_URI, ROOT_TYPE, graphQlNameGenerator, derivedSchemaContainer, readOnlyChecker, CustomProvenance.getCustomProvenance(ImmutableMap.of("fields", Lists.newArrayList(ImmutableMap.of("uri", "http://example.org/name", "isList", false, "valueType", STRING)))));
}
Also used : ReadOnlyChecker(nl.knaw.huygens.timbuctoo.v5.dataset.ReadOnlyChecker) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) CustomProvenance(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance) Before(org.junit.Before)

Example 3 with CustomProvenance

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance in project timbuctoo by HuygensING.

the class DerivedSchemaContainerTest method addsCustomProvenanceCreationMethod.

@Test
public void addsCustomProvenanceCreationMethod() {
    DerivedSchemaContainer instance = createWithProvenance(new CustomProvenance(newArrayList()));
    String schema = instance.getSchema();
    assertThat(schema, containsString("type rootTypeMutations{\n" + "  setCustomProvenance(customProvenance: CustomProvenanceInput!): Message!" + " @setCustomProvenanceMutation(dataSet: \"rootType\")\n"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) CustomProvenance(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance) Test(org.junit.Test)

Example 4 with CustomProvenance

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance in project timbuctoo by HuygensING.

the class ProvenanceChangeLogTest method getProvenanceForListField.

@Test
public void getProvenanceForListField() throws Exception {
    CustomProvenance customProvenance = CustomProvenance.getCustomProvenance(ImmutableMap.of("fields", Lists.newArrayList(ImmutableMap.of("uri", NAME_URI, "isList", true, "valueType", STRING))));
    when(dataSet.getCustomProvenance()).thenReturn(customProvenance);
    String value1 = "value1";
    String value2 = "value2";
    Map<Object, Object> provenance = Maps.newHashMap();
    provenance.put(NAME_FIELD, newArrayList(createPropertyInput(value1), createPropertyInput(value2)));
    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(value1, STRING), new Value(value2, 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 5 with CustomProvenance

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance in project timbuctoo by HuygensING.

the class ProvenanceChangeLogTest method getProvenanceForObjectField.

@Test
public void getProvenanceForObjectField() 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("uri", SUBJECT_NAME_1);
    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.size(), is(3));
    assertThat(provChanges.get(0), is(likeChange().withSubject(SUBJECT).withPredicate(NAME_URI).withValues(new Value(SUBJECT_NAME_1, null)).oldValuesIsEmpty()));
    assertThat(provChanges.get(1), is(likeChange().withSubject(SUBJECT_NAME_1).withPredicate(RDF_TYPE).withValues(new Value(TYPE_URI, null)).oldValuesIsEmpty()));
    assertThat(provChanges.get(2), is(likeChange().withSubject(SUBJECT_NAME_1).withPredicate(FIRST_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)

Aggregations

CustomProvenance (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance)9 Test (org.junit.Test)7 ChangeMatcher.likeChange (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange)5 ProvenanceChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ProvenanceChangeLog)5 Value (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)4 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)3 Predicate (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JsonSubTypes (com.fasterxml.jackson.annotation.JsonSubTypes)2 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Map (java.util.Map)2 Spliterator (java.util.Spliterator)2 Spliterators (java.util.Spliterators)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2