Search in sources :

Example 21 with DateTime

use of net.fortuna.ical4j.model.DateTime in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getRrm.

private RecurringRetrievalMode getRrm(final RetrievalMode rm) throws WebdavException {
    if (rm == null) {
        return RecurringRetrievalMode.overrides;
    }
    try {
        if (rm.getExpand() != null) {
            /* expand with time range */
            ExpandType ex = rm.getExpand();
            DateTime s = new DateTime(XcalUtil.getIcalFormatDateTime(ex.getStart()));
            DateTime e = new DateTime(XcalUtil.getIcalFormatDateTime(ex.getEnd()));
            return new RecurringRetrievalMode(Rmode.expanded, getBwDt(s), getBwDt(e));
        }
        if (rm.getLimitRecurrenceSet() != null) {
            /* Only return master event and overrides in range */
            LimitRecurrenceSetType l = rm.getLimitRecurrenceSet();
            DateTime s = new DateTime(XcalUtil.getIcalFormatDateTime(l.getStart()));
            DateTime e = new DateTime(XcalUtil.getIcalFormatDateTime(l.getEnd()));
            return new RecurringRetrievalMode(Rmode.overrides, getBwDt(s), getBwDt(e));
        }
    } catch (Throwable t) {
        throw new WebdavBadRequest(CaldavTags.validFilter, "Invalid time-range");
    }
    /* Return master + overrides */
    return RecurringRetrievalMode.overrides;
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) RecurringRetrievalMode(org.bedework.calfacade.RecurringRetrievalMode) LimitRecurrenceSetType(ietf.params.xml.ns.caldav.LimitRecurrenceSetType) ExpandType(ietf.params.xml.ns.caldav.ExpandType) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 22 with DateTime

use of net.fortuna.ical4j.model.DateTime in project bw-calendar-engine by Bedework.

the class InReply method updateOrganizerCopy.

private boolean updateOrganizerCopy(final EventInfo colEi, final EventInfo inBoxEi, final String attUri, final ScheduleResult sr) throws CalFacadeException {
    final BwEvent inBoxEv = inBoxEi.getEvent();
    final BwEvent calEv = colEi.getEvent();
    final ChangeTable chg = calEv.getChangeset(getPrincipalHref());
    /* Only set true if the inbox copy needs to stay as notification.
     * Do not set true for status updates
     */
    boolean changed = false;
    if (debug) {
        trace("Update for attendee " + attUri);
    }
    if (inBoxEv.getScheduleMethod() != ScheduleMethods.methodTypeReply) {
        sr.errorCode = CalFacadeException.schedulingBadMethod;
        return false;
    }
    /* If the incoming sequence is less than that in the organizers event
     * then ignore the incoming reply?
     */
    /* Update the participation status from the incoming attendee */
    BwAttendee calAtt;
    final ChangeTableEntry cte = chg.getEntry(PropertyIndex.PropertyInfoIndex.ATTENDEE);
    if (!inBoxEv.getSuppressed()) {
        calAtt = calEv.findAttendee(attUri);
        if (calAtt == null) {
            if (debug) {
                trace("Not an attendee of " + calEv);
            }
            sr.errorCode = CalFacadeException.schedulingUnknownAttendee;
            sr.extraInfo = attUri;
            return false;
        }
        // For a recurring instance we replace or we update all recurring instances.
        final boolean recurringInstance = (calEv instanceof BwEventProxy);
        final BwAttendee att = inBoxEv.findAttendee(attUri);
        if (calAtt.changedBy(att)) {
            changed = true;
            if (recurringInstance) {
                calEv.removeAttendee(att);
                calAtt = (BwAttendee) att.clone();
            } else {
                att.copyTo(calAtt);
            }
            cte.addChangedValue(calAtt);
        }
        calAtt.setScheduleStatus(getRstat(inBoxEv));
        if (recurringInstance) {
            calEv.addAttendee(calAtt);
        }
        // XXX Ensure no name change
        if (calEv instanceof BwEventProxy) {
            final BwEventProxy pr = (BwEventProxy) calEv;
            final BwEventAnnotation ann = pr.getRef();
            ann.setName(null);
        }
    }
    /* The above changed the master - now we need to update or add any overrides
     */
    if (calEv.getRecurring() && (inBoxEi.getOverrides() != null)) {
        for (final EventInfo oei : inBoxEi.getOverrides()) {
            final BwEvent oev = oei.getEvent();
            final EventInfo cei = colEi.findOverride(oev.getRecurrenceId());
            /*
        if (cei == null) {
          // Organizer must have deleted the override.
          if (debug) {
            trace("Skipping missing override " + oev.getRecurrenceId());
          }
          continue;
        }*/
            final BwEvent ocalEv = cei.getEvent();
            if (((BwEventProxy) ocalEv).getRef().unsaved()) {
                // New Override
                try {
                    final String rid = oev.getRecurrenceId();
                    Date dt = new DateTime(rid);
                    if (calEv.getDtstart().getDateType()) {
                        // RECUR - fix all day recurrences sometime
                        if (rid.length() > 8) {
                            // Try to fix up bad all day recurrence ids. - assume a local timezone
                            ((DateTime) dt).setTimeZone(null);
                            dt = new Date(dt.toString().substring(0, 8));
                        }
                    }
                    final DtStart st = new DtStart(dt);
                    final String tzid = calEv.getDtstart().getTzid();
                    if (tzid != null) {
                        final TimeZone tz = Timezones.getTz(tzid);
                        st.setTimeZone(tz);
                    }
                    ocalEv.setDtstart(BwDateTime.makeBwDateTime(st));
                    ocalEv.setDuration(calEv.getDuration());
                    ocalEv.setDtend(ocalEv.getDtstart().addDur(new Dur(calEv.getDuration())));
                } catch (final CalFacadeException cfe) {
                    throw cfe;
                } catch (final Throwable t) {
                    throw new CalFacadeException(t);
                }
            }
            final BwAttendee ovatt = oev.findAttendee(attUri);
            calAtt = ocalEv.findAttendee(attUri);
            if (calAtt == null) {
                // Organizer must have removed the attendee.
                if (debug) {
                    trace("Skipping override " + attUri + " is not attending");
                }
                continue;
            }
            if (calAtt.changedBy(ovatt)) {
                changed = true;
                ocalEv.removeAttendee(ovatt);
                calAtt = (BwAttendee) ovatt.clone();
                calAtt.setScheduleStatus(getRstat(oev));
                ocalEv.addAttendee(calAtt);
                cte.addChangedValue(calAtt);
            }
        }
    }
    final boolean noinvites = !changed;
    colEi.setReplyUpdate(true);
    /* Update the organizer copy. This will broadcast the changes tp all
     * attendees
     */
    getSvc().getEventsHandler().update(colEi, noinvites, attUri);
    return changed;
}
Also used : Dur(net.fortuna.ical4j.model.Dur) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) TimeZone(net.fortuna.ical4j.model.TimeZone) DtStart(net.fortuna.ical4j.model.property.DtStart) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) ChangeTable(org.bedework.calfacade.util.ChangeTable) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 23 with DateTime

use of net.fortuna.ical4j.model.DateTime in project OpenOLAT by OpenOLAT.

the class CalendarImportTest method testImportRecurringCal.

@Test
public void testImportRecurringCal() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("RecurringEvent.ics");
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(in);
    assertNotNull(calendar);
    VEvent rootEvent = null;
    VEvent exceptionEvent = null;
    for (Iterator<?> iter = calendar.getComponents().iterator(); iter.hasNext(); ) {
        Object comp = iter.next();
        if (comp instanceof VEvent) {
            VEvent vevent = (VEvent) comp;
            if (vevent.getRecurrenceId() == null) {
                rootEvent = vevent;
            } else {
                exceptionEvent = vevent;
            }
        }
    }
    assertNotNull(rootEvent);
    assertNotNull(exceptionEvent);
    java.util.Date startDate = CalendarUtils.getDate(2016, java.util.Calendar.OCTOBER, 10);
    DateTime start = new DateTime(startDate);
    java.util.Date endDate = CalendarUtils.getDate(2016, java.util.Calendar.NOVEMBER, 10);
    DateTime end = new DateTime(endDate);
    Period period = new Period(start, end);
    PeriodList pList = rootEvent.calculateRecurrenceSet(period);
    for (Object obj : pList) {
        Period p = (Period) obj;
        System.out.println("Period: " + p.getStart());
    }
    RecurrenceId recurrenceId = exceptionEvent.getRecurrenceId();
    Date recurrenceDate = recurrenceId.getDate();
    System.out.println("Recurrence: " + recurrenceDate);
    exceptionEvent.getSequence();
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) InputStream(java.io.InputStream) Date(java.util.Date) Calendar(net.fortuna.ical4j.model.Calendar) Period(net.fortuna.ical4j.model.Period) PeriodList(net.fortuna.ical4j.model.PeriodList) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) Test(org.junit.Test)

Example 24 with DateTime

use of net.fortuna.ical4j.model.DateTime in project ofbiz-framework by apache.

the class ICalConverter method createAlarm.

protected static VAlarm createAlarm(GenericValue workEffortEventReminder) {
    VAlarm alarm = null;
    Timestamp reminderStamp = workEffortEventReminder.getTimestamp("reminderDateTime");
    if (reminderStamp != null) {
        alarm = new VAlarm(new DateTime(reminderStamp));
    } else {
        TimeDuration duration = TimeDuration.fromNumber(workEffortEventReminder.getLong("reminderOffset"));
        alarm = new VAlarm(new Dur(duration.days(), duration.hours(), duration.minutes(), duration.seconds()));
    }
    return alarm;
}
Also used : Dur(net.fortuna.ical4j.model.Dur) TimeDuration(org.apache.ofbiz.base.util.TimeDuration) VAlarm(net.fortuna.ical4j.model.component.VAlarm) Timestamp(java.sql.Timestamp) DateTime(net.fortuna.ical4j.model.DateTime)

Example 25 with DateTime

use of net.fortuna.ical4j.model.DateTime in project opencast by opencast.

the class UtilTests method calculateDSTChange.

@Test
public void calculateDSTChange() throws ParseException {
    Calendar start;
    Calendar end;
    long durationMillis;
    String days;
    List<Period> periods;
    // CET
    TimeZone.setDefault(cet);
    start = Calendar.getInstance(cet);
    start.set(2016, 2, 24, 0, 5);
    end = Calendar.getInstance(cet);
    end.set(2016, 2, 29, start.get(Calendar.HOUR_OF_DAY), 10);
    durationMillis = (end.get(Calendar.MINUTE) - start.get(Calendar.MINUTE)) * 60 * 1000;
    days = "MO,TH,FR,SA,SU";
    periods = generatePeriods(cet, start, end, days, durationMillis);
    for (Period p : periods) {
        logger.info(p.toString());
    }
    assertEquals(5, periods.size());
    TimeZone.setDefault(cet);
    for (Period d : periods) {
        DateTime dEnd = d.getEnd();
        Date date = new Date(dEnd.getTime());
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        assertEquals(0, instance.get(Calendar.HOUR_OF_DAY));
    }
}
Also used : Calendar(java.util.Calendar) Period(net.fortuna.ical4j.model.Period) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DateTime (net.fortuna.ical4j.model.DateTime)70 Period (net.fortuna.ical4j.model.Period)20 VEvent (net.fortuna.ical4j.model.component.VEvent)18 BwDateTime (org.bedework.calfacade.BwDateTime)15 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)15 Date (java.util.Date)13 TimeZone (net.fortuna.ical4j.model.TimeZone)13 ParseException (java.text.ParseException)12 DtStart (net.fortuna.ical4j.model.property.DtStart)11 Date (net.fortuna.ical4j.model.Date)10 Dur (net.fortuna.ical4j.model.Dur)10 PeriodList (net.fortuna.ical4j.model.PeriodList)10 PropertyList (net.fortuna.ical4j.model.PropertyList)9 DtStamp (net.fortuna.ical4j.model.property.DtStamp)9 LastModified (net.fortuna.ical4j.model.property.LastModified)9 Uid (net.fortuna.ical4j.model.property.Uid)9 Calendar (net.fortuna.ical4j.model.Calendar)8 Recur (net.fortuna.ical4j.model.Recur)8 ExDate (net.fortuna.ical4j.model.property.ExDate)8 GregorianCalendar (java.util.GregorianCalendar)7