Search in sources :

Example 6 with WebdavForbidden

use of org.bedework.webdav.servlet.shared.WebdavForbidden 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 7 with WebdavForbidden

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

the class BwCalDAVResource method setBinaryContent.

@Override
public void setBinaryContent(final InputStream val) throws WebdavException {
    BwResource r = getRsrc();
    BwResourceContent rc = r.getContent();
    if (rc == null) {
        if (!isNew()) {
            intf.getFileContent(this);
            rc = r.getContent();
        }
        if (rc == null) {
            rc = new BwResourceContent();
            r.setContent(rc);
        }
    }
    try {
        /* If this is a notification we need to unprefix the data */
        final InputStream str;
        if (!isNotification()) {
            str = val;
        } else {
            final NotificationType note = Parser.fromXml(val);
            note.getNotification().unprefixHrefs(intf.getUrlHandler());
            str = new ByteArrayInputStream(note.toXml(true).getBytes());
        }
        final ByteArrayOutputStream outBuff = new ByteArrayOutputStream();
        byte[] inBuffer = new byte[1000];
        long clen = 0;
        int chunkSize;
        int maxSize = intf.getAuthProperties().getMaxUserEntitySize();
        long oldSize = r.getContentLength();
        while (clen <= maxSize) {
            chunkSize = str.read(inBuffer);
            if (chunkSize < 0) {
                break;
            }
            outBuff.write(inBuffer, 0, chunkSize);
            clen += chunkSize;
        }
        if (clen > maxSize) {
            throw new WebdavForbidden(CaldavTags.maxResourceSize);
        }
        rc.setValue(intf.getBlob(outBuff.toByteArray()));
        r.setContentLength(clen);
        if (!intf.updateQuota(getOwner(), clen - oldSize)) {
            throw new WebdavForbidden(WebdavTags.quotaNotExceeded);
        }
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BwResource(org.bedework.calfacade.BwResource) NotificationType(org.bedework.caldav.util.notifications.NotificationType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwResourceContent(org.bedework.calfacade.BwResourceContent) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 8 with WebdavForbidden

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

the class BwSysIntfImpl method checkStatus.

/**
 * @param sr schedule result
 * @return recipient results
 * @throws WebdavException
 */
private Collection<SchedRecipientResult> checkStatus(final ScheduleResult sr) throws WebdavException {
    if ((sr.errorCode == null) || (sr.errorCode.equals(CalFacadeException.schedulingNoRecipients))) {
        final Collection<SchedRecipientResult> srrs = new ArrayList<>();
        for (final ScheduleRecipientResult bwsrr : sr.recipientResults.values()) {
            final SchedRecipientResult srr = new SchedRecipientResult();
            srr.recipient = bwsrr.recipient;
            srr.status = bwsrr.getStatus();
            if (bwsrr.freeBusy != null) {
                srr.freeBusy = new BwCalDAVEvent(this, new EventInfo(bwsrr.freeBusy));
            }
            srrs.add(srr);
        }
        return srrs;
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingBadMethod)) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, "Bad METHOD");
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingBadAttendees)) {
        throw new WebdavForbidden(CaldavTags.attendeeAllowed, "Bad attendees");
    }
    if (sr.errorCode.equals(CalFacadeException.schedulingAttendeeAccessDisallowed)) {
        throw new WebdavForbidden(CaldavTags.attendeeAllowed, "attendeeAccessDisallowed");
    }
    throw new WebdavForbidden(sr.errorCode);
}
Also used : ScheduleRecipientResult(org.bedework.calfacade.ScheduleResult.ScheduleRecipientResult) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList)

Example 9 with WebdavForbidden

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

the class BwSysIntfImpl method deleteFile.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#deleteFile(org.bedework.caldav.server.CalDAVResource)
   */
@Override
public void deleteFile(final CalDAVResource val) throws WebdavException {
    try {
        updateQuota(val.getOwner(), -val.getQuotaSize());
        getSvci().getResourcesHandler().delete(Util.buildPath(false, val.getParentPath(), "/", val.getName()));
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 10 with WebdavForbidden

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

the class BwSysIntfImpl method tzidFromTzdef.

@Override
public String tzidFromTzdef(final String val) throws WebdavException {
    try {
        // Ensure open
        getSvci();
        StringReader sr = new StringReader(val);
        Icalendar ic = trans.fromIcal(null, sr);
        if ((ic == null) || // No components other than timezones
        (ic.size() != 0) || (ic.getTimeZones().size() != 1)) {
            if (debug) {
                debug("Not single timezone");
            }
            throw new WebdavForbidden(CaldavTags.calendarTimezone, "Not single timezone");
        }
        /* This should be the only timezone ion the Calendar object
       */
        TimeZone tz = ic.getTimeZones().iterator().next().tz;
        return tz.getID();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) StringReader(java.io.StringReader) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)15 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)13 EventInfo (org.bedework.calfacade.svc.EventInfo)8 BwCalendar (org.bedework.calfacade.BwCalendar)7 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)7 ArrayList (java.util.ArrayList)6 BwEvent (org.bedework.calfacade.BwEvent)4 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)3 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)3 Icalendar (org.bedework.icalendar.Icalendar)3 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)2 BwResource (org.bedework.calfacade.BwResource)2 ScheduleResult (org.bedework.calfacade.ScheduleResult)2 IcalMalformedException (org.bedework.icalendar.IcalMalformedException)2 UrlHandler (org.bedework.webdav.servlet.shared.UrlHandler)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1