Search in sources :

Example 6 with ExecutionEntity

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

the class GetExecutionVariableInstancesCmd method execute.

public Map<String, VariableInstance> execute(CommandContext commandContext) {
    // Verify existance of execution
    if (executionId == null) {
        throw new ActivitiIllegalArgumentException("executionId is null");
    }
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(executionId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }
    Map<String, VariableInstance> variables = null;
    if (variableNames == null || variableNames.isEmpty()) {
        // Fetch all
        if (isLocal) {
            variables = execution.getVariableInstancesLocal();
        } else {
            variables = execution.getVariableInstances();
        }
    } else {
        // Fetch specific collection of variables
        if (isLocal) {
            variables = execution.getVariableInstancesLocal(variableNames, false);
        } else {
            variables = execution.getVariableInstances(variableNames, false);
        }
    }
    if (variables != null && locale != null) {
        for (Entry<String, VariableInstance> entry : variables.entrySet()) {
            String variableName = entry.getKey();
            VariableInstance variableEntity = entry.getValue();
            String localizedName = null;
            String localizedDescription = null;
            ObjectNode languageNode = Context.getLocalizationElementProperties(locale, variableName, execution.getProcessDefinitionId(), withLocalizationFallback);
            if (languageNode != null) {
                JsonNode nameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                if (nameNode != null) {
                    localizedName = nameNode.asText();
                }
                JsonNode descriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                if (descriptionNode != null) {
                    localizedDescription = descriptionNode.asText();
                }
            }
            variableEntity.setLocalizedName(localizedName);
            variableEntity.setLocalizedDescription(localizedDescription);
        }
    }
    return variables;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Example 7 with ExecutionEntity

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

the class AbstractEventHandler method handleEvent.

public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {
    ExecutionEntity execution = eventSubscription.getExecution();
    ActivityImpl activity = eventSubscription.getActivity();
    if (activity == null) {
        throw new ActivitiException("Error while sending signal for event subscription '" + eventSubscription.getId() + "': " + "no activity associated with event subscription");
    }
    if (payload instanceof Map) {
        @SuppressWarnings("unchecked") Map<String, Object> processVariables = (Map<String, Object>) payload;
        execution.setVariables(processVariables);
    }
    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    if (activityBehavior instanceof BoundaryEventActivityBehavior || activityBehavior instanceof EventSubProcessStartEventActivityBehavior) {
        try {
            dispatchActivitiesCanceledIfNeeded(eventSubscription, execution, activity, commandContext);
            activityBehavior.execute(execution);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new ActivitiException("exception while sending signal for event subscription '" + eventSubscription + "':" + e.getMessage(), e);
        }
    } else {
        // not boundary
        if (!activity.equals(execution.getActivity())) {
            execution.setActivity(activity);
        }
        execution.signal(eventSubscription.getEventName(), payload);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) EventSubProcessStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventSubProcessStartEventActivityBehavior) ActivityBehavior(org.activiti.engine.impl.pvm.delegate.ActivityBehavior) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) EventSubProcessStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventSubProcessStartEventActivityBehavior) Map(java.util.Map)

Example 8 with ExecutionEntity

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

the class CompensationEventHandler method handleEvent.

public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {
    String configuration = eventSubscription.getConfiguration();
    if (configuration == null) {
        throw new ActivitiException("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId());
    }
    ExecutionEntity compensatingExecution = commandContext.getExecutionEntityManager().findExecutionById(configuration);
    ActivityImpl compensationHandler = eventSubscription.getActivity();
    if ((compensationHandler.getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION) == null || !(Boolean) compensationHandler.getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION)) && compensationHandler.isScope()) {
        // descend into scope:
        List<CompensateEventSubscriptionEntity> eventsForThisScope = compensatingExecution.getCompensateEventSubscriptions();
        ScopeUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);
    } else {
        try {
            if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPENSATE, compensationHandler.getId(), (String) compensationHandler.getProperty("name"), compensatingExecution.getId(), compensatingExecution.getProcessInstanceId(), compensatingExecution.getProcessDefinitionId(), (String) compensatingExecution.getActivity().getProperties().get("type"), compensatingExecution.getActivity().getActivityBehavior().getClass().getCanonicalName()));
            }
            compensatingExecution.setActivity(compensationHandler);
            // executing the atomic operation makes sure activity start events are fired
            compensatingExecution.performOperation(AtomicOperation.ACTIVITY_START);
        } catch (Exception e) {
            throw new ActivitiException("Error while handling compensation event " + eventSubscription, e);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) CompensateEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity) ActivitiException(org.activiti.engine.ActivitiException)

Example 9 with ExecutionEntity

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

the class CreateAttachmentCmd method execute.

public Attachment execute(CommandContext commandContext) {
    verifyParameters(commandContext);
    AttachmentEntity attachment = new AttachmentEntity();
    attachment.setName(attachmentName);
    attachment.setDescription(attachmentDescription);
    attachment.setType(attachmentType);
    attachment.setTaskId(taskId);
    attachment.setProcessInstanceId(processInstanceId);
    attachment.setUrl(url);
    attachment.setUserId(Authentication.getAuthenticatedUserId());
    attachment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(attachment);
    if (content != null) {
        byte[] bytes = IoUtil.readInputStream(content, attachmentName);
        ByteArrayEntity byteArray = ByteArrayEntity.createAndInsert(bytes);
        attachment.setContentId(byteArray.getId());
        attachment.setContent(byteArray);
    }
    commandContext.getHistoryManager().createAttachmentComment(taskId, processInstanceId, attachmentName, true);
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        if (attachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }
    return attachment;
}
Also used : ByteArrayEntity(org.activiti.engine.impl.persistence.entity.ByteArrayEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) AttachmentEntity(org.activiti.engine.impl.persistence.entity.AttachmentEntity) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 10 with ExecutionEntity

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

the class DeleteAttachmentCmd method execute.

public Object execute(CommandContext commandContext) {
    AttachmentEntity attachment = commandContext.getDbSqlSession().selectById(AttachmentEntity.class, attachmentId);
    commandContext.getDbSqlSession().delete(attachment);
    if (attachment.getContentId() != null) {
        commandContext.getByteArrayEntityManager().deleteByteArrayById(attachment.getContentId());
    }
    if (attachment.getTaskId() != null) {
        commandContext.getHistoryManager().createAttachmentComment(attachment.getTaskId(), attachment.getProcessInstanceId(), attachment.getName(), false);
    }
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        String processInstanceId = attachment.getProcessInstanceId();
        if (attachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }
    return null;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) AttachmentEntity(org.activiti.engine.impl.persistence.entity.AttachmentEntity)

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