use of org.bedework.calsvci.EventsI.RealiasResult in project bw-calendar-engine by Bedework.
the class ProcessRealias method doRealias.
private int doRealias(final EventInfo ei, final String fromHref, final BwXproperty xp, final boolean add, final boolean remove) throws Throwable {
final BwEvent ev = ei.getEvent();
int updated = 0;
boolean changed = false;
if (!add) {
// We need to remove the from alias
boolean found = false;
for (final BwXproperty xpi : ev.getXproperties(BwXproperty.bedeworkAlias)) {
if (xpi.getValue().equals(fromHref)) {
ev.removeXproperty(xpi);
found = true;
changed = true;
break;
}
}
if (!found) {
warn("Unable to find " + fromHref);
}
}
if (!remove) {
// Need to add a new one.
ev.addXproperty(xp);
changed = true;
}
final RealiasResult resp = getSvci().getEventsHandler().reAlias(ei.getEvent());
if (resp.getStatus() != ok) {
warn("Status from reAlias was " + resp.getStatus() + " message was " + resp.getMessage());
return 0;
}
if (!add) {
// Remove all the categories for the from alias
final Set<BwCategory> fromCats = getCols().getCategorySet(fromHref);
if (!Util.isEmpty(fromCats) && !Util.isEmpty(ev.getCategories())) {
for (final BwCategory cat : fromCats) {
if (ev.getCategories().remove(cat)) {
changed = true;
}
}
}
}
/* Now we need to adjust for the new alias
*/
final Set<BwCategory> cats = resp.getCats();
if (!Util.isEmpty(cats)) {
for (final BwCategory cat : cats) {
ev.addCategory(cat);
}
changed = true;
}
ei.clearChangeset();
final EventInfo.UpdateResult ur = getSvci().getEventsHandler().update(ei, true);
if (ur.hasChanged) {
updated++;
}
if (!Util.isEmpty(ei.getOverrides())) {
for (final EventInfo ovei : ei.getOverrides()) {
updated += doRealias(ovei, fromHref, xp, add, remove);
}
}
return updated;
}
Aggregations