Search in sources :

Example 16 with BwString

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

the class ContactPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final Set<BwContact> contacts = ev.getContacts();
        final BwString nm = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
        final String altrep = UpdaterUtil.getAltrep(ui.getProp());
        if (ui.isAdd()) {
            if (!Util.isEmpty(contacts)) {
                for (final BwContact cnct : contacts) {
                    if (cnct.getCn().equals(nm)) {
                        // Already there
                        return UpdateResult.getOkResult();
                    }
                }
            }
            // Add it
            BwContact cnct = ui.getIcalCallback().findContact(nm);
            if (cnct == null) {
                cnct = BwContact.makeContact();
                cnct.setCn(nm);
                cnct.setLink(altrep);
                ui.getIcalCallback().addContact(cnct);
            }
            ev.addContact(cnct);
            cte.addAddedValue(cnct);
            return UpdateResult.getOkResult();
        }
        if (ui.isRemove()) {
            if (Util.isEmpty(contacts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            for (final BwContact cnct : contacts) {
                if (cnct.getCn().equals(nm)) {
                    if (ev.removeContact(cnct)) {
                        cte.addRemovedValue(cnct);
                    }
                    return UpdateResult.getOkResult();
                }
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            // Change a value
            if (Util.isEmpty(contacts)) {
                // Nothing to change
                return new UpdateResult("No contact to change");
            }
            for (final BwContact evcnct : contacts) {
                if (evcnct.getCn().equals(nm)) {
                    // Found - remove that one and add a new one.
                    final BwString newnm = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
                    BwContact cnct = ui.getIcalCallback().findContact(newnm);
                    if (cnct == null) {
                        cnct = new BwContact();
                        cnct.setCn(newnm);
                        cnct.setLink(altrep);
                        ui.getIcalCallback().addContact(cnct);
                    }
                    if (ev.removeContact(evcnct)) {
                        cte.addRemovedValue(evcnct);
                    }
                    ev.addContact(cnct);
                    cte.addAddedValue(cnct);
                    return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwContact(org.bedework.calfacade.BwContact) 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 17 with BwString

use of org.bedework.calfacade.BwString 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 18 with BwString

use of org.bedework.calfacade.BwString 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 19 with BwString

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

the class EntityBuilder method restoreBwString.

private BwStringBase restoreBwString(final boolean longString) throws CalFacadeException {
    final BwStringBase sb;
    if (longString) {
        sb = new BwLongString();
    } else {
        sb = new BwString();
    }
    sb.setLang(getString(PropertyInfoIndex.LANG));
    sb.setValue(getString(PropertyInfoIndex.VALUE));
    return sb;
}
Also used : BwLongString(org.bedework.calfacade.BwLongString) BwStringBase(org.bedework.calfacade.base.BwStringBase) BwString(org.bedework.calfacade.BwString)

Example 20 with BwString

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

the class AlarmFieldRule method field.

@Override
public void field(final String name) throws Throwable {
    if (skippedNames.contains(name)) {
        return;
    }
    BwString str = null;
    if (top() instanceof BwString) {
        str = (BwString) pop();
    }
    final BwAlarm ent = (BwAlarm) top();
    if (ownedEntityTags(ent, name)) {
        return;
    }
    if (name.equals("trigger")) {
        ent.setTrigger(stringFld());
        return;
    }
    if (name.equals("duration")) {
        ent.setDuration(stringFld());
        return;
    }
    if (name.equals("repeat")) {
        ent.setRepeat(intFld());
        return;
    }
    if (name.equals("attach")) {
        ent.setAttach(stringFld());
        return;
    }
    if (name.equals("expired")) {
        ent.setExpired(booleanFld());
        return;
    }
    if (name.equals("alarmType")) {
        ent.setAlarmType(intFld());
        return;
    }
    if (name.equals("triggerStart")) {
        ent.setTriggerStart(booleanFld());
        return;
    }
    if (name.equals("triggerDateTime")) {
        ent.setTriggerDateTime(booleanFld());
        return;
    }
    if (name.equals("triggerTime")) {
        // ignore
        return;
    }
    if (name.equals("repeatCount")) {
        ent.setRepeatCount(intFld());
        return;
    }
    if (name.equals("previousTrigger")) {
        // ignore
        return;
    }
    if (name.equals("byteSize")) {
        ent.setByteSize(intFld());
        return;
    }
    unknownTag(name);
}
Also used : BwString(org.bedework.calfacade.BwString) BwAlarm(org.bedework.calfacade.BwAlarm)

Aggregations

BwString (org.bedework.calfacade.BwString)30 BwEvent (org.bedework.calfacade.BwEvent)14 BwCategory (org.bedework.calfacade.BwCategory)11 BwContact (org.bedework.calfacade.BwContact)11 BwLocation (org.bedework.calfacade.BwLocation)9 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)9 BwAttendee (org.bedework.calfacade.BwAttendee)7 BwXproperty (org.bedework.calfacade.BwXproperty)6 EventInfo (org.bedework.calfacade.svc.EventInfo)6 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)6 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)5 Period (net.fortuna.ical4j.model.Period)4 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)4 BwDateTime (org.bedework.calfacade.BwDateTime)4 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)4 BwOrganizer (org.bedework.calfacade.BwOrganizer)4 BwRequestStatus (org.bedework.calfacade.BwRequestStatus)4 BwStringBase (org.bedework.calfacade.base.BwStringBase)4 BwLongString (org.bedework.calfacade.BwLongString)3 Parameter (net.fortuna.ical4j.model.Parameter)2