Search in sources :

Example 1 with MutationHelpers.getUser

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers.getUser in project timbuctoo by HuygensING.

the class DeleteDataSetMutation method get.

@Override
public Object get(DataFetchingEnvironment environment) {
    String combinedId = environment.getArgument("dataSetId");
    Tuple<String, String> userAndDataSet = DataSetMetaData.splitCombinedId(combinedId);
    User user = MutationHelpers.getUser(environment);
    try {
        dataSetRepository.removeDataSet(userAndDataSet.getLeft(), userAndDataSet.getRight(), user);
        return new RemovedDataSet(combinedId);
    } catch (IOException e) {
        LOG.error("Data set deletion exception", e);
        throw new RuntimeException("Data set could not be deleted");
    } catch (NotEnoughPermissionsException e) {
        throw new RuntimeException("You do not have enough permissions");
    } catch (DataSetRepository.DataSetDoesNotExistException e) {
        throw new RuntimeException(e.getMessage());
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) NotEnoughPermissionsException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) IOException(java.io.IOException)

Example 2 with MutationHelpers.getUser

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers.getUser 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)

Aggregations

User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)2 IOException (java.io.IOException)1 DataSetRepository (nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 DataSetPublishException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetPublishException)1 NotEnoughPermissionsException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException)1 DataSetWithDatabase (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase)1