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