Package org.activiti.engine.impl.interceptor

Examples of org.activiti.engine.impl.interceptor.CommandContext


  @SuppressWarnings({ "unchecked", "rawtypes" })
  public void setReplacedBy(InterpretableExecution replacedBy) {
    this.replacedBy = (ExecutionEntity) replacedBy;
   
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();

    // update the related tasks
   
    List<TaskEntity> allTasks = new ArrayList<TaskEntity>();
    allTasks.addAll(getTasks());
   
    List<TaskEntity> cachedTasks = dbSqlSession.findInCache(TaskEntity.class);
    for (TaskEntity cachedTask : cachedTasks) {
      if (cachedTask.getExecutionId().equals(this.getId())) {
        allTasks.add(cachedTask);
      }
    }
   
    for (TaskEntity task: allTasks) {
      task.setExecutionId(replacedBy.getId());
      task.setExecution(this.replacedBy);        
     
      // update the related local task variables
      List<VariableInstanceEntity> variables = (List) commandContext
        .getVariableInstanceEntityManager()
        .findVariableInstancesByTaskId(task.getId());
     
      for (VariableInstanceEntity variable : variables) {
        variable.setExecution(this.replacedBy);
      }
     
      this.replacedBy.addTask(task);
    }
   
    // All tasks have been moved to 'replacedBy', safe to clear the list
    this.tasks.clear();
   
    tasks = dbSqlSession.findInCache(TaskEntity.class);
    for (TaskEntity task: tasks) {
      if (id.equals(task.getExecutionId())) {
        task.setExecutionId(replacedBy.getId());
      }
    }
   
    // update the related jobs
    List<JobEntity> jobs = getJobs();
    for (JobEntity job: jobs) {
      job.setExecution((ExecutionEntity) replacedBy);
    }
   
    // update the related event subscriptions
    List<EventSubscriptionEntity> eventSubscriptions = getEventSubscriptions();
    for (EventSubscriptionEntity subscriptionEntity: eventSubscriptions) {
      subscriptionEntity.setExecution((ExecutionEntity) replacedBy);
    }
   
    // update the related process variables
    List<VariableInstanceEntity> variables = (List) commandContext
      .getVariableInstanceEntityManager()
      .findVariableInstancesByExecutionId(id);
   
    for (VariableInstanceEntity variable: variables) {
      variable.setExecutionId(replacedBy.getId());
    }
    variables = dbSqlSession.findInCache(VariableInstanceEntity.class);
    for (VariableInstanceEntity variable: variables) {
      if (id.equals(variable.getExecutionId())) {
        variable.setExecutionId(replacedBy.getId());
      }
    }
   
    commandContext.getHistoryManager()
      .recordExecutionReplacedBy(this, replacedBy);
  }
View Full Code Here


          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, group));
    }
  }

  public void updateGroup(Group updatedGroup) {
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update((GroupEntity) updatedGroup);
   
    if(getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedGroup));
View Full Code Here

    eventHandler.handleEvent(this, payload, Context.getCommandContext());
  }
 
  protected void scheduleEventAsync(Serializable payload) {
   
    final CommandContext commandContext = Context.getCommandContext();

    MessageEntity message = new MessageEntity();
    message.setJobHandlerType(ProcessEventJobHandler.TYPE);
    message.setJobHandlerConfiguration(id);
    message.setTenantId(getTenantId());
   
    GregorianCalendar expireCal = new GregorianCalendar();
    ProcessEngineConfiguration processEngineConfig = Context.getCommandContext().getProcessEngineConfiguration();
    expireCal.setTime(processEngineConfig.getClock().getCurrentTime());
    expireCal.add(Calendar.SECOND, processEngineConfig.getLockTimeAsyncJobWaitTime());
    message.setLockExpirationTime(expireCal.getTime());

    // TODO: support payload
//    if(payload != null) {
//      message.setEventPayload(payload);
//    }
   
    commandContext.getJobEntityManager().send(message);
  }
