@Test public void filterReturnsListWithUserSpecifiedDatasetFileIfPresent() throws Exception { 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(CAPABILITY_LIST_URI, null)).willReturn(remoteFilesList); String userSpecifiedDataSet = BASE_URL + "files/dataset.rdf"; ResourceSyncReport filteredFiles = instance.filterAndImport(CAPABILITY_LIST_URI, userSpecifiedDataSet, false, null); verify(importManager).addLog(any(), any(), endsWith("dataset.rdf"), any(), any(), any()); assertThat(filteredFiles.importedFiles, contains(BASE_URL + "files/dataset.rdf")); }
public ResourceSyncReport filterAndImport(String capabilityListUri, String userSpecifiedDataSet, boolean update, String authString) throws CantDetermineDataSetException, IOException, CantRetrieveFileException { List<RemoteFile> filesToImport; if (userSpecifiedDataSet == null) { filesToImport = filter(capabilityListUri, update, authString); } else { filesToImport = filter(capabilityListUri, userSpecifiedDataSet, authString); } if (update) { dataSet.getMetadata().getImportInfo().get(0).setLastImportedOn(Date.from(Instant.now())); } Iterator<RemoteFile> files = filesToImport.iterator(); LOG.info("Found files '{}'", files.hasNext()); if (!files.hasNext()) { LOG.error("No supported files available for import."); return new ResourceSyncReport(); } ImportManager importManager = dataSet.getImportManager(); ResourceSyncReport resourceSyncReport = new ResourceSyncReport(); try { while (files.hasNext()) { RemoteFile file = files.next(); MediaType parsedMediatype = MediaType.APPLICATION_OCTET_STREAM_TYPE; try { parsedMediatype = MediaType.valueOf(file.getMimeType()); } catch (IllegalArgumentException e) { LOG.error("Failed to get mediatype", e); } if (importManager.isRdfTypeSupported(parsedMediatype)) { resourceSyncReport.importedFiles.add(file.getUrl()); Future<ImportStatus> importedFileFuture = importManager.addLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), file.getUrl().substring(file.getUrl().lastIndexOf('/') + 1), file.getData().get(), Optional.of(Charsets.UTF_8), parsedMediatype ); if (!async) { importedFileFuture.get(); } } else { resourceSyncReport.ignoredFiles.add(file.getUrl()); importManager.addFile( file.getData().get(), file.getUrl(), parsedMediatype ); } } return resourceSyncReport; } catch (Exception e) { LOG.error("Could not read files to import", e); return resourceSyncReport; } }
ResourceSyncImport { public ResourceSyncReport filterAndImport(String capabilityListUri, String userSpecifiedDataSet, boolean update, String authString) throws CantDetermineDataSetException, IOException, CantRetrieveFileException { List<RemoteFile> filesToImport; if (userSpecifiedDataSet == null) { filesToImport = filter(capabilityListUri, update, authString); } else { filesToImport = filter(capabilityListUri, userSpecifiedDataSet, authString); } if (update) { dataSet.getMetadata().getImportInfo().get(0).setLastImportedOn(Date.from(Instant.now())); } Iterator<RemoteFile> files = filesToImport.iterator(); LOG.info("Found files '{}'", files.hasNext()); if (!files.hasNext()) { LOG.error("No supported files available for import."); return new ResourceSyncReport(); } ImportManager importManager = dataSet.getImportManager(); ResourceSyncReport resourceSyncReport = new ResourceSyncReport(); try { while (files.hasNext()) { RemoteFile file = files.next(); MediaType parsedMediatype = MediaType.APPLICATION_OCTET_STREAM_TYPE; try { parsedMediatype = MediaType.valueOf(file.getMimeType()); } catch (IllegalArgumentException e) { LOG.error("Failed to get mediatype", e); } if (importManager.isRdfTypeSupported(parsedMediatype)) { resourceSyncReport.importedFiles.add(file.getUrl()); Future<ImportStatus> importedFileFuture = importManager.addLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), file.getUrl().substring(file.getUrl().lastIndexOf('/') + 1), file.getData().get(), Optional.of(Charsets.UTF_8), parsedMediatype ); if (!async) { importedFileFuture.get(); } } else { resourceSyncReport.ignoredFiles.add(file.getUrl()); importManager.addFile( file.getData().get(), file.getUrl(), parsedMediatype ); } } return resourceSyncReport; } catch (Exception e) { LOG.error("Could not read files to import", e); return resourceSyncReport; } } }
ResourceSyncImport { public ResourceSyncReport filterAndImport(String capabilityListUri, String userSpecifiedDataSet, boolean update, String authString) throws CantDetermineDataSetException, IOException, CantRetrieveFileException { List<RemoteFile> filesToImport; if (userSpecifiedDataSet == null) { filesToImport = filter(capabilityListUri, update, authString); } else { filesToImport = filter(capabilityListUri, userSpecifiedDataSet, authString); } if (update) { dataSet.getMetadata().getImportInfo().get(0).setLastImportedOn(Date.from(Instant.now())); } Iterator<RemoteFile> files = filesToImport.iterator(); LOG.info("Found files '{}'", files.hasNext()); if (!files.hasNext()) { LOG.error("No supported files available for import."); return new ResourceSyncReport(); } ImportManager importManager = dataSet.getImportManager(); ResourceSyncReport resourceSyncReport = new ResourceSyncReport(); try { while (files.hasNext()) { RemoteFile file = files.next(); MediaType parsedMediatype = MediaType.APPLICATION_OCTET_STREAM_TYPE; try { parsedMediatype = MediaType.valueOf(file.getMimeType()); } catch (IllegalArgumentException e) { LOG.error("Failed to get mediatype", e); } if (importManager.isRdfTypeSupported(parsedMediatype)) { resourceSyncReport.importedFiles.add(file.getUrl()); Future<ImportStatus> importedFileFuture = importManager.addLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), file.getUrl().substring(file.getUrl().lastIndexOf('/') + 1), file.getData().get(), Optional.of(Charsets.UTF_8), parsedMediatype ); if (!async) { importedFileFuture.get(); } } else { resourceSyncReport.ignoredFiles.add(file.getUrl()); importManager.addFile( file.getData().get(), file.getUrl(), parsedMediatype ); } } return resourceSyncReport; } catch (Exception e) { LOG.error("Could not read files to import", e); return resourceSyncReport; } } ResourceSyncImport(ResourceSyncFileLoader resourceSyncFileLoader, DataSet dataSet, boolean async); }
ResourceSyncImport { public ResourceSyncReport filterAndImport(String capabilityListUri, String userSpecifiedDataSet, boolean update, String authString) throws CantDetermineDataSetException, IOException, CantRetrieveFileException { List<RemoteFile> filesToImport; if (userSpecifiedDataSet == null) { filesToImport = filter(capabilityListUri, update, authString); } else { filesToImport = filter(capabilityListUri, userSpecifiedDataSet, authString); } if (update) { dataSet.getMetadata().getImportInfo().get(0).setLastImportedOn(Date.from(Instant.now())); } Iterator<RemoteFile> files = filesToImport.iterator(); LOG.info("Found files '{}'", files.hasNext()); if (!files.hasNext()) { LOG.error("No supported files available for import."); return new ResourceSyncReport(); } ImportManager importManager = dataSet.getImportManager(); ResourceSyncReport resourceSyncReport = new ResourceSyncReport(); try { while (files.hasNext()) { RemoteFile file = files.next(); MediaType parsedMediatype = MediaType.APPLICATION_OCTET_STREAM_TYPE; try { parsedMediatype = MediaType.valueOf(file.getMimeType()); } catch (IllegalArgumentException e) { LOG.error("Failed to get mediatype", e); } if (importManager.isRdfTypeSupported(parsedMediatype)) { resourceSyncReport.importedFiles.add(file.getUrl()); Future<ImportStatus> importedFileFuture = importManager.addLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), file.getUrl().substring(file.getUrl().lastIndexOf('/') + 1), file.getData().get(), Optional.of(Charsets.UTF_8), parsedMediatype ); if (!async) { importedFileFuture.get(); } } else { resourceSyncReport.ignoredFiles.add(file.getUrl()); importManager.addFile( file.getData().get(), file.getUrl(), parsedMediatype ); } } return resourceSyncReport; } catch (Exception e) { LOG.error("Could not read files to import", e); return resourceSyncReport; } } ResourceSyncImport(ResourceSyncFileLoader resourceSyncFileLoader, DataSet dataSet, boolean async); ResourceSyncReport filterAndImport(String capabilityListUri, String userSpecifiedDataSet, boolean update,
                                            String authString); }
