Search in sources :

Example 41 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method addEvent.

/* ====================================================================
   *                   Events
   * ==================================================================== */
/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#addEvent(org.bedework.caldav.server.CalDAVEvent, boolean, boolean)
   */
@Override
public Collection<CalDAVEvent> addEvent(final CalDAVEvent ev, final boolean noInvites, final boolean rollbackOnError) throws WebdavException {
    try {
        /* Is the event a scheduling object? */
        final EventInfo ei = getEvinfo(ev);
        final Collection<BwEventProxy> bwevs = getSvci().getEventsHandler().add(ei, noInvites, // scheduling - inbox
        false, // autocreate
        false, rollbackOnError).failedOverrides;
        if (bwevs == null) {
            return null;
        }
        final Collection<CalDAVEvent> evs = new ArrayList<CalDAVEvent>();
        for (final BwEvent bwev : bwevs) {
            evs.add(new BwCalDAVEvent(this, new EventInfo(bwev)));
        }
        return evs;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.schedulingTooManyAttendees.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.maxAttendeesPerInstance, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.invalidOverride.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.validCalendarData, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.duplicateGuid.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.duplicateName.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + ev.getName());
        }
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) CalDAVEvent(org.bedework.caldav.server.CalDAVEvent)

Example 42 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#getFreeBusy(org.bedework.caldav.server.CalDAVCollection, int, org.bedework.caldav.util.TimeRange)
   */
@Override
public CalDAVEvent getFreeBusy(final CalDAVCollection col, final int depth, final TimeRange timeRange) throws WebdavException {
    try {
        BwCalendar bwCol = unwrap(col);
        int calType = bwCol.getCalType();
        if (!bwCol.getCollectionInfo().allowFreeBusy) {
            throw new WebdavForbidden(WebdavTags.supportedReport);
        }
        Collection<BwCalendar> cals = new ArrayList<BwCalendar>();
        if (calType == BwCalendar.calTypeCalendarCollection) {
            cals.add(bwCol);
        } else if (depth == 0) {
        /* Cannot return anything */
        } else {
            for (BwCalendar ch : getSvci().getCalendarsHandler().getChildren(bwCol)) {
                // For depth 1 we only add calendar collections
                if ((depth > 1) || (ch.getCalType() == BwCalendar.calTypeCalendarCollection)) {
                    cals.add(ch);
                }
            }
        }
        AccessPrincipal owner = col.getOwner();
        String orgUri;
        if (owner instanceof BwPrincipal) {
            orgUri = getSvci().getDirectories().principalToCaladdr((BwPrincipal) owner);
        } else {
            BwPrincipal p = BwPrincipal.makeUserPrincipal();
            p.setAccount(owner.getAccount());
            orgUri = getSvci().getDirectories().principalToCaladdr(p);
        }
        BwOrganizer org = new BwOrganizer();
        org.setOrganizerUri(orgUri);
        BwEvent fb;
        if (cals.isEmpty()) {
            // Return an empty object
            fb = new BwEventObj();
            fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
            fb.setDtstart(getBwDt(timeRange.getStart()));
            fb.setDtend(getBwDt(timeRange.getEnd()));
        } else {
            fb = getSvci().getScheduler().getFreeBusy(cals, (BwPrincipal) currentPrincipal, getBwDt(timeRange.getStart()), getBwDt(timeRange.getEnd()), org, // uid
            null, null);
        }
        EventInfo ei = new EventInfo(fb);
        return new BwCalDAVEvent(this, ei);
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) AccessPrincipal(org.bedework.access.AccessPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 43 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getSvci.

/**
 * @return CalSvcI
 * @throws WebdavException
 */
private CalSvcI getSvci() throws WebdavException {
    if (!svci.isOpen()) {
        try {
            svci.open();
            svci.beginTransaction();
        } catch (Throwable t) {
            throw new WebdavException(t);
        }
    }
    return svci;
}
Also used : WebdavException(org.bedework.webdav.servlet.shared.WebdavException)

Example 44 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getSvci.

private CalSvcI getSvci(final String account, final String runAs, final boolean service, final boolean publicAdmin, final String clientId, final boolean allowCreateEprops) throws WebdavException {
    try {
        /* account is what we authenticated with.
       * user, if non-null, is the user calendar we want to access.
       */
        final boolean possibleSuperUser = // allow SuperUser
        "root".equals(account) || "admin".equals(account);
        String runAsUser = null;
        String clientIdent = null;
        if (possibleSuperUser) {
            runAsUser = runAs;
            clientIdent = clientId;
        }
        final CalSvcIPars pars = CalSvcIPars.getCaldavPars("bwcaldav", account, runAsUser, clientIdent, // allow SuperUser
        possibleSuperUser, service, publicAdmin, allowCreateEprops);
        svci = new CalSvcFactoryDefault().getSvc(pars);
        svci.open();
        svci.beginTransaction();
        trans = new IcalTranslator(svci.getIcalCallback());
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
    return svci;
}
Also used : CalSvcFactoryDefault(org.bedework.calsvci.CalSvcFactoryDefault) CalSvcIPars(org.bedework.calsvci.CalSvcIPars) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) IcalTranslator(org.bedework.icalendar.IcalTranslator)

Example 45 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method fromIcal.

@Override
public SysiIcalendar fromIcal(final CalDAVCollection col, final IcalendarType ical, final IcalResultType rtype) throws WebdavException {
    // Ensure open
    getSvci();
    boolean rollback = true;
    try {
        BwCalendar bwcol = null;
        if (col != null) {
            bwcol = unwrap(col.resolveAlias(true));
        }
        Icalendar ic = trans.fromIcal(bwcol, ical, // diff the contents
        true);
        if (rtype == IcalResultType.OneComponent) {
            if (ic.getComponents().size() != 1) {
                throw new WebdavBadRequest(CaldavTags.validCalendarObjectResource);
            }
            if (!(ic.getComponents().iterator().next() instanceof EventInfo)) {
                throw new WebdavBadRequest(CaldavTags.validCalendarObjectResource);
            }
        } else if (rtype == IcalResultType.TimeZone) {
            if (ic.getTimeZones().size() != 1) {
                throw new WebdavBadRequest("Expected one timezone");
            }
        }
        SysiIcalendar sic = new MySysiIcalendar(this, ic);
        rollback = false;
        return sic;
    } catch (WebdavException wde) {
        throw wde;
    } catch (IcalMalformedException ime) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, ime.getMessage());
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        // Assume bad data in some way
        throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, t.getMessage());
    } finally {
        if (rollback) {
            try {
                getSvci().rollbackTransaction();
            } catch (Throwable t) {
            }
        }
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) EventInfo(org.bedework.calfacade.svc.EventInfo) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) IcalMalformedException(org.bedework.icalendar.IcalMalformedException)

Aggregations

WebdavException (org.bedework.webdav.servlet.shared.WebdavException)55 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)32 BwEvent (org.bedework.calfacade.BwEvent)20 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)20 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)13 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)10 ArrayList (java.util.ArrayList)9 EventInfo (org.bedework.calfacade.svc.EventInfo)9 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)8 BwDateTime (org.bedework.calfacade.BwDateTime)7 BwString (org.bedework.calfacade.BwString)6 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)4 TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)3 Holder (javax.xml.ws.Holder)3 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)3 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)3 CalPrincipalInfo (org.bedework.caldav.server.sysinterface.CalPrincipalInfo)3 BwCategory (org.bedework.calfacade.BwCategory)3