Search in sources :

Example 1 with ElementValidationResult

use of nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult in project timbuctoo by HuygensING.

the class FullTextIndexCheck method check.

@Override
public ValidationResult check(Vertex vertex) {
    Boolean isLatest = vertex.property("isLatest").isPresent() ? (Boolean) vertex.property("isLatest").value() : false;
    if (isLatest) {
        final IndexManager indexManager = databaseService.index();
        String[] types = getEntityTypesOrDefault(vertex);
        Transaction transaction = graph.tx();
        // http://stackoverflow.com/questions/19428017
        if (!transaction.isOpen()) {
            transaction.open();
        }
        for (String type : types) {
            if (indexManager.existsForNodes(type + "s")) {
                final String timId = vertex.property("tim_id").isPresent() ? (String) vertex.property("tim_id").value() : null;
                if (timId == null) {
                    transaction.close();
                    return new ElementValidationResult(false, String.format("Vertex %s misses tim_id", vertex));
                } else {
                    final Index<Node> index = indexManager.forNodes(type + "s");
                    IndexHits<Node> hits = index.get("tim_id", timId);
                    if (hits.size() < 1) {
                        String message = String.format("Vertex with tim_id %s not found in index %ss", timId, type);
                        transaction.close();
                        return new ElementValidationResult(false, message);
                    }
                    if (hits.size() > 1) {
                        String message = String.format("Vertex with tim_id %s has duplicate entries in index %ss", timId, type);
                        transaction.close();
                        return new ElementValidationResult(false, message);
                    }
                    GraphTraversal<Vertex, Vertex> found = graph.traversal().V(hits.next().getId());
                    if (!found.hasNext()) {
                        String message = String.format("Vertex from index with tim_id %s is not present in graphdb", timId);
                        transaction.close();
                        return new ElementValidationResult(false, message);
                    }
                    Vertex foundVertex = found.next();
                    final PropertyDescriptor descriptor = displayNameDescriptors.get(type + "s");
                    if (descriptor.get(vertex) != null && descriptor.get(foundVertex) != null && !descriptor.get(vertex).equals(descriptor.get(foundVertex))) {
                        String message = String.format("Displayname of vertex from index does not match latest vertex with tim_id %s", timId);
                        transaction.close();
                        return new ElementValidationResult(false, message);
                    }
                }
            }
        }
        transaction.close();
    }
    return new ElementValidationResult(true, String.format("Vertex %s is valid", vertex));
}
Also used : IndexManager(org.neo4j.graphdb.index.IndexManager) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) PropertyDescriptor(nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor) ElementValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult) Node(org.neo4j.graphdb.Node)

Example 2 with ElementValidationResult

use of nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult in project timbuctoo by HuygensING.

the class InvariantsCheck method check.

@Override
public ValidationResult check(Vertex vertex) {
    List<ValidationResult> validationResults = Lists.newArrayList();
    String[] vertexTypes = getEntityTypesOrDefault(vertex);
    String id = vertex.value("tim_id");
    vertex.edges(Direction.BOTH).forEachRemaining(edge -> {
        if (!Objects.equals(edge.label(), "VERSION_OF")) {
            // ignore the VERSION_OF relations
            String[] edgeTypes = getEntityTypesOrDefault(edge);
            for (String edgeType : edgeTypes) {
                Optional<Collection> collectionOptional = vres.getCollectionForType(edgeType);
                String edgeId = edge.value("tim_id");
                if (!collectionOptional.isPresent()) {
                    validationResults.add(new ElementValidationResult(false, String.format("Edge with tim_id '%s' has contains unknown variant '%s'", edgeId, edgeType)));
                    continue;
                }
                Collection edgeCollection = collectionOptional.get();
                // Only check accepted edges / relations, Timbuctoo sees not accepted relations as deleted.
                if (isAccepted(edge, edgeType) && vreContainsAVariationOfTheVertex(vertexTypes, edgeCollection)) {
                    addInvalidVertex(validationResults, id, vertexTypes, edgeType, edgeId);
                }
            }
        }
    });
    return new CompositeValidationResult(validationResults);
}
Also used : ElementValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CompositeValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.CompositeValidationResult) ElementValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult) ValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.ValidationResult) CompositeValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.CompositeValidationResult)

Aggregations

ElementValidationResult (nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult)2 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)1 PropertyDescriptor (nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor)1 CompositeValidationResult (nl.knaw.huygens.timbuctoo.server.healthchecks.CompositeValidationResult)1 ValidationResult (nl.knaw.huygens.timbuctoo.server.healthchecks.ValidationResult)1 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1 Node (org.neo4j.graphdb.Node)1 IndexManager (org.neo4j.graphdb.index.IndexManager)1