use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class DumpSystem method doDump.
/**
* Dump everything owned by this principal
*
* @throws CalFacadeException on error
*/
public void doDump() throws CalFacadeException {
try {
makeDir(Defs.collectionsDirName, false);
final CalendarsI cols = getSvc().getCalendarsHandler();
final BwCalendar usercal = cols.get(getSysRoots().getUserCalendarRoot());
if (usercal == null) {
warn("Unable to fetch user calendar root");
return;
}
dumpCol(usercal, false);
} finally {
popPath();
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Restore method createNewSystem.
private void createNewSystem() throws Throwable {
// Create the public user.
final BwPrincipal pu = BwPrincipal.makeUserPrincipal();
pu.setAccount(BwPrincipal.publicUser);
globals.setPrincipalHref(pu);
globals.rintf.restorePrincipal(pu);
// Create the root user.
final BwPrincipal rootUser = BwPrincipal.makeUserPrincipal();
rootUser.setAccount(rootId);
globals.setPrincipalHref(rootUser);
globals.rintf.restorePrincipal(rootUser);
// Create the an authuser entry for the root user.
final BwAuthUser au = new BwAuthUser();
au.setUserHref(rootUser.getPrincipalRef());
au.setUsertype(UserAuth.allAuth);
au.setPrefs(BwAuthUserPrefs.makeAuthUserPrefs());
globals.rintf.restoreAuthUser(au);
// Create a group for all public admin groups
final BwAdminGroup g = new BwAdminGroup();
final String publicAdminGroupsAccount = // XXX Put into config
"publicAdminGroups";
g.setAccount(publicAdminGroupsAccount);
g.setGroupOwnerHref(pu.getPrincipalRef());
g.setOwnerHref(pu.getPrincipalRef());
if (!globals.onlyUsersMap.check(g.getGroupOwnerHref())) {
g.setGroupOwnerHref(globals.getPublicUser().getPrincipalRef());
}
globals.rintf.restoreAdminGroup(g);
// Create the public root.
final Collection<Privilege> privs = new ArrayList<>();
privs.add(Privileges.makePriv(PrivilegeDefs.privRead));
final Collection<Ace> aces = new ArrayList<>();
aces.add(Ace.makeAce(AceWho.other, privs, null));
privs.clear();
privs.add(Privileges.makePriv(PrivilegeDefs.privRead));
privs.add(Privileges.makePriv(PrivilegeDefs.privWriteContent));
final AceWho who = AceWho.getAceWho(publicAdminGroupsAccount, WhoDefs.whoTypeGroup, false);
aces.add(Ace.makeAce(who, privs, null));
makeCal(null, pu, BwCalendar.calTypeFolder, RestoreGlobals.getBasicSyspars().getPublicCalendarRoot(), new String(new Acl(aces).encode()));
// Create the user root.
privs.clear();
privs.add(Privileges.makePriv(PrivilegeDefs.privAll));
aces.clear();
aces.add(Ace.makeAce(AceWho.owner, privs, null));
final BwCalendar userRoot = makeCal(null, pu, BwCalendar.calTypeFolder, RestoreGlobals.getBasicSyspars().getUserCalendarRoot(), new String(new Acl(aces).encode()));
makeUserHome(userRoot, pu);
makeUserHome(userRoot, rootUser);
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CalendarRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
final BwCalendar entity = (BwCalendar) pop();
globals.counts[globals.collections]++;
if ((globals.counts[globals.collections] % 100) == 0) {
info("Restore calendar # " + globals.counts[globals.collections]);
}
fixSharableEntity(entity, "Calendar");
if (!entity.getTombstoned()) {
if (entity.getExternalSub()) {
globals.counts[globals.externalSubscriptions]++;
globals.externalSubs.add(AliasInfo.getExternalSubInfo(entity.getPath(), entity.getAliasUri(), entity.getPublick(), entity.getOwnerHref()));
} else if (entity.getInternalAlias() && !entity.getPublick()) {
final String target = entity.getInternalAliasPath();
final AliasInfo ai = new AliasInfo(entity.getPath(), target, entity.getPublick(), entity.getOwnerHref());
AliasEntry ae = globals.aliasInfo.get(target);
if (ae == null) {
ae = new AliasEntry();
ae.setTargetPath(target);
globals.aliasInfo.put(target, ae);
}
ae.getAliases().add(ai);
globals.counts[globals.aliases]++;
}
}
try {
if (globals.rintf != null) {
/* If the parent is null then this should be one of the root calendars,
*/
final String parentPath = entity.getColPath();
if (parentPath == null) {
// Ensure root
globals.rintf.saveRootCalendar(entity);
} else {
globals.rintf.addCalendar(entity);
}
}
} catch (final Throwable t) {
throw new Exception(t);
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class OutScheduler method getOutboxEvents.
private Collection<EventInfo> getOutboxEvents() throws CalFacadeException {
BwCalendar outbox = getSvc().getCalendarsHandler().getSpecial(BwCalendar.calTypeOutbox, false);
if (outbox == null) {
return null;
}
Collection<EventInfo> eis = getSvc().getEventsHandler().getEvents(outbox, null, null, null, // retrieveList
null, BwIndexer.DeletedState.noDeleted, RecurringRetrievalMode.overrides);
if (Util.isEmpty(eis)) {
if (debug) {
trace("autoSchedule: no outbox events for " + getSvc().getPrincipal().getPrincipalRef());
}
return null;
}
return eis;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class ImplicitSchedulingHandler method implicitSchedule.
@Override
public void implicitSchedule(final EventInfo ei, final boolean noInvites) throws CalFacadeException {
UpdateResult uer = ei.getUpdResult();
if (debug) {
dump(uer);
}
BwEvent ev = ei.getEvent();
boolean organizerSchedulingObject = ev.getOrganizerSchedulingObject();
boolean attendeeSchedulingObject = ev.getAttendeeSchedulingObject();
if (ev.getSuppressed()) {
if (!Util.isEmpty(ei.getOverrides())) {
for (EventInfo oei : ei.getOverrides()) {
uer = oei.getUpdResult();
if (debug) {
dump(uer);
}
BwEvent oev = oei.getEvent();
if (oev.getOrganizerSchedulingObject()) {
organizerSchedulingObject = true;
}
if (oev.getAttendeeSchedulingObject()) {
attendeeSchedulingObject = true;
}
}
}
}
if (!organizerSchedulingObject && !attendeeSchedulingObject) {
// Not a scheduling event
if (debug) {
trace("No a scheduling object: just return");
}
return;
}
if (ev.getOrganizer() == null) {
throw new CalFacadeBadRequest(CalFacadeException.missingEventProperty);
}
if (ev.getOriginator() == null) {
ev.setOriginator(ev.getOrganizer().getOrganizerUri());
}
if (uer.reply) {
int meth;
if (ei.getReplyAttendeeURI() != null) {
meth = ScheduleMethods.methodTypeRefresh;
} else {
meth = ScheduleMethods.methodTypeReply;
}
ev.setScheduleMethod(meth);
uer.schedulingResult = attendeeRespond(ei, meth);
return;
}
if (uer.deleting) {
if (organizerSchedulingObject) {
// if (schedMethod == Icalendar.methodTypeCancel) {
// /* We already canceled this one */
// return;
// }
ev.setScheduleMethod(ScheduleMethods.methodTypeCancel);
} else {
// Reply from attendee setting partstat
ev.setScheduleMethod(ScheduleMethods.methodTypeReply);
}
} else {
ev.setScheduleMethod(ScheduleMethods.methodTypeRequest);
}
if (!noInvites) {
uer.schedulingResult = schedule(ei, ei.getReplyAttendeeURI(), uer.fromAttUri, false);
}
if (!uer.adding && !Util.isEmpty(uer.deletedAttendees)) {
/* Send cancel to removed attendees */
for (BwAttendee att : uer.deletedAttendees) {
if (Util.compareStrings(att.getPartstat(), IcalDefs.partstats[IcalDefs.partstatDeclined]) == 0) {
// Already declined - send nothing
continue;
}
/* Clone is adequate here. For a CANCEL we just send either the master
* or the particular instance.
*/
BwEvent cncl = (BwEvent) ev.clone();
cncl.setAttendees(null);
cncl.addAttendee((BwAttendee) att.clone());
cncl.setRecipients(null);
cncl.addRecipient(att.getAttendeeUri());
cncl.setScheduleMethod(ScheduleMethods.methodTypeCancel);
cncl.setOrganizerSchedulingObject(true);
cncl.setAttendeeSchedulingObject(false);
EventInfo cei = new EventInfo(cncl);
ScheduleResult cnclr = schedule(cei, null, null, false);
if (debug) {
trace(cnclr.toString());
}
}
}
if (ei.getInboxEventName() != null) {
// Delete the given event from the inbox.
EventsI events = getSvc().getEventsHandler();
BwCalendar inbox = getSvc().getCalendarsHandler().getSpecial(BwCalendar.calTypeInbox, true);
final EventInfo inboxei = events.get(inbox.getPath(), ei.getInboxEventName());
if (inboxei != null) {
events.delete(inboxei, false);
}
}
}
Aggregations