Search in sources :

Example 26 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class BwCalDAVEvent method generatePropertyValue.

@Override
public boolean generatePropertyValue(final QName tag, final XmlEmit xml) throws WebdavException {
    try {
        BwEvent ev = getEv();
        if (tag.equals(CaldavTags.scheduleTag)) {
            if (!ev.getOrganizerSchedulingObject() && !ev.getAttendeeSchedulingObject()) {
                return false;
            }
            xml.property(tag, ev.getStag());
            return true;
        }
        if (tag.equals(CaldavTags.originator)) {
            if (ev.getOriginator() != null) {
                xml.openTag(tag);
                xml.property(WebdavTags.href, ev.getOriginator());
                xml.closeTag(tag);
            }
            return true;
        }
        if (tag.equals(CaldavTags.recipient)) {
            Collection<String> r = ev.getRecipients();
            if ((r == null) || (r.isEmpty())) {
                return true;
            }
            xml.openTag(tag);
            for (String recip : r) {
                xml.property(WebdavTags.href, recip);
            }
            xml.closeTag(tag);
            return true;
        }
        if (tag.equals(AppleServerTags.scheduleChanges)) {
            List<BwXproperty> xps = ev.getXproperties(BwXproperty.bedeworkChanges);
            if (Util.isEmpty(xps)) {
                return true;
            }
            BwXproperty xp = xps.get(0);
            String[] vals = xp.getValue().split(";");
            xml.openTag(tag);
            xml.property(AppleServerTags.dtstamp, vals[0]);
            xml.openTag(AppleServerTags.action);
            QName actionTag;
            if ("CANCEL".equals(vals[1])) {
                actionTag = AppleServerTags.cancel;
            } else if ("CREATE".equals(vals[1])) {
                actionTag = AppleServerTags.create;
            } else if ("REPLY".equals(vals[1])) {
                actionTag = AppleServerTags.reply;
            } else {
                // "UPDATE"
                actionTag = AppleServerTags.update;
            }
            xml.openTag(actionTag);
            int i = 2;
            while (i < vals.length) {
                /* Next is master or rid */
                xml.openTag(AppleServerTags.recurrence);
                String val = vals[i];
                if ("MASTER".equals(val)) {
                    xml.emptyTag(AppleServerTags.master);
                    i++;
                }
                if (val.startsWith("RID=")) {
                    xml.openTagNoNewline(AppleServerTags.recurrenceid);
                    xml.value(val);
                    xml.closeTag(AppleServerTags.recurrenceid);
                    i++;
                }
                if ((i < vals.length) && "CHANGES".equals(vals[i])) {
                    i++;
                    xml.openTag(AppleServerTags.changes);
                    while (i < vals.length) {
                        val = vals[i];
                        if ("MASTER".equals(val) || "CHANGES".equals(val) || val.startsWith("RID=")) {
                            break;
                        }
                        xml.startTag(AppleServerTags.changedProperty);
                        xml.attribute("name", val);
                        xml.endEmptyTag();
                        i++;
                    }
                    xml.closeTag(AppleServerTags.changes);
                }
                xml.closeTag(AppleServerTags.recurrence);
            }
            xml.closeTag(actionTag);
            xml.closeTag(AppleServerTags.action);
            xml.closeTag(tag);
            return true;
        }
        if (tag.equals(ICalTags.action)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.attach)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.attendee)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.categories)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags._class)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.comment)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.completed)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.contact)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.created)) {
            xml.property(tag, ev.getCreated());
            return true;
        }
        if (tag.equals(ICalTags.description)) {
            if (ev.getDescription() != null) {
                xml.property(tag, ev.getDescription());
            }
            return true;
        }
        if (tag.equals(ICalTags.dtend)) {
            xml.property(tag, ev.getDtend().getDate());
            return true;
        }
        if (tag.equals(ICalTags.dtstamp)) {
            xml.property(tag, ev.getDtstamp());
            return true;
        }
        if (tag.equals(ICalTags.dtstart)) {
            xml.property(tag, ev.getDtstart().getDate());
            return true;
        }
        if (tag.equals(ICalTags.duration)) {
            xml.property(tag, ev.getDuration());
            return true;
        }
        if (tag.equals(ICalTags.exdate)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.exrule)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.freebusy)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.geo)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.lastModified)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.lastModified)) {
            xml.property(tag, ev.getLastmod());
            return true;
        }
        if (tag.equals(ICalTags.location)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.organizer)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.organizer)) {
            if (ev.getOrganizer() != null) {
                xml.property(tag, ev.getOrganizer().getOrganizerUri());
            }
            return true;
        }
        if (tag.equals(ICalTags.percentComplete)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.priority)) {
            Integer val = ev.getPriority();
            if ((val != null) && (val != 0)) {
                xml.property(tag, String.valueOf(val));
            }
            return true;
        }
        if (tag.equals(ICalTags.rdate)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.recurrenceId)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.recurrenceId)) {
            if (ev.getRecurrenceId() != null) {
                xml.property(tag, ev.getRecurrenceId());
            }
            return true;
        }
        if (tag.equals(ICalTags.relatedTo)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.repeat)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.resources)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.requestStatus)) {
            /*
      if (ev.getRequestStatus() != null) {
        xml.property(tag, ev.getRequestStatus().strVal());
      }
         */
            return true;
        }
        if (tag.equals(ICalTags.rrule)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.sequence)) {
            xml.property(tag, String.valueOf(ev.getSequence()));
            return true;
        }
        if (tag.equals(ICalTags.status)) {
            xml.property(tag, ev.getStatus());
            return true;
        }
        if (tag.equals(ICalTags.summary)) {
            xml.property(tag, ev.getSummary());
            return true;
        }
        if (tag.equals(ICalTags.transp)) {
            xml.property(tag, ev.getPeruserTransparency(intf.getPrincipal().getPrincipalRef()));
            return true;
        }
        if (tag.equals(ICalTags.trigger)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.uid)) {
            xml.property(tag, ev.getUid());
            return true;
        }
        if (tag.equals(ICalTags.url)) {
            if (ev.getLink() != null) {
                xml.property(tag, ev.getLink());
            }
            return true;
        }
        if (tag.equals(ICalTags.version)) {
            // PROPTODO
            return true;
        }
        return false;
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) QName(javax.xml.namespace.QName) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent)

