From aebdeb1f09263eb706ff77ffa87523ed1fb0210d Mon Sep 17 00:00:00 2001 From: Connor Barker Date: Wed, 22 Jan 2025 11:04:45 -0500 Subject: [PATCH] [JN-1580] null-safe instants on enrollee import (#1399) --- .../pearl/core/service/export/EnrolleeImportService.java | 8 +++++--- pepper-import/scripts/translate.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bio/terra/pearl/core/service/export/EnrolleeImportService.java b/core/src/main/java/bio/terra/pearl/core/service/export/EnrolleeImportService.java index dae83d834..9a64029bb 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/export/EnrolleeImportService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/export/EnrolleeImportService.java @@ -284,7 +284,9 @@ public List importAccount(AccountImportData accountData, String port importItems.add(createImportItemFromEnrollee(accountEnrollee, importId)); } } catch (Exception e) { - importItems.add(createFailedImportItem(importId, e.getMessage(), Arrays.toString(e.getStackTrace()), adminId)); + String message = "%s: %s".formatted(e.getClass().getSimpleName(), e.getMessage()); + + importItems.add(createFailedImportItem(importId, message, Arrays.toString(e.getStackTrace()), adminId)); if (!accountData.getProxyData().isEmpty()) { log.warn("failed to import primary enrollee, skipping proxy import for username: {}", accountData.getEmail()); } @@ -600,7 +602,7 @@ private ParticipantTask findTask(PortalParticipantUser ppUser, StudyEnvironment .orElse(null); } else { if (completedAt.isEmpty()) { - throw new IllegalStateException("completedAt must be specified for importing survey response history"); + throw new IllegalStateException("Failed importing %s: completedAt must be specified for importing survey response history".formatted(formatter.getModuleName())); } // case 2: completedAt is specified, find task with that completion time relatedTask = participantTaskService.findTaskForActivityWithCompletionTime(ppUser.getId(), studyEnv.getId(), formatter.getModuleName(), completedAt.get()) @@ -640,7 +642,7 @@ private void shiftTime(SurveyResponse surveyResponse, ParticipantTask relatedTas private Optional parseSurveyFieldToInstant(SurveyFormatter formatter, Map enrolleeMap, Integer repeatNum, String field, ZoneId zoneId) { String key = formatter.formatColumnKey(repeatNum, field); if (enrolleeMap.containsKey(key)) { - return Optional.of(ExportFormatUtils.importInstant(enrolleeMap.get(key), zoneId == null ? ZoneId.of("America/New_York") : zoneId)); + return Optional.ofNullable(ExportFormatUtils.importInstant(enrolleeMap.get(key), zoneId == null ? ZoneId.of("America/New_York") : zoneId)); } return Optional.empty(); } diff --git a/pepper-import/scripts/translate.py b/pepper-import/scripts/translate.py index acf760887..46e952683 100644 --- a/pepper-import/scripts/translate.py +++ b/pepper-import/scripts/translate.py @@ -265,6 +265,7 @@ def parse_juniper_data_dict(filepath: str) -> list[DataDefinition]: while len(simple_questions) > 0: question = simple_questions.pop(0) + # subquestion; handled when we encounter the parent question if question.stable_id.endswith('[0]'): continue