All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.holunda.camunda.taskpool.cockpit.rest.impl.CockpitTasksController.kt Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
package io.holunda.camunda.taskpool.cockpit.rest.impl

import io.holunda.camunda.taskpool.cockpit.rest.Rest
import io.holunda.camunda.taskpool.cockpit.rest.mapper.TaskEventMapper
import io.holunda.camunda.taskpool.cockpit.rest.model.TaskEventDto
import io.holunda.camunda.taskpool.cockpit.service.QueryTaskEvents
import io.holunda.camunda.taskpool.cockpit.service.TaskEventWithMetaData
import mu.KLogging
import org.axonframework.messaging.responsetypes.ResponseTypes
import org.axonframework.queryhandling.QueryGateway
import org.axonframework.queryhandling.SubscriptionQueryResult
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Flux

/**
 * Task event controller.
 */
@RestController
@RequestMapping(path = [Rest.PATH])
class CockpitTasksController(
  private val queryGateway: QueryGateway,
  private val mapper: TaskEventMapper
) {

  companion object : KLogging()

  /**
   * Retrieves all task events.
   */
  @GetMapping(path = ["/task-events"], produces = [MediaType.TEXT_EVENT_STREAM_VALUE, MediaType.APPLICATION_JSON_VALUE])
  fun getEventTasks(): Flux {

    val taskEvents: SubscriptionQueryResult, TaskEventWithMetaData> = queryGateway.subscriptionQuery(
      QueryTaskEvents(),
      ResponseTypes.multipleInstancesOf(TaskEventWithMetaData::class.java),
      ResponseTypes.instanceOf(TaskEventWithMetaData::class.java)
    )

    return taskEvents.initialResult().flatMapMany { Flux.fromIterable(it) }
      .concatWith(taskEvents.updates())
      .map {
        mapper.dto(it)
      }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy