use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CalSuites method validateGroup.
/**
* Ensure the given group is valid for the given calendar suite
*
* @param cs
* @param groupName
* @return home for the group
* @throws CalFacadeException
*/
private BwCalendar validateGroup(final BwCalSuite cs, final String groupName) throws CalFacadeException {
if (groupName.length() > BwCalSuite.maxNameLength) {
throw new CalFacadeException(CalFacadeException.calsuiteGroupNameTooLong);
}
BwAdminGroup agrp = (BwAdminGroup) getSvc().getAdminDirectories().findGroup(groupName);
if (agrp == null) {
throw new CalFacadeException(CalFacadeException.groupNotFound, groupName);
}
final BwCalSuiteWrapper csw = get(agrp);
if ((csw != null) && !csw.equals(cs)) {
// Group already assigned to another cal suite
throw new CalFacadeException(CalFacadeException.calsuiteGroupAssigned, csw.getName());
}
final BwPrincipal eventsOwner = getPrincipal(agrp.getOwnerHref());
if (eventsOwner == null) {
throw new CalFacadeException(CalFacadeException.calsuiteBadowner);
}
final BwCalendar home = getCols().getHomeDb(eventsOwner, true);
if (home == null) {
throw new CalFacadeException(CalFacadeException.missingGroupOwnerHome);
}
cs.setGroup(agrp);
/* Change access on the home for the events creator which is also the
* owner of the calsuite resources.
*/
final Collection<Privilege> allPrivs = new ArrayList<>();
allPrivs.add(Access.all);
final Collection<Privilege> readPrivs = new ArrayList<>();
readPrivs.add(Access.read);
final Collection<Ace> aces = new ArrayList<>();
try {
aces.add(Ace.makeAce(AceWho.owner, allPrivs, null));
aces.add(Ace.makeAce(AceWho.getAceWho(eventsOwner.getAccount(), WhoDefs.whoTypeUser, false), allPrivs, null));
aces.add(Ace.makeAce(AceWho.getAceWho(null, WhoDefs.whoTypeAuthenticated, false), readPrivs, null));
aces.add(Ace.makeAce(AceWho.all, readPrivs, null));
getSvc().changeAccess(home, aces, true);
/* Same access to the calsuite itself */
getSvc().changeAccess(cs, aces, true);
/* Also set access so that categories, locations etc are readable */
final String aclStr = new String(new Acl(aces).encode());
eventsOwner.setCategoryAccess(aclStr);
eventsOwner.setLocationAccess(aclStr);
eventsOwner.setContactAccess(aclStr);
} catch (final AccessException ae) {
throw new CalFacadeException(ae);
}
getSvc().getUsersHandler().update(eventsOwner);
return home;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CalSuites method setRootCol.
/**
* Set root collection if supplied
*
* @param cs
* @param rootCollectionPath
* @throws CalFacadeException
*/
private void setRootCol(final BwCalSuite cs, final String rootCollectionPath) throws CalFacadeException {
if ((rootCollectionPath == null) || rootCollectionPath.equals(cs.getRootCollectionPath())) {
return;
}
BwCalendar rootCol = getCols().get(rootCollectionPath);
if (rootCol == null) {
throw new CalFacadeException(CalFacadeException.calsuiteUnknownRootCollection, rootCollectionPath);
}
cs.setRootCollection(rootCol);
cs.setRootCollectionPath(rootCol.getPath());
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CalSvc method getSynchReport.
/* (non-Javadoc)
* @see org.bedework.calsvci.CalSvcI#getSynchReport(java.lang.String, java.lang.String, int, boolean)
*/
@Override
public SynchReport getSynchReport(final String path, final String token, final int limit, final boolean recurse) throws CalFacadeException {
final BwCalendar col = getCalendarsHandler().get(path);
if (col == null) {
return null;
}
Set<SynchReportItem> items = new TreeSet<SynchReportItem>();
String resToken = getSynchItems(col, path, token, items, recurse);
final SynchReport res = new SynchReport(items, resToken);
if ((limit > 0) && (res.size() >= limit)) {
if (res.size() == limit) {
return res;
}
items = new TreeSet<>();
resToken = "";
for (final SynchReportItem item : res.getItems()) {
if (item.getToken().compareTo(resToken) > 0) {
resToken = item.getToken();
}
items.add(item);
if (items.size() == limit) {
break;
}
}
}
if (resToken.length() == 0) {
resToken = Util.icalUTCTimestamp() + "-0000";
}
return new SynchReport(items, resToken);
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CalSvc method changeAccess.
/* ====================================================================
* Access
* ==================================================================== */
/* (non-Javadoc)
* @see org.bedework.calsvci.CalSvcI#changeAccess(org.bedework.calfacade.base.BwShareableDbentity, java.util.Collection)
*/
@Override
public void changeAccess(BwShareableDbentity ent, final Collection<Ace> aces, final boolean replaceAll) throws CalFacadeException {
if (ent instanceof BwCalSuiteWrapper) {
ent = ((BwCalSuiteWrapper) ent).fetchEntity();
}
getCal().changeAccess(ent, aces, replaceAll);
if (ent instanceof BwCalendar) {
final BwCalendar col = (BwCalendar) ent;
if (col.getCalType() == BwCalendar.calTypeInbox) {
// Same access as inbox
final BwCalendar pendingInbox = getCalendarsHandler().getSpecial(BwCalendar.calTypePendingInbox, true);
if (pendingInbox == null) {
warn("Unable to update pending inbox access");
} else {
getCal().changeAccess(pendingInbox, aces, replaceAll);
}
}
((Preferences) getPrefsHandler()).updateAdminPrefs(false, col, null, null, null);
} else if (ent instanceof BwEventProperty) {
((Preferences) getPrefsHandler()).updateAdminPrefs(false, (BwEventProperty) ent);
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class Calendars method findAliases.
private void findAliases(final BwCalendar col, final AliasesInfo rootAi) throws CalFacadeException {
final String collectionHref = col.getPath();
final boolean defaultEnabled = !Boolean.valueOf(System.getProperty("org.bedework.nochangenote", "false")) && getAuthpars().getDefaultChangesNotifications();
if (notificationsEnabled(col, defaultEnabled)) {
rootAi.setNotificationsEnabled(true);
}
/* Handle aliases that are not a result of calendar sharing. These could be public or private.
*/
for (final BwCalendar alias : findAlias(collectionHref)) {
final AliasesInfo ai = new AliasesInfo(getPrincipal().getPrincipalRef(), alias, null);
rootAi.addSharee(ai);
findAliases(alias, ai);
}
/* for each sharee in the list find user collection(s) pointing to this
* collection and add the sharee if any are enabled for notifications.
*/
final InviteType invite = getSvc().getSharingHandler().getInviteStatus(col);
if (invite == null) {
// No sharees
return;
}
/* for sharees - it's the alias which points at this collection
* which holds the status.
*/
for (final UserType u : invite.getUsers()) {
final BwPrincipal principal = caladdrToPrincipal(u.getHref());
if (principal == null) {
final AliasesInfo ai = new AliasesInfo(u.getHref(), col, null);
ai.setExternalCua(true);
rootAi.addSharee(ai);
continue;
}
try {
pushPrincipal(principal);
for (final BwCalendar alias : findAlias(collectionHref)) {
if (!notificationsEnabled(alias, defaultEnabled)) {
continue;
}
final AliasesInfo ai = new AliasesInfo(principal.getPrincipalRef(), alias, null);
rootAi.addSharee(ai);
findAliases(alias, ai);
}
} finally {
popPrincipal();
}
}
}
Aggregations