use of nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty in project timbuctoo by HuygensING.
the class JsonPropertyConverterTest 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("prop")).thenReturn(Optional.of(readableProperty));
JsonPropertyConverter instance = new JsonPropertyConverter(collection);
TimProperty<?> from = instance.from("prop", jsn("1800"));
assertThat(from.getValue(), is("1800"));
}
use of nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty 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.model.properties.ReadableProperty in project timbuctoo by HuygensING.
the class Collection method loadProperties.
private static LinkedHashMap<String, ReadableProperty> loadProperties(Vertex collectionVertex, Vre vre) {
final Iterator<Vertex> initialV = collectionVertex.vertices(Direction.OUT, HAS_INITIAL_PROPERTY_RELATION_NAME);
final LinkedHashMap<String, ReadableProperty> properties = Maps.newLinkedHashMap();
if (!initialV.hasNext()) {
return properties;
}
Vertex current = initialV.next();
try {
properties.put(current.value(ReadableProperty.CLIENT_PROPERTY_NAME), ReadableProperty.load(current, vre.getVreName()));
while (current.vertices(Direction.OUT, ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME).hasNext()) {
current = current.vertices(Direction.OUT, ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME).next();
properties.put(current.value(ReadableProperty.CLIENT_PROPERTY_NAME), ReadableProperty.load(current, vre.getVreName()));
}
} catch (IOException | NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) {
LOG.error(databaseInvariant, "Failed to load configuration for property {} for collection {} ", current.property(ReadableProperty.CLIENT_PROPERTY_NAME).isPresent() ? current.value(ReadableProperty.CLIENT_PROPERTY_NAME) : "", collectionVertex.value(COLLECTION_NAME_PROPERTY_NAME), e);
}
return properties;
}
use of nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty in project timbuctoo by HuygensING.
the class Collection method load.
public static Collection load(Vertex collectionVertex, Vre vre) {
final Vertex archetype = collectionVertex.vertices(Direction.OUT, HAS_ARCHETYPE_RELATION_NAME).hasNext() ? collectionVertex.vertices(Direction.OUT, HAS_ARCHETYPE_RELATION_NAME).next() : null;
final String entityTypeName = collectionVertex.value(ENTITY_TYPE_NAME_PROPERTY_NAME);
final String abstractType = archetype == null ? entityTypeName : archetype.value(ENTITY_TYPE_NAME_PROPERTY_NAME);
final ReadableProperty displayName = loadDisplayName(collectionVertex, vre);
final LinkedHashMap<String, ReadableProperty> properties = loadProperties(collectionVertex, vre);
final String collectionName = collectionVertex.value(COLLECTION_NAME_PROPERTY_NAME);
final String label = getProp(collectionVertex, COLLECTION_LABEL_PROPERTY_NAME, String.class).orElse(null);
final String description = getProp(collectionVertex, COLLECTION_DESCRIPTION_PROPERTY_NAME, String.class).orElse(null);
boolean isRelationCollection = collectionVertex.value(IS_RELATION_COLLECTION_PROPERTY_NAME);
boolean unknown = getProp(collectionVertex, COLLECTION_IS_UNKNOWN_PROPERTY_NAME, Boolean.class).orElse(false);
return new Collection(entityTypeName, abstractType, displayName, properties, collectionName, vre, label, unknown, isRelationCollection, description);
}
use of nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty 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