Search in sources :

Example 1 with EntitiesValidationReportImpl

use of org.molgenis.data.importer.EntitiesValidationReportImpl in project molgenis by molgenis.

the class VcfImporterService method validateImport.

@Override
public EntitiesValidationReport validateImport(File file, RepositoryCollection source) {
    EntitiesValidationReport report = new EntitiesValidationReportImpl();
    Iterator<String> it = source.getEntityTypeIds().iterator();
    if (it.hasNext()) {
        String entityTypeId = it.next();
        EntityType emd = source.getRepository(entityTypeId).getEntityType();
        // Vcf entity
        boolean entityExists = runAsSystem(() -> dataService.hasRepository(entityTypeId));
        report.getSheetsImportable().put(entityTypeId, !entityExists);
        // Available Attributes
        List<String> availableAttributeNames = Lists.newArrayList();
        for (Attribute attr : emd.getAtomicAttributes()) {
            availableAttributeNames.add(attr.getName());
        }
        report.getFieldsImportable().put(entityTypeId, availableAttributeNames);
        // Sample entity
        Attribute sampleAttribute = emd.getAttribute(VcfAttributes.SAMPLES);
        if (sampleAttribute != null) {
            String sampleEntityName = sampleAttribute.getRefEntity().getId();
            boolean sampleEntityExists = runAsSystem(() -> dataService.hasRepository(sampleEntityName));
            report.getSheetsImportable().put(sampleEntityName, !sampleEntityExists);
            List<String> availableSampleAttributeNames = Lists.newArrayList();
            for (Attribute attr : sampleAttribute.getRefEntity().getAtomicAttributes()) {
                availableSampleAttributeNames.add(attr.getName());
            }
            report.getFieldsImportable().put(sampleEntityName, availableSampleAttributeNames);
        }
    }
    return report;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) Attribute(org.molgenis.data.meta.model.Attribute) EntitiesValidationReportImpl(org.molgenis.data.importer.EntitiesValidationReportImpl)

Example 2 with EntitiesValidationReportImpl

use of org.molgenis.data.importer.EntitiesValidationReportImpl in project molgenis by molgenis.

the class OntologyImportService method validateImport.

@Override
public EntitiesValidationReport validateImport(File file, RepositoryCollection source) {
    EntitiesValidationReport report = new EntitiesValidationReportImpl();
    if (source.getRepository(ONTOLOGY) == null)
        throw new MolgenisDataException("Exception Repository [" + ONTOLOGY + "] is missing");
    boolean ontologyExists = false;
    for (Entity ontologyEntity : source.getRepository(ONTOLOGY)) {
        String ontologyIRI = ontologyEntity.getString(OntologyMetaData.ONTOLOGY_IRI);
        String ontologyName = ontologyEntity.getString(OntologyMetaData.ONTOLOGY_NAME);
        Entity ontologyQueryEntity = dataService.findOne(ONTOLOGY, new QueryImpl<>().eq(OntologyMetaData.ONTOLOGY_IRI, ontologyIRI).or().eq(OntologyMetaData.ONTOLOGY_NAME, ontologyName));
        ontologyExists = ontologyQueryEntity != null;
    }
    if (ontologyExists)
        throw new MolgenisDataException("The ontology you are trying to import already exists");
    for (String entityTypeId : source.getEntityTypeIds()) {
        report.getSheetsImportable().put(entityTypeId, !ontologyExists);
    }
    return report;
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) EntitiesValidationReportImpl(org.molgenis.data.importer.EntitiesValidationReportImpl)

Aggregations

EntitiesValidationReport (org.molgenis.data.importer.EntitiesValidationReport)2 EntitiesValidationReportImpl (org.molgenis.data.importer.EntitiesValidationReportImpl)2 Attribute (org.molgenis.data.meta.model.Attribute)1 EntityType (org.molgenis.data.meta.model.EntityType)1 QueryImpl (org.molgenis.data.support.QueryImpl)1