Search in sources :

Example 6 with EntitiesValidationReport

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

the class VcfImporterServiceTest method validateImportWithSamples.

@Test
public void validateImportWithSamples() {
    // Test with multiple input repositories not possible due to
    // https://github.com/molgenis/molgenis/issues/4544
    File file = mock(File.class);
    String entityTypeId0 = "entity0";
    List<String> entityTypeIds = Arrays.asList(entityTypeId0);
    String attrName0 = "attr0";
    Attribute attr0 = mock(Attribute.class);
    when(attr0.getName()).thenReturn(attrName0);
    String sampleAttrName0 = "sampleAttr0";
    Attribute sampleAttr0 = mock(Attribute.class);
    when(sampleAttr0.getName()).thenReturn(sampleAttrName0);
    String sampleEntityName0 = "entity0sample";
    EntityType sampleEntityType0 = mock(EntityType.class);
    when(sampleEntityType0.getId()).thenReturn(sampleEntityName0);
    when(sampleEntityType0.getOwnAttributes()).thenReturn(emptyList());
    when(sampleEntityType0.getAtomicAttributes()).thenReturn(singleton(sampleAttr0));
    when(sampleEntityType0.getOwnLookupAttributes()).thenReturn(emptyList());
    Attribute sampleAttr = mock(Attribute.class);
    when(sampleAttr.getName()).thenReturn(VcfAttributes.SAMPLES);
    when(sampleAttr.getRefEntity()).thenReturn(sampleEntityType0);
    when(sampleAttr.getDataType()).thenReturn(MREF);
    EntityType entityType0 = mock(EntityType.class);
    when(entityType0.getId()).thenReturn(entityTypeId0);
    when(entityType0.getAttribute(VcfAttributes.SAMPLES)).thenReturn(sampleAttr);
    when(entityType0.getOwnAttributes()).thenReturn(singletonList(sampleAttr));
    when(entityType0.getAtomicAttributes()).thenReturn(singletonList(sampleAttr));
    when(entityType0.getOwnLookupAttributes()).thenReturn(emptyList());
    @SuppressWarnings("unchecked") Repository<Entity> repo0 = mock(Repository.class);
    when(repo0.getName()).thenReturn(entityTypeId0);
    when(repo0.getEntityType()).thenReturn(entityType0);
    RepositoryCollection source = mock(RepositoryCollection.class);
    when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
    when(source.getRepository(entityTypeId0)).thenReturn(repo0);
    EntitiesValidationReport entitiesValidationReport = vcfImporterService.validateImport(file, source);
    assertTrue(entitiesValidationReport.valid());
    assertEquals(entitiesValidationReport.getFieldsAvailable(), emptyMap());
    Map<String, List<String>> importableFields = new HashMap<>();
    importableFields.put(entityTypeId0, singletonList(VcfAttributes.SAMPLES));
    importableFields.put(sampleEntityName0, singletonList(sampleAttrName0));
    assertEquals(entitiesValidationReport.getFieldsImportable(), importableFields);
    assertEquals(entitiesValidationReport.getFieldsRequired(), emptyMap());
    assertEquals(entitiesValidationReport.getFieldsUnknown(), emptyMap());
    assertEquals(entitiesValidationReport.getImportOrder(), emptyList());
    assertEquals(entitiesValidationReport.getPackages(), emptyList());
    Map<String, Boolean> sheetsImportable = new HashMap<>();
    sheetsImportable.put(entityTypeId0, Boolean.TRUE);
    sheetsImportable.put(sampleEntityName0, Boolean.TRUE);
    assertEquals(entitiesValidationReport.getSheetsImportable(), sheetsImportable);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) File(java.io.File) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 7 with EntitiesValidationReport

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

the class VcfImporterServiceTest method validateImportWithoutSamples.

@Test
public void validateImportWithoutSamples() {
    // Test with multiple input repositories not possible due to
    // https://github.com/molgenis/molgenis/issues/4544
    File file = mock(File.class);
    String entityTypeId0 = "entity0";
    List<String> entityTypeIds = Arrays.asList(entityTypeId0);
    String attrName0 = "attr0";
    Attribute attr0 = mock(Attribute.class);
    when(attr0.getName()).thenReturn(attrName0);
    EntityType entityType0 = mock(EntityType.class);
    when(entityType0.getId()).thenReturn(entityTypeId0);
    when(entityType0.getOwnAttributes()).thenReturn(singletonList(attr0));
    when(entityType0.getAtomicAttributes()).thenReturn(singletonList(attr0));
    when(entityType0.getOwnLookupAttributes()).thenReturn(emptyList());
    @SuppressWarnings("unchecked") Repository<Entity> repo0 = mock(Repository.class);
    when(repo0.getName()).thenReturn(entityTypeId0);
    when(repo0.getEntityType()).thenReturn(entityType0);
    RepositoryCollection source = mock(RepositoryCollection.class);
    when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
    when(source.getRepository(entityTypeId0)).thenReturn(repo0);
    EntitiesValidationReport entitiesValidationReport = vcfImporterService.validateImport(file, source);
    assertTrue(entitiesValidationReport.valid());
    assertEquals(entitiesValidationReport.getFieldsAvailable(), emptyMap());
    assertEquals(entitiesValidationReport.getFieldsImportable(), singletonMap(entityTypeId0, singletonList(attrName0)));
    assertEquals(entitiesValidationReport.getFieldsRequired(), emptyMap());
    assertEquals(entitiesValidationReport.getFieldsUnknown(), emptyMap());
    assertEquals(entitiesValidationReport.getImportOrder(), emptyList());
    assertEquals(entitiesValidationReport.getPackages(), emptyList());
    assertEquals(entitiesValidationReport.getSheetsImportable(), singletonMap(entityTypeId0, Boolean.TRUE));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) Attribute(org.molgenis.data.meta.model.Attribute) File(java.io.File) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 8 with EntitiesValidationReport

use of org.molgenis.data.importer.EntitiesValidationReport 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)8 File (java.io.File)4 Attribute (org.molgenis.data.meta.model.Attribute)4 EntityType (org.molgenis.data.meta.model.EntityType)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)3 Test (org.testng.annotations.Test)3 EntitiesValidationReportImpl (org.molgenis.data.importer.EntitiesValidationReportImpl)2 Package (org.molgenis.data.meta.model.Package)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.builder (com.google.common.collect.ImmutableMap.builder)1 Iterables (com.google.common.collect.Iterables)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Maps.newLinkedHashMap (com.google.common.collect.Maps.newLinkedHashMap)1 FALSE (java.lang.Boolean.FALSE)1 TRUE (java.lang.Boolean.TRUE)1 String.format (java.lang.String.format)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1