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);
}
}
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations