Skip to content

Commit

Permalink
Execute normal action post function before split/join action
Browse files Browse the repository at this point in the history
  • Loading branch information
tedliang committed Sep 10, 2016
1 parent 6427994 commit 040f84d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<project name="workflow" default="jar" basedir=".">

<property name="compile.version" value="1.5"/>
<property name="test.compile.version" value="1.5"/>
<property name="src.test" location="src/test"/>
<property name="common.build" value="osbuild.xml"/>
Expand Down
63 changes: 34 additions & 29 deletions src/java/com/opensymphony/workflow/AbstractWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,40 @@ protected boolean transitionWorkflow(WorkflowEntry entry, List currentSteps, Wor
}
}

ActionType actionType = ActionType.resolveByResultDescriptor(theResults[0]);

// go to next step
if (theResults[0].getSplit() != 0) {
if (actionType == ActionType.NEXT) {
// normal finish, no splits or joins
long[] previousIds = null;

if (step != null) {
previousIds = new long[] {step.getId()};
}

if (!action.isFinish()) {
createNewCurrentStep(theResults[0], entry, store, action.getId(), step, previousIds, transientVars, ps);
}
}

// postFunctions (BOTH)
if (extraPostFunctions != null) {
for (Iterator iterator = extraPostFunctions.iterator();
iterator.hasNext();) {
FunctionDescriptor function = (FunctionDescriptor) iterator.next();
executeFunction(function, transientVars, ps);
}
}

List postFunctions = action.getPostFunctions();

for (Iterator iterator = postFunctions.iterator(); iterator.hasNext();) {
FunctionDescriptor function = (FunctionDescriptor) iterator.next();
executeFunction(function, transientVars, ps);
}


if (actionType == ActionType.SPLIT) {
// the result is a split request, handle it correctly
SplitDescriptor splitDesc = wf.getSplit(theResults[0].getSplit());
Collection results = splitDesc.getResults();
Expand Down Expand Up @@ -1397,7 +1429,7 @@ protected boolean transitionWorkflow(WorkflowEntry entry, List currentSteps, Wor
FunctionDescriptor function = (FunctionDescriptor) iterator.next();
executeFunction(function, transientVars, ps);
}
} else if (theResults[0].getJoin() != 0) {
} else if (actionType == ActionType.JOIN) {
// this is a join, finish this step...
JoinDescriptor joinDesc = wf.getJoin(theResults[0].getJoin());
step = store.markFinished(step, action.getId(), new Date(), theResults[0].getOldStatus(), context.getCaller());
Expand Down Expand Up @@ -1492,33 +1524,6 @@ protected boolean transitionWorkflow(WorkflowEntry entry, List currentSteps, Wor
executeFunction(function, transientVars, ps);
}
}
} else {
// normal finish, no splits or joins
long[] previousIds = null;

if (step != null) {
previousIds = new long[] {step.getId()};
}

if (!action.isFinish()) {
createNewCurrentStep(theResults[0], entry, store, action.getId(), step, previousIds, transientVars, ps);
}
}

// postFunctions (BOTH)
if (extraPostFunctions != null) {
for (Iterator iterator = extraPostFunctions.iterator();
iterator.hasNext();) {
FunctionDescriptor function = (FunctionDescriptor) iterator.next();
executeFunction(function, transientVars, ps);
}
}

List postFunctions = action.getPostFunctions();

for (Iterator iterator = postFunctions.iterator(); iterator.hasNext();) {
FunctionDescriptor function = (FunctionDescriptor) iterator.next();
executeFunction(function, transientVars, ps);
}

//if executed action was an initial action then workflow is activated
Expand Down
17 changes: 17 additions & 0 deletions src/java/com/opensymphony/workflow/ActionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.opensymphony.workflow;

import com.opensymphony.workflow.loader.ResultDescriptor;

public enum ActionType {
NEXT, SPLIT, JOIN;

public static ActionType resolveByResultDescriptor(ResultDescriptor result) {
if (result.getSplit() != 0) {
return SPLIT;
}
if (result.getJoin() != 0) {
return JOIN;
}
return NEXT;
}
}

0 comments on commit 040f84d

Please sign in to comment.