Last active
May 10, 2023 17:40
-
-
Save thomasmartin-whoz/9f08864747e42e366ea3642b67387f40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.JsonNode | |
import com.fasterxml.jackson.databind.ObjectMapper | |
import com.fasterxml.jackson.databind.node.ArrayNode | |
import com.fasterxml.jackson.databind.node.ObjectNode | |
import mu.KLogging | |
import org.springframework.stereotype.Service | |
import org.springframework.web.reactive.function.client.WebClient | |
import org.springframework.web.reactive.function.client.bodyToMono | |
import org.springframework.web.server.ServerWebExchange | |
import reactor.core.publisher.Mono | |
@Service | |
class V6TalentTransformer( | |
val objectMapper: ObjectMapper, | |
val webClient: WebClient | |
) : VersionTransformer { | |
override fun sourceVersionNumber(): ApiVersion = ApiVersion.V6 | |
override fun accept(exchange: ServerWebExchange): Boolean = exchange.request.uri.path.startsWith("/api/talent") | |
override fun transformRequestObjectNodeReactive(requestBody: ObjectNode): Mono<ObjectNode> { | |
return webClient | |
.get() | |
.uri("lb://microservicename/api/workspace/${requestBody.get(WORKSPACE_ID).asText()}") | |
.retrieve() | |
.bodyToMono<ObjectNode>() | |
.map { workspace -> | |
requestBody.set<JsonNode>(FEDERATION_ID, objectMapper.valueToTree(workspace.get(FEDERATION_ID).asText())) | |
requestBody | |
} | |
} | |
companion object : KLogging() { | |
const val WORKSPACE_ID = "workspaceId" | |
const val FEDERATION_ID = "federationId" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment