Search in sources :

Example 11 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class JsonCrudService method getCollection.

public List<ObjectNode> getCollection(String collectionName, int rows, int start, boolean withRelations) throws InvalidCollectionException {
    final Collection collection = mappings.getCollection(collectionName).orElseThrow(() -> new InvalidCollectionException(collectionName));
    DataStream<ReadEntity> entities = timDbAccess.getCollection(collection, start, rows, withRelations, (traversalSource, vre) -> {
    }, (entity1, entityVertex, target, relationRef) -> {
    });
    List<ObjectNode> result = entities.map(entity -> entityToJsonMapper.mapEntity(collection, entity, withRelations, (readEntity, resultJson) -> {
    }, (relationRef, resultJson) -> {
    }));
    return result;
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) EntityToJsonMapper(nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Iterator(java.util.Iterator) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) IOException(java.io.IOException) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) Optional(java.util.Optional) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)

Example 12 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class SingleEntityNTriple method get.

@GET
public Response get(@PathParam("collection") String collectionName, @PathParam("id") UUIDParam id, @QueryParam("rev") Integer rev) {
    return transactionEnforcer.executeAndReturn(timbuctooActions -> {
        try {
            Collection collection = timbuctooActions.getCollectionMetadata(collectionName);
            ReadEntity entity = timbuctooActions.getEntity(collection, id.get(), rev);
            URI rdfUri = entity.getRdfUri();
            String rdfString = rdfUri == null ? uriHelper.fromResourceUri(makeUrl(collectionName, id.get())).toString() : rdfUri.toString();
            StringBuilder sb = new StringBuilder();
            addRdfProp(rdfString, sb, "id", entity.getId() + "", "https://www.ietf.org/rfc/rfc4122.txt");
            entity.getRdfAlternatives().forEach(alt -> sb.append(asNtriples(new LinkTriple(rdfString, SAME_AS_PRED, alt))));
            TriplePropertyConverter converter = new TriplePropertyConverter(collection, rdfString);
            for (TimProperty<?> timProperty : entity.getProperties()) {
                try {
                    timProperty.convert(converter).getRight().forEach(triple -> sb.append(asNtriples(triple)));
                } catch (IOException e) {
                    LOG.error("Could not convert property with name '{}' and value '{}'", timProperty.getName(), timProperty.getValue());
                }
            }
            entity.getRelations().forEach(rel -> sb.append(asNtriples(new LinkTriple(rdfString, getRelationRdfUri(rel), getEntityRdfUri(rel)))));
            return commitAndReturn(Response.ok(sb.toString()).build());
        } catch (InvalidCollectionException e) {
            return commitAndReturn(Response.status(BAD_REQUEST).entity(e.getMessage()).build());
        } catch (NotFoundException e) {
            return commitAndReturn(Response.status(NOT_FOUND).build());
        }
    });
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) LinkTriple(nl.knaw.huygens.timbuctoo.rdf.LinkTriple) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) IOException(java.io.IOException) TriplePropertyConverter(nl.knaw.huygens.timbuctoo.rdf.conversion.TriplePropertyConverter) URI(java.net.URI) GET(javax.ws.rs.GET)

Example 13 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class TinkerPopOperations method getCollection.

