예제 #1
0
  /**
   * Test whether you can select weekdays using a monthly frequency.
   *
   * <p>This test really belongs in RecurTest, but the weekly range test in this VEventTest matches
   * so perfectly with the daily range test that should produce the same results for some weeks that
   * it was felt leveraging the existing test code was more important.
   *
   * <p>Section 4.3.10 of the iCalendar specification RFC 2445 reads:
   *
   * <pre>
   * If an integer modifier is not present, it means all days of
   * this type within the specified frequency.
   * </pre>
   *
   * This test ensures compliance.
   */
  public final void testGetConsumedTimeMonthly() throws Exception {

    // Test Starts 04/03/2005, Ends two weeks later.
    // Query Calendar Start and End Dates.
    Calendar queryStartDate = getCalendarInstance();
    queryStartDate.set(2005, Calendar.APRIL, 3, 05, 12, 0);
    queryStartDate.set(Calendar.MILLISECOND, 0);
    Calendar queryEndDate = getCalendarInstance();
    queryEndDate.set(2005, Calendar.APRIL, 17, 21, 55, 0);
    queryEndDate.set(Calendar.MILLISECOND, 0);

    // This range is Monday to Friday every month (which has a multiplying
    // effect), starting from March 7th 2005. Our query dates are
    // April 3rd through to the 17th.
    PeriodList monthlyPeriods =
        monthlyWeekdayEvents.getConsumedTime(
            new DateTime(queryStartDate.getTime()), new DateTime(queryEndDate.getTime()));
    PeriodList dailyPeriods =
        dailyWeekdayEvents.getConsumedTime(
            new DateTime(queryStartDate.getTime()), new DateTime(queryEndDate.getTime()));
    Calendar expectedCal = getCalendarInstance();
    expectedCal.set(2005, Calendar.APRIL, 4, 9, 0, 0);
    expectedCal.set(Calendar.MILLISECOND, 0);
    Date expectedStartOfFirstRange = new DateTime(expectedCal.getTime());
    expectedCal.set(2005, Calendar.APRIL, 4, 17, 0, 0);
    expectedCal.set(Calendar.MILLISECOND, 0);
    Date expectedEndOfFirstRange = new DateTime(expectedCal.getTime());
    assertNotNull(monthlyPeriods);
    assertTrue(monthlyPeriods.size() > 0);
    Period firstPeriod = (Period) monthlyPeriods.toArray()[0];
    assertEquals(expectedStartOfFirstRange, firstPeriod.getStart());
    assertEquals(expectedEndOfFirstRange, firstPeriod.getEnd());
    assertEquals(dailyPeriods, monthlyPeriods);
  }
예제 #2
0
  /**
   * Test Null Dates Test Start today, End One month from now.
   *
   * @throws Exception
   */
  public final void testGetConsumedTime() throws Exception {

    // Test Null Dates
    try {
      weekdayNineToFiveEvents.getConsumedTime(null, null);
      fail("Should've thrown an exception.");
    } catch (RuntimeException re) {
      log.info("Expecting an exception here.");
    }

    // Test Start 04/01/2005, End One month later.
    // Query Calendar Start and End Dates.
    Calendar queryStartDate = getCalendarInstance();
    queryStartDate.set(2005, Calendar.APRIL, 1, 14, 47, 0);
    queryStartDate.set(Calendar.MILLISECOND, 0);
    DateTime queryStart = new DateTime(queryStartDate.getTime().getTime());

    Calendar queryEndDate = getCalendarInstance();
    queryEndDate.set(2005, Calendar.MAY, 1, 07, 15, 0);
    queryEndDate.set(Calendar.MILLISECOND, 0);
    DateTime queryEnd = new DateTime(queryEndDate.getTime().getTime());

    Calendar week1EndDate = getCalendarInstance();
    week1EndDate.set(2005, Calendar.APRIL, 8, 11, 15, 0);
    week1EndDate.set(Calendar.MILLISECOND, 0);

    Calendar week4StartDate = getCalendarInstance();
    week4StartDate.set(2005, Calendar.APRIL, 24, 14, 47, 0);
    week4StartDate.set(Calendar.MILLISECOND, 0);
    DateTime week4Start = new DateTime(week4StartDate.getTime().getTime());

    // This range is monday to friday every three weeks, starting from
    // March 7th 2005, which means for our query dates we need
    // April 18th through to the 22nd.
    PeriodList weeklyPeriods = weekdayNineToFiveEvents.getConsumedTime(queryStart, queryEnd);
    PeriodList dailyPeriods = dailyWeekdayEvents.getConsumedTime(queryStart, queryEnd);
    //                                                      week1EndDate.getTime());
    dailyPeriods.addAll(dailyWeekdayEvents.getConsumedTime(week4Start, queryEnd));

    Calendar expectedCal = Calendar.getInstance(TimeZone.getTimeZone(TimeZones.GMT_ID));
    expectedCal.set(2005, Calendar.APRIL, 4, 9, 0, 0);
    expectedCal.set(Calendar.MILLISECOND, 0);
    Date expectedStartOfFirstRange = new DateTime(expectedCal.getTime().getTime());
    expectedCal.set(2005, Calendar.APRIL, 4, 17, 0, 0);
    expectedCal.set(Calendar.MILLISECOND, 0);
    Date expectedEndOfFirstRange = new DateTime(expectedCal.getTime().getTime());
    assertNotNull(weeklyPeriods);
    assertTrue(weeklyPeriods.size() > 0);
    Period firstPeriod = (Period) weeklyPeriods.toArray()[0];
    assertEquals(expectedStartOfFirstRange, firstPeriod.getStart());
    assertEquals(expectedEndOfFirstRange, firstPeriod.getEnd());
    assertEquals(dailyPeriods, weeklyPeriods);
  }
