Search in sources :

Example 76 with ActivitiException

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

the class ExpressionResolverTest method resolveExpressionsMap_should_keepExpressionContent_when_ObjecNodeContainsAnExpressionUnableToBeResolved.

@Test
public void resolveExpressionsMap_should_keepExpressionContent_when_ObjecNodeContainsAnExpressionUnableToBeResolved() throws IOException {
    // given
    Expression nameExpression = buildExpression("${name}");
    given(expressionEvaluator.evaluate(nameExpression, expressionManager, delegateInterceptor)).willThrow(new ActivitiException("Invalid property"));
    JsonNode node = mapper.readTree("{\"name\":\"${name}\",\"age\": 30}");
    // when
    Map<String, Object> result = expressionResolver.resolveExpressionsMap(expressionEvaluator, singletonMap("node", node));
    // then
    assertThat(result).containsEntry("node", map("name", "${name}", "age", 30));
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Expression(org.activiti.engine.delegate.Expression) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 77 with ActivitiException

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

the class ExpressionResolverTest method resolveExpressionsMap_should_keepExpressionContent_when_notAbleToResolveIt.

@Test
public void resolveExpressionsMap_should_keepExpressionContent_when_notAbleToResolveIt() {
    // given
    Expression expression = buildExpression("${nonResolvableExpression}");
    given(expressionEvaluator.evaluate(expression, expressionManager, delegateInterceptor)).willThrow(new ActivitiException("Invalid property"));
    // when
    Map<String, Object> result = expressionResolver.resolveExpressionsMap(expressionEvaluator, singletonMap("result", "${nonResolvableExpression}"));
    // then
    assertThat(result).containsEntry("result", "${nonResolvableExpression}");
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Expression(org.activiti.engine.delegate.Expression) Test(org.junit.jupiter.api.Test)

Example 78 with ActivitiException

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

the class ExpressionResolverTest method resolveExpressionsMap_should_keepExpressionContent_when_notAbleToResolveExpressionInString.

@Test
public void resolveExpressionsMap_should_keepExpressionContent_when_notAbleToResolveExpressionInString() {
    // given
    Expression expression = buildExpression("${nonResolvableExpression}");
    given(expressionEvaluator.evaluate(expression, expressionManager, delegateInterceptor)).willThrow(new ActivitiException("Invalid property"));
    // when
    Map<String, Object> result = expressionResolver.resolveExpressionsMap(expressionEvaluator, singletonMap("result", "Welcome to ${nonResolvableExpression}!"));
    // then
    assertThat(result).containsEntry("result", "Welcome to ${nonResolvableExpression}!");
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Expression(org.activiti.engine.delegate.Expression) Test(org.junit.jupiter.api.Test)

Example 79 with ActivitiException

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

the class ExecuteActivityForAdhocSubProcessCmd method execute.

public Execution execute(CommandContext commandContext) {
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(executionId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
    }
    if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess)) {
        throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process");
    }
    FlowNode foundNode = null;
    AdhocSubProcess adhocSubProcess = (AdhocSubProcess) execution.getCurrentFlowElement();
    // if sequential ordering, only one child execution can be active
    if (adhocSubProcess.hasSequentialOrdering()) {
        if (execution.getExecutions().size() > 0) {
            throw new ActivitiException("Sequential ad-hoc sub process already has an active execution");
        }
    }
    for (FlowElement flowElement : adhocSubProcess.getFlowElements()) {
        if (activityId.equals(flowElement.getId()) && flowElement instanceof FlowNode) {
            FlowNode flowNode = (FlowNode) flowElement;
            if (flowNode.getIncomingFlows().size() == 0) {
                foundNode = flowNode;
            }
        }
    }
    if (foundNode == null) {
        throw new ActivitiException("The requested activity with id " + activityId + " can not be enabled");
    }
    ExecutionEntity activityExecution = Context.getCommandContext().getExecutionEntityManager().createChildExecution(execution);
    activityExecution.setCurrentFlowElement(foundNode);
    Context.getAgenda().planContinueProcessOperation(activityExecution);
    return activityExecution;
}
Also used : AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) FlowElement(org.activiti.bpmn.model.FlowElement) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 80 with ActivitiException

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

the class CommandContext method getSession.

@SuppressWarnings({ "unchecked" })
public <T> T getSession(Class<T> sessionClass) {
    Session session = sessions.get(sessionClass);
    if (session == null) {
        SessionFactory sessionFactory = sessionFactories.get(sessionClass);
        if (sessionFactory == null) {
            throw new ActivitiException("no session factory configured for " + sessionClass.getName());
        }
        session = sessionFactory.openSession(this);
        sessions.put(sessionClass, session);
    }
    return (T) session;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

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