Skip to content

Instantly share code, notes, and snippets.

View thomasmartin-whoz's full-sized avatar

thomasmartin-whoz

View GitHub Profile
package io.biznet.event.handler
import io.biznet.event.EventHandlerProperties
import io.biznet.event.IdentifiedApplicationEvent
import mu.KLogging
import org.springframework.context.ApplicationListener
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.core.publisher.Sinks
import reactor.core.scheduler.Scheduler
override fun transformRequestObjectNodeReactive(
requestBody: ObjectNode
): Mono<ObjectNode> {
return if (requestBody.get("periods").isArray) {
val periods = (requestBody.get("periods") as ArrayNode).elements().asSequence().joinToString(",")
webClient
.get()
.uri("http://localhost/periods?code=${periods}")
.retrieve()
.bodyToMono<ArrayNode>()
override fun transformRequestObjectNode(
requestBody: ObjectNode
): ObjectNode = requestBody.renameProperty("era","periods")
override fun transformResponseObjectNode(
responseBody: ObjectNode
): ObjectNode = responseBody.renameProperty("periods","era")
override fun transformRequestQueryParam(
queryParams: MultiValueMap<String, String>
override fun transformRequestObjectNode(requestBody: ObjectNode): ObjectNode {
val eras = objectMapper.createArrayNode()
if (requestBody["era"].isNotNull()) {
val era = requestBody["era"] as ObjectNode
eras.add(era)
}
requestBody.remove("era")
requestBody.set<ArrayNode>("era", eras)
return requestBody
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
interface VersionTransformer {
fun sourceVersionNumber(): ApiVersion
fun accept(exchange: ServerWebExchange): Boolean
fun transformRequestQueryParam(queryParams: MultiValueMap<String, String>): MultiValueMap<String, String> = queryParams
fun transformResponseObjectNode(responseBody: ObjectNode): ObjectNode = responseBody
interface VersionTransformer {
fun sourceVersionNumber(): ApiVersion
fun accept(exchange: ServerWebExchange): Boolean
fun transformRequestQueryParam(queryParams: MultiValueMap<String, String>): MultiValueMap<String, String> = queryParams
fun transformResponseObjectNode(responseBody: ObjectNode): ObjectNode
@Repository
class PersonRepositoryImpl implements PersonRepositoryCustom {
@Autowired
MongoTemplate mongoTemplate
@Override
List<Person> findByIdsOrFirstNameOrLastName(List<String> personIds, String firstName, String lastName){
List<Person> listPersons(PersonListCommand command) {
return personRepository.findByIdsOrFirstNameOrLastName(command.personIds,command.firstName, command.lastName)
}
List<Person> listPersons(PersonListCommand command) {
List<Person> persons
if (command.personIds && command.firstName && command.lastName) {
persons = personRepository.findByIdInAndFirstNameAndLastName(command.personIds, command.firstName, command.lastName)
} else if (command.personIds && command.firstName) {
persons = personRepository.findByIdInAndFirstName(command.personIds, command.firstName)
} else if (command.personIds && command.lastName) {