From dcb3aac1856154c0d40b67a84705a861784956db Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Tue, 9 Jul 2024 11:54:29 -0500 Subject: [PATCH] SCRUM-4185 update executor to use sqtr gene association service --- .../SequenceTargetingReagentExecutor.java | 44 +++++++++++++------ ...argetingReagentGeneAssociationService.java | 34 +++++++------- ...ReagentGeneAssociationFmsDTOValidator.java | 34 +++++++------- ...quenceTargetingReagentFmsDTOValidator.java | 6 --- 4 files changed, 63 insertions(+), 55 deletions(-) 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 708b12cfe..3c7b0b3d8 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 @@ -2,7 +2,9 @@ import java.io.FileInputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.zip.GZIPInputStream; import org.alliancegenome.curation_api.enums.BackendBulkDataProvider; @@ -28,8 +30,10 @@ @ApplicationScoped public class SequenceTargetingReagentExecutor extends LoadFileExecutor { - @Inject SequenceTargetingReagentService sqtrService; - @Inject SequenceTargetingReagentGeneAssociationService sqtrGeneAssociationService; + @Inject + SequenceTargetingReagentService sqtrService; + @Inject + SequenceTargetingReagentGeneAssociationService sqtrGeneAssociationService; public void execLoad(BulkLoadFile bulkLoadFile) { @@ -53,20 +57,20 @@ public void execLoad(BulkLoadFile bulkLoadFile) { BackendBulkDataProvider dataProvider = BackendBulkDataProvider.valueOf(fms.getFmsDataSubType()); - List sqtrIdsLoaded = new ArrayList<>(); - List sqtrIdsBefore = sqtrService.getIdsByDataProvider(dataProvider.name()); - List sqtrGeneAssociationIdsLoaded = new ArrayList<>(); - List sqtrGeneAssociationIdsBefore = sqtrService.getIdsByDataProvider(dataProvider.name()); + Map> idsAdded = new HashMap>(); + idsAdded.put("SQTR", new ArrayList()); + idsAdded.put("SQTRGeneAssociation", new ArrayList()); + Map> previousIds = getPreviouslyLoadedIds(dataProvider); bulkLoadFileDAO.merge(bulkLoadFile); - BulkLoadFileHistory history = new BulkLoadFileHistory(sqtrIngestFmsDTO.getData().size()); + BulkLoadFileHistory history = new BulkLoadFileHistory(sqtrIngestFmsDTO.getData().size() * 2); - runLoad(history, dataProvider, sqtrIngestFmsDTO.getData(), sqtrIdsLoaded, sqtrGeneAssociationIdsLoaded); + runLoad(history, dataProvider, sqtrIngestFmsDTO.getData(), idsAdded.get("SQTR"), idsAdded.get("SQTRGeneAssociation")); - runCleanup(sqtrService, history, dataProvider.name(), sqtrIdsBefore, sqtrIdsLoaded, "SQTR", bulkLoadFile.getMd5Sum()); - runCleanup(sqtrService, history, dataProvider.name(), sqtrGeneAssociationIdsBefore, sqtrGeneAssociationIdsLoaded, "SQTR Gene Associations", bulkLoadFile.getMd5Sum()); + runCleanup(sqtrService, history, dataProvider.name(), previousIds.get("SQTR"), idsAdded.get("SQTR"), "SQTR", bulkLoadFile.getMd5Sum()); + runCleanup(sqtrService, history, dataProvider.name(), previousIds.get("SQTRGeneAssociation"), idsAdded.get("SQTRGeneAssociation"), "SQTR Gene Associations", bulkLoadFile.getMd5Sum()); history.finishLoad(); @@ -77,11 +81,20 @@ public void execLoad(BulkLoadFile bulkLoadFile) { } } + private Map> getPreviouslyLoadedIds(BackendBulkDataProvider dataProvider) { + Map> previousIds = new HashMap<>(); + + previousIds.put("SQTR", sqtrService.getIdsByDataProvider(dataProvider.name())); + previousIds.put("SQTRGeneAssociation", sqtrGeneAssociationService.getIdsByDataProvider(dataProvider.name())); + + return previousIds; + } + public APIResponse runLoadApi(String dataProviderName, List sqtrDTOs) { List sqtrIdsLoaded = new ArrayList<>(); List sqtrGeneAssociationIdsLoaded = new ArrayList<>(); - BulkLoadFileHistory history = new BulkLoadFileHistory(sqtrDTOs.size()); + BulkLoadFileHistory history = new BulkLoadFileHistory(sqtrDTOs.size() * 2); BackendBulkDataProvider dataProvider = BackendBulkDataProvider.valueOf(dataProviderName); runLoad(history, dataProvider, sqtrDTOs, sqtrIdsLoaded, sqtrGeneAssociationIdsLoaded); history.finishLoad(); @@ -101,7 +114,8 @@ private void runLoad(BulkLoadFileHistory history, BackendBulkDataProvider dataPr } - private void loadSequenceTargetingReagents(BulkLoadFileHistory history, List sqtrs, List idsLoaded, BackendBulkDataProvider dataProvider, ProcessDisplayHelper ph) { + private void loadSequenceTargetingReagents(BulkLoadFileHistory history, List sqtrs, + List idsLoaded, BackendBulkDataProvider dataProvider, ProcessDisplayHelper ph) { for (SequenceTargetingReagentFmsDTO dto : sqtrs) { try { SequenceTargetingReagent dbObject = sqtrService.upsert(dto, dataProvider); @@ -121,11 +135,13 @@ private void loadSequenceTargetingReagents(BulkLoadFileHistory history, List sqtrs, List idsLoaded, BackendBulkDataProvider dataProvider, ProcessDisplayHelper ph) { + private void loadSequenceTargetingReagentGeneAssociations(BulkLoadFileHistory history, + List sqtrs, List idsLoaded, BackendBulkDataProvider dataProvider, + ProcessDisplayHelper ph) { for (SequenceTargetingReagentFmsDTO dto : sqtrs) { try { - List associationIds = sqtrGeneAssociationService.addGeneAssociations(dto, dataProvider); + List associationIds = sqtrGeneAssociationService.loadGeneAssociations(dto, dataProvider); history.incrementCompleted(); if (idsLoaded != null) { idsLoaded.addAll(associationIds); 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 8a920fa87..4c00833a2 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 @@ -1,9 +1,13 @@ package org.alliancegenome.curation_api.services.associations; 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.associations.SequenceTargetingReagentGeneAssociationDAO; import org.alliancegenome.curation_api.dao.associations.alleleAssociations.AlleleGeneAssociationDAO; import org.alliancegenome.curation_api.enums.BackendBulkDataProvider; @@ -24,31 +28,15 @@ import jakarta.transaction.Transactional; @RequestScoped -public class SequenceTargetingReagentGeneAssociationService extends - BaseAssociationDTOCrudService { +public class SequenceTargetingReagentGeneAssociationService { + @Inject SequenceTargetingReagentGeneAssociationDAO sequenceTargetingReagentGeneAssociationDAO; @Inject SequenceTargetingReagentGeneAssociationFmsDTOValidator sequenceTargetingReagentGeneAssociationFmsDTOValidator; - @Override - @PostConstruct - protected void init() { - setSQLDao(sequenceTargetingReagentGeneAssociationDAO); - } - @Transactional - public SequenceTargetingReagentGeneAssociation upsert(SequenceTargetingReagentFmsDTO dto, - BackendBulkDataProvider dataProvider) throws ObjectUpdateException { - // TODO: fix this placeholder code - SequenceTargetingReagentGeneAssociation sequenceTargetingReagentGeneAssociation = new SequenceTargetingReagentGeneAssociation(); - return sequenceTargetingReagentGeneAssociation; - } - - // TODO: rename? - @Transactional - public List addGeneAssociations(SequenceTargetingReagentFmsDTO dto, BackendBulkDataProvider dataProvider) - throws ObjectUpdateException { + public List loadGeneAssociations(SequenceTargetingReagentFmsDTO dto, BackendBulkDataProvider dataProvider) throws ObjectUpdateException { List associations = sequenceTargetingReagentGeneAssociationFmsDTOValidator .validateSQTRGeneAssociationFmsDTO(dto, dataProvider); @@ -102,4 +90,12 @@ private void addAssociationToGene(SequenceTargetingReagentGeneAssociation associ } } + + public List getIdsByDataProvider(String dataProvider) { + Map params = new HashMap<>(); + params.put(EntityFieldConstants.DATA_PROVIDER, dataProvider); + List ids = sequenceTargetingReagentGeneAssociationDAO.findIdsByParams(params); + ids.removeIf(Objects::isNull); + return ids; + } } 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 74ff2f979..1997b6f97 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 @@ -31,8 +31,7 @@ public List validateSQTRGeneAssociation ObjectResponse sqtrResponse = new ObjectResponse<>(); SequenceTargetingReagent sqtr; - SearchResponse sqtrSearchResponse = sqtrDAO.findByField("modEntityId", - dto.getPrimaryId()); + SearchResponse sqtrSearchResponse = sqtrDAO.findByField("modEntityId", dto.getPrimaryId()); if (sqtrSearchResponse == null || sqtrSearchResponse.getSingleResult() == null) { sqtrResponse.addErrorMessage("modEntityId", @@ -51,22 +50,25 @@ public List validateSQTRGeneAssociation relation = relationSearchResponse.getSingleResult(); } - 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(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()); } diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/SequenceTargetingReagentFmsDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/SequenceTargetingReagentFmsDTOValidator.java index 37684191e..55cdec3ba 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/SequenceTargetingReagentFmsDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/SequenceTargetingReagentFmsDTOValidator.java @@ -1,16 +1,10 @@ package org.alliancegenome.curation_api.services.validation.dto.fms; -import java.util.ArrayList; -import java.util.List; - import org.alliancegenome.curation_api.constants.ValidationConstants; import org.alliancegenome.curation_api.dao.SequenceTargetingReagentDAO; import org.alliancegenome.curation_api.enums.BackendBulkDataProvider; import org.alliancegenome.curation_api.exceptions.ObjectValidationException; -import org.alliancegenome.curation_api.model.entities.Gene; import org.alliancegenome.curation_api.model.entities.SequenceTargetingReagent; -import org.alliancegenome.curation_api.model.entities.VocabularyTerm; -import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation; import org.alliancegenome.curation_api.model.entities.ontology.NCBITaxonTerm; import org.alliancegenome.curation_api.model.ingest.dto.fms.SequenceTargetingReagentFmsDTO; import org.alliancegenome.curation_api.response.ObjectResponse;