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