Search in sources :

Example 66 with CalFacadeException

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

the class NotificationsInfo method getDeleted.

/**
 * Call for a deleted event
 *
 * @param currentAuth
 * @param ev
 * @return resource deleted notification.
 * @throws CalFacadeException
 */
public static ResourceChangeType getDeleted(final String currentAuth, final BwEvent ev) throws CalFacadeException {
    try {
        ResourceChangeType rc = new ResourceChangeType();
        DeletedType del = new DeletedType();
        del.setHref(getHref(ev));
        del.setChangedBy(getChangedBy(currentAuth));
        DeletedDetailsType dd = new DeletedDetailsType();
        dd.setDeletedComponent(getType(ev));
        dd.setDeletedSummary(ev.getSummary());
        if (ev.isRecurringEntity()) {
        // TODO: Set these correctly.
        // dd.setDeletedNextInstance(val);
        // dd.setDeletedNextInstanceTzid(val);
        // dd.setDeletedHadMoreInstances(val);
        }
        if (ev.getDtstart() != null) {
            ChangedPropertyType start = new ChangedPropertyType();
            start.setName(PropertyInfoIndex.DTSTART.name());
            start.setDataFrom(String.valueOf(ev.getDtstart()));
            dd.getDeletedProps().add(start);
        }
        if (ev.getDtend() != null) {
            ChangedPropertyType end = new ChangedPropertyType();
            end.setName(PropertyInfoIndex.DTEND.name());
            end.setDataFrom(String.valueOf(ev.getDtend()));
            dd.getDeletedProps().add(end);
        }
        if (ev.getDuration() != null && !ev.getDuration().isEmpty()) {
            ChangedPropertyType dur = new ChangedPropertyType();
            dur.setName(PropertyInfoIndex.DURATION.name());
            dur.setDataFrom(ev.getDuration());
            dd.getDeletedProps().add(dur);
        }
        if (ev.getLocation() != null) {
            ChangedPropertyType loc = new ChangedPropertyType();
            loc.setName(PropertyInfoIndex.LOCATION.name());
            loc.setDataFrom(ev.getLocation().getAddress().getValue());
            dd.getDeletedProps().add(loc);
        }
        if (ev.getDescription() != null) {
            ChangedPropertyType desc = new ChangedPropertyType();
            desc.setName(PropertyInfoIndex.DESCRIPTION.name());
            desc.setDataFrom(ev.getDescription());
            dd.getDeletedProps().add(desc);
        }
        del.setDeletedDetails(dd);
        rc.setDeleted(del);
        return rc;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType) ChangedPropertyType(org.bedework.caldav.util.notifications.ChangedPropertyType) DeletedType(org.bedework.caldav.util.notifications.DeletedType) DeletedDetailsType(org.bedework.caldav.util.notifications.DeletedDetailsType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 67 with CalFacadeException

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

the class BwEventUtil method processCandidates.

private static void processCandidates(final VPoll val, final EventInfo vpoll, final ChangeTable changes) throws CalFacadeException {
    try {
        final ComponentList cands = val.getCandidates();
        if ((cands == null) || cands.isEmpty()) {
            return;
        }
        final Iterator it = cands.iterator();
        final Set<Integer> pids = new TreeSet<>();
        final BwEvent event = vpoll.getEvent();
        if (!Util.isEmpty(event.getPollItems())) {
            event.clearPollItems();
        }
        while (it.hasNext()) {
            final Component comp = (Component) it.next();
            final String pollItem = comp.toString();
            event.addPollItem(pollItem);
            changes.addValue(PropertyInfoIndex.POLL_ITEM, pollItem);
            final Property p = comp.getProperty(Property.POLL_ITEM_ID);
            if (p == null) {
                throw new CalFacadeException("XXX - no poll item id");
            }
            final int pid = ((PollItemId) p).getPollitemid();
            if (pids.contains(pid)) {
                throw new CalFacadeException("XXX - duplicate poll item id " + pid);
            }
            pids.add(pid);
        // EventInfo cand = toEvent(cb, cal, ical, (Component)o, true,
        // false);
        // cand.getEvent().setOwnerHref(vpoll.getEvent().getOwnerHref());
        // vpoll.addContainedItem(cand);
        }
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ComponentList(net.fortuna.ical4j.model.ComponentList) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PollItemId(net.fortuna.ical4j.model.property.PollItemId) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) Component(net.fortuna.ical4j.model.Component) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property) DateProperty(net.fortuna.ical4j.model.property.DateProperty)

Example 68 with CalFacadeException

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

the class BwFreeBusyUtil method toFreeBusy.

/**
 * @param cb
 * @param val
 * @return BwFreeBusy
 * @throws CalFacadeException
 */
public static EventInfo toFreeBusy(final IcalCallback cb, final VFreeBusy val) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    boolean debug = getLog().isDebugEnabled();
    try {
        PropertyList pl = val.getProperties();
        if (pl == null) {
            // Empty VEvent
            return null;
        }
        BwEvent fb = new BwEventObj();
        EventInfo ei = new EventInfo(fb);
        ChangeTable chg = ei.getChangeset(cb.getPrincipal().getPrincipalRef());
        fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
        setDates(cb.getPrincipal().getPrincipalRef(), ei, (DtStart) pl.getProperty(Property.DTSTART), (DtEnd) pl.getProperty(Property.DTEND), (Duration) pl.getProperty(Property.DURATION));
        Iterator it = pl.iterator();
        while (it.hasNext()) {
            Property prop = (Property) it.next();
            String pval = prop.getValue();
            if ((pval != null) && (pval.length() == 0)) {
                pval = null;
            }
            PropertyInfoIndex pi = PropertyInfoIndex.fromName(prop.getName());
            if (pi == null) {
                debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
                continue;
            }
            switch(pi) {
                case ATTENDEE:
                    /* ------------------- Attendee -------------------- */
                    BwAttendee att = getAttendee(cb, (Attendee) prop);
                    fb.addAttendee(att);
                    chg.addValue(pi, att);
                    break;
                case COMMENT:
                    /* ------------------- Comment -------------------- */
                    // LANG
                    fb.addComment(null, pval);
                    chg.addValue(pi, pval);
                case DTEND:
                    break;
                case DTSTAMP:
                    /* ------------------- DtStamp -------------------- */
                    chg.changed(pi, fb.getDtstamp(), pval);
                    fb.setDtstamp(pval);
                case DTSTART:
                    break;
                case FREEBUSY:
                    /* ------------------- freebusy -------------------- */
                    FreeBusy fbusy = (FreeBusy) prop;
                    PeriodList perpl = fbusy.getPeriods();
                    Parameter par = getParameter(fbusy, "FBTYPE");
                    int fbtype;
                    if (par == null) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY)) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY_TENTATIVE)) {
                        fbtype = BwFreeBusyComponent.typeBusyTentative;
                    } else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
                        fbtype = BwFreeBusyComponent.typeBusyUnavailable;
                    } else if (par.equals(FbType.FREE)) {
                        fbtype = BwFreeBusyComponent.typeFree;
                    } else {
                        if (debug) {
                            debugMsg("Unsupported parameter " + par.getName());
                        }
                        throw new IcalMalformedException("parameter " + par.getName());
                    }
                    BwFreeBusyComponent fbc = new BwFreeBusyComponent();
                    fbc.setType(fbtype);
                    Iterator perit = perpl.iterator();
                    while (perit.hasNext()) {
                        Period per = (Period) perit.next();
                        fbc.addPeriod(per);
                    }
                    fb.addFreeBusyPeriod(fbc);
                    chg.addValue(pi, fbc);
                    break;
                case ORGANIZER:
                    /* ------------------- Organizer -------------------- */
                    BwOrganizer org = getOrganizer(cb, (Organizer) prop);
                    fb.setOrganizer(org);
                    chg.addValue(pi, org);
                    break;
                case UID:
                    /* ------------------- Uid -------------------- */
                    chg.changed(pi, fb.getUid(), pval);
                    fb.setUid(pval);
                    break;
                default:
                    if (debug) {
                        debugMsg("Unsupported property with class " + prop.getClass() + " and value " + pval);
                    }
            }
        }
        return ei;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) EventInfo(org.bedework.calfacade.svc.EventInfo) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) ChangeTable(org.bedework.calfacade.util.ChangeTable) Iterator(java.util.Iterator) Parameter(net.fortuna.ical4j.model.Parameter) Property(net.fortuna.ical4j.model.Property) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 69 with CalFacadeException

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

the class Notifications method update.

@Override
public boolean update(final NotificationType val) throws CalFacadeException {
    if ((val == null) || (val.getNotification() == null) || (val.getNotification().getElementName() == null)) {
        return false;
    }
    try {
        final String xml = val.toXml(true);
        if (xml == null) {
            return false;
        }
        final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
        if (ncol == null) {
            return false;
        }
        final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", val.getName()));
        if (noteRsrc == null) {
            return false;
        }
        BwResourceContent rc = noteRsrc.getContent();
        if (rc == null) {
            rc = new BwResourceContent();
            noteRsrc.setContent(rc);
        }
        final byte[] xmlData = xml.getBytes();
        rc.setValue(getSvc().getBlob(xmlData));
        noteRsrc.setContentLength(xmlData.length);
        noteRsrc.setContentType(val.getContentType());
        getSvc().getResourcesHandler().update(noteRsrc, true);
        getNoteClient().informNotifier(getPrincipalHref(), noteRsrc.getName());
        return true;
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwResource(org.bedework.calfacade.BwResource) BwResourceContent(org.bedework.calfacade.BwResourceContent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 70 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException 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)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12