Skip to content

Commit 6c29a68

Browse files
authored
Merge pull request #685 from camunda-community-hub/feature/change_proposal
Feature/change proposal
2 parents 9a58722 + 1677759 commit 6c29a68

27 files changed

+538
-355
lines changed

examples/itest/src/test/kotlin/org/camunda/community/rest/itest/SpringBootConfigurationITest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import org.camunda.bpm.engine.variable.Variables
88
import org.camunda.community.rest.client.api.TaskApiClient
99
import org.camunda.community.rest.itest.SpringBootConfigurationITest.CustomValueMapperConfiguration.Companion.VALUE_MAPPER
1010
import org.camunda.community.rest.itest.stages.TestApplication
11-
import org.camunda.community.rest.variables.SpinValueMapper
11+
import org.camunda.community.rest.variables.serialization.SpinJsonValueSerializer
1212
import org.camunda.community.rest.variables.ValueMapper
13+
import org.camunda.community.rest.variables.ValueTypeRegistration
1314
import org.camunda.community.rest.variables.ValueTypeResolverImpl
1415
import org.camunda.spin.plugin.variable.value.SpinValue
1516
import org.junit.jupiter.api.Nested
@@ -32,7 +33,9 @@ internal class SpringBootConfigurationITest {
3233
companion object {
3334
val VALUE_MAPPER: ValueMapper =
3435
ValueMapper(objectMapper = jacksonObjectMapper(), valueTypeResolver = ValueTypeResolverImpl(),
35-
valueMappers = emptyList(),
36+
valueTypeRegistration = ValueTypeRegistration(),
37+
customValueSerializers = emptyList(),
38+
valueSerializers = emptyList(),
3639
serializationFormat = Variables.SerializationDataFormats.JSON)
3740
}
3841

@@ -59,7 +62,7 @@ internal class SpringBootConfigurationITest {
5962
lateinit var valueMapper: ValueMapper
6063

6164
@Autowired(required = false)
62-
lateinit var spinValueMapper: SpinValueMapper
65+
lateinit var spinValueSerializer: SpinJsonValueSerializer
6366

6467
@Autowired(required = false)
6568
lateinit var taskApiClient: TaskApiClient
@@ -69,7 +72,7 @@ internal class SpringBootConfigurationITest {
6972
assertThat(this::runtimeService.isInitialized).isTrue()
7073
assertThat(this::taskApiClient.isInitialized).isTrue()
7174
assertThat(this::valueMapper.isInitialized).isTrue()
72-
assertThat(this::spinValueMapper.isInitialized).isTrue()
75+
assertThat(this::spinValueSerializer.isInitialized).isTrue()
7376
assertThat(this.valueMapper).isNotEqualTo(VALUE_MAPPER)
7477
}
7578
}
@@ -140,7 +143,7 @@ internal class SpringBootConfigurationITest {
140143
.withUserConfiguration(TestApplication::class.java)
141144
.withClassLoader(FilteredClassLoader(SpinValue::class.java))
142145
.run {
143-
assertThatThrownBy { it.getBean(SpinValueMapper::class.java) }.isInstanceOf(NoSuchBeanDefinitionException::class.java)
146+
assertThatThrownBy { it.getBean(SpinJsonValueSerializer::class.java) }.isInstanceOf(NoSuchBeanDefinitionException::class.java)
144147
assertThat(it.getBean(ValueMapper::class.java)).isNotNull
145148
}
146149

extension/core/src/test/kotlin/org/camunda/community/rest/adapter/LockedExternalTaskAdapterTest.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ import org.camunda.community.rest.client.model.LockedExternalTaskDto
2929
import org.camunda.community.rest.client.model.VariableValueDto
3030
import org.camunda.community.rest.impl.toRequiredDate
3131
import org.camunda.community.rest.variables.ValueMapper
32+
import org.camunda.community.rest.variables.ValueTypeRegistration
3233
import org.camunda.community.rest.variables.ValueTypeResolverImpl
33-
import org.camunda.community.rest.variables.format.JsonFormatValueMapper
34+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
3435
import org.junit.Test
3536
import java.time.OffsetDateTime
3637

3738
class LockedExternalTaskAdapterTest {
3839

3940
private val objectMapper = jacksonObjectMapper()
4041
private val typeResolver = ValueTypeResolverImpl()
42+
private val typeRegistration = ValueTypeRegistration()
4143
private val valueMapper = ValueMapper(
4244
objectMapper = objectMapper,
4345
valueTypeResolver = typeResolver,
44-
valueMappers = listOf(JsonFormatValueMapper(objectMapper)),
45-
serializationFormat = Variables.SerializationDataFormats.JSON
46+
valueTypeRegistration = typeRegistration,
47+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
48+
serializationFormat = Variables.SerializationDataFormats.JSON,
49+
customValueSerializers = listOf()
4650
)
4751

4852
private val dto = LockedExternalTaskDto()

extension/core/src/test/kotlin/org/camunda/community/rest/impl/builder/DelegatingDecisionEvaluationBuilderTest.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,28 @@ import org.camunda.bpm.engine.variable.Variables
1010
import org.camunda.community.rest.client.api.DecisionDefinitionApiClient
1111
import org.camunda.community.rest.client.model.DecisionDefinitionDto
1212
import org.camunda.community.rest.client.model.VariableValueDto
13-
import org.camunda.community.rest.variables.SpinValueMapper
13+
import org.camunda.community.rest.variables.serialization.SpinJsonValueSerializer
1414
import org.camunda.community.rest.variables.ValueMapper
15+
import org.camunda.community.rest.variables.ValueTypeRegistration
1516
import org.camunda.community.rest.variables.ValueTypeResolverImpl
17+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
1618
import org.junit.Test
1719
import org.mockito.kotlin.*
1820
import org.springframework.http.ResponseEntity
1921

2022
internal class DelegatingDecisionEvaluationBuilderTest {
2123

2224
private val decisionDefinitionApiClient = mock<DecisionDefinitionApiClient>()
23-
private val valueTypeResolver = ValueTypeResolverImpl()
25+
private val objectMapper = jacksonObjectMapper()
26+
private val typeResolver = ValueTypeResolverImpl()
27+
private val typeRegistration = ValueTypeRegistration()
2428
private val valueMapper = ValueMapper(
25-
objectMapper = jacksonObjectMapper(),
26-
valueTypeResolver = valueTypeResolver,
27-
valueMappers = listOf(SpinValueMapper(valueTypeResolver)),
28-
serializationFormat = Variables.SerializationDataFormats.JSON
29+
objectMapper = objectMapper,
30+
valueTypeResolver = typeResolver,
31+
valueTypeRegistration = typeRegistration,
32+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
33+
serializationFormat = Variables.SerializationDataFormats.JSON,
34+
customValueSerializers = listOf(SpinJsonValueSerializer(typeResolver, typeRegistration))
2935
)
3036

3137
val builder = DelegatingDecisionEvaluationBuilder(

extension/core/src/test/kotlin/org/camunda/community/rest/impl/builder/DelegatingDecisionsEvaluationBuilderTest.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import org.assertj.core.api.Assertions
55
import org.camunda.bpm.engine.variable.Variables
66
import org.camunda.community.rest.client.api.DecisionDefinitionApiClient
77
import org.camunda.community.rest.client.model.VariableValueDto
8-
import org.camunda.community.rest.variables.SpinValueMapper
8+
import org.camunda.community.rest.variables.serialization.SpinXmlValueSerializer
99
import org.camunda.community.rest.variables.ValueMapper
10+
import org.camunda.community.rest.variables.ValueTypeRegistration
1011
import org.camunda.community.rest.variables.ValueTypeResolverImpl
12+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
1113
import org.junit.Test
1214
import org.mockito.kotlin.any
1315
import org.mockito.kotlin.eq
@@ -18,14 +20,17 @@ import org.springframework.http.ResponseEntity
1820
internal class DelegatingDecisionsEvaluationBuilderTest {
1921

2022
private val decisionDefinitionApiClient = mock<DecisionDefinitionApiClient>()
21-
private val valueTypeResolver = ValueTypeResolverImpl()
23+
private val objectMapper = jacksonObjectMapper()
24+
private val typeResolver = ValueTypeResolverImpl()
25+
private val typeRegistration = ValueTypeRegistration()
2226
private val valueMapper = ValueMapper(
23-
objectMapper = jacksonObjectMapper(),
24-
valueTypeResolver = valueTypeResolver,
25-
valueMappers = listOf(SpinValueMapper(valueTypeResolver)),
26-
serializationFormat = Variables.SerializationDataFormats.JSON
27+
objectMapper = objectMapper,
28+
valueTypeResolver = typeResolver,
29+
valueTypeRegistration = typeRegistration,
30+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
31+
serializationFormat = Variables.SerializationDataFormats.JSON,
32+
customValueSerializers = listOf(SpinXmlValueSerializer(typeResolver, typeRegistration))
2733
)
28-
2934
val builder = DelegatingDecisionsEvaluationBuilder(
3035
decisionDefinitionApiClient = decisionDefinitionApiClient,
3136
valueMapper = valueMapper,

extension/core/src/test/kotlin/org/camunda/community/rest/impl/builder/DelegatingMessageCorrelationBuilderTest.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import org.camunda.community.rest.client.api.MessageApiClient
88
import org.camunda.community.rest.client.model.MessageCorrelationResultWithVariableDto
99
import org.camunda.community.rest.client.model.ProcessInstanceDto
1010
import org.camunda.community.rest.variables.ValueMapper
11+
import org.camunda.community.rest.variables.ValueTypeRegistration
1112
import org.camunda.community.rest.variables.ValueTypeResolverImpl
13+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
1214
import org.junit.Test
1315
import org.mockito.kotlin.any
1416
import org.mockito.kotlin.mock
@@ -20,14 +22,20 @@ class DelegatingMessageCorrelationBuilderTest {
2022

2123
val messageApiClient = mock<MessageApiClient>()
2224

25+
private val objectMapper = jacksonObjectMapper()
26+
private val typeResolver = ValueTypeResolverImpl()
27+
private val typeRegistration = ValueTypeRegistration()
28+
2329
val builder = DelegatingMessageCorrelationBuilder(
2430
messageName = "messageName",
2531
messageApiClient = messageApiClient,
2632
valueMapper = ValueMapper(
27-
objectMapper = jacksonObjectMapper(),
28-
valueTypeResolver = ValueTypeResolverImpl(),
29-
valueMappers = emptyList(),
30-
serializationFormat = Variables.SerializationDataFormats.JSON
33+
objectMapper = objectMapper,
34+
valueTypeResolver = typeResolver,
35+
valueTypeRegistration = typeRegistration,
36+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
37+
serializationFormat = Variables.SerializationDataFormats.JSON,
38+
customValueSerializers = listOf()
3139
)
3240
).apply {
3341
this.localVariableEquals("localVar", "localValue")

extension/core/src/test/kotlin/org/camunda/community/rest/impl/builder/DelegatingSignalEventReceivedBuilderTest.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
44
import org.camunda.bpm.engine.variable.Variables
55
import org.camunda.community.rest.client.api.SignalApiClient
66
import org.camunda.community.rest.variables.ValueMapper
7+
import org.camunda.community.rest.variables.ValueTypeRegistration
78
import org.camunda.community.rest.variables.ValueTypeResolverImpl
9+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
810
import org.junit.Test
911
import org.mockito.kotlin.any
1012
import org.mockito.kotlin.mock
@@ -16,14 +18,20 @@ class DelegatingSignalEventReceivedBuilderTest {
1618

1719
val signalApiClient = mock<SignalApiClient>()
1820

21+
private val objectMapper = jacksonObjectMapper()
22+
private val typeResolver = ValueTypeResolverImpl()
23+
private val typeRegistration = ValueTypeRegistration()
24+
1925
val builder = DelegatingSignalEventReceivedBuilder(
2026
signalName = "signalName",
2127
signalApiClient = signalApiClient,
2228
valueMapper = ValueMapper(
23-
objectMapper = jacksonObjectMapper(),
24-
valueTypeResolver = ValueTypeResolverImpl(),
25-
valueMappers = emptyList(),
26-
serializationFormat = Variables.SerializationDataFormats.JSON
29+
objectMapper = objectMapper,
30+
valueTypeResolver = typeResolver,
31+
valueTypeRegistration = typeRegistration,
32+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
33+
serializationFormat = Variables.SerializationDataFormats.JSON,
34+
customValueSerializers = listOf()
2735
)
2836
).apply {
2937
this.tenantId("tenantId")

extension/core/src/test/kotlin/org/camunda/community/rest/impl/builder/RemoteExternalTaskQueryBuilderTest.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import org.camunda.community.rest.client.api.ExternalTaskApiClient
77
import org.camunda.community.rest.client.model.LockedExternalTaskDto
88
import org.camunda.community.rest.config.CamundaRestClientProperties
99
import org.camunda.community.rest.variables.ValueMapper
10+
import org.camunda.community.rest.variables.ValueTypeRegistration
1011
import org.camunda.community.rest.variables.ValueTypeResolverImpl
12+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
1113
import org.junit.Test
1214
import org.mockito.kotlin.any
1315
import org.mockito.kotlin.mock
@@ -21,13 +23,19 @@ class RemoteExternalTaskQueryBuilderTest {
2123

2224
val camundaRestClientProperties = mock<CamundaRestClientProperties>()
2325

26+
private val objectMapper = jacksonObjectMapper()
27+
private val typeResolver = ValueTypeResolverImpl()
28+
private val typeRegistration = ValueTypeRegistration()
29+
2430
val builder = RemoteExternalTaskQueryBuilder(
2531
externalTaskApiClient,
2632
valueMapper = ValueMapper(
27-
objectMapper = jacksonObjectMapper(),
28-
valueTypeResolver = ValueTypeResolverImpl(),
29-
valueMappers = emptyList(),
30-
serializationFormat = Variables.SerializationDataFormats.JSON
33+
objectMapper = objectMapper,
34+
valueTypeResolver = typeResolver,
35+
valueTypeRegistration = typeRegistration,
36+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
37+
serializationFormat = Variables.SerializationDataFormats.JSON,
38+
customValueSerializers = listOf()
3139
),
3240
camundaRestClientProperties,
3341
workerId = "workerId",

extension/variables/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
<artifactId>assertj-core</artifactId>
9494
<scope>test</scope>
9595
</dependency>
96+
<dependency>
97+
<groupId>org.camunda.spin</groupId>
98+
<artifactId>camunda-spin-dataformat-all</artifactId>
99+
<scope>test</scope>
100+
</dependency>
96101
</dependencies>
97102

98103
<profiles>

extension/variables/src/main/kotlin/org/camunda/community/rest/variables/CamundaRestClientVariablesProperties.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.camunda.community.rest.variables
22

33
import org.camunda.bpm.engine.variable.Variables.SerializationDataFormats
4+
import org.camunda.bpm.engine.variable.value.SerializationDataFormat
45
import org.springframework.boot.context.properties.ConfigurationProperties
56

67
@ConfigurationProperties("camunda.rest.client.variables")
@@ -12,7 +13,7 @@ data class CamundaRestClientVariablesProperties(
1213
*
1314
* Note: XML serialization format is not supported.
1415
*/
15-
val defaultSerializationFormat: SerializationDataFormats = SerializationDataFormats.JSON,
16+
val defaultSerializationFormat: SerializationDataFormat = SerializationDataFormats.JSON,
1617
) {
1718
init {
1819
require(SerializationDataFormats.XML != defaultSerializationFormat) {

extension/variables/src/main/kotlin/org/camunda/community/rest/variables/CustomValueMapper.kt

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,69 @@
2323

2424
package org.camunda.community.rest.variables
2525

26+
import org.camunda.bpm.engine.variable.Variables
27+
import org.camunda.bpm.engine.variable.value.SerializableValue
28+
import org.camunda.bpm.engine.variable.value.SerializationDataFormat
29+
import org.camunda.bpm.engine.variable.value.TypedValue
30+
import org.camunda.community.rest.variables.serialization.CustomValueSerializer
31+
2632
/**
27-
* Implement this interface to provide custom mapping logic.
33+
* Custom value mapper.
2834
*/
29-
interface CustomValueMapper : IValueMapper {
35+
@Deprecated(message = "Should use CustomValueSerializer instead", replaceWith = ReplaceWith("CustomValueSerializer",
36+
"org.camunda.community.rest.variables.serialization.CustomValueSerializer"))
37+
interface CustomValueMapper {
38+
39+
/**
40+
* Check method.
41+
* @param variableValue value.
42+
* @return `true`of the mapper is responsible.
43+
*/
44+
fun canHandle(variableValue: Any?): Boolean
45+
46+
/**
47+
* Maps the value into a typed value.
48+
* @param variableValue value.
49+
* @return typed representation.
50+
*/
51+
fun mapValue(variableValue: Any?): TypedValue
52+
53+
/**
54+
* Serializes the value (still returning the serializable value type).
55+
* @param variableValue value.
56+
* @return serialized representation.
57+
*/
58+
fun serializeValue(variableValue: SerializableValue): SerializableValue
59+
60+
/**
61+
* De-serializes the value.
62+
* @param variableValue serialized value.
63+
* @return typed value.
64+
*/
65+
fun deserializeValue(variableValue: SerializableValue): TypedValue
66+
67+
}
68+
69+
class CustomValueMapperAdapter(private val customValueMapper: CustomValueMapper) : CustomValueSerializer {
70+
71+
// custom value mappers probably only were JSON related
72+
override val serializationDataFormat: SerializationDataFormat = Variables.SerializationDataFormats.JSON
73+
74+
override fun serializeValue(value: TypedValue): SerializableValue {
75+
return customValueMapper.serializeValue(value as SerializableValue)
76+
}
77+
78+
override fun deserializeValue(value: SerializableValue): TypedValue {
79+
return customValueMapper.deserializeValue(value)
80+
}
81+
82+
override fun canSerializeValue(value: TypedValue): Boolean {
83+
return customValueMapper.canHandle(value)
84+
}
85+
86+
override fun canDeserializeValue(value: SerializableValue): Boolean {
87+
return customValueMapper.canHandle(value)
88+
}
89+
3090

3191
}

0 commit comments

Comments
 (0)