use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method toReturnsTheNameOfAnArrayOfLimitedValuesProperty.
@Test
public void toReturnsTheNameOfAnArrayOfLimitedValuesProperty() throws Exception {
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(null);
ArrayOfLimitedValuesProperty property = new ArrayOfLimitedValuesProperty("name", "[]");
Tuple<String, Object> value = instance.to(property);
assertThat(value.getLeft(), is("name"));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method fromThrowsAnIoExceptionIfThePropertyCannotBeConverted.
@Test(expected = IOException.class)
public void fromThrowsAnIoExceptionIfThePropertyCannotBeConverted() throws UnknownPropertyException, IOException {
Collection collection = mock(Collection.class);
ReadableProperty readableProperty = mock(ReadableProperty.class);
when(readableProperty.getUniqueTypeId()).thenReturn("string");
when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.of(readableProperty));
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
instance.from(PROPERTY_NAME, new Object());
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method toThrowsAnExceptionWhenTheDateFormatIsNotSupported.
@Test(expected = IOException.class)
public void toThrowsAnExceptionWhenTheDateFormatIsNotSupported() throws Exception {
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(null);
DatableProperty property = new DatableProperty(PROPERTY_NAME, "01-02-180");
instance.to(property);
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method fromCreatesAStringPropertyWhenUsesTheUniqueTypeIdOfThePropertyToDetermineTheTimPropertyType.
@Test
public void fromCreatesAStringPropertyWhenUsesTheUniqueTypeIdOfThePropertyToDetermineTheTimPropertyType() throws UnknownPropertyException, IOException {
Collection collection = mock(Collection.class);
ReadableProperty readableProperty = mock(ReadableProperty.class);
when(readableProperty.getUniqueTypeId()).thenReturn("string");
when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.of(readableProperty));
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
TimProperty property = instance.from(PROPERTY_NAME, STRING_VALUE);
assertThat(property, is(instanceOf(StringProperty.class)));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter in project timbuctoo by HuygensING.
the class TinkerPopOperations method replaceEntity.
@Override
public int replaceEntity(Collection collection, UpdateEntity updateEntity) throws NotFoundException, AlreadyUpdatedException, IOException {
requireCommit = true;
GraphTraversal<Vertex, Vertex> entityTraversal = entityFetcher.getEntity(this.traversal, updateEntity.getId(), null, collection.getCollectionName());
if (!entityTraversal.hasNext()) {
throw new NotFoundException();
}
Vertex entityVertex = entityTraversal.next();
int curRev = getProp(entityVertex, "rev", Integer.class).orElse(1);
if (curRev != updateEntity.getRev()) {
throw new AlreadyUpdatedException();
}
int newRev = updateEntity.getRev() + 1;
entityVertex.property("rev", newRev);
// update properties
TinkerPopPropertyConverter tinkerPopPropertyConverter = new TinkerPopPropertyConverter(collection);
for (TimProperty<?> property : updateEntity.getProperties()) {
try {
Tuple<String, Object> nameValue = property.convert(tinkerPopPropertyConverter);
collection.getWriteableProperties().get(nameValue.getLeft()).setValue(entityVertex, nameValue.getRight());
} catch (IOException e) {
throw new IOException(property.getName() + " could not be saved. " + e.getMessage(), e);
}
}
// Set removed values to null.
Set<String> propertyNames = updateEntity.getProperties().stream().map(prop -> prop.getName()).collect(Collectors.toSet());
for (String name : Sets.difference(collection.getWriteableProperties().keySet(), propertyNames)) {
collection.getWriteableProperties().get(name).setJson(entityVertex, null);
}
String entityTypesStr = getProp(entityVertex, "types", String.class).orElse("[]");
boolean wasAddedToCollection = false;
if (!entityTypesStr.contains("\"" + collection.getEntityTypeName() + "\"")) {
try {
ArrayNode entityTypes = arrayToEncodedArray.tinkerpopToJson(entityTypesStr);
entityTypes.add(collection.getEntityTypeName());
entityVertex.property("types", entityTypes.toString());
wasAddedToCollection = true;
} catch (IOException e) {
// FIXME potential bug?
LOG.error(Logmarkers.databaseInvariant, "property 'types' was not parseable: " + entityTypesStr);
}
}
setModified(entityVertex, updateEntity.getModified());
entityVertex.property("pid").remove();
Vertex duplicate = duplicateVertex(traversal, entityVertex, indexHandler);
listener.onPropertyUpdate(collection, Optional.of(entityVertex), duplicate);
if (wasAddedToCollection) {
listener.onAddToCollection(collection, Optional.of(entityVertex), duplicate);
}
return newRev;
}
Aggregations