Skip to content

Commit

Permalink
Merge branch 'develop' into feature/852-spring-boot-3
Browse files Browse the repository at this point in the history
  • Loading branch information
zambrovski committed Oct 11, 2023
2 parents ac9cc98 + 4443f64 commit 3c3a6dd
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 36 deletions.
13 changes: 2 additions & 11 deletions docs/examples/scenarios/distributed-axon-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,9 @@ Before you begin, please build the entire project with `mvn clean install` from
You will need some backing services (Axon Server, PostgreSQL, MongoDB) and you can easily start them locally
by using the provided `docker-compose.yml` file.

Before you start change the directory to `examples/scenarios/distributed-axon-server` and run a preparation script `.docker/setup.sh`.
You can do it with the following code from your command line (you need to do it once):


```bash
cd examples/scenarios/distributed-axon-server
.docker/setup.sh
```

Before you start change the directory to `examples/scenarios/distributed-axon-server`:
Now, start required containers. The easiest way to do so is to run:


```bash
docker-compose up -d
```
Expand All @@ -61,8 +52,8 @@ packaged application using:


```bash
java -jar process-platform-jpa/target/*.jar
java -jar taskpool-application/target/*.jar
java -jar process-application/target/*.jar
```

## Useful URLs
Expand Down
45 changes: 45 additions & 0 deletions docs/examples/scenarios/distributed-with-kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,48 @@ persistence of the query model.
#### From Kafka to Tasklist API

![Kafka to Tasklist API Messaging](../../img/scenario_kafka_to_tasklist_detail.png)

### System Requirements

* JDK 11
* Docker
* Docker Compose

### Preparations

Before you begin, please build the entire project with `mvn clean install` from the command line in the project root directory.

You will need some backing services (Kafka, PostgreSQL) and you can easily start them locally
by using the provided `docker-compose.yml` file.

Before you start change the directory to `examples/scenarios/distributed-kafka` and start required containers. The easiest way to do so is to run:

```bash
docker-compose up -d
```

### Start

The demo application consists of several Maven modules. In order to start the example, you will need to start only two
of them in the following order:

1. taskpool-application (process platform)
2. process-application (example process application)

The modules can be started by running from command line in the `examples/scenarios/distributed-kafka` directory using Maven or start the
packaged application using:


```bash
java -jar process-application-local-polyflow/target/*.jar
java -jar process-platform-view-only/target/*.jar
```

## Useful URLs

