Search in sources :

Example 51 with Collection

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;
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) EntityToJsonMapper(nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Iterator(java.util.Iterator) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) IOException(java.io.IOException) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) Optional(java.util.Optional) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)

Example 52 with Collection

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));
}
Also used : Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException)

Example 53 with Collection

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());
        }
    });
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) LinkTriple(nl.knaw.huygens.timbuctoo.rdf.LinkTriple) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) IOException(java.io.IOException) TriplePropertyConverter(nl.knaw.huygens.timbuctoo.rdf.conversion.TriplePropertyConverter) URI(java.net.URI) GET(javax.ws.rs.GET)

Example 54 with Collection

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);
}
Also used : ElementValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CompositeValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.CompositeValidationResult) ElementValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.ElementValidationResult) ValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.ValidationResult) CompositeValidationResult(nl.knaw.huygens.timbuctoo.server.healthchecks.CompositeValidationResult)

Example 55 with Collection

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);
        }
    });
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)147 Test (org.junit.Test)122 UUID (java.util.UUID)91 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)85 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)81 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)80 Optional (java.util.Optional)77 List (java.util.List)76 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)74 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)74 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)73 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)72 IOException (java.io.IOException)71 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)71 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)71 Matchers.is (org.hamcrest.Matchers.is)71 Change (nl.knaw.huygens.timbuctoo.model.Change)70 Matchers.not (org.hamcrest.Matchers.not)70 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)69 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)69