Search in sources :

Example 11 with RRule

use of net.fortuna.ical4j.model.property.RRule in project openolat by klemens.

the class ICalFileCalendarManager method getVEvent.

private VEvent getVEvent(KalendarEvent kEvent) {
    VEvent vEvent = new VEvent();
    if (!kEvent.isAllDayEvent()) {
        // regular VEvent
        DateTime dtBegin = new DateTime(kEvent.getBegin());
        if (tz != null) {
            dtBegin.setTimeZone(tz);
        }
        Date kEventEnd = kEvent.getEnd();
        if (kEventEnd == null) {
            vEvent = new VEvent(dtBegin, kEvent.getSubject());
        } else {
            DateTime dtEnd = new DateTime(kEventEnd);
            if (tz != null) {
                dtEnd.setTimeZone(tz);
            }
            vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
        }
    } else {
        // AllDay VEvent
        net.fortuna.ical4j.model.Date dtBegin = CalendarUtils.createDate(kEvent.getBegin());
        // adjust end date: ICal end dates for all day events are on the next day
        Date adjustedEndDate = new Date(kEvent.getEnd().getTime() + (1000 * 60 * 60 * 24));
        net.fortuna.ical4j.model.Date dtEnd = CalendarUtils.createDate(adjustedEndDate);
        vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
    }
    if (kEvent.getCreated() > 0) {
        Created created = new Created(new DateTime(kEvent.getCreated()));
        vEvent.getProperties().add(created);
    }
    if ((kEvent.getCreatedBy() != null) && !kEvent.getCreatedBy().trim().isEmpty()) {
        Contact contact = new Contact();
        contact.setValue(kEvent.getCreatedBy());
        vEvent.getProperties().add(contact);
    }
    if (kEvent.getLastModified() > 0) {
        LastModified lastMod = new LastModified(new DateTime(kEvent.getLastModified()));
        vEvent.getProperties().add(lastMod);
    }
    // Uid
    PropertyList vEventProperties = vEvent.getProperties();
    vEventProperties.add(new Uid(kEvent.getID()));
    // clazz
    switch(kEvent.getClassification()) {
        case KalendarEvent.CLASS_PRIVATE:
            vEventProperties.add(ICAL_CLASS_PRIVATE);
            break;
        case KalendarEvent.CLASS_PUBLIC:
            vEventProperties.add(ICAL_CLASS_PUBLIC);
            break;
        case KalendarEvent.CLASS_X_FREEBUSY:
            vEventProperties.add(ICAL_CLASS_X_FREEBUSY);
            break;
        default:
            vEventProperties.add(ICAL_CLASS_PRIVATE);
            break;
    }
    // location
    if (kEvent.getLocation() != null) {
        vEventProperties.add(new Location(kEvent.getLocation()));
    }
    if (kEvent.getDescription() != null) {
        vEventProperties.add(new Description(kEvent.getDescription()));
    }
    // event links
    Url urlOnce = null;
    List<KalendarEventLink> kalendarEventLinks = kEvent.getKalendarEventLinks();
    if ((kalendarEventLinks != null) && !kalendarEventLinks.isEmpty()) {
        for (Iterator<KalendarEventLink> iter = kalendarEventLinks.iterator(); iter.hasNext(); ) {
            KalendarEventLink link = iter.next();
            StringBuilder linkEncoded = new StringBuilder(200);
            linkEncoded.append(link.getProvider());
            linkEncoded.append("§");
            linkEncoded.append(link.getId());
            linkEncoded.append("§");
            linkEncoded.append(link.getDisplayName());
            linkEncoded.append("§");
            linkEncoded.append(link.getURI());
            linkEncoded.append("§");
            linkEncoded.append(link.getIconCssClass());
            XProperty linkProperty = new XProperty(ICAL_X_OLAT_LINK, linkEncoded.toString());
            vEventProperties.add(linkProperty);
            if (urlOnce == null) {
                try {
                    Url url = new Url();
                    url.setValue(link.getURI());
                    urlOnce = url;
                } catch (URISyntaxException e) {
                    log.error("Invalid URL:" + link.getURI());
                }
            }
        }
    }
    if (urlOnce != null) {
        vEventProperties.add(urlOnce);
    }
    if (kEvent.getComment() != null) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_COMMENT, kEvent.getComment()));
    }
    if (kEvent.getNumParticipants() != null) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_NUMPARTICIPANTS, Integer.toString(kEvent.getNumParticipants())));
    }
    if (kEvent.getParticipants() != null) {
        StringBuilder strBuf = new StringBuilder();
        String[] participants = kEvent.getParticipants();
        for (String participant : participants) {
            strBuf.append(participant);
            strBuf.append("§");
        }
        vEventProperties.add(new XProperty(ICAL_X_OLAT_PARTICIPANTS, strBuf.toString()));
    }
    if (kEvent.getSourceNodeId() != null) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_SOURCENODEID, kEvent.getSourceNodeId()));
    }
    if (kEvent.getManagedFlags() != null) {
        String val = CalendarManagedFlag.toString(kEvent.getManagedFlags());
        vEventProperties.add(new XProperty(ICAL_X_OLAT_MANAGED, val));
    }
    if (StringHelper.containsNonWhitespace(kEvent.getExternalId())) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_ID, kEvent.getExternalId()));
    }
    if (StringHelper.containsNonWhitespace(kEvent.getExternalSource())) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_SOURCE, kEvent.getExternalSource()));
    }
    String recurenceId = kEvent.getRecurrenceID();
    if (StringHelper.containsNonWhitespace(recurenceId)) {
        try {
            RecurrenceId recurId = new RecurrenceId(tz);
            // VALUE=DATE recurrence id need to be specially saved
            if (recurenceId.length() < 9) {
                recurId = new RecurrenceId(tz);
                recurId.setDate(CalendarUtils.createDate(new net.fortuna.ical4j.model.Date(recurenceId)));
            } else {
                recurId = new RecurrenceId(recurenceId, tz);
            }
            vEventProperties.add(recurId);
        } catch (ParseException e) {
            log.error("cannot create recurrence ID: " + recurenceId, e);
        }
    }
    // recurrence
    String recurrence = kEvent.getRecurrenceRule();
    if (recurrence != null && !recurrence.equals("")) {
        try {
            Recur recur = new Recur(recurrence);
            RRule rrule = new RRule(recur);
            vEventProperties.add(rrule);
        } catch (ParseException e) {
            log.error("cannot create recurrence rule: " + recurrence.toString(), e);
        }
    }
    // recurrence exclusions
    String recurrenceExc = kEvent.getRecurrenceExc();
    if (recurrenceExc != null && !recurrenceExc.equals("")) {
        ExDate exdate = new ExDate();
        try {
            exdate.setValue(recurrenceExc);
            vEventProperties.add(exdate);
        } catch (ParseException e) {
            log.error("", e);
        }
    }
    return vEvent;
}
Also used : Description(net.fortuna.ical4j.model.property.Description) RRule(net.fortuna.ical4j.model.property.RRule) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) URISyntaxException(java.net.URISyntaxException) DateTime(net.fortuna.ical4j.model.DateTime) Url(net.fortuna.ical4j.model.property.Url) Created(net.fortuna.ical4j.model.property.Created) LastModified(net.fortuna.ical4j.model.property.LastModified) ExDate(net.fortuna.ical4j.model.property.ExDate) VEvent(net.fortuna.ical4j.model.component.VEvent) XProperty(net.fortuna.ical4j.model.property.XProperty) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) Contact(net.fortuna.ical4j.model.property.Contact) Uid(net.fortuna.ical4j.model.property.Uid) PropertyList(net.fortuna.ical4j.model.PropertyList) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) ParseException(java.text.ParseException) Location(net.fortuna.ical4j.model.property.Location) Recur(net.fortuna.ical4j.model.Recur)

Example 12 with RRule

use of net.fortuna.ical4j.model.property.RRule in project openolat by klemens.

the class ICalFileCalendarManager method getRecurrenceRule.

/**
 * Build iCalendar-compliant recurrence rule
 * @param recurrence
 * @param recurrenceEnd
 * @return rrule
 */
@Override
public String getRecurrenceRule(String recurrence, Date recurrenceEnd) {
    if (recurrence != null) {
        // recurrence available
        // create recurrence rule
        StringBuilder sb = new StringBuilder();
        sb.append("FREQ=");
        if (recurrence.equals(KalendarEvent.WORKDAILY)) {
            // build rule for monday to friday
            sb.append(KalendarEvent.DAILY).append(";").append("BYDAY=MO,TU,WE,TH,FR");
        } else if (recurrence.equals(KalendarEvent.BIWEEKLY)) {
            // build rule for biweekly
            sb.append(KalendarEvent.WEEKLY).append(";").append("INTERVAL=2");
        } else {
            // normal supported recurrence
            sb.append(recurrence);
        }
        if (recurrenceEnd != null) {
            java.util.Calendar recurEndCal = java.util.Calendar.getInstance();
            recurEndCal.setTimeZone(tz);
            recurEndCal.setTime(recurrenceEnd);
            recurEndCal = CalendarUtils.getEndOfDay(recurEndCal);
            long recTime = recurEndCal.getTimeInMillis() - tz.getOffset(recurEndCal.getTimeInMillis());
            DateTime recurEndDT = new DateTime(recTime);
            if (tz != null) {
                recurEndDT.setTimeZone(tz);
            }
            sb.append(";").append(KalendarEvent.UNTIL).append("=").append(recurEndDT.toString());
        }
        try {
            Recur recur = new Recur(sb.toString());
            RRule rrule = new RRule(recur);
            return rrule.getValue();
        } catch (ParseException e) {
            log.error("cannot create recurrence rule: " + recurrence.toString(), e);
        }
    }
    return null;
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) ParseException(java.text.ParseException) DateTime(net.fortuna.ical4j.model.DateTime) Recur(net.fortuna.ical4j.model.Recur)

