Search in sources :

Example 6 with DataSetRepository

use of nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository in project timbuctoo by HuygensING.

the class DataSetMetadataMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    try {
        Map md = env.getArgument("metadata");
        final String baseUri = dataSet.getMetadata().getBaseUri().endsWith("/") ? dataSet.getMetadata().getBaseUri() : dataSet.getMetadata().getBaseUri() + "/";
        addMutation(dataSet, new PredicateMutation().entity(baseUri, this.<String>parseProp(md, "title", v -> replace("http://purl.org/dc/terms/title", value(v))), this.<String>parseProp(md, "description", v -> replace("http://purl.org/dc/terms/description", value(v, MARKDOWN))), this.<String>parseProp(md, "imageUrl", v -> replace("http://xmlns.com/foaf/0.1/depiction", value(v))), this.<String>parseProp(md, "license", v -> replace("http://purl.org/dc/terms/license", subject(v))), this.<Map>parseProp(md, "owner", owner -> getOrCreate("http://purl.org/dc/terms/rightsHolder", baseUri + "rightsHolder", this.<String>parseProp(owner, "name", v -> replace("http://schema.org/name", value(v))), this.<String>parseProp(owner, "email", v -> replace("http://schema.org/email", value(v))))), this.<Map>parseProp(md, "contact", owner -> getOrCreate("http://schema.org/ContactPoint", baseUri + "ContactPoint", this.<String>parseProp(owner, "name", v -> replace("http://schema.org/name", value(v))), this.<String>parseProp(owner, "email", v -> replace("http://schema.org/email", value(v))))), this.<Map>parseProp(md, "provenanceInfo", owner -> getOrCreate("http://purl.org/dc/terms/provenance", baseUri + "Provenance", this.<String>parseProp(owner, "title", v -> replace("http://purl.org/dc/terms/title", value(v))), this.<String>parseProp(owner, "body", v -> replace("http://purl.org/dc/terms/description", value(v, MARKDOWN)))))));
        return new DataSetWithDatabase(dataSet);
    } catch (LogStorageFailedException | InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
}
Also used : PredicateMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation) DataSetWithDatabase(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 7 with DataSetRepository

use of nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository in project timbuctoo by HuygensING.

the class ExtendSchemaMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    final SchemaStore generatedSchema = dataSet.getSchemaStore();
    Map<String, Type> customTypes = new HashMap<>();
    List<ExplicitType> customSchema;
    Map<String, List<ExplicitField>> newCustomSchema = new HashMap<>();
    try {
        String customSchemaString = OBJECT_MAPPER.writeValueAsString(env.getArgument("customSchema"));
        customSchema = OBJECT_MAPPER.readValue(customSchemaString, new TypeReference<List<ExplicitType>>() {
        });
    } catch (IOException e) {
        throw new RuntimeException("Could not parse the schema input");
    }
    for (ExplicitType explicitType : customSchema) {
        customTypes.put(explicitType.getCollectionId(), explicitType.convertToType());
        newCustomSchema.put(explicitType.getCollectionId(), explicitType.getFields());
    }
    Map<String, List<ExplicitField>> existingCustomSchema = dataSet.getCustomSchema();
    Map<String, Type> existingCustomSchemaTypes = new HashMap<>();
    for (Map.Entry<String, List<ExplicitField>> entry : existingCustomSchema.entrySet()) {
        ExplicitType tempExplicitType = new ExplicitType(entry.getKey(), entry.getValue());
        existingCustomSchemaTypes.put(entry.getKey(), tempExplicitType.convertToType());
    }
    MergeSchemas mergeSchemas = new MergeSchemas();
    customTypes = mergeSchemas.mergeSchema(existingCustomSchemaTypes, customTypes);
    MergeExplicitSchemas mergeExplicitSchemas = new MergeExplicitSchemas();
    Map<String, List<ExplicitField>> mergedExplicitSchema = mergeExplicitSchemas.mergeExplicitSchemas(existingCustomSchema, newCustomSchema);
    try {
        dataSet.saveCustomSchema(mergedExplicitSchema);
    } catch (IOException e) {
        LOG.error("Saving the custom schema failed", e);
        throw new RuntimeException(e);
    }
    Map<String, Type> mergedSchema = mergeSchemas.mergeSchema(generatedSchema.getStableTypes(), customTypes);
    for (Map.Entry<String, Type> customType : customTypes.entrySet()) {
        if (!mergedSchema.containsKey(customType.getKey())) {
            return ImmutableMap.of("message", "Schema extension was unsuccessful.");
        }
    }
    return ImmutableMap.of("message", "Schema extended successfully.");
}
Also used : MergeSchemas(nl.knaw.huygens.timbuctoo.v5.graphql.customschema.MergeSchemas) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) SchemaStore(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaStore) HashMap(java.util.HashMap) MergeExplicitSchemas(nl.knaw.huygens.timbuctoo.v5.graphql.customschema.MergeExplicitSchemas) IOException(java.io.IOException) ExplicitType(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.ExplicitType) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImmutableMap(jersey.repackaged.com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) ExplicitType(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.ExplicitType)

