org.activiti.engine.impl.persistence.entity.ExecutionEntity Java Examples

The following examples show how to use org.activiti.engine.impl.persistence.entity.ExecutionEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LockExclusiveJobCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Object execute(CommandContext commandContext) {

    if (job == null) {
      throw new ActivitiIllegalArgumentException("job is null");
    }

    if (log.isDebugEnabled()) {
      log.debug("Executing lock exclusive job {} {}", job.getId(), job.getExecutionId());
    }

    if (job.isExclusive()) {
      if (job.getExecutionId() != null) {
        ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(job.getExecutionId());
        if (execution != null) {
          commandContext.getExecutionEntityManager().updateProcessInstanceLockTime(execution.getProcessInstanceId());
        }
      }
    }

    return null;
  }
 
Example #2
Source File: FunctionEventListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void onProcessCompleted(ActivitiEntityEvent event) {
    logger.debug("process completed {}", event);

    String processInstanceId = event.getProcessInstanceId();
    ExecutionEntity executionEntity = Context.getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(processInstanceId);
    String businessKey = executionEntity.getBusinessKey();
    String processDefinitionId = event.getProcessDefinitionId();
    String activityId = "";
    String activityName = this.findActivityName(activityId,
            processDefinitionId);
    int eventCode = 24;
    String eventName = "process-end";
    String userId = Authentication.getAuthenticatedUserId();
    this.invokeExpression(eventCode, eventName, businessKey, userId,
            activityId, activityName);
}
 
Example #3
Source File: SubProcessActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    PvmActivity activity = activityExecution.getActivity();
    ActivityImpl initialActivity = (ActivityImpl) activity.getProperty(BpmnParse.PROPERTYNAME_INITIAL);

    if (initialActivity == null) {
        throw new ActivitiException("No initial activity found for subprocess "
                + activityExecution.getActivity().getId());
    }

    // initialize the template-defined data objects as variables
    initializeDataObjects(activityExecution, activity);

    if (initialActivity.getActivityBehavior() != null
            && initialActivity.getActivityBehavior() instanceof NoneStartEventActivityBehavior) { // embedded subprocess: only none start allowed
        ((ExecutionEntity) execution).setActivity(initialActivity);
        Context.getCommandContext().getHistoryManager().recordActivityStart((ExecutionEntity) execution);
    }

    activityExecution.executeActivity(initialActivity);
}
 
Example #4
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public InputStream getWorkflowImage(String workflowInstanceId)
{
    String processInstanceId = createLocalId(workflowInstanceId);
    ExecutionEntity pi = (ExecutionEntity) runtimeService.createProcessInstanceQuery()
                .processInstanceId(processInstanceId).singleResult();

    // If the process is finished, there is no diagram available
    if (pi != null)
    {
        // Fetch the bpmn model
        BpmnModel model = repoService.getBpmnModel(pi.getProcessDefinitionId());

        if (model != null && model.getLocationMap().size() > 0) 
        {              
            ProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
            return generator.generateDiagram(model,
                  ActivitiConstants.PROCESS_INSTANCE_IMAGE_FORMAT,
                  runtimeService.getActiveActivityIds(processInstanceId)); 
        }
    }
    return null;
}
 
Example #5
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeCompensationBoundaryEvents(FlowElement flowElement, DelegateExecution execution) {

    //Execute compensation boundary events
    Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), flowElement);
    if (CollectionUtil.isNotEmpty(boundaryEvents)) {

      // The parent execution becomes a scope, and a child execution is created for each of the boundary events
      for (BoundaryEvent boundaryEvent : boundaryEvents) {

        if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) {
          continue;
        }

        if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
          ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager()
              .createChildExecution((ExecutionEntity) execution);
          childExecutionEntity.setParentId(execution.getId());
          childExecutionEntity.setCurrentFlowElement(boundaryEvent);
          childExecutionEntity.setScope(false);

          ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
          boundaryEventBehavior.execute(childExecutionEntity);
        }
      }
    }
  }
 