Example 13 with RRule

use of net.fortuna.ical4j.model.property.RRule in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method removeFutureOfEvent.

@Override
public boolean removeFutureOfEvent(Kalendar cal, KalendarRecurEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            boolean successfullyPersist = false;
            try {
                String uid = kalendarEvent.getID();
                Date occurenceDate = kalendarEvent.getOccurenceDate();
                Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
                KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
                String rRule = rootEvent.getRecurrenceRule();
                Recur recur = new Recur(rRule);
                recur.setUntil(CalendarUtils.createDate(occurenceDate));
                RRule rrule = new RRule(recur);
                rootEvent.setRecurrenceRule(rrule.getValue());
                for (KalendarEvent kEvent : loadedCal.getEvents()) {
                    if (uid.equals(kEvent.getID()) && StringHelper.containsNonWhitespace(kEvent.getRecurrenceID()) && occurenceDate.before(kEvent.getBegin())) {
                        loadedCal.removeEvent(kEvent);
                    }
                }
                successfullyPersist = persistCalendar(loadedCal);
            } catch (ParseException e) {
                log.error("", e);
            }
            return new Boolean(successfullyPersist);
        }
    });
    // inform all controller about calendar change for reload
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
    return removeSuccessful.booleanValue();
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ParseException(java.text.ParseException) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent) Recur(net.fortuna.ical4j.model.Recur)

Example 14 with RRule

use of net.fortuna.ical4j.model.property.RRule in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method getVEvent.

private VEvent getVEvent(KalendarEvent kEvent) {
    VEvent vEvent = new VEvent();
    if (!kEvent.isAllDayEvent()) {
        // regular VEvent
        DateTime dtBegin = new DateTime(kEvent.getBegin());
        if (tz != null) {
            dtBegin.setTimeZone(tz);
        }
        Date kEventEnd = kEvent.getEnd();
        if (kEventEnd == null) {
            vEvent = new VEvent(dtBegin, kEvent.getSubject());
        } else {
            DateTime dtEnd = new DateTime(kEventEnd);
            if (tz != null) {
                dtEnd.setTimeZone(tz);
            }
            vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
        }
    } else {
        // AllDay VEvent
        net.fortuna.ical4j.model.Date dtBegin = CalendarUtils.createDate(kEvent.getBegin());
        // adjust end date: ICal end dates for all day events are on the next day
        Date adjustedEndDate = new Date(kEvent.getEnd().getTime() + (1000 * 60 * 60 * 24));
        net.fortuna.ical4j.model.Date dtEnd = CalendarUtils.createDate(adjustedEndDate);
        vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
    }
    if (kEvent.getCreated() > 0) {
        Created created = new Created(new DateTime(kEvent.getCreated()));
        vEvent.getProperties().add(created);
    }
    if ((kEvent.getCreatedBy() != null) && !kEvent.getCreatedBy().trim().isEmpty()) {
        Contact contact = new Contact();
        contact.setValue(kEvent.getCreatedBy());
        vEvent.getProperties().add(contact);
    }
    if (kEvent.getLastModified() > 0) {
        LastModified lastMod = new LastModified(new DateTime(kEvent.getLastModified()));
        vEvent.getProperties().add(lastMod);
    }
    // Uid
    PropertyList vEventProperties = vEvent.getProperties();
    vEventProperties.add(new Uid(kEvent.getID()));
    // clazz
    switch(kEvent.getClassification()) {
        case KalendarEvent.CLASS_PRIVATE:
            vEventProperties.add(ICAL_CLASS_PRIVATE);
            break;
        case KalendarEvent.CLASS_PUBLIC:
            vEventProperties.add(ICAL_CLASS_PUBLIC);
            break;
        case KalendarEvent.CLASS_X_FREEBUSY:
            vEventProperties.add(ICAL_CLASS_X_FREEBUSY);
            break;
        default:
            vEventProperties.add(ICAL_CLASS_PRIVATE);
            break;
    }
    // location
    if (kEvent.getLocation() != null) {
        vEventProperties.add(new Location(kEvent.getLocation()));
    }
    if (kEvent.getDescription() != null) {
        vEventProperties.add(new Description(kEvent.getDescription()));
    }
    // event links
    Url urlOnce = null;
    List<KalendarEventLink> kalendarEventLinks = kEvent.getKalendarEventLinks();
    if ((kalendarEventLinks != null) && !kalendarEventLinks.isEmpty()) {
        for (Iterator<KalendarEventLink> iter = kalendarEventLinks.iterator(); iter.hasNext(); ) {
            KalendarEventLink link = iter.next();
            StringBuilder linkEncoded = new StringBuilder(200);
            linkEncoded.append(link.getProvider());
            linkEncoded.append("§");
            linkEncoded.append(link.getId());
            linkEncoded.append("§");
            linkEncoded.append(link.getDisplayName());
            linkEncoded.append("§");
            linkEncoded.append(link.getURI());
            linkEncoded.append("§");
            linkEncoded.append(link.getIconCssClass());
            XProperty linkProperty = new XProperty(ICAL_X_OLAT_LINK, linkEncoded.toString());
            vEventProperties.add(linkProperty);
            if (urlOnce == null) {
                try {
                    Url url = new Url();
                    url.setValue(link.getURI());
                    urlOnce = url;
                } catch (URISyntaxException e) {
                    log.error("Invalid URL:" + link.getURI());
                }
            }
        }
    }
    if (urlOnce != null) {
        vEventProperties.add(urlOnce);
    }
    if (kEvent.getComment() != null) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_COMMENT, kEvent.getComment()));
    }
    if (kEvent.getNumParticipants() != null) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_NUMPARTICIPANTS, Integer.toString(kEvent.getNumParticipants())));
    }
    if (kEvent.getParticipants() != null) {
        StringBuilder strBuf = new StringBuilder();
        String[] participants = kEvent.getParticipants();
        for (String participant : participants) {
            strBuf.append(participant);
            strBuf.append("§");
        }
        vEventProperties.add(new XProperty(ICAL_X_OLAT_PARTICIPANTS, strBuf.toString()));
    }
    if (kEvent.getSourceNodeId() != null) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_SOURCENODEID, kEvent.getSourceNodeId()));
    }
    if (kEvent.getManagedFlags() != null) {
        String val = CalendarManagedFlag.toString(kEvent.getManagedFlags());
        vEventProperties.add(new XProperty(ICAL_X_OLAT_MANAGED, val));
    }
    if (StringHelper.containsNonWhitespace(kEvent.getExternalId())) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_ID, kEvent.getExternalId()));
    }
    if (StringHelper.containsNonWhitespace(kEvent.getExternalSource())) {
        vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_SOURCE, kEvent.getExternalSource()));
    }
    String recurenceId = kEvent.getRecurrenceID();
    if (StringHelper.containsNonWhitespace(recurenceId)) {
        try {
            RecurrenceId recurId = new RecurrenceId(tz);
            // VALUE=DATE recurrence id need to be specially saved
            if (recurenceId.length() < 9) {
                recurId = new RecurrenceId(tz);
                recurId.setDate(CalendarUtils.createDate(new net.fortuna.ical4j.model.Date(recurenceId)));
            } else {
                recurId = new RecurrenceId(recurenceId, tz);
            }
            vEventProperties.add(recurId);
        } catch (ParseException e) {
            log.error("cannot create recurrence ID: " + recurenceId, e);
        }
    }
    // recurrence
    String recurrence = kEvent.getRecurrenceRule();
    if (recurrence != null && !recurrence.equals("")) {
        try {
            Recur recur = new Recur(recurrence);
            RRule rrule = new RRule(recur);
            vEventProperties.add(rrule);
        } catch (ParseException e) {
            log.error("cannot create recurrence rule: " + recurrence.toString(), e);
        }
    }
    // recurrence exclusions
    String recurrenceExc = kEvent.getRecurrenceExc();
    if (recurrenceExc != null && !recurrenceExc.equals("")) {
        ExDate exdate = new ExDate();
        try {
            exdate.setValue(recurrenceExc);
            vEventProperties.add(exdate);
        } catch (ParseException e) {
            log.error("", e);
        }
    }
    return vEvent;
}
Also used : Description(net.fortuna.ical4j.model.property.Description) RRule(net.fortuna.ical4j.model.property.RRule) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) URISyntaxException(java.net.URISyntaxException) DateTime(net.fortuna.ical4j.model.DateTime) Url(net.fortuna.ical4j.model.property.Url) Created(net.fortuna.ical4j.model.property.Created) LastModified(net.fortuna.ical4j.model.property.LastModified) ExDate(net.fortuna.ical4j.model.property.ExDate) VEvent(net.fortuna.ical4j.model.component.VEvent) XProperty(net.fortuna.ical4j.model.property.XProperty) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) Contact(net.fortuna.ical4j.model.property.Contact) Uid(net.fortuna.ical4j.model.property.Uid) PropertyList(net.fortuna.ical4j.model.PropertyList) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) ParseException(java.text.ParseException) Location(net.fortuna.ical4j.model.property.Location) Recur(net.fortuna.ical4j.model.Recur)

Example 15 with RRule

use of net.fortuna.ical4j.model.property.RRule in project zm-mailbox by Zimbra.

the class RecurrenceDefinition method icalRecurrenceProperty.

/**
 * @param isAllDay
 * @param isFloating
 * @return The main recurrence property as ICAL - typically an RRULE but
 *         could theoretically be an X-MICROSOFT-RRULE
 * @throws ServiceException
 */
public Property icalRecurrenceProperty(boolean isAllDay, boolean isFloating) throws ServiceException {
    RRule theRule = null;
    if (this.calScale.isSolarCalendar() == false) {
        throw TNEFtoIcalendarServiceException.NON_SOLAR_CALENDAR();
    }
    // iCal4j Recur is a bit basic when it come to building things
    // up from components, for instance, there currently isn't a way
    // to set any BYDAY= value other than in the constructor from a String
    StringBuffer recurrenceRule = new StringBuffer("FREQ=");
    // According to RFC, only absolutely NEED WKST of have a
    // weekly recurrence with interval greater than 1 OR using
    // BYWEEKNO - however, does no harm to always include it.
    String weekStartDay = firstDayOfWeek.toString();
    boolean hasBYDAY = false;
    boolean isYearly = false;
    int interval = 1;
    switch(patternType) {
        case DAY:
            recurrenceRule.append(Recur.DAILY);
            interval = Long.valueOf(period).intValue() / 1440;
            break;
        case WEEK:
            recurrenceRule.append(Recur.WEEKLY);
            interval = Long.valueOf(period).intValue();
            hasBYDAY = true;
            break;
        case MONTH:
            interval = Long.valueOf(period).intValue();
            if ((interval % 12) == 0) {
                isYearly = true;
                recurrenceRule.append(Recur.YEARLY);
                interval = (interval / 12);
            } else {
                recurrenceRule.append(Recur.MONTHLY);
            }
            if (dayOfMonth != 0) {
                recurrenceRule.append(";BYMONTHDAY=");
                if (dayOfMonth == 31) {
                    recurrenceRule.append("-1");
                } else {
                    recurrenceRule.append(dayOfMonth);
                }
            }
            if (isYearly) {
                java.util.TimeZone javaTZ = null;
                if (tzDef != null) {
                    javaTZ = tzDef.getTimeZone();
                } else {
                    javaTZ = TimeZone.getTimeZone(TimeZones.UTC_ID);
                }
                Date bymonthDate = IcalUtil.localMinsSince1601toDate(firstDateTime, tzDef);
                Calendar bymonthCal = new GregorianCalendar(javaTZ);
                bymonthCal.setTimeInMillis(bymonthDate.getTime());
                String MONTH_ONLY_PATTERN = "MM";
                DateFormat monthOnlyFormat = new SimpleDateFormat(MONTH_ONLY_PATTERN);
                monthOnlyFormat.setCalendar(bymonthCal);
                recurrenceRule.append(";BYMONTH=");
                recurrenceRule.append(monthOnlyFormat.format(bymonthDate));
            }
            break;
        case MONTH_NTH:
            interval = Long.valueOf(period).intValue();
            if ((interval % 12) == 0) {
                isYearly = true;
                recurrenceRule.append(Recur.YEARLY);
                interval = (interval / 12);
            } else {
                recurrenceRule.append(Recur.MONTHLY);
            }
            hasBYDAY = true;
            recurrenceRule.append(";BYSETPOS=");
            if (weekDayOccurrenceNumber == 5) {
                recurrenceRule.append(-1);
            } else {
                recurrenceRule.append(weekDayOccurrenceNumber);
            }
            if (isYearly) {
                java.util.TimeZone javaTZ = null;
                if (tzDef != null) {
                    javaTZ = tzDef.getTimeZone();
                } else {
                    javaTZ = TimeZone.getTimeZone(TimeZones.UTC_ID);
                }
                Date bymonthDate = IcalUtil.localMinsSince1601toDate(firstDateTime, tzDef);
                Calendar bymonthCal = new GregorianCalendar(javaTZ);
                bymonthCal.setTimeInMillis(bymonthDate.getTime());
                String MONTH_ONLY_PATTERN = "MM";
                DateFormat monthOnlyFormat = new SimpleDateFormat(MONTH_ONLY_PATTERN);
                monthOnlyFormat.setCalendar(bymonthCal);
                recurrenceRule.append(";BYMONTH=");
                recurrenceRule.append(monthOnlyFormat.format(bymonthDate));
            }
            break;
        case MONTH_END:
        case HJ_MONTH:
        case HJ_MONTH_END:
        case HJ_MONTH_NTH:
            throw TNEFtoIcalendarServiceException.UNSUPPORTED_RECURRENCE_TYPE(patternType.name());
        default:
            throw TNEFtoIcalendarServiceException.UNSUPPORTED_RECURRENCE_TYPE(patternType.name());
    }
    if (recurrenceRule.length() > 5) /* length of "FREQ=" */
    {
        if (endType.equals(EndType.END_AFTER_N_OCCURRENCES)) {
            recurrenceRule.append(";COUNT=");
            recurrenceRule.append(occurrenceCount);
        } else if (endType.equals(EndType.END_BY_DATE)) {
            // MS-OXCICAL :
            // set to (EndDate + startTimeOffset), converted from the
            // time zone specified by PidLidTimeZoneStruct to the UTC time zone
            // From RFC 5545 :
            // The UNTIL rule part defines a DATE or DATE-TIME value that bounds
            // the recurrence rule in an inclusive manner.  If the value
            // specified by UNTIL is synchronized with the specified recurrence,
            // this DATE or DATE-TIME becomes the last instance of the
            // recurrence.  The value of the UNTIL rule part MUST have the same
            // value type as the "DTSTART" property.  Furthermore, if the
            // "DTSTART" property is specified as a date with local time, then
            // the UNTIL rule part MUST also be specified as a date with local
            // time [Gren - i.e. when DTSTART is a floating time].
            // If the "DTSTART" property is specified as a date with UTC
            // time or a date with local time and time zone reference, then the
            // UNTIL rule part MUST be specified as a date with UTC time.
            long minsSince1601 = this.endMinsSince1601 + this.startTimeOffset;
            DateTime untilDateTime = IcalUtil.localMinsSince1601toDate(minsSince1601, tzDef);
            recurrenceRule.append(";UNTIL=");
            java.util.TimeZone untilTZ = null;
            if (this.tzDef != null) {
                untilTZ = this.tzDef.getTimeZone();
            }
            if (isFloating) {
                // Use localtime.
                recurrenceRule.append(IcalUtil.iCalDateTimeValue(untilDateTime, untilTZ, isAllDay));
            } else {
                if (isAllDay) {
                    recurrenceRule.append(IcalUtil.iCalDateTimeValue(untilDateTime, untilTZ, isAllDay));
                } else {
                    // MUST be UTC time
                    recurrenceRule.append(IcalUtil.icalUtcTime(minsSince1601, tzDef));
                }
            }
        }
        if (hasBYDAY) {
            WeekDayList weekDayList = new WeekDayList();
            dayOfWeekMask = getDayOfWeekMask();
            for (DayOfWeek dow : dayOfWeekMask) {
                weekDayList.add(dow.iCal4JWeekDay());
            }
            if (!weekDayList.isEmpty()) {
                recurrenceRule.append(";BYDAY=");
                recurrenceRule.append(weekDayList);
            }
        }
        if (interval != 1) {
            recurrenceRule.append(";INTERVAL=");
            recurrenceRule.append(interval);
        }
        if (weekStartDay != null) {
            recurrenceRule.append(";WKST=");
            recurrenceRule.append(weekStartDay);
        }
        Recur recur;
        try {
            recur = new Recur(recurrenceRule.toString());
        } catch (ParseException ex) {
            throw TNEFtoIcalendarServiceException.RRULE_PARSING_PROBLEM(ex);
        }
        theRule = new RRule(recur);
    }
    return theRule;
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) WeekDayList(net.fortuna.ical4j.model.WeekDayList) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) TimeZone(net.fortuna.ical4j.model.TimeZone) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Recur(net.fortuna.ical4j.model.Recur)

Aggregations

RRule (net.fortuna.ical4j.model.property.RRule)23 ParseException (java.text.ParseException)14 Date (java.util.Date)11 Recur (net.fortuna.ical4j.model.Recur)9 DateTime (net.fortuna.ical4j.model.DateTime)8 PropertyList (net.fortuna.ical4j.model.PropertyList)7 ExDate (net.fortuna.ical4j.model.property.ExDate)6 VEvent (net.fortuna.ical4j.model.component.VEvent)5 MediaPackage (org.opencastproject.mediapackage.MediaPackage)5 TimeZone (java.util.TimeZone)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Period (net.fortuna.ical4j.model.Period)4 RecurrenceId (net.fortuna.ical4j.model.property.RecurrenceId)4 Kalendar (org.olat.commons.calendar.model.Kalendar)4 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)4 IOException (java.io.IOException)3 Calendar (java.util.Calendar)3 Path (javax.ws.rs.Path)3 Date (net.fortuna.ical4j.model.Date)3 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3