Skip to content

Commit 36631a3

Browse files
committed
Add an interface that can be customized for the variable length verifier
1 parent cdcb2b9 commit 36631a3

19 files changed

Lines changed: 145 additions & 72 deletions

File tree

modules/flowable-app-engine/src/main/java/org/flowable/app/engine/AppEngineConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ public void initVariableTypes() {
392392
}
393393
}
394394
variableTypes.addType(new NullType());
395-
variableTypes.addType(new StringType(getMaxLengthString(), maxAllowedLengthVariableType));
396-
variableTypes.addType(new LongStringType(getMaxLengthString() + 1, maxAllowedLengthVariableType));
395+
variableTypes.addType(new StringType(getMaxLengthString(), variableLengthVerifier));
396+
variableTypes.addType(new LongStringType(getMaxLengthString() + 1, variableLengthVerifier));
397397
variableTypes.addType(new BooleanType());
398398
variableTypes.addType(new ShortType());
399399
variableTypes.addType(new IntegerType());
@@ -408,12 +408,12 @@ public void initVariableTypes() {
408408
variableTypes.addType(new BigDecimalType());
409409
variableTypes.addType(new BigIntegerType());
410410
variableTypes.addType(new UUIDType());
411-
variableTypes.addType(new JsonType(getMaxLengthString(), maxAllowedLengthVariableType, objectMapper, jsonVariableTypeTrackObjects));
411+
variableTypes.addType(new JsonType(getMaxLengthString(), variableLengthVerifier, objectMapper, jsonVariableTypeTrackObjects));
412412
// longJsonType only needed for reading purposes
413-
variableTypes.addType(JsonType.longJsonType(getMaxLengthString(), maxAllowedLengthVariableType, objectMapper, jsonVariableTypeTrackObjects));
414-
variableTypes.addType(new ByteArrayType(maxAllowedLengthVariableType));
413+
variableTypes.addType(JsonType.longJsonType(getMaxLengthString(), variableLengthVerifier, objectMapper, jsonVariableTypeTrackObjects));
414+
variableTypes.addType(new ByteArrayType(variableLengthVerifier));
415415
variableTypes.addType(new EmptyCollectionType());
416-
variableTypes.addType(new SerializableType(serializableVariableTypeTrackDeserializedObjects, maxAllowedLengthVariableType));
416+
variableTypes.addType(new SerializableType(serializableVariableTypeTrackDeserializedObjects, variableLengthVerifier));
417417
if (customPostVariableTypes != null) {
418418
for (VariableType customVariableType : customPostVariableTypes) {
419419
variableTypes.addType(customVariableType);

modules/flowable-app-rest/src/test/java/org/flowable/rest/app/variable/MaxAllowedShortStringVariableLengthTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.flowable.cmmn.engine.test.CmmnDeployment;
2424
import org.flowable.cmmn.spring.impl.test.FlowableCmmnSpringExtension;
2525
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
26+
import org.flowable.common.engine.impl.variable.MaxAllowedLengthVariableVerifier;
2627
import org.flowable.engine.RuntimeService;
2728
import org.flowable.engine.TaskService;
2829
import org.flowable.engine.runtime.ProcessInstance;
@@ -181,7 +182,7 @@ static class CustomConfiguration {
181182
@Bean
182183
public EngineConfigurationConfigurer<SpringAppEngineConfiguration> customAppEngineConfigurationConfigurer() {
183184
return appEngineConfiguration -> {
184-
appEngineConfiguration.setMaxAllowedLengthVariableType(500);
185+
appEngineConfiguration.setVariableLengthVerifier(new MaxAllowedLengthVariableVerifier(500));
185186
};
186187
}
187188
}

modules/flowable-app-rest/src/test/java/org/flowable/rest/app/variable/MaxAllowedVariableLengthTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.flowable.cmmn.engine.test.CmmnDeployment;
3030
import org.flowable.cmmn.spring.impl.test.FlowableCmmnSpringExtension;
3131
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
32+
import org.flowable.common.engine.impl.variable.MaxAllowedLengthVariableVerifier;
3233
import org.flowable.engine.RuntimeService;
3334
import org.flowable.engine.TaskService;
3435
import org.flowable.engine.runtime.ProcessInstance;
@@ -302,7 +303,7 @@ static class CustomConfiguration {
302303
@Bean
303304
public EngineConfigurationConfigurer<SpringAppEngineConfiguration> customAppEngineConfigurationConfigurer() {
304305
return appEngineConfiguration -> {
305-
appEngineConfiguration.setMaxAllowedLengthVariableType(5000);
306+
appEngineConfiguration.setVariableLengthVerifier(new MaxAllowedLengthVariableVerifier(5000));
306307
};
307308
}
308309
}

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/CmmnEngineConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,8 +1395,8 @@ public void initVariableTypes() {
13951395
}
13961396
}
13971397
variableTypes.addType(new NullType());
1398-
variableTypes.addType(new StringType(getMaxLengthString(), maxAllowedLengthVariableType));
1399-
variableTypes.addType(new LongStringType(getMaxLengthString() + 1, maxAllowedLengthVariableType));
1398+
variableTypes.addType(new StringType(getMaxLengthString(), variableLengthVerifier));
1399+
variableTypes.addType(new LongStringType(getMaxLengthString() + 1, variableLengthVerifier));
14001400
variableTypes.addType(new BooleanType());
14011401
variableTypes.addType(new ShortType());
14021402
variableTypes.addType(new IntegerType());
@@ -1411,13 +1411,13 @@ public void initVariableTypes() {
14111411
variableTypes.addType(new BigDecimalType());
14121412
variableTypes.addType(new BigIntegerType());
14131413
variableTypes.addType(new UUIDType());
1414-
variableTypes.addType(new JsonType(getMaxLengthString(), maxAllowedLengthVariableType, objectMapper, jsonVariableTypeTrackObjects));
1414+
variableTypes.addType(new JsonType(getMaxLengthString(), variableLengthVerifier, objectMapper, jsonVariableTypeTrackObjects));
14151415
// longJsonType only needed for reading purposes
1416-
variableTypes.addType(JsonType.longJsonType(getMaxLengthString(), maxAllowedLengthVariableType, objectMapper, jsonVariableTypeTrackObjects));
1416+
variableTypes.addType(JsonType.longJsonType(getMaxLengthString(), variableLengthVerifier, objectMapper, jsonVariableTypeTrackObjects));
14171417
variableTypes.addType(new CmmnAggregatedVariableType(this));
1418-
variableTypes.addType(new ByteArrayType(maxAllowedLengthVariableType));
1418+
variableTypes.addType(new ByteArrayType(variableLengthVerifier));
14191419
variableTypes.addType(new EmptyCollectionType());
1420-
variableTypes.addType(new SerializableType(serializableVariableTypeTrackDeserializedObjects, maxAllowedLengthVariableType));
1420+
variableTypes.addType(new SerializableType(serializableVariableTypeTrackDeserializedObjects, variableLengthVerifier));
14211421

14221422
} else {
14231423
if (customPreVariableTypes != null) {

modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/runtime/MaxAllowedShortStringVariableLengthTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.flowable.cmmn.engine.test.CmmnDeployment;
2222
import org.flowable.cmmn.test.impl.CustomCmmnConfigurationFlowableTestCase;
2323
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
24+
import org.flowable.common.engine.impl.variable.MaxAllowedLengthVariableVerifier;
2425
import org.flowable.task.api.Task;
2526
import org.junit.Test;
2627

@@ -36,7 +37,7 @@ protected String getEngineName() {
3637

3738
@Override
3839
protected void configureConfiguration(CmmnEngineConfiguration cmmnEngineConfiguration) {
39-
cmmnEngineConfiguration.setMaxAllowedLengthVariableType(500);
40+
cmmnEngineConfiguration.setVariableLengthVerifier(new MaxAllowedLengthVariableVerifier(500));
4041
}
4142

4243
@Test

modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/runtime/MaxAllowedVariableLengthTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.flowable.cmmn.engine.test.CmmnDeployment;
2828
import org.flowable.cmmn.test.impl.CustomCmmnConfigurationFlowableTestCase;
2929
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
30+
import org.flowable.common.engine.impl.variable.MaxAllowedLengthVariableVerifier;
3031
import org.flowable.task.api.Task;
3132
import org.junit.Test;
3233

@@ -44,7 +45,7 @@ protected String getEngineName() {
4445

4546
@Override
4647
protected void configureConfiguration(CmmnEngineConfiguration cmmnEngineConfiguration) {
47-
cmmnEngineConfiguration.setMaxAllowedLengthVariableType(5000);
48+
cmmnEngineConfiguration.setVariableLengthVerifier(new MaxAllowedLengthVariableVerifier(5000));
4849
}
4950

5051
@Test

modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
import org.flowable.common.engine.impl.util.DefaultClockImpl;
123123
import org.flowable.common.engine.impl.util.IoUtil;
124124
import org.flowable.common.engine.impl.util.ReflectUtil;
125+
import org.flowable.common.engine.impl.variable.NoopVariableLengthVerifier;
126+
import org.flowable.common.engine.impl.variable.VariableLengthVerifier;
125127
import org.flowable.eventregistry.api.EventRegistryEventConsumer;
126128
import org.slf4j.Logger;
127129
import org.slf4j.LoggerFactory;
@@ -401,10 +403,10 @@ public static Properties getDefaultDatabaseTypeMappings() {
401403
protected int maxLengthStringVariableType = -1;
402404

403405
/**
404-
* Define a max allowed length for storing large variables, e.g. String, JSON, etc. in the database.
405-
* If the length of the variable exceeds this value, there will be an exception thrown when trying to store the variable.
406+
* Define variable length for variables that have length, e.g. String, JSON, etc.
407+
* The length verifier can be used to throw an exception if the length exceeds a certain threshold and / or it can log a warning.
406408
*/
407-
protected int maxAllowedLengthVariableType = -1;
409+
protected VariableLengthVerifier variableLengthVerifier = NoopVariableLengthVerifier.INSTANCE;
408410

409411
protected void initEngineConfigurations() {
410412
addEngineConfiguration(getEngineCfgKey(), getEngineScopeType(), this);
@@ -1941,12 +1943,12 @@ public AbstractEngineConfiguration setMaxLengthStringVariableType(int maxLengthS
19411943
return this;
19421944
}
19431945

1944-
public int getMaxAllowedLengthVariableType() {
1945-
return maxAllowedLengthVariableType;
1946+
public VariableLengthVerifier getVariableLengthVerifier() {
1947+
return variableLengthVerifier;
19461948
}
19471949

1948-
public AbstractEngineConfiguration setMaxAllowedLengthVariableType(int maxAllowedLengthVariableType) {
1949-
this.maxAllowedLengthVariableType = maxAllowedLengthVariableType;
1950+
public AbstractEngineConfiguration setVariableLengthVerifier(VariableLengthVerifier variableLengthVerifier) {
1951+
this.variableLengthVerifier = variableLengthVerifier;
19501952
return this;
19511953
}
19521954

modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/util/VariableTypeUtils.java renamed to modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/variable/MaxAllowedLengthVariableVerifier.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,31 @@
1010
* See the License for the specific language governing permissions and
1111
* limitations under the License.
1212
*/
13-
package org.flowable.variable.service.impl.util;
13+
package org.flowable.common.engine.impl.variable;
1414

1515
import org.apache.commons.lang3.StringUtils;
1616
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
17-
import org.flowable.common.engine.api.FlowableIllegalStateException;
1817
import org.flowable.common.engine.api.scope.ScopeTypes;
1918
import org.flowable.variable.api.types.ValueFields;
2019
import org.flowable.variable.api.types.VariableType;
2120

2221
/**
2322
* @author Filip Hrisafov
2423
*/
25-
public class VariableTypeUtils {
24+
public class MaxAllowedLengthVariableVerifier implements VariableLengthVerifier {
2625

27-
public static void validateMaxAllowedLength(int maxAllowedLength, int length, ValueFields valueFields, VariableType variableType) {
28-
if (maxAllowedLength < 0) {
29-
return;
26+
protected final int maxAllowedLength;
27+
28+
public MaxAllowedLengthVariableVerifier(int maxAllowedLength) {
29+
if (maxAllowedLength <= 0) {
30+
throw new FlowableIllegalArgumentException("The maximum allowed length must be greater than 0");
3031
}
32+
this.maxAllowedLength = maxAllowedLength;
33+
}
3134

32-
if (maxAllowedLength > 0 && length > maxAllowedLength) {
35+
@Override
36+
public void verifyLength(int length, ValueFields valueFields, VariableType variableType) {
37+
if (length > maxAllowedLength) {
3338
String scopeId;
3439
String scopeType;
3540
if (StringUtils.isNotEmpty(valueFields.getTaskId())) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.common.engine.impl.variable;
14+
15+
import org.flowable.variable.api.types.ValueFields;
16+
import org.flowable.variable.api.types.VariableType;
17+
18+
/**
19+
* @author Filip Hrisafov
20+
*/
21+
public class NoopVariableLengthVerifier implements VariableLengthVerifier {
22+
23+
public static final VariableLengthVerifier INSTANCE = new NoopVariableLengthVerifier();
24+
25+
@Override
26+
public void verifyLength(int length, ValueFields valueFields, VariableType variableType) {
27+
// Nothing to do
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.common.engine.impl.variable;
14+
15+
import org.flowable.variable.api.types.ValueFields;
16+
import org.flowable.variable.api.types.VariableType;
17+
18+
/**
19+
* @author Filip Hrisafov
20+
*/
21+
public interface VariableLengthVerifier {
22+
23+
void verifyLength(int length, ValueFields valueFields, VariableType variableType);
24+
25+
}

0 commit comments

Comments
 (0)