Example 27 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method validateAlarm.

/**
 * Validate an alarm component
 *
 * @param val
 * @return boolean false for failure
 * @throws WebdavException
 */
@Override
public boolean validateAlarm(final String val) throws WebdavException {
    try {
        // Ensure open
        getSvci();
        StringReader sr = new StringReader(ValidateAlarmPrefix + val + ValidateAlarmSuffix);
        Icalendar ic = trans.fromIcal(null, sr);
        if ((ic == null) || (ic.getEventInfo() == null)) {
            if (debug) {
                debug("Not single event");
            }
            return false;
        }
        /* There should be alarms in the Calendar object
       */
        EventInfo ei = ic.getEventInfo();
        BwEvent ev = ei.getEvent();
        if ((ev.getAlarms() == null) || ev.getAlarms().isEmpty()) {
            return false;
        }
        return true;
    } catch (CalFacadeException cfe) {
        if (debug) {
            error(cfe);
        }
        return false;
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) StringReader(java.io.StringReader) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 28 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method requestFreeBusy.

@Override
public Collection<SchedRecipientResult> requestFreeBusy(final CalDAVEvent val, final boolean iSchedule) throws WebdavException {
    try {
        ScheduleResult sr;
        BwEvent ev = getEvent(val);
        if (currentPrincipal != null) {
            ev.setOwnerHref(currentPrincipal.getPrincipalRef());
        }
        if (Icalendar.itipReplyMethodType(ev.getScheduleMethod())) {
            sr = getSvci().getScheduler().scheduleResponse(getEvinfo(val));
        } else {
            sr = getSvci().getScheduler().schedule(getEvinfo(val), null, null, iSchedule);
        }
        return checkStatus(sr);
    } catch (CalFacadeAccessException cfae) {
        if (debug) {
            error(cfae);
        }
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ScheduleResult(org.bedework.calfacade.ScheduleResult) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 29 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class BwUpdates method match.

/* Return matching entities. */
private List<EventInfo> match(final List<EventInfo> eis, // final SelectElementType sel,
final BaseComponentType selComp) throws WebdavException {
    List<EventInfo> matched = new ArrayList<EventInfo>();
    CompSelector cs = getCompSelector(selComp);
    for (EventInfo ei : eis) {
        if ((cs.uid == null) && (cs.recurrenceId == null)) {
            /* Only valid for a single non-recurring entity */
            if (ei.getEvent().isRecurringEntity() || (eis.size() > 1)) {
                return null;
            }
            matched.add(ei);
            return matched;
        }
        // matched.addAll(ei.getOverrideProxies());
        if (cs.uid == null) {
            // Not valid
            return null;
        }
        BwEvent ev = ei.getEvent();
        // UID must match
        if (!cs.uid.equals(ev.getUid())) {
            continue;
        }
        if (cs.recurrenceId == null) {
            // if ((ev.getRecurrenceId() == null) || sel.isAll()) {
            if (ev.getRecurrenceId() == null) {
                matched.add(ei);
            }
            continue;
        }
        // Looking for override
        if ((ev.getRecurrenceId() != null) && ev.getRecurrenceId().equals(cs.recurrenceId.getDate())) {
            matched.add(ei);
            continue;
        }
    }
    return matched;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) ArrayList(java.util.ArrayList) BwEvent(org.bedework.calfacade.BwEvent)

Example 30 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class BwUpdates method validateDates.

private UpdateResult validateDates(final EventInfo ei) throws WebdavException {
    DatesState ds = (DatesState) state.get(DatesState.stateName);
    if (ds == null) {
        return UpdateResult.getOkResult();
    }
    BwEvent ev = ei.getEvent();
    boolean task = ev.getEntityType() == IcalDefs.entityTypeTodo;
    PropertyInfoIndex endPi;
    ChangeTable chg = ei.getChangeset(userHref);
    if (task) {
        endPi = PropertyInfoIndex.DUE;
    } else {
        endPi = PropertyInfoIndex.DTEND;
    }
    try {
        boolean scheduleReply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
        if (ds.start == null) {
            if (!scheduleReply && !task) {
                return new UpdateResult("org.bedework.error.nostartdate");
            }
            /* A todo can have no date and time. set start to now, end to
         * many years from now and the noStart flag.
         *
         * Such an entry has to appear only on the current day.
         */
            if (ds.end != null) {
                ds.start = ds.end;
            } else {
                Date now = new Date(new java.util.Date().getTime());
                DtStart dtStart = new DtStart(now);
                dtStart.getParameters().add(Value.DATE);
                ds.start = BwDateTime.makeBwDateTime(dtStart);
            }
            if (!ev.getNoStart() || !CalFacadeUtil.eqObjval(ev.getDtstart(), ds.start)) {
                chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), null);
                ev.setDtstart(ds.start);
                ev.setNoStart(true);
            }
        } else if (ev.getNoStart() || !ds.start.equals(ev.getDtstart())) {
            chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), ds.start);
            ev.setNoStart(false);
            ev.setDtstart(ds.start);
        }
        char endType = StartEndComponent.endTypeNone;
        if (ds.end != null) {
            if ((ev.getEndType() != StartEndComponent.endTypeDate) || !CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
                chg.changed(endPi, ev.getDtend(), ds.end);
                endType = StartEndComponent.endTypeDate;
                ev.setDtend(ds.end);
            }
        } else if (scheduleReply || task) {
            // about 10 years
            Dur years = new Dur(520);
            Date now = new Date(new java.util.Date().getTime());
            DtEnd dtEnd = new DtEnd(new Date(years.getTime(now)));
            dtEnd.getParameters().add(Value.DATE);
            ds.end = BwDateTime.makeBwDateTime(dtEnd);
            if (!CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
                chg.changed(endPi, ev.getDtend(), ds.end);
                ev.setDtend(ds.end);
            }
        }
        /**
         * If we were given a duration store it in the event and calculate
         *          an end to the event - which we should not have been given.
         */
        if (ds.duration != null) {
            if (endType != StartEndComponent.endTypeNone) {
                if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
                // Apple is sending both - duration indicates the minimum
                // freebusy duration. Ignore for now.
                } else {
                    return new UpdateResult(CalFacadeException.endAndDuration);
                }
            }
            endType = StartEndComponent.endTypeDuration;
            if (!ds.duration.equals(ev.getDuration())) {
                chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), ds.duration);
                ev.setDuration(ds.duration);
            }
            ev.setDtend(BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), ev.getDtstart().getDateType(), new Dur(ds.duration)));
        } else if (!scheduleReply && (endType == StartEndComponent.endTypeNone) && !task) {
            /* No duration and no end specified.
         * Set the end values to the start values + 1 for dates
         */
            boolean dateOnly = ev.getDtstart().getDateType();
            Dur dur;
            if (dateOnly) {
                // 1 day
                dur = new Dur(1, 0, 0, 0);
            } else {
                // No duration
                dur = new Dur(0, 0, 0, 0);
            }
            BwDateTime bwDtEnd = BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), dateOnly, dur);
            if (!CalFacadeUtil.eqObjval(ev.getDtend(), bwDtEnd)) {
                chg.changed(endPi, ev.getDtend(), bwDtEnd);
                ev.setDtend(bwDtEnd);
            }
        }
        if ((endType != StartEndComponent.endTypeDuration) && (ev.getDtstart() != null) && (ev.getDtend() != null)) {
            // Calculate a duration
            String durVal = BwDateTime.makeDuration(ev.getDtstart(), ev.getDtend()).toString();
            if (!durVal.equals(ev.getDuration())) {
                chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), durVal);
                ev.setDuration(durVal);
            }
        }
        ev.setEndType(endType);
        return UpdateResult.getOkResult();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : Dur(net.fortuna.ical4j.model.Dur) BwDateTime(org.bedework.calfacade.BwDateTime) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) Date(net.fortuna.ical4j.model.Date) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) DtStart(net.fortuna.ical4j.model.property.DtStart) ChangeTable(org.bedework.calfacade.util.ChangeTable) DatesState(org.bedework.caldav.bwserver.stdupdaters.DateDatetimePropUpdater.DatesState) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10