From 155985af6fca7ee156ee3de387615ad5f378623b Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 4 Jun 2024 16:05:41 +0200 Subject: [PATCH 1/5] Upgrade dependencies as the upload paths changed in there --- build.gradle | 4 ++-- .../de/cyface/app/digural/upload/WebdavUploader.kt | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 1272536f..06502756 100644 --- a/build.gradle +++ b/build.gradle @@ -62,8 +62,8 @@ ext { // (!) Match versions `android-app`, `SDK` and `camera-service`. // When `android-app` is checkout out, `rootProject.uploaderVersion` in the submodules will point // to `android-app/build.gradle` instead of `submodule/build.gradle`. - cyfaceSerializationVersion = "3.2.0" - cyfaceUploaderVersion = "1.3.0" + cyfaceSerializationVersion = "3.4.0-alpha2" // FIXME + cyfaceUploaderVersion = "1.4.0-alpha2" // FIXME // These versions just document the currently linked version of this dependency. // To upgrade the dependencies you need to update the submodules to a newer commit. cyfaceAndroidBackendVersion = "7.12.0" diff --git a/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt b/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt index 7bcc3139..dc29ceb6 100644 --- a/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt +++ b/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt @@ -97,12 +97,13 @@ class WebdavUploader( override fun uploadAttachment( jwtToken: String, metaData: RequestMetaData, - measurementId: Long, file: File, fileName: String, progressListener: UploadProgressListener ): Result { - val endpoint = attachmentsEndpoint(measurementId) + val measurementId = metaData.measurementIdentifier.toLong() + val deviceId = metaData.deviceIdentifier + val endpoint = attachmentsEndpoint(deviceId, measurementId) val result = uploadFile(metaData, file, fileName, endpoint, progressListener) if (result != Result.UPLOAD_FAILED) { progressListener.updatedProgress(1.0f) // the whole file is uploaded @@ -114,7 +115,10 @@ class WebdavUploader( return URL(measurementsDirectory()) } - override fun attachmentsEndpoint(measurementId: Long): URL { + override fun attachmentsEndpoint(deviceId: String, measurementId: Long): URL { + // For Webdav we use another directory structure than in the Collector API, here we use: + // /files//devices//measurements//attachments + // But the API uses /measurements///attachments return URL(attachmentsDirectory(measurementId)) } From cfcc8d24e32a2e1e77442b1c8ef6c8e6007e9480 Mon Sep 17 00:00:00 2001 From: Armin Date: Mon, 24 Jun 2024 15:46:09 +0200 Subject: [PATCH 2/5] Upgrade dependencies with generic RequestMetaData --- build.gradle | 4 +- .../app/digural/upload/WebdavUploader.kt | 50 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index 06502756..6e1da866 100644 --- a/build.gradle +++ b/build.gradle @@ -62,8 +62,8 @@ ext { // (!) Match versions `android-app`, `SDK` and `camera-service`. // When `android-app` is checkout out, `rootProject.uploaderVersion` in the submodules will point // to `android-app/build.gradle` instead of `submodule/build.gradle`. - cyfaceSerializationVersion = "3.4.0-alpha2" // FIXME - cyfaceUploaderVersion = "1.4.0-alpha2" // FIXME + cyfaceSerializationVersion = "4.0.0-alpha2" // FIXME + cyfaceUploaderVersion = "1.4.0-alpha3" // FIXME // These versions just document the currently linked version of this dependency. // To upgrade the dependencies you need to update the submodules to a newer commit. cyfaceAndroidBackendVersion = "7.12.0" diff --git a/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt b/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt index dc29ceb6..62bc34a6 100644 --- a/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt +++ b/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt @@ -82,11 +82,11 @@ class WebdavUploader( @Suppress("unused", "CyclomaticComplexMethod", "LongMethod") // Part of the API override fun uploadMeasurement( jwtToken: String, - metaData: RequestMetaData, + metaData: RequestMetaData, file: File, progressListener: UploadProgressListener ): Result { - val endpoint = URL(measurementDirectory(metaData.measurementIdentifier.toLong())) + val endpoint = URL(measurementDirectory(metaData.identifier.measurementId.toLong())) val result = uploadFile(metaData, file, MEASUREMENT_FILE_FILENAME, endpoint, progressListener) if (result != Result.UPLOAD_FAILED) { progressListener.updatedProgress(1.0f) // the whole file is uploaded @@ -96,13 +96,13 @@ class WebdavUploader( override fun uploadAttachment( jwtToken: String, - metaData: RequestMetaData, + metaData: RequestMetaData, file: File, fileName: String, progressListener: UploadProgressListener ): Result { - val measurementId = metaData.measurementIdentifier.toLong() - val deviceId = metaData.deviceIdentifier + val measurementId = metaData.identifier.measurementId.toLong() + val deviceId = metaData.identifier.deviceId val endpoint = attachmentsEndpoint(deviceId, measurementId) val result = uploadFile(metaData, file, fileName, endpoint, progressListener) if (result != Result.UPLOAD_FAILED) { @@ -144,8 +144,8 @@ class WebdavUploader( } @Throws(UploadFailed::class) - private fun uploadFile( - metaData: RequestMetaData, + private fun uploadFile( + metaData: RequestMetaData, file: File, fileName: String, endpoint: URL, @@ -169,7 +169,7 @@ class WebdavUploader( // `Authenticating for response: Response{protocol=http/1.1, code=401, message=Unauthorized,` val isMeasurementUpload = fileName == MEASUREMENT_FILE_FILENAME - val measurementId = metaData.measurementIdentifier.toLong() + val measurementId = metaData.identifier.measurementId.toLong() ensureDirectoriesExist(isMeasurementUpload, measurementId) // File uploads @@ -374,35 +374,37 @@ class WebdavUploader( * @param metaData The metadata to convert. * @return The meta data as `Map`. */ - fun preRequestBody(metaData: RequestMetaData): Map { + fun preRequestBody( + metaData: RequestMetaData, + ): Map { val attributes: MutableMap = HashMap() // Location meta data - metaData.startLocation?.let { startLocation -> + metaData.measurementMetaData.startLocation?.let { startLocation -> attributes["startLocLat"] = startLocation.latitude.toString() attributes["startLocLon"] = startLocation.longitude.toString() attributes["startLocTS"] = startLocation.timestamp.toString() } - metaData.endLocation?.let { endLocation -> + metaData.measurementMetaData.endLocation?.let { endLocation -> attributes["endLocLat"] = endLocation.latitude.toString() attributes["endLocLon"] = endLocation.longitude.toString() attributes["endLocTS"] = endLocation.timestamp.toString() } - attributes["locationCount"] = metaData.locationCount.toString() + attributes["locationCount"] = metaData.measurementMetaData.locationCount.toString() // Remaining meta data - attributes["deviceId"] = metaData.deviceIdentifier - attributes["measurementId"] = metaData.measurementIdentifier - attributes["deviceType"] = metaData.deviceType - attributes["osVersion"] = metaData.operatingSystemVersion - attributes["appVersion"] = metaData.applicationVersion - attributes["length"] = metaData.length.toString() - attributes["modality"] = metaData.modality - attributes["formatVersion"] = metaData.formatVersion.toString() - attributes["logCount"] = metaData.logCount.toString() - attributes["imageCount"] = metaData.imageCount.toString() - attributes["videoCount"] = metaData.videoCount.toString() - attributes["filesSize"] = metaData.filesSize.toString() + attributes["deviceId"] = metaData.identifier.deviceId + attributes["measurementId"] = metaData.identifier.measurementId + attributes["deviceType"] = metaData.deviceMetaData.deviceType + attributes["osVersion"] = metaData.deviceMetaData.operatingSystemVersion + attributes["appVersion"] = metaData.applicationMetaData.applicationVersion + attributes["length"] = metaData.measurementMetaData.length.toString() + attributes["modality"] = metaData.measurementMetaData.modality + attributes["formatVersion"] = metaData.applicationMetaData.formatVersion.toString() + attributes["logCount"] = metaData.attachmentMetaData.logCount.toString() + attributes["imageCount"] = metaData.attachmentMetaData.imageCount.toString() + attributes["videoCount"] = metaData.attachmentMetaData.videoCount.toString() + attributes["filesSize"] = metaData.attachmentMetaData.filesSize.toString() return attributes } } From 855bc72e6e8e7ea05544111352be1ab156cd8588 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 16 Jul 2024 10:12:14 +0200 Subject: [PATCH 3/5] Upgrade SDK to 7.12.1 --- backend | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend b/backend index fece2976..ee4f211e 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit fece29764e06f81e5ee9ee9e456440e4934baec3 +Subproject commit ee4f211ee8e80436e8e055d6be45ced83b63e78f diff --git a/build.gradle b/build.gradle index 6e1da866..7243ac51 100644 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ ext { cyfaceUploaderVersion = "1.4.0-alpha3" // FIXME // These versions just document the currently linked version of this dependency. // To upgrade the dependencies you need to update the submodules to a newer commit. - cyfaceAndroidBackendVersion = "7.12.0" + cyfaceAndroidBackendVersion = "7.12.1" cyfaceEnergySettingsVersion = "4.0.6" cyfaceCameraServiceVersion = "4.5.7" From 122fa4e88da83b149edd9319791698ec2cc352f6 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 16 Jul 2024 10:12:33 +0200 Subject: [PATCH 4/5] Upgrade camera-service to 4.5.8 --- build.gradle | 2 +- camera_service | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 7243ac51..405a7609 100644 --- a/build.gradle +++ b/build.gradle @@ -68,7 +68,7 @@ ext { // To upgrade the dependencies you need to update the submodules to a newer commit. cyfaceAndroidBackendVersion = "7.12.1" cyfaceEnergySettingsVersion = "4.0.6" - cyfaceCameraServiceVersion = "4.5.7" + cyfaceCameraServiceVersion = "4.5.8" // Android SDK versions minSdkVersion = 21 // device support diff --git a/camera_service b/camera_service index 388b6f48..3369eb74 160000 --- a/camera_service +++ b/camera_service @@ -1 +1 @@ -Subproject commit 388b6f4864c87e60f4f1d8d5fff4e03e8b8900ff +Subproject commit 3369eb746eb6a963d6da25dd2e13e57e5e0e8767 From eeb9518b08a8b962680ab0c9c1c6f1e956d4e707 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 16 Jul 2024 10:13:45 +0200 Subject: [PATCH 5/5] Upgrade uploader to 1.4.1, serialization to 3.4.0 --- build.gradle | 4 +- .../app/digural/upload/WebdavUploader.kt | 83 ++++++------------- 2 files changed, 29 insertions(+), 58 deletions(-) diff --git a/build.gradle b/build.gradle index 405a7609..72a56017 100644 --- a/build.gradle +++ b/build.gradle @@ -62,8 +62,8 @@ ext { // (!) Match versions `android-app`, `SDK` and `camera-service`. // When `android-app` is checkout out, `rootProject.uploaderVersion` in the submodules will point // to `android-app/build.gradle` instead of `submodule/build.gradle`. - cyfaceSerializationVersion = "4.0.0-alpha2" // FIXME - cyfaceUploaderVersion = "1.4.0-alpha3" // FIXME + cyfaceSerializationVersion = "3.4.0" + cyfaceUploaderVersion = "1.4.1" // These versions just document the currently linked version of this dependency. // To upgrade the dependencies you need to update the submodules to a newer commit. cyfaceAndroidBackendVersion = "7.12.1" diff --git a/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt b/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt index 62bc34a6..03128dd4 100644 --- a/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt +++ b/ui/digural/src/main/kotlin/de/cyface/app/digural/upload/WebdavUploader.kt @@ -24,7 +24,6 @@ import com.thegrizzlylabs.sardineandroid.impl.OkHttpSardine import de.cyface.app.digural.MainActivity.Companion.TAG import de.cyface.model.Json import de.cyface.model.Json.JsonObject -import de.cyface.model.RequestMetaData import de.cyface.uploader.Result import de.cyface.uploader.UploadProgressListener import de.cyface.uploader.Uploader @@ -44,6 +43,9 @@ import de.cyface.uploader.exception.UnauthorizedException import de.cyface.uploader.exception.UnexpectedResponseCode import de.cyface.uploader.exception.UploadFailed import de.cyface.uploader.exception.UploadSessionExpired +import de.cyface.uploader.model.Attachment +import de.cyface.uploader.model.Measurement +import de.cyface.uploader.model.Uploadable import java.io.File import java.io.IOException import java.io.InterruptedIOException @@ -58,8 +60,6 @@ import javax.net.ssl.SSLException * To use this interface just call [WebdavUploader.uploadMeasurement] or [WebdavUploader.uploadAttachment]. * * @author Armin Schnabel - * @version 1.0.0 - * @since 3.8.0 * @property apiEndpoint An API endpoint running a Webdav data collector service, like `https://some.url/api/v3` */ class WebdavUploader( @@ -82,12 +82,18 @@ class WebdavUploader( @Suppress("unused", "CyclomaticComplexMethod", "LongMethod") // Part of the API override fun uploadMeasurement( jwtToken: String, - metaData: RequestMetaData, + uploadable: Measurement, file: File, progressListener: UploadProgressListener ): Result { - val endpoint = URL(measurementDirectory(metaData.identifier.measurementId.toLong())) - val result = uploadFile(metaData, file, MEASUREMENT_FILE_FILENAME, endpoint, progressListener) + val endpoint = URL(measurementDirectory(uploadable.identifier.measurementIdentifier)) + val result = uploadFile( + uploadable, + uploadable.identifier.measurementIdentifier, + file, + MEASUREMENT_FILE_FILENAME, + endpoint, + ) if (result != Result.UPLOAD_FAILED) { progressListener.updatedProgress(1.0f) // the whole file is uploaded } @@ -96,15 +102,21 @@ class WebdavUploader( override fun uploadAttachment( jwtToken: String, - metaData: RequestMetaData, + uploadable: Attachment, file: File, fileName: String, progressListener: UploadProgressListener ): Result { - val measurementId = metaData.identifier.measurementId.toLong() - val deviceId = metaData.identifier.deviceId + val measurementId = uploadable.identifier.measurementIdentifier + val deviceId = uploadable.identifier.deviceIdentifier.toString() val endpoint = attachmentsEndpoint(deviceId, measurementId) - val result = uploadFile(metaData, file, fileName, endpoint, progressListener) + val result = uploadFile( + uploadable, + uploadable.identifier.measurementIdentifier, + file, + fileName, + endpoint + ) if (result != Result.UPLOAD_FAILED) { progressListener.updatedProgress(1.0f) // the whole file is uploaded } @@ -144,12 +156,12 @@ class WebdavUploader( } @Throws(UploadFailed::class) - private fun uploadFile( - metaData: RequestMetaData, + private fun uploadFile( + uploadable: Uploadable, + measurementId: Long, file: File, fileName: String, - endpoint: URL, - progressListener: UploadProgressListener + endpoint: URL ): Result { return try { // TODO: the sardine library has PRs which support input streams but they are not merged @@ -169,7 +181,6 @@ class WebdavUploader( // `Authenticating for response: Response{protocol=http/1.1, code=401, message=Unauthorized,` val isMeasurementUpload = fileName == MEASUREMENT_FILE_FILENAME - val measurementId = metaData.identifier.measurementId.toLong() ensureDirectoriesExist(isMeasurementUpload, measurementId) // File uploads @@ -179,7 +190,7 @@ class WebdavUploader( val metaDataUri = "$uploadDir/meta.json" if (!sardine.exists(metaDataUri)) { Log.d(TAG, "upload meta data") - val metaDataMap = preRequestBody(metaData) + val metaDataMap = uploadable.toMap() val metaDataJson = JsonObject.Builder() metaDataMap.keys.forEach { metaDataJson.add(Json.jsonKeyValue(it, metaDataMap.getValue(it))) @@ -367,45 +378,5 @@ class WebdavUploader( "$url/" } } - - /** - * Assembles a `Map` which contains the metadata. - * - * @param metaData The metadata to convert. - * @return The meta data as `Map`. - */ - fun preRequestBody( - metaData: RequestMetaData, - ): Map { - val attributes: MutableMap = HashMap() - - // Location meta data - metaData.measurementMetaData.startLocation?.let { startLocation -> - attributes["startLocLat"] = startLocation.latitude.toString() - attributes["startLocLon"] = startLocation.longitude.toString() - attributes["startLocTS"] = startLocation.timestamp.toString() - } - metaData.measurementMetaData.endLocation?.let { endLocation -> - attributes["endLocLat"] = endLocation.latitude.toString() - attributes["endLocLon"] = endLocation.longitude.toString() - attributes["endLocTS"] = endLocation.timestamp.toString() - } - attributes["locationCount"] = metaData.measurementMetaData.locationCount.toString() - - // Remaining meta data - attributes["deviceId"] = metaData.identifier.deviceId - attributes["measurementId"] = metaData.identifier.measurementId - attributes["deviceType"] = metaData.deviceMetaData.deviceType - attributes["osVersion"] = metaData.deviceMetaData.operatingSystemVersion - attributes["appVersion"] = metaData.applicationMetaData.applicationVersion - attributes["length"] = metaData.measurementMetaData.length.toString() - attributes["modality"] = metaData.measurementMetaData.modality - attributes["formatVersion"] = metaData.applicationMetaData.formatVersion.toString() - attributes["logCount"] = metaData.attachmentMetaData.logCount.toString() - attributes["imageCount"] = metaData.attachmentMetaData.imageCount.toString() - attributes["videoCount"] = metaData.attachmentMetaData.videoCount.toString() - attributes["filesSize"] = metaData.attachmentMetaData.filesSize.toString() - return attributes - } } }