public synchronized DataSource getDataSourceById(String id) { for (DataSource dataSource : getDataSources()) { if (id.equals(dataSource.getId())) return dataSource; } return null; }
public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; DataSource dataSource = (DataSource) o; return getId().equals(dataSource.getId()); }
private DataSourceService loadDataSources(List<DataSource> dataSources, java.io.File directory) throws IOException, JAXBException { DataSourceService result = new DataSourceService(); for (DataSource dataSource : new ArrayList<>(dataSources)) { java.io.File file = new java.io.File(directory, dataSource.getId() + DOT_XML); log.info(format("Initializing data source from %s", file)); if (!file.exists()) { log.warning(format("Cannot find data source file %s", file)); continue; } try (InputStream inputStream = new FileInputStream(file)) { result.load(inputStream); } } return result; }
public void downloadDataSources(List<DataSource> dataSources, java.io.File directory) { List<Download> downloads = new ArrayList<>(); for (DataSource dataSource : dataSources) { String datasourceUrl = dataSource.getHref() + FORMAT_XML; java.io.File file = new java.io.File(directory, dataSource.getId() + DOT_XML); Download download = downloadManager.queueForDownload("Datasource: " + dataSource.getId(), datasourceUrl, Copy, new FileAndChecksum(file, null), null); downloads.add(download); } downloadManager.waitForCompletion(downloads); }
public synchronized void initialize() { hgtFiles.clear(); for (DataSource dataSource : dataSourceManager.getDataSourceService().getDataSources()) { if (DATASOURCE_URIS.contains(dataSource.getId())) hgtFiles.add(new HgtFiles(dataSource, dataSourceManager.getDownloadManager())); } }
public String sendChecksums(DataSource dataSource, java.util.Map<FileAndChecksum, List<FileAndChecksum>> fileToFragments, String filterUrl) throws IOException { String xml = toXml(dataSource, fileToFragments, filterUrl); log.info(format("Sending checksums for %s filtered with %s:%n%s", fileToFragments, filterUrl, xml)); String dataSourcesUrl = getDataSourcesUrl(dataSource.getId()); Put request = new Put(dataSourcesUrl, credentials); request.setAccept(APPLICATION_JSON); request.addFile("file", xml.getBytes(StandardCharsets.UTF_8)); String result = request.executeAsString(); if (request.isUnAuthorized()) throw new UnAuthorizedException("Cannot send checksums", dataSourcesUrl); if (!request.isSuccessful()) throw new IOException("PUT on " + dataSourcesUrl + " for data source " + dataSource + " not successful: " + result); log.info(format("Sent checksum for %s filtered with %s with result:%n%s", fileToFragments, filterUrl, result)); return result; } }
public static DatasourceType asDatasourceType(DataSource dataSource) { DatasourceType datasourceType = new ObjectFactory().createDatasourceType(); datasourceType.setId(dataSource.getId()); datasourceType.setName(dataSource.getName()); datasourceType.setBaseUrl(dataSource.getBaseUrl()); datasourceType.setDirectory(dataSource.getDirectory()); datasourceType.setAction(ActionType.fromValue(dataSource.getAction())); return datasourceType; }