Search in sources :

Example 1 with CantDetermineDataSetException

use of nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantDetermineDataSetException 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 2 with CantDetermineDataSetException

use of nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantDetermineDataSetException in project timbuctoo by HuygensING.

the class ResourceSyncUpdateMutation method executeAction.

@Override
public Object executeAction(DataFetchingEnvironment env) {
    User user = MutationHelpers.getUser(env);
    String combinedId = env.getArgument("dataSetId");
    // the user-specified authorization token for remote server:
    String authString = env.getArgument("authorization");
    Tuple<String, String> userAndDataSet = DataSetMetaData.splitCombinedId(combinedId);
    Optional<DataSet> dataSetOpt;
    ResourceSyncReport resourceSyncReport = new ResourceSyncReport();
    try {
        dataSetOpt = dataSetRepository.getDataSet(user, userAndDataSet.getLeft(), userAndDataSet.getRight());
        if (!dataSetOpt.isPresent()) {
            LOG.error("DataSet does not exist.");
            throw new RuntimeException("DataSet does not exist.");
        }
        DataSet dataSet = dataSetOpt.get();
        MutationHelpers.checkPermission(env, dataSet.getMetadata(), Permission.UPDATE_RESOURCESYNC);
        String capabilityListUri = dataSet.getMetadata().getImportInfo().get(0).getImportSource();
        Date lastUpdate = dataSet.getMetadata().getImportInfo().get(0).getLastImportedOn();
        dataSet.getMetadata().getImportInfo().get(0).setLastImportedOn(Date.from(Instant.now()));
        ResourceSyncMutationFileHelper fileHelper = new ResourceSyncMutationFileHelper(dataSet, resourceSyncReport);
        ResourceSyncImport resourceSyncImport = new ResourceSyncImport(resourceSyncFileLoader, false);
        resourceSyncImport.filterAndImport(capabilityListUri, null, authString, lastUpdate, fileHelper);
    } catch (IOException | CantRetrieveFileException | CantDetermineDataSetException e) {
        LOG.error("Failed to do a resource sync import. ", e);
        throw new RuntimeException(e);
    }
    return resourceSyncReport;
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) ResourceSyncImport(nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncImport) IOException(java.io.IOException) Date(java.util.Date) ResourceSyncReport(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport) CantRetrieveFileException(nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantRetrieveFileException) CantDetermineDataSetException(nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantDetermineDataSetException)

Aggregations

IOException (java.io.IOException)2 ResourceSyncImport (nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncImport)2 CantDetermineDataSetException (nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantDetermineDataSetException)2 CantRetrieveFileException (nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantRetrieveFileException)2 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)2 ResourceSyncReport (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport)2 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)2 Date (java.util.Date)1 ImportInfo (nl.knaw.huygens.timbuctoo.v5.dataset.dto.ImportInfo)1 DataSetCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetCreationException)1 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)1 IllegalDataSetNameException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException)1