Skip to content

Commit

Permalink
[LEIP-280] Support date in upload path
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Oct 2, 2024
1 parent ee8de52 commit 63eb369
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/main/kotlin/de/cyface/uploader/DefaultUploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ 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 de.cyface.uploader.model.metadata.GeoLocation
import org.slf4j.LoggerFactory
import java.io.BufferedInputStream
import java.io.BufferedReader
Expand Down Expand Up @@ -81,7 +82,7 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
): Result {
val measurementId = uploadable.identifier.measurementIdentifier
val deviceId = uploadable.identifier.deviceIdentifier.toString()
val endpoint = measurementsEndpoint(deviceId, measurementId)
val endpoint = measurementsEndpoint(deviceId, measurementId, uploadable.measurementMetaData.startLocation)
return uploadFile(jwtToken, uploadable, file, endpoint, progressListener)
}

Expand All @@ -94,15 +95,15 @@ class DefaultUploader(private val apiEndpoint: String) : Uploader {
): Result {
val measurementId = uploadable.identifier.measurementIdentifier
val deviceId = uploadable.identifier.deviceIdentifier.toString()
val endpoint = attachmentsEndpoint(deviceId, measurementId)
val endpoint = attachmentsEndpoint(deviceId, measurementId, uploadable.measurementMetaData.startLocation)
return uploadFile(jwtToken, uploadable, file, endpoint, progressListener)
}

override fun measurementsEndpoint(deviceId: String, measurementId: Long): URL {
override fun measurementsEndpoint(deviceId: String, measurementId: Long, startLocation: GeoLocation?): URL {
return URL(returnUrlWithTrailingSlash(apiEndpoint) + "measurements")
}

override fun attachmentsEndpoint(deviceId: String, measurementId: Long): URL {
override fun attachmentsEndpoint(deviceId: String, measurementId: Long, startLocation: GeoLocation?): URL {
return URL(returnUrlWithTrailingSlash(apiEndpoint) + "measurements/$deviceId/$measurementId/attachments")
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/kotlin/de/cyface/uploader/Uploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import de.cyface.uploader.exception.UploadFailed
import de.cyface.uploader.model.Attachment
import de.cyface.uploader.model.Measurement
import de.cyface.uploader.model.Uploadable
import de.cyface.uploader.model.metadata.GeoLocation
import java.io.File
import java.net.MalformedURLException
import java.net.URL
Expand Down Expand Up @@ -74,20 +75,26 @@ interface Uploader {
): Result

/**
* Determines the URL endpoint for uploading 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 startLocation The first location of the measurement or `null` if non exists.
* @return The URL endpoint used for uploading measurement files.
* @throws MalformedURLException if the endpoint address is malformed.
*/
@Throws(MalformedURLException::class)
fun measurementsEndpoint(deviceId: String, measurementId: Long): URL
fun measurementsEndpoint(deviceId: String, measurementId: Long, startLocation: GeoLocation?): 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 startLocation The first location of the measurement or `null` if non exists.
* @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(deviceId: String, measurementId: Long, startLocation: GeoLocation?): URL
}
2 changes: 1 addition & 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

0 comments on commit 63eb369

Please sign in to comment.