예제 #3
0
  static JAXBElement<? extends BasePropertyType> doProperty(
      final Property prop, final PropertyInfoIndex pii, final boolean wrapXprops) throws Throwable {
    if (prop instanceof XProperty) {
      if (!wrapXprops) {
        return null;
      }

      final XBedeworkWrapperPropType wrapper = new XBedeworkWrapperPropType();

      wrapper.setText(prop.getValue());

      processParameters(prop.getParameters(), wrapper);

      final XBedeworkWrappedNameParamType wnp = new XBedeworkWrappedNameParamType();
      wnp.setText(prop.getName());
      if (wrapper.getParameters() == null) {
        wrapper.setParameters(new ArrayOfParameters());
      }
      wrapper.getParameters().getBaseParameter().add(of.createXBedeworkWrappedName(wnp));

      return of.createXBedeworkWrapper(wrapper);
    }

    switch (pii) {
      case ACTION:
        /* ------------------- Action: Alarm -------------------- */

        ActionPropType a = new ActionPropType();
        a.setText(prop.getValue());
        return of.createAction(a);

      case ATTACH:
        /* ------------------- Attachments -------------------- */
        //          pl.add(setAttachment(att));
        return null;

      case ATTENDEE:
        /* ------------------- Attendees -------------------- */

        final AttendeePropType att = new AttendeePropType();
        att.setCalAddress(prop.getValue());
        return of.createAttendee(att);

      case BUSYTYPE:
        return null;

      case CATEGORIES:
        /* ------------------- Categories -------------------- */

        // LANG - filter on language - group language in one cat list?

        CategoriesPropType c = new CategoriesPropType();
        CategoryList cats = ((Categories) prop).getCategories();

        Iterator pit = cats.iterator();
        while (pit.hasNext()) {
          c.getText().add((String) pit.next());
        }

        return of.createCategories(c);

      case CLASS:
        /* ------------------- Class -------------------- */

        ClassPropType cl = new ClassPropType();
        cl.setText(prop.getValue());
        return of.createClass(cl);

      case COMMENT:
        /* ------------------- Comments -------------------- */

        CommentPropType cm = new CommentPropType();
        cm.setText(prop.getValue());
        return of.createComment(cm);

      case COMPLETED:
        /* ------------------- Completed -------------------- */

        CompletedPropType cmp = new CompletedPropType();
        cmp.setUtcDateTime(XcalUtil.getXMlUTCCal(prop.getValue()));
        return of.createCompleted(cmp);

      case CONTACT:
        /* ------------------- Contact -------------------- */

        // LANG
        ContactPropType ct = new ContactPropType();
        ct.setText(prop.getValue());

        return of.createContact(ct);

      case CREATED:
        /* ------------------- Created -------------------- */

        CreatedPropType created = new CreatedPropType();
        created.setUtcDateTime(XcalUtil.getXMlUTCCal(prop.getValue()));
        return of.createCreated(created);

      case DESCRIPTION:
        /* ------------------- Description -------------------- */

        DescriptionPropType desc = new DescriptionPropType();
        desc.setText(prop.getValue());
        return of.createDescription(desc);

      case DTEND:
        /* ------------------- DtEnd -------------------- */

        DtendPropType dtend = (DtendPropType) makeDateDatetime(new DtendPropType(), prop);
        return of.createDtend(dtend);

      case DTSTAMP:
        /* ------------------- DtStamp -------------------- */

        DtstampPropType dtstamp = new DtstampPropType();
        dtstamp.setUtcDateTime(XcalUtil.getXMlUTCCal(prop.getValue()));
        return of.createDtstamp(dtstamp);

      case DTSTART:
        /* ------------------- DtStart -------------------- */

        DtstartPropType dtstart = (DtstartPropType) makeDateDatetime(new DtstartPropType(), prop);
        return of.createDtstart(dtstart);

      case DUE:
        /* ------------------- Due -------------------- */

        DuePropType due = (DuePropType) makeDateDatetime(new DuePropType(), prop);
        return of.createDue(due);

      case DURATION:
        /* ------------------- Duration -------------------- */

        DurationPropType dur = new DurationPropType();

        dur.setDuration(prop.getValue());
        return of.createDuration(dur);

      case EXDATE:
        /* ------------------- ExDate --below------------ */
        return null;

      case EXRULE:
        /* ------------------- ExRule --below------------- */

        ExrulePropType er = new ExrulePropType();
        er.setRecur(doRecur(((RRule) prop).getRecur()));

        return of.createExrule(er);

      case FREEBUSY:
        /* ------------------- freebusy -------------------- */

        FreeBusy icfb = (FreeBusy) prop;
        PeriodList fbps = icfb.getPeriods();

        if (Util.isEmpty(fbps)) {
          return null;
        }

        FreebusyPropType fb = new FreebusyPropType();

        String fbtype = paramVal(prop, Parameter.FBTYPE);

        if (fbtype != null) {
          ArrayOfParameters pars = getAop(fb);

          FbtypeParamType f = new FbtypeParamType();

          f.setText(fbtype);
          JAXBElement<FbtypeParamType> param = of.createFbtype(f);
          pars.getBaseParameter().add(param);
        }

        List<PeriodType> pdl = fb.getPeriod();

        for (Object o : fbps) {
          Period p = (Period) o;
          PeriodType np = new PeriodType();

          np.setStart(XcalUtil.getXMlUTCCal(p.getStart().toString()));
          np.setEnd(XcalUtil.getXMlUTCCal(p.getEnd().toString()));
          pdl.add(np);
        }

        return of.createFreebusy(fb);

      case GEO:
        /* ------------------- Geo -------------------- */

        Geo geo = (Geo) prop;
        GeoPropType g = new GeoPropType();

        g.setLatitude(geo.getLatitude().floatValue());
        g.setLatitude(geo.getLongitude().floatValue());
        return of.createGeo(g);

      case LAST_MODIFIED:
        /* ------------------- LastModified -------------------- */

        LastModifiedPropType lm = new LastModifiedPropType();
        lm.setUtcDateTime(XcalUtil.getXMlUTCCal(prop.getValue()));
        return of.createLastModified(lm);

      case LOCATION:
        /* ------------------- Location -------------------- */

        LocationPropType l = new LocationPropType();
        l.setText(prop.getValue());

        return of.createLocation(l);

      case METHOD:
        /* ------------------- Method -------------------- */

        MethodPropType m = new MethodPropType();

        m.setText(prop.getValue());
        return of.createMethod(m);

      case ORGANIZER:
        /* ------------------- Organizer -------------------- */

        OrganizerPropType org = new OrganizerPropType();
        org.setCalAddress(prop.getValue());
        return of.createOrganizer(org);

      case PERCENT_COMPLETE:
        /* ------------------- PercentComplete -------------------- */

        PercentCompletePropType p = new PercentCompletePropType();
        p.setInteger(BigInteger.valueOf(((PercentComplete) prop).getPercentage()));

        return of.createPercentComplete(p);

      case PRIORITY:
        /* ------------------- Priority -------------------- */

        PriorityPropType pr = new PriorityPropType();
        pr.setInteger(BigInteger.valueOf(((Priority) prop).getLevel()));

        return of.createPriority(pr);

      case PRODID:
        /* ------------------- Prodid -------------------- */
        ProdidPropType prod = new ProdidPropType();
        prod.setText(prop.getValue());
        return of.createProdid(prod);

      case RDATE:
        /* ------------------- RDate ------------------- */
        // XXX Todo
        return null;

      case RECURRENCE_ID:
        /* ------------------- RecurrenceID -------------------- */

        RecurrenceIdPropType ri = new RecurrenceIdPropType();
        String strval = prop.getValue();

        if (dateOnly(prop)) {
          // RECUR - fix all day recurrences sometime
          if (strval.length() > 8) {
            // Try to fix up bad all day recurrence ids. - assume a local timezone
            strval = strval.substring(0, 8);
          }

          ri.setDate(XcalUtil.fromDtval(strval));
        } else {
          XcalUtil.initDt(ri, strval, getTzid(prop));
        }

        return of.createRecurrenceId(ri);

      case RELATED_TO:
        /* ------------------- RelatedTo -------------------- */

        RelatedToPropType rt = new RelatedToPropType();

        String relType = paramVal(prop, Parameter.RELTYPE);
        String value = paramVal(prop, Parameter.VALUE);

        if ((value == null) || "uid".equalsIgnoreCase(value)) {
          rt.setUid(prop.getValue());
        } else if ("uri".equalsIgnoreCase(value)) {
          rt.setUri(prop.getValue());
        } else {
          rt.setText(prop.getValue());
        }

        if (relType != null) {
          ArrayOfParameters pars = getAop(rt);

          ReltypeParamType r = new ReltypeParamType();
          r.setText(relType);
          JAXBElement<ReltypeParamType> param = of.createReltype(r);
          pars.getBaseParameter().add(param);
        }

        return of.createRelatedTo(rt);

      case REPEAT:
        /* ------------------- Repeat Alarm -------------------- */
        Repeat rept = (Repeat) prop;
        RepeatPropType rep = new RepeatPropType();
        rep.setInteger(BigInteger.valueOf(rept.getCount()));

        return of.createRepeat(rep);

      case REQUEST_STATUS:
        /* ------------------- RequestStatus -------------------- */

        // XXX Later
        return null;

      case RESOURCES:
        /* ------------------- Resources -------------------- */

        ResourcesPropType r = new ResourcesPropType();

        List<String> rl = r.getText();
        ResourceList rlist = ((Resources) prop).getResources();

        Iterator rlit = rlist.iterator();
        while (rlit.hasNext()) {
          rl.add((String) rlit.next());
        }

        return of.createResources(r);

      case RRULE:
        /* ------------------- RRule ------------------- */

        RrulePropType rrp = new RrulePropType();
        rrp.setRecur(doRecur(((RRule) prop).getRecur()));

        return of.createRrule(rrp);

      case SEQUENCE:
        /* ------------------- Sequence -------------------- */

        SequencePropType s = new SequencePropType();
        s.setInteger(BigInteger.valueOf(((Sequence) prop).getSequenceNo()));

        return of.createSequence(s);

      case STATUS:
        /* ------------------- Status -------------------- */

        StatusPropType st = new StatusPropType();

        st.setText(prop.getValue());
        return of.createStatus(st);

      case SUMMARY:
        /* ------------------- Summary -------------------- */

        SummaryPropType sum = new SummaryPropType();
        sum.setText(prop.getValue());
        return of.createSummary(sum);

      case TRIGGER:
        /* ------------------- Trigger - alarm -------------------- */
        TriggerPropType trig = new TriggerPropType();

        String valType = paramVal(prop, Parameter.VALUE);

        if ((valType == null) || (valType.equalsIgnoreCase(Value.DURATION.getValue()))) {
          trig.setDuration(prop.getValue());
          String rel = paramVal(prop, Parameter.RELATED);
          if (rel != null) {
            ArrayOfParameters pars = getAop(trig);

            RelatedParamType rpar = new RelatedParamType();
            rpar.setText(IcalDefs.alarmTriggerRelatedEnd);
            JAXBElement<RelatedParamType> param = of.createRelated(rpar);
            pars.getBaseParameter().add(param);
          }
        } else if (valType.equalsIgnoreCase(Value.DATE_TIME.getValue())) {
          // t.setDateTime(val.getTrigger());
          trig.setDateTime(XcalUtil.getXMlUTCCal(prop.getValue()));
        }

        return of.createTrigger(trig);

      case TRANSP:
        /* ------------------- Transp -------------------- */

        TranspPropType t = new TranspPropType();
        t.setText(prop.getValue());
        return of.createTransp(t);

      case TZID:
      case TZNAME:
      case TZOFFSETFROM:
      case TZOFFSETTO:
      case TZURL:
        return null;

      case UID:
        /* ------------------- Uid -------------------- */

        final UidPropType uid = new UidPropType();
        uid.setText(prop.getValue());
        return of.createUid(uid);

      case URL:
        /* ------------------- Url -------------------- */

        final UrlPropType u = new UrlPropType();

        u.setUri(prop.getValue());
        return of.createUrl(u);

      case VERSION:
        /* ------------------- Version - vcal only -------------------- */

        final VersionPropType vers = new VersionPropType();
        vers.setText(prop.getValue());
        return of.createVersion(vers);

      case XBEDEWORK_COST:
        /* ------------------- Cost -------------------- */

        final XBedeworkCostPropType cst = new XBedeworkCostPropType();

        cst.setText(prop.getValue());
        return of.createXBedeworkCost(cst);

      case X_BEDEWORK_CATEGORIES:
        /* ------------------- Categories -------------------- */

        final XBwCategoriesPropType xpcat = new XBwCategoriesPropType();

        xpcat.getText().add(prop.getValue());
        return of.createXBedeworkCategories(xpcat);

      case X_BEDEWORK_CONTACT:
        /* ------------------- Categories -------------------- */

        final XBwContactPropType xpcon = new XBwContactPropType();

        xpcon.setText(prop.getValue());
        return of.createXBedeworkContact(xpcon);

      case X_BEDEWORK_LOCATION:
        /* ------------------- Categories -------------------- */

        final XBwLocationPropType xploc = new XBwLocationPropType();

        xploc.setText(prop.getValue());
        return of.createXBedeworkLocation(xploc);

      default:
        if (prop instanceof XProperty) {
          /* ------------------------- x-property --------------------------- */

          /*
          final PropertyInfoIndex xpii =
                  PropertyInfoIndex.fromName(prop.getName());

          if (xpii == null) {
            return null;
          }

          return null;*/

          if (!wrapXprops) {
            return null;
          }

          final XBedeworkWrapperPropType wrapper = new XBedeworkWrapperPropType();

          processParameters(prop.getParameters(), wrapper);

          return of.createXBedeworkWrapper(wrapper);
        }
    } // switch (pii)

    return null;
  }
