-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AAE-22465 Added logic to validate the cardinality #4654
base: develop
Are you sure you want to change the base?
AAE-22465 Added logic to validate the cardinality #4654
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer review our approach here with @gicappa @igdianov @erdemedeiros, let's have a call next week
@@ -100,6 +100,7 @@ public interface Problems { | |||
String THROW_EVENT_INVALID_EVENTDEFINITION = "activiti-throw-event-invalid-eventdefinition"; | |||
|
|||
String MULTI_INSTANCE_MISSING_COLLECTION = "activiti-multi-instance-missing-collection"; | |||
String MULTI_INSTANCE_HIGHER_CARDINALITY = "activiti-multi-instance-cardinality-greater-than-200"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u fix formatting? Thanks!
try { | ||
int loopCardinality= Integer.parseInt(multiInstanceLoopCharacteristics.getLoopCardinality()); | ||
if(loopCardinality >200){ | ||
addError(errors, Problems.MULTI_INSTANCE_HIGHER_CARDINALITY, process, activity, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please replace addError with addWarning
129183d
to
c14cc6c
Compare
if(!StringUtils.isEmpty(multiInstanceLoopCharacteristics.getLoopCardinality())){ | ||
try { | ||
int loopCardinality= Integer.parseInt(multiInstanceLoopCharacteristics.getLoopCardinality()); | ||
if(loopCardinality >200){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we extract the value in an external property? thanks
} | ||
} | ||
protected static final int ID_MAX_LENGTH = 255; | ||
@Value("${loop.cardinality.threshold}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a blank new line above, prefix it with acitivi and specify the default value here.
@Value("${loop.cardinality.threshold}") | |
@Value("${activiti.loop.cardinality.threshold:200}") |
@@ -0,0 +1 @@ | |||
loop.cardinality.threshold=200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specifying the default value, then, we can remove it
Hi @eromano we changed to warning. @gicappa @igdianov @erdemedeiros what do you think? I asked to add a warning because in my tests I noticed that when we have many parallelel task to create we can face 500 errors because the operation it's going to be really long. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jesty Could add unit tests to make sure there is coverage against future regressions?
@@ -37,5 +37,9 @@ | |||
<artifactId>assertj-core</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really needed to include the dependency from Spring in the core engine?
} | ||
protected static final int ID_MAX_LENGTH = 255; | ||
|
||
@Value("${loop.cardinality.threshold:200}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a good practice to use Spring value injection. The core validation configuration approach should not rely on Spring field injection to configure parameter limits.
protected static final int ID_MAX_LENGTH = 255; | ||
|
||
@Override | ||
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) { | ||
for (FlowElement flowElement : process.getFlowElements()) { | ||
|
||
if (flowElement instanceof Activity) { | ||
Activity activity = (Activity) flowElement; | ||
handleConstraints(process, activity, errors); | ||
handleMultiInstanceLoopCharacteristics(process, activity, errors); | ||
handleDataAssociations(process, activity, errors); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
protected void handleConstraints(Process process, Activity activity, List<ValidationError> errors) { | ||
if (activity.getId() != null && activity.getId().length() > ID_MAX_LENGTH) { | ||
addError(errors, Problems.FLOW_ELEMENT_ID_TOO_LONG, process, activity, | ||
"The id of a flow element must not contain more than " + ID_MAX_LENGTH + " characters"); | ||
} | ||
} | ||
|
||
protected void handleMultiInstanceLoopCharacteristics(Process process, Activity activity, List<ValidationError> errors) { | ||
MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = activity.getLoopCharacteristics(); | ||
if (multiInstanceLoopCharacteristics != null) { | ||
|
||
if (StringUtils.isEmpty(multiInstanceLoopCharacteristics.getLoopCardinality()) | ||
&& StringUtils.isEmpty(multiInstanceLoopCharacteristics.getInputDataItem())) { | ||
|
||
addError(errors, Problems.MULTI_INSTANCE_MISSING_COLLECTION, process, activity, | ||
"Either loopCardinality or loopDataInputRef/activiti:collection must been set"); | ||
} | ||
|
||
} | ||
} | ||
|
||
protected void handleDataAssociations(Process process, Activity activity, List<ValidationError> errors) { | ||
if (activity.getDataInputAssociations() != null) { | ||
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) { | ||
if (StringUtils.isEmpty(dataAssociation.getTargetRef())) { | ||
addError(errors, Problems.DATA_ASSOCIATION_MISSING_TARGETREF, process, activity, | ||
"Targetref is required on a data association"); | ||
} | ||
} | ||
} | ||
if (activity.getDataOutputAssociations() != null) { | ||
for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) { | ||
if (StringUtils.isEmpty(dataAssociation.getTargetRef())) { | ||
addError(errors, Problems.DATA_ASSOCIATION_MISSING_TARGETREF, process, activity, | ||
"Targetref is required on a data association"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you restore original indents to keep the formatting consistent for easier code review?
What kind of change does this PR introduce?
Description
Added logic to validate the cardinality
Does this PR introduce a breaking change? (check one with "x")