Skip to content
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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

AkhileshPamidimarthi
Copy link
Contributor

@AkhileshPamidimarthi AkhileshPamidimarthi commented May 10, 2024

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation
  • Other... Please describe:

Description

Added logic to validate the cardinality

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

@AkhileshPamidimarthi AkhileshPamidimarthi marked this pull request as ready for review May 10, 2024 14:08
Copy link
Contributor

@eromano eromano left a 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";
Copy link
Contributor

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,
Copy link
Contributor

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

@AkhileshPamidimarthi AkhileshPamidimarthi force-pushed the fix/AAE-22465_Cannot_execute_many_parallel_tasks_ branch from 129183d to c14cc6c Compare May 28, 2024 11:09
if(!StringUtils.isEmpty(multiInstanceLoopCharacteristics.getLoopCardinality())){
try {
int loopCardinality= Integer.parseInt(multiInstanceLoopCharacteristics.getLoopCardinality());
if(loopCardinality >200){
Copy link
Contributor

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}")
Copy link
Contributor

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.

Suggested change
@Value("${loop.cardinality.threshold}")
@Value("${activiti.loop.cardinality.threshold:200}")

@@ -0,0 +1 @@
loop.cardinality.threshold=200
Copy link
Contributor

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

@jesty
Copy link
Contributor

jesty commented Jun 3, 2024

I would prefer review our approach here with @gicappa @igdianov @erdemedeiros, let's have a call next week

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.

Copy link
Contributor

@igdianov igdianov left a 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>
Copy link
Contributor

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}")
Copy link
Contributor

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.

Comment on lines -40 to -94
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");
}
}
}
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants