From ce4f6ae1cb510716c113077eb9dc668d818849ce Mon Sep 17 00:00:00 2001 From: Nathaniel Brown Date: Thu, 23 Sep 2021 10:06:53 -0700 Subject: [PATCH 1/2] V3 upload metadata android --- .../upload/AssessmentResultArchiveUploader.kt | 24 ++++++++++++++----- .../bridge/kmm/shared/upload/UploadFile.kt | 2 ++ .../bridge/kmm/shared/models/UploadRequest.kt | 10 +++++--- 3 files changed, 27 insertions(+), 9 deletions(-) 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 83652dd72..bcc55a73c 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 @@ -8,6 +8,8 @@ import android.os.Build import android.util.Log import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonPrimitive import org.joda.time.DateTime import org.joda.time.DateTimeZone import org.joda.time.Instant @@ -51,6 +53,7 @@ abstract class AssessmentResultArchiveUploader( fun archiveResultAndQueueUpload(assessmentResult: AssessmentResult, jsonCoder: Json, assessmentInstanceId: String, + eventTimestamp: String, sessionWindowExpiration: kotlinx.datetime.Instant? = null) { if (assessmentResult.schemaIdentifier == null) { Log.e( @@ -90,7 +93,13 @@ abstract class AssessmentResultArchiveUploader( assessmentResult.runUUIDString } - val uploadFile = persist(assessmentRunUUID, builder.build(), sessionWindowExpiration) + val uploadMetadata: Map = mapOf( + "instanceGuid" to JsonPrimitive(assessmentInstanceId), + "eventTimeStamp" to JsonPrimitive(eventTimestamp) + ) + + + val uploadFile = persist(assessmentRunUUID, builder.build(), uploadMetadata, sessionWindowExpiration) Log.i("Archiver", "UploadFile $uploadFile") uploadRequester.queueAndRequestUpload(context, uploadFile, assessmentInstanceId) } @@ -100,7 +109,7 @@ abstract class AssessmentResultArchiveUploader( CMSException::class, NoSuchAlgorithmException::class ) - fun persist(filename: String, archive: Archive, sessionWindowExpiration: kotlinx.datetime.Instant?): UploadFile { + fun persist(filename: String, archive: Archive, uploadMetadata: Map, sessionWindowExpiration: kotlinx.datetime.Instant?): UploadFile { val encryptor = AndroidStudyUploadEncryptor(getPublicKey()) val md5: MessageDigest = try { @@ -131,10 +140,13 @@ abstract class AssessmentResultArchiveUploader( } return UploadFile( - filePath, - CONTENT_TYPE_DATA_ARCHIVE, - size, - digestEnc + filePath = filePath, + contentType = CONTENT_TYPE_DATA_ARCHIVE, + fileLength = size, + md5Hash = digestEnc, + encrypted = true, + metadata = uploadMetadata, + sessionExpires = sessionWindowExpiration ) } catch (e: CMSException) { diff --git a/bridge-client/src/androidMain/kotlin/org/sagebionetworks/bridge/kmm/shared/upload/UploadFile.kt b/bridge-client/src/androidMain/kotlin/org/sagebionetworks/bridge/kmm/shared/upload/UploadFile.kt index dcb865770..28f8da3ff 100644 --- a/bridge-client/src/androidMain/kotlin/org/sagebionetworks/bridge/kmm/shared/upload/UploadFile.kt +++ b/bridge-client/src/androidMain/kotlin/org/sagebionetworks/bridge/kmm/shared/upload/UploadFile.kt @@ -11,6 +11,7 @@ data class UploadFile ( val fileLength: Long, val md5Hash: String, val encrypted: Boolean = true, + val metadata: Map? = null, val sessionExpires: Instant? = null // Delay doing upload until after session expires ) { @@ -29,6 +30,7 @@ data class UploadFile ( contentMd5 = md5Hash, contentType = contentType, encrypted = encrypted, + metadata = metadata, type = "UploadRequest" ) } diff --git a/bridge-client/src/commonMain/kotlin/org/sagebionetworks/bridge/kmm/shared/models/UploadRequest.kt b/bridge-client/src/commonMain/kotlin/org/sagebionetworks/bridge/kmm/shared/models/UploadRequest.kt index 1e0644294..bc9c62a41 100644 --- a/bridge-client/src/commonMain/kotlin/org/sagebionetworks/bridge/kmm/shared/models/UploadRequest.kt +++ b/bridge-client/src/commonMain/kotlin/org/sagebionetworks/bridge/kmm/shared/models/UploadRequest.kt @@ -16,12 +16,13 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.SerialName /** - * **Important: Headers of the same values must be used when doing the upload against the pre-signed URL.** + * **Important: Headers of the same values must be used when doing the upload against the pre-signed URL.** * @param name File name - * @param contentLength The size of the object in bytes. A standard HTTP header. For more information, go to [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13) + * @param contentLength The size of the object in bytes. A standard HTTP header. For more information, go to [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13) * @param contentMd5 The base64-encoded, 128-bit MD5 digest of the object body. - * @param contentType A standard MIME type. For more information, go to [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17) + * @param contentType A standard MIME type. For more information, go to [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17) * @param encrypted True if the upload is encrypted. False if it is not encrypted. If not specified, defaults to true. + * @param metadata JSON map with key value pairs representing metadata for this upload, as submitted by the app. This corresponds with the uploadMetadataFieldDefinitions configured in the app. * @param zipped True if the upload is zipped. False if it is a single file. If not specified, defaults to true. * @param type UploadRequest */ @@ -42,6 +43,9 @@ internal data class UploadRequest ( /* True if the upload is encrypted. False if it is not encrypted. If not specified, defaults to true. */ @SerialName("encrypted") val encrypted: kotlin.Boolean? = null, + /* JSON map with key value pairs representing metadata for this upload, as submitted by the app. This corresponds with the uploadMetadataFieldDefinitions configured in the app. */ + @SerialName("metadata") + val metadata: kotlin.collections.Map? = null, /* True if the upload is zipped. False if it is a single file. If not specified, defaults to true. */ @SerialName("zipped") val zipped: kotlin.Boolean? = null, From 468df094349acdd5060d7e9cc0fc66bccbd42fe4 Mon Sep 17 00:00:00 2001 From: nategbrown9 <43688326+nategbrown9@users.noreply.github.com> Date: Thu, 23 Sep 2021 16:08:24 -0700 Subject: [PATCH 2/2] Update assessmentmodel-sdk/src/main/java/org/sagebionetworks/bridge/assessmentmodel/upload/AssessmentResultArchiveUploader.kt Co-authored-by: Erin-Mounts --- .../assessmentmodel/upload/AssessmentResultArchiveUploader.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bcc55a73c..5579c450a 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 @@ -95,7 +95,7 @@ abstract class AssessmentResultArchiveUploader( val uploadMetadata: Map = mapOf( "instanceGuid" to JsonPrimitive(assessmentInstanceId), - "eventTimeStamp" to JsonPrimitive(eventTimestamp) + "eventTimestamp" to JsonPrimitive(eventTimestamp) )