use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class ProcessRealias method realiasEvents.
private boolean realiasEvents() throws Throwable {
boolean add = false;
boolean remove = false;
BwXproperty xp = null;
/* Expect from (possibly quoted)
* to (possibly quoted)
*/
try {
open();
final String fromHref = getAliasPath();
if (fromHref == null) {
return false;
}
final String wd = word();
if (wd == null) {
return false;
}
if ("remove".equals(wd)) {
remove = true;
} else {
if ("add".equals(wd)) {
add = true;
} else if ("replace".equals(wd)) {
remove = true;
} else {
error("Expect add | remove | replace");
return false;
}
final BwCalendar col = getCal();
if (col == null) {
return false;
}
/* At the moment an alias is represented by an x-property with
the form:
X-BEDEWORK-ALIAS; \
X-BEDEWORK-PARAM-DISPLAYNAME=Jobs;\
X-BEDEWORK-PARAM-PATH=/public/aliases/Browse By Topic/Jobs;\
X-BEDEWORK-PARAM-ALIASPATH=/public/cals/MainCal:\
/user/agrp_calsuite-MainCampus/Browse By Topic/Jobs"
That is - it appears the displayname comes from the top level
the path is what it points to
the aliaspath is the path of the final target
the value is the path of the alias itself.
*/
final BwCalendar aliasTarget = getAliasTarget(col);
xp = new BwXproperty();
xp.setName("X-BEDEWORK-ALIAS");
xp.setPars("X-BEDEWORK-PARAM-DISPLAYNAME=" + col.getName() + ";X-BEDEWORK-PARAM-PATH=" + col.getAliasUri().substring(BwCalendar.internalAliasUriPrefix.length()) + ";X-BEDEWORK-PARAM-ALIASPATH=" + aliasTarget.getPath());
xp.setValue(col.getPath());
}
final FilterBase fltr = parseQuery("topical_area=\"\t" + fromHref + "\"");
if (fltr == null) {
return false;
}
close();
/* Now we need to process the stuff in batches */
open();
final BwIndexer idx = getIndexer();
final SearchResult sr = idx.search(null, false, fltr, null, null, null, null, batchSize, includeDeleted, RecurringRetrievalMode.entityOnly);
if (sr.getFound() == 0) {
warn("No events found");
return false;
}
for (; ; ) {
final List<SearchResultEntry> sres = idx.getSearchResult(sr, BwIndexer.Position.next, PrivilegeDefs.privAny);
if (Util.isEmpty(sres)) {
break;
}
int updated = 0;
for (final SearchResultEntry sre : sres) {
final Object o = sre.getEntity();
if (!(o instanceof EventInfo)) {
warn("Unhandled entity " + o.getClass());
continue;
}
EventInfo ei = (EventInfo) o;
/* Fetch the persistent version
*/
final String colPath = ei.getEvent().getColPath();
final String name = ei.getEvent().getName();
ei = getEvents().get(colPath, name);
if (ei == null) {
warn("Unable to retrieve persistent copy of " + colPath + " " + name);
continue;
}
updated += doRealias(ei, fromHref, xp, add, remove);
if ((updated % 10) == 0) {
info("done " + updated);
}
}
info("Total updated: " + updated);
}
return true;
} finally {
close();
}
}
use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class XbwContactPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xcontacts = ev.getXproperties(BwXproperty.xBedeworkContact);
final Set<BwContact> contacts = ev.getContacts();
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = ((TextPropertyType) ui.getProp()).getText();
final BwString cstr = new BwString(lang, xval);
if (ui.isRemove()) {
if (Util.isEmpty(xcontacts)) {
// Nothing to remove
return UpdateResult.getOkResult();
}
for (final BwXproperty xp : xcontacts) {
if (!xp.getValue().equals(xval)) {
continue;
}
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
/* Do we have a corresponding contact */
for (final BwContact c : contacts) {
if (c.getCn().equals(cstr)) {
ev.removeContact(c);
cte.addRemovedValue(c);
break;
}
}
return UpdateResult.getOkResult();
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
for (final BwXproperty xp : xcontacts) {
if (xp.getValue().equals(xval)) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
}
}
/* Add the xprop or a contact */
if (!checkContact(ui, ev, contacts, lang, xval)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addAddedValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
for (final BwXproperty xp : xcontacts) {
if (xp.getValue().equals(xval)) {
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
if (!checkContact(ui, ev, contacts, nlang, nxval)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
ev.addXproperty(nxp);
cte.addAddedValue(nxp);
}
return UpdateResult.getOkResult();
}
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class XbwLocPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xlocs = ev.getXproperties(xBedeworkLocation);
// Should only be one or zero
final BwXproperty xloc;
if (Util.isEmpty(xlocs)) {
xloc = null;
} else {
xloc = xlocs.get(0);
}
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = ((TextPropertyType) ui.getProp()).getText();
final BaseParameterType keyParam = XcalUtil.findParam(ui.getProp(), XcalTags.xBedeworkLocationKey);
final String keyName;
if (keyParam != null) {
keyName = ((TextParameterType) keyParam).getText();
} else {
keyName = null;
}
final BwLocation evLoc = ev.getLocation();
if (ui.isRemove()) {
if (xlocs == null) {
// Nothing to remove
return UpdateResult.getOkResult();
}
// TODO - match values?
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
if (evLoc != null) {
ev.setLocation(null);
cte.addRemovedValue(evLoc);
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (xloc != null) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
}
if (!checkLocation(ui, ev, lang, xval, null)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addAddedValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
if (xloc == null) {
return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot change");
}
if (CalFacadeUtil.cmpObjval(xval, xloc.getValue()) != 0) {
return new UpdateResult("Values don't match for update to " + ui.getPropName());
}
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
if (!checkLocation(ui, ev, nlang, nxval, keyName)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
if (keyName != null) {
nxp.getParameters().add(new Xpar(XcalTags.xBedeworkLocationKey.getLocalPart(), keyName));
}
ev.addXproperty(nxp);
cte.addAddedValue(nxp);
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class XbwWrapperPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
/* Create an x-property from the selector */
// TODO - do parameters properly
final XBedeworkWrapperPropType wrapper = (XBedeworkWrapperPropType) ui.getProp();
final BwXproperty theProp = new BwXproperty(UpdaterUtil.getWrapperName(wrapper), null, wrapper.getText());
if (ui.isRemove()) {
ev.removeXproperty(theProp);
cte.addRemovedValue(theProp);
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
ev.addXproperty(theProp);
cte.addValue(theProp);
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
ev.removeXproperty(theProp);
cte.addRemovedValue(theProp);
final BwXproperty newProp = new BwXproperty(UpdaterUtil.getWrapperName(wrapper), null, ((XBedeworkWrapperPropType) ui.getUpdprop()).getText());
ev.addXproperty(newProp);
cte.addValue(newProp);
return UpdateResult.getOkResult();
}
return UpdateResult.getOkResult();
}
use of org.bedework.calfacade.BwXproperty 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);
}
}
Aggregations