Example 8 with DataSetRepository

use of nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository in project timbuctoo by HuygensING.

the class IndexConfigMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    String collectionUri = env.getArgument("collectionUri");
    Object indexConfig = env.getArgument("indexConfig");
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    try {
        MutationHelpers.addMutation(dataSet, new PredicateMutation().entity(collectionUri, replace(TIM_HASINDEXERCONFIG, value(OBJECT_MAPPER.writeValueAsString(indexConfig)))));
        return indexConfig;
    } 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 9 with DataSetRepository

use of nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository in project timbuctoo by HuygensING.

the class MakePublicMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    User user = MutationHelpers.getUser(env);
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    try {
        dataSetRepository.publishDataSet(user, dataSet.getMetadata().getOwnerId(), dataSet.getMetadata().getDataSetId());
    } catch (DataSetPublishException e) {
        LOG.error("Failed to publish data set", e);
        throw new RuntimeException("Failed to publish data set");
    }
    return new DataSetWithDatabase(dataSet);
}
Also used : DataSetPublishException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetPublishException) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) DataSetWithDatabase(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)

Example 10 with DataSetRepository

use of nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository in project timbuctoo by HuygensING.

the class SummaryPropsMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    try {
        String collectionUri = env.getArgument("collectionUri");
        Map data = env.getArgument("summaryProperties");
        final PredicateMutation mutation = new PredicateMutation();
        mutation.entity(collectionUri, getValue(data, "title").map(v -> replace(TIM_SUMMARYTITLEPREDICATE, value(v))).orElse(null), getValue(data, "image").map(v -> replace(TIM_SUMMARYIMAGEPREDICATE, value(v))).orElse(null), getValue(data, "description").map(v -> replace(TIM_SUMMARYDESCRIPTIONPREDICATE, value(v))).orElse(null));
        MutationHelpers.addMutation(dataSet, mutation);
        return new LazyTypeSubjectReference(collectionUri, dataSet);
    } catch (LogStorageFailedException | InterruptedException | ExecutionException 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) LazyTypeSubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.dto.LazyTypeSubjectReference) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Aggregations

DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)15 DataSetRepository (nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository)8 Test (org.junit.Test)6 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)5 GraphQLFieldsContainer (graphql.schema.GraphQLFieldsContainer)5 Map (java.util.Map)5 ExecutionException (java.util.concurrent.ExecutionException)5 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)4 PredicateMutation (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation)4 IOException (java.io.IOException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 GraphQLSchema (graphql.schema.GraphQLSchema)2 HashMap (java.util.HashMap)2 List (java.util.List)2 UriHelper (nl.knaw.huygens.timbuctoo.util.UriHelper)2 LazyTypeSubjectReference (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.dto.LazyTypeSubjectReference)2 DataSetWithDatabase (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase)2 RootData (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.RootData)2 UserPermissionCheck (nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck)2 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)2