Search in sources :

Example 1 with PropertyDescriptor

use of nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor 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 PropertyDescriptor

use of nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor in project timbuctoo by HuygensING.

the class AppenderPropertyDescriptorTest method getReturnsOnlyTheValueOfTheFirstDescriptorIfTheSecondReturnsNull.

@Test
public void getReturnsOnlyTheValueOfTheFirstDescriptorIfTheSecondReturnsNull() {
    PropertyDescriptor propertyDescriptor1 = propertyDescriptorThatReturns("value1");
    PropertyDescriptor propertyDescriptor2 = propertyDescriptorThatReturns(null);
    String separator = " ";
    AppenderPropertyDescriptor instance = new AppenderPropertyDescriptor(propertyDescriptor1, propertyDescriptor2, separator);
    Vertex vertex = vertex().build();
    String value = instance.get(vertex);
    assertThat(value, is("value1"));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PropertyDescriptor(nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor) Test(org.junit.Test)

Example 3 with PropertyDescriptor

use of nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor in project timbuctoo by HuygensING.

the class AppenderPropertyDescriptorTest method propertyDescriptorThatReturns.

private PropertyDescriptor propertyDescriptorThatReturns(String value) {
    PropertyDescriptor propertyDescriptor1 = mock(PropertyDescriptor.class);
    given(propertyDescriptor1.get(any())).willReturn(value);
    return propertyDescriptor1;
}
Also used : PropertyDescriptor(nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor)

Example 4 with PropertyDescriptor

use of nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor in project timbuctoo by HuygensING.

the class CompositePropertyDescriptorTest method getReturnsTheValueOfTheSecondPropDescriptionIfTheValueOfTheFirstOneItIsNull.

@Test
public void getReturnsTheValueOfTheSecondPropDescriptionIfTheValueOfTheFirstOneItIsNull() {
    PropertyDescriptor propertyDescriptor1 = mock(PropertyDescriptor.class);
    given(propertyDescriptor1.get(any(Vertex.class))).willReturn(null);
    PropertyDescriptor propertyDescriptor2 = mock(PropertyDescriptor.class);
    String valueOfDesc2 = "notNull";
    given(propertyDescriptor2.get(any(Vertex.class))).willReturn(valueOfDesc2);
    CompositePropertyDescriptor instance = new CompositePropertyDescriptor(propertyDescriptor1, propertyDescriptor2);
    String value = instance.get(mock(Vertex.class));
    assertThat(value, is(valueOfDesc2));
    verify(propertyDescriptor1).get(any(Vertex.class));
    verify(propertyDescriptor2).get(any(Vertex.class));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PropertyDescriptor(nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor) Test(org.junit.Test)

Example 5 with PropertyDescriptor

use of nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor in project timbuctoo by HuygensING.

the class PropertyDescriptorFactoryTest method getCompositeReturnsACompositePropertyDescriptor.

@Test
public void getCompositeReturnsACompositePropertyDescriptor() {
    PropertyDescriptor descriptor = instance.getComposite(mock(PropertyDescriptor.class), mock(PropertyDescriptor.class));
    assertThat(descriptor, is(instanceOf(CompositePropertyDescriptor.class)));
}
Also used : PropertyDescriptor(nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor) Test(org.junit.Test)

Aggregations

PropertyDescriptor (nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor)15 Test (org.junit.Test)11 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)7 PropertyParser (nl.knaw.huygens.timbuctoo.search.description.PropertyParser)3 PersonNames (nl.knaw.huygens.timbuctoo.model.PersonNames)1 ElementValidationResult (nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult)1 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)1 Node (org.neo4j.graphdb.Node)1 IndexManager (org.neo4j.graphdb.index.IndexManager)1