Example #6
Source File: TimerActivateProcessDefinitionHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Job job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
    ProcessEngineConfigurationImpl processEngineConfiguration = commandContext.getProcessEngineConfiguration();

    boolean activateProcessInstances = false;
    try {
        JsonNode configNode = processEngineConfiguration.getObjectMapper().readTree(configuration);
        activateProcessInstances = getIncludeProcessInstances(configNode);
    } catch (Exception e) {
        throw new FlowableException("Error reading json value " + configuration, e);
    }

    String processDefinitionId = job.getProcessDefinitionId();

    ActivateProcessDefinitionCmd activateProcessDefinitionCmd = new ActivateProcessDefinitionCmd(processDefinitionId, null, activateProcessInstances, null, job.getTenantId());
    activateProcessDefinitionCmd.execute(commandContext);
}
 
Example #7
Source File: AbstractBpmnActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void signalCompensationDone(ActivityExecution execution, Object signalData) {
    // default behavior is to join compensating executions and propagate the signal if all executions
    // have compensated

    // join compensating executions
    if (execution.getExecutions().isEmpty()) {
        if (execution.getParent() != null) {
            ActivityExecution parent = execution.getParent();
            ((InterpretableExecution) execution).remove();
            ((InterpretableExecution) parent).signal("compensationDone", signalData);
        }
    } else {
        ((ExecutionEntity) execution).forceUpdate();
    }

}
 
Example #8
Source File: ExecutionTreeStringBuilder.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void internalToString(ExecutionEntity execution, StringBuilder strb, String prefix, boolean isTail) {
  strb.append(prefix)
      .append(isTail ? "└── " : "├── ")
      .append(execution.getId()).append(" : ")
      .append("activityId=" + execution.getActivityId())
      .append(", parent id ")
      .append(execution.getParentId())
      .append(execution.isScope() ? " (scope)" : "")
      .append(execution.isMultiInstanceRoot() ? " (multi instance root)" : "")
      .append("\r\n");
  
  List<? extends ExecutionEntity> children = executionEntity.getExecutions();
  if (children != null) {
    for (int i = 0; i < children.size() - 1; i++) {
      internalToString(children.get(i), strb, prefix + (isTail ? "    " : "│   "), false);
    }
    if (children.size() > 0) {
      internalToString(children.get(children.size() - 1), strb, prefix + (isTail ? "    " : "│   "), true);
    }
  }
}
 
Example #9
Source File: CtrlrServletTest.java    From oneops with Apache License 2.0 6 votes vote down vote up
@BeforeTest
public void setUp(){
	RuntimeService rts = mock(RuntimeService.class);
	List<ProcessInstance> processList = new ArrayList<ProcessInstance>();
	ExecutionEntity executionEntity = new  ExecutionEntity();
	executionEntity.setActive(false);
	processList.add(executionEntity);
	
	ProcessInstanceQuery pQuery = mock(ProcessInstanceQuery.class);
	when(pQuery.active()).thenReturn(pQuery);
	when(pQuery.list()).thenReturn(processList);
	when(rts.createProcessInstanceQuery()).thenReturn(pQuery);

	this.servlet.setRuntimeService(rts);
	this.servlet.setWoDispatcher(mock(WoDispatcher.class));
	this.servlet.init();
}
 
Example #10
Source File: SaveAttachmentCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
    AttachmentEntity updateAttachment = commandContext
            .getDbSqlSession()
            .selectById(AttachmentEntity.class, attachment.getId());

    updateAttachment.setName(attachment.getName());
    updateAttachment.setDescription(attachment.getDescription());

    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        String processInstanceId = updateAttachment.getProcessInstanceId();
        if (updateAttachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }

        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }

    return null;
}
 
