From bc8af6e7164f7ec3870915b904ea46e9aa1c2d2c Mon Sep 17 00:00:00 2001 From: Christian Pich Date: Fri, 2 Aug 2024 16:43:20 +0200 Subject: [PATCH] SCRUM-4305 set obsolete / internal variables explicitly when being updated. (#1629) --- .../helpers/UniqueIdentifierHelper.java | 72 +++++++++++++++++++ .../dto/AGMDiseaseAnnotationDTOValidator.java | 50 +++++-------- .../AlleleDiseaseAnnotationDTOValidator.java | 19 ++--- .../dto/AnnotationDTOValidator.java | 8 +-- .../validation/dto/ConstructDTOValidator.java | 22 ++---- .../dto/DiseaseAnnotationDTOValidator.java | 39 +++++----- .../GeneDiseaseAnnotationDTOValidator.java | 29 +++----- 7 files changed, 132 insertions(+), 107 deletions(-) create mode 100644 src/main/java/org/alliancegenome/curation_api/services/helpers/UniqueIdentifierHelper.java diff --git a/src/main/java/org/alliancegenome/curation_api/services/helpers/UniqueIdentifierHelper.java b/src/main/java/org/alliancegenome/curation_api/services/helpers/UniqueIdentifierHelper.java new file mode 100644 index 000000000..a0fea2520 --- /dev/null +++ b/src/main/java/org/alliancegenome/curation_api/services/helpers/UniqueIdentifierHelper.java @@ -0,0 +1,72 @@ +package org.alliancegenome.curation_api.services.helpers; + +import org.alliancegenome.curation_api.model.entities.Annotation; +import org.alliancegenome.curation_api.model.entities.base.AuditedObject; +import org.alliancegenome.curation_api.model.entities.base.SubmittedObject; +import org.alliancegenome.curation_api.model.ingest.dto.AnnotationDTO; +import org.alliancegenome.curation_api.model.ingest.dto.DiseaseAnnotationDTO; +import org.alliancegenome.curation_api.model.ingest.dto.base.SubmittedObjectDTO; +import org.apache.commons.lang3.StringUtils; + +public class UniqueIdentifierHelper { + + public static String getIdentifyingField(E annotationDTO) { + if (StringUtils.isNotBlank(annotationDTO.getModEntityId())) { + return "modEntityId"; + } else if (StringUtils.isNotBlank(annotationDTO.getModInternalId())) { + return "modInternalId"; + } else { + return "uniqueId"; + } + } + + public static void setObsoleteAndInternal(DiseaseAnnotationDTO dto, AuditedObject annotation) { + // default obsolete value: false + annotation.setObsolete(dto.getObsolete() != null && dto.getObsolete()); + // default internal value: false + annotation.setInternal(dto.getInternal() != null && dto.getInternal()); + } + + public static String setAnnotationID(E annotationDTO, F annotation, String uniqueId) { + if (StringUtils.isNotBlank(annotationDTO.getModEntityId())) { + annotation.setModEntityId(annotationDTO.getModEntityId()); + return annotationDTO.getModEntityId(); + } else if (StringUtils.isNotBlank(annotationDTO.getModInternalId())) { + annotation.setModInternalId(annotationDTO.getModInternalId()); + return annotationDTO.getModInternalId(); + } else { + return uniqueId; + } + } + + + public static String getIdentifyingField(E submittedObjectDto) { + if (StringUtils.isNotBlank(submittedObjectDto.getModEntityId())) { + return "modEntityId"; + } else if (StringUtils.isNotBlank(submittedObjectDto.getModInternalId())) { + return "modInternalId"; + } else { + return "uniqueId"; + } + } + + public static void setObsoleteAndInternal(SubmittedObjectDTO dto, SubmittedObject submittedObject) { + // default obsolete value: false + submittedObject.setObsolete(dto.getObsolete() != null && dto.getObsolete()); + // default internal value: false + submittedObject.setInternal(dto.getInternal() != null && dto.getInternal()); + } + + public static String setAnnotationID(E submittedObjectDTO, F submittedObject, String uniqueId) { + if (StringUtils.isNotBlank(submittedObjectDTO.getModEntityId())) { + submittedObject.setModEntityId(submittedObjectDTO.getModEntityId()); + return submittedObjectDTO.getModEntityId(); + } else if (StringUtils.isNotBlank(submittedObjectDTO.getModInternalId())) { + submittedObject.setModInternalId(submittedObjectDTO.getModInternalId()); + return submittedObjectDTO.getModInternalId(); + } else { + return uniqueId; + } + } + +} diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AGMDiseaseAnnotationDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AGMDiseaseAnnotationDTOValidator.java index 875022490..42ef855a4 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AGMDiseaseAnnotationDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AGMDiseaseAnnotationDTOValidator.java @@ -1,20 +1,14 @@ package org.alliancegenome.curation_api.services.validation.dto; -import java.util.ArrayList; -import java.util.List; - +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Inject; import org.alliancegenome.curation_api.constants.ValidationConstants; import org.alliancegenome.curation_api.constants.VocabularyConstants; import org.alliancegenome.curation_api.dao.AGMDiseaseAnnotationDAO; import org.alliancegenome.curation_api.enums.BackendBulkDataProvider; import org.alliancegenome.curation_api.exceptions.ObjectUpdateException; import org.alliancegenome.curation_api.exceptions.ObjectValidationException; -import org.alliancegenome.curation_api.model.entities.AGMDiseaseAnnotation; -import org.alliancegenome.curation_api.model.entities.AffectedGenomicModel; -import org.alliancegenome.curation_api.model.entities.Allele; -import org.alliancegenome.curation_api.model.entities.Gene; -import org.alliancegenome.curation_api.model.entities.Reference; -import org.alliancegenome.curation_api.model.entities.VocabularyTerm; +import org.alliancegenome.curation_api.model.entities.*; import org.alliancegenome.curation_api.model.ingest.dto.AGMDiseaseAnnotationDTO; import org.alliancegenome.curation_api.response.ObjectResponse; import org.alliancegenome.curation_api.response.SearchResponse; @@ -22,22 +16,28 @@ import org.alliancegenome.curation_api.services.AlleleService; import org.alliancegenome.curation_api.services.GeneService; import org.alliancegenome.curation_api.services.VocabularyTermService; +import org.alliancegenome.curation_api.services.helpers.UniqueIdentifierHelper; import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationRetrievalHelper; import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationUniqueIdHelper; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; +import java.util.ArrayList; +import java.util.List; @RequestScoped public class AGMDiseaseAnnotationDTOValidator extends DiseaseAnnotationDTOValidator { - @Inject AGMDiseaseAnnotationDAO agmDiseaseAnnotationDAO; - @Inject VocabularyTermService vocabularyTermService; - @Inject AffectedGenomicModelService agmService; - @Inject GeneService geneService; - @Inject AlleleService alleleService; + @Inject + AGMDiseaseAnnotationDAO agmDiseaseAnnotationDAO; + @Inject + VocabularyTermService vocabularyTermService; + @Inject + AffectedGenomicModelService agmService; + @Inject + GeneService geneService; + @Inject + AlleleService alleleService; public AGMDiseaseAnnotation validateAGMDiseaseAnnotationDTO(AGMDiseaseAnnotationDTO dto, BackendBulkDataProvider dataProvider) throws ObjectUpdateException, ObjectValidationException { @@ -58,27 +58,15 @@ public AGMDiseaseAnnotation validateAGMDiseaseAnnotationDTO(AGMDiseaseAnnotation if (agm == null) { adaResponse.addErrorMessage("agm_identifier", ValidationConstants.INVALID_MESSAGE + " (" + dto.getAgmIdentifier() + ")"); } else { - String annotationId; - String identifyingField; String uniqueId = AnnotationUniqueIdHelper.getDiseaseAnnotationUniqueId(dto, dto.getAgmIdentifier(), refCurie); - - if (StringUtils.isNotBlank(dto.getModEntityId())) { - annotationId = dto.getModEntityId(); - annotation.setModEntityId(annotationId); - identifyingField = "modEntityId"; - } else if (StringUtils.isNotBlank(dto.getModInternalId())) { - annotationId = dto.getModInternalId(); - annotation.setModInternalId(annotationId); - identifyingField = "modInternalId"; - } else { - annotationId = uniqueId; - identifyingField = "uniqueId"; - } + String annotationId = UniqueIdentifierHelper.setAnnotationID(dto, annotation, uniqueId); + String identifyingField = UniqueIdentifierHelper.getIdentifyingField(dto); SearchResponse annotationList = agmDiseaseAnnotationDAO.findByField(identifyingField, annotationId); annotation = AnnotationRetrievalHelper.getCurrentAnnotation(annotation, annotationList); annotation.setUniqueId(uniqueId); annotation.setDiseaseAnnotationSubject(agm); + UniqueIdentifierHelper.setObsoleteAndInternal(dto, annotation); if (dataProvider != null && (dataProvider.name().equals("RGD") || dataProvider.name().equals("HUMAN")) diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AlleleDiseaseAnnotationDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AlleleDiseaseAnnotationDTOValidator.java index 69c1ad33f..8baba7e91 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AlleleDiseaseAnnotationDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AlleleDiseaseAnnotationDTOValidator.java @@ -19,6 +19,7 @@ import org.alliancegenome.curation_api.services.AlleleService; import org.alliancegenome.curation_api.services.GeneService; import org.alliancegenome.curation_api.services.VocabularyTermService; +import org.alliancegenome.curation_api.services.helpers.UniqueIdentifierHelper; import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationRetrievalHelper; import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationUniqueIdHelper; import org.apache.commons.collections.CollectionUtils; @@ -53,27 +54,15 @@ public AlleleDiseaseAnnotation validateAlleleDiseaseAnnotationDTO(AlleleDiseaseA if (allele == null) { adaResponse.addErrorMessage("allele_identifier", ValidationConstants.INVALID_MESSAGE + " (" + dto.getAlleleIdentifier() + ")"); } else { - String annotationId; - String identifyingField; String uniqueId = AnnotationUniqueIdHelper.getDiseaseAnnotationUniqueId(dto, dto.getAlleleIdentifier(), refCurie); - - if (StringUtils.isNotBlank(dto.getModEntityId())) { - annotationId = dto.getModEntityId(); - annotation.setModEntityId(annotationId); - identifyingField = "modEntityId"; - } else if (StringUtils.isNotBlank(dto.getModInternalId())) { - annotationId = dto.getModInternalId(); - annotation.setModInternalId(annotationId); - identifyingField = "modInternalId"; - } else { - annotationId = uniqueId; - identifyingField = "uniqueId"; - } + String annotationId = UniqueIdentifierHelper.setAnnotationID(dto, annotation, uniqueId); + String identifyingField = UniqueIdentifierHelper.getIdentifyingField(dto); SearchResponse annotationList = alleleDiseaseAnnotationDAO.findByField(identifyingField, annotationId); annotation = AnnotationRetrievalHelper.getCurrentAnnotation(annotation, annotationList); annotation.setUniqueId(uniqueId); annotation.setDiseaseAnnotationSubject(allele); + UniqueIdentifierHelper.setObsoleteAndInternal(dto, annotation); if (dataProvider != null && (dataProvider.name().equals("RGD") || dataProvider.name().equals("HUMAN")) diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AnnotationDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AnnotationDTOValidator.java index 6f7026b73..5044fed15 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AnnotationDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/AnnotationDTOValidator.java @@ -10,11 +10,7 @@ import org.alliancegenome.curation_api.dao.ConditionRelationDAO; import org.alliancegenome.curation_api.dao.DataProviderDAO; import org.alliancegenome.curation_api.dao.NoteDAO; -import org.alliancegenome.curation_api.model.entities.Annotation; -import org.alliancegenome.curation_api.model.entities.ConditionRelation; -import org.alliancegenome.curation_api.model.entities.DataProvider; -import org.alliancegenome.curation_api.model.entities.Note; -import org.alliancegenome.curation_api.model.entities.Reference; +import org.alliancegenome.curation_api.model.entities.*; import org.alliancegenome.curation_api.model.ingest.dto.AnnotationDTO; import org.alliancegenome.curation_api.model.ingest.dto.ConditionRelationDTO; import org.alliancegenome.curation_api.response.ObjectResponse; @@ -141,4 +137,6 @@ public ObjectResponse validat aResponse.setEntity(annotation); return aResponse; } + + } diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/ConstructDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/ConstructDTOValidator.java index 667802e52..c3523d1e2 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/ConstructDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/ConstructDTOValidator.java @@ -20,6 +20,7 @@ import org.alliancegenome.curation_api.model.ingest.dto.slotAnnotions.constructSlotAnnotations.ConstructComponentSlotAnnotationDTO; import org.alliancegenome.curation_api.response.ObjectResponse; import org.alliancegenome.curation_api.response.SearchResponse; +import org.alliancegenome.curation_api.services.helpers.UniqueIdentifierHelper; import org.alliancegenome.curation_api.services.helpers.constructs.ConstructUniqueIdHelper; import org.alliancegenome.curation_api.services.helpers.slotAnnotations.SlotAnnotationIdentityHelper; import org.alliancegenome.curation_api.services.validation.dto.slotAnnotations.constructSlotAnnotations.ConstructComponentSlotAnnotationDTOValidator; @@ -27,7 +28,6 @@ import org.alliancegenome.curation_api.services.validation.dto.slotAnnotations.constructSlotAnnotations.ConstructSymbolSlotAnnotationDTOValidator; import org.alliancegenome.curation_api.services.validation.dto.slotAnnotations.constructSlotAnnotations.ConstructSynonymSlotAnnotationDTOValidator; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; @@ -48,25 +48,13 @@ public class ConstructDTOValidator extends ReagentDTOValidator { @Transactional public Construct validateConstructDTO(ConstructDTO dto, BackendBulkDataProvider dataProvider) throws ObjectValidationException { - constructResponse = new ObjectResponse(); + constructResponse = new ObjectResponse<>(); Construct construct = new Construct(); - String constructId; - String identifyingField; String uniqueId = ConstructUniqueIdHelper.getConstructUniqueId(dto); - - if (StringUtils.isNotBlank(dto.getModEntityId())) { - constructId = dto.getModEntityId(); - construct.setModEntityId(constructId); - identifyingField = "modEntityId"; - } else if (StringUtils.isNotBlank(dto.getModInternalId())) { - constructId = dto.getModInternalId(); - construct.setModInternalId(constructId); - identifyingField = "modInternalId"; - } else { - constructId = uniqueId; - identifyingField = "uniqueId"; - } + String constructId = UniqueIdentifierHelper.setAnnotationID(dto, construct, uniqueId); + String identifyingField = UniqueIdentifierHelper.getIdentifyingField(dto); + UniqueIdentifierHelper.setObsoleteAndInternal(dto, construct); SearchResponse constructList = constructDAO.findByField(identifyingField, constructId); if (constructList != null && constructList.getResults().size() > 0) { diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/DiseaseAnnotationDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/DiseaseAnnotationDTOValidator.java index 522038733..5d327504b 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/DiseaseAnnotationDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/DiseaseAnnotationDTOValidator.java @@ -1,17 +1,12 @@ package org.alliancegenome.curation_api.services.validation.dto; -import java.util.ArrayList; -import java.util.List; - +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Inject; import org.alliancegenome.curation_api.constants.OntologyConstants; import org.alliancegenome.curation_api.constants.ValidationConstants; import org.alliancegenome.curation_api.constants.VocabularyConstants; import org.alliancegenome.curation_api.dao.DataProviderDAO; -import org.alliancegenome.curation_api.model.entities.BiologicalEntity; -import org.alliancegenome.curation_api.model.entities.DataProvider; -import org.alliancegenome.curation_api.model.entities.DiseaseAnnotation; -import org.alliancegenome.curation_api.model.entities.Gene; -import org.alliancegenome.curation_api.model.entities.VocabularyTerm; +import org.alliancegenome.curation_api.model.entities.*; import org.alliancegenome.curation_api.model.entities.ontology.DOTerm; import org.alliancegenome.curation_api.model.entities.ontology.ECOTerm; import org.alliancegenome.curation_api.model.ingest.dto.DiseaseAnnotationDTO; @@ -25,20 +20,28 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; +import java.util.ArrayList; +import java.util.List; @RequestScoped public class DiseaseAnnotationDTOValidator extends AnnotationDTOValidator { - @Inject DoTermService doTermService; - @Inject EcoTermService ecoTermService; - @Inject ReferenceService referenceService; - @Inject VocabularyTermService vocabularyTermService; - @Inject GeneService geneService; - @Inject BiologicalEntityService biologicalEntityService; - @Inject DataProviderDTOValidator dataProviderDtoValidator; - @Inject DataProviderDAO dataProviderDAO; + @Inject + DoTermService doTermService; + @Inject + EcoTermService ecoTermService; + @Inject + ReferenceService referenceService; + @Inject + VocabularyTermService vocabularyTermService; + @Inject + GeneService geneService; + @Inject + BiologicalEntityService biologicalEntityService; + @Inject + DataProviderDTOValidator dataProviderDtoValidator; + @Inject + DataProviderDAO dataProviderDAO; public ObjectResponse validateDiseaseAnnotationDTO(E annotation, D dto) { ObjectResponse daResponse = validateAnnotationDTO(annotation, dto, VocabularyConstants.DISEASE_ANNOTATION_NOTE_TYPES_VOCABULARY_TERM_SET); diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/GeneDiseaseAnnotationDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/GeneDiseaseAnnotationDTOValidator.java index 0b54f7f96..3cc48b120 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/GeneDiseaseAnnotationDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/GeneDiseaseAnnotationDTOValidator.java @@ -7,16 +7,13 @@ import org.alliancegenome.curation_api.dao.NoteDAO; import org.alliancegenome.curation_api.enums.BackendBulkDataProvider; import org.alliancegenome.curation_api.exceptions.ObjectValidationException; -import org.alliancegenome.curation_api.model.entities.AffectedGenomicModel; -import org.alliancegenome.curation_api.model.entities.Gene; -import org.alliancegenome.curation_api.model.entities.GeneDiseaseAnnotation; -import org.alliancegenome.curation_api.model.entities.Reference; -import org.alliancegenome.curation_api.model.entities.VocabularyTerm; +import org.alliancegenome.curation_api.model.entities.*; import org.alliancegenome.curation_api.model.ingest.dto.GeneDiseaseAnnotationDTO; import org.alliancegenome.curation_api.response.ObjectResponse; import org.alliancegenome.curation_api.response.SearchResponse; import org.alliancegenome.curation_api.services.AffectedGenomicModelService; import org.alliancegenome.curation_api.services.VocabularyTermService; +import org.alliancegenome.curation_api.services.helpers.UniqueIdentifierHelper; import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationRetrievalHelper; import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationUniqueIdHelper; import org.apache.commons.lang3.StringUtils; @@ -36,7 +33,7 @@ public class GeneDiseaseAnnotationDTOValidator extends DiseaseAnnotationDTOValid public GeneDiseaseAnnotation validateGeneDiseaseAnnotationDTO(GeneDiseaseAnnotationDTO dto, BackendBulkDataProvider dataProvider) throws ObjectValidationException { GeneDiseaseAnnotation annotation = new GeneDiseaseAnnotation(); Gene gene; - ObjectResponse gdaResponse = new ObjectResponse(); + ObjectResponse gdaResponse = new ObjectResponse<>(); ObjectResponse refResponse = validateReference(annotation, dto); gdaResponse.addErrorMessages(refResponse.getErrorMessages()); @@ -51,27 +48,16 @@ public GeneDiseaseAnnotation validateGeneDiseaseAnnotationDTO(GeneDiseaseAnnotat if (gene == null) { gdaResponse.addErrorMessage("gene_identifier", ValidationConstants.INVALID_MESSAGE + " (" + dto.getGeneIdentifier() + ")"); } else { - String annotationId; - String identifyingField; String uniqueId = AnnotationUniqueIdHelper.getDiseaseAnnotationUniqueId(dto, dto.getGeneIdentifier(), refCurie); - - if (StringUtils.isNotBlank(dto.getModEntityId())) { - annotationId = dto.getModEntityId(); - annotation.setModEntityId(annotationId); - identifyingField = "modEntityId"; - } else if (StringUtils.isNotBlank(dto.getModInternalId())) { - annotationId = dto.getModInternalId(); - annotation.setModInternalId(annotationId); - identifyingField = "modInternalId"; - } else { - annotationId = uniqueId; - identifyingField = "uniqueId"; - } + String annotationId = UniqueIdentifierHelper.setAnnotationID(dto, annotation, uniqueId); + String identifyingField = UniqueIdentifierHelper.getIdentifyingField(dto); SearchResponse annotationList = geneDiseaseAnnotationDAO.findByField(identifyingField, annotationId); annotation = AnnotationRetrievalHelper.getCurrentAnnotation(annotation, annotationList); annotation.setUniqueId(uniqueId); annotation.setDiseaseAnnotationSubject(gene); + UniqueIdentifierHelper.setObsoleteAndInternal(dto, annotation); + if (dataProvider != null && (dataProvider.name().equals("RGD") || dataProvider.name().equals("HUMAN")) && !gene.getTaxon().getCurie().equals(dataProvider.canonicalTaxonCurie) || !dataProvider.sourceOrganization.equals(gene.getDataProvider().getSourceOrganization().getAbbreviation())) { @@ -111,4 +97,5 @@ public GeneDiseaseAnnotation validateGeneDiseaseAnnotationDTO(GeneDiseaseAnnotat return annotation; } + }