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;
}
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;
}
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);
}
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")));
}
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));
}
Aggregations