use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Sharing method unsubscribe.
@Override
public void unsubscribe(final BwCalendar col) throws CalFacadeException {
if (!col.getInternalAlias()) {
return;
}
final BwCalendar shared = getCols().resolveAlias(col, true, false);
if (shared == null) {
// Gone or no access - nothing to do now.
return;
}
final String sharerHref = shared.getOwnerHref();
final BwPrincipal sharee = getSvc().getPrincipal();
pushPrincipal(sharerHref);
try {
/* Get the invite property and locate and update this sharee */
final InviteType invite = getInviteStatus(shared);
UserType uentry = null;
final String invitee = principalToCaladdr(sharee);
if (invite != null) {
uentry = invite.finduser(invitee);
}
if (uentry == null) {
if (debug) {
trace("Cannot find invitee: " + invitee);
}
return;
}
uentry.setInviteStatus(AppleServerTags.inviteDeclined);
shared.setProperty(NamespaceAbbrevs.prefixed(AppleServerTags.invite), invite.toXml());
getCols().update(shared);
/* At this stage we need a message to notify the sharer -
change notification.
The name of the alias is the uid of the original invite
*/
final NotificationType note = new NotificationType();
note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
// Create a reply object.
final InviteReplyType reply = new InviteReplyType();
reply.setHref(principalToCaladdr(sharee));
reply.setAccepted(false);
reply.setHostUrl(shared.getPath());
reply.setInReplyTo(col.getName());
reply.setSummary(col.getSummary());
note.setNotification(reply);
getSvc().getNotificationsHandler().add(note);
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
} finally {
popPrincipal();
}
/*
final BwPrincipal pr = caladdrToPrincipal(getPrincipalHref());
if (pr != null) {
pushPrincipal(shared.getOwnerHref());
NotificationType n = null;
try {
n = findInvite(pr, shared.getPath());
} finally {
popPrincipal();
}
if (n != null) {
InviteNotificationType in = (InviteNotificationType)n.getNotification();
Holder<AccessType> access = new Holder<AccessType>();
// Create a dummy reply object.
InviteReplyType reply = new InviteReplyType();
reply.setHref(getPrincipalHref());
reply.setAccepted(false);
reply.setHostUrl(shared.getPath());
reply.setInReplyTo(in.getUid());
updateSharingStatus(shared.getOwnerHref(), shared.getPath(), reply, access);
}
}
*/
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Sharing method removeAccess.
private boolean removeAccess(final BwCalendar col, final String principalHref) throws CalFacadeException {
Acl acl = col.getCurrentAccess().getAcl();
try {
if (Util.isEmpty(acl.getAces())) {
return false;
}
final BwPrincipal pr = caladdrToPrincipal(principalHref);
acl = removeAccess(acl, pr.getAccount(), pr.getKind());
if (acl == null) {
// no change
return false;
}
getSvc().changeAccess(col, acl.getAces(), true);
if (!col.getInternalAlias()) {
return true;
}
final BwCalendar target = getSvc().getCalendarsHandler().resolveAlias(col, false, false);
if (target == null) {
return false;
}
/* Switch identity to the sharee then reget the handler
* and do the share
*/
pushPrincipal(target.getOwnerHref());
try {
return removeAccess(target, principalHref);
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
} finally {
popPrincipal();
}
} catch (final AccessException ae) {
throw new CalFacadeException(ae);
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Users method remove.
@Override
public void remove(final BwPrincipal pr) throws CalFacadeException {
final String userRoot = getSvc().getPrincipalInfo().getCalendarHomePath(pr);
/* views */
final Collection<BwView> views = getSvc().getViewsHandler().getAll(pr);
for (final BwView view : views) {
getSvc().getViewsHandler().remove(view);
}
/* Set default calendar to null so we don't get blocked. */
final BwPreferences prefs = getSvc().getPrefsHandler().get(pr);
if (prefs != null) {
prefs.setDefaultCalendarPath(null);
getSvc().getPrefsHandler().update(prefs);
}
/* collections and user home */
final BwCalendar home = getSvc().getCalendarsHandler().get(userRoot);
if (home != null) {
((Calendars) getCols()).delete(home, true, true, false, true);
}
/* Remove preferences */
getSvc().getPrefsHandler().delete(prefs);
getCal().delete(pr);
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Notifications method find.
@Override
public NotificationType find(final String name) throws CalFacadeException {
final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return null;
}
final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", name));
if (noteRsrc == null) {
return null;
}
return makeNotification(noteRsrc);
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Notifications method remove.
@Override
public void remove(final String principalHref, final String name) throws CalFacadeException {
if (name == null) {
return;
}
final BwCalendar ncol = getCols().getSpecial(principalHref, BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return;
}
final String path = Util.buildPath(false, ncol.getPath(), "/", name);
getSvc().getResourcesHandler().delete(path);
}
Aggregations