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);
}
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();
}
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();
}
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);
}
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;
}
Aggregations