public TransitionImpl DelegateDecision(DelegationImpl delegation, ExecutionContextImpl executionContext) { TransitionImpl selectedTransition = null; try { IDecisionHandler decision = (IDecisionHandler)GetDelegate(delegation); executionContext.SetConfiguration(ParseConfiguration(delegation)); String transitionName = decision.Decide(executionContext); if ((Object)transitionName == null) { throw new SystemException("Decision-delegate for decision '" + executionContext.GetNode() + "' returned null instead of a transition-name : " + decision.GetType().FullName); } try { Object[] args = new Object[] { executionContext.GetNode().Id, transitionName }; IType[] types = new IType[] { DbType.LONG, DbType.STRING }; selectedTransition = (TransitionImpl)executionContext.DbSession.FindOne(queryFindLeavingTransitionByName, args, types); } catch (Exception t) { throw new SystemException("couldn't find transition '" + transitionName + "' that was selected by the decision-delegate of activity '" + executionContext.GetNode().Name + "' : " + t.Message); } } catch (Exception t) { HandleException(delegation, executionContext, t); } return(selectedTransition); }
public void DelegateFork(DelegationImpl delegation, ExecutionContextImpl executionContext) { try { // delegate the fork IForkHandler forker = (IForkHandler)delegation.GetDelegate(); executionContext.SetConfiguration(ParseConfiguration(delegation)); forker.Fork(executionContext); } catch (Exception t) { HandleException(delegation, executionContext, t); } }
public void DelegateAction(DelegationImpl delegation, ExecutionContextImpl executionContext) { try { executionContext.CreateLog(EventType.ACTION); executionContext.AddLogDetail(new DelegateCallImpl(delegation, typeof(IAction))); IActionHandler actionHandler = (IActionHandler)GetDelegate(delegation); executionContext.SetConfiguration(ParseConfiguration(delegation)); actionHandler.Run(executionContext); } catch (Exception t) { HandleException(delegation, executionContext, t); } }
public Object ResolveArgumentRole(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext) { if (parameters.Length != 1) { throw new SystemException("argument role expects exactly one parameter (role-name) instead of " + parameters.Length); } IActor actor = null; if (resolvedActor == null) { try { actor = (IActor)executionContext.GetAttribute(parameters[0]); } catch (InvalidCastException e) { throw new SystemException("argument attribute(" + parameters[0] + ") does not contain an actor : " + executionContext.GetAttribute(parameters[0]).GetType().FullName, e); } } else { String roleName = parameters[0].Trim(); try { IList users = executionContext.GetOrganisationComponent().FindUsersByGroupAndRole(resolvedActor.Id, roleName); if (users.Count < 1) { throw new SystemException("no users have role " + roleName + " for group " + resolvedActor.Id); } actor = (IUser)users[0]; // TODO : create a new group if more then one user is returned on the query... } catch (InvalidCastException e) { throw new SystemException("can't resolve role-argument : a role must be calculated from a Group, not a " + resolvedActor.GetType().FullName, e); } catch (OrganisationRuntimeException e) { throw new SystemException("can't resolve role-argument : can't find the users that perform role " + roleName + " for group " + resolvedActor.Id + " : " + e.Message); } } return(actor); }
public String DelegateAssignment(DelegationImpl delegation, ExecutionContextImpl executionContext) { String actorId = null; try { IAssignmentHandler assigner = (IAssignmentHandler)delegation.GetDelegate(); executionContext.SetConfiguration(ParseConfiguration(delegation)); actorId = assigner.SelectActor(executionContext); } catch (Exception t) { HandleException(delegation, executionContext, t); } return(actorId); }
public bool DelegateJoin(DelegationImpl delegation, ExecutionContextImpl executionContext) { bool reactivateParent = false; try { IJoinHandler joiner = (IJoinHandler)delegation.GetDelegate(); executionContext.SetConfiguration(ParseConfiguration(delegation)); reactivateParent = joiner.Join(executionContext); } catch (Exception t) { HandleException(delegation, executionContext, t); } return(reactivateParent); }
public Object[] DelegateProcessTermination(DelegationImpl delegation, ExecutionContextImpl executionContext) { Object[] completionData = new Object[2]; try { IProcessInvocationHandler processInvoker = (IProcessInvocationHandler)delegation.GetDelegate(); log.Debug("collecting results from the sub-process..."); executionContext.SetConfiguration(ParseConfiguration(delegation)); completionData[0] = processInvoker.CollectResults(executionContext); completionData[1] = processInvoker.GetCompletionTransitionName(executionContext); } catch (Exception t) { HandleException(delegation, executionContext, t); } return(completionData); }
public Object[] DelegateProcessInvocation(DelegationImpl delegation, ExecutionContextImpl executionContext) { Object[] invocationData = new Object[2]; try { IProcessInvocationHandler processInvoker = (IProcessInvocationHandler)delegation.GetDelegate(); log.Debug("requesting the attributeValues from the process invoker..."); executionContext.SetConfiguration(ParseConfiguration(delegation)); invocationData[0] = processInvoker.GetStartTransitionName(executionContext); invocationData[1] = processInvoker.GetStartAttributeValues(executionContext); log.Debug("process invoker specified transition '" + invocationData[0] + "' and supplied attributeValues '" + invocationData[1] + "'"); } catch (Exception t) { HandleException(delegation, executionContext, t); } return(invocationData); }
public void RunActionsForEvent(EventType eventType, long definitionObjectId, ExecutionContextImpl executionContext, DbSession dbSession) { log.Debug("processing '" + eventType + "' events for executionContext " + executionContext); // find all actions for definitionObject on the given eventType Object[] values = new Object[] { eventType, definitionObjectId }; IType[] types = new IType[] { DbType.INTEGER, DbType.LONG }; IList actions = dbSession.Find(queryFindActionsByEventType, values, types); IEnumerator iter = actions.GetEnumerator(); log.Debug("list" + actions); while (iter.MoveNext()) { ActionImpl action = (ActionImpl)iter.Current; log.Debug("action: " + action); delegationHelper.DelegateAction(action.ActionDelegation, executionContext); } log.Debug("ende runActionsForEvent!"); }
public void DelegateScheduledAction(DelegationImpl delegation, ExecutionContextImpl executionContext) { try { /* can't add logs because of a integritiy constraint violation... * can you find why ? */ if (executionContext.GetFlow() != null) { executionContext.CreateLog(EventType.ACTION); executionContext.AddLogDetail(new DelegateCallImpl(delegation, typeof(IAction))); } IActionHandler actionHandler = (IActionHandler)GetDelegate(delegation); executionContext.SetConfiguration(ParseConfiguration(delegation)); actionHandler.Run(executionContext); } catch (Exception t) { HandleException(delegation, executionContext, t); } }
private void HandleException(DelegationImpl delegation, ExecutionContextImpl executionContext, Exception exception) { log.Debug("handling delegation exception :", exception); String exceptionClassName = exception.GetType().FullName; String delegationClassName = delegation.ClassName; ExceptionHandlingType exceptionHandlingType = delegation.ExceptionHandlingType; if (exceptionHandlingType != 0) { if (exceptionHandlingType == ExceptionHandlingType.IGNORE) { log.Debug("ignoring '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); } else if (exceptionHandlingType == ExceptionHandlingType.LOG) { log.Debug("logging '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); executionContext.AddLogDetail(new ExceptionReportImpl(exception)); } else if (exceptionHandlingType == ExceptionHandlingType.ROLLBACK) { log.Debug("rolling back for '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); throw new SystemException("rolling back for '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); } else { throw new SystemException("unknown exception handler '" + exceptionHandlingType + "' : " + exception.Message); } } else { log.Debug("'" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); executionContext.AddLogDetail(new ExceptionReportImpl(exception)); } }
public Object ResolveArgumentParentGroup(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext) { if (parameters.Length != 0) { throw new SystemException("argument parentGroup expects exactly zero parameters instead of " + parameters.Length); } IGroup group = null; try { group = (IGroup)resolvedActor; group = group.Parent; } catch (InvalidCastException e) { throw new SystemException("can't resolve parentGroup-argument : a role must be calculated from a Group, not a " + resolvedActor.GetType().FullName, e); } return(group); }
public Object ResolveArgumentGroup(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext) { log.Debug("resolvedActor inside resolveArgumentGroup: " + resolvedActor); if (resolvedActor == null) { if (parameters.Length != 1) { throw new SystemException("argument group expects exactly one parameter instead of " + parameters.Length); } String groupId = parameters[0]; IGroup group = null; try { group = executionContext.GetOrganisationComponent().FindGroupById(groupId); } catch (OrganisationRuntimeException e) { throw new SystemException("can't resolve group-argument with parameter " + groupId + " : " + e.Message); } return(group); } else { if (parameters.Length != 1) { throw new SystemException("argument group expects exactly one parameter (membership-type) instead of " + parameters.Length); } IUser user = null; IGroup group = null; String membershipType = parameters[0]; try { group = executionContext.GetOrganisationComponent().FindGroupByMembership(resolvedActor.Id, membershipType); } catch (InvalidCastException e) { throw new SystemException("can't resolve group-argument : a group must be calculated from a User, not a " + resolvedActor.GetType().FullName, e); } catch (OrganisationRuntimeException e) { throw new SystemException("can't resolve group-argument : can't find the hierarchy-memberschip of User " + user.Id + " and membership-type " + membershipType + " : " + e.Message, e); } return(group); } }
public Object ResolveArgumentActor(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext) { if (parameters.Length != 1) { throw new SystemException("argument actor expects exactly one (the actor-id) parameter instead of " + parameters.Length); } IActor actor = null; try { actor = executionContext.GetOrganisationComponent().FindActorById(parameters[0]); } catch (OrganisationRuntimeException e) { throw new SystemException("can't resolve actor-argument with parameter " + parameters[0], e); } return(actor); }
public Object ResolveArgumentProcessInitiator(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext) { return(executionContext.GetProcessInstance().GetInitiator()); }
public Object ResolveArgumentPreviousActor(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext) { if (parameters.Length != 0) { throw new SystemException("argument previousActor expects exactly zero parameters instead of " + parameters.Length); } IActor actor = executionContext.GetPreviousActor(); if (actor == null) { throw new SystemException("argument previousActor could not be resolve because there is no previous actor"); } return(actor); }
public long ExecuteTask(DbSession dbSession, IOrganisationService organisationComponent) { long millisToWait = DEFAULT_INTERVAL; DateTime now = DateTime.Now; IEnumerator iter = dbSession.Iterate(queryFindJobsToBeExecuted, now, DbType.TIMESTAMP).GetEnumerator(); if (iter.MoveNext()) { JobImpl job = (JobImpl)iter.Current; try { log.Debug("executing activation '" + job.Id + "' scheduled for " + job.Date.ToString()); log.Debug("activation's flow-context is :" + job.Context); String userId = job.UserId; DelegationImpl actionDelegation = job.ActionDelegation; ExecutionContextImpl executionContext = new ExecutionContextImpl(userId, dbSession, organisationComponent); IFlow context = job.Context; if (context != null) { executionContext.SetFlow(context); executionContext.SetProcessInstance(context.ProcessInstance); executionContext.SetProcessDefinition(context.ProcessInstance.ProcessDefinition); } else { executionContext.SetProcessDefinition(job.ProcessDefinition); } delegationHelper.DelegateScheduledAction(actionDelegation, executionContext); } catch (Exception t) { log.Error("scheduler-exception : couldn't perform task : " + t.Message, t); } dbSession.Delete(job); dbSession.Flush(); if (iter.MoveNext()) { return(0); } } iter = dbSession.Iterate(queryFindJobsInTheFuture, now, DbType.TIMESTAMP).GetEnumerator(); if (iter.MoveNext()) { JobImpl activation = (JobImpl)iter.Current; long activationDate = activation.Date.Ticks; millisToWait = activationDate - now.Ticks; log.Debug("next activation is scheduled at " + activation.Date.ToString() + ", (in " + millisToWait + " millis)"); if (millisToWait < 0) { millisToWait = 0; } if (millisToWait > DEFAULT_INTERVAL) { millisToWait = DEFAULT_INTERVAL; } } return(millisToWait); }