Search in sources :

Example 1 with DataSetCreationException

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

the class DataSetRepository method createDataSet.

public DataSet createDataSet(User user, String dataSetId, List<ImportInfo> importInfos) throws DataStoreCreationException, IllegalDataSetNameException, DataSetCreationException {
    // 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();
    if (dataStorage.dataSetExists(ownerPrefix, dataSetId)) {
        throw new DataSetCreationException("DataSet already exists on disk.");
    }
    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, importInfos);
    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());
                DataSet createdDataset = dataSet(dataSet, executorService, rdfBaseUri, dataStoreFactory, () -> onUpdated.accept(dataSet.getCombinedId()), dataStorage.getDataSetStorage(ownerPrefix, dataSetId), readOnlyChecker);
                userDataSets.put(dataSetId, createdDataset);
                dataSetsUpdatedListeners.forEach(createdDataset::subscribeToDataChanges);
            } catch (PermissionFetchingException | AuthorizationCreationException | IOException e) {
                LOG.error("Could not create data set", e);
                throw new DataStoreCreationException(e);
            }
        }
        return userDataSets.get(dataSetId);
    }
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) IOException(java.io.IOException) DataSetCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetCreationException) DataStorageSaveException(nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) 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 DataSetCreationException

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

the class ResourceSyncImportMutation method executeAction.

@Override
public Object executeAction(DataFetchingEnvironment env) {
    User user = MutationHelpers.getUser(env);
    String dataSetName = env.getArgument("dataSetName");
    String capabilityListUri = env.getArgument("capabilityListUri");
    String userSpecifiedDataSet = env.getArgument("userSpecifiedDataSet");
    String authString = env.getArgument("authorization");
    try {
        ImportInfo importInfo = new ImportInfo(capabilityListUri, Date.from(Instant.now()));
        DataSet dataSet = dataSetRepository.createDataSet(user, dataSetName, Lists.newArrayList(importInfo));
        MutationHelpers.checkPermission(env, dataSet.getMetadata(), Permission.IMPORT_RESOURCESYNC);
        ResourceSyncReport resourceSyncReport = new ResourceSyncReport();
        ResourceSyncMutationFileHelper fileHelper = new ResourceSyncMutationFileHelper(dataSet, resourceSyncReport);
        ResourceSyncImport resourceSyncImport = new ResourceSyncImport(resourceSyncFileLoader, false);
        resourceSyncImport.filterAndImport(capabilityListUri, userSpecifiedDataSet, authString, null, fileHelper);
        return resourceSyncReport;
    } catch (DataStoreCreationException | IllegalDataSetNameException | IOException | CantRetrieveFileException | CantDetermineDataSetException | DataSetCreationException e) {
        LOG.error("Failed to do a resource sync import. ", e);
        throw new RuntimeException(e);
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) ImportInfo(nl.knaw.huygens.timbuctoo.v5.dataset.dto.ImportInfo) ResourceSyncImport(nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncImport) IllegalDataSetNameException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException) IOException(java.io.IOException) DataSetCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetCreationException) ResourceSyncReport(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport) CantRetrieveFileException(nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantRetrieveFileException) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException) CantDetermineDataSetException(nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantDetermineDataSetException)

Example 3 with DataSetCreationException

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

the class CreateDataSetMutation method executeAction.

@Override
public Object executeAction(DataFetchingEnvironment env) {
    User currentUser = getUser(env);
    String dataSetName = env.getArgument("dataSetName");
    try {
        return new DataSetWithDatabase(dataSetRepository.createDataSet(currentUser, dataSetName), env.<ContextData>getContext().getUserPermissionCheck());
    } 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());
    } catch (DataSetCreationException e) {
        throw new RuntimeException(e.getMessage());
    }
}
Also used : DataSetCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetCreationException) 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) ContextData(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData) IllegalDataSetNameException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)

Aggregations

DataSetCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetCreationException)3 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)3 IOException (java.io.IOException)2 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)2 IllegalDataSetNameException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException)2 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)2 ResourceSyncImport (nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncImport)1 CantDetermineDataSetException (nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantDetermineDataSetException)1 CantRetrieveFileException (nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantRetrieveFileException)1 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)1 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)1 ImportInfo (nl.knaw.huygens.timbuctoo.v5.dataset.dto.ImportInfo)1 DataStorageSaveException (nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException)1 ContextData (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData)1 DataSetWithDatabase (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase)1 MutationHelpers.getUser (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers.getUser)1 ResourceSyncReport (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport)1 AuthorizationCreationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)1 PermissionFetchingException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException)1