Search in sources :

Example 66 with BwCalendar

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

the class ProcessUpdate method updateCollection.

private boolean updateCollection() {
    try {
        open();
        final BwCalendar col = getCal();
        if (col == null) {
            warn("No path or no calendar");
            return true;
        }
        while (true) {
            final String upname = word();
            if (upname == null) {
                break;
            }
            assertToken('=');
            switch(upname) {
                case "topicalArea":
                    {
                        final Boolean val = boolFor(upname);
                        if (val == null) {
                            return true;
                        }
                        col.setIsTopicalArea(val);
                        break;
                    }
                case "summary":
                    {
                        final String val = qstringFor(upname);
                        if (val == null) {
                            return true;
                        }
                        col.setSummary(val);
                        break;
                    }
            }
        }
        getSvci().getCalendarsHandler().update(col);
        return true;
    } catch (final Throwable t) {
        error(t);
        return false;
    } finally {
        close();
    }
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar)

Example 67 with BwCalendar

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

the class BwSysIntfImpl method getSyncToken.

@Override
public String getSyncToken(final CalDAVCollection col) throws WebdavException {
    try {
        BwCalendar bwcol = ((BwCalDAVCollection) col).getCol();
        String path = col.getPath();
        if (bwcol.getInternalAlias()) {
            path = bwcol.getAliasTarget().getPath();
        }
        return "data:," + getSvci().getCalendarsHandler().getSyncToken(path);
    } 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) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 68 with BwCalendar

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

the class BwSysIntfImpl method copyMove.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#copyMove(org.bedework.caldav.server.CalDAVCollection, org.bedework.caldav.server.CalDAVCollection, boolean, boolean)
   */
@Override
public void copyMove(final CalDAVCollection from, final CalDAVCollection to, final boolean copy, final boolean overwrite) throws WebdavException {
    try {
        BwCalendar bwFrom = unwrap(from);
        BwCalendar bwTo = unwrap(to);
        if (!copy) {
            /* Move the from collection to the new location "to".
         * If the parent calendar is the same in both cases, this is just a rename.
         */
            if ((bwFrom.getColPath() == null) || (bwTo.getColPath() == null)) {
                throw new WebdavForbidden("Cannot move root");
            }
            if (bwFrom.getColPath().equals(bwTo.getColPath())) {
                // Rename
                getSvci().getCalendarsHandler().rename(bwFrom, to.getName());
                return;
            }
        }
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
    throw new WebdavException("unimplemented");
}
Also used : WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 69 with BwCalendar

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

the class BwSysIntfImpl method fromIcal.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#fromIcal(org.bedework.caldav.server.CalDAVCollection, java.io.Reader, java.lang.String, org.bedework.caldav.server.sysinterface.SysIntf.IcalResultType, boolean)
   */
@Override
public SysiIcalendar fromIcal(final CalDAVCollection col, final Reader rdr, final String contentType, final IcalResultType rtype, final boolean mergeAttendees) throws WebdavException {
    // Ensure open
    getSvci();
    boolean rollback = true;
    /* (CALDAV:supported-calendar-data) */
    if ((contentType == null) || (!contentType.equals("text/calendar") && !contentType.equals("application/calendar+json"))) {
        if (debug) {
            debug("Bad content type: " + contentType);
        }
        throw new WebdavForbidden(CaldavTags.supportedCalendarData, "Bad content type: " + contentType);
    }
    try {
        BwCalendar bwcol = null;
        if (col != null) {
            bwcol = unwrap(col);
        }
        final Icalendar ic = trans.fromIcal(bwcol, new SysIntfReader(rdr), contentType, // diff the contents
        true, mergeAttendees);
        if (rtype == IcalResultType.OneComponent) {
            if (ic.getComponents().size() != 1) {
                throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
            }
            if (!(ic.getComponents().iterator().next() instanceof EventInfo)) {
                throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
            }
        } else if (rtype == IcalResultType.TimeZone) {
            if (ic.getTimeZones().size() != 1) {
                throw new WebdavForbidden("Expected one timezone");
            }
        }
        final SysiIcalendar sic = new MySysiIcalendar(this, ic);
        rollback = false;
        return sic;
    } catch (final IcalMalformedException ime) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, ime.getMessage());
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.unknownTimezone.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.validTimezone, cfe.getMessage());
        }
        throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, cfe.getMessage());
    } catch (final WebdavException wde) {
        throw wde;
    } catch (final 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 (final Throwable ignored) {
            }
        }
    }
}
Also used : SysIntfReader(org.bedework.caldav.server.SysIntfReader) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) IcalMalformedException(org.bedework.icalendar.IcalMalformedException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 70 with BwCalendar

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

the class BwSysIntfImpl method allowsSyncReport.

@Override
public boolean allowsSyncReport(final WdCollection col) throws WebdavException {
    if (col == null) {
        return false;
    }
    /* This - or any target if an alias - cannot be filtered at the moment. */
    final BwCalendar bwcol = ((BwCalDAVCollection) col).getCol();
    if (bwcol.getFilterExpr() != null) {
        return false;
    }
    BwCalendar leaf = bwcol;
    while (leaf.getInternalAlias()) {
        leaf = resolveAlias(leaf, false);
        if (// bad alias
        (leaf == null) || (leaf.getFilterExpr() != null)) {
            return false;
        }
    }
    /* This must be a collection which is either a user home or below. */
    String uhome = basicSysProperties.getUserCalendarRoot();
    if (uhome.endsWith("/")) {
        uhome = uhome.substring(0, uhome.length() - 1);
    }
    if (uhome.startsWith("/")) {
        uhome = uhome.substring(1);
    }
    final String[] els = bwcol.getPath().split("/");
    if ((els.length < 3) || (!"".equals(els[0])) || (els[1] == null) || (els[2] == null) || (els[2].length() == 0)) {
        return false;
    }
    return els[1].equals(uhome);
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)134 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)46 EventInfo (org.bedework.calfacade.svc.EventInfo)23 BwEvent (org.bedework.calfacade.BwEvent)19 ArrayList (java.util.ArrayList)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)18 BwPrincipal (org.bedework.calfacade.BwPrincipal)15 TreeSet (java.util.TreeSet)10 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)10 BwCategory (org.bedework.calfacade.BwCategory)10 BwResource (org.bedework.calfacade.BwResource)10 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)9 FilterBase (org.bedework.caldav.util.filter.FilterBase)8 BwPreferences (org.bedework.calfacade.svc.BwPreferences)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)7 CurrentAccess (org.bedework.access.Acl.CurrentAccess)6 CalendarsI (org.bedework.calsvci.CalendarsI)6 Acl (org.bedework.access.Acl)5 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)5