@Override
public String addWorkflow(Workflow workflow) throws RepositoryException {
// first check to see that its tasks are all present
if (workflow.getTasks() == null
|| (workflow.getTasks() != null && workflow.getTasks().size() == 0)) {
throw new RepositoryException("Attempt to define a new worklfow: ["
+ workflow.getName() + "] with no tasks.");
}
List<WorkflowTask> allTasks = this.getTasks();
for (WorkflowTask task : (List<WorkflowTask>) workflow.getTasks()) {
if (!this.hasTaskId(allTasks, task.getTaskId())) {
throw new RepositoryException("Reference in new workflow: ["
+ workflow.getName() + "] to undefined task with id: ["
+ task.getTaskId() + "]");
}
// check its conditions
if (task.getConditions() != null && task.getConditions().size() > 0) {
List<WorkflowCondition> conditions = this.getConditionsByTaskId(task
.getTaskId());
for (WorkflowCondition cond : (List<WorkflowCondition>) task
.getConditions()) {
if (!this.hasConditionId(conditions, cond.getConditionId())) {
throw new RepositoryException("Reference in new workflow: ["
+ workflow.getName() + "] to undefined condition ith id: ["
+ cond.getConditionId() + "]");
}
}
}