@Override
public DataStream<ReadEntity> getCollection(Collection collection, int start, int rows, boolean withRelations, CustomEntityProperties customEntityProperties, CustomRelationProperties customRelationProperties) {
    GraphTraversal<Vertex, Vertex> entities = getCurrentEntitiesFor(collection.getEntityTypeName()).range(start, start + rows);
    TinkerPopToEntityMapper tinkerPopToEntityMapper = new TinkerPopToEntityMapper(collection, traversal, mappings, customEntityProperties, customRelationProperties);
    return new TinkerPopGetCollection(entities.toStream().map(vertex -> tinkerPopToEntityMapper.mapEntity(vertex, withRelations)));
}
Also used : AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) RdfImportedDefaultDisplayname(nl.knaw.huygens.timbuctoo.model.properties.RdfImportedDefaultDisplayname) VRE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.VRE_NAME_PROPERTY_NAME) EdgeManipulator.duplicateEdge(nl.knaw.huygens.timbuctoo.database.tinkerpop.EdgeManipulator.duplicateEdge) MediaType(javax.ws.rs.core.MediaType) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) COLLECTION_IS_UNKNOWN_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_IS_UNKNOWN_PROPERTY_NAME) Map(java.util.Map) Converters.arrayToEncodedArray(nl.knaw.huygens.timbuctoo.model.properties.converters.Converters.arrayToEncodedArray) JsonNode(com.fasterxml.jackson.databind.JsonNode) DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) RdfIndexChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.RdfIndexChangeListener) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) Logmarkers.configurationFailure(nl.knaw.huygens.timbuctoo.logging.Logmarkers.configurationFailure) Set(java.util.Set) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ImmutableValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableValueTypeInUse) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) DATABASE_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL) Element(org.apache.tinkerpop.gremlin.structure.Element) Stream(java.util.stream.Stream) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Index(org.neo4j.graphdb.index.Index) ERROR_PREFIX(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.ERROR_PREFIX) LocalProperty(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) Supplier(java.util.function.Supplier) Node(org.neo4j.graphdb.Node) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) ImmutableVresDto(nl.knaw.huygens.timbuctoo.core.dto.dataset.ImmutableVresDto) PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) StreamSupport(java.util.stream.StreamSupport) PropertyDescriptorFactory(nl.knaw.huygens.timbuctoo.search.description.property.PropertyDescriptorFactory) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) Logmarkers.databaseInvariant(nl.knaw.huygens.timbuctoo.logging.Logmarkers.databaseInvariant) RelationTypeService(nl.knaw.huygens.timbuctoo.relationtypes.RelationTypeService) AddLabelChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.AddLabelChangeListener) VreBuilder(nl.knaw.huygens.timbuctoo.model.vre.VreBuilder) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) ImmutablePredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutablePredicateInUse) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) HAS_NEXT_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME) DatabaseMigrator(nl.knaw.huygens.timbuctoo.server.databasemigration.DatabaseMigrator) Direction(org.apache.tinkerpop.gremlin.structure.Direction) VertexDuplicator.duplicateVertex(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.duplicateVertex) CompositeChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.CompositeChangeListener) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) WwDocumentDisplayNameDescriptor(nl.knaw.huygens.timbuctoo.search.description.property.WwDocumentDisplayNameDescriptor) RDFINDEX_NAME(nl.knaw.huygens.timbuctoo.rdf.Database.RDFINDEX_NAME) ImmutableEntityRelation(nl.knaw.huygens.timbuctoo.core.dto.ImmutableEntityRelation) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) Graph(org.apache.tinkerpop.gremlin.structure.Graph) LoggerFactory(org.slf4j.LoggerFactory) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) PropertyParserFactory(nl.knaw.huygens.timbuctoo.search.description.propertyparser.PropertyParserFactory) EntityRelation(nl.knaw.huygens.timbuctoo.core.dto.EntityRelation) TinkerPopToEntityMapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopToEntityMapper) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) P(org.apache.tinkerpop.gremlin.process.traversal.P) Property(org.apache.tinkerpop.gremlin.structure.Property) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) CollectionHasEntityRelationChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.CollectionHasEntityRelationChangeListener) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) ImmutableMap(com.google.common.collect.ImmutableMap) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) LocationNames(nl.knaw.huygens.timbuctoo.model.LocationNames) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) DirectionalRelationType(nl.knaw.huygens.timbuctoo.core.dto.DirectionalRelationType) Optional(java.util.Optional) FulltextIndexChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.FulltextIndexChangeListener) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) HAS_PREDICATE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PREDICATE_RELATION_NAME) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) HashMap(java.util.HashMap) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Function(java.util.function.Function) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) VreMetadata(nl.knaw.huygens.timbuctoo.model.vre.VreMetadata) Logmarkers(nl.knaw.huygens.timbuctoo.logging.Logmarkers) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) SAVED_MAPPING_STATE(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.SAVED_MAPPING_STATE) HAS_INITIAL_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_INITIAL_PROPERTY_RELATION_NAME) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) COLLECTION_ENTITIES_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_ENTITIES_LABEL) NoSuchElementException(java.util.NoSuchElementException) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) Logger(org.slf4j.Logger) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Iterator(java.util.Iterator) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) PropertyDescriptor(nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) TempName(nl.knaw.huygens.timbuctoo.model.TempName) Maps(com.google.common.collect.Maps) IdIndexChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.IdIndexChangeListener) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) TIMBUCTOO_NAMESPACE(nl.knaw.huygens.timbuctoo.server.databasemigration.RelationTypeRdfUriMigration.TIMBUCTOO_NAMESPACE) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) SystemPropertyModifier(nl.knaw.huygens.timbuctoo.rdf.SystemPropertyModifier) Collectors.toList(java.util.stream.Collectors.toList) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) Clock(java.time.Clock) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexDuplicator.duplicateVertex(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.duplicateVertex) TinkerPopToEntityMapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopToEntityMapper)

