diff --git a/src/main/java/org/alliancegenome/curation_api/jobs/executors/SequenceTargetingReagentExecutor.java b/src/main/java/org/alliancegenome/curation_api/jobs/executors/SequenceTargetingReagentExecutor.java index 3c7b0b3d8..9c96eec15 100644 --- a/src/main/java/org/alliancegenome/curation_api/jobs/executors/SequenceTargetingReagentExecutor.java +++ b/src/main/java/org/alliancegenome/curation_api/jobs/executors/SequenceTargetingReagentExecutor.java @@ -12,7 +12,6 @@ import org.alliancegenome.curation_api.exceptions.ObjectUpdateException.ObjectUpdateExceptionData; import org.alliancegenome.curation_api.interfaces.AGRCurationSchemaVersion; import org.alliancegenome.curation_api.model.entities.SequenceTargetingReagent; -import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation; import org.alliancegenome.curation_api.model.entities.bulkloads.BulkFMSLoad; import org.alliancegenome.curation_api.model.entities.bulkloads.BulkLoadFile; import org.alliancegenome.curation_api.model.entities.bulkloads.BulkLoadFileHistory; diff --git a/src/main/java/org/alliancegenome/curation_api/services/SequenceTargetingReagentService.java b/src/main/java/org/alliancegenome/curation_api/services/SequenceTargetingReagentService.java index a11689115..14d3fa63b 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/SequenceTargetingReagentService.java +++ b/src/main/java/org/alliancegenome/curation_api/services/SequenceTargetingReagentService.java @@ -1,20 +1,16 @@ package org.alliancegenome.curation_api.services; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import org.alliancegenome.curation_api.constants.EntityFieldConstants; import org.alliancegenome.curation_api.dao.SequenceTargetingReagentDAO; import org.alliancegenome.curation_api.enums.BackendBulkDataProvider; import org.alliancegenome.curation_api.exceptions.ObjectUpdateException; import org.alliancegenome.curation_api.interfaces.crud.BaseUpsertServiceInterface; -import org.alliancegenome.curation_api.model.entities.Gene; import org.alliancegenome.curation_api.model.entities.SequenceTargetingReagent; -import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation; import org.alliancegenome.curation_api.model.ingest.dto.fms.SequenceTargetingReagentFmsDTO; import org.alliancegenome.curation_api.services.base.BaseEntityCrudService; import org.alliancegenome.curation_api.services.validation.dto.fms.SequenceTargetingReagentFmsDTOValidator; diff --git a/src/main/java/org/alliancegenome/curation_api/services/associations/SequenceTargetingReagentGeneAssociationService.java b/src/main/java/org/alliancegenome/curation_api/services/associations/SequenceTargetingReagentGeneAssociationService.java index 4c00833a2..bf19881cf 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/associations/SequenceTargetingReagentGeneAssociationService.java +++ b/src/main/java/org/alliancegenome/curation_api/services/associations/SequenceTargetingReagentGeneAssociationService.java @@ -9,20 +9,14 @@ import org.alliancegenome.curation_api.constants.EntityFieldConstants; import org.alliancegenome.curation_api.dao.associations.SequenceTargetingReagentGeneAssociationDAO; -import org.alliancegenome.curation_api.dao.associations.alleleAssociations.AlleleGeneAssociationDAO; import org.alliancegenome.curation_api.enums.BackendBulkDataProvider; import org.alliancegenome.curation_api.exceptions.ObjectUpdateException; -import org.alliancegenome.curation_api.interfaces.crud.BaseUpsertServiceInterface; import org.alliancegenome.curation_api.model.entities.Gene; import org.alliancegenome.curation_api.model.entities.SequenceTargetingReagent; -import org.alliancegenome.curation_api.model.entities.associations.alleleAssociations.AlleleGeneAssociation; import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation; -import org.alliancegenome.curation_api.model.ingest.dto.associations.alleleAssociations.AlleleGeneAssociationDTO; import org.alliancegenome.curation_api.model.ingest.dto.fms.SequenceTargetingReagentFmsDTO; -import org.alliancegenome.curation_api.services.base.BaseAssociationDTOCrudService; import org.alliancegenome.curation_api.services.validation.associations.SequenceTargetingReagentGeneAssociationFmsDTOValidator; -import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.transaction.Transactional; diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/associations/SequenceTargetingReagentGeneAssociationFmsDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/associations/SequenceTargetingReagentGeneAssociationFmsDTOValidator.java index 1997b6f97..ca24216f8 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/associations/SequenceTargetingReagentGeneAssociationFmsDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/associations/SequenceTargetingReagentGeneAssociationFmsDTOValidator.java @@ -22,57 +22,61 @@ @RequestScoped public class SequenceTargetingReagentGeneAssociationFmsDTOValidator { - @Inject SequenceTargetingReagentDAO sqtrDAO; - @Inject VocabularyTermService vocabularyTermService; - @Inject GeneService geneService; + @Inject + SequenceTargetingReagentDAO sqtrDAO; + @Inject + VocabularyTermService vocabularyTermService; + @Inject + GeneService geneService; - public List validateSQTRGeneAssociationFmsDTO( SequenceTargetingReagentFmsDTO dto, BackendBulkDataProvider beDataProvider) throws ObjectValidationException { - List strGeneAssociations = new ArrayList<>(); - ObjectResponse sqtrResponse = new ObjectResponse<>(); + public List validateSQTRGeneAssociationFmsDTO(SequenceTargetingReagentFmsDTO dto, BackendBulkDataProvider beDataProvider) throws ObjectValidationException { + List strGeneAssociations = new ArrayList<>(); + ObjectResponse sqtrResponse = new ObjectResponse<>(); - SequenceTargetingReagent sqtr; - SearchResponse sqtrSearchResponse = sqtrDAO.findByField("modEntityId", dto.getPrimaryId()); + SequenceTargetingReagent sqtr; + SearchResponse sqtrSearchResponse = sqtrDAO.findByField("modEntityId", + dto.getPrimaryId()); - if (sqtrSearchResponse == null || sqtrSearchResponse.getSingleResult() == null) { - sqtrResponse.addErrorMessage("modEntityId", - ValidationConstants.INVALID_MESSAGE + " (" + dto.getPrimaryId() + ")"); - sqtr = new SequenceTargetingReagent(); - } else { - sqtr = sqtrSearchResponse.getSingleResult(); - } + if (sqtrSearchResponse == null || sqtrSearchResponse.getSingleResult() == null) { + sqtrResponse.addErrorMessage("modEntityId", + ValidationConstants.INVALID_MESSAGE + " (" + dto.getPrimaryId() + ")"); + sqtr = new SequenceTargetingReagent(); + } else { + sqtr = sqtrSearchResponse.getSingleResult(); + } - VocabularyTerm relation; - SearchResponse relationSearchResponse = vocabularyTermService.findByField("name", "targets"); - if (relationSearchResponse == null || relationSearchResponse.getSingleResult() == null) { - sqtrResponse.addErrorMessage("relation", ValidationConstants.INVALID_MESSAGE + " (" + "targets" + ")"); - relation = new VocabularyTerm(); - } else { - relation = relationSearchResponse.getSingleResult(); - } + VocabularyTerm relation; + SearchResponse relationSearchResponse = vocabularyTermService.findByField("name", "targets"); + if (relationSearchResponse == null || relationSearchResponse.getSingleResult() == null) { + sqtrResponse.addErrorMessage("relation", ValidationConstants.INVALID_MESSAGE + " (" + "targets" + ")"); + relation = new VocabularyTerm(); + } else { + relation = relationSearchResponse.getSingleResult(); + } - if(dto.getTargetGeneIds() != null){ - for (String geneId : dto.getTargetGeneIds()) { - Gene gene = geneService.findByIdentifierString(geneId); - - if (gene == null) { - sqtrResponse.addErrorMessage("targetGeneIds", - ValidationConstants.INVALID_MESSAGE + " (" + geneId + ")"); - } else { - SequenceTargetingReagentGeneAssociation strGeneAssociation = new SequenceTargetingReagentGeneAssociation(); - strGeneAssociation.setSequenceTargetingReagentAssociationSubject(sqtr); - strGeneAssociation.setRelation(relation); - strGeneAssociation.setSequenceTargetingReagentGeneAssociationObject(gene); - - strGeneAssociations.add(strGeneAssociation); - } - - } - } - - if (sqtrResponse.hasErrors()) { - throw new ObjectValidationException(dto, sqtrResponse.errorMessagesString()); - } + if (dto.getTargetGeneIds() != null) { + for (String geneId : dto.getTargetGeneIds()) { + Gene gene = geneService.findByIdentifierString(geneId); - return strGeneAssociations; - } + if (gene == null) { + sqtrResponse.addErrorMessage("targetGeneIds", + ValidationConstants.INVALID_MESSAGE + " (" + geneId + ")"); + } else { + SequenceTargetingReagentGeneAssociation strGeneAssociation = new SequenceTargetingReagentGeneAssociation(); + strGeneAssociation.setSequenceTargetingReagentAssociationSubject(sqtr); + strGeneAssociation.setRelation(relation); + strGeneAssociation.setSequenceTargetingReagentGeneAssociationObject(gene); + + strGeneAssociations.add(strGeneAssociation); + } + + } + } + + if (sqtrResponse.hasErrors()) { + throw new ObjectValidationException(dto, sqtrResponse.errorMessagesString()); + } + + return strGeneAssociations; + } } diff --git a/src/test/java/org/alliancegenome/curation_api/SequenceTargetingReagentBulkUploadFmsITCase.java b/src/test/java/org/alliancegenome/curation_api/SequenceTargetingReagentBulkUploadFmsITCase.java index 8939c04a8..03a2df0a4 100644 --- a/src/test/java/org/alliancegenome/curation_api/SequenceTargetingReagentBulkUploadFmsITCase.java +++ b/src/test/java/org/alliancegenome/curation_api/SequenceTargetingReagentBulkUploadFmsITCase.java @@ -67,41 +67,17 @@ public void sqtrBulkUploadCheckFields() throws Exception { @Order(2) public void sqtrBulkUploadMissingRequiredFields() throws Exception { - checkFailedBulkLoad( - sqtrBulkPostEndpoint, - sqtrTestFilePath + "MR_01_no_name.json", - 2, - 1, - 1 - ); - checkFailedBulkLoad( - sqtrBulkPostEndpoint, - sqtrTestFilePath + "MR_02_no_taxon.json", - 2, - 1, - 1 - ); + checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "MR_01_no_name.json", 2, 1, 1); + checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "MR_02_no_taxon.json", 2, 1, 1); } @Test @Order(3) public void sqtrBulkUploadEmptyRequiredFields() throws Exception { - checkFailedBulkLoad( - sqtrBulkPostEndpoint, - sqtrTestFilePath + "ER_01_empty_name.json", - 2, - 1, - 1 - ); - - checkFailedBulkLoad( - sqtrBulkPostEndpoint, - sqtrTestFilePath + "ER_02_empty_taxon.json", - 2, - 1, - 1 - ); + checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "ER_01_empty_name.json", 2, 1, 1); + + checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "ER_02_empty_taxon.json", 2, 1, 1); }