Improve WorkflowRepresentation.Builder, changing concurrency(true) to concurrency().cancelIfRunning() for better clarity

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
This commit is contained in:
Stefan Guilhen 2025-10-17 11:18:33 -03:00 committed by Pedro Igor
parent c4edb97e68
commit 657105bb41
3 changed files with 16 additions and 3 deletions

View File

@ -22,6 +22,10 @@ public class WorkflowConcurrencyRepresentation {
return cancelIfRunning;
}
public void setCancelIfRunning(Boolean cancelIfRunning) {
this.cancelIfRunning = cancelIfRunning;
}
@Override
public int hashCode() {
return cancelIfRunning != null ? cancelIfRunning.hashCode() : 0;

View File

@ -180,8 +180,17 @@ public final class WorkflowRepresentation extends AbstractWorkflowComponentRepre
return this;
}
public Builder concurrency(boolean cancelIfRunning) {
representation.setConcurrency(new WorkflowConcurrencyRepresentation(cancelIfRunning));
public Builder concurrency() {
representation.setConcurrency(new WorkflowConcurrencyRepresentation());
return this;
}
// move this to its own builder if we expand the capabilities of the concurrency settings.
public Builder cancelIfRunning() {
if (representation.getConcurrency() == null) {
representation.setConcurrency(new WorkflowConcurrencyRepresentation());
}
representation.getConcurrency().setCancelIfRunning(true);
return this;
}

View File

@ -92,7 +92,7 @@ public class UserSessionRefreshTimeWorkflowTest {
managedRealm.admin().workflows().create(WorkflowRepresentation.create()
.of(UserSessionRefreshTimeWorkflowProviderFactory.ID)
.onEvent(ResourceOperationType.USER_LOGIN.toString())
.concurrency(true) // this setting enables restarting the workflow
.concurrency().cancelIfRunning() // this setting enables restarting the workflow
.withSteps(
WorkflowStepRepresentation.create().of(NotifyUserStepProviderFactory.ID)
.after(Duration.ofDays(5))