Search in sources :

Example 81 with ActivitiException

use of org.activiti.engine.ActivitiException 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().findById(configuration);
    String processDefinitionId = compensatingExecution.getProcessDefinitionId();
    Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
    if (process == null) {
        throw new ActivitiException("Cannot start process instance. Process model (id = " + processDefinitionId + ") could not be found");
    }
    FlowElement flowElement = process.getFlowElement(eventSubscription.getActivityId(), true);
    if (flowElement instanceof SubProcess && !((SubProcess) flowElement).isForCompensation()) {
        // descend into scope:
        compensatingExecution.setScope(true);
        List<CompensateEventSubscriptionEntity> eventsForThisScope = commandContext.getEventSubscriptionEntityManager().findCompensateEventSubscriptionsByExecutionId(compensatingExecution.getId());
        ScopeUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);
    } else {
        try {
            if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPENSATE, flowElement.getId(), flowElement.getName(), compensatingExecution.getId(), compensatingExecution.getProcessInstanceId(), compensatingExecution.getProcessDefinitionId(), flowElement));
            }
            compensatingExecution.setCurrentFlowElement(flowElement);
            Context.getAgenda().planContinueProcessInCompensation(compensatingExecution);
        } catch (Exception e) {
            throw new ActivitiException("Error while handling compensation event " + eventSubscription, e);
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) FlowElement(org.activiti.bpmn.model.FlowElement) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) CompensateEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity) ActivitiException(org.activiti.engine.ActivitiException)

Example 82 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class AbstractEventHandler method handleEvent.

public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {
    ExecutionEntity execution = eventSubscription.getExecution();
    FlowNode currentFlowElement = (FlowNode) execution.getCurrentFlowElement();
    if (currentFlowElement == 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);
    }
    Context.getAgenda().planTriggerExecutionOperation(execution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Map(java.util.Map) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 83 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class JPAEntityMappings method findEntity.

private Object findEntity(Class<?> entityClass, Object primaryKey) {
    EntityManager em = Context.getCommandContext().getSession(EntityManagerSession.class).getEntityManager();
    Object entity = em.find(entityClass, primaryKey);
    if (entity == null) {
        throw new ActivitiException("Entity does not exist: " + entityClass.getName() + " - " + primaryKey);
    }
    return entity;
}
Also used : EntityManager(javax.persistence.EntityManager) ActivitiException(org.activiti.engine.ActivitiException)

Example 84 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class JPAEntityListVariableType method deserializeIds.

protected String[] deserializeIds(byte[] bytes) {
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ObjectInputStream in = new ObjectInputStream(bais);
        Object read = in.readObject();
        if (!(read instanceof String[])) {
            throw new ActivitiIllegalArgumentException("Deserialized value is not an array of ID's: " + read);
        }
        return (String[]) read;
    } catch (IOException ioe) {
        throw new ActivitiException("Unexpected exception when deserializing JPA id's", ioe);
    } catch (ClassNotFoundException e) {
        throw new ActivitiException("Unexpected exception when deserializing JPA id's", e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ByteArrayInputStream(java.io.ByteArrayInputStream) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 85 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class JPAEntityListVariableType method setValue.

@Override
public void setValue(Object value, ValueFields valueFields) {
    EntityManagerSession entityManagerSession = Context.getCommandContext().getSession(EntityManagerSession.class);
    if (entityManagerSession == null) {
        throw new ActivitiException("Cannot set JPA variable: " + EntityManagerSession.class + " not configured");
    } else {
        // Before we set the value we must flush all pending changes from
        // the entitymanager
        // If we don't do this, in some cases the primary key will not yet
        // be set in the object
        // which will cause exceptions down the road.
        entityManagerSession.flush();
    }
    if (value instanceof List<?> && ((List<?>) value).size() > 0) {
        List<?> list = (List<?>) value;
        List<String> ids = new ArrayList<String>();
        String type = mappings.getJPAClassString(list.get(0));
        for (Object entry : list) {
            ids.add(mappings.getJPAIdString(entry));
        }
        // Store type in text field and the ID's as a serialized array
        valueFields.setBytes(serializeIds(ids));
        valueFields.setTextValue(type);
    } else if (value == null) {
        valueFields.setBytes(null);
        valueFields.setTextValue(null);
    } else {
        throw new ActivitiIllegalArgumentException("Value is not a list of JPA entities: " + value);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)289 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)45 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)44 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)38 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FlowElement (org.activiti.bpmn.model.FlowElement)19 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Expression (org.activiti.engine.delegate.Expression)17 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)17 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 ObjectOutputStream (java.io.ObjectOutputStream)15 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)15 HashMap (java.util.HashMap)12 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 InputStream (java.io.InputStream)10