Search in sources :

Example 26 with BwCategory

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

the class CategoryPropUpdater method addValue.

@Override
protected void addValue(final BwEvent ev, final BwString val, final UpdateInfo ui) throws WebdavException {
    try {
        BwCategory cat = null;
        if (ev.getNumCategories() == 0) {
            // Nothing to do
            return;
        }
        for (BwCategory evcat : ev.getCategories()) {
            if (evcat.getWord().equals(val)) {
                // Found the category attached to the event.
                cat = evcat;
                break;
            }
        }
        if (cat != null) {
            // Nothing to do
            return;
        }
        cat = ui.getIcalCallback().findCategory(val);
        if (cat == null) {
            cat = BwCategory.makeCategory();
            cat.setWord(val);
            ui.getIcalCallback().addCategory(cat);
        }
        ev.addCategory(cat);
        ui.getCte().addAddedValue(cat);
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwCategory(org.bedework.calfacade.BwCategory) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 27 with BwCategory

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

the class XbwCategoryPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xcats = ev.getXproperties(BwXproperty.xBedeworkCategories);
        final Set<BwCategory> cats = ev.getCategories();
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = getValue(ui.getProp());
        final BwString cstr = new BwString(lang, xval);
        if (ui.isRemove()) {
            if (Util.isEmpty(xcats)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            for (final BwXproperty xp : xcats) {
                if (!xp.getValue().equals(xval)) {
                    continue;
                }
                // Found
                ev.removeXproperty(xp);
                cte.addRemovedValue(xp);
                /* Do we have a corresponding category */
                for (final BwCategory c : cats) {
                    if (c.getWord().equals(cstr)) {
                        ev.removeCategory(c);
                        cte.addRemovedValue(c);
                        break;
                    }
                }
                return UpdateResult.getOkResult();
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            for (final BwXproperty xp : xcats) {
                if (xp.getValue().equals(xval)) {
                    return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
                }
            }
            /* Add the xprop or a category */
            if (!checkCategory(ui, ev, cats, lang, xval)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            for (final BwXproperty xp : xcats) {
                if (xp.getValue().equals(xval)) {
                    // Found
                    ev.removeXproperty(xp);
                    cte.addRemovedValue(xp);
                    final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
                    final String nxval = getValue(ui.getUpdprop());
                    if (!checkCategory(ui, ev, cats, nlang, nxval)) {
                        final BwXproperty nxp = makeXprop(nlang, nxval);
                        ev.addXproperty(nxp);
                        cte.addValue(nxp);
                    }
                    return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) BwCategory(org.bedework.calfacade.BwCategory) 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) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 28 with BwCategory

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

the class XbwCategoryPropUpdater method checkCategory.

/* Return true if value matches a category - which may be added as
   * a result
   */
private boolean checkCategory(final UpdateInfo ui, final BwEvent ev, final Set<BwCategory> cats, final String lang, final String val) throws CalFacadeException {
    final BwString sval = new BwString(lang, val);
    final BwCategory cat = ui.getIcalCallback().findCategory(sval);
    if (cat == null) {
        return false;
    }
    for (final BwCategory c : cats) {
        if (c.getWord().equals(sval)) {
            // Already present
            return true;
        }
    }
    ev.addCategory(cat);
    ui.getCte(PropertyIndex.PropertyInfoIndex.CATEGORIES).addValue(cat);
    return true;
}
Also used : BwCategory(org.bedework.calfacade.BwCategory) BwString(org.bedework.calfacade.BwString)

Example 29 with BwCategory

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

the class BwIndexEsImpl method fetchCat.

@Override
public BwCategory fetchCat(final String val, final PropertyInfoIndex... index) throws CalFacadeException {
    final EntityBuilder eb = fetchEntity(docTypeCategory, val, index);
    if (eb == null) {
        return null;
    }
    final BwCategory entity = eb.makeCat();
    if (entity == null) {
        return null;
    }
    categories.put(entity);
    return entity;
}
Also used : BwCategory(org.bedework.calfacade.BwCategory)

Example 30 with BwCategory

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

the class BwIndexEsImpl method restoreEvProps.

private boolean restoreEvProps(final Response resp, final EventInfo ei) {
    final BwEvent ev = ei.getEvent();
    try {
        final Set<String> catUids = ev.getCategoryUids();
        if (!Util.isEmpty(catUids)) {
            for (final String uid : catUids) {
                BwCategory evprop = categories.get(uid);
                if (evprop == null) {
                    evprop = fetchCat(uid, PropertyInfoIndex.UID);
                    if (evprop == null) {
                        warn("Unable to fetch category " + uid + " for event " + ev.getHref());
                        errorReturn(resp, "Unable to fetch category " + uid);
                        continue;
                    }
                }
                ev.addCategory(evprop);
            }
        }
        final Set<String> contactUids = ev.getContactUids();
        if (!Util.isEmpty(contactUids)) {
            for (final String uid : contactUids) {
                BwContact evprop = contacts.get(uid);
                if (evprop == null) {
                    evprop = fetchContact(uid, PropertyInfoIndex.UID);
                    if (evprop == null) {
                        warn("Unable to fetch contact " + uid + " for event " + ev.getHref());
                        errorReturn(resp, "Unable to fetch contact " + uid);
                        continue;
                    }
                }
                ev.addContact(evprop);
            }
        }
        final String uid = ev.getLocationUid();
        if (uid != null) {
            BwLocation evprop = locations.get(uid);
            if (evprop == null) {
                evprop = fetchLocation(uid, PropertyInfoIndex.UID);
                if (evprop == null) {
                    warn("Unable to fetch location " + uid + " for event " + ev.getHref());
                    errorReturn(resp, "Unable to fetch location " + uid);
                }
            }
            if (evprop != null) {
                ev.setLocation(evprop);
            }
        }
        return resp.getStatus() == ok;
    } catch (final Throwable t) {
        errorReturn(resp, t);
        return false;
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) BwCategory(org.bedework.calfacade.BwCategory) BwEvent(org.bedework.calfacade.BwEvent) BwContact(org.bedework.calfacade.BwContact)

Aggregations

BwCategory (org.bedework.calfacade.BwCategory)42 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)13 BwContact (org.bedework.calfacade.BwContact)11 BwString (org.bedework.calfacade.BwString)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 BwEvent (org.bedework.calfacade.BwEvent)10 BwLocation (org.bedework.calfacade.BwLocation)8 BwXproperty (org.bedework.calfacade.BwXproperty)7 ArrayList (java.util.ArrayList)6 EventInfo (org.bedework.calfacade.svc.EventInfo)6 BwDateTime (org.bedework.calfacade.BwDateTime)5 TreeSet (java.util.TreeSet)4 BwAttendee (org.bedework.calfacade.BwAttendee)4 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)4 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)4 Period (net.fortuna.ical4j.model.Period)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)3 FilterBase (org.bedework.caldav.util.filter.FilterBase)2 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)2