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);
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations