* @return The new assignment object.
* @throws WfException
*/
public WfAssignment delegate(String workEffortId, String fromPartyId, String fromRoleTypeId, Timestamp fromFromDate, String toPartyId, String toRoleTypeId, Timestamp toFromDate) throws WfException {
WfActivity activity = WfFactory.getWfActivity(delegator, workEffortId);
WfAssignment fromAssign = null;
// check status and delegateAfterStart attribute
if (activity.state().equals("open.running") && !activity.getDefinitionObject().getBoolean("delegateAfterStart").booleanValue())
throw new WfException("This activity cannot be delegated once it has been started");
if (fromPartyId == null && fromRoleTypeId == null && fromFromDate == null) {
Iterator<WfAssignment> i = activity.getIteratorAssignment();
fromAssign = i.next();
if (i.hasNext()) {
throw new WfException("Cannot locate the assignment to delegate from, there is more then one " +
"assignment for this activity.");
}
}
if (fromAssign == null) {
fromAssign = WfFactory.getWfAssignment(delegator, workEffortId, fromPartyId, fromRoleTypeId, fromFromDate);
}
fromAssign.delegate();
// check for a restartOnDelegate
WfActivity newActivity = null;
if (activity.getDefinitionObject().getBoolean("restartOnDelegate").booleanValue()) {
// this only applies to running single assignment activities
if (activity.state().equals("open.running") && activity.howManyAssignment() == 0) {
try {
activity.abort();
} catch (CannotStop cs) {
throw new WfException("Cannot stop the current activity");
} catch (NotRunning nr) {
throw new WfException("Current activity is not running; cannot abort");
}
String parentProcessId = activity.container().runtimeKey();
newActivity = WfFactory.getWfActivity(activity.getDefinitionObject(), parentProcessId);
}
}
WfAssignment assign = null;
if (newActivity != null) {
assign = assign(newActivity.runtimeKey(), toPartyId, toRoleTypeId, toFromDate, true);
} else {
assign = assign(workEffortId, toPartyId, toRoleTypeId, toFromDate, true);
}