use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class ParallelMultiInstanceBehavior method createInstances.
/**
* Handles the parallel case of spawning the instances.
* Will create child executions accordingly for every instance needed.
*/
protected void createInstances(ActivityExecution execution) throws Exception {
int nrOfInstances = resolveNrOfInstances(execution);
if (nrOfInstances < 0) {
throw new ActivitiIllegalArgumentException("Invalid number of instances: must be non-negative integer value" + ", but was " + nrOfInstances);
}
setLoopVariable(execution, NUMBER_OF_INSTANCES, nrOfInstances);
setLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES, 0);
setLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES, nrOfInstances);
List<ActivityExecution> concurrentExecutions = new ArrayList<ActivityExecution>();
for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
ActivityExecution concurrentExecution = execution.createExecution();
concurrentExecution.setActive(true);
concurrentExecution.setConcurrent(true);
concurrentExecution.setScope(false);
// without any differentiation to which embedded subprocess they belong
if (isExtraScopeNeeded()) {
ActivityExecution extraScopedExecution = concurrentExecution.createExecution();
extraScopedExecution.setActive(true);
extraScopedExecution.setConcurrent(false);
extraScopedExecution.setScope(true);
concurrentExecution = extraScopedExecution;
}
concurrentExecutions.add(concurrentExecution);
logLoopDetails(concurrentExecution, "initialized", loopCounter, 0, nrOfInstances, nrOfInstances);
}
// due to possible child execution pruning.
for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
ActivityExecution concurrentExecution = concurrentExecutions.get(loopCounter);
// and completionCondition has been met in the meantime
if (concurrentExecution.isActive() && !concurrentExecution.isEnded() && concurrentExecution.getParent().isActive() && !concurrentExecution.getParent().isEnded()) {
setLoopVariable(concurrentExecution, getCollectionElementIndexVariable(), loopCounter);
executeOriginalBehavior(concurrentExecution, loopCounter);
}
}
// have been a better solution), as it would break boundary event behavior.
if (!concurrentExecutions.isEmpty()) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
executionEntity.setActive(false);
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class ProcessInstanceQueryImpl method localize.
protected void localize(ProcessInstance processInstance) {
ExecutionEntity processInstanceExecution = (ExecutionEntity) processInstance;
processInstanceExecution.setLocalizedName(null);
processInstanceExecution.setLocalizedDescription(null);
if (locale != null) {
String processDefinitionId = processInstanceExecution.getProcessDefinitionId();
if (processDefinitionId != null) {
ObjectNode languageNode = Context.getLocalizationElementProperties(locale, processInstanceExecution.getProcessDefinitionKey(), processDefinitionId, withLocalizationFallback);
if (languageNode != null) {
JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
if (languageNameNode != null && languageNameNode.isNull() == false) {
processInstanceExecution.setLocalizedName(languageNameNode.asText());
}
JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
if (languageDescriptionNode != null && languageDescriptionNode.isNull() == false) {
processInstanceExecution.setLocalizedDescription(languageDescriptionNode.asText());
}
}
}
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class ExecutionQueryImpl method localize.
protected void localize(Execution execution, String activityId) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
executionEntity.setLocalizedName(null);
executionEntity.setLocalizedDescription(null);
String processDefinitionId = executionEntity.getProcessDefinitionId();
if (locale != null && processDefinitionId != null) {
ObjectNode languageNode = Context.getLocalizationElementProperties(locale, activityId, processDefinitionId, withLocalizationFallback);
if (languageNode != null) {
JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
if (languageNameNode != null && languageNameNode.isNull() == false) {
executionEntity.setLocalizedName(languageNameNode.asText());
}
JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
if (languageDescriptionNode != null && languageDescriptionNode.isNull() == false) {
executionEntity.setLocalizedDescription(languageDescriptionNode.asText());
}
}
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class AddCommentCmd method execute.
public Comment execute(CommandContext commandContext) {
// Validate task
if (taskId != null) {
TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
if (task == null) {
throw new ActivitiObjectNotFoundException("Cannot find task with id " + taskId, Task.class);
}
if (task.isSuspended()) {
throw new ActivitiException(getSuspendedTaskException());
}
}
if (processInstanceId != null) {
ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
if (execution == null) {
throw new ActivitiObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class);
}
if (execution.isSuspended()) {
throw new ActivitiException(getSuspendedExceptionMessage());
}
}
String userId = Authentication.getAuthenticatedUserId();
CommentEntity comment = new CommentEntity();
comment.setUserId(userId);
comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);
comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
comment.setTaskId(taskId);
comment.setProcessInstanceId(processInstanceId);
comment.setAction(Event.ACTION_ADD_COMMENT);
String eventMessage = message.replaceAll("\\s+", " ");
if (eventMessage.length() > 163) {
eventMessage = eventMessage.substring(0, 160) + "...";
}
comment.setMessage(eventMessage);
comment.setFullMessage(message);
commandContext.getCommentEntityManager().insert(comment);
return comment;
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class AddIdentityLinkForProcessInstanceCmd method execute.
public Void execute(CommandContext commandContext) {
ExecutionEntity processInstance = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
if (processInstance == null) {
throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
}
processInstance.addIdentityLink(userId, groupId, type);
commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true);
return null;
}
Aggregations