private void parseDate(String param) {
   String newParam = extractParameter(param);
   try {
     if (newParam.endsWith("Z")) {
       /* The string representation of an instant includes a Z at the end, but this is not
        *  a valid format for the parser. */
       newParam = newParam.substring(0, param.length() - 1);
     }
     mDateTime = DateTime.parse(newParam, ISODateTimeFormat.localDateOptionalTimeParser());
     mPeriod = null;
   } catch (IllegalArgumentException ignored) {
     mPeriod = toPeriod(newParam);
     mDateTime = null;
   }
 }
示例#2
0
  abstract static class JodaDeserializer<T> extends StdScalarDeserializer<T> {
    static final DateTimeFormatter _localDateTimeFormat =
        ISODateTimeFormat.localDateOptionalTimeParser();

    protected JodaDeserializer(Class<T> cls) {
      super(cls);
    }

    protected DateTime parseLocal(JsonParser jp) throws IOException, JsonProcessingException {
      String str = jp.getText().trim();
      if (str.length() == 0) { // [JACKSON-360]
        return null;
      }
      return _localDateTimeFormat.parseDateTime(str);
    }
  }
  protected static ScheduledEventCreateParam createScheduledOrder(OrderCreateParam orderParam) {
    if (!isSchedulerEnabled()) {
      return null;
    }
    ScheduleInfo scheduleInfo = new ScheduleInfo();
    String cycleFrequency = params.get("scheduler.cycleFrequency");
    if (cycleFrequency != null) {
      scheduleInfo.setCycleFrequency(Integer.parseInt(cycleFrequency));
    } else {
      scheduleInfo.setCycleFrequency(1);
    }

    String cycleType = params.get("scheduler.cycleType");
    if (cycleType != null) {
      ScheduleCycleType cycleTypeEnum = ScheduleCycleType.valueOf(cycleType);
      scheduleInfo.setCycleType(cycleTypeEnum);
      List<String> sectionsInCycleList = Lists.newArrayList();
      if (cycleTypeEnum == ScheduleCycleType.WEEKLY) {
        String sectionsInCycle = params.get("scheduler.dayOfWeek");
        sectionsInCycleList.add(sectionsInCycle);
      } else if (cycleTypeEnum == ScheduleCycleType.MONTHLY) {
        String sectionsInCycle = params.get("scheduler.dayOfMonth");
        sectionsInCycleList.add(sectionsInCycle);
      }
      scheduleInfo.setSectionsInCycle(sectionsInCycleList);
    } else {
      scheduleInfo.setCycleType(ScheduleCycleType.DAILY);
    }

    String currentTimezoneOffsetInMins = params.get("scheduler.currentTimezoneOffsetInMins");
    Integer timezoneOffset = Integer.parseInt(currentTimezoneOffsetInMins);

    String startDate = params.get("scheduler.startDate");
    String startTime = params.get("scheduler.startTime");

    String isoDateTimeStr = String.format("%sT%s", startDate, startTime);
    DateTime startDateTime =
        DateTime.parse(
            isoDateTimeStr,
            ISODateTimeFormat.localDateOptionalTimeParser()
                .withZone(TimeUtils.getLocalTimeZone(timezoneOffset)));
    startDateTime = startDateTime.withZone(DateTimeZone.UTC);
    scheduleInfo.setHourOfDay(startDateTime.getHourOfDay());
    scheduleInfo.setMinuteOfHour(startDateTime.getMinuteOfHour());
    scheduleInfo.setStartDate(
        String.format(
            "%d-%02d-%02d",
            startDateTime.getYear(),
            startDateTime.getMonthOfYear(),
            startDateTime.getDayOfMonth()));

    String recurrence = params.get("scheduler.recurrence");
    int recurrenceNum = 1;
    if (recurrence != null) {
      recurrenceNum = Integer.parseInt(recurrence);
      if (recurrenceNum == -1) {
        String range = params.get("scheduler.rangeOfRecurrence");
        recurrenceNum = Integer.parseInt(range);
      }
    }
    scheduleInfo.setReoccurrence(recurrenceNum);

    /*
     * if reoccurence number large than 1, we must make sure the name contains patten {datetime},
     * with the pattern in the name, vipr know how to generate dynamic name for each snaphot/fullcopy.
     */
    if (recurrenceNum != 1) {
      List<Parameter> parameters = orderParam.getParameters();
      CatalogServiceRestRep service =
          CatalogServiceUtils.getCatalogService(orderParam.getCatalogService());
      Logger.info("creating order with parameter for: " + service.getBaseService());
      String nameToValidate = SCHEDULED_SERVICE.get(service.getBaseService());
      for (Parameter parameter : parameters) {
        if (parameter.getLabel().equals(nameToValidate)
            && !parameter.getValue().contains("{datetime}")) {
          Validation.addError(
              nameToValidate,
              "need to add patten '{datetime}' in the name for reoccuring scheduled operation");
        }
        Logger.info(
            parameter.getLabel()
                + " = "
                + parameter.getValue()
                + ", "
                + parameter.getFriendlyLabel()
                + " = "
                + parameter.getFriendlyValue());
      }
    }

    String maxNumOfCopies = params.get("scheduler.maxNumOfCopies");
    if (maxNumOfCopies != null) {
      orderParam.setAdditionalScheduleInfo(maxNumOfCopies);
    }

    scheduleInfo.setDurationLength(3600);
    ScheduledEventCreateParam eventParam = new ScheduledEventCreateParam();
    eventParam.setOrderCreateParam(orderParam);
    eventParam.setScheduleInfo(scheduleInfo);

    return eventParam;
  }