Search in sources :

Example 6 with Entity

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.

the class AzureVreAuthorizationAccess method deleteVreAuthorizations.

@Override
public void deleteVreAuthorizations(String vreId) throws AuthorizationUnavailableException {
    String condition = TableQuery.generateFilterCondition("PartitionKey", TableQuery.QueryComparisons.EQUAL, vreId);
    TableBatchOperation deletes = new TableBatchOperation();
    for (DynamicTableEntity entity : table.execute(TableQuery.from(DynamicTableEntity.class).where(condition))) {
        deletes.delete(entity);
    }
    try {
        table.execute(deletes);
    } catch (StorageException e) {
        LOG.error("deleteVreAuthorizations failed", e);
        throw new AuthorizationUnavailableException("Could not delete authorizations");
    }
}
Also used : DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) TableBatchOperation(com.microsoft.azure.storage.table.TableBatchOperation) StorageException(com.microsoft.azure.storage.StorageException) AuthorizationUnavailableException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationUnavailableException)

Example 7 with Entity

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatch method collectReplacements.

public static Map<String, List<CursorQuad>> collectReplacements(JsonNode activity, QuadStore quadStore) {
    Map<String, List<CursorQuad>> toReplace = new HashMap<>();
    for (JsonNode revision : activity.get(PROV_GENERATES)) {
        final JsonNode replacements = revision.get(TIM_REPLACEMENTS);
        if (replacements != null) {
            String entity = revision.get(PROV_SPECIALIZATION_OF).get(0).get("@id").asText();
            List<CursorQuad> quads = new ArrayList<>();
            toReplace.put(revision.get("@id").asText(), quads);
            for (JsonNode replacement : replacements) {
                if (replacement.has(TIM_PREDICATE)) {
                    final String predicate = replacement.get(TIM_PREDICATE).get(0).get("@value").asText();
                    try (Stream<CursorQuad> source = quadStore.getQuads(entity, predicate, Direction.OUT, "")) {
                        source.forEach(quads::add);
                    }
                }
            }
        }
    }
    return toReplace;
}
Also used : HashMap(java.util.HashMap) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 8 with Entity

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.

the class ViewConfigFetcher method makeDefaultViewConfig.

private ArrayList<Map> makeDefaultViewConfig(String collectionUri, Map<String, Type> schema, TypeNameStore typeNameStore) {
    ArrayList<Map> result = new ArrayList<>();
    Type collectionType = schema.get(collectionUri);
    if (collectionType == null) {
        LOG.error("The collectionUri " + collectionUri + " does not exist in the schema! (it does contain: [ " + schema.keySet().stream().collect(Collectors.joining(", ")) + " ]");
    } else {
        result.add(title(path(jsnA(jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value"))))));
        final String collectionGraphqlTypeWithoutDataSet = typeNameStore.makeGraphQlname(collectionUri);
        for (Predicate predicate : collectionType.getPredicates()) {
            final String predicateAsGraphqlProp = typeNameStore.makeGraphQlnameForPredicate(predicate.getName(), predicate.getDirection(), predicate.isList());
            ArrayNode predicateReference = jsnA(jsnA(jsn(collectionGraphqlTypeWithoutDataSet), jsn(predicateAsGraphqlProp)));
            if (predicate.isList()) {
                predicateReference.add(jsnA(jsn("items"), jsn("items")));
            }
            String title = "";
            if (predicate.getDirection() == Direction.IN) {
                title = "⬅︎ ";
            }
            title += typeNameStore.shorten(predicate.getName());
            if (predicate.getReferenceTypes().values().stream().anyMatch(x -> x > 0)) {
                // it's at least sometimes a link
                result.add(keyValue(title, internalLink(path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("uri")))), path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value")))))));
            }
            if (predicate.getValueTypes().values().stream().anyMatch(x -> x > 0)) {
                // it's at least sometimes a normal value
                result.add(keyValue(title, path(pushImm(predicateReference, jsnA(jsn("Value"), jsn("value"))))));
            }
        }
    }
    return result;
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Example 9 with Entity

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity in project timbuctoo by HuygensING.

the class ViewConfigMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    String collectionUri = env.getArgument("collectionUri");
    Object viewConfig = env.getArgument("viewConfig");
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    try {
        MutationHelpers.addMutation(dataSet, new PredicateMutation().entity(collectionUri, replace(HAS_VIEW_CONFIG, value(OBJECT_MAPPER.writeValueAsString(viewConfig)))));
        return viewConfig;
    } catch (LogStorageFailedException | InterruptedException | ExecutionException | JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
Also used : PredicateMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) ExecutionException(java.util.concurrent.ExecutionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 10 with Entity

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Entity 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)

Aggregations

User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)7 IOException (java.io.IOException)6 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)6 UserValidationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException)6 ExecutionException (java.util.concurrent.ExecutionException)5 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 UUID (java.util.UUID)3 POST (javax.ws.rs.POST)3 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)3 PermissionFetchingException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Future (java.util.concurrent.Future)2 Either (javaslang.control.Either)2