diff --git a/docs/pom.xml b/docs/pom.xml index 8111802d..6be0c499 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.0 + 1.0.1 camunda-bpm-data-docs diff --git a/docs/src/orchid/resources/changelog/1.0/1.0.1.ad b/docs/src/orchid/resources/changelog/1.0/1.0.1.ad new file mode 100644 index 00000000..e500e080 --- /dev/null +++ b/docs/src/orchid/resources/changelog/1.0/1.0.1.ad @@ -0,0 +1,9 @@ +--- +version: 1.0.0 +--- + +== Bugfixes + +* Completed JavaDoc and Sources for the `càmunda-bpm-data` parts written in Kotlin (ACL, Guards). +* Improved test coverage for factories +* Separated `LocalVariableWriter` from `GlobalVariableWriter` interface. diff --git a/docs/src/orchid/resources/pages/quick-start.ad b/docs/src/orchid/resources/pages/quick-start.ad index 329f2650..5d2e5595 100644 --- a/docs/src/orchid/resources/pages/quick-start.ad +++ b/docs/src/orchid/resources/pages/quick-start.ad @@ -16,20 +16,20 @@ In Apache Maven add to your `pom.xml`: io.holunda.data camunda-bpm-data - 1.0.0 + 1.0.1 ---- For Gradle Kotlin DSL add to your `build.gradle`: [source,kotlin] ---- -implementation("io.holunda.data:camunda-bpm-data:1.0.0") +implementation("io.holunda.data:camunda-bpm-data:1.0.1") ---- For Gradle Groovy DSL add to your `build.gradle`: [source,groovy] ---- -implementation 'io.holunda.data:camunda-bpm-data:1.0.0' +implementation 'io.holunda.data:camunda-bpm-data:1.0.1' ---- === Declare process variable factories diff --git a/docs/src/orchid/resources/wiki/user-guide/features.ad b/docs/src/orchid/resources/wiki/user-guide/features.ad index 922a3cbb..6cc2bd77 100644 --- a/docs/src/orchid/resources/wiki/user-guide/features.ad +++ b/docs/src/orchid/resources/wiki/user-guide/features.ad @@ -12,7 +12,7 @@ title: Features - The adapter works for all types supported by Camunda BPM. This includes primitive types, object and container types ( `List`, `Set`, `Map` ). - The adapter supports global / local variables. - The adapter support transient variables. -- Fluent API helper are available in order to set, remove or update multiple variables in the same context (`VariableMapBuilder`, `VariableReader` and `VariableWriter`). +- Fluent API helper are available in order to set, remove or update multiple variables in the same context (`VariableMapBuilder`, `VariableReader` and `GlobalVariableWriter`). * Process Variable Guards - Generic support for `VariableGuard` for evaluation of a list of `VariableCondition`s - Condition to check if variable exists. diff --git a/example/example-java/pom.xml b/example/example-java/pom.xml index 39e8a099..d0a3c0ae 100644 --- a/example/example-java/pom.xml +++ b/example/example-java/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.0 + 1.0.1 camunda-bpm-data-example-java @@ -24,7 +24,7 @@ io.holunda.data.example camunda-bpm-data-spin-type-detector - ${project.version} + ${project.parent.version} diff --git a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalProcessTest.java b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalProcessTest.java index a4d70126..96679ce0 100644 --- a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalProcessTest.java +++ b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalProcessTest.java @@ -47,7 +47,6 @@ public void register() { @Test public void shouldDeploy() { // empty method body checks deployment - assertTrue(true); } @Test diff --git a/example/example-kotlin/pom.xml b/example/example-kotlin/pom.xml index 57b91c13..8c6479a7 100644 --- a/example/example-kotlin/pom.xml +++ b/example/example-kotlin/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.0 + 1.0.1 camunda-bpm-data-example-kotlin @@ -24,6 +24,7 @@ io.holunda.data.example camunda-bpm-data-spin-type-detector + ${project.parent.version} @@ -132,7 +133,6 @@ spring-boot-starter-test test - @@ -149,10 +149,6 @@ com.tngtech.jgiven jgiven-maven-plugin - - org.jacoco - jacoco-maven-plugin - diff --git a/example/pom.xml b/example/pom.xml index 54270182..0719cf32 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.0 + 1.0.1 io.holunda.data.example @@ -42,11 +42,6 @@ test ${project.version} - - io.holunda.data.example - camunda-bpm-data-spin-type-detector - ${project.version} - diff --git a/example/spin-type-detector/pom.xml b/example/spin-type-detector/pom.xml index 85c73a0e..bab9c776 100644 --- a/example/spin-type-detector/pom.xml +++ b/example/spin-type-detector/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.0 + 1.0.1 camunda-bpm-data-spin-type-detector diff --git a/extension/core/pom.xml b/extension/core/pom.xml index 5c5c95d8..74fc5756 100644 --- a/extension/core/pom.xml +++ b/extension/core/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.0 + 1.0.1 ../.. diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java index f3717bb5..cd74e061 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java @@ -11,10 +11,8 @@ import io.holunda.camunda.bpm.data.reader.VariableMapReader; import io.holunda.camunda.bpm.data.reader.VariableReader; import io.holunda.camunda.bpm.data.reader.VariableScopeReader; -import io.holunda.camunda.bpm.data.writer.RuntimeServiceVariableWriter; -import io.holunda.camunda.bpm.data.writer.TaskServiceVariableWriter; -import io.holunda.camunda.bpm.data.writer.VariableMapWriter; -import io.holunda.camunda.bpm.data.writer.VariableScopeWriter; +import io.holunda.camunda.bpm.data.writer.*; + import java.util.Date; import java.util.List; import java.util.Map; @@ -184,7 +182,7 @@ public static VariableMapBuilder builder() { * @return new writer */ @NotNull - public static VariableMapWriter writer(VariableMap variables) { + public static GlobalVariableWriter writer(VariableMap variables) { return new VariableMapWriter(variables); } @@ -195,7 +193,7 @@ public static VariableMapWriter writer(VariableMap variables) { * @return new writer working on provided variable scope. */ @NotNull - public static VariableScopeWriter writer(VariableScope variableScope) { + public static VariableWriter writer(VariableScope variableScope) { return new VariableScopeWriter(variableScope); } @@ -207,7 +205,7 @@ public static VariableScopeWriter writer(VariableScope variableScope) { * @return new writer working on provided process execution. */ @NotNull - public static RuntimeServiceVariableWriter writer(RuntimeService runtimeService, String executionId) { + public static VariableWriter writer(RuntimeService runtimeService, String executionId) { return new RuntimeServiceVariableWriter(runtimeService, executionId); } @@ -219,7 +217,7 @@ public static RuntimeServiceVariableWriter writer(RuntimeService runtimeService, * @return new writer working on provided user task. */ @NotNull - public static TaskServiceVariableWriter writer(TaskService taskService, String taskId) { + public static VariableWriter writer(TaskService taskService, String taskId) { return new TaskServiceVariableWriter(taskService, taskId); } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java index 25af90b4..4f083b2e 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java @@ -3,6 +3,8 @@ import io.holunda.camunda.bpm.data.factory.VariableFactory; import io.holunda.camunda.bpm.data.writer.VariableMapWriter; import java.util.Collections; +import java.util.Objects; + import org.camunda.bpm.engine.variable.VariableMap; import org.camunda.bpm.engine.variable.Variables; import org.jetbrains.annotations.NotNull; @@ -51,10 +53,26 @@ public VariableMapBuilder set(VariableFactory variableFactory, T value, b } /** + * Creates the variable map. * @return instance of {@link VariableMap} containing set values */ @NotNull public VariableMap build() { return Variables.fromMap(Collections.unmodifiableMap(writer.variables())); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VariableMapBuilder that = (VariableMapBuilder) o; + + return Objects.equals(writer, that.writer); + } + + @Override + public int hashCode() { + return writer != null ? writer.hashCode() : 0; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java index e72ac8ad..a7097f07 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java @@ -85,8 +85,8 @@ public ReadAdapter from(TaskService taskService, String taskId) { * * @return adapter builder. */ - public RuntimeServiceAdapterBuilder using(RuntimeService runtimeService) { - return new RuntimeServiceAdapterBuilder<>(this, runtimeService); + public BasicRuntimeServiceAdapterBuilder using(RuntimeService runtimeService) { + return new BasicRuntimeServiceAdapterBuilder<>(this, runtimeService); } /** @@ -96,8 +96,8 @@ public RuntimeServiceAdapterBuilder using(RuntimeService runtimeService) { * * @return adapter builder. */ - public TaskServiceAdapterBuilder using(TaskService taskService) { - return new TaskServiceAdapterBuilder<>(this, taskService); + public BasicTaskServiceAdapterBuilder using(TaskService taskService) { + return new BasicTaskServiceAdapterBuilder<>(this, taskService); } @Override @@ -138,4 +138,95 @@ public String toString() { ", clazz=" + clazz + '}'; } + + /** + * Creates a builder to encapsulate the runtime service access. + * + * @param type of builder. + */ + public static class BasicRuntimeServiceAdapterBuilder { + + private final RuntimeService runtimeService; + private final BasicVariableFactory basicVariableFactory; + + /** + * Constructs the builder. + * + * @param basicVariableFactory variable factory to use. + * @param runtimeService task service to build adapter with. + */ + public BasicRuntimeServiceAdapterBuilder(BasicVariableFactory basicVariableFactory, RuntimeService runtimeService) { + this.runtimeService = runtimeService; + this.basicVariableFactory = basicVariableFactory; + } + + /** + * Creates a write adapter on execution. + * + * @param executionId id identifying execution. + * + * @return write adapter + */ + public WriteAdapter on(String executionId) { + return new ReadWriteAdapterRuntimeService<>(runtimeService, executionId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); + } + + /** + * Creates a read adapter on execution. + * + * @param executionId id identifying execution. + * + * @return read adapter. + */ + public ReadAdapter from(String executionId) { + return new ReadWriteAdapterRuntimeService<>(runtimeService, executionId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); + } + } + + /** + * Creates a builder to encapsulate the task service access. + * + * @param type of builder. + */ + public static class BasicTaskServiceAdapterBuilder { + + private final TaskService taskService; + private final BasicVariableFactory basicVariableFactory; + + /** + * Constructs the builder. + * + * @param basicVariableFactory variable factory to use. + * @param taskService task service to build adapter with. + */ + public BasicTaskServiceAdapterBuilder(BasicVariableFactory basicVariableFactory, TaskService taskService) { + this.taskService = taskService; + this.basicVariableFactory = basicVariableFactory; + } + + /** + * Creates a write adapter on task. + * + * @param taskId id identifying task. + * + * @return write adapter + */ + public WriteAdapter on(String taskId) { + return new ReadWriteAdapterTaskService<>(taskService, taskId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); + } + + /** + * Creates a read adapter on task. + * + * @param taskId id identifying task. + * + * @return read adapter. + */ + public ReadAdapter from(String taskId) { + return new ReadWriteAdapterTaskService<>(taskService, taskId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); + } + + } + + } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/RuntimeServiceAdapterBuilder.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/RuntimeServiceAdapterBuilder.java deleted file mode 100644 index 62a123e7..00000000 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/RuntimeServiceAdapterBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.holunda.camunda.bpm.data.factory; - - -import io.holunda.camunda.bpm.data.adapter.ReadAdapter; -import io.holunda.camunda.bpm.data.adapter.WriteAdapter; -import io.holunda.camunda.bpm.data.adapter.basic.ReadWriteAdapterRuntimeService; -import org.camunda.bpm.engine.RuntimeService; - -/** - * Creates a builder to encapsulate the runtime service access. - * - * @param type of builder. - */ -public class RuntimeServiceAdapterBuilder { - - private final RuntimeService runtimeService; - private final BasicVariableFactory basicVariableFactory; - - /** - * Constructs the builder. - * - * @param basicVariableFactory variable factory to use. - * @param runtimeService task service to build adapter with. - */ - public RuntimeServiceAdapterBuilder(BasicVariableFactory basicVariableFactory, RuntimeService runtimeService) { - this.runtimeService = runtimeService; - this.basicVariableFactory = basicVariableFactory; - } - - /** - * Creates a write adapter on execution. - * - * @param executionId id identifying execution. - * - * @return write adapter - */ - public WriteAdapter on(String executionId) { - return new ReadWriteAdapterRuntimeService<>(runtimeService, executionId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); - } - - /** - * Creates a read adapter on execution. - * - * @param executionId id identifying execution. - * - * @return read adapter. - */ - public ReadAdapter from(String executionId) { - return new ReadWriteAdapterRuntimeService<>(runtimeService, executionId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); - } -} diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/TaskServiceAdapterBuilder.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/TaskServiceAdapterBuilder.java deleted file mode 100644 index 9037ff77..00000000 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/TaskServiceAdapterBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.holunda.camunda.bpm.data.factory; - -import io.holunda.camunda.bpm.data.adapter.ReadAdapter; -import io.holunda.camunda.bpm.data.adapter.WriteAdapter; -import io.holunda.camunda.bpm.data.adapter.basic.ReadWriteAdapterTaskService; -import org.camunda.bpm.engine.TaskService; - -/** - * Creates a builder to encapsulate the task service access. - * - * @param type of builder. - */ -public class TaskServiceAdapterBuilder { - - private final TaskService taskService; - private final BasicVariableFactory basicVariableFactory; - - /** - * Constructs the builder. - * - * @param basicVariableFactory variable factory to use. - * @param taskService task service to build adapter with. - */ - public TaskServiceAdapterBuilder(BasicVariableFactory basicVariableFactory, TaskService taskService) { - this.taskService = taskService; - this.basicVariableFactory = basicVariableFactory; - } - - /** - * Creates a write adapter on task. - * - * @param taskId id identifying task. - * - * @return write adapter - */ - public WriteAdapter on(String taskId) { - return new ReadWriteAdapterTaskService<>(taskService, taskId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); - } - - /** - * Creates a read adapter on task. - * - * @param taskId id identifying task. - * - * @return read adapter. - */ - public ReadAdapter from(String taskId) { - return new ReadWriteAdapterTaskService<>(taskService, taskId, basicVariableFactory.getName(), basicVariableFactory.getVariableClass()); - } - -} diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java index 14345e11..bef54551 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java @@ -1,6 +1,8 @@ package io.holunda.camunda.bpm.data.reader; import io.holunda.camunda.bpm.data.factory.VariableFactory; + +import java.util.Objects; import java.util.Optional; import org.camunda.bpm.engine.RuntimeService; import org.jetbrains.annotations.NotNull; @@ -46,4 +48,22 @@ public T getLocal(VariableFactory variableFactory) { public Optional getLocalOptional(VariableFactory variableFactory) { return variableFactory.from(runtimeService, executionId).getLocalOptional(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RuntimeServiceVariableReader that = (RuntimeServiceVariableReader) o; + + if (!Objects.equals(runtimeService, that.runtimeService)) return false; + return Objects.equals(executionId, that.executionId); + } + + @Override + public int hashCode() { + int result = runtimeService != null ? runtimeService.hashCode() : 0; + result = 31 * result + (executionId != null ? executionId.hashCode() : 0); + return result; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java index 7e4b2e87..b5da36a0 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java @@ -1,6 +1,8 @@ package io.holunda.camunda.bpm.data.reader; import io.holunda.camunda.bpm.data.factory.VariableFactory; + +import java.util.Objects; import java.util.Optional; import org.camunda.bpm.engine.TaskService; import org.jetbrains.annotations.NotNull; @@ -47,4 +49,22 @@ public T getLocal(VariableFactory variableFactory) { public Optional getLocalOptional(VariableFactory variableFactory) { return variableFactory.from(taskService, taskId).getLocalOptional(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TaskServiceVariableReader that = (TaskServiceVariableReader) o; + + if (!Objects.equals(taskService, that.taskService)) return false; + return Objects.equals(taskId, that.taskId); + } + + @Override + public int hashCode() { + int result = taskService != null ? taskService.hashCode() : 0; + result = 31 * result + (taskId != null ? taskId.hashCode() : 0); + return result; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java index 584f8c01..6b5188d6 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java @@ -1,6 +1,8 @@ package io.holunda.camunda.bpm.data.reader; import io.holunda.camunda.bpm.data.factory.VariableFactory; + +import java.util.Objects; import java.util.Optional; import org.camunda.bpm.engine.variable.VariableMap; @@ -38,4 +40,19 @@ public T getLocal(VariableFactory variableFactory) { public Optional getLocalOptional(VariableFactory variableFactory) { return variableFactory.from(variableMap).getLocalOptional(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VariableMapReader that = (VariableMapReader) o; + + return Objects.equals(variableMap, that.variableMap); + } + + @Override + public int hashCode() { + return variableMap != null ? variableMap.hashCode() : 0; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java index 4e00a3c7..86f26f33 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java @@ -1,6 +1,8 @@ package io.holunda.camunda.bpm.data.reader; import io.holunda.camunda.bpm.data.factory.VariableFactory; + +import java.util.Objects; import java.util.Optional; import org.camunda.bpm.engine.delegate.VariableScope; import org.jetbrains.annotations.NotNull; @@ -43,4 +45,19 @@ public T getLocal(VariableFactory variableFactory) { public Optional getLocalOptional(VariableFactory variableFactory) { return variableFactory.from(variableScope).getLocalOptional(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VariableScopeReader that = (VariableScopeReader) o; + + return Objects.equals(variableScope, that.variableScope); + } + + @Override + public int hashCode() { + return variableScope != null ? variableScope.hashCode() : 0; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java new file mode 100644 index 00000000..7c505336 --- /dev/null +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java @@ -0,0 +1,59 @@ +package io.holunda.camunda.bpm.data.writer; + +import io.holunda.camunda.bpm.data.adapter.WriteAdapter; +import io.holunda.camunda.bpm.data.factory.VariableFactory; +import org.camunda.bpm.engine.variable.VariableMap; +import org.jetbrains.annotations.NotNull; + +/** + * Inverting calls to {@link io.holunda.camunda.bpm.data.adapter.WriteAdapter}. + * + * @param type of concrete Writer for fluent usage. + */ +public interface GlobalVariableWriter> { + + /** + * Sets the value for the provided variable and returns the builder (fluently). + * + * @param variableFactory the variable + * @param value the value + * @param type of value + * @return current writer instance + * @see io.holunda.camunda.bpm.data.adapter.WriteAdapter#set(Object) + */ + @NotNull + S set(VariableFactory variableFactory, T value); + + /** + * Sets the (transient) value for the provided variable and returns the builder (fluently). + * + * @param variableFactory the variable + * @param value the value + * @param isTransient if true, the variable is transient, default false. + * @param type of value + * @return current writer instance + * @see io.holunda.camunda.bpm.data.adapter.WriteAdapter#set(Object, boolean) + */ + @NotNull + S set(VariableFactory variableFactory, T value, boolean isTransient); + + /** + * Removes the value for the provided variable and returns the builder (fluently). + * + * @param variableFactory the variable + * @param type of value + * @return current writer instance + * @see WriteAdapter#remove() + */ + @NotNull + S remove(VariableFactory variableFactory); + + /** + * Returns the resulting variables. + * + * @return variables. + */ + @NotNull + VariableMap variables(); + +} diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java index e08b28ed..45b231e4 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java @@ -10,7 +10,7 @@ * * @param type of concrete Writer for fluent usage. */ -public interface LocalVariableWriter> extends VariableWriter { +public interface LocalVariableWriter> { /** * Sets the local value for the provided variable and returns the builder (fluently). @@ -21,6 +21,7 @@ public interface LocalVariableWriter> extends V * @return current writer instance * @see WriteAdapter#setLocal(Object) */ + @NotNull S setLocal(VariableFactory variableFactory, T value); /** @@ -33,6 +34,7 @@ public interface LocalVariableWriter> extends V * @return current writer instance * @see WriteAdapter#setLocal(Object, boolean) */ + @NotNull S setLocal(VariableFactory variableFactory, T value, boolean isTransient); /** @@ -43,6 +45,7 @@ public interface LocalVariableWriter> extends V * @return current writer instance * @see WriteAdapter#removeLocal() */ + @NotNull S removeLocal(VariableFactory variableFactory); /** diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java index 26e7b13e..218d6585 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java @@ -5,10 +5,12 @@ import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * Process execution builder allowing for fluent variable setting. */ -public class RuntimeServiceVariableWriter implements LocalVariableWriter { +public class RuntimeServiceVariableWriter implements VariableWriter { private final RuntimeService runtimeService; private final String executionId; @@ -72,4 +74,22 @@ public RuntimeServiceVariableWriter removeLocal(VariableFactory factory) factory.on(this.runtimeService, this.executionId).removeLocal(); return this; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RuntimeServiceVariableWriter that = (RuntimeServiceVariableWriter) o; + + if (!Objects.equals(runtimeService, that.runtimeService)) return false; + return Objects.equals(executionId, that.executionId); + } + + @Override + public int hashCode() { + int result = runtimeService != null ? runtimeService.hashCode() : 0; + result = 31 * result + (executionId != null ? executionId.hashCode() : 0); + return result; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java index 1aebfe24..b57d8fb4 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java @@ -5,10 +5,12 @@ import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * User task builder allowing for fluent variable setting. */ -public class TaskServiceVariableWriter implements LocalVariableWriter { +public class TaskServiceVariableWriter implements VariableWriter { private final TaskService taskService; private final String taskId; @@ -73,4 +75,21 @@ public TaskServiceVariableWriter removeLocal(VariableFactory factory) { return this; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TaskServiceVariableWriter that = (TaskServiceVariableWriter) o; + + if (!Objects.equals(taskService, that.taskService)) return false; + return Objects.equals(taskId, that.taskId); + } + + @Override + public int hashCode() { + int result = taskService != null ? taskService.hashCode() : 0; + result = 31 * result + (taskId != null ? taskId.hashCode() : 0); + return result; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java index 1ae318eb..bd0004c5 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java @@ -4,10 +4,12 @@ import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * Variable map builder allowing for fluent variable setting. */ -public class VariableMapWriter implements VariableWriter { +public class VariableMapWriter implements GlobalVariableWriter { private final VariableMap variables; @@ -45,4 +47,18 @@ public VariableMapWriter remove(VariableFactory factory) { public VariableMap variables() { return variables; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VariableMapWriter that = (VariableMapWriter) o; + return Objects.equals(variables, that.variables); + } + + @Override + public int hashCode() { + return variables != null ? variables.hashCode() : 0; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java index 1e317f2d..6eb8cf2e 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java @@ -5,10 +5,12 @@ import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * Variable scope builder allowing for fluent variable setting. */ -public class VariableScopeWriter implements LocalVariableWriter { +public class VariableScopeWriter implements VariableWriter { private final VariableScope scope; @@ -74,4 +76,17 @@ public VariableMap variablesLocal() { return scope.getVariablesLocalTyped(); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VariableScopeWriter that = (VariableScopeWriter) o; + return Objects.equals(scope, that.scope); + } + + @Override + public int hashCode() { + return scope != null ? scope.hashCode() : 0; + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableWriter.java index 9529956f..7a3f8b35 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableWriter.java @@ -6,54 +6,10 @@ import org.jetbrains.annotations.NotNull; /** - * Inverting calls to {@link io.holunda.camunda.bpm.data.adapter.WriteAdapter}. + * Inverting calls to {@link WriteAdapter}. * * @param type of concrete Writer for fluent usage. */ -public interface VariableWriter> { - - /** - * Sets the value for the provided variable and returns the builder (fluently). - * - * @param variableFactory the variable - * @param value the value - * @param type of value - * @return current writer instance - * @see io.holunda.camunda.bpm.data.adapter.WriteAdapter#set(Object) - */ - @NotNull - S set(VariableFactory variableFactory, T value); - - /** - * Sets the (transient) value for the provided variable and returns the builder (fluently). - * - * @param variableFactory the variable - * @param value the value - * @param isTransient if true, the variable is transient, default false. - * @param type of value - * @return current writer instance - * @see io.holunda.camunda.bpm.data.adapter.WriteAdapter#set(Object, boolean) - */ - @NotNull - S set(VariableFactory variableFactory, T value, boolean isTransient); - - /** - * Removes the value for the provided variable and returns the builder (fluently). - * - * @param variableFactory the variable - * @param type of value - * @return current writer instance - * @see WriteAdapter#remove() - */ - @NotNull - S remove(VariableFactory variableFactory); - - /** - * Returns the resulting variables. - * - * @return variables. - */ - @NotNull - VariableMap variables(); +public interface VariableWriter> extends LocalVariableWriter, GlobalVariableWriter { } diff --git a/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt b/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt index cb87a576..d1df0f70 100644 --- a/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt +++ b/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt @@ -17,23 +17,16 @@ import org.camunda.bpm.engine.variable.Variables * A typical application of an ACL is the protection of external access to the process (signal, message correlation). * To do so, signal / correlate with transient variables only and those got pumped into the execution if the guard is satisfied. *

+ * @constructor Creates a new ACL. + * @property precondition Precondition to be fulfilled to pass the ACL. + * @property variableMapTransformer Mapping to be applied. + * @property factory Factory to use. + * @property valueApplicationStrategy Strategy to apply values from transformer to given variable scope. */ class AntiCorruptionLayer( - /** - * Precondition to be fulfilled to pass the ACL. - */ val precondition: VariablesGuard, - /** - * Mapping to be applied. - */ val variableMapTransformer: VariableMapTransformer, - /** - * Factory to use. - */ internal val factory: VariableFactory, - /** - * Strategy to apply values from transformer to given variable scope. - */ internal val valueApplicationStrategy: ValueApplicationStrategy ) { @@ -60,6 +53,7 @@ class AntiCorruptionLayer( /** * Retrieves the ACL in form of an execution listener. + * @return Camunda Execution Listener responsible for variable extraction, guard check and modification. */ fun getExecutionListener() = ExecutionListener { execution -> val variablesExternal = factory.from(execution).get() @@ -71,6 +65,7 @@ class AntiCorruptionLayer( /** * Retrieves the ACL in form of a task listener. + * @return Camunda Task Listener responsible for variable extraction, guard check and modification. */ fun getTaskListener() = TaskListener { task -> val variablesExternal = factory.from(task).get() @@ -83,7 +78,7 @@ class AntiCorruptionLayer( /** * Checks if the preconditions are satisfied and constructs a variable map wrapping the variables. * @param variableMap variable map containing the variables. - * @return new variables + * @return new variable map */ fun checkAndWrap(variableMap: VariableMap): VariableMap { val violations = precondition.evaluate(variableMap) @@ -96,9 +91,9 @@ class AntiCorruptionLayer( /** * Constructs a variable map wrapping the variables. * @param variableMap variable map containing the variables. - * @return new variables + * @return new variable map */ fun wrap(variableMap: VariableMap): VariableMap { return wrapAsTypedTransientVariable(variableName = factory.name, variables = variableMap) } -} \ No newline at end of file +} diff --git a/extension/core/src/main/kotlin/acl/package-info.kt b/extension/core/src/main/kotlin/acl/package-info.kt deleted file mode 100644 index 20937e29..00000000 --- a/extension/core/src/main/kotlin/acl/package-info.kt +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Package providing resources for building of Anti-Corruption-Layer (ACL). - * - * @since 1.0.0 - * @see {@link io.holunda.camunda.bpm.data.acl.ACL} for more details. - * - */ -package io.holunda.camunda.bpm.data.acl diff --git a/extension/core/src/main/kotlin/guard/GuardViolation.kt b/extension/core/src/main/kotlin/guard/GuardViolation.kt index a692e788..5cbc2e92 100644 --- a/extension/core/src/main/kotlin/guard/GuardViolation.kt +++ b/extension/core/src/main/kotlin/guard/GuardViolation.kt @@ -6,6 +6,10 @@ import java.util.* /** * Represents a violation of a guard. * @param T factory type. + * @constructor creates a new guard violation. + * @property condition violated condition + * @property option option read (cointaining the value) + * @property message violation message */ data class GuardViolation( /** diff --git a/extension/core/src/main/kotlin/guard/VariablesGuard.kt b/extension/core/src/main/kotlin/guard/VariablesGuard.kt index a8129f5c..310cad1e 100644 --- a/extension/core/src/main/kotlin/guard/VariablesGuard.kt +++ b/extension/core/src/main/kotlin/guard/VariablesGuard.kt @@ -8,92 +8,96 @@ import org.camunda.bpm.engine.variable.VariableMap /** * Guard on a set of variables. - * @param variableConditions a list of conditions to add to the guard. + * @constructor Creates new guard. + * @property variableConditions a list of conditions to add to the guard. */ class VariablesGuard( - private val variableConditions: List> + private val variableConditions: List> ) { - companion object { - val EMPTY = VariablesGuard(listOf()) - } - - /** - * Constructs a guard with exactly one condition. - * @param condition condition to add to gurad. - */ - constructor(condition: VariableGuardCondition<*>) : this(listOf(condition)) - + companion object { /** - * Fluent builer to create a new guard from existing one adding one additional condition. - * @param condition to add to existing guard. + * Empty guard. */ - fun fromExisting(condition: VariableGuardCondition<*>) = VariablesGuard(variableConditions.plus(condition)) - - /** - * Evaluates the contained conditions on variables from given variable map. - * @param variableMap variable map to work on. - * @return list of violations if any. - */ - fun evaluate(variableMap: VariableMap): List> = - variableConditions.flatMap { it.evaluate(variableMap) } - - /** - * Evaluates the contained conditions on variables from given variable scope. - * @param variableScope variable scope to work on. - * @return list of violations if any. - */ - fun evaluate(variableScope: VariableScope): List> = - variableConditions.flatMap { it.evaluate(variableScope) } - - /** - * Evaluates the contained conditions on variables retrieved from task service. - * @param taskService task service to access the task. - * @param taskId task id. - * @return list of violations if any. - */ - fun evaluate(taskService: TaskService, taskId: String): List> = - variableConditions.flatMap { it.evaluate(taskService, taskId) } - - /** - * Evaluates the contained conditions on variables retrieved from runtime service. - * @param runtimeService runtime service to access the execution. - * @param executionId execution id. - * @return list of violations if any. - */ - fun evaluate(runtimeService: RuntimeService, executionId: String): List> = - variableConditions.flatMap { it.evaluate(runtimeService, executionId) } - - /** - * Retrieves a list of local variables addressed by this guard. - * @return variable factories extracted from condition with scope local. - */ - fun getLocalVariables() = variableConditions.filter { it.local }.map { it.variableFactory } - - /** - * Retrieves a list of variables addressed by this guard. - * @return variable factories extracted from condition with scope global. - */ - fun getVariables() = variableConditions.filter { !it.local }.map { it.variableFactory } - - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as VariablesGuard - - if (variableConditions != other.variableConditions) return false - - return true - } - - override fun hashCode(): Int { - return variableConditions.hashCode() - } - - override fun toString(): String { - return "VariablesGuard(variableConditions=$variableConditions)" - } + val EMPTY = VariablesGuard(listOf()) + } + + /** + * Constructs a guard with exactly one condition. + * @param condition condition to add to gurad. + */ + constructor(condition: VariableGuardCondition<*>) : this(listOf(condition)) + + /** + * Fluent builder to create a new guard from existing one adding one additional condition. + * @param condition to add to existing guard. + */ + fun fromExisting(condition: VariableGuardCondition<*>) = VariablesGuard(variableConditions.plus(condition)) + + /** + * Evaluates the contained conditions on variables from given variable map. + * @param variableMap variable map to work on. + * @return list of violations if any. + */ + fun evaluate(variableMap: VariableMap): List> = + variableConditions.flatMap { it.evaluate(variableMap) } + + /** + * Evaluates the contained conditions on variables from given variable scope. + * @param variableScope variable scope to work on. + * @return list of violations if any. + */ + fun evaluate(variableScope: VariableScope): List> = + variableConditions.flatMap { it.evaluate(variableScope) } + + /** + * Evaluates the contained conditions on variables retrieved from task service. + * @param taskService task service to access the task. + * @param taskId task id. + * @return list of violations if any. + */ + fun evaluate(taskService: TaskService, taskId: String): List> = + variableConditions.flatMap { it.evaluate(taskService, taskId) } + + /** + * Evaluates the contained conditions on variables retrieved from runtime service. + * @param runtimeService runtime service to access the execution. + * @param executionId execution id. + * @return list of violations if any. + */ + fun evaluate(runtimeService: RuntimeService, executionId: String): List> = + variableConditions.flatMap { it.evaluate(runtimeService, executionId) } + + /** + * Retrieves a list of local variables addressed by this guard. + * @return variable factories extracted from condition with scope local. + */ + fun getLocalVariables() = variableConditions.filter { it.local }.map { it.variableFactory } + + /** + * Retrieves a list of variables addressed by this guard. + * @return variable factories extracted from condition with scope global. + */ + fun getVariables() = variableConditions.filter { !it.local }.map { it.variableFactory } + + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as VariablesGuard + + if (variableConditions != other.variableConditions) return false + + return true + } + + override fun hashCode(): Int { + return variableConditions.hashCode() + } + + override fun toString(): String { + return "VariablesGuard(variableConditions=$variableConditions)" + } } diff --git a/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt index 21dea549..bc4716ef 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt @@ -6,6 +6,7 @@ import java.util.* /** * Condition to check if the variable exists. + * @constructor Creates a condition. * @param variableFactory factory to work on. * @param local flag indicating if local or global scope is required. */ diff --git a/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt index a6c9f053..3e78a851 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt @@ -10,13 +10,14 @@ import java.util.* /** * Abstract guard condition. - * @since 0.0.6 - * @param T variable type. - * @param variableFactory factory to work on. - * @param local flag indicating the variable scope (global/local). Defaults to global. *

* This class is intended to be subclassed by developers of new variable guards. *

+ * @constructor Creates a condition. + * @since 0.0.6 + * @param T variable type. + * @property variableFactory factory to work on. + * @property local flag indicating the variable scope (global/local). Defaults to global. */ abstract class VariableGuardCondition( internal val variableFactory: VariableFactory, diff --git a/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt index 1da3946c..22c333fb 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt @@ -6,10 +6,11 @@ import java.util.* /** * Guard for testing a condition passed by a matcher-function. + * @constructor Creates a condition. * @param T variable type. * @param variableFactory Factory to work with. * @param local flag indicating the variable scope (global/local). Defaults to global. - * @param matcher matcher function, specifying the condition. + * @property matcher matcher function, specifying the condition. */ class VariableMatchesGuardCondition( /** @@ -48,4 +49,4 @@ class VariableMatchesGuardCondition( * @param matcher function that must match the value. * @return instance of [VariableMatchesGuardCondition] on current factory. */ -fun VariableFactory.matches(local: Boolean = false, matcher: (value: T) -> Boolean) = VariableMatchesGuardCondition(this, local, matcher) \ No newline at end of file +fun VariableFactory.matches(local: Boolean = false, matcher: (value: T) -> Boolean) = VariableMatchesGuardCondition(this, local, matcher) diff --git a/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt index fdcf8cb6..2858ddfa 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt @@ -6,6 +6,7 @@ import java.util.* /** * Condition to check if the variable doesn't exist. + * @constructor Creates a condition. * @param variableFactory factory to work on. * @param local flag indicating if local or global scope is required. */ diff --git a/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt index 754538ba..c719167e 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt @@ -6,6 +6,7 @@ import java.util.* /** * Condition to check if the variable has provided value. + * @constructor Creates a condition. * @param variableFactory factory to work on. * @param value set of values to compare with. * @param local flag indicating if local or global scope is required. diff --git a/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt index c621f4ea..979b9cd0 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt @@ -6,6 +6,7 @@ import java.util.* /** * Condition to check if the variable has on of the provided values. + * @constructor Creates a condition. * @param variableFactory factory to work on. * @param values set of values to compare with. * @param local flag indicating if local or global scope is required. diff --git a/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt b/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt index 98e6e494..775166dd 100644 --- a/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt +++ b/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt @@ -8,8 +8,9 @@ import org.slf4j.LoggerFactory /** * Default guard execution listener, evaluating the given guard conditions on the execution. - * @param guard guard to check. - * @param throwViolations flag controlling if the violation should lead to an exception. + * @constructor Creates a listener. + * @property guard guard to check. + * @property throwViolations flag controlling if the violation should lead to an exception. */ class DefaultGuardExecutionListener( val guard: VariablesGuard, @@ -39,4 +40,4 @@ class DefaultGuardExecutionListener( } } } -} \ No newline at end of file +} diff --git a/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt b/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt index 8bea4d32..8a2a8862 100644 --- a/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt +++ b/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt @@ -8,8 +8,9 @@ import org.slf4j.LoggerFactory /** * Default guard execution listener, evaluating the given guard conditions on the task. - * @param guard guard to check. - * @param throwViolations flag controlling if the violation should lead to an exception. + * @constructor Creates a listener. + * @property guard guard to check. + * @property throwViolations flag controlling if the violation should lead to an exception. */ class DefaultGuardTaskListener( val guard: VariablesGuard, @@ -45,4 +46,4 @@ class DefaultGuardTaskListener( */ private fun String.removeNewLines() = this .replace("\n", " ") -} \ No newline at end of file +} diff --git a/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt b/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt index db164443..aad37442 100644 --- a/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt +++ b/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt @@ -5,6 +5,7 @@ import org.camunda.bpm.engine.ProcessEngineException /** * Exception indicating a guard violation. + * @constructor Creates the exception. * @param violations list of guard violations. * @param reason reason of failure. */ @@ -24,4 +25,4 @@ class GuardViolationException( return "$message\n" + violations.joinToString(separator = ",\n") { "\t${it.message}" } } } -} \ No newline at end of file +} diff --git a/extension/core/src/main/kotlin/guard/package-info.kt b/extension/core/src/main/kotlin/guard/package-info.kt deleted file mode 100644 index 4307db83..00000000 --- a/extension/core/src/main/kotlin/guard/package-info.kt +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Package providing resources for building Variable Guards. - * - * @since 0.0.4 - * @see io.holunda.camunda.bpm.data.guard.CamundaBpmDataGuards for more details. - */ -package io.holunda.camunda.bpm.data.guard diff --git a/extension/core/src/main/kotlin/package-info.kt b/extension/core/src/main/kotlin/package-info.kt deleted file mode 100644 index 6a97145d..00000000 --- a/extension/core/src/main/kotlin/package-info.kt +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Top-level package of the library. - * - * @see io.holunda.camunda.bpm.data.CamundaBpmData as entry point for variable factory definition. - * @since 0.0.2 - */ -package io.holunda.camunda.bpm.data diff --git a/extension/core/src/main/kotlin/packages.md b/extension/core/src/main/kotlin/packages.md new file mode 100644 index 00000000..98c2acf1 --- /dev/null +++ b/extension/core/src/main/kotlin/packages.md @@ -0,0 +1,21 @@ +# Package io.holunda.camunda.bpm.data + +Top-level package of the library. + +check [io.holunda.camunda.bpm.data.CamundaBpmDataKotlin] as entry point for variable factory definition. +@since 0.0.2 + + +# Package io.holunda.camunda.bpm.data.guard + +Package providing resources for building Variable Guards. +@since 0.0.4 +check [io.holunda.camunda.bpm.data.guard.CamundaBpmDataGuards] for more details. + +# Package io.holunda.camunda.bpm.data.acl + +Package providing resources for building of Anti-Corruption-Layer (ACL). +@since 1.0.0 +@see [io.holunda.camunda.bpm.data.acl.CamundaBpmDataACL] for more details. + + diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/CamundaBpmDataTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/CamundaBpmDataTest.java new file mode 100644 index 00000000..282c28c4 --- /dev/null +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/CamundaBpmDataTest.java @@ -0,0 +1,263 @@ +package io.holunda.camunda.bpm.data; + + +import io.holunda.camunda.bpm.data.builder.VariableMapBuilder; +import io.holunda.camunda.bpm.data.factory.*; +import io.holunda.camunda.bpm.data.reader.*; +import io.holunda.camunda.bpm.data.writer.*; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.TaskService; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; + +import java.util.Date; + +import static io.holunda.camunda.bpm.data.CamundaBpmData.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.camunda.bpm.engine.variable.Variables.createVariables; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class CamundaBpmDataTest { + + private final String VAR_NAME = "foo"; + private final RuntimeService runtimeService = mock(RuntimeService.class); + private final TaskService taskService = mock(TaskService.class); + + + @Before + public void setupStubs() { + when(runtimeService.getVariablesLocalTyped(any())).thenReturn(createVariables()); + when(runtimeService.getVariablesTyped(any())).thenReturn(createVariables()); + + when(taskService.getVariablesLocalTyped(any())).thenReturn(createVariables()); + when(taskService.getVariablesTyped(any())).thenReturn(createVariables()); + } + + @Test + public void shouldCreateStringVariableFactory() { + + VariableFactory factory = stringVariable(VAR_NAME); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(String.class); + } + + @Test + public void shouldCreateDateVariableFactory() { + + VariableFactory factory = dateVariable(VAR_NAME); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(Date.class); + } + + @Test + public void shouldCreateIntVariableFactory() { + + VariableFactory factory = intVariable(VAR_NAME); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(Integer.class); + } + + + @Test + public void shouldCreateLongVariableFactory() { + + VariableFactory factory = longVariable(VAR_NAME); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(Long.class); + } + + @Test + public void shouldCreateShortVariableFactory() { + + VariableFactory factory = shortVariable(VAR_NAME); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(Short.class); + } + + @Test + public void shouldCreateDoubleVariableFactory() { + + VariableFactory factory = doubleVariable(VAR_NAME); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(Double.class); + } + + @Test + public void shouldCreateBooleanVariableFactory() { + + VariableFactory factory = booleanVariable(VAR_NAME); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(Boolean.class); + } + + @Test + public void shouldCreateCustomVariableFactory() { + + VariableFactory factory = customVariable(VAR_NAME, MyCustomType.class); + assertThat(factory).isInstanceOf(BasicVariableFactory.class); + + BasicVariableFactory basicFactory = (BasicVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getVariableClass()).isEqualTo(MyCustomType.class); + } + + @Test + public void shouldCreateListVariableFactory() { + + VariableFactory factory = listVariable(VAR_NAME, MyCustomType.class); + assertThat(factory).isInstanceOf(ListVariableFactory.class); + + ListVariableFactory basicFactory = (ListVariableFactory) factory; + assertThat(basicFactory.getName()).isEqualTo(VAR_NAME); + assertThat(basicFactory.getMemberClass()).isEqualTo(MyCustomType.class); + } + + @Test + public void shouldCreateSetVariableFactory() { + + VariableFactory factory = setVariable(VAR_NAME, MyCustomType.class); + assertThat(factory).isInstanceOf(SetVariableFactory.class); + + SetVariableFactory setFactory = (SetVariableFactory) factory; + assertThat(setFactory.getName()).isEqualTo(VAR_NAME); + assertThat(setFactory.getMemberClass()).isEqualTo(MyCustomType.class); + } + + @Test + public void shouldCreateMapVariableFactory() { + + VariableFactory factory = mapVariable(VAR_NAME, String.class, MyCustomType.class); + assertThat(factory).isInstanceOf(MapVariableFactory.class); + + MapVariableFactory mapFactory = (MapVariableFactory) factory; + assertThat(mapFactory.getName()).isEqualTo(VAR_NAME); + assertThat(mapFactory.getKeyClass()).isEqualTo(String.class); + assertThat(mapFactory.getValueClass()).isEqualTo(MyCustomType.class); + } + + + @Test + public void shouldCreateBuilder() { + + VariableMapBuilder builder = builder(); + VariableMapBuilder builder2 = builder(); + assertThat(builder).isEqualTo(builder2); + assertThat(builder).isNotSameAs(builder2); + } + + @Test + public void shouldCreateWriterRuntimeService() { + + VariableWriter writer = writer(runtimeService, "4711"); + VariableWriter writer2 = writer(runtimeService, "4711"); + assertThat(writer).isNotSameAs(writer2); + assertThat(writer).isEqualTo(writer2); + assertThat(writer).isInstanceOf(RuntimeServiceVariableWriter.class); + assertThat(writer.variablesLocal()).isNotNull(); + assertThat(writer.variables()).isNotNull(); + } + + @Test + public void shouldCreateWriterTaskService() { + + VariableWriter writer = writer(taskService, "4711"); + VariableWriter writer2 = writer(taskService, "4711"); + assertThat(writer).isNotSameAs(writer2); + assertThat(writer).isEqualTo(writer2); + assertThat(writer).isInstanceOf(TaskServiceVariableWriter.class); + assertThat(writer.variablesLocal()).isNotNull(); + assertThat(writer.variables()).isNotNull(); + } + + @Test + public void shouldCreateWriterVariableScope() { + + DelegateExecutionFake execution = new DelegateExecutionFake(); + + VariableWriter writer = writer(execution); + VariableWriter writer2 = writer(execution); + assertThat(writer).isNotSameAs(writer2).isEqualTo(writer2); + assertThat(writer).isInstanceOf(VariableScopeWriter.class); + assertThat(writer.variablesLocal()).isNotNull(); + assertThat(writer.variables()).isNotNull(); + } + + @Test + public void shouldCreateWriterVariableMap() { + GlobalVariableWriter writer = writer(createVariables()); + GlobalVariableWriter writer2 = writer(createVariables()); + assertThat(writer).isNotSameAs(writer2).isEqualTo(writer2); + assertThat(writer).isInstanceOf(VariableMapWriter.class); + assertThat(writer.variables()).isNotNull(); + } + + @Test + public void shouldCreateReaderRuntimeService() { + + VariableReader reader = reader(runtimeService, "4711"); + VariableReader reader2 = reader(runtimeService, "4711"); + assertThat(reader).isNotSameAs(reader2); + assertThat(reader).isEqualTo(reader2); + assertThat(reader).isInstanceOf(RuntimeServiceVariableReader.class); + } + + @Test + public void shouldCreateReaderTaskService() { + + VariableReader reader = reader(taskService, "4711"); + VariableReader reader2 = reader(taskService, "4711"); + assertThat(reader).isNotSameAs(reader2); + assertThat(reader).isEqualTo(reader2); + assertThat(reader).isInstanceOf(TaskServiceVariableReader.class); + + } + + @Test + public void shouldCreateReaderVariableScope() { + + DelegateExecutionFake execution = new DelegateExecutionFake(); + VariableReader reader = reader(execution); + VariableReader reader2 = reader(execution); + assertThat(reader).isNotSameAs(reader2); + assertThat(reader).isEqualTo(reader2); + assertThat(reader).isInstanceOf(VariableScopeReader.class); + } + + @Test + public void shouldCreateReaderVariableMap() { + VariableReader reader = reader(createVariables()); + VariableReader reader2 = reader(createVariables()); + assertThat(reader).isNotSameAs(reader2); + assertThat(reader).isEqualTo(reader2); + assertThat(reader).isInstanceOf(VariableMapReader.class); + } + + + static class MyCustomType { + + } +} diff --git a/extension/test/pom.xml b/extension/test/pom.xml index efc3f1be..08c61f76 100644 --- a/extension/test/pom.xml +++ b/extension/test/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.0 + 1.0.1 ../.. @@ -99,27 +99,4 @@ - - - release - - - release - - - - - - org.jetbrains.dokka - dokka-maven-plugin - - - org.codehaus.mojo - build-helper-maven-plugin - - - - - - diff --git a/pom.xml b/pom.xml index b36e999d..a01ee667 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.0 + 1.0.1 ${project.artifactId} Camunda BPM Data https://github.com/holunda-io/camunda-bpm-data/ @@ -350,16 +350,26 @@ org.jetbrains.dokka dokka-maven-plugin - 0.10.0 + 0.10.1 - test attach-javadocs + pre-site javadocJar + + + packages.md + + 8 + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/main/java + + org.apache.maven.plugins @@ -662,6 +672,14 @@ org.sonatype.plugins nexus-staging-maven-plugin + + org.jetbrains.dokka + dokka-maven-plugin + + + org.codehaus.mojo + build-helper-maven-plugin +