public void start(String activityId) throws WfException, CannotStart, AlreadyRunning {
if (state().equals("open.running"))
throw new AlreadyRunning("Process is already running");
if (activityId == null && getDefinitionObject().get("defaultStartActivityId") == null)
throw new CannotStart("Initial activity is not defined.");
changeState("open.running");
// start the first activity (using the defaultStartActivityId)
GenericValue start = null;
try {
if (activityId != null) {
GenericValue processDef = getDefinitionObject();
Map<String, Object> fields = UtilMisc.toMap("packageId", (Object) processDef.getString("packageId"), "packageVersion",
processDef.getString("packageVersion"), "processId", processDef.getString("processId"),
"processVersion", processDef.getString("processVersion"), "activityId", activityId);
start = getDelegator().findByPrimaryKey("WorkflowActivity", fields);
// here we must check and make sure this activity is defined to as a starting activity
if (!start.getBoolean("canStart").booleanValue())
throw new CannotStart("The specified activity cannot initiate the workflow process");
} else {
// this is either the first activity defined or specified as an ExtendedAttribute
// since this is defined in XPDL, we don't care if canStart is set.
start = getDefinitionObject().getRelatedOne("DefaultStartWorkflowActivity");
}
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e.getNested());
}
if (start == null)
throw new CannotStart("No initial activity available");
if (Debug.verboseOn())
Debug.logVerbose("[WfProcess.start] : Started the workflow process.", module);
// set the actualStartDate