Example 14 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class TinkerPopToEntityMapper method mapEntity.

public ReadEntity mapEntity(GraphTraversal<Vertex, Vertex> entityT, boolean withRelations) {
    final List<TimProperty<?>> properties = Lists.newArrayList();
    TinkerPopPropertyConverter dbPropertyConverter = new TinkerPopPropertyConverter(collection);
    String entityTypeName = collection.getEntityTypeName();
    GraphTraversal[] propertyGetters = collection.getReadableProperties().entrySet().stream().map(prop -> prop.getValue().traversalRaw().sideEffect(x -> x.get().onSuccess(value -> {
        try {
            properties.add(dbPropertyConverter.from(prop.getKey(), value));
        } catch (UnknownPropertyException e) {
            LOG.error("Unknown property", e);
        } catch (IOException e) {
            LOG.error(databaseInvariant, "Property '" + prop.getKey() + "' is not encoded correctly", e.getCause());
        }
    }).onFailure(e -> {
        if (e.getCause() instanceof IOException) {
            LOG.error(databaseInvariant, "Property '" + prop.getKey() + "' is not encoded correctly", e.getCause());
        } else {
            LOG.error("Something went wrong while reading the property '" + prop.getKey() + "'.", e.getCause());
        }
    }))).toArray(GraphTraversal[]::new);
    entityT.asAdmin().clone().union(propertyGetters).forEachRemaining(x -> {
    // Force side effects to happen
    });
    ReadEntityImpl entity = new ReadEntityImpl();
    entity.setProperties(properties);
    Vertex entityVertex = entityT.asAdmin().clone().next();
    // TODO make use conversion for the types
    entity.setRev(getProp(entityVertex, "rev", Integer.class).orElse(-1));
    entity.setDeleted(getProp(entityVertex, "deleted", Boolean.class).orElse(false));
    entity.setPid(getProp(entityVertex, "pid", String.class).orElse(null));
    URI rdfUri = getProp(entityVertex, RDF_URI_PROP, String.class).map(x -> {
        try {
            return new URI(x);
        } catch (URISyntaxException e) {
            return null;
        }
    }).orElse(null);
    entity.setRdfUri(rdfUri);
    Property<String[]> rdfAlternativesProp = entityVertex.property(RDF_SYNONYM_PROP);
    if (rdfAlternativesProp.isPresent()) {
        try {
            entity.setRdfAlternatives(Lists.newArrayList(rdfAlternativesProp.value()));
        } catch (Exception e) {
            LOG.error(databaseInvariant, "Error while reading rdfAlternatives", e);
        }
    }
    Optional<String> typesOptional = getProp(entityVertex, "types", String.class);
    if (typesOptional.isPresent()) {
        try {
            List<String> types = new ObjectMapper().readValue(typesOptional.get(), new TypeReference<List<String>>() {
            });
            entity.setTypes(types);
        } catch (Exception e) {
            LOG.error(databaseInvariant, "Error while generating variation refs", e);
            entity.setTypes(Lists.newArrayList(entityTypeName));
        }
    } else {
        entity.setTypes(Lists.newArrayList(entityTypeName));
    }
    Optional<String> modifiedStringOptional = getProp(entityVertex, "modified", String.class);
    if (modifiedStringOptional.isPresent()) {
        try {
            entity.setModified(new ObjectMapper().readValue(modifiedStringOptional.get(), Change.class));
        } catch (IOException e) {
            LOG.error(databaseInvariant, "Change cannot be converted", e);
            entity.setModified(new Change());
        }
    } else {
        entity.setModified(new Change());
    }
    Optional<String> createdStringOptional = getProp(entityVertex, "created", String.class);
    if (createdStringOptional.isPresent()) {
        try {
            entity.setCreated(new ObjectMapper().readValue(createdStringOptional.get(), Change.class));
        } catch (IOException e) {
            LOG.error(databaseInvariant, "Change cannot be converted", e);
            entity.setCreated(new Change());
        }
    } else {
        entity.setCreated(new Change());
    }
    entity.setDisplayName(DisplayNameHelper.getDisplayname(traversalSource, entityVertex, collection).orElse(""));
    entity.setId(getIdOrDefault(entityVertex));
    if (withRelations) {
        entity.setRelations(getRelations(entityVertex, traversalSource, collection));
    }
    customEntityProperties.execute(entity, entityVertex);
    return entity;
}
Also used : StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CustomEntityProperties(nl.knaw.huygens.timbuctoo.database.tinkerpop.CustomEntityProperties) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) Lists(com.google.common.collect.Lists) Map(java.util.Map) URI(java.net.URI) TypeReference(com.fasterxml.jackson.core.type.TypeReference) P(org.apache.tinkerpop.gremlin.process.traversal.P) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Logmarkers.databaseInvariant(nl.knaw.huygens.timbuctoo.logging.Logmarkers.databaseInvariant) Property(org.apache.tinkerpop.gremlin.structure.Property) RelationRef(nl.knaw.huygens.timbuctoo.core.dto.RelationRef) Logger(org.slf4j.Logger) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) ReadEntityImpl(nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CustomRelationProperties(nl.knaw.huygens.timbuctoo.database.tinkerpop.CustomRelationProperties) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) IOException(java.io.IOException) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) T(org.apache.tinkerpop.gremlin.structure.T) GraphReadUtils.getEntityTypesOrDefault(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getEntityTypesOrDefault) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) UnknownPropertyException(nl.knaw.huygens.timbuctoo.core.UnknownPropertyException) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) EmptyGraph(org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) DisplayNameHelper(nl.knaw.huygens.timbuctoo.core.dto.DisplayNameHelper) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Optional(java.util.Optional) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Change(nl.knaw.huygens.timbuctoo.model.Change) UnknownPropertyException(nl.knaw.huygens.timbuctoo.core.UnknownPropertyException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UnknownPropertyException(nl.knaw.huygens.timbuctoo.core.UnknownPropertyException) ReadEntityImpl(nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method getEntityByRdfUriReturnsAnEmptyOptionalIfTheEntityCannotBeFound.

@Test
public void getEntityByRdfUriReturnsAnEmptyOptionalIfTheEntityCannotBeFound() {
    Vres vres = createConfiguration();
    TinkerPopOperations instance = forGraphWrapperAndMappings(newGraph().wrap(), vres);
    Collection collection = vres.getCollection("testthings").get();
    Optional<ReadEntity> readEntity = instance.getEntityByRdfUri(collection, "http://example.com/entity", false);
    assertThat(readEntity, is(not(present())));
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Aggregations

ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)37 Test (org.junit.Test)30 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)28 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)26 IOException (java.io.IOException)25 List (java.util.List)25 UUID (java.util.UUID)25 Optional (java.util.Optional)24 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)24 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)23 URI (java.net.URI)23 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)23 DataStream (nl.knaw.huygens.timbuctoo.core.dto.DataStream)23 Change (nl.knaw.huygens.timbuctoo.model.Change)23 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)23 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)23 JsonBuilder.jsnO (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO)23 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)22 Lists (com.google.common.collect.Lists)22