use of org.molgenis.data.importer.EntitiesValidationReport in project molgenis by molgenis.
the class EmxMetaDataParser method buildValidationReport.
private EntitiesValidationReport buildValidationReport(RepositoryCollection source, MyEntitiesValidationReport report, Map<String, EntityType> metaDataMap) {
metaDataMap.values().forEach(entityTypeValidator::validate);
metaDataMap.values().stream().map(EntityType::getAllAttributes).forEach(attributes -> attributes.forEach(attr -> {
attributeValidator.validate(attr, ValidationMode.ADD_SKIP_ENTITY_VALIDATION);
}));
// validate package/entity/attribute tags
metaDataMap.values().stream().map(EntityType::getPackage).filter(Objects::nonNull).forEach(package_ -> package_.getTags().forEach(tagValidator::validate));
metaDataMap.values().forEach(entityType -> entityType.getTags().forEach(tagValidator::validate));
metaDataMap.values().stream().map(EntityType::getAllAttributes).forEach(attributes -> attributes.forEach(attr -> {
attr.getTags().forEach(tagValidator::validate);
}));
report = generateEntityValidationReport(source, report, metaDataMap);
// Add entities without data
for (String entityTypeId : metaDataMap.keySet()) {
if (!report.getSheetsImportable().containsKey(entityTypeId))
report.addEntity(entityTypeId, true);
}
return report;
}
use of org.molgenis.data.importer.EntitiesValidationReport 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.EntitiesValidationReport in project molgenis by molgenis.
the class VcfImporterServiceTest method validateImportWithSamplesAlreadyExists.
@Test
public void validateImportWithSamplesAlreadyExists() {
// 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);
when(dataService.hasRepository(entityTypeId0)).thenReturn(true);
when(dataService.hasRepository(sampleEntityName0)).thenReturn(true);
EntitiesValidationReport entitiesValidationReport = vcfImporterService.validateImport(file, source);
assertFalse(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.FALSE);
sheetsImportable.put(sampleEntityName0, Boolean.FALSE);
assertEquals(entitiesValidationReport.getSheetsImportable(), sheetsImportable);
}
use of org.molgenis.data.importer.EntitiesValidationReport 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;
}
use of org.molgenis.data.importer.EntitiesValidationReport in project molgenis by molgenis.
the class VcfImporterServiceTest method validateImportWithoutSamplesAlreadyExists.
@Test
public void validateImportWithoutSamplesAlreadyExists() {
// 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);
when(dataService.hasRepository(entityTypeId0)).thenReturn(true);
EntitiesValidationReport entitiesValidationReport = vcfImporterService.validateImport(file, source);
assertFalse(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.FALSE));
}
Aggregations