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