public void execute(
      JobEntity job,
      String configuration,
      ExecutionEntity execution,
      CommandContext commandContext) {
    ActivityImpl borderEventActivity = execution.getProcessDefinition().findActivity(configuration);

    if (borderEventActivity == null) {
      throw new ActivitiException(
          "Error while firing timer: border event activity " + configuration + " not found");
    }

    try {

      borderEventActivity.getActivityBehavior().execute(execution);

      if (commandContext.getEventDispatcher().isEnabled()) {
        commandContext
            .getEventDispatcher()
            .dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TIMER_FIRED, job));
      }

    } catch (RuntimeException e) {
      log.error("exception during timer execution", e);
      throw e;

    } catch (Exception e) {
      log.error("exception during timer execution", e);
      throw new ActivitiException("exception during timer execution: " + e.getMessage(), e);
    }
  }
예제 #2
0
  protected void createLocalizationValues(String processDefinitionId, Process process) {
    if (process == null) return;

    CommandContext commandContext = Context.getCommandContext();
    DynamicBpmnService dynamicBpmnService =
        commandContext.getProcessEngineConfiguration().getDynamicBpmnService();
    ObjectNode infoNode = dynamicBpmnService.getProcessDefinitionInfo(processDefinitionId);

    boolean localizationValuesChanged = false;
    List<ExtensionElement> localizationElements =
        process.getExtensionElements().get("localization");
    if (localizationElements != null) {
      for (ExtensionElement localizationElement : localizationElements) {
        if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.equals(
            localizationElement.getNamespacePrefix())) {
          String locale = localizationElement.getAttributeValue(null, "locale");
          String name = localizationElement.getAttributeValue(null, "name");
          String documentation = null;
          List<ExtensionElement> documentationElements =
              localizationElement.getChildElements().get("documentation");
          if (documentationElements != null) {
            for (ExtensionElement documentationElement : documentationElements) {
              documentation = StringUtils.trimToNull(documentationElement.getElementText());
              break;
            }
          }

          String processId = process.getId();
          if (isEqualToCurrentLocalizationValue(locale, processId, "name", name, infoNode)
              == false) {
            dynamicBpmnService.changeLocalizationName(locale, processId, name, infoNode);
            localizationValuesChanged = true;
          }

          if (documentation != null
              && isEqualToCurrentLocalizationValue(
                      locale, processId, "description", documentation, infoNode)
                  == false) {
            dynamicBpmnService.changeLocalizationDescription(
                locale, processId, documentation, infoNode);
            localizationValuesChanged = true;
          }

          break;
        }
      }
    }

    boolean isFlowElementLocalizationChanged =
        localizeFlowElements(process.getFlowElements(), infoNode);
    boolean isDataObjectLocalizationChanged =
        localizeDataObjectElements(process.getDataObjects(), infoNode);
    if (isFlowElementLocalizationChanged || isDataObjectLocalizationChanged) {
      localizationValuesChanged = true;
    }

    if (localizationValuesChanged) {
      dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    }
  }
예제 #3
0
  public void schedule(TimerEntity timer) {
    Date duedate = timer.getDuedate();
    if (duedate == null) {
      throw new ActivitiException("duedate is null");
    }

    CommandContext commandContext = Context.getCommandContext();

    commandContext.getDbSqlSession().insert(timer);

    // Check if this timer fires before the next time the job executor will check for new timers to
    // fire.
    // This is highly unlikely because normally waitTimeInMillis is 5000 (5 seconds)
    // and timers are usually set further in the future

    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    int waitTimeInMillis = jobExecutor.getWaitTimeInMillis();
    if (duedate.getTime() < (ClockUtil.getCurrentTime().getTime() + waitTimeInMillis)) {
      // then notify the job executor.
      commandContext
          .getTransactionContext()
          .addTransactionListener(
              TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor));
    }
  }
  public Object execute(CommandContext commandContext) {
    if (processInstanceId == null) {
      throw new ActivitiException("processInstanceId is null");
    }
    // Check if process instance is still running
    HistoricProcessInstance instance =
        commandContext
            .getHistoricProcessInstanceManager()
            .findHistoricProcessInstance(processInstanceId);

    if (instance == null) {
      throw new ActivitiException(
          "No historic process instance found with id: " + processInstanceId);
    }
    if (instance.getEndTime() == null) {
      throw new ActivitiException(
          "Process instance is still running, cannot delete historic process instance: "
              + processInstanceId);
    }

    commandContext
        .getHistoricProcessInstanceManager()
        .deleteHistoricProcessInstanceById(processInstanceId);

    return null;
  }
