Search in sources :

Example 31 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class JsonCrudService method getEntity.

private JsonNode getEntity(UUID id, Integer rev, Collection collection) throws NotFoundException {
    ReadEntity entity = timDbAccess.getEntity(collection, id, rev, (entity1, entityVertex) -> {
    }, (traversalSource, vre, target, relationRef) -> {
    });
    ObjectNode result = entityToJsonMapper.mapEntity(collection, entity, true, (readEntity, resultJson) -> {
    }, (relationRef, resultJson) -> {
    });
    return result;
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 32 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class EntityToJsonMapper method mapEntity.

public ObjectNode mapEntity(Collection collection, ReadEntity entity, boolean withRelations, ExtraEntityMappingOptions extraEntityMappingOptions, ExtraRelationMappingOptions relationMappingOptions) {
    final ObjectNode mappedEntity = JsonNodeFactory.instance.objectNode();
    String id = entity.getId().toString();
    mappedEntity.set("@type", jsn(collection.getEntityTypeName()));
    mappedEntity.set("_id", jsn(id));
    mappedEntity.set("^rev", jsn(entity.getRev()));
    mappedEntity.set("^deleted", jsn(entity.getDeleted()));
    mappedEntity.set("^pid", jsn(entity.getPid()));
    if (entity.getRdfUri() != null) {
        mappedEntity.set("^rdfUri", jsn(entity.getRdfUri().toString()));
    }
    mappedEntity.set("^rdfAlternatives", jsnA(entity.getRdfAlternatives().stream().map(JsonBuilder::jsn)));
    JsonNode variationRefs = jsnA(entity.getTypes().stream().map(type -> {
        ObjectNode variationRef = jsnO();
        variationRef.set("id", jsn(id));
        variationRef.set("type", jsn(type));
        return variationRef;
    }));
    mappedEntity.set("@variationRefs", variationRefs);
    Change modified = entity.getModified();
    mappedEntity.set("^modified", mapChange(modified));
    Change created = entity.getCreated();
    mappedEntity.set("^created", mapChange(created));
    // translate TimProperties to Json
    JsonPropertyConverter jsonPropertyConverter = new JsonPropertyConverter(collection);
    entity.getProperties().forEach(prop -> {
        try {
            Tuple<String, JsonNode> convertedProperty = prop.convert(jsonPropertyConverter);
            mappedEntity.set(convertedProperty.getLeft(), convertedProperty.getRight());
        } catch (IOException e) {
            LOG.error(databaseInvariant, propConversionErrorMessage(id, prop));
            LOG.error("Exception message: {}", e.getMessage());
            LOG.debug("Stack trace", e);
        }
    });
    if (!Strings.isNullOrEmpty(entity.getDisplayName())) {
        mappedEntity.set("@displayName", jsn(entity.getDisplayName()));
    }
    extraEntityMappingOptions.execute(entity, mappedEntity);
    if (withRelations) {
        mappedEntity.set("@relationCount", jsn(entity.getRelations().size()));
        mappedEntity.set("@relations", mapRelations(entity.getRelations(), relationMappingOptions));
    }
    return mappedEntity;
}
Also used : JsonBuilder(nl.knaw.huygens.timbuctoo.util.JsonBuilder) UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) JsonBuilder(nl.knaw.huygens.timbuctoo.util.JsonBuilder) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UrlGenerator(nl.knaw.huygens.timbuctoo.crud.UrlGenerator) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Strings(com.google.common.base.Strings) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Logmarkers.databaseInvariant(nl.knaw.huygens.timbuctoo.logging.Logmarkers.databaseInvariant) RelationRef(nl.knaw.huygens.timbuctoo.core.dto.RelationRef) Logger(org.slf4j.Logger) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) UUID(java.util.UUID) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Change(nl.knaw.huygens.timbuctoo.model.Change) Tuple.tuple(nl.knaw.huygens.timbuctoo.util.Tuple.tuple) UserValidationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) Change(nl.knaw.huygens.timbuctoo.model.Change) IOException(java.io.IOException)

Example 33 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class WomenWritersJsonCrudService method getEntity.

private JsonNode getEntity(UUID id, Integer rev, Collection collection) throws NotFoundException {
    CustomEntityMapping customEntityMapping = new CustomEntityMapping();
    CustomRelationMapping customRelationMapping = new CustomRelationMapping();
    ReadEntity entity = timDbAccess.getEntity(collection, id, rev, customEntityMapping, customRelationMapping);
    return entityToJsonMapper.mapEntity(collection, entity, true, customEntityMapping, customRelationMapping);
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)

Example 34 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class TripleImporterIntegrationTest method importTripleAddsTheCollectionsAndTheArchetypeToTheTypesPropOfTheSubject.

@Test
public void importTripleAddsTheCollectionsAndTheArchetypeToTheTypesPropOfTheSubject() throws Exception {
    final Triple abadanIsAFeature = createTripleIterator(ABADAN_HAS_TYPE_FEATURE_TRIPLE).next();
    instance.importTriple(true, abadanIsAFeature);
    rdfImportSession.commit();
    rdfImportSession.close();
    Optional<ReadEntity> readEntity = getReadEntity(COLLECTION_NAME, ABADAN_URI);
    assertThat(readEntity.get(), hasProperty("types", containsInAnyOrder(TYPE_NAME, "concept")));
}
Also used : Triple(org.apache.jena.graph.Triple) TripleCreator.createSingleTriple(nl.knaw.huygens.timbuctoo.rdf.TripleCreator.createSingleTriple) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Test(org.junit.Test)

Example 35 with ReadEntity

use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.

the class TripleImporterIntegrationTest method importTripleShouldSetsTheRdfUriAsDisplayName.

@Test
public void importTripleShouldSetsTheRdfUriAsDisplayName() throws Exception {
    final Triple abadanIsAFeature = createTripleIterator(ABADAN_HAS_TYPE_FEATURE_TRIPLE).next();
    final Triple abadanIsAFictionalFeature = createTripleIterator(ABADAN_HAS_TYPE_FICTIONAL_FEATURE_TRIPLE).next();
    final Triple abadanHasPoint = createTripleIterator(ABADAN_POINT_TRIPLE).next();
    instance.importTriple(true, abadanIsAFeature);
    instance.importTriple(true, abadanIsAFictionalFeature);
    instance.importTriple(true, abadanHasPoint);
    rdfImportSession.commit();
    rdfImportSession.close();
    Optional<ReadEntity> type = getReadEntity(COLLECTION_NAME, ABADAN_URI);
    assertThat(type.get().getDisplayName(), is(ABADAN_URI));
}
Also used : Triple(org.apache.jena.graph.Triple) TripleCreator.createSingleTriple(nl.knaw.huygens.timbuctoo.rdf.TripleCreator.createSingleTriple) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Test(org.junit.Test)

Aggregations

ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)37 Test (org.junit.Test)30 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)28 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)26 IOException (java.io.IOException)25 List (java.util.List)25 UUID (java.util.UUID)25 Optional (java.util.Optional)24 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)24 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)23 URI (java.net.URI)23 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)23 DataStream (nl.knaw.huygens.timbuctoo.core.dto.DataStream)23 Change (nl.knaw.huygens.timbuctoo.model.Change)23 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)23 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)23 JsonBuilder.jsnO (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO)23 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)22 Lists (com.google.common.collect.Lists)22