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);
}
}
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);
}
}
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());
}
}
Aggregations