Example #11
Source File: BoundarySignalEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();

  if (boundaryEvent.isCancelActivity()) {
    String eventName = null;
    if (signal != null) {
      eventName = signal.getName();
    } else {
      eventName = signalEventDefinition.getSignalRef();
    }

    EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
    List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
    for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
      if (eventSubscription instanceof SignalEventSubscriptionEntity && eventSubscription.getEventName().equals(eventName)) {

        eventSubscriptionEntityManager.delete(eventSubscription);
      }
    }
  }

  super.trigger(executionEntity, triggerName, triggerData);
}
 
Example #12
Source File: CompleteAdhocSubProcessCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Void execute(CommandContext commandContext) {
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  ExecutionEntity execution = executionEntityManager.findById(executionId);
  if (execution == null) {
    throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
  }

  if (execution.getCurrentFlowElement() instanceof AdhocSubProcess == false) {
    throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process");
  }

  List<? extends ExecutionEntity> childExecutions = execution.getExecutions();
  if (childExecutions.size() > 0) {
    throw new ActivitiException("Ad-hoc sub process has running child executions that need to be completed first");
  }

  ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());
  outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());

  executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);

  Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);

  return null;
}
 
Example #13
Source File: GetExecutionVariableInstanceCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public VariableInstance execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new FlowableIllegalArgumentException("executionId is null");
    }
    if (variableName == null) {
        throw new FlowableIllegalArgumentException("variableName is null");
    }

    ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(executionId);

    if (execution == null) {
        throw new FlowableObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }

    VariableInstance variableEntity = null;
    if (isLocal) {
        variableEntity = execution.getVariableInstanceLocal(variableName, false);
    } else {
        variableEntity = execution.getVariableInstance(variableName, false);
    }

    return variableEntity;
}
 
Example #14
Source File: TimerExecuteNestedActivityJobHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void dispatchExecutionTimeOut(Job job, ExecutionEntity execution, CommandContext commandContext) {
    // subprocesses
    for (ExecutionEntity subExecution : execution.getExecutions()) {
        dispatchExecutionTimeOut(job, subExecution, commandContext);
    }

    // call activities
    ExecutionEntity subProcessInstance = commandContext.getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId());
    if (subProcessInstance != null) {
        dispatchExecutionTimeOut(job, subProcessInstance, commandContext);
    }

    // activity with timer boundary event
    ActivityImpl activity = execution.getActivity();
    if (activity != null && activity.getActivityBehavior() != null) {
        dispatchActivityTimeOut(job, activity, execution, commandContext);
    }
}
 
Example #15
Source File: AddIdentityLinkForProcessInstanceCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Void execute(CommandContext commandContext) {

    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity processInstance = executionEntityManager.findById(processInstanceId);

    if (processInstance == null) {
      throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
    }
    
    if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); 
      activiti5CompatibilityHandler.addIdentityLinkForProcessInstance(processInstanceId, userId, groupId, type);
      return null;
    }

    IdentityLinkEntityManager identityLinkEntityManager = commandContext.getIdentityLinkEntityManager();
    identityLinkEntityManager.addIdentityLink(processInstance, userId, groupId, type);
    commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true);

    return null;

  }
 
Example #16
Source File: JumpCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
public Object execute(CommandContext commandContext) {
    // for (TaskEntity taskEntity : commandContext.getTaskEntityManager()
    // .findTasksByExecutionId(executionId)) {
    // taskEntity.setVariableLocal("跳转原因", jumpOrigin);
    // commandContext.getTaskEntityManager().deleteTask(taskEntity,
    // jumpOrigin, false);
    // }
    ExecutionEntity executionEntity = commandContext
            .getExecutionEntityManager().findExecutionById(executionId);
    executionEntity.destroyScope(jumpOrigin);

    ProcessDefinitionImpl processDefinition = executionEntity
            .getProcessDefinition();
    ActivityImpl activity = processDefinition.findActivity(activityId);

    executionEntity.executeActivity(activity);

    return null;
}
 
Example #17
Source File: BoundaryCompensateEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();

  if (boundaryEvent.isCancelActivity()) {
    EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
    List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
    for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
      if (eventSubscription instanceof CompensateEventSubscriptionEntity && eventSubscription.getActivityId().equals(compensateEventDefinition.getActivityRef())) {
        eventSubscriptionEntityManager.delete(eventSubscription);
      }
    }
  }

  super.trigger(executionEntity, triggerName, triggerData);
}
 
Example #18
Source File: ExecutionQueryImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void localize(Execution execution, String activityId) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  executionEntity.setLocalizedName(null);
  executionEntity.setLocalizedDescription(null);

  String processDefinitionId = executionEntity.getProcessDefinitionId();
  if (locale != null && processDefinitionId != null) {
    ObjectNode languageNode = Context.getLocalizationElementProperties(locale, activityId, processDefinitionId, withLocalizationFallback);
    if (languageNode != null) {
      JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
      if (languageNameNode != null && languageNameNode.isNull() == false) {
        executionEntity.setLocalizedName(languageNameNode.asText());
      }

      JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
      if (languageDescriptionNode != null && languageDescriptionNode.isNull() == false) {
        executionEntity.setLocalizedDescription(languageDescriptionNode.asText());
      }
    }
  }
}
 
Example #19
Source File: AbstractBpmnActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeCompensateBoundaryEvents(Collection<BoundaryEvent> boundaryEvents, DelegateExecution execution) {

    // The parent execution becomes a scope, and a child execution is created for each of the boundary events
    for (BoundaryEvent boundaryEvent : boundaryEvents) {

      if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) {
        continue;
      }
      
      if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition == false) {
        continue;
      }

      ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager().createChildExecution((ExecutionEntity) execution); 
      childExecutionEntity.setParentId(execution.getId());
      childExecutionEntity.setCurrentFlowElement(boundaryEvent);
      childExecutionEntity.setScope(false);

      ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
      boundaryEventBehavior.execute(childExecutionEntity);
    }

  }
 
Example #20
Source File: DeleteTaskWithCommentCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
public Object execute(CommandContext commandContext) {
    TaskEntity taskEntity = commandContext.getTaskEntityManager()
            .findTaskById(taskId);

    // taskEntity.fireEvent(TaskListener.EVENTNAME_COMPLETE);
    if ((Authentication.getAuthenticatedUserId() != null)
            && (taskEntity.getProcessInstanceId() != null)) {
        taskEntity.getProcessInstance().involveUser(
                Authentication.getAuthenticatedUserId(),
                IdentityLinkType.PARTICIPANT);
    }

    Context.getCommandContext().getTaskEntityManager()
            .deleteTask(taskEntity, comment, false);

    if (taskEntity.getExecutionId() != null) {
        ExecutionEntity execution = taskEntity.getExecution();
        execution.removeTask(taskEntity);

        // execution.signal(null, null);
    }

    return null;
}
 
Example #21
Source File: ActivitiEventBuilder.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static ActivitiSequenceFlowTakenEvent createSequenceFlowTakenEvent(ExecutionEntity executionEntity, ActivitiEventType type,
    String sequenceFlowId, String sourceActivityId, String sourceActivityName, String sourceActivityType, Object sourceActivityBehavior,
    String targetActivityId, String targetActivityName, String targetActivityType, Object targetActivityBehavior) {

  ActivitiSequenceFlowTakenEventImpl newEvent = new ActivitiSequenceFlowTakenEventImpl(type);

  if (executionEntity != null) {
    newEvent.setExecutionId(executionEntity.getId());
    newEvent.setProcessInstanceId(executionEntity.getProcessInstanceId());
    newEvent.setProcessDefinitionId(executionEntity.getProcessDefinitionId());
  }

  newEvent.setId(sequenceFlowId);
  newEvent.setSourceActivityId(sourceActivityId);
  newEvent.setSourceActivityName(sourceActivityName);
  newEvent.setSourceActivityType(sourceActivityType);
  newEvent.setSourceActivityBehaviorClass(sourceActivityBehavior != null ? sourceActivityBehavior.getClass().getCanonicalName() : null);
  newEvent.setTargetActivityId(targetActivityId);
  newEvent.setTargetActivityName(targetActivityName);
  newEvent.setTargetActivityType(targetActivityType);
  newEvent.setTargetActivityBehaviorClass(targetActivityBehavior != null ? targetActivityBehavior.getClass().getCanonicalName() :  null);

  return newEvent;
}
 
