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