use of org.bedework.calfacade.exc.CalFacadeException 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.exc.CalFacadeException 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.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class TimeZonesStoreImpl method updateFromTimeZones.
@Override
public UpdateFromTimeZonesInfo updateFromTimeZones(final String colHref, final int limit, final boolean checkOnly, final UpdateFromTimeZonesInfo info) throws CalFacadeException {
/* Versions < 3.3 don't have recurrences fully implemented so we'll
* ignore those.
*
* Fields that could be affected:
* Event start + end
* rdates and exdates
* Recurrence instances
*
*/
if ((info != null) && !(info instanceof UpdateFromTimeZonesInfoInternal)) {
throw new CalFacadeException(CalFacadeException.illegalObjectClass);
}
boolean redo = false;
final UpdateFromTimeZonesInfoInternal iinfo;
if (info != null) {
if (info.getTotalEventsToCheck() == info.getTotalEventsChecked()) {
redo = true;
}
iinfo = (UpdateFromTimeZonesInfoInternal) info;
} else {
iinfo = new UpdateFromTimeZonesInfoInternal();
}
if (redo || (iinfo.names == null)) {
String lastmod = null;
if (redo) {
lastmod = new LastModified(new DateTime(iinfo.lastmod - 5000)).getValue();
}
// Get event ids from db.
iinfo.lastmod = System.currentTimeMillis();
if (iinfo.names == null) {
iinfo.names = new ArrayList<>();
}
iinfo.totalEventsChecked = 0;
iinfo.totalEventsUpdated = 0;
iinfo.iterator = iinfo.names.iterator();
}
for (int i = 0; i < limit; i++) {
if (!iinfo.iterator.hasNext()) {
break;
}
final String name = iinfo.iterator.next();
/*
// See if event needs update
BwPrincipal owner = svci.getUsersHandler().getPrincipal(ikey.getOwnerHref());
BwDateTime start = checkDateTimeForTZ(ikey.getStart(), owner, iinfo);
BwDateTime end = checkDateTimeForTZ(ikey.getEnd(), owner, iinfo);
if ((start != null) || (end != null)) {
CoreEventInfo cei = ((Events)svci.getEventsHandler()).getEvent(ikey);
BwEvent ev = cei.getEvent();
if (cei != null) {
iinfo.updatedList.add(new BwEventKey(ev.getColPath(),
ev.getUid(),
ev.getRecurrenceId(),
ev.getName(),
ev.getRecurring()));
if (!checkOnly) {
if (start != null) {
BwDateTime evstart = ev.getDtstart();
if (debug) {
trace("Updated start: ev.tzid=" + evstart.getTzid() +
" ev.dtval=" + evstart.getDtval() +
" ev.date=" + evstart.getDate() +
" newdate=" + start.getDate());
}
ev.setDtstart(BwDateTime.makeBwDateTime(evstart.getDateType(),
evstart.getDtval(),
start.getDate(),
evstart.getTzid(),
evstart.getFloating()));
}
if (end != null) {
BwDateTime evend = ev.getDtend();
if (debug) {
trace("Updated end: ev.tzid=" + evend.getTzid() +
" ev.dtval=" + evend.getDtval() +
" ev.date=" + evend.getDate() +
" newdate=" + end.getDate());
}
ev.setDtend(BwDateTime.makeBwDateTime(evend.getDateType(),
evend.getDtval(),
end.getDate(),
evend.getTzid(),
evend.getFloating()));
}
EventInfo ei = new EventInfo(ev);
Collection<CoreEventInfo> overrides = cei.getOverrides();
if (overrides != null) {
for (CoreEventInfo ocei: overrides) {
BwEventProxy op = (BwEventProxy)ocei.getEvent();
ei.addOverride(new EventInfo(op));
}
}
svci.getEventsHandler().update(ei, false, null);
iinfo.totalEventsUpdated++;
}
}
}
*/
iinfo.totalEventsChecked++;
}
if (debug) {
trace(iinfo.toString());
}
return iinfo;
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class Users method initUserObject.
BwPrincipal initUserObject(final String val) throws CalFacadeException {
String account = val;
if (account.endsWith("/")) {
account = account.substring(0, account.length() - 1);
}
if (getSvc().getDirectories().isPrincipal(val)) {
account = getSvc().getDirectories().accountFromPrincipal(val);
}
if (account == null) {
throw new CalFacadeException("Bad user account " + val);
}
setRoots(getSvc());
final BwPrincipal user = BwPrincipal.makeUserPrincipal();
user.setAccount(account);
user.setCategoryAccess(Access.getDefaultPersonalAccess());
user.setLocationAccess(Access.getDefaultPersonalAccess());
user.setContactAccess(Access.getDefaultPersonalAccess());
user.setQuota(getSvc().getAuthProperties().getDefaultUserQuota());
user.setPrincipalRef(Util.buildPath(colPathEndsWithSlash, userPrincipalRoot, "/", account));
return user;
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class NotificationsInfo method updated.
/**
* @param currentAuth
* @param ev
* @return Info for single updated event.
* @throws CalFacadeException
*/
public static String updated(final String currentAuth, final BwEvent ev) throws CalFacadeException {
ResourceChangeType rc = getUpdated(currentAuth, ev);
if (rc == null) {
return null;
}
NotificationType note = getNotification();
note.setNotification(rc);
try {
return note.toXml(true);
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations