예제 #1
0
  @SuppressWarnings("unchecked")
  protected void addSignalEventSubscriptions(ProcessDefinitionEntity processDefinition) {
    List<EventSubscriptionDeclaration> eventDefinitions =
        (List<EventSubscriptionDeclaration>)
            processDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
    if (eventDefinitions != null) {
      for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
        if (eventDefinition.getEventType().equals("signal") && eventDefinition.isStartEvent()) {

          SignalEventSubscriptionEntity subscriptionEntity = new SignalEventSubscriptionEntity();
          subscriptionEntity.setEventName(eventDefinition.getEventName());
          subscriptionEntity.setActivityId(eventDefinition.getActivityId());
          subscriptionEntity.setProcessDefinitionId(processDefinition.getId());
          if (processDefinition.getTenantId() != null) {
            subscriptionEntity.setTenantId(processDefinition.getTenantId());
          }
          subscriptionEntity.insert();
        }
      }
    }
  }
예제 #2
0
  @SuppressWarnings("unchecked")
  protected void addTimerDeclarations(
      ProcessDefinitionEntity processDefinition, List<TimerEntity> timers) {
    List<TimerDeclarationImpl> timerDeclarations =
        (List<TimerDeclarationImpl>)
            processDefinition.getProperty(BpmnParse.PROPERTYNAME_START_TIMER);
    if (timerDeclarations != null) {
      for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
        TimerEntity timer = timerDeclaration.prepareTimerEntity(null);
        if (timer != null) {
          timer.setProcessDefinitionId(processDefinition.getId());

          // Inherit timer (if appliccable)
          if (processDefinition.getTenantId() != null) {
            timer.setTenantId(processDefinition.getTenantId());
          }
          timers.add(timer);
        }
      }
    }
  }
예제 #3
0
  public FirstTaskForm execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinitionEntity =
        Context.getProcessEngineConfiguration()
            .getDeploymentManager()
            .findDeployedProcessDefinitionById(processDefinitionId);

    if (processDefinitionEntity == null) {
      throw new IllegalArgumentException("cannot find processDefinition : " + processDefinitionId);
    }

    if (processDefinitionEntity.hasStartFormKey()) {
      return this.findStartEventForm(processDefinitionEntity);
    }

    ActivityImpl startActivity = processDefinitionEntity.getInitial();

    if (startActivity.getOutgoingTransitions().size() != 1) {
      throw new IllegalStateException(
          "start activity outgoing transitions cannot more than 1, now is : "
              + startActivity.getOutgoingTransitions().size());
    }

    PvmTransition pvmTransition = startActivity.getOutgoingTransitions().get(0);
    PvmActivity targetActivity = pvmTransition.getDestination();

    if (!"userTask".equals(targetActivity.getProperty("type"))) {
      logger.info("first activity is not userTask, just skip");

      return new FirstTaskForm();
    }

    FirstTaskForm firstTaskForm = new FirstTaskForm();
    firstTaskForm.setProcessDefinitionId(processDefinitionId);
    firstTaskForm.setExists(true);
    firstTaskForm.setTaskForm(true);

    String taskDefinitionKey = targetActivity.getId();
    logger.debug("activityId : {}", targetActivity.getId());
    firstTaskForm.setActivityId(taskDefinitionKey);

    TaskDefinition taskDefinition =
        processDefinitionEntity.getTaskDefinitions().get(taskDefinitionKey);

    Expression expression = taskDefinition.getAssigneeExpression();

    if (expression != null) {
      String expressionText = expression.getExpressionText();
      logger.debug("{}", expressionText);
      logger.debug("{}", startActivity.getProperties());
      logger.debug("{}", processDefinitionEntity.getProperties());
      firstTaskForm.setAssignee(expressionText);
    } else {
      logger.info("cannot find expression : {}, {}", processDefinitionId, taskDefinitionKey);
    }

    String initiatorVariableName =
        (String)
            processDefinitionEntity.getProperty(BpmnParse.PROPERTYNAME_INITIATOR_VARIABLE_NAME);
    firstTaskForm.setInitiatorName(initiatorVariableName);

    DefaultFormHandler formHandler = (DefaultFormHandler) taskDefinition.getTaskFormHandler();

    if (formHandler.getFormKey() != null) {
      String formKey = formHandler.getFormKey().getExpressionText();
      firstTaskForm.setFormKey(formKey);
    } else {
      logger.info("cannot formKey : {}, {}", processDefinitionId, taskDefinitionKey);
    }

    return firstTaskForm;
  }
예제 #4
0
  @SuppressWarnings("unchecked")
  protected void addMessageEventSubscriptions(ProcessDefinitionEntity processDefinition) {
    CommandContext commandContext = Context.getCommandContext();
    List<EventSubscriptionDeclaration> eventDefinitions =
        (List<EventSubscriptionDeclaration>)
            processDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
    if (eventDefinitions != null) {

      Set<String> messageNames = new HashSet<String>();
      for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
        if (eventDefinition.getEventType().equals("message") && eventDefinition.isStartEvent()) {

          if (!messageNames.contains(eventDefinition.getEventName())) {
            messageNames.add(eventDefinition.getEventName());
          } else {
            throw new ActivitiException(
                "Cannot deploy process definition '"
                    + processDefinition.getResourceName()
                    + "': there are multiple message event subscriptions for the message with name '"
                    + eventDefinition.getEventName()
                    + "'.");
          }

          // look for subscriptions for the same name in db:
          List<EventSubscriptionEntity> subscriptionsForSameMessageName =
              commandContext
                  .getEventSubscriptionEntityManager()
                  .findEventSubscriptionsByName(
                      MessageEventHandler.EVENT_HANDLER_TYPE,
                      eventDefinition.getEventName(),
                      processDefinition.getTenantId());

          // also look for subscriptions created in the session:
          List<MessageEventSubscriptionEntity> cachedSubscriptions =
              commandContext.getDbSqlSession().findInCache(MessageEventSubscriptionEntity.class);
          for (MessageEventSubscriptionEntity cachedSubscription : cachedSubscriptions) {
            if (eventDefinition.getEventName().equals(cachedSubscription.getEventName())
                && !subscriptionsForSameMessageName.contains(cachedSubscription)) {
              subscriptionsForSameMessageName.add(cachedSubscription);
            }
          }

          // remove subscriptions deleted in the same command
          subscriptionsForSameMessageName =
              commandContext
                  .getDbSqlSession()
                  .pruneDeletedEntities(subscriptionsForSameMessageName);

          for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsForSameMessageName) {
            // throw exception only if there's already a subscription as start event

            // no process instance-id = it's a message start event
            if (StringUtils.isEmpty(eventSubscriptionEntity.getProcessInstanceId())) {
              throw new ActivitiException(
                  "Cannot deploy process definition '"
                      + processDefinition.getResourceName()
                      + "': there already is a message event subscription for the message with name '"
                      + eventDefinition.getEventName()
                      + "'.");
            }
          }

          MessageEventSubscriptionEntity newSubscription = new MessageEventSubscriptionEntity();
          newSubscription.setEventName(eventDefinition.getEventName());
          newSubscription.setActivityId(eventDefinition.getActivityId());
          newSubscription.setConfiguration(processDefinition.getId());
          newSubscription.setProcessDefinitionId(processDefinition.getId());

          if (processDefinition.getTenantId() != null) {
            newSubscription.setTenantId(processDefinition.getTenantId());
          }

          newSubscription.insert();
        }
      }
    }
  }