View Full Code Here

  public void onEvent(ActivitiEvent event) {
    EventLoggerEventHandler eventHandler = getEventHandler(event);
    if (eventHandler != null) {

      // Events are flushed when command context is closed
      CommandContext currentCommandContext = Context.getCommandContext();
      EventFlusher eventFlusher = (EventFlusher) currentCommandContext.getAttribute(EVENT_FLUSHER_KEY);
     
      if (eventHandler != null && eventFlusher == null) {
       
        eventFlusher = createEventFlusher();
        if (eventFlusher == null) {
          eventFlusher = new DatabaseEventFlusher(); // Default
        }
        currentCommandContext.addAttribute(EVENT_FLUSHER_KEY, eventFlusher);
       
        currentCommandContext.addCloseListener(eventFlusher);
        currentCommandContext
            .addCloseListener(new CommandContextCloseListener() {

              @Override
              public void closing(CommandContext commandContext) {
              }
View Full Code Here

        definition.getEventSupport().dispatchEvent(event);
      }
    } else {
      // Try getting hold of the Process definition, based on the process
      // definition-key, if a context is active
      CommandContext commandContext = Context.getCommandContext();
      if (commandContext != null) {
        ProcessDefinitionEntity processDefinition = extractProcessDefinitionEntityFromEvent(event);
        if (processDefinition != null) {
          processDefinition.getEventSupport().dispatchEvent(event);
        }
View Full Code Here

    task.insert((ExecutionEntity) execution);
    return task;
  }

  public void insert(ExecutionEntity execution) {
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(this);
   
    // Inherit tenant id (if applicable)
    if (execution != null && execution.getTenantId() != null) {
      setTenantId(execution.getTenantId());
    }
   
    if(execution != null) {
      execution.addTask(this);
    }
   
    commandContext.getHistoryManager().recordTaskCreated(this, execution);
   
    if(commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, this));
      commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, this));
    }
  }
View Full Code Here

    setCreateTime(this.getCreateTime());
    setDueDate(this.getDueDate());
    setParentTaskId(this.getParentTaskId());
    setFormKey(formKey);
   
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update(this);
   
    if(commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, this));
    }
  }
View Full Code Here

  // special setters //////////////////////////////////////////////////////////
 
  public void setName(String taskName) {
    this.name = taskName;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext!=null) {
      commandContext
        .getHistoryManager()
        .recordTaskNameChange(id, taskName);
    }
  }
View Full Code Here

  }

  public void setDescription(String description) {
    this.description = description;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext!=null) {
      commandContext
        .getHistoryManager()
        .recordTaskDescriptionChange(id, description);
    }
  }
View Full Code Here

  public void setAssignee(String assignee) {
    setAssignee(assignee, false, false);
  }
 
  public void setAssignee(String assignee, boolean dispatchAssignmentEvent, boolean dispatchUpdateEvent) {
    CommandContext commandContext = Context.getCommandContext();
   
    if (assignee==null && this.assignee==null) {
     
      // ACT-1923: even if assignee is unmodified and null, this should be stored in history.
      if (commandContext!=null) {
        commandContext
          .getHistoryManager()
          .recordTaskAssigneeChange(id, assignee);
      }
     
      return;
    }
    this.assignee = assignee;

    // if there is no command context, then it means that the user is calling the
    // setAssignee outside a service method.  E.g. while creating a new task.
    if (commandContext!=null) {
      commandContext
        .getHistoryManager()
        .recordTaskAssigneeChange(id, assignee);
     
      if (assignee != null && processInstanceId != null) {
        getProcessInstance().involveUser(assignee, IdentityLinkType.PARTICIPANT);
      }
     
      if(!StringUtils.equals(initialAssignee, assignee)) {
        fireEvent(TaskListener.EVENTNAME_ASSIGNMENT);
        initialAssignee = assignee;
      }
     
      if(commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        if(dispatchAssignmentEvent) {
          commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
              ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_ASSIGNED, this));
        }
       
        if(dispatchUpdateEvent) {
          commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
              ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, this));
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.activiti.engine.impl.interceptor.CommandContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.