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 #73 from Sage-Bionetworks/v3-upload-metadata-android
Browse files Browse the repository at this point in the history
V3 upload metadata android
  • Loading branch information
nategbrown9 authored Sep 24, 2021
2 parents 747ae86 + 468df09 commit 3c716c1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -90,7 +93,13 @@ abstract class AssessmentResultArchiveUploader(
assessmentResult.runUUIDString
}

val uploadFile = persist(assessmentRunUUID, builder.build(), sessionWindowExpiration)
val uploadMetadata: Map<String, JsonElement> = 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)
}
Expand All @@ -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<String, JsonElement>, sessionWindowExpiration: kotlinx.datetime.Instant?): UploadFile {
val encryptor = AndroidStudyUploadEncryptor(getPublicKey())

val md5: MessageDigest = try {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class UploadFile (
val fileLength: Long,
val md5Hash: String,
val encrypted: Boolean = true,
val metadata: Map<kotlin.String, kotlinx.serialization.json.JsonElement>? = null,
val sessionExpires: Instant? = null // Delay doing upload until after session expires
) {

Expand All @@ -29,6 +30,7 @@ data class UploadFile (
contentMd5 = md5Hash,
contentType = contentType,
encrypted = encrypted,
metadata = metadata,
type = "UploadRequest"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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<kotlin.String, kotlinx.serialization.json.JsonElement>? = 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,
Expand Down

0 comments on commit 3c716c1

Please sign in to comment.