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