Search in sources :

Example 1 with ResourceSyncReport

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport 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 ResourceSyncReport

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

Example 3 with ResourceSyncReport

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport in project timbuctoo by HuygensING.

the class ResourceSyncImportTest method filterReturnsMessageWithFilesListIfMultipleFilesAndNoneSpecifiedAsDataset.

@Test(expected = CantDetermineDataSetException.class)
public void filterReturnsMessageWithFilesListIfMultipleFilesAndNoneSpecifiedAsDataset() throws Exception {
    String capabilityListUri = BASE_URL + "capabilitylist.xml";
    List<RemoteFile> changes = Collections.emptyList();
    List<RemoteFile> resources = new ArrayList<>();
    resources.add(RemoteFile.create(BASE_URL + "files/dataset.nq", () -> null, "", metadata));
    resources.add(RemoteFile.create(BASE_URL + "files/dataset.rdf", () -> null, "", metadata));
    RemoteFilesList remoteFilesList = new RemoteFilesList(changes, resources);
    given(resourceSyncFileLoader.getRemoteFilesList(capabilityListUri, null)).willReturn(remoteFilesList);
    ResourceSyncMutationFileHelper fileHelper = new ResourceSyncMutationFileHelper(dataSet, new ResourceSyncReport());
    instance.filterAndImport(capabilityListUri, null, null, null, fileHelper);
}
Also used : ResourceSyncReport(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport) ResourceSyncMutationFileHelper(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ResourceSyncMutationFileHelper) RemoteFilesList(nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncFileLoader.RemoteFilesList) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with ResourceSyncReport

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport in project timbuctoo by HuygensING.

the class ResourceSyncImportTest method filterAndImportImportsAllChanges.

@Test
public void filterAndImportImportsAllChanges() throws Exception {
    List<RemoteFile> changes = new ArrayList<>();
    changes.add(RemoteFile.create(BASE_URL + "files/changes1.nqud", () -> null, "", metadata));
    changes.add(RemoteFile.create(BASE_URL + "files/changes2.nqud", () -> null, "", metadata));
    List<RemoteFile> resources = new ArrayList<>();
    resources.add(RemoteFile.create(BASE_URL + "files/dataset.nq", () -> null, "", metadata));
    RemoteFilesList remoteFilesList = new RemoteFilesList(changes, resources);
    given(resourceSyncFileLoader.getRemoteFilesList(CAPABILITY_LIST_URI, null)).willReturn(remoteFilesList);
    ResourceSyncReport resourceSyncReport = new ResourceSyncReport();
    ResourceSyncMutationFileHelper fileHelper = new ResourceSyncMutationFileHelper(dataSet, resourceSyncReport);
    instance.filterAndImport(CAPABILITY_LIST_URI, null, null, null, fileHelper);
    verify(importManager).addLog(any(), any(), endsWith("changes1.nqud"), any(), any(), any());
    verify(importManager).addLog(any(), any(), endsWith("changes2.nqud"), any(), any(), any());
    assertThat(resourceSyncReport.importedFiles, containsInAnyOrder(is(BASE_URL + "files/changes1.nqud"), is(BASE_URL + "files/changes2.nqud")));
}
Also used : ResourceSyncReport(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport) ResourceSyncMutationFileHelper(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ResourceSyncMutationFileHelper) RemoteFilesList(nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncFileLoader.RemoteFilesList) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with ResourceSyncReport

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport in project timbuctoo by HuygensING.

the class ResourceSyncImportTest method filterReturnsListWithSingleDataSetFileIfChangesNotPresentAndDataSetPropertySet.

@Test
public void filterReturnsListWithSingleDataSetFileIfChangesNotPresentAndDataSetPropertySet() throws Exception {
    List<RemoteFile> resources = new ArrayList<>();
    resources.add(RemoteFile.create(BASE_URL + "files/dataset.nq", () -> null, "", metadata));
    Metadata metadata2 = new Metadata();
    metadata2.setIsDataset(true);
    resources.add(RemoteFile.create(BASE_URL + "files/dataset.rdf", () -> null, "", metadata2));
    List<RemoteFile> changes = Collections.emptyList();
    RemoteFilesList remoteFilesList = new RemoteFilesList(changes, resources);
    given(resourceSyncFileLoader.getRemoteFilesList(CAPABILITY_LIST_URI, null)).willReturn(remoteFilesList);
    ResourceSyncReport resourceSyncReport = new ResourceSyncReport();
    ResourceSyncMutationFileHelper fileHelper = new ResourceSyncMutationFileHelper(dataSet, resourceSyncReport);
    instance.filterAndImport(CAPABILITY_LIST_URI, null, null, null, fileHelper);
    verify(importManager).addLog(any(), any(), endsWith("dataset.rdf"), any(), any(), any());
    assertThat(resourceSyncReport.importedFiles, contains(BASE_URL + "files/dataset.rdf"));
}
Also used : ResourceSyncReport(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport) ResourceSyncMutationFileHelper(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ResourceSyncMutationFileHelper) RemoteFilesList(nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncFileLoader.RemoteFilesList) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ResourceSyncReport (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ResourceSyncReport)8 ResourceSyncMutationFileHelper (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ResourceSyncMutationFileHelper)6 ArrayList (java.util.ArrayList)5 RemoteFilesList (nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncFileLoader.RemoteFilesList)5 Test (org.junit.Test)5 ResourceSyncImport (nl.knaw.huygens.timbuctoo.remote.rs.download.ResourceSyncImport)3 CantRetrieveFileException (nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantRetrieveFileException)3 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)3 IOException (java.io.IOException)2 CantDetermineDataSetException (nl.knaw.huygens.timbuctoo.remote.rs.download.exceptions.CantDetermineDataSetException)2 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)2 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)2 Either (io.vavr.control.Either)1 URI (java.net.URI)1 Date (java.util.Date)1 DefaultValue (javax.ws.rs.DefaultValue)1 HeaderParam (javax.ws.rs.HeaderParam)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1