Search in sources :

Example 81 with CalFacadeException

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

the class CalintfImpl method deleteFilterDef.

@Override
public void deleteFilterDef(final String name, final BwPrincipal owner) throws CalFacadeException {
    final BwFilterDef fd = filterDefs.fetch(name, owner);
    if (fd == null) {
        throw new CalFacadeException(CalFacadeException.unknownFilter, name);
    }
    entityDao.delete(fd);
}
Also used : BwFilterDef(org.bedework.calfacade.BwFilterDef) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 82 with CalFacadeException

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

the class CoreCalendars method checkNewCalendarName.

private void checkNewCalendarName(final String name, final boolean special, final BwCalendar parent) throws CalFacadeException {
    // XXX This should be accessible to all implementations.
    if (!special) {
        final BasicSystemProperties sys = getSyspars();
        if (name.equals(sys.getUserInbox())) {
            throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
        }
        if (name.equals(sys.getUserOutbox())) {
            throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
        }
        if (name.equals(sys.getDefaultNotificationsName())) {
            throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
        }
    }
    /* Ensure the name is not-null and contains no invalid characters
     */
    if ((name == null) || name.contains("/")) {
        throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
    }
    /* Ensure the new path is unique */
    String path;
    if (parent == null) {
        path = "";
    } else {
        path = parent.getPath();
    }
    path = Util.buildPath(colPathEndsWithSlash, path, "/", name);
    final BwCalendar col = dao.getCollection(path);
    if (col != null) {
        if (!col.getTombstoned()) {
            throw new CalFacadeException(CalFacadeException.duplicateCalendar);
        }
        dao.deleteCalendar(unwrap(col));
    }
}
Also used : BasicSystemProperties(org.bedework.calfacade.configs.BasicSystemProperties) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 83 with CalFacadeException

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

the class CoreCalendars method deleteCalendar.

@Override
public boolean deleteCalendar(BwCalendar val, final boolean reallyDelete) throws CalFacadeException {
    colCache.flush();
    ac.checkAccess(val, privUnbind, false);
    final String parentPath = val.getColPath();
    if (parentPath == null) {
        throw new CalFacadeException(CalFacadeException.cannotDeleteCalendarRoot);
    }
    /* Ensure the parent exists and we have writeContent on the parent.
     */
    final BwCalendar parent = getCalendar(parentPath, privWriteContent, false);
    if (parent == null) {
        throw new CalFacadeException(CalFacadeException.collectionNotFound);
    }
    val = getCalendar(val.getPath(), privUnbind, false);
    if (val == null) {
        throw new CalFacadeException(CalFacadeException.collectionNotFound);
    }
    if (!isEmpty(val)) {
        throw new CalFacadeException(CalFacadeException.collectionNotEmpty);
    }
    /* See if this is a no-op after all. We do this now to ensure the caller
     * really does have access
     */
    if (!reallyDelete && val.getTombstoned()) {
        // Nothing to do
        return true;
    }
    final BwCalendar unwrapped = unwrap(val);
    final String path = val.getPath();
    /* Ensure it's not in any (auth)user preferences */
    dao.removeCalendarFromAuthPrefs(unwrapped);
    /* Ensure no tombstoned events or childen */
    dao.removeTombstoned(fixPath(path));
    if (reallyDelete) {
        dao.deleteCalendar(unwrapped);
    } else {
        tombstoneEntity(unwrapped);
        unwrapped.tombstone();
        dao.updateCollection(unwrapped);
        touchCalendar(unwrapped);
    }
    colCache.remove(path);
    touchCalendar(parent);
    notify(SysEvent.SysCode.COLLECTION_DELETED, val);
    getIndexer(val).unindexEntity(path);
    return true;
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 84 with CalFacadeException

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

the class DtStartPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        BwEvent ev = ui.getEvent();
        boolean scheduleReply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
        // No dates valid for reply
        DtstartPropType dt = (DtstartPropType) ui.getProp();
        DatesState ds = (DatesState) ui.getState(DatesState.stateName);
        if (ds == null) {
            ds = new DatesState(ev);
            ui.saveState(DatesState.stateName, ds);
        }
        ChangeTableEntry cte = ui.getCte();
        if (ui.isRemove()) {
            if (!scheduleReply && (ev.getEntityType() != IcalDefs.entityTypeTodo)) {
                return new UpdateResult("Entity requires start date");
            }
            cte.setDeleted(ev.getDtstart());
            ds.start = null;
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            if (!ev.getNoStart()) {
                return new UpdateResult("Entity already has start date - cannot add");
            }
            ds.start = BwDateTime.makeBwDateTime(dt);
            cte.setAdded(ds.start);
            return UpdateResult.getOkResult();
        }
        /* Changing dtstart - either value or parameters */
        if (ev.getNoStart()) {
            return new UpdateResult("Entity has no start date - cannot change");
        }
        Holder<BwDateTime> resdt = new Holder<BwDateTime>();
        UpdateResult ur = makeDt(ev.getDtstart(), resdt, ui);
        if (!ur.getOk()) {
            return ur;
        }
        if (resdt.value != null) {
            cte.setChanged(ev.getDtstart(), resdt.value);
            ds.start = resdt.value;
        }
        return UpdateResult.getOkResult();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) Holder(javax.xml.ws.Holder) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) DtstartPropType(ietf.params.xml.ns.icalendar_2.DtstartPropType) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 85 with CalFacadeException

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

the class LocationPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final BwEvent ev = ui.getEvent();
        final ChangeTableEntry cte = ui.getCte();
        BwString val = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
        final BwLocation evLoc = ev.getLocation();
        BwString evVal = null;
        if (evLoc != null) {
            evVal = evLoc.getAddress();
        }
        if (ui.isRemove()) {
            if (evVal == null) {
                return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
            }
            val = null;
        } else if (ui.isAdd()) {
            if (evVal != null) {
                return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
            }
        } else if (!ui.isChange()) {
            final ParameterUpdater.UpdateInfo langUpd = UpdaterUtil.findLangUpdate(ui.getParamUpdates());
            if (langUpd == null) {
                return new UpdateResult("No update specified for " + ui.getPropName());
            }
            String lang = val.getLang();
            if (langUpd.isRemove()) {
                lang = null;
            } else if (langUpd.isAdd()) {
                lang = ((TextParameterType) langUpd.getParam()).getText();
            } else if (langUpd.getUpdparam() != null) {
                lang = ((TextParameterType) langUpd.getUpdparam()).getText();
            }
            if (!Util.equalsString(lang, val.getLang())) {
                val = new BwString(lang, val.getValue());
            }
        } else {
            if (!val.equals(evVal)) {
                return new UpdateResult("Values don't match for update to " + ui.getPropName());
            }
            val = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
        }
        if (val == null) {
            cte.setDeleted(ev.getLocation());
            ev.setLocation(null);
        } else if (Util.cmpObjval(val, evVal) != 0) {
            BwLocation loc = ui.getIcalCallback().findLocation(val);
            if (loc == null) {
                loc = BwLocation.makeLocation();
                loc.setAddress(val);
                ui.getIcalCallback().addLocation(loc);
            }
            if (cte.setChanged(evLoc, loc)) {
                ev.setLocation(loc);
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) TextParameterType(ietf.params.xml.ns.icalendar_2.TextParameterType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) ParameterUpdater(org.bedework.caldav.bwserver.ParameterUpdater) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) 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