use of net.fortuna.ical4j.model.Date 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.Date 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;
}
use of net.fortuna.ical4j.model.Date in project android by nextcloud.
the class SaveCalendar method convertFromDb.
private VEvent convertFromDb(Cursor cur, Calendar cal, DtStamp timestamp) {
Log_OC.d(TAG, "cursor: " + DatabaseUtils.dumpCurrentRowToString(cur));
if (hasStringValue(cur, Events.ORIGINAL_ID)) {
// FIXME: Support these edited instances
Log_OC.w(TAG, "Ignoring edited instance of a recurring event");
return null;
}
PropertyList l = new PropertyList();
l.add(timestamp);
copyProperty(l, Property.UID, cur, Events.UID_2445);
String summary = copyProperty(l, Property.SUMMARY, cur, Events.TITLE);
String description = copyProperty(l, Property.DESCRIPTION, cur, Events.DESCRIPTION);
String organizer = getString(cur, Events.ORGANIZER);
if (!TextUtils.isEmpty(organizer)) {
// incorrectly left it in the organizer column.
if (!organizer.startsWith("mailto:")) {
organizer = "mailto:" + organizer;
}
try {
l.add(new Organizer(organizer));
} catch (URISyntaxException ignored) {
if (!mFailedOrganisers.contains(organizer)) {
Log_OC.e(TAG, "Failed to create mailTo for organizer " + organizer);
mFailedOrganisers.add(organizer);
}
}
}
copyProperty(l, Property.LOCATION, cur, Events.EVENT_LOCATION);
copyEnumProperty(l, Property.STATUS, cur, Events.STATUS, STATUS_ENUM);
boolean allDay = TextUtils.equals(getString(cur, Events.ALL_DAY), "1");
boolean isTransparent;
DtEnd dtEnd = null;
if (allDay) {
// All day event
isTransparent = true;
Date start = getDateTime(cur, Events.DTSTART, null, null);
Date end = getDateTime(cur, Events.DTEND, null, null);
l.add(new DtStart(new Date(start)));
if (end != null) {
dtEnd = new DtEnd(new Date(end));
} else {
dtEnd = new DtEnd(utcDateFromMs(start.getTime() + DateUtils.DAY_IN_MILLIS));
}
l.add(dtEnd);
} else {
// Regular or zero-time event. Start date must be a date-time
Date startDate = getDateTime(cur, Events.DTSTART, Events.EVENT_TIMEZONE, cal);
l.add(new DtStart(startDate));
// Use duration if we have one, otherwise end date
if (hasStringValue(cur, Events.DURATION)) {
isTransparent = getString(cur, Events.DURATION).equals("PT0S");
if (!isTransparent) {
copyProperty(l, Property.DURATION, cur, Events.DURATION);
}
} else {
String endTz = Events.EVENT_END_TIMEZONE;
if (endTz == null) {
endTz = Events.EVENT_TIMEZONE;
}
Date end = getDateTime(cur, Events.DTEND, endTz, cal);
dtEnd = new DtEnd(end);
isTransparent = startDate.getTime() == end.getTime();
if (!isTransparent) {
l.add(dtEnd);
}
}
}
copyEnumProperty(l, Property.CLASS, cur, Events.ACCESS_LEVEL, CLASS_ENUM);
int availability = getInt(cur, Events.AVAILABILITY);
if (availability > Events.AVAILABILITY_TENTATIVE) {
// Unknown/Invalid
availability = -1;
}
if (isTransparent) {
// not free, then mark it opaque.
if (availability >= 0 && availability != Events.AVAILABILITY_FREE) {
l.add(Transp.OPAQUE);
}
} else if (availability > Events.AVAILABILITY_BUSY) {
// This event is ordinarily busy but differs, so output a FREEBUSY
// period covering the time of the event
FreeBusy fb = new FreeBusy();
fb.getParameters().add(new FbType(AVAIL_ENUM.get(availability)));
DateTime start = new DateTime(((DtStart) l.getProperty(Property.DTSTART)).getDate());
if (dtEnd != null) {
fb.getPeriods().add(new Period(start, new DateTime(dtEnd.getDate())));
} else {
Duration d = (Duration) l.getProperty(Property.DURATION);
fb.getPeriods().add(new Period(start, d.getDuration()));
}
l.add(fb);
}
copyProperty(l, Property.RRULE, cur, Events.RRULE);
copyProperty(l, Property.RDATE, cur, Events.RDATE);
copyProperty(l, Property.EXRULE, cur, Events.EXRULE);
copyProperty(l, Property.EXDATE, cur, Events.EXDATE);
if (TextUtils.isEmpty(getString(cur, Events.CUSTOM_APP_PACKAGE))) {
// Only copy URL if there is no app i.e. we probably imported it.
copyProperty(l, Property.URL, cur, Events.CUSTOM_APP_URI);
}
VEvent e = new VEvent(l);
if (getInt(cur, Events.HAS_ALARM) == 1) {
// Add alarms
String s = summary == null ? (description == null ? "" : description) : summary;
Description desc = new Description(s);
ContentResolver resolver = activity.getContentResolver();
long eventId = getLong(cur, Events._ID);
Cursor alarmCur;
alarmCur = Reminders.query(resolver, eventId, mAllCols ? null : REMINDER_COLS);
while (alarmCur.moveToNext()) {
int mins = getInt(alarmCur, Reminders.MINUTES);
if (mins == -1) {
// FIXME: Get the real default
mins = 60;
}
// FIXME: We should support other types if possible
int method = getInt(alarmCur, Reminders.METHOD);
if (method == Reminders.METHOD_DEFAULT || method == Reminders.METHOD_ALERT) {
VAlarm alarm = new VAlarm(new Dur(0, 0, -mins, 0));
alarm.getProperties().add(Action.DISPLAY);
alarm.getProperties().add(desc);
e.getAlarms().add(alarm);
}
}
alarmCur.close();
}
return e;
}
use of net.fortuna.ical4j.model.Date in project bw-calendar-engine by Bedework.
the class BwDateTime method getNextDay.
/**
* For a date only object returns a date 1 day in advance of this date.
* Used when moving between displayed and internal values and also when
* breaking a collection of events up into days.
*
* @return BwDateTime tomorrow
* @throws CalFacadeException
*/
public BwDateTime getNextDay() throws CalFacadeException {
if (!getDateType()) {
throw new CalFacadeException("org.bedework.datetime.expect.dateonly");
}
try {
Date dt = new Date(getDtval());
synchronized (dateIncrementor) {
dateIncrementor.setTime(dt);
dateIncrementor.add(Calendar.DATE, 1);
dt = new Date(dateIncrementor.getTime());
}
return makeBwDateTime(dt);
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.model.Date in project bw-calendar-engine by Bedework.
the class BwDateTime method makeDateTime.
/**
* Make a new date time value based on the dtStart value + the duration.
*
* @param dtStart
* @param dateOnly
* @param dur
* @return BwDateTime
* @throws CalFacadeException
*/
public static BwDateTime makeDateTime(final DateProperty dtStart, final boolean dateOnly, final Dur dur) throws CalFacadeException {
DtEnd dtEnd;
java.util.Date endDt = dur.getTime(dtStart.getDate());
Parameter tzid = getIcalParameter(dtStart, "TZID");
if (dateOnly) {
// dtEnd = new DtEnd(new Date(endDt));
ParameterList parl = new ParameterList();
parl.add(Value.DATE);
dtEnd = new DtEnd(parl, new Date(endDt));
// addIcalParameter(dtEnd, Value.DATE);
// if (tzid != null) {
// addIcalParameter(dtEnd, tzid);
// }
} else {
DateTime d = new DateTime(endDt);
if (tzid != null) {
DateTime sd = (DateTime) dtStart.getDate();
d.setTimeZone(sd.getTimeZone());
}
// dtEnd = new DtEnd(d, dtStart.isUtc());
dtEnd = new DtEnd(d);
if (tzid != null) {
addIcalParameter(dtEnd, tzid);
} else if (dtStart.isUtc()) {
dtEnd.setUtc(true);
}
}
return makeBwDateTime(dtEnd);
}
Aggregations