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));
}
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);
}
Aggregations