use of org.molgenis.file.ingest.meta.FileIngestJobExecution in project molgenis by molgenis.
the class FileIngester method ingest.
/**
* Imports a csv file defined in the fileIngest entity
*
* @see FileIngestJobExecutionMetaData
*/
public FileMeta ingest(String entityTypeId, String url, String loader, String jobExecutionID, Progress progress) {
if (!"CSV".equals(loader)) {
throw new FileIngestException("Unknown loader '" + loader + "'");
}
progress.setProgressMax(2);
progress.progress(0, "Downloading url '" + url + "'");
File file = fileStoreDownload.downloadFile(url, jobExecutionID, entityTypeId + ".csv");
progress.progress(1, "Importing...");
FileRepositoryCollection repoCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
ImportService importService = importServiceFactory.getImportService(file, repoCollection);
EntityImportReport report = importService.doImport(repoCollection, ADD_UPDATE_EXISTING, PACKAGE_DEFAULT);
progress.status("Ingestion of url '" + url + "' done.");
Integer count = report.getNrImportedEntitiesMap().get(entityTypeId);
count = count != null ? count : 0;
progress.progress(2, "Successfully imported " + count + " " + entityTypeId + " entities.");
FileMeta fileMeta = createFileMeta(jobExecutionID, file);
FileIngestJobExecution fileIngestJobExecution = (FileIngestJobExecution) progress.getJobExecution();
fileIngestJobExecution.setFile(fileMeta);
dataService.add(FILE_META, fileMeta);
return fileMeta;
}
Aggregations