use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method fromThrowsAnUnknownPropertyExceptionWhenThePropertyDoesNotExistInTheCollection.
@Test(expected = UnknownPropertyException.class)
public void fromThrowsAnUnknownPropertyExceptionWhenThePropertyDoesNotExistInTheCollection() throws UnknownPropertyException, IOException {
Collection collection = mock(Collection.class);
when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.empty());
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
instance.from(PROPERTY_NAME, STRING_VALUE);
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method toReturnsAJsonEncodedStringForADatableProperty.
@Test
public void toReturnsAJsonEncodedStringForADatableProperty() throws Exception {
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(null);
DatableProperty property = new DatableProperty(PROPERTY_NAME, "1800");
Tuple<String, Object> value = instance.to(property);
assertThat(value.getRight(), is("\"1800\""));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method fromReturnsADatablePropertyWithADecodedStringValue.
// Datable tests
@Test
public void fromReturnsADatablePropertyWithADecodedStringValue() throws Exception {
Collection collection = mock(Collection.class);
ReadableProperty readableProperty = mock(ReadableProperty.class);
when(readableProperty.getUniqueTypeId()).thenReturn("datable");
when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.of(readableProperty));
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
TimProperty<?> from = instance.from(PROPERTY_NAME, "\"1800\"");
assertThat(from.getValue(), is("1800"));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopOperations method createEntity.
@Override
public void createEntity(Collection col, Optional<Collection> baseCollection, CreateEntity input) throws IOException {
requireCommit = true;
Map<String, LocalProperty> mapping = col.getWriteableProperties();
TinkerPopPropertyConverter colConverter = new TinkerPopPropertyConverter(col);
Map<String, LocalProperty> baseMapping = baseCollection.isPresent() ? baseCollection.get().getWriteableProperties() : Maps.newHashMap();
TinkerPopPropertyConverter baseColConverter = // converter not needed without mapping
baseCollection.isPresent() ? new TinkerPopPropertyConverter(baseCollection.get()) : null;
GraphTraversal<Vertex, Vertex> traversalWithVertex = traversal.addV();
Vertex vertex = traversalWithVertex.next();
for (TimProperty<?> property : input.getProperties()) {
String fieldName = property.getName();
if (mapping.containsKey(fieldName)) {
try {
String dbName = mapping.get(fieldName).getDatabasePropertyName();
Tuple<String, Object> convertedProp = property.convert(colConverter);
vertex.property(dbName, convertedProp.getRight());
} catch (IOException e) {
throw new IOException(fieldName + " could not be saved. " + e.getMessage(), e);
}
} else {
throw new IOException(String.format("Items of %s have no property %s", col.getCollectionName(), fieldName));
}
if (baseMapping.containsKey(fieldName)) {
try {
property.convert(baseColConverter);
Tuple<String, Object> convertedProp = property.convert(baseColConverter);
baseMapping.get(fieldName).setValue(vertex, convertedProp.getRight());
} catch (IOException e) {
LOG.error(configurationFailure, "Field could not be parsed by Admin VRE converter {}_{}", baseCollection.get().getCollectionName(), fieldName);
}
}
}
setAdministrativeProperties(col, vertex, input);
Vertex duplicate = duplicateVertex(traversal, vertex, indexHandler);
listener.onCreate(col, duplicate);
// not passing oldVertex because old has never been passed to addToCollection so it doesn't need to be removed
listener.onAddToCollection(col, Optional.empty(), duplicate);
baseCollection.ifPresent(baseCol -> listener.onAddToCollection(baseCol, Optional.empty(), duplicate));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method fromThrowsAnUnknownPropertyExceptionWhenThePropertyHasAnUnknownUniqueTypeId.
@Test(expected = UnknownPropertyException.class)
public void fromThrowsAnUnknownPropertyExceptionWhenThePropertyHasAnUnknownUniqueTypeId() throws UnknownPropertyException, IOException {
Collection collection = mock(Collection.class);
ReadableProperty readableProperty = mock(ReadableProperty.class);
when(readableProperty.getUniqueTypeId()).thenReturn("unknownType");
when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.of(readableProperty));
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
instance.from(PROPERTY_NAME, STRING_VALUE);
}
Aggregations