use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class UserRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
BwPrincipal entity = (BwPrincipal) pop();
globals.counts[globals.users]++;
try {
if (entity.getPrincipalRef() == null) {
// Pre 3.5?
globals.setPrincipalHref(entity);
}
globals.principalsTbl.put(entity);
entity.setId(CalFacadeDefs.unsavedItemKey);
// trace("Restore user " + entity);
if (globals.rintf != null) {
globals.rintf.restorePrincipal(entity);
}
} catch (Throwable t) {
throw new Exception(t);
}
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class EventRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
if (!(top() instanceof EventInfo)) {
warn("Top is not an event");
warn(top().toString());
return;
}
if (globals.entityError) {
warn("Not restoring event because of previous error");
warn(top().toString());
return;
}
EventInfo ei = (EventInfo) top();
BwEvent entity = ei.getEvent();
if (entity instanceof BwEventProxy) {
entity = ((BwEventProxy) entity).getRef();
}
boolean override = (entity instanceof BwEventAnnotation) && (((BwEventAnnotation) entity).getOverride());
boolean alias = (entity instanceof BwEventAnnotation) && !override;
globals.counts[globals.events]++;
if ((globals.counts[globals.events] % 100) == 0) {
info("Restore event # " + globals.counts[globals.events]);
}
if (!override) {
fixSharableEntity(entity, "Event");
}
if ((entity.getEntityType() == IcalDefs.entityTypeTodo) && entity.getNoStart() && (entity.getEndType() == StartEndComponent.endTypeNone)) {
/* The end date should be sometime in the distant future. If it isn't make
* it so.
* A bug was creating essentially one day events.
*/
Date sdt = BwDateTimeUtil.getDate(entity.getDtstart());
Date edt = BwDateTimeUtil.getDate(entity.getDtend());
// about 9 years of millis
long years9 = 52L * 7L * 24L * 60L * 60L * 1000L * 9L;
if ((edt.getTime() - sdt.getTime()) < years9) {
// about 10 years
Dur years10 = new Dur(520);
net.fortuna.ical4j.model.Date newDt = new net.fortuna.ical4j.model.Date(sdt.getTime());
DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.Date(years10.getTime(newDt)));
entity.setDtend(BwDateTime.makeBwDateTime(dtEnd));
warn("Fixed task uid=" + entity.getUid());
}
}
// Out here for debugging
BwEvent target = null;
BwEvent master = null;
try {
if (override) {
pop();
if (!(top() instanceof EventInfo)) {
warn("Not restoring event because of previous error");
warn(top().toString());
return;
}
if (debug) {
trace("Add override to event ");
}
EventInfo masterei = (EventInfo) top();
masterei.addOverride(ei);
return;
}
if (alias) {
BwEventAnnotation ann = (BwEventAnnotation) entity;
/* It's an alias, save an entry in the alias table then remove the dummy target.
* We'll update them all at the end
*/
// XXX Never did get on table globals.aliasTbl.put(ann);
target = ann.getTarget();
BwPrincipal annOwner = globals.getPrincipal(ann.getOwnerHref());
BwEvent ntarget = globals.rintf.getEvent(annOwner, target.getColPath(), target.getRecurrenceId(), target.getUid());
if (ntarget == null) {
error("Unknown target " + target);
}
ann.setTarget(ntarget);
master = ann.getMaster();
if (master.equals(target)) {
ann.setMaster(ntarget);
} else {
BwEvent nmaster = globals.rintf.getEvent(annOwner, master.getColPath(), master.getRecurrenceId(), master.getUid());
if (nmaster == null) {
error("Unknown master " + master);
}
ann.setMaster(nmaster);
}
}
boolean ok = true;
if ((entity.getUid() == null) || (entity.getUid().length() == 0)) {
error("Unable to save event " + entity + ". Has no guid.");
ok = false;
}
if (entity.getColPath() == null) {
error("Unable to save event " + entity + ". Has no calendar.");
ok = false;
}
BwEvent ev = ei.getEvent();
if (ok && (globals.rintf != null) && globals.onlyUsersMap.check(ev)) {
globals.currentUser = globals.getPrincipal(ev.getOwnerHref());
globals.rintf.restoreEvent(ei);
}
} catch (CalFacadeException cfe) {
if (cfe.getMessage().equals(CalFacadeException.noRecurrenceInstances)) {
error("Event has no recurrence instances - not restored." + entity.getUid() + "\n" + atLine());
} else {
error("Unable to save event " + entity.getUid() + "\n" + atLine());
cfe.printStackTrace();
}
} catch (Throwable t) {
error("Unable to save event " + entity.getUid() + "\n" + atLine());
t.printStackTrace();
}
pop();
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class MemberRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
/* Top should be the principal info, underneath is the actual entity -
*/
PrincipalHref oi = (PrincipalHref) pop();
try {
if (oi.prefix == null) {
error("Unable to handle principal type " + oi.getKind());
}
oi.href = Util.buildPath(false, oi.prefix, "/", oi.account);
} catch (Throwable t) {
error("Unable to get user principal root", t);
return;
}
BwPrincipal pr = globals.principalsTbl.get(oi);
if (top() instanceof BwGroup) {
BwGroup gr = (BwGroup) top();
if (pr == null) {
if (gr instanceof BwAdminGroup) {
ArrayList<PrincipalHref> m = globals.adminGroupMembers.get(gr.getAccount());
if (m == null) {
m = new ArrayList<PrincipalHref>();
globals.adminGroupMembers.put(gr.getAccount(), m);
}
m.add(oi);
} else {
error("Cannot handle group " + gr);
}
return;
}
gr.addGroupMember(pr);
return;
}
error("Unknown class for member " + top());
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class OwnerRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
error("OwnerRule called");
BwPrincipal p = doPrincipal();
if (top() instanceof OwnerUidKey) {
OwnerUidKey key = (OwnerUidKey) top();
key.setOwnerHref(p.getPrincipalRef());
globals.inOwnerKey = false;
return;
}
if (top() instanceof BwAdminGroup) {
BwAdminGroup ag = (BwAdminGroup) top();
if (name.equals("owner")) {
ag.setOwnerHref(p.getPrincipalRef());
} else if (name.equals("owner-key")) {
// PRE3.5
ag.setOwnerHref(p.getPrincipalRef());
} else {
ag.setGroupOwnerHref(p.getPrincipalRef());
}
globals.inOwnerKey = false;
return;
}
BwOwnedDbentity o = null;
if (top() == null) {
error("Null stack top when setting owner. Match: " + getDigester().getMatch());
return;
}
if (top() instanceof EventInfo) {
o = ((EventInfo) top()).getEvent();
} else if (!(top() instanceof BwOwnedDbentity)) {
if (top() instanceof BwOrganizer) {
// No owner now
} else if (top() instanceof BwView) {
// No owner now
} else if (top() instanceof SkipThis) {
} else {
// We expect organizer in old data
warn("top() is not BwOwnedDbentity:" + top().getClass().getCanonicalName());
warn(" match: " + getDigester().getMatch());
}
globals.inOwnerKey = false;
return;
} else {
o = (BwOwnedDbentity) top();
}
o.setOwnerHref(p.getPrincipalRef());
globals.inOwnerKey = false;
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class CreatorRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
error("CreatorRule called");
BwPrincipal p = doPrincipal();
BwShareableDbentity o;
if (top() instanceof EventInfo) {
o = ((EventInfo) top()).getEvent();
} else {
o = (BwShareableDbentity) top();
}
if (o == null) {
error("Null stack top when setting creator");
return;
}
o.setCreatorHref(p.getPrincipalRef());
globals.inOwnerKey = false;
}
Aggregations