add logcall in Helper.kt

This commit is contained in:
2024-11-30 18:43:29 +01:00
parent a8f1a4d38b
commit ff78cc7b39
4 changed files with 15 additions and 19 deletions

View File

@@ -3,7 +3,7 @@ package ltd.hlaeja.service
import java.util.UUID
import ltd.hlaeja.library.deviceConfiguration.Node
import ltd.hlaeja.property.DeviceConfigurationProperty
import mu.KotlinLogging
import ltd.hlaeja.util.logCall
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.NO_CONTENT
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
@@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBodyOrNull
import org.springframework.web.server.ResponseStatusException
private val log = KotlinLogging.logger {}
@Service
class DeviceConfigurationService(
private val webClient: WebClient,
@@ -27,8 +25,4 @@ class DeviceConfigurationService(
.retrieve()
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) }
.awaitBodyOrNull<Node.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)
private fun logCall(url: String) {
log.debug("calling: {}", url)
}
}

View File

@@ -3,7 +3,7 @@ package ltd.hlaeja.service
import java.util.UUID
import ltd.hlaeja.library.deviceData.MeasurementData
import ltd.hlaeja.property.DeviceDataProperty
import mu.KotlinLogging
import ltd.hlaeja.util.logCall
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.NO_CONTENT
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
@@ -13,8 +13,6 @@ import org.springframework.web.reactive.function.client.awaitBodilessEntity
import org.springframework.web.reactive.function.client.awaitBodyOrNull
import org.springframework.web.server.ResponseStatusException
private val log = KotlinLogging.logger {}
@Service
class DeviceDataService(
private val webClient: WebClient,
@@ -25,8 +23,7 @@ class DeviceDataService(
client: UUID,
node: UUID,
): MeasurementData.Response = webClient.get()
.uri("${deviceDataProperty.url}/client-$client/node-$node")
.also { log.debug("{}/client-{}/node-{}", deviceDataProperty.url, client, node) }
.uri("${deviceDataProperty.url}/client-$client/node-$node".also(::logCall))
.retrieve()
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NO_CONTENT) }
.awaitBodyOrNull<MeasurementData.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)
@@ -35,8 +32,7 @@ class DeviceDataService(
client: UUID,
request: MeasurementData.Request,
) = webClient.post()
.uri("${deviceDataProperty.url}/client-$client")
.also { log.debug("{}/client-{}", deviceDataProperty.url, client) }
.uri("${deviceDataProperty.url}/client-$client".also(::logCall))
.bodyValue(request)
.retrieve()
.awaitBodilessEntity()

View File

@@ -3,7 +3,7 @@ package ltd.hlaeja.service
import java.util.UUID
import ltd.hlaeja.library.deviceRegistry.Identity
import ltd.hlaeja.property.DeviceRegistryProperty
import mu.KotlinLogging
import ltd.hlaeja.util.logCall
import org.springframework.http.HttpStatus.NOT_ACCEPTABLE
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
@@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.awaitBodyOrNull
import org.springframework.web.server.ResponseStatusException
private val log = KotlinLogging.logger {}
@Service
class DeviceRegistryService(
private val webClient: WebClient,
@@ -23,8 +21,7 @@ class DeviceRegistryService(
suspend fun getIdentityFromDevice(
device: UUID,
): Identity.Response = webClient.get()
.uri("${deviceRegistryProperty.url}/identity/device-$device")
.also { log.debug("{}/node/device-{}", deviceRegistryProperty.url, device) }
.uri("${deviceRegistryProperty.url}/identity/device-$device".also(::logCall))
.retrieve()
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NOT_ACCEPTABLE) }
.awaitBodyOrNull<Identity.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)

View File

@@ -0,0 +1,9 @@
package ltd.hlaeja.util
import mu.KotlinLogging
private val log = KotlinLogging.logger {}
fun logCall(url: String) {
log.debug("calling: {}", url)
}