Search in sources :

Example 1 with FileIngestJobExecution

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;
}
Also used : ImportService(org.molgenis.data.importer.ImportService) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) FileIngestJobExecution(org.molgenis.file.ingest.meta.FileIngestJobExecution) File(java.io.File) FileMeta(org.molgenis.data.file.model.FileMeta) EntityImportReport(org.molgenis.data.importer.EntityImportReport)

Aggregations

File (java.io.File)1 FileMeta (org.molgenis.data.file.model.FileMeta)1 FileRepositoryCollection (org.molgenis.data.file.support.FileRepositoryCollection)1 EntityImportReport (org.molgenis.data.importer.EntityImportReport)1 ImportService (org.molgenis.data.importer.ImportService)1 FileIngestJobExecution (org.molgenis.file.ingest.meta.FileIngestJobExecution)1