Skip to content

Commit

Permalink
[LEIP-272] Support d/mid/date in upload paths
Browse files Browse the repository at this point in the history
Task/leip 272 upload specification
  • Loading branch information
hb0 authored Oct 23, 2024
2 parents e6b929b + 862fe78 commit bd56316
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/main/kotlin/de/cyface/uploader/DefaultUploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
file: File,
progressListener: UploadProgressListener
): Result {
val endpoint = measurementsEndpoint()
val endpoint = measurementsEndpoint(uploadable)
return uploadFile(jwtToken, uploadable, file, endpoint, progressListener)
}

Expand All @@ -90,17 +90,17 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
fileName: String,
progressListener: UploadProgressListener,
): Result {
val measurementId = uploadable.identifier.measurementIdentifier
val deviceId = uploadable.identifier.deviceIdentifier.toString()
val endpoint = attachmentsEndpoint(deviceId, measurementId)
val endpoint = attachmentsEndpoint(uploadable)
return uploadFile(jwtToken, uploadable, file, endpoint, progressListener)
}

override fun measurementsEndpoint(): URL {
override fun measurementsEndpoint(uploadable: Uploadable): URL {
return URL(returnUrlWithTrailingSlash(apiEndpoint) + "measurements")
}

override fun attachmentsEndpoint(deviceId: String, measurementId: Long): URL {
override fun attachmentsEndpoint(uploadable: Uploadable): URL {
val measurementId = uploadable.measurementId()
val deviceId = uploadable.deviceId()
return URL(returnUrlWithTrailingSlash(apiEndpoint) + "measurements/$deviceId/$measurementId/attachments")
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/kotlin/de/cyface/uploader/Uploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,22 @@ interface Uploader {
): Result

/**
* Determines the URL endpoint for uploading files associated with a specific measurement.
*
* @param uploadable The file to upload.
* @return The URL endpoint used for uploading measurement files.
* @throws MalformedURLException if the endpoint address is malformed.
*/
@Throws(MalformedURLException::class)
fun measurementsEndpoint(): URL
fun measurementsEndpoint(uploadable: Uploadable): URL

/**
* Determines the URL endpoint for uploading attachment files associated with a specific measurement.
*
* @param deviceId The ID of the device the measurement is attached to.
* @param measurementId The ID of the measurement the files are attached to.
* @param uploadable The file to upload.
* @return The URL endpoint used for uploading attachment files.
* @throws MalformedURLException if the endpoint address is malformed.
*/
@Throws(MalformedURLException::class)
fun attachmentsEndpoint(deviceId: String, measurementId: Long): URL
fun attachmentsEndpoint(uploadable: Uploadable): URL
}
14 changes: 13 additions & 1 deletion src/main/kotlin/de/cyface/uploader/model/Attachment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class Attachment(
val identifier: AttachmentIdentifier,
private val deviceMetaData: DeviceMetaData,
private val applicationMetaData: ApplicationMetaData,
private val measurementMetaData: MeasurementMetaData,
val measurementMetaData: MeasurementMetaData,
private val attachmentMetaData: AttachmentMetaData,
) : Uploadable {
override fun toMap(): Map<String, String> {
Expand Down Expand Up @@ -66,6 +66,18 @@ data class Attachment(

return map
}

override fun deviceId(): String {
return identifier.deviceIdentifier.toString()
}

override fun measurementId(): Long {
return identifier.measurementIdentifier
}

override fun timestamp(): Long? {
return measurementMetaData.startLocation?.timestamp
}
}

data class AttachmentIdentifier(
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/de/cyface/uploader/model/Measurement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ data class Measurement(

return map
}

override fun deviceId(): String {
return identifier.deviceIdentifier.toString()
}

override fun measurementId(): Long {
return identifier.measurementIdentifier
}

override fun timestamp(): Long? {
return measurementMetaData.startLocation?.timestamp
}
}

data class MeasurementIdentifier(val deviceIdentifier: UUID, val measurementIdentifier: Long)
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/de/cyface/uploader/model/Uploadable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ interface Uploadable {
* Transform this object into a `Map` representation which can be injected into the upload request header.
*/
fun toMap(): Map<String, String>

fun deviceId(): String

fun measurementId(): Long

fun timestamp(): Long?
}

/**
Expand Down

0 comments on commit bd56316

Please sign in to comment.