Skip to content

Commit

Permalink
Merge branch 'release/1.2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanzilske committed Jun 15, 2022
2 parents 346a55a + 21c5036 commit 2f59d6f
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 75 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
## Camunda BPM Data

[![stable](https://img.shields.io/badge/lifecycle-STABLE-green.svg)](https://github.com/holisticon#open-source-lifecycle)
[![Build Status](https://github.com/holunda-io/camunda-bpm-data/workflows/default/badge.svg)](https://github.com/holunda-io/camunda-bpm-data/actions)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.holunda.data/camunda-bpm-data/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.holunda.data/camunda-bpm-data)
[![CodeCov](https://codecov.io/gh/holunda-io/camunda-bpm-data/branch/master/graph/badge.svg)](https://codecov.io/gh/holunda-io/camunda-bpm-data)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/02d238f71a8243cb96fd2fe322a710eb)](https://www.codacy.com/gh/holunda-io/camunda-bpm-data/dashboard?utm_source=github.com&utm_medium=referral&utm_content=holunda-io/camunda-bpm-data&utm_campaign=Badge_Grade)
[![Changes](https://img.shields.io/badge/CHANGES---yellow)](https://www.holunda.io/camunda-bpm-data/changelog)
[![gitter](https://badges.gitter.im/holunda-io/camunda-bpm-data.svg)](https://gitter.im/holunda-io/camunda-bpm-data?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

## Camunda BPM Data

> Beautiful process data handling for Camunda BPM.
> Beautiful process data handling for Camunda Platform 7.
## Why to use this library in every Camunda project

If you are a software engineer and run process automation projects in your company or on behalf of the customer
based on Camunda Process Engine, you probably are familiar with process variables. Camunda offers an API to access
them and thereby manipulate the state of the process execution - one of the core features during process automation.

Unfortunately, as a user of the Camunda API, you have to exactly know the variable type (so the Java class behind it).
Unfortunately, as a user of the Camunda Platform 7 API, you have to exactly know the variable type (so the Java class behind it).
For example, if you store a String in a variable `"orderId"` you must extract it as a String in every piece of code.
Since there is no code connection between the different code parts, but the BPMN process model orchestrates
these snippets to a single process execution, it makes refactoring and testing of process automation projects
error-prone and challenging.

This library helps you to overcome these difficulties and make access, manipulation and testing process variables really
easy and convenient. We leverage the Camunda API and offer you not only a better API but also some [additional features](https://www.holunda.io/camunda-bpm-data/wiki/user-guide/features).
easy and convenient. We leverage the Camunda Platform 7 API and offer you not only a better API but also some [additional features](https://www.holunda.io/camunda-bpm-data/snapshot/user-guide/features.html).

If you want to read more about data in Camunda processes, have a look on those articles:

Expand All @@ -40,20 +41,20 @@ If you just want to start using the library, put the following dependency into y
<dependency>
<groupId>io.holunda.data</groupId>
<artifactId>camunda-bpm-data</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</dependency>
```

If you are using Gradle Kotlin DSL add to your `build.gradle.kts`:

``` kotlin
implementation("io.holunda.data:camunda-bpm-data:1.2.5")
implementation("io.holunda.data:camunda-bpm-data:1.2.6")
```

For Gradle Groovy DSL add to your `build.gradle`:

``` groovy
implementation 'io.holunda.data:camunda-bpm-data:1.2.5'
implementation 'io.holunda.data:camunda-bpm-data:1.2.6'
```
### Variable declaration
Now your setup is completed, and you can declare your variables like this:
Expand Down Expand Up @@ -139,7 +140,7 @@ Please put the following dependency into your `pom.xml`:
<dependency>
<groupId>io.holunda.data</groupId>
<artifactId>camunda-bpm-data-test</artifactId>
<version>1.2.2</version>
<version>1.2.6</version>
<scope>test</scope>
</dependency>
```
Expand Down Expand Up @@ -191,23 +192,23 @@ public class ApproveOrderTaskControllerTest {

### Further documentation

For further details, please consult our [Quick Start](https://www.holunda.io/camunda-bpm-data/quick-start)
guide or have a look to our primary documentation - [the User Guide](https://www.holunda.io/camunda-bpm-data/wiki/user-guide)
For further details, please consult our [Quick Start](https://www.holunda.io/camunda-bpm-data/snapshot/quick-start)
guide or have a look to our primary documentation: [User Guide](https://www.holunda.io/camunda-bpm-data/snapshot/user-guide/motivation.html)

## Working Example

We prepared some typical usage scenarios and implemented two example projects in Java and Kotlin.
See our [Examples](https://www.holunda.io/camunda-bpm-data/wiki/user-guide/examples) section for usage and configuration.
See our [Examples](https://www.holunda.io/camunda-bpm-data/snapshot/user-guide/examples.html) section for usage and configuration.

## License

[![Apache License 2](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.holunda.io/camunda-bpm-data/license)
[![Apache License 2](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)

This library is developed under Apache 2.0 License.

## Contribution

If you want to contribute to this project, feel free to do so. Start with [Contributing guide](http://holunda.io/camunda-bpm-data/wiki/developer-guide/contribution).
If you want to contribute to this project, feel free to do so. Start with [Contributing guide](http://holunda.io/camunda-bpm-data/snapshot/developer-guide/contribution.html).

## Maintainer

Expand Down
2 changes: 1 addition & 1 deletion example/coverage-report-aggregator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data.example</groupId>
<artifactId>camunda-bpm-data-example-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<artifactId>camunda-bpm-data-coverage-report</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion example/example-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data.example</groupId>
<artifactId>camunda-bpm-data-example-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<artifactId>camunda-bpm-data-example-java</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion example/example-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data.example</groupId>
<artifactId>camunda-bpm-data-example-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<artifactId>camunda-bpm-data-example-kotlin</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions example/example-no-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data.example</groupId>
<artifactId>camunda-bpm-data-example-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<artifactId>camunda-bpm-data-example-no-engine</artifactId>
Expand All @@ -32,7 +32,7 @@
<dependency>
<groupId>io.holunda.camunda-api</groupId>
<artifactId>camunda-bpm-engine-api</artifactId>
<version>7.15.0</version>
<version>7.17.0</version>
</dependency>


Expand Down
2 changes: 1 addition & 1 deletion example/itest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data.example</groupId>
<artifactId>camunda-bpm-data-example-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<artifactId>camunda-bpm-data-integration-test</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data</groupId>
<artifactId>camunda-bpm-data-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<groupId>io.holunda.data.example</groupId>
Expand All @@ -15,7 +15,7 @@
<packaging>pom</packaging>

<properties>
<springdoc.version>1.6.7</springdoc.version>
<springdoc.version>1.6.9</springdoc.version>
<jacoco.skip>true</jacoco.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.sources.skip>true</maven.sources.skip>
Expand Down
2 changes: 1 addition & 1 deletion example/spin-type-detector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data.example</groupId>
<artifactId>camunda-bpm-data-example-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<artifactId>camunda-bpm-data-spin-type-detector</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion extension/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.data</groupId>
<artifactId>camunda-bpm-data-parent</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.holunda.camunda.bpm.data.adapter.basic;

import io.holunda.camunda.bpm.data.adapter.ReadAdapter;
import io.holunda.camunda.bpm.data.adapter.VariableNotFoundException;
import org.camunda.bpm.engine.externaltask.LockedExternalTask;

import java.util.Optional;
Expand All @@ -14,24 +13,21 @@
@SuppressWarnings("java:S1192")
public class ReadAdapterLockedExternalTask<T> implements ReadAdapter<T> {

private final LockedExternalTask lockedExternalTask;
private final String variableName;
private final ReadAdapter<T> readAdapter;

public ReadAdapterLockedExternalTask(LockedExternalTask lockedExternalTask, String variableName) {
this.lockedExternalTask = lockedExternalTask;
this.variableName = variableName;
public ReadAdapterLockedExternalTask(LockedExternalTask lockedExternalTask, String variableName, Class<T> clazz) {
readAdapter = new ReadWriteAdapterVariableMap<>(lockedExternalTask.getVariables(), variableName, clazz);
}

@Override
public T get() {
return getOptional().orElseThrow(() -> new VariableNotFoundException("Couldn't find required variable '" + variableName + "'"));
return readAdapter.get();
}

@Override
@SuppressWarnings("unchecked")
public Optional<T> getOptional() {
return (Optional<T>) Optional.ofNullable(lockedExternalTask.getVariables())
.map(it -> it.get(variableName));
return readAdapter.getOptional();
}

@Override
Expand All @@ -46,7 +42,7 @@ public Optional<T> getLocalOptional() {

@Override
public T getOrDefault(T defaultValue) {
return getOptional().orElse(defaultValue);
return readAdapter.getOrDefault(defaultValue);
}

@Override
Expand All @@ -56,7 +52,7 @@ public T getLocalOrDefault(T defaultValue) {

@Override
public T getOrNull() {
return getOptional().orElse(null);
return readAdapter.getOrNull();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ReadAdapter<T> from(CaseService caseService, String caseExecutionId) {

@Override
public ReadAdapter<T> from(LockedExternalTask lockedExternalTask) {
return new ReadAdapterLockedExternalTask<>(lockedExternalTask, name);
return new ReadAdapterLockedExternalTask<>(lockedExternalTask, name, clazz);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static io.holunda.camunda.bpm.data.CamundaBpmData.listVariable;
import static io.holunda.camunda.bpm.data.CamundaBpmData.mapVariable;
import static io.holunda.camunda.bpm.data.CamundaBpmData.setVariable;
import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable;
import static io.holunda.camunda.bpm.data.CamundaBpmData.uuidVariable;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -24,12 +26,14 @@

public class LockedExternalTaskReaderTest {

private static final VariableFactory<String> STRING = stringVariable("myString");
private static final VariableFactory<List<String>> LIST = listVariable("myList", String.class);
private static final VariableFactory<Set<String>> SET = setVariable("mySet", String.class);
private static final VariableFactory<Map<String, String>> MAP = mapVariable("myMap", String.class, String.class);
private static final VariableFactory<String> STRING_VAR = stringVariable("myString");
private static final VariableFactory<UUID> UUID_VAR = uuidVariable("myUuid");
private static final VariableFactory<List<String>> LIST_VAR = listVariable("myList", String.class);
private static final VariableFactory<Set<String>> SET_VAR = setVariable("mySet", String.class);
private static final VariableFactory<Map<String, String>> MAP_VAR = mapVariable("myMap", String.class, String.class);

private final String stringValue = "value";
private final UUID uuidValue = UUID.randomUUID();
private final List<String> listValue = asList("foo", "bar");
private final Set<String> setValue = asHashSet("foo", "bar");
private final Map<String, String> mapValue = Map.of("a", "b", "c", "d");
Expand All @@ -42,66 +46,71 @@ public class LockedExternalTaskReaderTest {
public void setUp() {
when(externalTask.getVariables()).thenReturn(
Variables
.putValue(STRING.getName(), stringValue)
.putValue(LIST.getName(), listValue)
.putValue(SET.getName(), setValue)
.putValue(MAP.getName(), mapValue)
.putValue(STRING_VAR.getName(), stringValue)
.putValue(LIST_VAR.getName(), listValue)
.putValue(SET_VAR.getName(), setValue)
.putValue(MAP_VAR.getName(), mapValue)
.putValue(UUID_VAR.getName(), uuidValue)
);
}

@Test
public void shouldDelegateGet() {
assertThat(reader.get(STRING)).isEqualTo(stringValue);
assertThat(reader.get(LIST)).isEqualTo(listValue);
assertThat(reader.get(SET)).isEqualTo(setValue);
assertThat(reader.get(MAP)).isEqualTo(mapValue);
assertThat(reader.get(STRING_VAR)).isEqualTo(stringValue);
assertThat(reader.get(LIST_VAR)).isEqualTo(listValue);
assertThat(reader.get(SET_VAR)).isEqualTo(setValue);
assertThat(reader.get(MAP_VAR)).isEqualTo(mapValue);
assertThat(reader.get(UUID_VAR)).isEqualTo(uuidValue);
assertThat(reader.get(UUID_VAR)).isInstanceOf(UUID.class);
}

@Test
public void shouldDelegateGetOptional() {
assertThat(reader.getOptional(STRING)).hasValue(stringValue);
assertThat(reader.getOptional(LIST)).hasValue(listValue);
assertThat(reader.getOptional(SET)).hasValue(setValue);
assertThat(reader.getOptional(MAP)).hasValue(mapValue);
assertThat(reader.getOptional(STRING_VAR)).hasValue(stringValue);
assertThat(reader.getOptional(LIST_VAR)).hasValue(listValue);
assertThat(reader.getOptional(SET_VAR)).hasValue(setValue);
assertThat(reader.getOptional(MAP_VAR)).hasValue(mapValue);
assertThat(reader.getOptional(UUID_VAR)).hasValue(uuidValue);
assertThat(reader.getOptional(stringVariable("xxx"))).isEmpty();
}

@Test
public void shouldDelegateGetLocalOptional() {
assertThatThrownBy(() -> reader.getLocalOptional(STRING))
assertThatThrownBy(() -> reader.getLocalOptional(STRING_VAR))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Can't get a local variable on an external task");
}

@Test
public void shouldDelegateGetLocal() {
assertThatThrownBy(() -> reader.getLocal(STRING))
assertThatThrownBy(() -> reader.getLocal(STRING_VAR))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Can't get a local variable on an external task");
}

@Test
public void shouldDelegateGetOrNull() {
assertThat(reader.getOrNull(STRING)).isEqualTo(stringValue);
assertThat(reader.getOrNull(LIST)).isEqualTo(listValue);
assertThat(reader.getOrNull(SET)).isEqualTo(setValue);
assertThat(reader.getOrNull(MAP)).isEqualTo(mapValue);
assertThat(reader.getOrNull(STRING_VAR)).isEqualTo(stringValue);
assertThat(reader.getOrNull(LIST_VAR)).isEqualTo(listValue);
assertThat(reader.getOrNull(SET_VAR)).isEqualTo(setValue);
assertThat(reader.getOrNull(MAP_VAR)).isEqualTo(mapValue);
assertThat(reader.getOrNull(UUID_VAR)).isEqualTo(uuidValue);
assertThat(reader.getOrNull(stringVariable("xxx"))).isNull();
}

@Test
public void shouldDelegateGetLocalOrNull() {
assertThatThrownBy(() -> reader.getLocalOrNull(STRING))
assertThatThrownBy(() -> reader.getLocalOrNull(STRING_VAR))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Can't get a local variable on an external task");
}

@Test
public void shouldDelegateGetOrDefault() {
assertThat(reader.getOrDefault(STRING, "default")).isEqualTo(stringValue);
assertThat(reader.getOrDefault(LIST, asList("a", "b"))).isEqualTo(listValue);
assertThat(reader.getOrDefault(SET, asHashSet("a", "b"))).isEqualTo(setValue);
assertThat(reader.getOrDefault(MAP, Map.of("a", "b", "c", "d"))).isEqualTo(mapValue);
assertThat(reader.getOrDefault(STRING_VAR, "default")).isEqualTo(stringValue);
assertThat(reader.getOrDefault(LIST_VAR, asList("a", "b"))).isEqualTo(listValue);
assertThat(reader.getOrDefault(SET_VAR, asHashSet("a", "b"))).isEqualTo(setValue);
assertThat(reader.getOrDefault(MAP_VAR, Map.of("a", "b", "c", "d"))).isEqualTo(mapValue);

assertThat(reader.getOrDefault(stringVariable("xxx"), "default")).isEqualTo("default");
assertThat(reader.getOrDefault(listVariable("xxx", String.class), asList("a", "b"))).isEqualTo(asList("a", "b"));
Expand All @@ -111,7 +120,7 @@ public void shouldDelegateGetOrDefault() {

@Test
public void shouldDelegateGetLocalOrDefault() {
assertThatThrownBy(() -> reader.getLocalOrDefault(STRING, stringValue))
assertThatThrownBy(() -> reader.getLocalOrDefault(STRING_VAR, stringValue))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Can't get a local variable on an external task");
}
Expand Down
Loading

0 comments on commit 2f59d6f

Please sign in to comment.