예제 #5
0
  protected boolean localizeDataObjectElements(
      List<ValuedDataObject> dataObjects, ObjectNode infoNode) {
    boolean localizationValuesChanged = false;
    CommandContext commandContext = Context.getCommandContext();
    DynamicBpmnService dynamicBpmnService =
        commandContext.getProcessEngineConfiguration().getDynamicBpmnService();

    for (ValuedDataObject dataObject : dataObjects) {
      List<ExtensionElement> localizationElements =
          dataObject.getExtensionElements().get("localization");
      if (localizationElements != null) {
        for (ExtensionElement localizationElement : localizationElements) {
          if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.equals(
              localizationElement.getNamespacePrefix())) {
            String locale = localizationElement.getAttributeValue(null, "locale");
            String name = localizationElement.getAttributeValue(null, "name");
            String documentation = null;

            List<ExtensionElement> documentationElements =
                localizationElement.getChildElements().get("documentation");
            if (documentationElements != null) {
              for (ExtensionElement documentationElement : documentationElements) {
                documentation = StringUtils.trimToNull(documentationElement.getElementText());
                break;
              }
            }

            if (name != null
                && isEqualToCurrentLocalizationValue(
                        locale,
                        dataObject.getName(),
                        DynamicBpmnConstants.LOCALIZATION_NAME,
                        name,
                        infoNode)
                    == false) {
              dynamicBpmnService.changeLocalizationName(
                  locale, dataObject.getName(), name, infoNode);
              localizationValuesChanged = true;
            }

            if (documentation != null
                && isEqualToCurrentLocalizationValue(
                        locale,
                        dataObject.getName(),
                        DynamicBpmnConstants.LOCALIZATION_DESCRIPTION,
                        documentation,
                        infoNode)
                    == false) {

              dynamicBpmnService.changeLocalizationDescription(
                  locale, dataObject.getName(), documentation, infoNode);
              localizationValuesChanged = true;
            }
          }
        }
      }
    }

    return localizationValuesChanged;
  }
예제 #6
0
  public void setDueDate(Date dueDate) {
    this.dueDate = dueDate;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskDueDateChange(id, dueDate);
    }
  }
예제 #7
0
  public void setDescription(String description) {
    this.description = description;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskDescriptionChange(id, description);
    }
  }
예제 #8
0
  public void setName(String taskName) {
    this.name = taskName;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskNameChange(id, taskName);
    }
  }
예제 #9
0
  public void setPriority(int priority) {
    this.priority = priority;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskPriorityChange(id, priority);
    }
  }
예제 #10
0
  public void setParentTaskId(String parentTaskId) {
    this.parentTaskId = parentTaskId;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskParentTaskIdChange(id, parentTaskId);
    }
  }
예제 #11
0
  public void setTaskDefinitionKey(String taskDefinitionKey) {
    this.taskDefinitionKey = taskDefinitionKey;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskDefinitionKeyChange(this, taskDefinitionKey);
    }
  }
예제 #12
0
  public void insert(ExecutionEntity execution) {
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(this);

    if (execution != null) {
      execution.addTask(this);
    }

    commandContext.getHistoryManager().recordTaskCreated(this, execution);
  }
예제 #13
0
  public void send(MessageEntity message) {
    CommandContext commandContext = Context.getCommandContext();

    commandContext.getDbSqlSession().insert(message);

    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    commandContext
        .getTransactionContext()
        .addTransactionListener(
            TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor));
  }
  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(),
                      compensatingExecution.getId(),
                      compensatingExecution.getProcessInstanceId(),
                      compensatingExecution.getProcessDefinitionId()));
        }
        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);
      }
    }
  }
 @Override
 public List<HistoricTaskInstance> executeList(CommandContext commandContext, Page page) {
   ensureVariablesInitialized();
   checkQueryOk();
   if (includeTaskLocalVariables || includeProcessVariables) {
     return commandContext
         .getHistoricTaskInstanceEntityManager()
         .findHistoricTaskInstancesAndVariablesByQueryCriteria(this);
   } else {
     return commandContext
         .getHistoricTaskInstanceEntityManager()
         .findHistoricTaskInstancesByQueryCriteria(this);
   }
 }
예제 #16
0
  protected void addDefinitionInfoToCache(
      ProcessDefinitionEntity processDefinition,
      ProcessEngineConfigurationImpl processEngineConfiguration,
      CommandContext commandContext) {

    if (processEngineConfiguration.isEnableProcessDefinitionInfoCache() == false) {
      return;
    }

    DeploymentManager deploymentManager = processEngineConfiguration.getDeploymentManager();
    ProcessDefinitionInfoEntityManager definitionInfoEntityManager =
        commandContext.getProcessDefinitionInfoEntityManager();
    ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
    ProcessDefinitionInfoEntity definitionInfoEntity =
        definitionInfoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(
            processDefinition.getId());

    ObjectNode infoNode = null;
    if (definitionInfoEntity != null && definitionInfoEntity.getInfoJsonId() != null) {
      byte[] infoBytes =
          definitionInfoEntityManager.findInfoJsonById(definitionInfoEntity.getInfoJsonId());
      if (infoBytes != null) {
        try {
          infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
        } catch (Exception e) {
          throw new ActivitiException(
              "Error deserializing json info for process definition " + processDefinition.getId());
        }
      }
    }

    ProcessDefinitionInfoCacheObject definitionCacheObject = new ProcessDefinitionInfoCacheObject();
    if (definitionInfoEntity == null) {
      definitionCacheObject.setRevision(0);
    } else {
      definitionCacheObject.setId(definitionInfoEntity.getId());
      definitionCacheObject.setRevision(definitionInfoEntity.getRevision());
    }

    if (infoNode == null) {
      infoNode = objectMapper.createObjectNode();
    }
    definitionCacheObject.setInfoNode(infoNode);

    deploymentManager
        .getProcessDefinitionInfoCache()
        .add(processDefinition.getId(), definitionCacheObject);
  }
 public TimeMeasureInstance execute(CommandContext commandContext) {
   TimeMeasureInstance persistedValue =
       commandContext
           .getBaseMeasureManager()
           .findTimeMeasureInstance(measureId, processInstanceId);
   return persistedValue;
 }
예제 #18
0
  public List<HistoricDetail> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    List<HistoricDetail> historicDetails =
        commandContext
            .getHistoricDetailEntityManager()
            .findHistoricDetailsByQueryCriteria(this, page);

    HistoricDetailVariableInstanceUpdateEntity varUpdate = null;
    if (historicDetails != null) {
      for (HistoricDetail historicDetail : historicDetails) {
        if (historicDetail instanceof HistoricDetailVariableInstanceUpdateEntity) {
          varUpdate = (HistoricDetailVariableInstanceUpdateEntity) historicDetail;

          // Touch byte-array to ensure initialized inside context
          varUpdate.getByteArrayValue();

          // ACT-863: EntityManagerFactorySession instance needed for fetching value, touch while
          // inside context to store
          // cached value
          if (varUpdate.getVariableType() instanceof JPAEntityVariableType) {
            // Use HistoricJPAEntityVariableType to force caching of value to return from query
            varUpdate.setVariableType(HistoricJPAEntityVariableType.getSharedInstance());
            varUpdate.getValue();
          }
        }
      }
    }
    return historicDetails;
  }
예제 #19
0
  public void update() {
    // Needed to make history work: the setter will also update the historic task
    setOwner(this.getOwner());
    setAssignee(this.getAssignee());
    setDelegationState(this.getDelegationState());
    setName(this.getName());
    setDescription(this.getDescription());
    setPriority(this.getPriority());
    setCreateTime(this.getCreateTime());
    setDueDate(this.getDueDate());
    setParentTaskId(this.getParentTaskId());

    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update(this);
  }
  @Override
  public Void execute(CommandContext commandContext) {
    if (currentTaskEntity != null) {

      ExecutionEntity execution =
          commandContext
              .getExecutionEntityManager()
              .findExecutionById(currentTaskEntity.getExecutionId());
      execution.setActivity(activity);
      execution.performOperation(AtomicOperation.TRANSITION_CREATE_SCOPE);

      if (variables != null) {
        if (currentTaskEntity.getExecutionId() != null) {
          currentTaskEntity.setExecutionVariables(variables);
        } else {
          currentTaskEntity.setVariables(variables);
        }
      }
      // 删除当前的任务,不能删除当前正在执行的任务,所以要先清除掉关联
      Context.getCommandContext()
          .getTaskEntityManager()
          .deleteTask(currentTaskEntity, TaskEntity.DELETE_REASON_DELETED, false);
    }
    return null;
  }
