Search in sources :

Example 1 with ImportService

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;
}
Also used : DatabaseAction(org.molgenis.data.DatabaseAction) IOException(java.io.IOException) RepositoryCollection(org.molgenis.data.RepositoryCollection) MolgenisDataException(org.molgenis.data.MolgenisDataException) ImportService(org.molgenis.data.importer.ImportService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ImportService

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;
}
Also used : RepositoryCollection(org.molgenis.data.RepositoryCollection) EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) ImportService(org.molgenis.data.importer.ImportService) ArrayList(java.util.ArrayList) Package(org.molgenis.data.meta.model.Package) HashSet(java.util.HashSet)

Example 3 with ImportService

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;
}
Also used : RepositoryCollection(org.molgenis.data.RepositoryCollection) ObjectError(org.springframework.validation.ObjectError) ImportService(org.molgenis.data.importer.ImportService) Part(javax.servlet.http.Part) File(java.io.File)

Example 4 with ImportService

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);
}
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 5 with ImportService

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

Aggregations

ImportService (org.molgenis.data.importer.ImportService)14 EntityImportReport (org.molgenis.data.importer.EntityImportReport)11 File (java.io.File)10 FileRepositoryCollection (org.molgenis.data.file.support.FileRepositoryCollection)10 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 MolgenisDataException (org.molgenis.data.MolgenisDataException)2 FileMeta (org.molgenis.data.file.model.FileMeta)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Part (javax.servlet.http.Part)1 DatabaseAction (org.molgenis.data.DatabaseAction)1 EntitiesValidationReport (org.molgenis.data.importer.EntitiesValidationReport)1 Package (org.molgenis.data.meta.model.Package)1 FileIngestJobExecution (org.molgenis.file.ingest.meta.FileIngestJobExecution)1 ObjectError (org.springframework.validation.ObjectError)1