Skip to content

fix: user metadata was persisted empty in the database #2165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import android.content.ContentValues
import android.content.Context
import android.net.Uri
import androidx.test.core.app.ApplicationProvider
import com.amplifyframework.storage.ObjectMetadata
import java.io.File
import java.sql.Date
import java.time.Instant
import java.util.UUID
import org.junit.After
import org.junit.Assert
Expand Down Expand Up @@ -91,6 +94,40 @@ open class TransferDBTest {
} ?: Assert.fail("InsertedRecord is null")
}

@Test
fun generateContentValuesForMultiPartUploadWithMetadata() {
val key = UUID.randomUUID().toString()
val expectedHttpExpiresDate = Date.from(Instant.now())
val expectedExpirationDate = Date.from(Instant.EPOCH)
val restoreExpirationTime = Date.from(Instant.EPOCH)
val contentValues = arrayOfNulls<ContentValues>(1)
contentValues[0] = transferDB.generateContentValuesForMultiPartUpload(
key,
bucketName,
key,
tempFile,
0L,
0,
null,
1L,
0,
ObjectMetadata(
userMetadata = mapOf("key1" to "value1"),
metaData = mutableMapOf("key1" to "value1"),
httpExpiresDate = expectedHttpExpiresDate,
expirationTime = expectedExpirationDate,
expirationTimeRuleId = "ruleId",
ongoingRestore = false,
restoreExpirationTime = restoreExpirationTime
),
null
)
val uri = transferDB.bulkInsertTransferRecords(contentValues)
transferDB.getTransferRecordById(uri).run {
assertEquals(mapOf("key1" to "value1"), this?.userMetadata)
}
}

@Test
fun testMultiPartDelete() {
val key = UUID.randomUUID().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,19 +749,26 @@ internal class TransferDB private constructor(context: Context) {
val values = ContentValues()
metadata?.let {
values.apply {
TransferTable.COLUMN_USER_METADATA to JsonUtils.mapToString(it.userMetadata)
TransferTable.COLUMN_HEADER_CONTENT_TYPE to it.metaData[ObjectMetadata.CONTENT_TYPE].toString()
TransferTable.COLUMN_HEADER_CONTENT_ENCODING to it.metaData[ObjectMetadata.CONTENT_ENCODING].toString()
TransferTable.COLUMN_HEADER_CACHE_CONTROL to it.metaData[ObjectMetadata.CACHE_CONTROL].toString()
TransferTable.COLUMN_CONTENT_MD5 to it.metaData[ObjectMetadata.CONTENT_MD5].toString()
TransferTable.COLUMN_HEADER_CONTENT_DISPOSITION to
put(TransferTable.COLUMN_USER_METADATA, JsonUtils.mapToString(it.userMetadata))
put(TransferTable.COLUMN_HEADER_CONTENT_TYPE, it.metaData[ObjectMetadata.CONTENT_TYPE].toString())
put(
TransferTable.COLUMN_HEADER_CONTENT_ENCODING,
it.metaData[ObjectMetadata.CONTENT_ENCODING].toString()
)
put(TransferTable.COLUMN_HEADER_CACHE_CONTROL, it.metaData[ObjectMetadata.CACHE_CONTROL].toString())
put(TransferTable.COLUMN_CONTENT_MD5, it.metaData[ObjectMetadata.CONTENT_MD5].toString())
put(
TransferTable.COLUMN_HEADER_CONTENT_DISPOSITION,
it.metaData[ObjectMetadata.CONTENT_DISPOSITION].toString()
TransferTable.COLUMN_SSE_ALGORITHM to it.metaData[ObjectMetadata.SERVER_SIDE_ENCRYPTION].toString()
TransferTable.COLUMN_SSE_KMS_KEY to
)
put(TransferTable.COLUMN_SSE_ALGORITHM, it.metaData[ObjectMetadata.SERVER_SIDE_ENCRYPTION].toString())
put(
TransferTable.COLUMN_SSE_KMS_KEY,
it.metaData[ObjectMetadata.SERVER_SIDE_ENCRYPTION_KMS_KEY_ID].toString()
TransferTable.COLUMN_EXPIRATION_TIME_RULE_ID to it.expirationTimeRuleId
TransferTable.COLUMN_HTTP_EXPIRES_DATE to it.httpExpiresDate?.time.toString()
TransferTable.COLUMN_HEADER_STORAGE_CLASS to it.metaData[ObjectMetadata.STORAGE_CLASS].toString()
)
put(TransferTable.COLUMN_EXPIRATION_TIME_RULE_ID, it.expirationTimeRuleId)
put(TransferTable.COLUMN_HTTP_EXPIRES_DATE, it.httpExpiresDate?.time)
put(TransferTable.COLUMN_HEADER_STORAGE_CLASS, it.metaData[ObjectMetadata.STORAGE_CLASS].toString())
}
}
return values
Expand Down