Skip to content

Commit

Permalink
SCRUM-4305 set obsolete / internal variables explicitly when being up… (
Browse files Browse the repository at this point in the history
#1631)

* SCRUM-4305 set obsolete / internal variables explicitly when being updated. (#1629)

(cherry picked from commit bc8af6e)

* private constructor for helper class

* add whitespace

* add whitespace
  • Loading branch information
cmpich authored Aug 5, 2024
1 parent 7e9d3be commit 5d6de03
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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 {

private UniqueIdentifierHelper() {
}

public static <E extends AnnotationDTO> 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 <E extends AnnotationDTO, F extends Annotation> 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 <E extends SubmittedObjectDTO> 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 <E extends SubmittedObjectDTO, F extends SubmittedObject> 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;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
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;
import org.alliancegenome.curation_api.services.AffectedGenomicModelService;
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 {

Expand All @@ -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<AGMDiseaseAnnotation> 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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AlleleDiseaseAnnotation> 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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -141,4 +137,6 @@ public <E extends Annotation, D extends AnnotationDTO> ObjectResponse<E> validat
aResponse.setEntity(annotation);
return aResponse;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
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;
import org.alliancegenome.curation_api.services.validation.dto.slotAnnotations.constructSlotAnnotations.ConstructFullNameSlotAnnotationDTOValidator;
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;
Expand All @@ -48,25 +48,13 @@ public class ConstructDTOValidator extends ReagentDTOValidator {
@Transactional
public Construct validateConstructDTO(ConstructDTO dto, BackendBulkDataProvider dataProvider) throws ObjectValidationException {

constructResponse = new ObjectResponse<Construct>();
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<Construct> constructList = constructDAO.findByField(identifyingField, constructId);
if (constructList != null && constructList.getResults().size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 <E extends DiseaseAnnotation, D extends DiseaseAnnotationDTO> ObjectResponse<E> validateDiseaseAnnotationDTO(E annotation, D dto) {
ObjectResponse<E> daResponse = validateAnnotationDTO(annotation, dto, VocabularyConstants.DISEASE_ANNOTATION_NOTE_TYPES_VOCABULARY_TERM_SET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<GeneDiseaseAnnotation> gdaResponse = new ObjectResponse<GeneDiseaseAnnotation>();
ObjectResponse<GeneDiseaseAnnotation> gdaResponse = new ObjectResponse<>();

ObjectResponse<GeneDiseaseAnnotation> refResponse = validateReference(annotation, dto);
gdaResponse.addErrorMessages(refResponse.getErrorMessages());
Expand All @@ -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<GeneDiseaseAnnotation> 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())) {
Expand Down Expand Up @@ -111,4 +97,5 @@ public GeneDiseaseAnnotation validateGeneDiseaseAnnotationDTO(GeneDiseaseAnnotat

return annotation;
}

}

0 comments on commit 5d6de03

Please sign in to comment.