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;
}
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;
}
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();
}
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;
}
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));
}
}
Aggregations