use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class AttendeePropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
ChangeTableEntry cte = ui.getCte();
BwEvent ev = ui.getEvent();
Set<BwAttendee> atts = ev.getAttendees();
AttendeePropType pr = (AttendeePropType) ui.getProp();
String attUri = ui.getIcalCallback().getCaladdr(ui.getIcalCallback().getPrincipal().getPrincipalRef());
/* Must have an organizer propery */
BwOrganizer org = ev.getOrganizer();
if (org == null) {
return new UpdateResult("No organizer for attendee update");
}
boolean isOrganizer = attUri.equals(org.getOrganizerUri());
if (!isOrganizer) {
/* Options are pretty limited here - change partstat only to our own entry
*/
if (!pr.getCalAddress().equals(attUri)) {
return new UpdateResult("Cannot update other attendees");
}
if (ui.isAdd() || ui.isRemove()) {
return new UpdateResult("Cannot add or remove attendees");
}
if (!ui.isChange()) {
// Nothing to do
return UpdateResult.getOkResult();
}
// return new UpdateResult("unimplemented - attendee update");
throw new WebdavException("Unimplemented - attendees update");
}
if (ui.isAdd()) {
if (!Util.isEmpty(atts)) {
for (BwAttendee att : atts) {
if (att.getAttendeeUri().equals(pr.getCalAddress())) {
// Already there
return UpdateResult.getOkResult();
}
}
}
BwAttendee newAtt = makeAttendee(pr);
ev.addAttendee(newAtt);
cte.addAddedValue(newAtt);
return UpdateResult.getOkResult();
}
if (ui.isRemove()) {
if (Util.isEmpty(atts)) {
// Nothing to remove
return UpdateResult.getOkResult();
}
BwAttendee remAtt = makeAttendee(pr);
if (ev.removeAttendee(remAtt)) {
cte.addRemovedValue(remAtt);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
// Change a value
if (Util.isEmpty(atts)) {
// Nothing to change
return new UpdateResult("No comment to change");
}
for (BwAttendee att : atts) {
if (att.getAttendeeUri().equals(pr.getCalAddress())) {
// Found
throw new WebdavException("Unimplemented - attendees update");
// return UpdateResult.getOkResult();
}
}
}
return UpdateResult.getOkResult();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException 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);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException 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.webdav.servlet.shared.WebdavException 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.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class Filters method match.
private boolean match(final FilterBase f, final BwEvent ev, final String userHref) throws CalFacadeException {
if (f == null) {
return true;
}
if (debug) {
debug("match " + f);
}
if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
boolean itsAnd = (f instanceof AndFilter);
for (FilterBase flt : f.getChildren()) {
if (match(flt, ev, userHref)) {
if (!itsAnd) {
// Success for OR
if (debug) {
debug("match true");
}
return true;
}
} else if (itsAnd) {
debug("match true");
return false;
}
}
// For AND all matched, for OR nothing matched
debug("match " + itsAnd);
return itsAnd;
}
if (f instanceof EntityTimeRangeFilter) {
// Matched in db query
return true;
}
if (!(f instanceof PropertyFilter)) {
/* We assume we can't handle this one as a query.
*/
throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
PropertyFilter pf = (PropertyFilter) f;
BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
if (pi == null) {
throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
}
String fieldName = pi.getDbFieldName();
boolean param = pi.getParam();
if (param) {
BwIcalPropertyInfoEntry parentPi = BwIcalPropertyInfo.getPinfo(pf.getParentPropertyIndex());
fieldName = parentPi.getDbFieldName() + "." + fieldName;
}
try {
if (pf instanceof BwCategoryFilter) {
return traceMatch(pf.match(ev, userHref));
}
if (f instanceof PresenceFilter) {
return traceMatch(matchPresence(pf.getPropertyIndex(), ev, userHref));
}
if (pf instanceof TimeRangeFilter) {
return traceMatch(match((TimeRangeFilter) pf, ev));
}
if (pf instanceof BwObjectFilter) {
return traceMatch(pf.match(ev, userHref));
}
} catch (WebdavException wde) {
throw new CalFacadeException(wde);
}
throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
Aggregations