Oleg Shuliak
10/18/2022, 6:41 AMworkflowService.findByCompanyId
, that returns data class:
data class WorkflowWithStatusLookup(val workflow: Workflow, val status: Result<WorkflowStatus>)
also, I’d like to log the exception based on the “invalid” result of the status. Here is want I’ve came up with, but I’m pretty sure it’s not optimal way
override fun listWorkflow(featureToggles: FeatureToggles): ResponseEntity<GetWorkflowsResponse> {
return runBlocking(requestContext.coroutineContext) {
val (valid, invalid) = workflowService.findByCompanyId(getCompanyId(), featureToggles)
.partition { it.status.isSuccess }
val apiResponseModel = valid.map {
it.workflow.toWorkflowInfoResponse(it.status.getOrThrow())
}
return@runBlocking if (invalid.isEmpty()) {
ResponseEntity(
GetWorkflowsResponse(
data = apiResponseModel
),
HttpStatus.OK
)
} else {
ResponseEntity(
GetWorkflowsResponse(
data = apiResponseModel,
meta = invalid.map { it.workflow.name }
),
HttpStatus.PARTIAL_CONTENT
).also {
invalid.forEach {
throw FormNotFound(
it.workflow.definition.trigger.entityId!!.toString(),
it.workflow.companyId
)
}
}
}
}
}
Ros
10/27/2022, 8:06 AM