From d89d142963ca0e8833deb0b6613455044fb93688 Mon Sep 17 00:00:00 2001 From: Armin Date: Mon, 24 Jun 2024 14:51:49 +0200 Subject: [PATCH] Fix build --- .../de/cyface/uploader/DefaultUploader.kt | 2 +- .../uploader/RequestInitializeHandler.kt | 43 ++++++++-------- .../kotlin/de/cyface/uploader/Uploader.kt | 4 +- .../de/cyface/uploader/DefaultUploaderTest.kt | 51 +++++++++++-------- 4 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/de/cyface/uploader/DefaultUploader.kt b/src/main/kotlin/de/cyface/uploader/DefaultUploader.kt index 4d91159..a8d2051 100644 --- a/src/main/kotlin/de/cyface/uploader/DefaultUploader.kt +++ b/src/main/kotlin/de/cyface/uploader/DefaultUploader.kt @@ -405,7 +405,7 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader { * @return The meta data as `HttpContent`. */ fun preRequestBody(metaData: RequestMetaData): - Map { + Map { val attributes: MutableMap = HashMap() // Location meta data diff --git a/src/main/kotlin/de/cyface/uploader/RequestInitializeHandler.kt b/src/main/kotlin/de/cyface/uploader/RequestInitializeHandler.kt index 9863e98..4a6abbd 100644 --- a/src/main/kotlin/de/cyface/uploader/RequestInitializeHandler.kt +++ b/src/main/kotlin/de/cyface/uploader/RequestInitializeHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 Cyface GmbH + * Copyright 2021-2024 Cyface GmbH * * This file is part of the Cyface Uploader. * @@ -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( + private val metaData: RequestMetaData, private val jwtBearer: String ) : HttpRequestInitializer { @Throws(IOException::class) @@ -49,32 +47,35 @@ class RequestInitializeHandler( request.headers = headers } - private fun addMetaData(metaData: RequestMetaData, headers: HttpHeaders) { + private fun addMetaData( + metaData: RequestMetaData, + 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 } } diff --git a/src/main/kotlin/de/cyface/uploader/Uploader.kt b/src/main/kotlin/de/cyface/uploader/Uploader.kt index effbd2f..4fd7f2f 100644 --- a/src/main/kotlin/de/cyface/uploader/Uploader.kt +++ b/src/main/kotlin/de/cyface/uploader/Uploader.kt @@ -45,7 +45,7 @@ interface Uploader { @Throws(UploadFailed::class) fun uploadMeasurement( jwtToken: String, - metaData: RequestMetaData, + metaData: RequestMetaData, file: File, progressListener: UploadProgressListener ): Result @@ -65,7 +65,7 @@ interface Uploader { @Throws(UploadFailed::class) fun uploadAttachment( jwtToken: String, - metaData: RequestMetaData, + metaData: RequestMetaData, file: File, fileName: String, progressListener: UploadProgressListener, diff --git a/src/test/kotlin/de/cyface/uploader/DefaultUploaderTest.kt b/src/test/kotlin/de/cyface/uploader/DefaultUploaderTest.kt index 516911f..a5f068c 100644 --- a/src/test/kotlin/de/cyface/uploader/DefaultUploaderTest.kt +++ b/src/test/kotlin/de/cyface/uploader/DefaultUploaderTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 Cyface GmbH + * Copyright 2018-2024 Cyface GmbH * * This file is part of the Cyface Uploader. * @@ -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 @@ -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 { /** @@ -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