Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCRUM-3515 validation fix #1440

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.alliancegenome.curation_api.model.entities.ontology.NCBITaxonTerm;
import org.alliancegenome.curation_api.services.ontology.NcbiTaxonTermService;
import org.alliancegenome.curation_api.services.validation.base.SubmittedObjectValidator;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import jakarta.inject.Inject;
Expand All @@ -26,20 +27,23 @@ public E validateBiologicalEntityFields(E uiEntity, E dbEntity) {

public NCBITaxonTerm validateTaxon(E uiEntity, E dbEntity) {
String field = "taxon";
if (uiEntity.getTaxon() == null || StringUtils.isBlank(uiEntity.getTaxon().getCurie())) {
if (ObjectUtils.isEmpty(uiEntity.getTaxon())) {
addMessageResponse(field, ValidationConstants.REQUIRED_MESSAGE);
return null;
}

NCBITaxonTerm taxon = ncbiTaxonTermService.get(uiEntity.getTaxon().getCurie()).getEntity();
if (taxon == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
}
NCBITaxonTerm taxon = null;
if (StringUtils.isNotBlank(uiEntity.getTaxon().getCurie())) {
taxon = ncbiTaxonTermService.findByCurie(uiEntity.getTaxon().getCurie());
if (taxon == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
}

if (taxon.getObsolete() && (dbEntity.getTaxon() == null || !taxon.getCurie().equals(dbEntity.getTaxon().getCurie()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (taxon.getObsolete() && (dbEntity.getTaxon() == null || !taxon.getCurie().equals(dbEntity.getTaxon().getCurie()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}

return taxon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.alliancegenome.curation_api.dao.BiologicalEntityDAO;
import org.alliancegenome.curation_api.dao.DiseaseAnnotationDAO;
import org.alliancegenome.curation_api.dao.GeneDAO;
import org.alliancegenome.curation_api.dao.ontology.DoTermDAO;
import org.alliancegenome.curation_api.dao.ontology.EcoTermDAO;
import org.alliancegenome.curation_api.model.entities.BiologicalEntity;
import org.alliancegenome.curation_api.model.entities.DataProvider;
Expand All @@ -24,8 +23,10 @@
import org.alliancegenome.curation_api.services.DataProviderService;
import org.alliancegenome.curation_api.services.VocabularyTermService;
import org.alliancegenome.curation_api.services.helpers.diseaseAnnotations.DiseaseAnnotationUniqueIdHelper;
import org.alliancegenome.curation_api.services.ontology.DoTermService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import jakarta.inject.Inject;

Expand All @@ -34,7 +35,7 @@ public class DiseaseAnnotationValidator extends AnnotationValidator {
@Inject
EcoTermDAO ecoTermDAO;
@Inject
DoTermDAO doTermDAO;
DoTermService doTermService;
@Inject
GeneDAO geneDAO;
@Inject
Expand All @@ -56,14 +57,15 @@ public DOTerm validateObjectOntologyTerm(DiseaseAnnotation uiEntity, DiseaseAnno
}

DOTerm diseaseTerm = null;
if (uiEntity.getDiseaseAnnotationObject().getId() != null)
diseaseTerm = doTermDAO.find(uiEntity.getDiseaseAnnotationObject().getId());
if (diseaseTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (diseaseTerm.getObsolete() && (dbEntity.getDiseaseAnnotationObject() == null || !diseaseTerm.getId().equals(dbEntity.getDiseaseAnnotationObject().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getDiseaseAnnotationObject().getCurie())) {
diseaseTerm = doTermService.findByCurie(uiEntity.getDiseaseAnnotationObject().getCurie());
if (diseaseTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (diseaseTerm.getObsolete() && (dbEntity.getDiseaseAnnotationObject() == null || !diseaseTerm.getId().equals(dbEntity.getDiseaseAnnotationObject().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return diseaseTerm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
import org.alliancegenome.curation_api.constants.OntologyConstants;
import org.alliancegenome.curation_api.constants.ValidationConstants;
import org.alliancegenome.curation_api.dao.ExperimentalConditionDAO;
import org.alliancegenome.curation_api.dao.ontology.AnatomicalTermDAO;
import org.alliancegenome.curation_api.dao.ontology.ChemicalTermDAO;
import org.alliancegenome.curation_api.dao.ontology.ExperimentalConditionOntologyTermDAO;
import org.alliancegenome.curation_api.dao.ontology.GoTermDAO;
import org.alliancegenome.curation_api.dao.ontology.NcbiTaxonTermDAO;
import org.alliancegenome.curation_api.dao.ontology.ZecoTermDAO;
import org.alliancegenome.curation_api.exceptions.ApiErrorException;
import org.alliancegenome.curation_api.model.entities.ExperimentalCondition;
import org.alliancegenome.curation_api.model.entities.ontology.AnatomicalTerm;
Expand All @@ -21,9 +15,15 @@
import org.alliancegenome.curation_api.response.SearchResponse;
import org.alliancegenome.curation_api.services.helpers.diseaseAnnotations.DiseaseAnnotationUniqueIdHelper;
import org.alliancegenome.curation_api.services.helpers.diseaseAnnotations.ExperimentalConditionSummary;
import org.alliancegenome.curation_api.services.ontology.AnatomicalTermService;
import org.alliancegenome.curation_api.services.ontology.ChemicalTermService;
import org.alliancegenome.curation_api.services.ontology.ExperimentalConditionOntologyTermService;
import org.alliancegenome.curation_api.services.ontology.GoTermService;
import org.alliancegenome.curation_api.services.ontology.NcbiTaxonTermService;
import org.alliancegenome.curation_api.services.ontology.ZecoTermService;
import org.alliancegenome.curation_api.services.validation.base.AuditedObjectValidator;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
Expand All @@ -34,17 +34,15 @@ public class ExperimentalConditionValidator extends AuditedObjectValidator<Exper
@Inject
ExperimentalConditionDAO experimentalConditionDAO;
@Inject
GoTermDAO goTermDAO;
GoTermService goTermService;
@Inject
ZecoTermDAO zecoTermDAO;
ZecoTermService zecoTermService;
@Inject
AnatomicalTermDAO anatomicalTermDAO;
AnatomicalTermService anatomicalTermService;
@Inject
ChemicalTermDAO chemicalTermDAO;
ChemicalTermService chemicalTermService;
@Inject
ExperimentalConditionOntologyTermDAO ecOntologyTermDAO;
@Inject
NcbiTaxonTermDAO ncbiTaxonTermDAO;
ExperimentalConditionOntologyTermService ecOntologyTermService;
@Inject
NcbiTaxonTermService ncbiTaxonTermService;

Expand Down Expand Up @@ -130,14 +128,15 @@ public ZECOTerm validateConditionClass(ExperimentalCondition uiEntity, Experimen
return null;
}
ZECOTerm zecoTerm = null;
if (uiEntity.getConditionClass().getId() != null)
zecoTerm = zecoTermDAO.find(uiEntity.getConditionClass().getId());
if (zecoTerm == null || zecoTerm.getSubsets().isEmpty() || !zecoTerm.getSubsets().contains(OntologyConstants.ZECO_AGR_SLIM_SUBSET)) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (zecoTerm.getObsolete() && (dbEntity.getConditionClass() == null || !zecoTerm.getId().equals(dbEntity.getConditionClass().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getConditionClass().getCurie())) {
zecoTerm = zecoTermService.findByCurie(uiEntity.getConditionClass().getCurie());
if (zecoTerm == null || zecoTerm.getSubsets().isEmpty() || !zecoTerm.getSubsets().contains(OntologyConstants.ZECO_AGR_SLIM_SUBSET)) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (zecoTerm.getObsolete() && (dbEntity.getConditionClass() == null || !zecoTerm.getId().equals(dbEntity.getConditionClass().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return zecoTerm;
}
Expand All @@ -147,14 +146,15 @@ public ExperimentalConditionOntologyTerm validateConditionId(ExperimentalConditi
if (ObjectUtils.isEmpty(uiEntity.getConditionId()))
return null;
ExperimentalConditionOntologyTerm ecOntologyTerm = null;
if (uiEntity.getConditionId().getId() != null)
ecOntologyTerm = ecOntologyTermDAO.find(uiEntity.getConditionId().getId());
if (ecOntologyTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (ecOntologyTerm.getObsolete() && (dbEntity.getConditionId() == null || !ecOntologyTerm.getId().equals(dbEntity.getConditionId().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getConditionId().getCurie())) {
ecOntologyTerm = ecOntologyTermService.findByCurie(uiEntity.getConditionId().getCurie());
if (ecOntologyTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (ecOntologyTerm.getObsolete() && (dbEntity.getConditionId() == null || !ecOntologyTerm.getId().equals(dbEntity.getConditionId().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return ecOntologyTerm;
}
Expand All @@ -164,14 +164,15 @@ public GOTerm validateConditionGeneOntology(ExperimentalCondition uiEntity, Expe
if (ObjectUtils.isEmpty(uiEntity.getConditionGeneOntology()))
return null;
GOTerm goTerm = null;
if (uiEntity.getConditionGeneOntology().getId() != null)
goTerm = goTermDAO.find(uiEntity.getConditionGeneOntology().getId());
if (goTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (goTerm.getObsolete() && (dbEntity.getConditionGeneOntology() == null || !goTerm.getId().equals(dbEntity.getConditionGeneOntology().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getConditionGeneOntology().getCurie())) {
goTerm = goTermService.findByCurie(uiEntity.getConditionGeneOntology().getCurie());
if (goTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (goTerm.getObsolete() && (dbEntity.getConditionGeneOntology() == null || !goTerm.getId().equals(dbEntity.getConditionGeneOntology().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return goTerm;
}
Expand All @@ -181,14 +182,15 @@ public AnatomicalTerm validateConditionAnatomy(ExperimentalCondition uiEntity, E
if (ObjectUtils.isEmpty(uiEntity.getConditionAnatomy()))
return null;
AnatomicalTerm anatomicalTerm = null;
if (uiEntity.getConditionAnatomy().getId() != null)
anatomicalTerm = anatomicalTermDAO.find(uiEntity.getConditionAnatomy().getId());
if (anatomicalTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (anatomicalTerm.getObsolete() && (dbEntity.getConditionAnatomy() == null || !anatomicalTerm.getId().equals(dbEntity.getConditionAnatomy().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getConditionAnatomy().getCurie())) {
anatomicalTerm = anatomicalTermService.findByCurie(uiEntity.getConditionAnatomy().getCurie());
if (anatomicalTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (anatomicalTerm.getObsolete() && (dbEntity.getConditionAnatomy() == null || !anatomicalTerm.getId().equals(dbEntity.getConditionAnatomy().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return anatomicalTerm;
}
Expand All @@ -198,14 +200,15 @@ public ChemicalTerm validateConditionChemical(ExperimentalCondition uiEntity, Ex
if (ObjectUtils.isEmpty(uiEntity.getConditionChemical()))
return null;
ChemicalTerm chemicalTerm = null;
if (uiEntity.getConditionChemical().getId() != null)
chemicalTerm = chemicalTermDAO.find(uiEntity.getConditionChemical().getId());
if (chemicalTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (chemicalTerm.getObsolete() && (dbEntity.getConditionChemical() == null || !chemicalTerm.getId().equals(dbEntity.getConditionChemical().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getConditionChemical().getCurie())) {
chemicalTerm = chemicalTermService.findByCurie(uiEntity.getConditionChemical().getCurie());
if (chemicalTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (chemicalTerm.getObsolete() && (dbEntity.getConditionChemical() == null || !chemicalTerm.getId().equals(dbEntity.getConditionChemical().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return chemicalTerm;
}
Expand All @@ -215,17 +218,17 @@ public NCBITaxonTerm validateConditionTaxon(ExperimentalCondition uiEntity, Expe
if (ObjectUtils.isEmpty(uiEntity.getConditionTaxon()))
return null;
NCBITaxonTerm taxonTerm = null;
if (uiEntity.getConditionTaxon().getId() != null)
taxonTerm = ncbiTaxonTermDAO.find(uiEntity.getConditionTaxon().getId());
if (taxonTerm == null) {
taxonTerm = ncbiTaxonTermService.downloadAndSave(uiEntity.getConditionTaxon().getCurie());
}
if (taxonTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (taxonTerm.getObsolete() && (dbEntity.getConditionTaxon() == null || !taxonTerm.getId().equals(dbEntity.getConditionTaxon().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getConditionTaxon().getCurie())) {
taxonTerm = ncbiTaxonTermService.findByCurie(uiEntity.getConditionTaxon().getCurie());
if (taxonTerm == null)
taxonTerm = ncbiTaxonTermService.downloadAndSave(uiEntity.getConditionTaxon().getCurie());
if (taxonTerm == null) {
addMessageResponse(field, ValidationConstants.INVALID_MESSAGE);
return null;
} else if (taxonTerm.getObsolete() && (dbEntity.getConditionTaxon() == null || !taxonTerm.getId().equals(dbEntity.getConditionTaxon().getId()))) {
addMessageResponse(field, ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return taxonTerm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.alliancegenome.curation_api.constants.ValidationConstants;
import org.alliancegenome.curation_api.dao.CrossReferenceDAO;
import org.alliancegenome.curation_api.dao.GeneDAO;
import org.alliancegenome.curation_api.dao.ontology.SoTermDAO;
import org.alliancegenome.curation_api.exceptions.ApiErrorException;
import org.alliancegenome.curation_api.model.entities.Gene;
import org.alliancegenome.curation_api.model.entities.ontology.SOTerm;
Expand All @@ -16,13 +15,15 @@
import org.alliancegenome.curation_api.model.entities.slotAnnotations.geneSlotAnnotations.GeneSynonymSlotAnnotation;
import org.alliancegenome.curation_api.model.entities.slotAnnotations.geneSlotAnnotations.GeneSystematicNameSlotAnnotation;
import org.alliancegenome.curation_api.response.ObjectResponse;
import org.alliancegenome.curation_api.services.ontology.SoTermService;
import org.alliancegenome.curation_api.services.validation.slotAnnotations.geneSlotAnnotations.GeneFullNameSlotAnnotationValidator;
import org.alliancegenome.curation_api.services.validation.slotAnnotations.geneSlotAnnotations.GeneSecondaryIdSlotAnnotationValidator;
import org.alliancegenome.curation_api.services.validation.slotAnnotations.geneSlotAnnotations.GeneSymbolSlotAnnotationValidator;
import org.alliancegenome.curation_api.services.validation.slotAnnotations.geneSlotAnnotations.GeneSynonymSlotAnnotationValidator;
import org.alliancegenome.curation_api.services.validation.slotAnnotations.geneSlotAnnotations.GeneSystematicNameSlotAnnotationValidator;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
Expand All @@ -33,7 +34,7 @@ public class GeneValidator extends GenomicEntityValidator<Gene> {
@Inject
GeneDAO geneDAO;
@Inject
SoTermDAO soTermDAO;
SoTermService soTermService;
@Inject
GeneSymbolSlotAnnotationValidator geneSymbolValidator;
@Inject
Expand Down Expand Up @@ -139,14 +140,15 @@ private SOTerm validateGeneType(Gene uiEntity, Gene dbEntity) {
return null;

SOTerm soTerm = null;
if (uiEntity.getGeneType().getId() != null)
soTerm = soTermDAO.find(uiEntity.getGeneType().getId());
if (soTerm == null) {
addMessageResponse("geneType", ValidationConstants.INVALID_MESSAGE);
return null;
} else if (soTerm.getObsolete() && (dbEntity.getGeneType() == null || !soTerm.getId().equals(dbEntity.getGeneType().getId()))) {
addMessageResponse("geneType", ValidationConstants.OBSOLETE_MESSAGE);
return null;
if (StringUtils.isNotBlank(uiEntity.getGeneType().getCurie())) {
soTerm = soTermService.findByCurie(uiEntity.getGeneType().getCurie());
if (soTerm == null) {
addMessageResponse("geneType", ValidationConstants.INVALID_MESSAGE);
return null;
} else if (soTerm.getObsolete() && (dbEntity.getGeneType() == null || !soTerm.getId().equals(dbEntity.getGeneType().getId()))) {
addMessageResponse("geneType", ValidationConstants.OBSOLETE_MESSAGE);
return null;
}
}
return soTerm;
}
Expand Down
Loading
Loading