Search in sources :

Example 11 with TinkerPopPropertyConverter

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.

the class TinkerPopOperations method assertProperty.

@Override
public void assertProperty(Vre vre, String entityRdfUri, RdfProperty property) {
    Vertex vertex = assertEntity(vre, entityRdfUri);
    Object value;
    try {
        // The TinkerPopConverter does not need a collection for the external -> db case.
        // It does need one for the db -> external case (but we're not using that one here)
        TinkerPopPropertyConverter propertyConverter = new TinkerPopPropertyConverter(null);
        Tuple<String, Object> convert = property.getTimProperty().convert(propertyConverter);
        value = convert.getRight();
    } catch (IOException e) {
        LOG.error("Could not parse timproperty of '{}' with value '{}' for entity '{}'", property.getPredicateUri(), property.getValue(), entityRdfUri);
        value = property.getValue();
    }
    // to be able to use the value in a lambda
    final Object val = value;
    collectionsFor(vertex).forEachRemaining(collection -> {
        getProp(collection, ENTITY_TYPE_NAME_PROPERTY_NAME, String.class).ifPresent(entityTypeName -> {
            vertex.property(createPropName(entityTypeName, property.getPredicateUri()), val);
        });
    });
    assertPredicateAndValueType(vertex, getPredicateValueTypeVertexFor(vre), property);
    committer.tick();
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexDuplicator.duplicateVertex(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.duplicateVertex) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) IOException(java.io.IOException)

Aggregations

TinkerPopPropertyConverter (nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter)11 Test (org.junit.Test)8 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)6 ReadableProperty (nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty)5 IOException (java.io.IOException)3 VertexDuplicator.duplicateVertex (nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.duplicateVertex)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 URI (java.net.URI)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1