Example #22
Source File: EndExecutionOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected boolean allChildExecutionsEnded(ExecutionEntity parentExecutionEntity, ExecutionEntity executionEntityToIgnore) {
  for (ExecutionEntity childExecutionEntity : parentExecutionEntity.getExecutions()) {
    if (executionEntityToIgnore == null || !executionEntityToIgnore.getId().equals(childExecutionEntity.getId())) {
      if (!childExecutionEntity.isEnded()) {
        return false;
      }
      if (childExecutionEntity.getExecutions() != null && childExecutionEntity.getExecutions().size() > 0) {
        if (!allChildExecutionsEnded(childExecutionEntity, executionEntityToIgnore)) {
          return false;
        }
      }
    }
  }
  return true;
}
 
Example #23
Source File: HasExecutionVariableCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new ActivitiIllegalArgumentException("executionId is null");
    }
    if (variableName == null) {
        throw new ActivitiIllegalArgumentException("variableName is null");
    }

    ExecutionEntity execution = commandContext
            .getExecutionEntityManager()
            .findExecutionById(executionId);

    if (execution == null) {
        throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }

    boolean hasVariable = false;

    if (isLocal) {
        hasVariable = execution.hasVariableLocal(variableName);
    } else {
        hasVariable = execution.hasVariable(variableName);
    }

    return hasVariable;
}
 
Example #24
Source File: ExecutionQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/runtime/concurrentExecution.bpmn20.xml"})
public void testExecutionQueryWithProcessVariable() {
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("x", "parent");
  variables.put("xIgnoreCase", "PaReNt");
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("concurrent", variables);
  
  List<Execution> concurrentExecutions = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).list();
  assertEquals(3, concurrentExecutions.size());
  for (Execution execution : concurrentExecutions) {
    if (!((ExecutionEntity)execution).isProcessInstanceType()) {
      // only the concurrent executions, not the root one, would be cooler to query that directly, see https://activiti.atlassian.net/browse/ACT-1373
      runtimeService.setVariableLocal(execution.getId(), "x", "child");
      runtimeService.setVariableLocal(execution.getId(), "xIgnoreCase", "ChILD");
    }      
  }
  
  assertEquals(2, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "child").count());
  assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "parent").count());    

  assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("x", "parent").count());
  assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEquals("x", "xxx").count());
  
  // Test value-only query
  assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("child").count());
  assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("parent").count());
  
  // Test ignore-case queries
  assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "CHILD").count());
  assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "PARENT").count());   
  
  // Test ignore-case queries
  assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "paRent").count());
  assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "chilD").count());  
  
}
 
Example #25
Source File: DefaultActivitiEngineAgenda.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Generic method to plan a {@link Runnable}.
 */
@Override
public void planOperation(Runnable operation) {
    operations.add(operation);

    if (operation instanceof AbstractOperation) {
        ExecutionEntity execution = ((AbstractOperation) operation).getExecution();
        if (execution != null) {
            commandContext.addInvolvedExecution(execution);
        }
    }

    logger.debug("Operation {} added to agenda", operation.getClass());
}
 
