コード例 #1
0
  protected void configureTimerInstance(Timer timer, TimerInstance timerInstance) {
    String s = null;
    long duration = -1;
    switch (timer.getTimeType()) {
      case Timer.TIME_CYCLE:
        if (timer.getPeriod() != null) {
          timerInstance.setDelay(resolveValue(timer.getDelay()));
          if (timer.getPeriod() == null) {
            timerInstance.setPeriod(0);
          } else {
            timerInstance.setPeriod(resolveValue(timer.getPeriod()));
          }
        } else {
          if (CronExpression.isValidExpression(timer.getDelay())) {
            timerInstance.setCronExpression(timer.getDelay());
          } else {

            // when using ISO date/time period is not set
            long[] repeatValues = null;
            try {
              repeatValues = DateTimeUtils.parseRepeatableDateTime(timer.getDelay());
            } catch (RuntimeException e) {
              // cannot parse delay, trying to interpret it
              s = resolveVariable(timer.getDelay());
              repeatValues = DateTimeUtils.parseRepeatableDateTime(s);
            }
            if (repeatValues.length == 3) {
              int parsedReapedCount = (int) repeatValues[0];
              if (parsedReapedCount > -1) {
                timerInstance.setRepeatLimit(parsedReapedCount + 1);
              }
              timerInstance.setDelay(repeatValues[1]);
              timerInstance.setPeriod(repeatValues[2]);
            } else if (repeatValues.length == 2) {
              timerInstance.setDelay(repeatValues[0]);
              timerInstance.setPeriod(repeatValues[1]);
            } else {
              timerInstance.setDelay(repeatValues[0]);
              timerInstance.setPeriod(0);
            }
          }
        }
        break;
      case Timer.TIME_DURATION:
        try {
          duration = DateTimeUtils.parseDuration(timer.getDelay());
        } catch (RuntimeException e) {
          // cannot parse delay, trying to interpret it
          s = resolveVariable(timer.getDelay());
          duration = DateTimeUtils.parseDuration(s);
        }
        timerInstance.setDelay(duration);
        timerInstance.setPeriod(0);
        break;
      case Timer.TIME_DATE:
        try {
          duration = DateTimeUtils.parseDateAsDuration(timer.getDate());
        } catch (RuntimeException e) {
          // cannot parse delay, trying to interpret it
          s = resolveVariable(timer.getDate());
          duration = DateTimeUtils.parseDateAsDuration(s);
        }
        timerInstance.setDelay(duration);
        timerInstance.setPeriod(0);
        break;

      default:
        break;
    }
  }
コード例 #2
0
  protected TimerInstance createTimerInstance(Timer timer) {
    TimerInstance timerInstance = new TimerInstance();
    KnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    if (kruntime != null && kruntime.getEnvironment().get("jbpm.business.calendar") != null) {
      BusinessCalendar businessCalendar =
          (BusinessCalendar) kruntime.getEnvironment().get("jbpm.business.calendar");
      String delay = null;
      switch (timer.getTimeType()) {
        case Timer.TIME_CYCLE:
          if (CronExpression.isValidExpression(timer.getDelay())) {
            timerInstance.setCronExpression(timer.getDelay());
          } else {

            String tempDelay = resolveVariable(timer.getDelay());
            String tempPeriod = resolveVariable(timer.getPeriod());
            if (DateTimeUtils.isRepeatable(tempDelay)) {
              String[] values = DateTimeUtils.parseISORepeatable(tempDelay);
              String tempRepeatLimit = values[0];
              tempDelay = values[1];
              tempPeriod = values[2];

              if (!tempRepeatLimit.isEmpty()) {
                try {
                  int repeatLimit = Integer.parseInt(tempRepeatLimit);
                  if (repeatLimit > -1) {
                    timerInstance.setRepeatLimit(repeatLimit + 1);
                  }
                } catch (NumberFormatException e) {
                  // ignore
                }
              }
            }

            timerInstance.setDelay(businessCalendar.calculateBusinessTimeAsDuration(tempDelay));

            if (tempPeriod == null) {
              timerInstance.setPeriod(0);
            } else {
              timerInstance.setPeriod(businessCalendar.calculateBusinessTimeAsDuration(tempPeriod));
            }
          }
          break;
        case Timer.TIME_DURATION:
          delay = resolveVariable(timer.getDelay());

          timerInstance.setDelay(businessCalendar.calculateBusinessTimeAsDuration(delay));
          timerInstance.setPeriod(0);
          break;
        case Timer.TIME_DATE:
          // even though calendar is available concrete date was provided so it shall be used
          configureTimerInstance(timer, timerInstance);
        default:
          break;
      }

    } else {
      configureTimerInstance(timer, timerInstance);
    }
    timerInstance.setTimerId(timer.getId());
    return timerInstance;
  }