Changeset 2532


Ignore:
Timestamp:
Jun 26, 2014, 4:27:52 PM (9 years ago)
Author:
olle
Message:

Refs #607. Lab environment extension configuration file updated to accept lab sensor start date both in YYYYMMDD and YYYY-MM-DD format, and alarm start and end times in HHMM, HH:MM, HHMMSS, and HH:MM:SS formats:

  1. Class/file LabEnvironmentConfiguration.java in src/net/sf/basedb/labenv/ updated:
    a. Private method void fetchConfiguration() updated to call new private convenience method String convertToDateStringWithHyphens(String dateStr) to convert input sensor start date to format YYYY-MM-DD.
    b. Private method List<LabSensorAlarmConfig> fetchLabSensorAlarmList(Element labSensorTag, Namespace ns) updated to call new private convenience method String convertToTimeStringInFormatHHMM(String timeStr) to convert input alarm start and end times to HHMM format.
    c. New private convenience method String convertToDateStringWithHyphens(String dateStr) added. It converts input date string from format YYYYMMDD to YYYY-MM-DD, if necessary.
    d. New private convenience method String convertToTimeStringInFormatHHMM(String timeStr) added. It converts input time string from formats HHMMSS, HH:MM:SS, and HH:MM to HHMM, if necessary. If input time contains seconds, the latter will be dropped, i.e. the minute entry will not be incremented if the number of seconds >= 30.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv/LabEnvironmentConfiguration.java

    r2432 r2532  
    274274                    String nameConf = Values.getStringOrNull(labSensorTag.getChildText("name", ns));
    275275                    String startDateConf = Values.getStringOrNull(labSensorTag.getChildText("startdate", ns));
     276                    startDateConf = convertToDateStringWithHyphens(startDateConf);
    276277                    List<LabSensorAlarmConfig> alarmList = fetchLabSensorAlarmList(labSensorTag, ns);
    277278                    log.debug("numberConf = " + numberConf + " urlConf = " + urlConf + " nameConf = \"" + nameConf + "\" startDateConf = " + startDateConf);
     
    327328  }
    328329
     330
    329331  @SuppressWarnings("unchecked")
    330332  private List<LabSensorAlarmConfig> fetchLabSensorAlarmList(Element labSensorTag, Namespace ns)
     
    343345            {
    344346                String startTimeConf = Values.getStringOrNull(alarmTag.getChildText("starttime", ns));
     347                startTimeConf = convertToTimeStringInFormatHHMM(startTimeConf);
    345348                String endTimeConf = Values.getStringOrNull(alarmTag.getChildText("endtime", ns));
     349                endTimeConf = convertToTimeStringInFormatHHMM(endTimeConf);
    346350                String weekdayFilterConf = Values.getStringOrNull(alarmTag.getChildText("weekdayfilter", ns));
    347351                Double temperatureMinConf = Values.getDouble(alarmTag.getChildText("temperaturemin", ns), null);
     
    480484  }
    481485
     486
     487  /**
     488   * Converts input date string from format YYYYMMDD to YYYY-MM-DD,
     489   * if necessary.
     490   *
     491   * @param dateStr String Input date string
     492   * @return String Date string in YYYY-MM-DD format if input in YYYYMMDD, otherwise no change
     493   */
     494  String convertToDateStringWithHyphens(String dateStr)
     495  {
     496    String outDateStr = dateStr;
     497    if (dateStr != null)
     498    {
     499      if (dateStr.length() == 8)
     500      {
     501        // Expected format: YYYYMMDD
     502        String yearStr = dateStr.substring(0, 4);
     503        String monthStr = dateStr.substring(4, 6);
     504        String dayStr = dateStr.substring(6, 8);
     505        outDateStr = yearStr + "-" + monthStr + "-" + dayStr;
     506      }
     507    }
     508    return outDateStr;
     509  }
     510
     511  /**
     512   * Converts input time string from formats HHMMSS, HH:MM:SS, and HH:MM to HHMM,
     513   * if necessary. If input time contains seconds, the latter will be dropped,
     514   * i.e. the minute entry will not be incremented if the number of seconds >= 30.
     515   * If input time string is null or an empty string, no change.
     516   *
     517   * @param timeStr String Input time string
     518   * @return String Time string in HHMM format
     519   */
     520  String convertToTimeStringInFormatHHMM(String timeStr)
     521  {
     522    String outTimeStr = timeStr;
     523    if (timeStr != null)
     524    {
     525      if (timeStr.length() == 8)
     526      {
     527        // Expected format: HH:MM:SS
     528        String hourStr = timeStr.substring(0, 2);
     529        String minuteStr = timeStr.substring(3, 5);
     530        outTimeStr = hourStr + minuteStr;
     531      }
     532      else if (timeStr.length() == 6)
     533      {
     534        // Expected format: HHMMSS
     535        String hourStr = timeStr.substring(0, 2);
     536        String minuteStr = timeStr.substring(2, 4);
     537        outTimeStr = hourStr + minuteStr;
     538      }
     539      else if (timeStr.length() == 5)
     540      {
     541        // Expected format: HH:MM
     542        String hourStr = timeStr.substring(0, 2);
     543        String minuteStr = timeStr.substring(3, 5);
     544        outTimeStr = hourStr + minuteStr;
     545      }
     546    }
     547    return outTimeStr;
     548  }
     549
    482550  private LabSensorAlarmConfig createIfNeeded(LabSensorAlarmConfig labSensorAlarmConfig)
    483551  {
Note: See TracChangeset for help on using the changeset viewer.