예제 #4
0
  /**
   * @param val
   * @return VFreeBusy
   * @throws CalFacadeException
   */
  public static VFreeBusy toVFreeBusy(final BwEvent val) throws CalFacadeException {
    try {
      VFreeBusy vfb =
          new VFreeBusy(
              IcalUtil.makeDateTime(val.getDtstart()), IcalUtil.makeDateTime(val.getDtend()));

      PropertyList pl = vfb.getProperties();
      Property prop;

      /* ------------------- Attendees -------------------- */
      if (val.getNumAttendees() > 0) {
        for (BwAttendee att : val.getAttendees()) {
          pl.add(setAttendee(att));
        }
      }

      /* ------------------- Comments -------------------- */

      if (val.getNumComments() > 0) {
        for (BwString str : val.getComments()) {
          // LANG
          pl.add(new Comment(str.getValue()));
        }
      }

      /* ------------------- Dtstamp -------------------- */

      if (val.getDtstamp() != null) {
        DtStamp dts = (DtStamp) pl.getProperty(Property.DTSTAMP);

        if (dts == null) {
          prop = new DtStamp(new DateTime(val.getDtstamp()));
          //      if (pars.includeDateTimeProperty) {
          //      prop.getParameters().add(Value.DATE_TIME);
          //      }
          pl.add(prop);
        } else {
          dts.setDateTime(new DateTime(val.getDtstamp()));
        }
      }

      /* ------------------- freebusy -------------------- */

      Collection<BwFreeBusyComponent> times = val.getFreeBusyPeriods();

      if (times != null) {
        for (BwFreeBusyComponent fbc : times) {
          FreeBusy fb = new FreeBusy();

          int type = fbc.getType();
          if (type == BwFreeBusyComponent.typeBusy) {
            addParameter(fb, FbType.BUSY);
          } else if (type == BwFreeBusyComponent.typeFree) {
            addParameter(fb, FbType.FREE);
          } else if (type == BwFreeBusyComponent.typeBusyUnavailable) {
            addParameter(fb, FbType.BUSY_UNAVAILABLE);
          } else if (type == BwFreeBusyComponent.typeBusyTentative) {
            addParameter(fb, FbType.BUSY_TENTATIVE);
          } else {
            throw new CalFacadeException("Bad free-busy type " + type);
          }

          PeriodList pdl = fb.getPeriods();

          for (Period p : fbc.getPeriods()) {
            // XXX inverse.ca plugin cannot handle durations.
            Period np = new Period(p.getStart(), p.getEnd());
            pdl.add(np);
          }

          pl.add(fb);
        }
      }

      /* ------------------- Organizer -------------------- */

      BwOrganizer org = val.getOrganizer();
      if (org != null) {
        pl.add(setOrganizer(org));
      }

      /* ------------------- Uid -------------------- */

      if (val.getUid() != null) {
        pl.add(new Uid(val.getUid()));
      }

      return vfb;
    } catch (CalFacadeException cfe) {
      throw cfe;
    } catch (Throwable t) {
      throw new CalFacadeException(t);
    }
  }