Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #243 from BridgeDigitalHealth/archiving
Browse files Browse the repository at this point in the history
Don't serialize AssessmentResults that implement JsonFileArchivableResult
  • Loading branch information
nategbrown9 authored Dec 1, 2023
2 parents b3d70c9 + 51a0746 commit d05bafa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArchiveFileInfo> = mutableSetOf()
Expand All @@ -44,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)
Expand All @@ -55,9 +56,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 && assessmentResultFilename != null) {
if (assessmentResult is AssessmentResult) {
val assessmentResultFilename = "assessmentResult.json"
Logger.d("Writing result for assessment ${assessmentResult.identifier}")
archiveBuilder.addDataFile(
JsonArchiveFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ class AssessmentArchiverTest {
val archiver = AssessmentArchiver(
assessmentResult = assessmentResult,
jsonCoder = jsonCoder,
bridgeConfig = TestBridgeConfig(),
assessmentResultFilename = resultFileName
bridgeConfig = TestBridgeConfig()
)

val archive = archiver.buildArchive()
Expand Down

0 comments on commit d05bafa

Please sign in to comment.