### Process Platform
* [http://localhost:8081/polyflow/tasks](http://localhost:8081/polyflow/tasks)
* [http://localhost:8081/polyflow/archive](http://localhost:8081/polyflow/archive)

### Process Application
* [http://localhost:8080/camunda/app/](http://localhost:8080/camunda/app/)
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ internal class JpaPolyflowViewServiceDataEntryITest {
assertThat(result.payload.elements.map { it.entryId }).containsExactly(id2, id, id4)
}

@Suppress("DEPRECATION")
@Test
fun `sort should be backwards compatible`() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,30 @@ internal class JpaPolyflowViewServiceTaskITest {
assertThat(strawhatsInverse.elements.map { it.task.id }).containsExactly(id4, id3)
}

@Suppress("DEPRECATION")
@Test
fun `should sort with empty string, null or empty list correctly`() {
val sortWithNullQuery = jpaPolyflowViewService.query(AllTasksWithDataEntriesQuery(
sort = null
))

val sortWithEmptyStringQuery =jpaPolyflowViewService.query(AllTasksWithDataEntriesQuery(
sort = ""
))

val sortWithEmptyListQuery =jpaPolyflowViewService.query(AllTasksWithDataEntriesQuery(
sort = listOf()
))

val sortWithSortNotSuppliedQuery = jpaPolyflowViewService.query(AllTasksWithDataEntriesQuery())


assertThat(sortWithNullQuery.elements).isEqualTo(sortWithEmptyStringQuery.elements)
assertThat(sortWithEmptyStringQuery.elements).isEqualTo(sortWithEmptyListQuery.elements)
assertThat(sortWithEmptyListQuery.elements).isEqualTo(sortWithSortNotSuppliedQuery.elements)
assertThat(sortWithSortNotSuppliedQuery.elements).isEqualTo(sortWithNullQuery.elements)
}

@Test
fun `should find the task with data entries and sort by multiple correctly`() {
val query = jpaPolyflowViewService.query(AllTasksWithDataEntriesQuery(
Expand Down Expand Up @@ -324,6 +348,12 @@ internal class JpaPolyflowViewServiceTaskITest {
))
}.message).isEqualTo("Sort must start either with '+' or '-' but it was starting with '*'")

assertThat(assertThrows<IllegalArgumentException> {
jpaPolyflowViewService.query(AllTasksWithDataEntriesQuery(
sort = listOf("")
))
}.message).isEqualTo("Sort parameter must not be blank")

}

@Test
Expand Down
4 changes: 3 additions & 1 deletion view/view-api/src/main/kotlin/query/PageableSortableQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ interface PageableSortableQuery {
if (sort.isEmpty()) {
return
}
sort.forEach {

sort.forEach {
require(it.isNotBlank() && it.isNotEmpty()) { "Sort parameter must not be blank" }
val direction = it.substring(0, 1)
require(
direction == ASCENDING.sign
Expand All @@ -44,4 +45,5 @@ interface PageableSortableQuery {
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ data class DataEntriesForDataEntryTypeQuery(
) : FilterQuery<DataEntry>, PageableSortableQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(entryType: EntryType, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String): this(
constructor(entryType: EntryType, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?) : this(
entryType = entryType,
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
)

override fun applyFilter(element: DataEntry) = element.entryType == this.entryType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ data class DataEntriesForUserQuery(
) : FilterQuery<DataEntry>, PageableSortableQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(user: User, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()): this(
constructor(user: User, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()): this(
user = user,
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

Expand Down
8 changes: 6 additions & 2 deletions view/view-api/src/main/kotlin/query/data/DataEntriesQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ data class DataEntriesQuery(
) : FilterQuery<DataEntry>, PageableSortableQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()): this(
constructor(page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()): this(
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

Expand Down
8 changes: 6 additions & 2 deletions view/view-api/src/main/kotlin/query/task/AllTasksQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ data class AllTasksQuery(
) : PageableSortableFilteredTaskQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()): this(
constructor(page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()): this(
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ data class AllTasksWithDataEntriesQuery(
) : FilterQuery<TaskWithDataEntries>, PageableSortableQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()): this(
constructor(page: Int = 0, size: Int = Int.MAX_VALUE, sort: String? , filters: List<String> = listOf()) : this(
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ data class TasksForCandidateUserAndGroupQuery(
) : PageableSortableFilteredTaskQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(user: User, includeAssigned: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()): this(
constructor(user: User, includeAssigned: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()): this(
user = user,
includeAssigned = includeAssigned,
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ data class TasksForGroupQuery(
) : PageableSortableFilteredTaskQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(user: User, includeAssigned: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()): this(
constructor(user: User, includeAssigned: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()): this(
user = user,
includeAssigned = includeAssigned,
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

Expand Down
16 changes: 12 additions & 4 deletions view/view-api/src/main/kotlin/query/task/TasksForUserQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,33 @@ data class TasksForUserQuery(
) : PageableSortableFilteredTaskQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(user: User, assignedToMeOnly: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()): this(
constructor(user: User, assignedToMeOnly: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()): this(
user = user,
assignedToMeOnly = assignedToMeOnly,
page = page,
size = size,
sort = listOf(sort),
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

/**
* Compatibility constructor for old clients.
*/
@Deprecated(message = "Please use other constructor setting the assignedToMeOnly.")
constructor(user: User, page: Int = 0, size: Int = Int.MAX_VALUE, sort: List<String> = listOf(), filters: List<String> = listOf()): this(
constructor(user: User, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String? = null, filters: List<String> = listOf()): this(
user = user,
assignedToMeOnly = false,
page = page,
size = size,
sort = sort,
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@ data class TasksWithDataEntriesForGroupQuery(
) : FilterQuery<TaskWithDataEntries>, PageableSortableQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(user: User, includeAssigned: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()) : this(
user = user, includeAssigned = includeAssigned, page = page, size = size, sort = listOf(sort), filters = filters
constructor(user: User, includeAssigned: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()) : this(
user = user,
includeAssigned = includeAssigned,
page = page,
size = size,
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

override fun applyFilter(element: TaskWithDataEntries): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,34 @@ data class TasksWithDataEntriesForUserQuery(
) : FilterQuery<TaskWithDataEntries>, PageableSortableQuery {

@Deprecated("Please use other constructor setting sort as List<String>")
constructor(user: User, assignedToMeOnly: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String, filters: List<String> = listOf()) : this(
user = user, assignedToMeOnly = assignedToMeOnly, page = page, size = size, sort = listOf(sort), filters = filters
constructor(user: User, assignedToMeOnly: Boolean = false, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String?, filters: List<String> = listOf()) : this(
user = user,
assignedToMeOnly = assignedToMeOnly,
page = page,
size = size,
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

/**
* Compatibility constructor for old clients.
*/
@Deprecated("Please use other constructor setting the assignedToMeOnly.")
constructor(user: User, page: Int = 0, size: Int = Int.MAX_VALUE, sort: List<String> = listOf(), filters: List<String> = listOf()) : this(
user = user, assignedToMeOnly = false, page = page, size = size, sort = sort, filters = filters
constructor(user: User, page: Int = 0, size: Int = Int.MAX_VALUE, sort: String? = null, filters: List<String> = listOf()) : this(
user = user,
assignedToMeOnly = false,
page = page,
size = size,
sort = if (sort.isNullOrBlank()) {
listOf()
} else {
listOf(sort)
},
filters = filters
)

override fun applyFilter(element: TaskWithDataEntries): Boolean =
Expand Down
18 changes: 18 additions & 0 deletions view/view-api/src/test/kotlin/query/PageableSortableQueryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ internal class PageableSortableQueryTest {
private val badOrdering = listOf("*createTime")
private val user = User(username = "kermit", groups = setOf())


@Test
fun should_sanitize_blank_sort() {

class TestQuery(
override val page: Int,
override val size: Int,
override val sort: List<String>,
) : PageableSortableQuery

assertThat(assertThrows<IllegalArgumentException> { TestQuery(1, 1, listOf("")).sanitizeSort(Task::class) }.message).isEqualTo("Sort parameter must not be blank")
assertThat(assertThrows<IllegalArgumentException> { TestQuery(1, 1, listOf("\t")).sanitizeSort(Task::class) }.message).isEqualTo("Sort parameter must not be blank")
assertThat(assertThrows<IllegalArgumentException> { TestQuery(1, 1, listOf("\t\r\n")).sanitizeSort(Task::class) }.message).isEqualTo("Sort parameter must not be blank")
assertThat(assertThrows<IllegalArgumentException> { TestQuery(1, 1, listOf(" \t")).sanitizeSort(Task::class) }.message).isEqualTo("Sort parameter must not be blank")
assertThat(assertThrows<IllegalArgumentException> { TestQuery(1, 1, listOf(" \n")).sanitizeSort(Task::class) }.message).isEqualTo("Sort parameter must not be blank")
}


@Test
fun should_sanitize_task_query() {
assertThat(AllTasksQuery(sort = createTimeAsc).apply { sanitizeSort(Task::class) }.sort).isEqualTo(createTimeAsc)
Expand Down

0 comments on commit 3c3a6dd

Please sign in to comment.