Skip to content

Commit

Permalink
fix(asyncInstanceModification): respect ancestor during startBefore/a…
Browse files Browse the repository at this point in the history
…fter cmd execution

related to #4507
  • Loading branch information
PHWaechtler committed Dec 3, 2024
1 parent 824b35f commit d5a4999
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public VariableMap getVariablesLocal() {
return variablesLocal;
}

public String getAncestorActivityInstanceId() {
return ancestorActivityInstanceId;
}

public void setAncestorActivityInstanceId(String ancestorActivityInstanceId) {
this.ancestorActivityInstanceId = ancestorActivityInstanceId;
}

public Void execute(final CommandContext commandContext) {
ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);

Expand Down Expand Up @@ -326,7 +334,6 @@ else if (PvmActivity.class.isAssignableFrom(targetElement.getClass())) {
}
}


protected void instantiateConcurrent(ExecutionEntity ancestorScopeExecution, List<PvmActivity> parentFlowScopes, CoreModelElement targetElement) {
if (PvmTransition.class.isAssignableFrom(targetElement.getClass())) {
ancestorScopeExecution.executeActivitiesConcurrent(parentFlowScopes, null, (PvmTransition) targetElement, variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.camunda.bpm.engine.impl.json;

import com.google.gson.JsonObject;
import org.camunda.bpm.engine.impl.cmd.AbstractProcessInstanceModificationCommand;
import org.camunda.bpm.engine.impl.cmd.ActivityAfterInstantiationCmd;
import org.camunda.bpm.engine.impl.cmd.ActivityBeforeInstantiationCmd;
Expand All @@ -24,7 +25,6 @@
import org.camunda.bpm.engine.impl.cmd.TransitionInstanceCancellationCmd;
import org.camunda.bpm.engine.impl.cmd.TransitionInstantiationCmd;
import org.camunda.bpm.engine.impl.util.JsonUtil;
import com.google.gson.JsonObject;

public class ModificationCmdJsonConverter extends JsonObjectConverter<AbstractProcessInstanceModificationCommand> {

Expand All @@ -38,30 +38,33 @@ public class ModificationCmdJsonConverter extends JsonObjectConverter<AbstractPr
public static final String CANCEL_ACTIVITY_INSTANCES = "cancelActivityInstances";
public static final String PROCESS_INSTANCE = "processInstances";
public static final String CANCEL_TRANSITION_INSTANCES = "cancelTransitionInstances";
public static final String ANCESTOR_ACTIVITY_INSTANCE_ID = "ancestorActivityInstanceId";

@Override
public JsonObject toJsonObject(AbstractProcessInstanceModificationCommand command) {
JsonObject json = JsonUtil.createObject();

if (command instanceof ActivityAfterInstantiationCmd) {
JsonUtil.addField(json, START_AFTER, ((ActivityAfterInstantiationCmd) command).getTargetElementId());
}
else if (command instanceof ActivityBeforeInstantiationCmd) {
JsonUtil.addField(json, ANCESTOR_ACTIVITY_INSTANCE_ID,
((ActivityAfterInstantiationCmd) command).getAncestorActivityInstanceId());
} else if (command instanceof ActivityBeforeInstantiationCmd) {
JsonUtil.addField(json, START_BEFORE, ((ActivityBeforeInstantiationCmd) command).getTargetElementId());
}
else if (command instanceof TransitionInstantiationCmd) {
JsonUtil.addField(json, ANCESTOR_ACTIVITY_INSTANCE_ID,
((ActivityBeforeInstantiationCmd) command).getAncestorActivityInstanceId());
} else if (command instanceof TransitionInstantiationCmd) {
JsonUtil.addField(json, START_TRANSITION, ((TransitionInstantiationCmd) command).getTargetElementId());
}
else if (command instanceof ActivityCancellationCmd) {
} else if (command instanceof ActivityCancellationCmd) {
JsonUtil.addField(json, CANCEL_ALL, ((ActivityCancellationCmd) command).getActivityId());
JsonUtil.addField(json, CANCEL_CURRENT, ((ActivityCancellationCmd) command).isCancelCurrentActiveActivityInstances());
}
else if (command instanceof ActivityInstanceCancellationCmd) {
JsonUtil.addField(json, CANCEL_ACTIVITY_INSTANCES, ((ActivityInstanceCancellationCmd) command).getActivityInstanceId());
JsonUtil.addField(json, CANCEL_CURRENT,
((ActivityCancellationCmd) command).isCancelCurrentActiveActivityInstances());
} else if (command instanceof ActivityInstanceCancellationCmd) {
JsonUtil.addField(json, CANCEL_ACTIVITY_INSTANCES,
((ActivityInstanceCancellationCmd) command).getActivityInstanceId());
JsonUtil.addField(json, PROCESS_INSTANCE, ((ActivityInstanceCancellationCmd) command).getProcessInstanceId());
}
else if (command instanceof TransitionInstanceCancellationCmd) {
JsonUtil.addField(json, CANCEL_TRANSITION_INSTANCES, ((TransitionInstanceCancellationCmd) command).getTransitionInstanceId());
} else if (command instanceof TransitionInstanceCancellationCmd) {
JsonUtil.addField(json, CANCEL_TRANSITION_INSTANCES,
((TransitionInstanceCancellationCmd) command).getTransitionInstanceId());
JsonUtil.addField(json, PROCESS_INSTANCE, ((TransitionInstanceCancellationCmd) command).getProcessInstanceId());
}

Expand All @@ -75,23 +78,24 @@ public AbstractProcessInstanceModificationCommand toObject(JsonObject json) {

if (json.has(START_BEFORE)) {
cmd = new ActivityBeforeInstantiationCmd(JsonUtil.getString(json, START_BEFORE));
}
else if (json.has(START_AFTER)) {
((ActivityBeforeInstantiationCmd) cmd).setAncestorActivityInstanceId(
JsonUtil.getString(json, ANCESTOR_ACTIVITY_INSTANCE_ID));
} else if (json.has(START_AFTER)) {
cmd = new ActivityAfterInstantiationCmd(JsonUtil.getString(json, START_AFTER));
}
else if (json.has(START_TRANSITION)) {
((ActivityAfterInstantiationCmd) cmd).setAncestorActivityInstanceId(
JsonUtil.getString(json, ANCESTOR_ACTIVITY_INSTANCE_ID));
} else if (json.has(START_TRANSITION)) {
cmd = new TransitionInstantiationCmd(JsonUtil.getString(json, START_TRANSITION));
}
else if (json.has(CANCEL_ALL)) {
} else if (json.has(CANCEL_ALL)) {
cmd = new ActivityCancellationCmd(JsonUtil.getString(json, CANCEL_ALL));
boolean cancelCurrentActiveActivityInstances = JsonUtil.getBoolean(json, CANCEL_CURRENT);
((ActivityCancellationCmd) cmd).setCancelCurrentActiveActivityInstances(cancelCurrentActiveActivityInstances);
}
else if (json.has(CANCEL_ACTIVITY_INSTANCES)) {
cmd = new ActivityInstanceCancellationCmd(JsonUtil.getString(json, PROCESS_INSTANCE), JsonUtil.getString(json, CANCEL_ACTIVITY_INSTANCES));
}
else if (json.has(CANCEL_TRANSITION_INSTANCES)) {
cmd = new TransitionInstanceCancellationCmd(JsonUtil.getString(json, PROCESS_INSTANCE), JsonUtil.getString(json, CANCEL_TRANSITION_INSTANCES));
} else if (json.has(CANCEL_ACTIVITY_INSTANCES)) {
cmd = new ActivityInstanceCancellationCmd(JsonUtil.getString(json, PROCESS_INSTANCE),
JsonUtil.getString(json, CANCEL_ACTIVITY_INSTANCES));
} else if (json.has(CANCEL_TRANSITION_INSTANCES)) {
cmd = new TransitionInstanceCancellationCmd(JsonUtil.getString(json, PROCESS_INSTANCE),
JsonUtil.getString(json, CANCEL_TRANSITION_INSTANCES));
}

return cmd;
Expand Down
Loading

0 comments on commit d5a4999

Please sign in to comment.