use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class JsonCrudService method getCollection.
public List<ObjectNode> getCollection(String collectionName, int rows, int start, boolean withRelations) throws InvalidCollectionException {
final Collection collection = mappings.getCollection(collectionName).orElseThrow(() -> new InvalidCollectionException(collectionName));
DataStream<ReadEntity> entities = timDbAccess.getCollection(collection, start, rows, withRelations, (traversalSource, vre) -> {
}, (entity1, entityVertex, target, relationRef) -> {
});
List<ObjectNode> result = entities.map(entity -> entityToJsonMapper.mapEntity(collection, entity, withRelations, (readEntity, resultJson) -> {
}, (relationRef, resultJson) -> {
}));
return result;
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TimbuctooActions method getCollectionMetadata.
public Collection getCollectionMetadata(String collectionName) throws InvalidCollectionException {
Vres vres = loadVres();
Optional<Collection> collection = vres.getCollection(collectionName);
return collection.orElseThrow(() -> new InvalidCollectionException(collectionName));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class SingleEntityNTriple method get.
@GET
public Response get(@PathParam("collection") String collectionName, @PathParam("id") UUIDParam id, @QueryParam("rev") Integer rev) {
return transactionEnforcer.executeAndReturn(timbuctooActions -> {
try {
Collection collection = timbuctooActions.getCollectionMetadata(collectionName);
ReadEntity entity = timbuctooActions.getEntity(collection, id.get(), rev);
URI rdfUri = entity.getRdfUri();
String rdfString = rdfUri == null ? uriHelper.fromResourceUri(makeUrl(collectionName, id.get())).toString() : rdfUri.toString();
StringBuilder sb = new StringBuilder();
addRdfProp(rdfString, sb, "id", entity.getId() + "", "https://www.ietf.org/rfc/rfc4122.txt");
entity.getRdfAlternatives().forEach(alt -> sb.append(asNtriples(new LinkTriple(rdfString, SAME_AS_PRED, alt))));
TriplePropertyConverter converter = new TriplePropertyConverter(collection, rdfString);
for (TimProperty<?> timProperty : entity.getProperties()) {
try {
timProperty.convert(converter).getRight().forEach(triple -> sb.append(asNtriples(triple)));
} catch (IOException e) {
LOG.error("Could not convert property with name '{}' and value '{}'", timProperty.getName(), timProperty.getValue());
}
}
entity.getRelations().forEach(rel -> sb.append(asNtriples(new LinkTriple(rdfString, getRelationRdfUri(rel), getEntityRdfUri(rel)))));
return commitAndReturn(Response.ok(sb.toString()).build());
} catch (InvalidCollectionException e) {
return commitAndReturn(Response.status(BAD_REQUEST).entity(e.getMessage()).build());
} catch (NotFoundException e) {
return commitAndReturn(Response.status(NOT_FOUND).build());
}
});
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class InvariantsCheck method check.
@Override
public ValidationResult check(Vertex vertex) {
List<ValidationResult> validationResults = Lists.newArrayList();
String[] vertexTypes = getEntityTypesOrDefault(vertex);
String id = vertex.value("tim_id");
vertex.edges(Direction.BOTH).forEachRemaining(edge -> {
if (!Objects.equals(edge.label(), "VERSION_OF")) {
// ignore the VERSION_OF relations
String[] edgeTypes = getEntityTypesOrDefault(edge);
for (String edgeType : edgeTypes) {
Optional<Collection> collectionOptional = vres.getCollectionForType(edgeType);
String edgeId = edge.value("tim_id");
if (!collectionOptional.isPresent()) {
validationResults.add(new ElementValidationResult(false, String.format("Edge with tim_id '%s' has contains unknown variant '%s'", edgeId, edgeType)));
continue;
}
Collection edgeCollection = collectionOptional.get();
// Only check accepted edges / relations, Timbuctoo sees not accepted relations as deleted.
if (isAccepted(edge, edgeType) && vreContainsAVariationOfTheVertex(vertexTypes, edgeCollection)) {
addInvalidVertex(validationResults, id, vertexTypes, edgeType, edgeId);
}
}
}
});
return new CompositeValidationResult(validationResults);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class MoveIndicesToIsLatestVertexMigration method fillVertexIndices.
private void fillVertexIndices(TinkerPopGraphManager graphWrapper, IndexManager indexManager) {
ObjectMapper mapper = new ObjectMapper();
GraphTraversalSource traversalSource = graphWrapper.getGraph().traversal();
Collection wwpersonCollection = vres.getCollection("wwpersons").orElse(null);
graphWrapper.getGraphDatabase().getAllNodes().stream().filter(node -> node.hasProperty("tim_id")).filter(this::isLatest).forEach(node -> {
updateIdIndex(indexManager, node);
if (!isDeleted(node)) {
updateQuicksearchIndex(vres, indexManager, mapper, node, wwpersonCollection, traversalSource);
}
});
}
Aggregations