use of org.bedework.caldav.util.sharing.InviteReplyType 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.caldav.util.sharing.InviteReplyType in project bw-calendar-engine by Bedework.
the class Sharing method updateSharingStatus.
/* ====================================================================
* Private methods
* ==================================================================== */
/* This requires updating the shared calendar to reflect the accept/decline
* status
*/
private boolean updateSharingStatus(final String sharerHref, final String path, final InviteReplyType reply, final Holder<AccessType> access) throws CalFacadeException {
pushPrincipal(sharerHref);
try {
final BwCalendar col = getCols().get(path);
if (col == null) {
// Bad hosturl?
throw new CalFacadeForbidden(CalFacadeException.shareTargetNotFound);
}
/* See if we have an outstanding invite for this user */
final QName qn = new QName(AppleServerTags.inviteNotification.getNamespaceURI(), AppleServerTags.inviteNotification.getLocalPart() + reply.getInReplyTo());
final String pname = NamespaceAbbrevs.prefixed(qn);
final String xmlInvite = col.getProperty(pname);
if (xmlInvite == null) {
// No invite
if (debug) {
trace("No invite notification on collection with name: " + pname);
}
throw new CalFacadeForbidden(CalFacadeException.noInvite);
}
/* Remove the invite */
col.setProperty(pname, null);
/* Get the invite property and locate and update this sharee */
final InviteType invite = getInviteStatus(col);
UserType uentry = null;
final String invitee = getSvc().getDirectories().normalizeCua(reply.getHref());
if (invite != null) {
uentry = invite.finduser(invitee);
}
if (uentry == null) {
if (debug) {
trace("Cannot find invitee: " + invitee);
}
throw new CalFacadeForbidden(CalFacadeException.noInviteeInUsers);
}
if (reply.testAccepted()) {
uentry.setInviteStatus(AppleServerTags.inviteAccepted);
} else {
uentry.setInviteStatus(AppleServerTags.inviteDeclined);
}
access.value = uentry.getAccess();
col.setProperty(NamespaceAbbrevs.prefixed(AppleServerTags.invite), invite.toXml());
getCols().update(col);
/* Now send the sharer the reply as a notification */
final NotificationType note = new NotificationType();
note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
final InviteReplyType irt = (InviteReplyType) reply.clone();
note.setNotification(irt);
/* Fill in the summary (the sharer's summary) on the reply. */
irt.setSummary(reply.getSummary());
getSvc().getNotificationsHandler().add(note);
return irt.testAccepted();
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
} finally {
popPrincipal();
}
}
Aggregations