Search in sources :

Example 1 with IllegalDataSetNameException

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

the class DataSetRepository method createDataSet.

public DataSet createDataSet(User user, String dataSetId) throws DataStoreCreationException, IllegalDataSetNameException {
    // The ownerId might not be valid (i.e. a safe string). We make it safe here:
    // dataSetId is under the control of the user so we simply throw if it's not valid
    String ownerPrefix = "u" + user.getPersistentId();
    final String baseUri = rdfIdHelper.dataSetBaseUri(ownerPrefix, dataSetId);
    String uriPrefix;
    if (!baseUri.endsWith("/") && !baseUri.endsWith("#") && !baseUri.endsWith("?")) {
        // #boo&foo=bar
        if (baseUri.contains("#") || baseUri.contains("?")) {
            if (baseUri.endsWith("&")) {
                uriPrefix = baseUri;
            } else {
                uriPrefix = baseUri + "&";
            }
        } else {
            uriPrefix = baseUri + "/";
        }
    } else {
        uriPrefix = baseUri;
    }
    final DataSetMetaData dataSet = new BasicDataSetMetaData(ownerPrefix, dataSetId, baseUri, uriPrefix, false, publicByDefault);
    try {
        dataStorage.getDataSetStorage(ownerPrefix, dataSetId).saveMetaData(dataSet);
    } catch (DataStorageSaveException e) {
        throw new DataStoreCreationException(e);
    }
    synchronized (dataSetMap) {
        Map<String, DataSet> userDataSets = dataSetMap.computeIfAbsent(ownerPrefix, key -> new HashMap<>());
        if (!userDataSets.containsKey(dataSetId)) {
            try {
                permissionFetcher.initializeOwnerAuthorization(user, dataSet.getOwnerId(), dataSet.getDataSetId());
                userDataSets.put(dataSetId, dataSet(dataSet, executorService, rdfBaseUri, dataStoreFactory, () -> onUpdated.accept(dataSet.getCombinedId()), dataStorage.getDataSetStorage(ownerPrefix, dataSetId)));
            } catch (PermissionFetchingException | AuthorizationCreationException | IOException e) {
                throw new DataStoreCreationException(e);
            }
        }
        return userDataSets.get(dataSetId);
    }
}
Also used : DataStorageSaveException(nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) IOException(java.io.IOException) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException) AuthorizationCreationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)

Example 2 with IllegalDataSetNameException

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

the class CreateDataSetMutation method get.

@Override
public Object get(DataFetchingEnvironment environment) {
    User currentUser = getUser(environment);
    String dataSetName = environment.getArgument("dataSetName");
    try {
        return new DataSetWithDatabase(dataSetRepository.createDataSet(currentUser, dataSetName));
    } catch (DataStoreCreationException e) {
        LOG.error("Data set creation exception", e);
        throw new RuntimeException("Data set could not be created");
    } catch (IllegalDataSetNameException e) {
        throw new RuntimeException("Data set id is not supported: " + e.getMessage());
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) MutationHelpers.getUser(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers.getUser) DataSetWithDatabase(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase) IllegalDataSetNameException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)

Aggregations

DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)2 IOException (java.io.IOException)1 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)1 IllegalDataSetNameException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException)1 DataStorageSaveException (nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException)1 DataSetWithDatabase (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase)1 MutationHelpers.getUser (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers.getUser)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1 AuthorizationCreationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)1 PermissionFetchingException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException)1