ResourceSyncImport { public ResourceSyncReport filterAndImport(String capabilityListUri, String userSpecifiedDataSet, boolean update, String authString) throws CantDetermineDataSetException, IOException, CantRetrieveFileException { List<RemoteFile> filesToImport; if (userSpecifiedDataSet == null) { filesToImport = filter(capabilityListUri, update, authString); } else { filesToImport = filter(capabilityListUri, userSpecifiedDataSet, authString); } if (update) { dataSet.getMetadata().getImportInfo().get(0).setLastImportedOn(Date.from(Instant.now())); } Iterator<RemoteFile> files = filesToImport.iterator(); LOG.info("Found files '{}'", files.hasNext()); if (!files.hasNext()) { LOG.error("No supported files available for import."); return new ResourceSyncReport(); } ImportManager importManager = dataSet.getImportManager(); ResourceSyncReport resourceSyncReport = new ResourceSyncReport(); try { while (files.hasNext()) { RemoteFile file = files.next(); MediaType parsedMediatype = MediaType.APPLICATION_OCTET_STREAM_TYPE; try { parsedMediatype = MediaType.valueOf(file.getMimeType()); } catch (IllegalArgumentException e) { LOG.error("Failed to get mediatype", e); } if (importManager.isRdfTypeSupported(parsedMediatype)) { resourceSyncReport.importedFiles.add(file.getUrl()); Future<ImportStatus> importedFileFuture = importManager.addLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), file.getUrl().substring(file.getUrl().lastIndexOf('/') + 1), file.getData().get(), Optional.of(Charsets.UTF_8), parsedMediatype ); if (!async) { importedFileFuture.get(); } } else { resourceSyncReport.ignoredFiles.add(file.getUrl()); importManager.addFile( file.getData().get(), file.getUrl(), parsedMediatype ); } } return resourceSyncReport; } catch (Exception e) { LOG.error("Could not read files to import", e); return resourceSyncReport; } } ResourceSyncImport(ResourceSyncFileLoader resourceSyncFileLoader, DataSet dataSet, boolean async); ResourceSyncReport filterAndImport(String capabilityListUri, String userSpecifiedDataSet, boolean update,
                                            String authString); static final Logger LOG; }