From b90e4d5bf7710475f0d3475d1adc8b1161442c46 Mon Sep 17 00:00:00 2001 From: ao508 <15623749+ao508@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:45:33 -0400 Subject: [PATCH] TEMPO additional logging (#1142) Added extra logging to help with debugging. Additonal logs also report whether a cohort attempts to import with samples that are unknown to SMILE. The cohort is still imported but incompletely. Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> --- .../impl/CohortCompleteServiceImpl.java | 18 ++++++++++++- .../impl/TempoMessageHandlingServiceImpl.java | 26 +++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/service/src/main/java/org/mskcc/smile/service/impl/CohortCompleteServiceImpl.java b/service/src/main/java/org/mskcc/smile/service/impl/CohortCompleteServiceImpl.java index 4ecb8396..7c246180 100644 --- a/service/src/main/java/org/mskcc/smile/service/impl/CohortCompleteServiceImpl.java +++ b/service/src/main/java/org/mskcc/smile/service/impl/CohortCompleteServiceImpl.java @@ -1,8 +1,10 @@ package org.mskcc.smile.service.impl; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.mskcc.smile.commons.JsonComparator; @@ -41,7 +43,8 @@ public class CohortCompleteServiceImpl implements CohortCompleteService { public Cohort saveCohort(Cohort cohort, Set samplePrimaryIds) throws Exception { // persist new cohort complete event to the db cohortCompleteRepository.save(cohort); - // create cohort-smaple relationships + Set unknownSamples = new HashSet<>(); // tracks unknown samples in smile + // create cohort-sample relationships for (String primaryId : samplePrimaryIds) { // confirm sample exists by primary id and then link to cohort if (sampleService.sampleExistsByPrimaryId(primaryId)) { @@ -50,8 +53,21 @@ public Cohort saveCohort(Cohort cohort, Set samplePrimaryIds) throws Exc tempoService.initAndSaveDefaultTempoData(primaryId); } cohortCompleteRepository.addCohortSampleRelationship(cohort.getCohortId(), primaryId); + } else { + unknownSamples.add(primaryId); } } + // log and report unknown samples for reference + if (!unknownSamples.isEmpty()) { + StringBuilder builder = new StringBuilder(); + builder.append("Could not import ") + .append(unknownSamples.size()) + .append(" samnples for cohort ") + .append(cohort.getCohortId()) + .append(": ") + .append(StringUtils.join(unknownSamples,", ")); + LOG.warn(builder.toString()); + } return getCohortByCohortId(cohort.getCohortId()); } diff --git a/service/src/main/java/org/mskcc/smile/service/impl/TempoMessageHandlingServiceImpl.java b/service/src/main/java/org/mskcc/smile/service/impl/TempoMessageHandlingServiceImpl.java index 4dfd52ea..c35930ad 100644 --- a/service/src/main/java/org/mskcc/smile/service/impl/TempoMessageHandlingServiceImpl.java +++ b/service/src/main/java/org/mskcc/smile/service/impl/TempoMessageHandlingServiceImpl.java @@ -35,6 +35,7 @@ import org.mskcc.smile.service.TempoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.stereotype.Component; /** @@ -117,8 +118,13 @@ public void run() { Tempo tempo = tempoService.getTempoDataBySamplePrimaryId(primaryId); if (tempo == null || !tempo.hasBamCompleteEvent(bamComplete)) { - tempoService.mergeBamCompleteEventBySamplePrimaryId(primaryId, + try { + tempoService.mergeBamCompleteEventBySamplePrimaryId(primaryId, bamComplete); + } catch (IncorrectResultSizeDataAccessException e) { + LOG.error("Encountered error while persisting BAM complete " + + "event to database: " + bcEvent.toString(), e); + } } } else { LOG.error("Sample with primary id " + primaryId + " does not exist"); @@ -156,8 +162,13 @@ public void run() { Tempo tempo = tempoService.getTempoDataBySamplePrimaryId(primaryId); if (tempo == null || !tempo.hasQcCompleteEvent(qcComplete)) { - tempoService.mergeQcCompleteEventBySamplePrimaryId(primaryId, - qcComplete); + try { + tempoService.mergeQcCompleteEventBySamplePrimaryId(primaryId, + qcComplete); + } catch (IncorrectResultSizeDataAccessException e) { + LOG.error("Encountered error while persisting QC complete " + + "event to database: " + qcEvent.toString(), e); + } } } else { LOG.error("Sample with primary id: " + primaryId + " does not exist"); @@ -195,8 +206,13 @@ public void run() { Tempo tempo = tempoService.getTempoDataBySamplePrimaryId(primaryId); if (tempo == null || !tempo.hasMafCompleteEvent(mafComplete)) { - tempoService.mergeMafCompleteEventBySamplePrimaryId(primaryId, - mafComplete); + try { + tempoService.mergeMafCompleteEventBySamplePrimaryId(primaryId, + mafComplete); + } catch (IncorrectResultSizeDataAccessException e) { + LOG.error("Encountered error while persisting MAF complete " + + "event to database: " + mcEvent.toString(), e); + } } } else { LOG.error("Sample with primary id " + primaryId + " does not exist");