Search in sources :

Example 6 with FileRepositoryCollection

use of org.molgenis.data.file.support.FileRepositoryCollection in project molgenis by molgenis.

the class EmxImportServiceIT method testDoImportEmxTsvZip.

private void testDoImportEmxTsvZip() {
    String fileName = "emx-tsv.zip";
    File file = getFile("/tsv/" + fileName);
    FileRepositoryCollection repoCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
    ImportService importService = importServiceFactory.getImportService(file, repoCollection);
    EntityImportReport importReport = importService.doImport(repoCollection, ADD, PACKAGE_DEFAULT);
    validateImportReport(importReport, ImmutableMap.of(TSV_HOSPITAL, 3, TSV_PATIENTS, 3), ImmutableSet.of(TSV_HOSPITAL, TSV_PATIENTS));
    verifyFirstAndLastRows(TSV_HOSPITAL, hospitalFirstRow, hospitalLastRow);
    verifyFirstAndLastRows(TSV_PATIENTS, patientsFirstRow, patientsLastRow);
}
Also used : ImportService(org.molgenis.data.importer.ImportService) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) File(java.io.File) EntityImportReport(org.molgenis.data.importer.EntityImportReport)

Example 7 with FileRepositoryCollection

use of org.molgenis.data.file.support.FileRepositoryCollection in project molgenis by molgenis.

the class EmxImportServiceIT method executeAddUpdateOrUpdateTest.

private void executeAddUpdateOrUpdateTest(File file, File addUpdateFile, Map<String, Integer> entityCountMap, Set<String> addedEntityTypes, Runnable entityValidationMethod) {
    FileRepositoryCollection addRepoCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
    ImportService addImportService = importServiceFactory.getImportService(file, addRepoCollection);
    addImportService.doImport(addRepoCollection, ADD, PACKAGE_DEFAULT);
    FileRepositoryCollection addUpdateRepoCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(addUpdateFile);
    ImportService addUpdateImportService = importServiceFactory.getImportService(addUpdateFile, addUpdateRepoCollection);
    EntityImportReport importReport = addUpdateImportService.doImport(addUpdateRepoCollection, ADD_UPDATE_EXISTING, PACKAGE_DEFAULT);
    validateImportReport(importReport, entityCountMap, addedEntityTypes);
    entityValidationMethod.run();
}
Also used : ImportService(org.molgenis.data.importer.ImportService) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) EntityImportReport(org.molgenis.data.importer.EntityImportReport)

Example 8 with FileRepositoryCollection

use of org.molgenis.data.file.support.FileRepositoryCollection in project molgenis by molgenis.

the class EmxImportServiceIT method testDoImportAddEmx.

private void testDoImportAddEmx(File file, Map<String, Integer> entityCountMap, Set<String> addedEntityTypes, Runnable entityValidationMethod) {
    FileRepositoryCollection repoCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
    ImportService importService = importServiceFactory.getImportService(file, repoCollection);
    EntityImportReport importReport = importService.doImport(repoCollection, ADD, PACKAGE_DEFAULT);
    validateImportReport(importReport, entityCountMap, addedEntityTypes);
    entityValidationMethod.run();
}
Also used : ImportService(org.molgenis.data.importer.ImportService) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) EntityImportReport(org.molgenis.data.importer.EntityImportReport)

Example 9 with FileRepositoryCollection

use of org.molgenis.data.file.support.FileRepositoryCollection in project molgenis by molgenis.

the class OntologyImportServiceIT method testDoImportObo.

private void testDoImportObo() {
    String fileName = "ontology-small.obo.zip";
    File file = getFile("/obo/" + fileName);
    FileRepositoryCollection repoCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
    ImportService importService = importServiceFactory.getImportService(file, repoCollection);
    EntityImportReport importReport = importService.doImport(repoCollection, ADD, PACKAGE_DEFAULT);
    validateImportReport(importReport, ImmutableMap.of("sys_ont_OntologyTermDynamicAnnotation", 0, "sys_ont_OntologyTermSynonym", 5, "sys_ont_OntologyTermNodePath", 5, "sys_ont_Ontology", 1, "sys_ont_OntologyTerm", 5), emptySet());
    // Verify the import as system as we need write permissions on sys tables to carry out the verification
    runAsSystem(this::verifyOboAsSystem);
}
Also used : ImportService(org.molgenis.data.importer.ImportService) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) File(java.io.File) EntityImportReport(org.molgenis.data.importer.EntityImportReport)

Example 10 with FileRepositoryCollection

use of org.molgenis.data.file.support.FileRepositoryCollection in project molgenis by molgenis.

the class FileRepositoryCollectionFactory method createFileRepositoryCollection.

/**
 * Factory method for creating a new FileRepositorySource
 * <p>
 * For example an excel file
 */
public FileRepositoryCollection createFileRepositoryCollection(File file) {
    Class<? extends FileRepositoryCollection> clazz;
    String extension = FileExtensionUtils.findExtensionFromPossibilities(file.getName(), fileRepositoryCollection.keySet());
    clazz = fileRepositoryCollection.get(extension);
    if (clazz == null) {
        throw new MolgenisDataException("Unknown extension for file '" + file.getName() + "'");
    }
    Constructor<? extends FileRepositoryCollection> ctor;
    try {
        ctor = clazz.getConstructor(File.class);
    } catch (Exception e) {
        throw new MolgenisDataException("Exception creating [" + clazz + "]  missing constructor FileRepositorySource(File file)");
    }
    FileRepositoryCollection fileRepositoryCollection = BeanUtils.instantiateClass(ctor, file);
    autowireCapableBeanFactory.autowireBeanProperties(fileRepositoryCollection, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    try {
        fileRepositoryCollection.init();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return fileRepositoryCollection;
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) MolgenisDataException(org.molgenis.data.MolgenisDataException)

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