Search in sources :

Example 1 with ReadableProperty

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"));
}
Also used : ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) JsonPropertyConverter(nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter) Test(org.junit.Test)

Example 2 with ReadableProperty

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"));
}
Also used : ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Example 3 with ReadableProperty

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;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ReadableProperty

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);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty)

Example 5 with ReadableProperty

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);
}
Also used : ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Aggregations

ReadableProperty (nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty)8 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)6 Test (org.junit.Test)5 TinkerPopPropertyConverter (nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)1 JsonPropertyConverter (nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter)1 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)1