예제 #21
0
 public IdBlock execute(CommandContext commandContext) {
   PropertyEntity property =
       (PropertyEntity) commandContext.getPropertyEntityManager().findPropertyById("next.dbid");
   long oldValue = Long.parseLong(property.getValue());
   long newValue = oldValue + idBlockSize;
   property.setValue(Long.toString(newValue));
   return new IdBlock(oldValue, newValue - 1);
 }
 @Override
 public long executeCount(CommandContext commandContext) {
   ensureVariablesInitialized();
   checkQueryOk();
   return commandContext
       .getHistoricTaskInstanceEntityManager()
       .findHistoricTaskInstanceCountByQueryCriteria(this);
 }
 public void execute(
     JobEntity job,
     String configuration,
     ExecutionEntity execution,
     CommandContext commandContext) {
   // ATM only AtomicOperationTransitionCreateScope can be performed asynchronously
   AtomicOperation atomicOperation = AtomicOperation.TRANSITION_CREATE_SCOPE;
   commandContext.performOperation(atomicOperation, execution);
 }
예제 #24
0
  public void setOwner(String owner) {
    if (owner == null && this.owner == null) {
      return;
    }
    //    if (owner!=null && owner.equals(this.owner)) {
    //      return;
    //    }
    this.owner = owner;

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskOwnerChange(id, owner);

      if (owner != null && processInstanceId != null) {
        getProcessInstance().involveUser(owner, IdentityLinkType.PARTICIPANT);
      }
    }
  }
예제 #25
0
  protected void removeExistingSignalEventSubScription(
      ProcessDefinitionEntity processDefinition, ProcessDefinitionEntity latestProcessDefinition) {
    if (latestProcessDefinition != null) {
      CommandContext commandContext = Context.getCommandContext();

      List<EventSubscriptionEntity> subscriptionsToDisable =
          commandContext
              .getEventSubscriptionEntityManager()
              .findEventSubscriptionsByTypeAndProcessDefinitionId(
                  SignalEventHandler.EVENT_HANDLER_TYPE,
                  latestProcessDefinition.getId(),
                  latestProcessDefinition.getTenantId());

      for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsToDisable) {
        eventSubscriptionEntity.delete();
      }
    }
  }
 public List<HistoricProcessInstance> executeList(
     CommandContext commandContext,
     Map<String, Object> parameterMap,
     int firstResult,
     int maxResults) {
   return commandContext
       .getHistoricProcessInstanceEntityManager()
       .findHistoricProcessInstancesByNativeQuery(parameterMap, firstResult, maxResults);
 }
예제 #27
0
  public void setAssignee(String assignee) {
    if (assignee == null && this.assignee == null) {
      return;
    }
    this.assignee = assignee;

    CommandContext commandContext = Context.getCommandContext();
    // 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);
      }

      fireEvent(TaskListener.EVENTNAME_ASSIGNMENT);
    }
  }
예제 #28
0
 public Object execute(CommandContext commandContext) {
   if (userId == null) {
     throw new ActivitiException("userId is null");
   }
   UserEntity user = (UserEntity) commandContext.getUserManager().findUserById(userId);
   if (user == null) {
     throw new ActivitiException("user " + userId + " doesn't exist");
   }
   user.setPicture(picture);
   return null;
 }
  public List<ProcessInstance> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    ensureVariablesInitialized();
    List<ProcessInstance> processInstances = null;
    if (includeProcessVariables) {
      processInstances =
          commandContext
              .getExecutionEntityManager()
              .findProcessInstanceAndVariablesByQueryCriteria(this);
    } else {
      processInstances =
          commandContext.getExecutionEntityManager().findProcessInstanceByQueryCriteria(this);
    }

    for (ProcessInstance processInstance : processInstances) {
      localize(processInstance);
    }

    return processInstances;
  }
예제 #30
0
  public Object execute(CommandContext commandContext) {
    if (jobId == null) {
      throw new ActivitiException("jobId is null");
    }

    if (log.isLoggable(Level.FINE)) {
      log.fine("Executing job " + jobId);
    }
    JobEntity job = commandContext.getJobManager().findJobById(jobId);

    if (job == null) {
      throw new ActivitiException("No job found with id '" + jobId + "'");
    }

    JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
    if (jobExecutorContext != null) { // if null, then we are not called by the job executor
      jobExecutorContext.setCurrentJob(job);
    }

    try {
      job.execute(commandContext);
    } catch (RuntimeException exception) {
      // When transaction is rolled back, decrement retries
      CommandExecutor commandExecutor =
          Context.getProcessEngineConfiguration().getCommandExecutorTxRequiresNew();

      commandContext
          .getTransactionContext()
          .addTransactionListener(
              TransactionState.ROLLED_BACK,
              new DecrementJobRetriesListener(commandExecutor, jobId, exception));

      // throw the original exception to indicate the ExecuteJobCmd failed
      throw exception;
    } finally {
      if (jobExecutorContext != null) {
        jobExecutorContext.setCurrentJob(null);
      }
    }
    return null;
  }