Ejemplo n.º 1
0
 /**
  * Compute a time range based on a specific time.
  *
  * @return The time range that encloses the specific time.
  */
 protected TimeRange computeRange(Time time) {
   // set the period to "today" (local!) from day start to next day start, not end inclusive
   TimeBreakdown brk = time.breakdownLocal();
   brk.setMs(0);
   brk.setSec(0);
   brk.setMin(0);
   brk.setHour(0);
   Time start = timeService().newTimeLocal(brk);
   Time end = timeService().newTime(start.getTime() + 24 * 60 * 60 * 1000);
   return timeService().newTimeRange(start, end, true, false);
 }
Ejemplo n.º 2
0
  /* (non-Javadoc)
   * @see org.sakaiproject.tool.calendar.schedimportreaders.Reader#filterEvents(java.util.List, java.lang.String[])
   */
  public List filterEvents(List events, String[] customFieldNames) throws ImportException {
    setColumnDelimiter(",");

    Map augmentedMapping = getDefaultColumnMap();

    // Add custom fields.
    if (customFieldNames != null) {
      for (int i = 0; i < customFieldNames.length; i++) {
        augmentedMapping.put(customFieldNames[i], customFieldNames[i]);
      }
    }

    // Use the default mappings
    setColumnHeaderToAtributeMapping(augmentedMapping);

    Iterator it = events.iterator();

    int lineNumber = 2; // The headers are (or should be) on line 1.

    //
    // Convert the date/time fields as they appear in the Outlook import to
    // be a synthesized start/end timerange.
    //
    while (it.hasNext()) {
      Map eventProperties = (Map) it.next();

      Date startTime =
          (Date)
              eventProperties.get(
                  defaultHeaderMap.get(GenericCalendarImporter.START_TIME_DEFAULT_COLUMN_HEADER));
      TimeBreakdown startTimeBreakdown = null;

      if (startTime != null) {
        // if the source time zone were known, this would be
        // a good place to set it: startCal.setTimeZone()
        GregorianCalendar startCal = new GregorianCalendar();
        startCal.setTimeInMillis(startTime.getTime());
        startTimeBreakdown =
            getTimeService()
                .newTimeBreakdown(
                    0,
                    0,
                    0,
                    startCal.get(Calendar.HOUR_OF_DAY),
                    startCal.get(Calendar.MINUTE),
                    startCal.get(Calendar.SECOND),
                    0);
      }

      Integer durationInMinutes =
          (Integer)
              eventProperties.get(
                  defaultHeaderMap.get(GenericCalendarImporter.DURATION_DEFAULT_COLUMN_HEADER));

      if (durationInMinutes == null) {
        Integer line = Integer.valueOf(lineNumber);
        String msg = (String) rb.getFormattedMessage("err_no_dur", new Object[] {line});
        throw new ImportException(msg);
      }

      Date endTime = new Date(startTime.getTime() + (durationInMinutes.longValue() * 60 * 1000));

      TimeBreakdown endTimeBreakdown = null;

      if (endTime != null) {
        // if the source time zone were known, this would be
        // a good place to set it: endCal.setTimeZone()
        GregorianCalendar endCal = new GregorianCalendar();
        endCal.setTimeInMillis(endTime.getTime());
        endTimeBreakdown =
            getTimeService()
                .newTimeBreakdown(
                    0,
                    0,
                    0,
                    endCal.get(Calendar.HOUR_OF_DAY),
                    endCal.get(Calendar.MINUTE),
                    endCal.get(Calendar.SECOND),
                    0);
      }

      Date startDate =
          (Date)
              eventProperties.get(
                  defaultHeaderMap.get(GenericCalendarImporter.DATE_DEFAULT_COLUMN_HEADER));
      TimeBreakdown startDateBreakdown = null;

      if (startDate != null) {
        // if the source time zone were known, this would be
        // a good place to set it: endCal.setTimeZone()
        GregorianCalendar startCal = new GregorianCalendar();
        startCal.setTimeInMillis(startDate.getTime());

        startTimeBreakdown.setYear(startCal.get(Calendar.YEAR));
        startTimeBreakdown.setMonth(startCal.get(Calendar.MONTH) + 1);
        startTimeBreakdown.setDay(startCal.get(Calendar.DAY_OF_MONTH));

        endTimeBreakdown.setYear(startCal.get(Calendar.YEAR));
        endTimeBreakdown.setMonth(startCal.get(Calendar.MONTH) + 1);
        endTimeBreakdown.setDay(startCal.get(Calendar.DAY_OF_MONTH));
      } else {
        Integer line = Integer.valueOf(lineNumber);
        String msg = (String) rb.getFormattedMessage("err_no_start", new Object[] {line});
        throw new ImportException(msg);
      }

      eventProperties.put(
          GenericCalendarImporter.ACTUAL_TIMERANGE,
          getTimeService()
              .newTimeRange(
                  getTimeService().newTimeLocal(startTimeBreakdown),
                  getTimeService().newTimeLocal(endTimeBreakdown),
                  true,
                  false));

      lineNumber++;
    }

    return events;
  }