Search in sources :

Example 11 with FileRepositoryCollection

use of org.molgenis.data.file.support.FileRepositoryCollection 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

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