public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("processInstanceId", ProcessInstanceId); ExecutionEntity execution = commandContext.ExecutionManager.FindExecutionById(ProcessInstanceId); EnsureUtil.EnsureNotNull("No process instance found for id '" + ProcessInstanceId + "'", "execution", execution); commandContext.TaskManager.DeleteTasksByProcessInstanceId(ProcessInstanceId, DeleteReason, false, false); foreach (var currentExecution in this.CollectExecutionToDelete(execution)) { currentExecution.DeleteCascade2(DeleteReason); } return(null); }
protected internal override ExecutionEntity DetermineSourceInstanceExecution(CommandContext commandContext) { ExecutionEntity processInstance = commandContext.ExecutionManager.FindExecutionById(processInstanceId); // rebuild the mapping because the execution tree changes with every iteration var mapping = new ActivityExecutionTreeMapping(commandContext, processInstanceId); IActivityInstance instance = commandContext.RunWithoutAuthorization(() => (new GetActivityInstanceCmd(processInstanceId)).Execute(commandContext)); IActivityInstance instanceToCancel = FindActivityInstance(instance, ActivityInstanceId); EnsureUtil.EnsureNotNull(typeof(NotValidException), DescribeFailure("Activity instance '" + ActivityInstanceId + "' does not exist"), "activityInstance", instanceToCancel); ExecutionEntity scopeExecution = GetScopeExecutionForActivityInstance(processInstance, mapping, instanceToCancel); return(scopeExecution); //return new ExecutionEntity(); }
public virtual IVariableMap Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("executionId", ExecutionId); ExecutionEntity execution = commandContext.ExecutionManager.FindExecutionById(ExecutionId); EnsureUtil.EnsureNotNull("execution " + ExecutionId + " doesn't exist", "execution", execution); CheckGetExecutionVariables(execution, commandContext); var executionVariables = new VariableMapImpl(); //collect variables from execution execution.CollectVariables(executionVariables, VariableNames, IsLocal, DeserializeValues); return(executionVariables); }
protected internal virtual void SendSignalToExecution(CommandContext commandContext, string signalName, string executionId) { IExecutionManager executionManager = commandContext.ExecutionManager; ExecutionEntity execution = executionManager.FindExecutionById(executionId); EnsureUtil.EnsureNotNull("Cannot find execution with id '" + executionId + "'", "execution", execution); IEventSubscriptionManager eventSubscriptionManager = commandContext.EventSubscriptionManager; IList <EventSubscriptionEntity> signalEvents = eventSubscriptionManager.FindSignalEventSubscriptionsByNameAndExecution(signalName, executionId); EnsureUtil.EnsureNotEmpty("Execution '" + executionId + "' has not subscribed to a signal event with name '" + signalName + "'.", ListExt.ConvertToIlist(signalEvents)); CheckAuthorizationOfCatchSignals(commandContext, signalEvents); NotifyExecutions(signalEvents); }
public virtual IProcessInstanceModificationInstantiationBuilder SetVariableLocal(string name, object value) { EnsureUtil.EnsureNotNull(typeof(NotValidException), "Variable name must not be null", "name", name); var currentInstantiation = CurrentInstantiation; if (currentInstantiation != null) { currentInstantiation.AddVariableLocal(name, value); } else { ProcessVariables.PutValue(name, value); } return(this); }
public virtual Picture Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("userId", UserId); IdentityInfoEntity pictureInfo = commandContext.IdentityInfoManager.FindUserInfoByUserIdAndKey(UserId, "picture"); if (pictureInfo != null) { string pictureByteArrayId = pictureInfo.Value; if (!string.ReferenceEquals(pictureByteArrayId, null)) { ResourceEntity byteArray = commandContext.ByteArrayManager.Get(pictureByteArrayId); return(new Picture(byteArray.Bytes, byteArray.Name)); } } return(null); }
public virtual string Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("historicExternalTaskLogId", HistoricExternalTaskLogId); HistoricExternalTaskLogEntity @event = commandContext.HistoricExternalTaskLogManager.FindHistoricExternalTaskLogById(HistoricExternalTaskLogId); EnsureUtil.EnsureNotNull("No historic external ITask log found with id " + HistoricExternalTaskLogId, "historicExternalTaskLog", @event); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckReadHistoricExternalTaskLog(@event); } return(@event.ErrorDetails); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("externalTaskId", ExternalTaskId); ValidateInput(); ExternalTaskEntity externalTask = commandContext.ExternalTaskManager.FindExternalTaskById(ExternalTaskId); EnsureUtil.EnsureNotNull(typeof(NotFoundException), "Cannot find external ITask with id " + ExternalTaskId, "externalTask", externalTask); foreach (ICommandChecker checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckUpdateProcessInstanceById(externalTask.ProcessInstanceId); } Execute(externalTask); return(null); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("taskId", TaskId); ITaskManager taskManager = commandContext.TaskManager; TaskEntity task = taskManager.FindTaskById(TaskId); EnsureUtil.EnsureNotNull("Cannot find ITask with id " + TaskId, "ITask", task); //TODO auth CheckCompleteTask(task, commandContext); if (Variables != null) { task.ExecutionVariables = Variables; } CompleteTask(task); return(null); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("historicDecisionInstanceId", HistoricDecisionInstanceId); //IHistoricDecisionInstance historicDecisionInstance = // commandContext.HistoricDecisionInstanceManager.findHistoricDecisionInstance(historicDecisionInstanceId); //EnsureUtil.EnsureNotNull("No historic decision instance found with id: " + historicDecisionInstanceId, // "historicDecisionInstance", historicDecisionInstance); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { //checker.checkDeleteHistoricDecisionInstance(historicDecisionInstance); } //commandContext.HistoricDecisionInstanceManager.deleteHistoricHistoricInstanceByInstanceId( // historicDecisionInstanceId); return(null); }
protected internal virtual ExecutionEntity GetScopeExecutionForActivityInstance(ExecutionEntity processInstance, ActivityExecutionTreeMapping mapping, IActivityInstance activityInstance) { EnsureUtil.EnsureNotNull("activityInstance", activityInstance); ProcessDefinitionImpl processDefinition = processInstance.ProcessDefinition; ScopeImpl scope = GetScopeForActivityInstance(processDefinition, activityInstance); ISet <ExecutionEntity> executions = mapping.GetExecutions(scope); ISet <string> activityInstanceExecutions = new HashSet <string>(activityInstance.ExecutionIds); // TODO: this is a hack around the activity instance tree // remove with fix of CAM-3574 foreach (var activityInstanceExecutionId in activityInstance.ExecutionIds) { ExecutionEntity execution = context.Impl.Context.CommandContext.ExecutionManager.FindExecutionById(activityInstanceExecutionId); if (execution.IsConcurrent && execution.HasChildren()) { // concurrent executions have at most one child IActivityExecution child = execution.executions.First();//.Executions[0]; activityInstanceExecutions.Add(child.Id); } } // find the scope execution for the given activity instance ISet <ExecutionEntity> retainedExecutionsForInstance = new HashSet <ExecutionEntity>(); foreach (ExecutionEntity execution in executions) { if (activityInstanceExecutions.Contains(execution.Id)) { retainedExecutionsForInstance.Add(execution); } } if (retainedExecutionsForInstance.Count != 1) { throw new ProcessEngineException("There are " + retainedExecutionsForInstance.Count + " (!= 1) executions for activity instance " + activityInstance.Id); } return(retainedExecutionsForInstance.GetEnumerator().Current); }
public virtual void CreateTenantUserMembership(string tenantId, string userId) { CheckAuthorization(Permissions.Create, Resources.TenantMembership, tenantId); ITenant tenant = FindTenantById(tenantId); IUser user = FindUserById(userId); EnsureUtil.EnsureNotNull("No tenant found with id '" + tenantId + "'.", "tenant", tenant); EnsureUtil.EnsureNotNull("No user found with id '" + userId + "'.", "user", user); TenantMembershipEntity membership = new TenantMembershipEntity(); membership.SetTenant((TenantEntity)tenant); membership.SetUser((UserEntity)user); CommandContext.GetDbEntityManager <TenantMembershipEntity>().Add(membership); CreateDefaultTenantMembershipAuthorizations(tenant, user); }
public virtual IProcessInstance Execute(CommandContext commandContext) { var processEngineConfiguration = context.Impl.Context.ProcessEngineConfiguration; DeploymentCache deploymentCache = processEngineConfiguration.DeploymentCache; ProcessDefinitionEntity processDefinition = deploymentCache.FindDeployedProcessDefinitionById(ProcessDefinitionId); EnsureUtil.EnsureNotNull("No process definition found for id = '" + ProcessDefinitionId + "'", "processDefinition", processDefinition); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckCreateProcessInstance(processDefinition); } ExecutionEntity processInstance = null; if (!ReferenceEquals(BusinessKey, null)) { processInstance = (ExecutionEntity)processDefinition.CreateProcessInstance(BusinessKey); } else { processInstance = (ExecutionEntity)processDefinition.CreateProcessInstance(); } //if the start event is async, we have to set the variables already here //since they are lost after the async continuation otherwise if (processDefinition.Initial.AsyncBefore) { // avoid firing history events processInstance.StartContext = new ProcessInstanceStartContext(processInstance.Activity as ActivityImpl); FormPropertyHelper.InitFormPropertiesOnScope(Variables, processInstance); processInstance.Start(); } else { processInstance.StartWithFormProperties(Variables); } return((IProcessInstance)processInstance); }
public virtual void CreateTenantGroupMembership(string tenantId, string groupId) { CheckAuthorization(Permissions.Create, Resources.TenantMembership, tenantId); ITenant tenant = FindTenantById(tenantId); IGroup group = FindGroupById(groupId); EnsureUtil.EnsureNotNull("No tenant found with id '" + tenantId + "'.", "tenant", tenant); EnsureUtil.EnsureNotNull("No group found with id '" + groupId + "'.", "group", group); TenantMembershipEntity membership = new TenantMembershipEntity(); membership.SetTenant((TenantEntity)tenant); membership.SetGroup((GroupEntity)group); CommandContext.GetDbEntityManager <TenantMembershipEntity>().Add(membership); CreateDefaultTenantMembershipAuthorizations(tenant, group); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("UserId", UserId); IdentityInfoEntity infoEntity = commandContext.IdentityInfoManager.FindUserInfoByUserIdAndKey(UserId, "picture"); if (infoEntity != null) { string byteArrayId = infoEntity.Value; if (!string.ReferenceEquals(byteArrayId, null)) { commandContext.ByteArrayManager.DeleteByteArrayById(byteArrayId); } commandContext.IdentityInfoManager.Delete(infoEntity); } return(null); }
public virtual IStartFormData Execute(CommandContext commandContext) { var processEngineConfiguration = context.Impl.Context.ProcessEngineConfiguration; DeploymentCache deploymentCache = processEngineConfiguration.DeploymentCache; ProcessDefinitionEntity processDefinition = deploymentCache.FindDeployedProcessDefinitionById(ProcessDefinitionId); EnsureUtil.EnsureNotNull("No process definition found for id '" + ProcessDefinitionId + "'", "processDefinition", processDefinition); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckReadProcessDefinition(processDefinition); } IStartFormHandler startFormHandler = processDefinition.StartFormHandler; EnsureUtil.EnsureNotNull("No startFormHandler defined in process '" + ProcessDefinitionId + "'", "startFormHandler", startFormHandler); return(startFormHandler.CreateStartFormData(processDefinition)); }
public virtual IProcessInstanceModificationInstantiationBuilder SetVariables( IDictionary <string, ITypedValue> variables) { EnsureUtil.EnsureNotNull(typeof(NotValidException), "Variable map must not be null", "variables", variables); var currentInstantiation = CurrentInstantiation; if (currentInstantiation != null) { currentInstantiation.AddVariables(variables); } else { foreach (var t in variables) { ProcessVariables.PutValue(t.Key, t.Value); } } return(this); }
public virtual IBpmnModelInstance Execute(CommandContext commandContext) { var configuration = context.Impl.Context.ProcessEngineConfiguration; DeploymentCache deploymentCache = configuration.DeploymentCache; ProcessDefinitionEntity processDefinition = deploymentCache.FindDeployedProcessDefinitionById(ProcessDefinitionId); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckReadProcessDefinition(processDefinition); } IBpmnModelInstance modelInstance = deploymentCache.FindBpmnModelInstanceForProcessDefinition(ProcessDefinitionId); EnsureUtil.EnsureNotNull("no BPMN model instance found for process definition id " + ProcessDefinitionId, "modelInstance", modelInstance); return(modelInstance); }
protected internal virtual TransitionImpl FindTransition(ProcessDefinitionImpl processDefinition) { var activity = (IPvmActivity)processDefinition.FindActivity(ActivityId); EnsureUtil.EnsureNotNull(typeof(NotValidException), DescribeFailure("Activity '" + ActivityId + "' does not exist"), "activity", activity); if (activity.OutgoingTransitions.Count == 0) { throw new ProcessEngineException("Cannot start after activity " + ActivityId + "; activity " + "has no outgoing sequence flow to take"); } if (activity.OutgoingTransitions.Count > 1) { throw new ProcessEngineException("Cannot start after activity " + ActivityId + "; " + "activity has more than one outgoing sequence flow"); } return((TransitionImpl)activity.OutgoingTransitions[0]); }
public virtual void Execute(IJobHandlerConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, string tenantId) { var conf = (BatchMonitorJobConfiguration)configuration; var batchId = conf.BatchId; BatchEntity batch = commandContext.BatchManager.FindBatchById(conf.BatchId); EnsureUtil.EnsureNotNull("Batch with id '" + batchId + "' cannot be found", "batch", batch); bool completed = batch.Completed; if (!completed) { //batch.CreateMonitorJob(true); } else { batch.Delete(false); } }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("job id must not be null", "jobId", JobId); JobEntity job = commandContext.JobManager.FindJobById(JobId); EnsureUtil.EnsureNotNull(typeof(NotFoundException), "No job found with id '" + JobId + "'", "job", job); foreach (ICommandChecker checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckUpdateJob(job); } long currentPriority = job.Priority; job.Priority = Priority; CreateOpLogEntry(commandContext, currentPriority, job); return(null); }
public virtual void Schedule(TimerEntity timer) { DateTime?duedate = timer.Duedate; EnsureUtil.EnsureNotNull("duedate", duedate); timer.Insert(); // Check if this timer fires before the next time the job executor will check for new timers to fire. // This is highly unlikely because normally waitTimeInMillis is 5000 (5 seconds) // and timers are usually set further in the future JobExecutor jobExecutor = context.Impl.Context.ProcessEngineConfiguration.JobExecutor; int waitTimeInMillis = jobExecutor.WaitTimeInMillis; if (((DateTime)duedate).Ticks < (ClockUtil.CurrentTime.Ticks + waitTimeInMillis)) { HintJobExecutor(timer); } }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("decisionDefinitionId", DecisionDefinitionId); var decisionDefinition = commandContext.DecisionDefinitionManager.FindDecisionDefinitionById(DecisionDefinitionId); EnsureUtil.EnsureNotNull("No decision definition found with id: " + DecisionDefinitionId, "decisionDefinition", decisionDefinition); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckDeleteHistoricDecisionInstance(decisionDefinition.Key); } //commandContext.HistoricDecisionInstanceManager.deleteHistoricDecisionInstancesByDecisionDefinitionId( // decisionDefinitionId); return(null); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull(typeof(BadUserRequestException), "executionId is null", "executionId", ExecutionId); ExecutionEntity execution = commandContext.ExecutionManager.FindExecutionById(ExecutionId); EnsureUtil.EnsureNotNull(typeof(BadUserRequestException), "execution " + ExecutionId + " doesn't exist", "execution", execution); foreach (ICommandChecker checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckUpdateProcessInstance(execution); } if (ProcessVariables != null) { execution.Variables = ProcessVariables; } execution.Signal(SignalName, SignalData); return(null); }
public virtual IList <string> Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("executionId", ExecutionId); var execution = commandContext.ExecutionManager.FindExecutionById(ExecutionId); EnsureUtil.EnsureNotNull("execution " + ExecutionId + " doesn't exist", "execution", execution); IList <string> executionVariables; if (IsLocal) { executionVariables = new List <string>(execution.VariableNamesLocal); } else { executionVariables = new List <string>(execution.VariableNames); } return(executionVariables); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull(typeof(BadUserRequestException), "Batch id must not be null", "batch id", BatchId); BatchManager batchManager = commandContext.BatchManager as BatchManager; BatchEntity batch = batchManager.FindBatchById(BatchId); EnsureUtil.EnsureNotNull(typeof(BadUserRequestException), "Batch for id '" + BatchId + "' cannot be found", "batch", batch); CheckAccess(commandContext, batch); SetJobDefinitionState(commandContext, batch.SeedJobDefinitionId); SetJobDefinitionState(commandContext, batch.MonitorJobDefinitionId); SetJobDefinitionState(commandContext, batch.BatchJobDefinitionId); batchManager.UpdateBatchSuspensionStateById(BatchId, NewSuspensionState); LogUserOperation(commandContext); return(null); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("taskId", TaskId); ITaskManager taskManager = commandContext.TaskManager; TaskEntity task = taskManager.FindTaskById(TaskId); EnsureUtil.EnsureNotNull("Cannot find ITask with id " + TaskId, "ITask", task); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckTaskWork(task); } TaskDefinition taskDefinition = task.TaskDefinition; if (taskDefinition != null) { var taskFormHandler = taskDefinition.TaskFormHandler; taskFormHandler.SubmitFormVariables(Properties, task); } else { // set variables on standalone ITask task.Variables = Properties; } // complete or resolve the ITask if (DelegationState.Pending.Equals(task.DelegationState)) { task.Resolve(); task.CreateHistoricTaskDetails(UserOperationLogEntryFields.OperationTypeResolve); } else { task.Complete(); task.CreateHistoricTaskDetails(UserOperationLogEntryFields.OperationTypeComplete); } return(null); }
public virtual IList <IIdentityLink> Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("taskId", TaskId); ITaskManager taskManager = commandContext.TaskManager; TaskEntity task = taskManager.FindTaskById(TaskId); EnsureUtil.EnsureNotNull("Cannot find ITask with id " + TaskId, "ITask", task); CheckGetIdentityLink(task, commandContext); var identityLinks = (IList <IIdentityLink>)task.IdentityLinks; //assignee is not part of identity links in the db. // so if there is one, we add it here. // @Tom: we discussed this long on skype and you agreed; -) // an assigneeis*an identityLink, and so must it be reflected in the API //Note: we cant move this code to the TaskEntity(which would be cleaner), //since the ITask.delete cascased to all associated identityLinks //and of course this leads to exception while trying to delete a non-existing identityLink if (!ReferenceEquals(task.Assignee, null)) { var identityLink = new IdentityLinkEntity(); identityLink.UserId = task.Assignee; identityLink.Task = task; identityLink.Type = IdentityLinkType.Assignee; identityLinks.Add(identityLink); } if (!ReferenceEquals(task.Owner, null)) { var identityLink = new IdentityLinkEntity(); identityLink.UserId = task.Owner; identityLink.Task = task; identityLink.Type = IdentityLinkType.Owner; identityLinks.Add(identityLink); } return((IList <IIdentityLink>)task.IdentityLinks); }
public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("caseInstanceId", CaseInstanceId); // Check if case instance is still running IHistoricCaseInstance instance = commandContext.HistoricCaseInstanceManager.FindHistoricCaseInstance(CaseInstanceId); EnsureUtil.EnsureNotNull("No historic case instance found with id: " + CaseInstanceId, "instance", instance); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckDeleteHistoricCaseInstance(instance); } EnsureUtil.EnsureNotNull( "Case instance is still running, cannot delete historic case instance: " + CaseInstanceId, "instance.getCloseTime()", instance.CloseTime); commandContext.HistoricCaseInstanceManager.DeleteHistoricCaseInstanceById(CaseInstanceId); return(null); }
public override object Execute(CommandContext commandContext) { ValidateInput(); ExternalTaskEntity externalTask = commandContext.ExternalTaskManager.FindExternalTaskById(ExternalTaskId); EnsureUtil.EnsureNotNull(typeof(NotFoundException), "Cannot find external ITask with id " + ExternalTaskId, "externalTask", externalTask); if (!WorkerId.Equals(externalTask.WorkerId)) { throw new BadUserRequestException(ErrorMessageOnWrongWorkerAccess + "'. It is locked by worker '" + externalTask.WorkerId + "'."); } foreach (ICommandChecker checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckUpdateProcessInstanceById(externalTask.ProcessInstanceId); } Execute(externalTask); return(null); }