Example #26
Source File: FlowableProcessController.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@PostMapping("/next-task-candidate/{taskId}")
@Authorize(merge = false)
public ResponseMessage<List<CandidateDetail>> candidateList(@PathVariable String taskId,
                                                            @RequestBody Map<String, Object> data,
                                                            Authentication authentication) {

    Task task = taskService.createTaskQuery()
            .taskId(taskId)
            .singleResult();

    ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery()
            .processInstanceId(task.getProcessInstanceId())
            .activityId(task.getTaskDefinitionKey())
            .singleResult();

    execution.setTransientVariables(data);

    List<TaskDefinition> taskDefinitions = bpmActivityService
            .getNextActivities(task.getProcessDefinitionId(), task.getTaskDefinitionKey(), (execution));

    List<CandidateDetail> candidates = taskDefinitions.stream().map(TaskDefinition::getKey)
            .flatMap(key ->
                    processConfigurationService
                            .getActivityConfiguration(authentication.getUser().getId(), task.getProcessDefinitionId(), key)
                            .getCandidateInfo(task)
                            .stream())
            .distinct()
            .map(CandidateDetail::of)
            .collect(Collectors.toList());


    return ResponseMessage.ok(candidates);
}
 
Example #27
Source File: EndExecutionOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected int getNumberOfActiveChildExecutionsForExecution(ExecutionEntityManager executionEntityManager, String executionId) {
  List<ExecutionEntity> executions = executionEntityManager.findChildExecutionsByParentExecutionId(executionId);
  int activeExecutions = 0;

  // Filter out the boundary events
  for (ExecutionEntity activeExecution : executions) {
    if (!(activeExecution.getCurrentFlowElement() instanceof BoundaryEvent)) {
      activeExecutions++;
    }
  }

  return activeExecutions;
}
 
Example #28
Source File: ProcessInstanceEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
  if (event instanceof ActivitiEntityEvent && ProcessInstance.class.isAssignableFrom(((ActivitiEntityEvent) event).getEntity().getClass())) {
    // check whether entity in the event is initialized before
    // adding to the list.
    assertNotNull(((ExecutionEntity) ((ActivitiEntityEvent) event).getEntity()).getId());
    eventsReceived.add(event);
  } else if (ActivitiEventType.PROCESS_CANCELLED.equals(event.getType()) || ActivitiEventType.ACTIVITY_CANCELLED.equals(event.getType())) {
    eventsReceived.add(event);
  }
}
 
Example #29
Source File: IntermediateCatchTimerEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  JobManager jobManager = Context.getCommandContext().getJobManager();
  
  // end date should be ignored for intermediate timer events.
  TimerJobEntity timerJob = jobManager.createTimerJob(timerEventDefinition, false, (ExecutionEntity) execution, TriggerTimerEventJobHandler.TYPE,
      TimerEventHandler.createConfiguration(execution.getCurrentActivityId(), null, timerEventDefinition.getCalendarName()));
  
  if (timerJob != null) {
    jobManager.scheduleTimerJob(timerJob);
  }
}
 
Example #30
Source File: ScopeUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * we create a separate execution for each compensation handler invocation.
 */
public static void throwCompensationEvent(List<CompensateEventSubscriptionEntity> eventSubscriptions, DelegateExecution execution, boolean async) {

  ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
  
  // first spawn the compensating executions
  for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
    ExecutionEntity compensatingExecution = null;
    
    // check whether compensating execution is already created (which is the case when compensating an embedded subprocess,
    // where the compensating execution is created when leaving the subprocess and holds snapshot data).
    if (eventSubscription.getConfiguration() != null) {
      compensatingExecution = executionEntityManager.findById(eventSubscription.getConfiguration());
      compensatingExecution.setParent(compensatingExecution.getProcessInstance());
      compensatingExecution.setEventScope(false);
    } else {
      compensatingExecution = executionEntityManager.createChildExecution((ExecutionEntity) execution); 
      eventSubscription.setConfiguration(compensatingExecution.getId());
    }
    
  }

  // signal compensation events in reverse order of their 'created' timestamp
  Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {
    public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
      return o2.getCreated().compareTo(o1.getCreated());
    }
  });

  for (CompensateEventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
    Context.getCommandContext().getEventSubscriptionEntityManager().eventReceived(compensateEventSubscriptionEntity, null, async);
  }
}