Search in sources :

Example 1 with Neo4jIndexHandler

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

the class IndexAllEntityIds method execute.

@Override
public void execute(TinkerPopGraphManager graphManager) throws IOException {
    Vres vres = getVres(graphManager);
    Neo4jIndexHandler indexHandler = new Neo4jIndexHandler(graphManager);
    ObjectMapper mapper = new ObjectMapper();
    GraphTraversalSource traversalSource = graphManager.getGraph().traversal();
    traversalSource.V().has(// only valid entities
    "types").forEachRemaining(vertex -> {
        try {
            String[] types = mapper.readValue(vertex.<String>value("types"), String[].class);
            for (String type : types) {
                if (TYPES_TO_IGNORE.contains(type)) {
                    continue;
                }
                if (vres.getCollectionForType(type).isPresent()) {
                    VertexProperty<String> timIdProp = vertex.property("tim_id");
                    if (timIdProp.isPresent()) {
                        try {
                            UUID timId = UUID.fromString(timIdProp.value());
                            indexHandler.insertIntoIdIndex(timId, vertex);
                        } catch (IllegalArgumentException e) {
                            // This exception should not happen, but we do not want our migration to fail on it.
                            LOG.error("'{}' is not a valid id", timIdProp.value());
                        }
                    } else {
                        LOG.error("Vertex with id '{}' has no 'tim_id' property", vertex.id());
                    }
                } else {
                    LOG.error("'{}' is not a known entity type.", type);
                }
            }
        } catch (IOException e) {
            LOG.error("And exception occurred while indexing vertex with vertex id '{}'.", vertex.id());
        }
    });
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopOperationsForMigrations.getVres(nl.knaw.huygens.timbuctoo.server.databasemigration.TinkerPopOperationsForMigrations.getVres) Neo4jIndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jIndexHandler) IOException(java.io.IOException) UUID(java.util.UUID) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)

Aggregations

IOException (java.io.IOException)1 UUID (java.util.UUID)1 Neo4jIndexHandler (nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jIndexHandler)1 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)1 TinkerPopOperationsForMigrations.getVres (nl.knaw.huygens.timbuctoo.server.databasemigration.TinkerPopOperationsForMigrations.getVres)1 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)1