Skip to content

Commit

Permalink
Added new rest resource for attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
p-wunderlich committed Jul 1, 2024
1 parent 239b164 commit 9ad4081
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 8 deletions.
84 changes: 84 additions & 0 deletions components/tasklist-backend/src/main/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,65 @@ paths:
'404':
description: Task not found.

'/tasks/payload/attribute/names':
parameters:
- $ref: '#/components/parameters/CurrentUserIdParam'
- $ref: '#/components/parameters/FiltersParam'
get:
tags:
- Task
summary: Lists all available attribute names for task payload.
operationId: getTasksAttributeNames
responses:
'200':
description: Successful operation.
content:
application/json:
schema:
title: List of attribute names.
type: array
items:
$ref: '#/components/schemas/TaskAttributeName'
headers:
X-ElementCount:
description: Number of elements in total.
schema:
type: integer
'401':
description: Not authenticated.
'403':
description: Not authorized.

'/tasks/payload/attribute/{attributeName}/values':
parameters:
- $ref: '#/components/parameters/CurrentUserIdParam'
- $ref: '#/components/parameters/AttributeNameParam'
- $ref: '#/components/parameters/FiltersParam'
get:
tags:
- Task
summary: Lists all available attribute values for given attribute name.
operationId: getTasksAttributeValues
responses:
'200':
description: Successful operation.
content:
application/json:
schema:
title: List of attribute values.
type: array
items:
$ref: '#/components/schemas/TaskAttributeValue'
headers:
X-ElementCount:
description: Number of elements in total.
schema:
type: integer
'401':
description: Not authenticated.
'403':
description: Not authorized.

'/business-data-entries':
parameters:
- $ref: '#/components/parameters/CurrentUserIdParam'
Expand Down Expand Up @@ -313,6 +372,14 @@ components:
schema:
type: string

AttributeNameParam:
name: attributeName
in: path
description: Paylpad Attribute Name.
required: true
schema:
type: string

schemas:
TaskWithDataEntries:
type: object
Expand Down Expand Up @@ -554,4 +621,21 @@ components:
type: string
description: username of currently logged-in user.

TaskAttributeName:
type: object
description: Represents a user task.
properties:
name:
type: string
required:
- name


TaskAttributeValue:
type: object
description: Represents a user task.
properties:
value:
type: object
required:
- value
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import io.holunda.camunda.taskpool.api.task.*
import io.holunda.polyflow.example.tasklist.adapter.rest.ElementNotFoundException
import io.holunda.polyflow.example.tasklist.adapter.rest.api.TaskApiDelegate
import io.holunda.polyflow.example.tasklist.adapter.rest.mapper.TaskWithDataEntriesMapper
import io.holunda.polyflow.example.tasklist.adapter.rest.model.TaskAttributeNameDto
import io.holunda.polyflow.example.tasklist.adapter.rest.model.TaskAttributeValueDto
import io.holunda.polyflow.example.tasklist.adapter.rest.model.TaskWithDataEntriesDto
import io.holunda.polyflow.view.Task
import io.holunda.polyflow.view.auth.User
Expand Down Expand Up @@ -147,6 +149,33 @@ class TaskResource(
return ResponseEntity.noContent().build()
}

override fun getTasksAttributeNames(
xCurrentUserID: String,
filters: List<String>?
): ResponseEntity<List<TaskAttributeNameDto>> {
val user = userService.getUser(xCurrentUserID)
val result = taskServiceGateway.getTaskAttributeNames(user,filters ?: listOf())

return ResponseEntity
.ok()
.headers(HttpHeaders().apply { this[HEADER_ELEMENT_COUNT] = result.totalElementCount.toString() })
.body(mapper.mapTaskAttributeNameDto(result.elements))
}

override fun getTasksAttributeValues(
xCurrentUserID: String,
attributeName: String,
filters: List<String>?
): ResponseEntity<List<TaskAttributeValueDto>> {
val user = userService.getUser(xCurrentUserID)
val result = taskServiceGateway.getTaskAttributeValues(attributeName, user,filters ?: listOf())

return ResponseEntity
.ok()
.headers(HttpHeaders().apply { this[HEADER_ELEMENT_COUNT] = result.totalElementCount.toString() })
.body(mapper.mapTaskAttributeValueDto(result.elements))
}

private fun getAuthorizedTask(taskId: String, user: User): Task = taskServiceGateway
.getTask(taskId)
.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import io.holunda.polyflow.example.tasklist.adapter.rest.ElementNotFoundExceptio
import io.holunda.polyflow.view.Task
import io.holunda.polyflow.view.TaskQueryClient
import io.holunda.polyflow.view.auth.User
import io.holunda.polyflow.view.query.task.TaskForIdQuery
import io.holunda.polyflow.view.query.task.TasksWithDataEntriesForUserQuery
import io.holunda.polyflow.view.query.task.TasksWithDataEntriesQueryResult
import io.holunda.polyflow.view.query.task.*
import mu.KLogging
import org.axonframework.commandhandling.gateway.CommandGateway
import org.axonframework.queryhandling.QueryGateway
Expand Down Expand Up @@ -56,4 +54,30 @@ class TaskServiceGateway(
filters = filters
)
).join() ?: throw ElementNotFoundException()

fun getTaskAttributeNames(
user: User,
filters: List<String>
): TaskAttributeNamesQueryResult = taskQueryClient
.query(
TaskAttributeNamesQuery(
user = user,
assignedToMeOnly = false,
filters = filters
)
).join() ?: throw ElementNotFoundException()

fun getTaskAttributeValues(
attributeName: String,
user: User,
filters: List<String>
): TaskAttributeValuesQueryResult = taskQueryClient
.query(
TaskAttributeValuesQuery(
attributeName = attributeName,
user = user,
assignedToMeOnly = false,
filters = filters
)
).join() ?: throw ElementNotFoundException()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.holunda.polyflow.example.tasklist.adapter.rest.mapper

import io.holunda.polyflow.example.tasklist.adapter.rest.model.DataEntryDto
import io.holunda.polyflow.example.tasklist.adapter.rest.model.ProtocolEntryDto
import io.holunda.polyflow.example.tasklist.adapter.rest.model.TaskDto
import io.holunda.polyflow.example.tasklist.adapter.rest.model.TaskWithDataEntriesDto
import io.holunda.polyflow.example.tasklist.adapter.rest.model.*
import io.holunda.polyflow.view.*
import org.mapstruct.*
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -60,6 +57,11 @@ abstract class TaskWithDataEntriesMapper {
)
abstract fun dto(taskWithDataEntries: TaskWithDataEntries): TaskWithDataEntriesDto

fun mapTaskAttributeNameDto(names: List<String>): List<TaskAttributeNameDto> = names.map { TaskAttributeNameDto(it) }

fun mapTaskAttributeValueDto(values: List<Any>): List<TaskAttributeValueDto> = values.map { TaskAttributeValueDto(it) }


fun toOffsetDateTime(@Valid time: Instant?): OffsetDateTime? =
if (time == null) null else OffsetDateTime.ofInstant(time, ZoneOffset.UTC)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


<springboot.version>3.2.6</springboot.version>
<polyflow.version>4.2.0</polyflow.version>
<polyflow.version>4.2.1-SNAPSHOT</polyflow.version>

<camunda-ce.version>7.21.0</camunda-ce.version>
<camunda-ee.version>7.21.0-ee</camunda-ee.version>
Expand Down

0 comments on commit 9ad4081

Please sign in to comment.