Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Jun 24, 2024
1 parent dd6c1b6 commit d89d142
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/de/cyface/uploader/DefaultUploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
* @return The meta data as `HttpContent`.
*/
fun <T : RequestMetaData.MeasurementIdentifier> preRequestBody(metaData: RequestMetaData<T>):
Map<String, String> {
Map<String, String> {
val attributes: MutableMap<String, String> = HashMap()

// Location meta data
Expand Down
43 changes: 22 additions & 21 deletions src/main/kotlin/de/cyface/uploader/RequestInitializeHandler.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 Cyface GmbH
* Copyright 2021-2024 Cyface GmbH
*
* This file is part of the Cyface Uploader.
*
Expand Down Expand Up @@ -28,13 +28,11 @@ import java.io.IOException
* Assembles a request as requested to upload data.
*
* @author Armin Schnabel
* @version 1.0.0
* @since 7.0.0
* @property metaData the `MetaData` used to request the upload permission from the server
* @property jwtBearer the JWT token to authenticate the upload requests
*/
class RequestInitializeHandler(
private val metaData: RequestMetaData,
class RequestInitializeHandler<T : RequestMetaData.MeasurementIdentifier>(
private val metaData: RequestMetaData<T>,
private val jwtBearer: String
) : HttpRequestInitializer {
@Throws(IOException::class)
Expand All @@ -49,32 +47,35 @@ class RequestInitializeHandler(
request.headers = headers
}

private fun addMetaData(metaData: RequestMetaData, headers: HttpHeaders) {
private fun <T : RequestMetaData.MeasurementIdentifier> addMetaData(
metaData: RequestMetaData<T>,
headers: HttpHeaders
) {
// Location meta data
metaData.startLocation?.let { startLocation ->
metaData.measurementMetaData.startLocation?.let { startLocation ->
headers["startLocLat"] = startLocation.latitude.toString()
headers["startLocLon"] = startLocation.longitude.toString()
headers["startLocTS"] = startLocation.timestamp.toString()
}
metaData.endLocation?.let { endLocation ->
metaData.measurementMetaData.endLocation?.let { endLocation ->
headers["endLocLat"] = endLocation.latitude.toString()
headers["endLocLon"] = endLocation.longitude.toString()
headers["endLocTS"] = endLocation.timestamp.toString()
}
headers["locationCount"] = metaData.locationCount.toString()
headers["locationCount"] = metaData.measurementMetaData.locationCount.toString()

// Remaining meta data
headers["deviceId"] = metaData.deviceIdentifier
headers["measurementId"] = java.lang.Long.valueOf(metaData.measurementIdentifier).toString()
headers["deviceType"] = metaData.deviceType
headers["osVersion"] = metaData.operatingSystemVersion
headers["appVersion"] = metaData.applicationVersion
headers["length"] = metaData.length.toString()
headers["modality"] = metaData.modality
headers["formatVersion"] = metaData.formatVersion.toString()
headers["logCount"] = metaData.logCount
headers["imageCount"] = metaData.imageCount
headers["videoCount"] = metaData.videoCount
headers["filesSize"] = metaData.filesSize
headers["deviceId"] = metaData.identifier.deviceId
headers["measurementId"] = java.lang.Long.valueOf(metaData.identifier.measurementId).toString()
headers["deviceType"] = metaData.deviceMetaData.deviceType
headers["osVersion"] = metaData.deviceMetaData.operatingSystemVersion
headers["appVersion"] = metaData.applicationMetaData.applicationVersion
headers["length"] = metaData.measurementMetaData.length.toString()
headers["modality"] = metaData.measurementMetaData.modality
headers["formatVersion"] = metaData.applicationMetaData.formatVersion.toString()
headers["logCount"] = metaData.attachmentMetaData.logCount
headers["imageCount"] = metaData.attachmentMetaData.imageCount
headers["videoCount"] = metaData.attachmentMetaData.videoCount
headers["filesSize"] = metaData.attachmentMetaData.filesSize
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/de/cyface/uploader/Uploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Uploader {
@Throws(UploadFailed::class)
fun uploadMeasurement(
jwtToken: String,
metaData: RequestMetaData,
metaData: RequestMetaData<RequestMetaData.MeasurementIdentifier>,
file: File,
progressListener: UploadProgressListener
): Result
Expand All @@ -65,7 +65,7 @@ interface Uploader {
@Throws(UploadFailed::class)
fun uploadAttachment(
jwtToken: String,
metaData: RequestMetaData,
metaData: RequestMetaData<RequestMetaData.AttachmentIdentifier>,
file: File,
fileName: String,
progressListener: UploadProgressListener,
Expand Down
51 changes: 29 additions & 22 deletions src/test/kotlin/de/cyface/uploader/DefaultUploaderTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 Cyface GmbH
* Copyright 2018-2024 Cyface GmbH
*
* This file is part of the Cyface Uploader.
*
Expand All @@ -20,7 +20,6 @@ package de.cyface.uploader

import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import de.cyface.model.MeasurementIdentifier
import de.cyface.model.Modality
import de.cyface.model.RequestMetaData
import org.junit.jupiter.api.Test
Expand All @@ -29,8 +28,6 @@ import org.junit.jupiter.api.Test
* Tests whether our default implementation of the HTTP protocol works as expected.
*
* @author Armin Schnabel
* @version 2.1.0
* @since 1.0.0
*/
class DefaultUploaderTest {
/**
Expand All @@ -39,25 +36,35 @@ class DefaultUploaderTest {
@Test
fun testPreRequestBody() {
val deviceId = "testDevi-ce00-42b6-a840-1b70d30094b8" // Must be a valid UUID
val id = MeasurementIdentifier(deviceId, 78)
val startLocation = RequestMetaData.GeoLocation(1000000000L, 51.1, 13.1)
val endLocation = RequestMetaData.GeoLocation(1000010000L, 51.2, 13.2)
val measurementId = 78
val startLocation = RequestMetaData.MeasurementMetaData.GeoLocation(1000000000L, 51.1, 13.1)
val endLocation = RequestMetaData.MeasurementMetaData.GeoLocation(1000010000L, 51.2, 13.2)
val metaData = RequestMetaData(
id.deviceIdentifier,
id.measurementIdentifier.toString(),
"test_osVersion",
"test_deviceType",
"test_appVersion",
10.0,
5,
startLocation,
endLocation,
Modality.BICYCLE.databaseIdentifier,
3,
0,
0,
0,
0
RequestMetaData.MeasurementIdentifier(
deviceId,
measurementId.toString(),
),
RequestMetaData.DeviceMetaData(
"test_osVersion",
"test_deviceType",
),
RequestMetaData.ApplicationMetaData(
"test_appVersion",
3,
),
RequestMetaData.MeasurementMetaData(
10.0,
5,
startLocation,
endLocation,
Modality.BICYCLE.databaseIdentifier,
),
RequestMetaData.AttachmentMetaData(
0,
0,
0,
0,
),
)

// Act
Expand Down

0 comments on commit d89d142

Please sign in to comment.