use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.
the class VreImage method getImage.
@GET
public Response getImage(@PathParam("vreName") String vreName) {
return transactionEnforcer.executeAndReturn(timbuctooActions -> {
final Vre vre = timbuctooActions.getVre(vreName);
if (vre == null) {
return TransactionStateAndResult.commitAndReturn(Response.status(Response.Status.NOT_FOUND).build());
}
final byte[] imageBlob = timbuctooActions.getVreImageBlob(vreName);
final MediaType mediaType = vre.getMetadata().getImageMediaType();
if (imageBlob != null && mediaType != null) {
final CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(604800);
cacheControl.setPrivate(false);
return TransactionStateAndResult.commitAndReturn(Response.ok(imageBlob).type(mediaType).cacheControl(cacheControl).build());
} else {
return TransactionStateAndResult.commitAndReturn(Response.status(Response.Status.NOT_FOUND).build());
}
});
}
use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.
the class TinkerPopOperations method retrieveProperty.
@Override
public Optional<RdfReadProperty> retrieveProperty(Vre vre, String entityRdfUri, String propertyUri) {
Optional<Vertex> entityOpt = indexHandler.findVertexInRdfIndex(vre, entityRdfUri);
if (entityOpt.isPresent()) {
Vertex entity = entityOpt.get();
Iterable<Vertex> collectionOfEntity = () -> collectionsFor(entity);
Optional<Collection> colOpt = StreamSupport.stream(collectionOfEntity.spliterator(), false).map(col -> getProp(col, COLLECTION_NAME_PROPERTY_NAME, String.class)).filter(colNameProp -> colNameProp.isPresent()).map(colNameProp -> colNameProp.get()).map(vre::getCollectionForCollectionName).filter(Optional::isPresent).map(Optional::get).findFirst();
if (colOpt.isPresent()) {
Collection collection = colOpt.get();
VertexProperty<String> property = entity.property(createPropName(collection.getEntityTypeName(), propertyUri));
if (property.isPresent()) {
return Optional.of(new RdfReadProperty(propertyUri, property.value()));
}
}
}
return Optional.empty();
}
use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.
the class TinkerPopOperations method loadVres.
@Override
public Vres loadVres() {
defaultCollectionVerticesCache.clear();
ImmutableVresDto.Builder builder = ImmutableVresDto.builder();
traversal.V().has(T.label, LabelP.of(Vre.DATABASE_LABEL)).forEachRemaining(vreVertex -> {
final Vre vre = Vre.load(vreVertex);
builder.putVres(vre.getVreName(), vre);
});
return builder.build();
}
use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.
the class TinkerPopToEntityMapper method getRelations.
private List<RelationRef> getRelations(Vertex entity, GraphTraversalSource traversalSource, Collection collection) {
final Vre vre = collection.getVre();
Vre adminVre = mappings.getVre("Admin");
Map<String, Collection> collectionsOfVre = vre.getCollections();
Object[] relationTypes = traversalSource.V().has(T.label, LabelP.of("relationtype")).id().toList().toArray();
GraphTraversal<Vertex, RelationRef> realRelations = collectionsOfVre.values().stream().filter(Collection::isRelationCollection).findAny().map(Collection::getEntityTypeName).map(ownRelationType -> traversalSource.V(entity.id()).union(__.outE().as("edge").label().as("label").select("edge"), __.inE().as("edge").label().as("edgeLabel").V(relationTypes).has("relationtype_regularName", __.where(P.eq("edgeLabel"))).properties("relationtype_inverseName").value().as("label").select("edge")).where(// FIXME move to strategy
__.has("isLatest", true).not(__.has("deleted", true)).not(__.hasLabel("VERSION_OF")).not(__.has(ownRelationType + "_accepted", false))).otherV().as("vertex").select("edge", "vertex", "label").map(r -> {
try {
Map<String, Object> val = r.get();
Edge edge = (Edge) val.get("edge");
Vertex target = (Vertex) val.get("vertex");
String label = (String) val.get("label");
String targetEntityType = vre.getOwnType(getEntityTypesOrDefault(target));
Collection targetCollection = vre.getCollectionForTypeName(targetEntityType);
if (targetEntityType == null) {
// this means that the edge is of this VRE, but the
// Vertex it points to is of another VRE
// In that case we use the admin vre
targetEntityType = adminVre.getOwnType(getEntityTypesOrDefault(target));
targetCollection = adminVre.getCollectionForTypeName(targetEntityType);
}
String displayName = DisplayNameHelper.getDisplayname(traversalSource, target, targetCollection).orElse("<No displayname found>");
String targetId = getProp(target, "tim_id", String.class).orElse("");
String targetRdfUri = getProp(target, RDF_URI_PROP, String.class).orElse("");
String[] targetAlternativeUris = getProp(target, RDF_SYNONYM_PROP, String[].class).orElse(new String[0]);
boolean accepted = getProp(edge, "accepted", Boolean.class).orElse(true);
String relationId = getProp(edge, "tim_id", String.class).orElse("");
String relationRdfUri = getProp(edge, "rdfUri", String.class).orElse("");
int relationRev = getProp(edge, "rev", Integer.class).orElse(1);
RelationRef relationRef = new RelationRef(targetId, targetRdfUri, targetAlternativeUris, targetCollection.getCollectionName(), targetEntityType, accepted, relationId, relationRdfUri, relationRev, label, displayName);
customRelationProperties.execute(traversalSource, vre, target, relationRef);
return relationRef;
} catch (Exception e) {
LOG.error(databaseInvariant, "Something went wrong while formatting the entity", e);
return null;
}
})).orElse(EmptyGraph.instance().traversal().V().map(x -> null));
List<RelationRef> relations = stream(realRelations).filter(x -> x != null).collect(toList());
return relations;
}
use of nl.knaw.huygens.timbuctoo.model.vre.Vre in project timbuctoo by HuygensING.
the class CollectionNameHelperTest method rdfUriPrefixesTheEntityTypeNameWithTheDefaultUri.
@Test
public void rdfUriPrefixesTheEntityTypeNameWithTheDefaultUri() {
Vre vre = VreStubs.withName(VRE_NAME);
String rdfUri = CollectionNameHelper.rdfUri(UNPREFIXED_ENTITY_NAME, vre);
String entityTypeName = CollectionNameHelper.entityTypeName(UNPREFIXED_ENTITY_NAME, vre);
assertThat(rdfUri, allOf(startsWith(RDF_URI_PREFIX), endsWith(entityTypeName)));
}
Aggregations