use of org.molgenis.data.importer.ImportService in project molgenis by molgenis.
the class PackageWizardPage method handleRequest.
@Override
public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) {
ImportWizardUtil.validateImportWizard(wizard);
ImportWizard importWizard = (ImportWizard) wizard;
String entityImportOption = importWizard.getEntityImportOption();
if (entityImportOption != null) {
try {
// convert input to database action
DatabaseAction entityDbAction = ImportWizardUtil.toDatabaseAction(entityImportOption);
if (entityDbAction == null) {
throw new IOException("unknown database action: " + entityImportOption);
}
RepositoryCollection repositoryCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(importWizard.getFile());
ImportService importService = importServiceFactory.getImportService(importWizard.getFile(), repositoryCollection);
// Do integration test only if there are no previous errors found
if (!importWizard.getEntitiesImportable().containsValue(false)) {
// The package name that is selected in the "package selection" page
String selectedPackage = request.getParameter("selectedPackage");
// The entities that can be imported
Map<String, Boolean> entitiesImportable = importService.determineImportableEntities(metaDataService, repositoryCollection, selectedPackage);
// The results of the attribute checks are stored in maps with the entityname as key, those need to be updated with the packagename
updateFieldReports(importWizard, selectedPackage, entitiesImportable);
// Set the entities that can be imported
importWizard.setEntitiesImportable(entitiesImportable);
// The entities that can not be imported. If even one entity can not be imported, everything fails
List<String> entitiesNotImportable = entitiesImportable.entrySet().stream().filter(entity -> !entity.getValue()).map(Map.Entry::getKey).collect(toList());
if (!entitiesNotImportable.isEmpty()) {
throw new MolgenisDataException("You are trying to upload entities that are not compatible with the already existing entities: " + entitiesNotImportable.toString());
}
}
} catch (RuntimeException | IOException e) {
ImportWizardUtil.handleException(e, importWizard, result, LOG, entityImportOption);
}
}
return null;
}
use of org.molgenis.data.importer.ImportService in project molgenis by molgenis.
the class OptionsWizardPage method validateInput.
private String validateInput(File file, ImportWizard wizard, BindingResult result) {
// decide what importer to use...
RepositoryCollection source = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
ImportService importService = importServiceFactory.getImportService(file, source);
EntitiesValidationReport validationReport = importService.validateImport(file, source);
wizard.setEntitiesImportable(validationReport.getSheetsImportable());
wizard.setFieldsDetected(validationReport.getFieldsImportable());
wizard.setFieldsRequired(validationReport.getFieldsRequired());
wizard.setFieldsAvailable(validationReport.getFieldsAvailable());
wizard.setFieldsUnknown(validationReport.getFieldsUnknown());
Set<String> allPackages = new HashSet<>(validationReport.getPackages());
for (Package p : dataService.getMeta().getPackages()) {
allPackages.add(p.getId());
}
List<String> entitiesInDefaultPackage = new ArrayList<>();
for (String entityTypeId : validationReport.getSheetsImportable().keySet()) {
if (validationReport.getSheetsImportable().get(entityTypeId)) {
if (isInDefaultPackage(entityTypeId, allPackages))
entitiesInDefaultPackage.add(entityTypeId);
}
}
wizard.setEntitiesInDefaultPackage(entitiesInDefaultPackage);
List<String> packages = new ArrayList<>(validationReport.getPackages());
packages.add(0, PACKAGE_DEFAULT);
wizard.setPackages(packages);
String msg = null;
if (validationReport.valid()) {
wizard.setFile(file);
msg = "File is validated and can be imported.";
} else {
wizard.setValidationMessage("File did not pass validation see results below. Please resolve the errors and try again.");
}
return msg;
}
use of org.molgenis.data.importer.ImportService in project molgenis by molgenis.
the class UploadWizardPage method handleRequest.
@Override
public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) {
ImportWizardUtil.validateImportWizard(wizard);
ImportWizard importWizard = (ImportWizard) wizard;
String entityImportOption = request.getParameter("entity_option");
try {
File file = null;
Part part = request.getPart("upload");
if (part != null) {
file = FileUploadUtils.saveToTempFolder(part);
}
if (file == null) {
result.addError(new ObjectError("wizard", "No file selected"));
} else {
importWizard.setFile(file);
RepositoryCollection repositoryCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
ImportService importService = importServiceFactory.getImportService(file, repositoryCollection);
importWizard.setSupportedDatabaseActions(importService.getSupportedDatabaseActions());
importWizard.setMustChangeEntityName(importService.getMustChangeEntityName());
}
} catch (Exception e) {
ImportWizardUtil.handleException(e, importWizard, result, LOG, entityImportOption);
}
return null;
}
use of org.molgenis.data.importer.ImportService in project molgenis by molgenis.
the class OntologyImportServiceIT method testDoImportOwl.
private void testDoImportOwl() {
String fileName = "ontology-small.owl.zip";
File file = getFile("/owl/" + 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", 4, "sys_ont_OntologyTermSynonym", 9, "sys_ont_OntologyTermNodePath", 10, "sys_ont_Ontology", 1, "sys_ont_OntologyTerm", 9), emptySet());
// Verify the import as system as we need write permissions on sys tables to carry out the verification
runAsSystem(this::verifyOwlAsSystem);
}
use of org.molgenis.data.importer.ImportService in project molgenis by molgenis.
the class VcfImportServiceIT method testDoImportVcfWithoutSamples.
private void testDoImportVcfWithoutSamples() {
String entityTypeId = "variantsWithoutSamples";
String fileName = entityTypeId + ".vcf";
File file = getFile("/vcf/" + fileName);
FileRepositoryCollection repoCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
ImportService importService = importServiceFactory.getImportService(file, repoCollection);
EntityImportReport importReport = importService.doImport(repoCollection, ADD, PACKAGE_DEFAULT);
validateImportReport(importReport, ImmutableMap.of(entityTypeId, 10), ImmutableSet.of(entityTypeId));
assertVariants(entityTypeId, false);
}
Aggregations