From cef53bb7ada6cfeb9159349e2f635b6b8f2494f1 Mon Sep 17 00:00:00 2001 From: Nathaniel Brown Date: Mon, 20 Nov 2023 12:50:58 -0800 Subject: [PATCH 1/3] Don't serialize AssessmentResults that implement JsonFileArchivableResult --- .../bridge/assessmentmodel/upload/AssessmentArchiver.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt index a471fc90d..0b84412c5 100644 --- a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt +++ b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt @@ -57,7 +57,7 @@ class AssessmentArchiver( recursiveAdd(assessmentResult) // Add assessment result file to archive - if (assessmentResult is AssessmentResult && assessmentResultFilename != null) { + if (assessmentResult is AssessmentResult && assessmentResult !is JsonFileArchivableResult && assessmentResultFilename != null) { Logger.d("Writing result for assessment ${assessmentResult.identifier}") archiveBuilder.addDataFile( JsonArchiveFile( From 7151412e7fd6e0987788cf11eb1989761824773b Mon Sep 17 00:00:00 2001 From: Nathaniel Brown Date: Mon, 20 Nov 2023 14:53:31 -0800 Subject: [PATCH 2/3] Just hardcode assessmentResultFilename instead of passing it through. --- .../bridge/assessmentmodel/upload/AssessmentArchiver.kt | 6 ++---- .../upload/AssessmentResultArchiveUploader.kt | 6 ++---- .../bridge/assessmentmodel/upload/AssessmentArchiverTest.kt | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt index 0b84412c5..07f2602a9 100644 --- a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt +++ b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt @@ -34,8 +34,6 @@ class AssessmentArchiver( private val assessmentResult: Result, private val jsonCoder: Json, private val bridgeConfig: BridgeConfig, - // To serialize assessmentResult as part of archive, include a filename for the result. - private val assessmentResultFilename: String? = null // Used when result is of type AssessmentResult ) { private val manifest: MutableSet = mutableSetOf() @@ -55,9 +53,9 @@ class AssessmentArchiver( fun buildArchive() : Archive { // Iterate through all the results within this collection and add if they are `JsonFileArchivableResult`. recursiveAdd(assessmentResult) - // Add assessment result file to archive - if (assessmentResult is AssessmentResult && assessmentResult !is JsonFileArchivableResult && assessmentResultFilename != null) { + if (assessmentResult is AssessmentResult && assessmentResult !is JsonFileArchivableResult) { + val assessmentResultFilename = "assessmentResult.json" Logger.d("Writing result for assessment ${assessmentResult.identifier}") archiveBuilder.addDataFile( JsonArchiveFile( diff --git a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentResultArchiveUploader.kt b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentResultArchiveUploader.kt index 77b34399c..71207400c 100644 --- a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentResultArchiveUploader.kt +++ b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentResultArchiveUploader.kt @@ -43,14 +43,12 @@ class AssessmentResultArchiveUploader( */ fun archiveResultAndQueueUpload(assessmentResult: Result, jsonCoder: Json, - adherenceRecord: AdherenceRecord?, - assessmentResultFilename: String? = "assessmentResult.json") { + adherenceRecord: AdherenceRecord?) { val archiver = AssessmentArchiver( assessmentResult = assessmentResult, jsonCoder = jsonCoder, - bridgeConfig = bridgeConfig, - assessmentResultFilename = assessmentResultFilename + bridgeConfig = bridgeConfig ) val assessmentRunUUID = if (assessmentResult is AssessmentResult && assessmentResult.runUUIDString.isNotEmpty()) { diff --git a/assessmentmodel-sdk/src/test/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiverTest.kt b/assessmentmodel-sdk/src/test/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiverTest.kt index eaeb5f884..bddd6cdc1 100644 --- a/assessmentmodel-sdk/src/test/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiverTest.kt +++ b/assessmentmodel-sdk/src/test/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiverTest.kt @@ -161,8 +161,7 @@ class AssessmentArchiverTest { val archiver = AssessmentArchiver( assessmentResult = assessmentResult, jsonCoder = jsonCoder, - bridgeConfig = TestBridgeConfig(), - assessmentResultFilename = resultFileName + bridgeConfig = TestBridgeConfig() ) val archive = archiver.buildArchive() From 51a07466d3b97f1b12e49190e90c40a2cb1b5f21 Mon Sep 17 00:00:00 2001 From: Nathaniel Brown Date: Tue, 21 Nov 2023 13:19:47 -0800 Subject: [PATCH 3/3] Throw error if result doesn't implement AssessmentResult or JsonFileArchivableResult. --- .../bridge/assessmentmodel/upload/AssessmentArchiver.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt index 07f2602a9..73b507b81 100644 --- a/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt +++ b/assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentArchiver.kt @@ -42,6 +42,9 @@ class AssessmentArchiver( private var answersSchema: SimpleJsonSchema init { + if (assessmentResult !is AssessmentResult && assessmentResult !is JsonFileArchivableResult) { + throw IllegalArgumentException("Result must implement either AssessmentResult or JsonFileArchivableResult") + } val appVersion = "version ${bridgeConfig.appVersionName}, build ${bridgeConfig.appVersion}" val item = assessmentResult.identifier archiveBuilder = Archive.Builder.forActivity(item) @@ -54,7 +57,7 @@ class AssessmentArchiver( // Iterate through all the results within this collection and add if they are `JsonFileArchivableResult`. recursiveAdd(assessmentResult) // Add assessment result file to archive - if (assessmentResult is AssessmentResult && assessmentResult !is JsonFileArchivableResult) { + if (assessmentResult is AssessmentResult) { val assessmentResultFilename = "assessmentResult.json" Logger.d("Writing result for assessment ${assessmentResult.identifier}") archiveBuilder.addDataFile(