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