Search in sources :

Example 41 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ParallelMultiInstanceBehavior method createInstances.

/**
   * Handles the parallel case of spawning the instances.
   * Will create child executions accordingly for every instance needed.
   */
protected void createInstances(ActivityExecution execution) throws Exception {
    int nrOfInstances = resolveNrOfInstances(execution);
    if (nrOfInstances < 0) {
        throw new ActivitiIllegalArgumentException("Invalid number of instances: must be non-negative integer value" + ", but was " + nrOfInstances);
    }
    setLoopVariable(execution, NUMBER_OF_INSTANCES, nrOfInstances);
    setLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES, 0);
    setLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES, nrOfInstances);
    List<ActivityExecution> concurrentExecutions = new ArrayList<ActivityExecution>();
    for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
        ActivityExecution concurrentExecution = execution.createExecution();
        concurrentExecution.setActive(true);
        concurrentExecution.setConcurrent(true);
        concurrentExecution.setScope(false);
        // without any differentiation to which embedded subprocess they belong
        if (isExtraScopeNeeded()) {
            ActivityExecution extraScopedExecution = concurrentExecution.createExecution();
            extraScopedExecution.setActive(true);
            extraScopedExecution.setConcurrent(false);
            extraScopedExecution.setScope(true);
            concurrentExecution = extraScopedExecution;
        }
        concurrentExecutions.add(concurrentExecution);
        logLoopDetails(concurrentExecution, "initialized", loopCounter, 0, nrOfInstances, nrOfInstances);
    }
    // due to possible child execution pruning.
    for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
        ActivityExecution concurrentExecution = concurrentExecutions.get(loopCounter);
        // and completionCondition has been met in the meantime
        if (concurrentExecution.isActive() && !concurrentExecution.isEnded() && concurrentExecution.getParent().isActive() && !concurrentExecution.getParent().isEnded()) {
            setLoopVariable(concurrentExecution, getCollectionElementIndexVariable(), loopCounter);
            executeOriginalBehavior(concurrentExecution, loopCounter);
        }
    }
    // have been a better solution), as it would break boundary event behavior.
    if (!concurrentExecutions.isEmpty()) {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        executionEntity.setActive(false);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution)

Example 42 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ProcessInstanceQueryImpl method localize.

protected void localize(ProcessInstance processInstance) {
    ExecutionEntity processInstanceExecution = (ExecutionEntity) processInstance;
    processInstanceExecution.setLocalizedName(null);
    processInstanceExecution.setLocalizedDescription(null);
    if (locale != null) {
        String processDefinitionId = processInstanceExecution.getProcessDefinitionId();
        if (processDefinitionId != null) {
            ObjectNode languageNode = Context.getLocalizationElementProperties(locale, processInstanceExecution.getProcessDefinitionKey(), processDefinitionId, withLocalizationFallback);
            if (languageNode != null) {
                JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                if (languageNameNode != null && languageNameNode.isNull() == false) {
                    processInstanceExecution.setLocalizedName(languageNameNode.asText());
                }
                JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                if (languageDescriptionNode != null && languageDescriptionNode.isNull() == false) {
                    processInstanceExecution.setLocalizedDescription(languageDescriptionNode.asText());
                }
            }
        }
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 43 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ExecutionQueryImpl method localize.

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());
            }
        }
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 44 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class AddCommentCmd method execute.

public Comment execute(CommandContext commandContext) {
    // Validate task
    if (taskId != null) {
        TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
        if (task == null) {
            throw new ActivitiObjectNotFoundException("Cannot find task with id " + taskId, Task.class);
        }
        if (task.isSuspended()) {
            throw new ActivitiException(getSuspendedTaskException());
        }
    }
    if (processInstanceId != null) {
        ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
        if (execution == null) {
            throw new ActivitiObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class);
        }
        if (execution.isSuspended()) {
            throw new ActivitiException(getSuspendedExceptionMessage());
        }
    }
    String userId = Authentication.getAuthenticatedUserId();
    CommentEntity comment = new CommentEntity();
    comment.setUserId(userId);
    comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);
    comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
    comment.setTaskId(taskId);
    comment.setProcessInstanceId(processInstanceId);
    comment.setAction(Event.ACTION_ADD_COMMENT);
    String eventMessage = message.replaceAll("\\s+", " ");
    if (eventMessage.length() > 163) {
        eventMessage = eventMessage.substring(0, 160) + "...";
    }
    comment.setMessage(eventMessage);
    comment.setFullMessage(message);
    commandContext.getCommentEntityManager().insert(comment);
    return comment;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) CommentEntity(org.activiti.engine.impl.persistence.entity.CommentEntity)

Example 45 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class AddIdentityLinkForProcessInstanceCmd method execute.

public Void execute(CommandContext commandContext) {
    ExecutionEntity processInstance = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
    if (processInstance == null) {
        throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
    }
    processInstance.addIdentityLink(userId, groupId, type);
    commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true);
    return null;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Aggregations

ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)58 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)15 ActivitiException (org.activiti.engine.ActivitiException)12 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)11 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)8 HashMap (java.util.HashMap)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 CompensateEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)5 Deployment (org.activiti.engine.test.Deployment)5 ArrayList (java.util.ArrayList)4 DeploymentManager (org.activiti.engine.impl.persistence.deploy.DeploymentManager)4 AttachmentEntity (org.activiti.engine.impl.persistence.entity.AttachmentEntity)3 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)3 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)3 List (java.util.List)2 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2