use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getCollections.
@Override
public Collection<CalDAVCollection> getCollections(final CalDAVCollection col) throws WebdavException {
try {
final BwCalendar bwCol = unwrap(col);
boolean isUserHome = false;
List<Integer> provisionedTypes = null;
/* Is this the calendar home? If so we have to ensure all
provisioned collections exist */
if (getPrincipal() != null) {
final String userHomePath = Util.buildPath(true, getSvci().getPrincipalInfo().getCalendarHomePath(getPrincipal()));
if (Util.buildPath(true, bwCol.getPath()).equals(userHomePath)) {
isUserHome = true;
provisionedTypes = new ArrayList<>();
for (final BwCalendar.CollectionInfo ci : BwCalendar.getAllCollectionInfo()) {
if (ci.provision) {
provisionedTypes.add(ci.collectionType);
}
}
}
}
final CalendarsI ci = getSvci().getCalendarsHandler();
final Collection<BwCalendar> bwch = ci.getChildren(bwCol);
final Collection<CalDAVCollection> ch = new ArrayList<>();
if (bwch == null) {
return ch;
}
for (final BwCalendar c : bwch) {
if (bedeworkExtensionsEnabled() || !c.getName().startsWith(".")) {
ci.resolveAlias(c, true, false);
ch.add(new BwCalDAVCollection(this, c));
}
if (isUserHome && !c.getAlias()) {
provisionedTypes.remove(new Integer(c.getCalType()));
}
}
if (isUserHome && !provisionedTypes.isEmpty()) {
// Need to add some
for (final int colType : provisionedTypes) {
final BwCalendar pcol = ci.getSpecial(currentPrincipal, colType, true, PrivilegeDefs.privAny);
ch.add(new BwCalDAVCollection(this, pcol));
}
}
return ch;
} catch (final CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getCollection.
/* (non-Javadoc)
* @see org.bedework.caldav.server.SysIntf#getCollection(java.lang.String)
*/
@Override
public CalDAVCollection getCollection(final String path) throws WebdavException {
try {
BwCalendar col = getSvci().getCalendarsHandler().get(path);
if (col == null) {
return null;
}
getSvci().getCalendarsHandler().resolveAlias(col, true, false);
return new BwCalDAVCollection(this, col);
} catch (CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
} catch (Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getPrincipals.
@Override
public Collection<CalPrincipalInfo> getPrincipals(String resourceUri, final PrincipalPropertySearch pps) throws WebdavException {
List<CalPrincipalInfo> principals = null;
if (pps.applyToPrincipalCollectionSet) {
/* I believe it's valid (if unhelpful) to return nothing
*/
return new ArrayList<>();
}
if (!resourceUri.endsWith("/")) {
resourceUri += "/";
}
try {
String proot = BwPrincipal.principalRoot;
if (!proot.endsWith("/")) {
proot += "/";
}
if (!resourceUri.equals(proot)) {
return new ArrayList<>();
}
} catch (final Throwable t) {
throw new WebdavException(t);
}
/* If we don't support any of the properties in the searches we don't match.
*
* Currently we only support calendarUserAddressSet or calendarHomeSet.
*
* For calendarUserAddressSet the value to match must be a valid CUA
*
* For calendarHomeSet it must be a valid home uri
*/
final List<WebdavProperty> props = new ArrayList<>();
String cutype = null;
for (final WebdavProperty prop : pps.props) {
if (debug) {
debug("Try to match " + prop);
}
final String pval = prop.getPval();
if (CaldavTags.calendarUserAddressSet.equals(prop.getTag())) {
principals = and(principals, getCalPrincipalInfo(caladdrToPrincipal(pval)));
} else if (CaldavTags.calendarHomeSet.equals(prop.getTag())) {
final String path = getUrlHandler().unprefix(pval);
final CalDAVCollection col = getCollection(path);
if (col != null) {
principals = and(principals, getCalPrincipalInfo(col.getOwner()));
}
} else if (CaldavTags.calendarUserType.equals(prop.getTag())) {
cutype = pval;
} else if (WebdavTags.displayname.equals(prop.getTag())) {
// Store for directory search
props.add(prop);
}
}
try {
if (props.size() != 0) {
// Directory search
final Holder<Boolean> truncated = new Holder<>();
if (principals == null) {
principals = new ArrayList<>();
}
final List<BwPrincipalInfo> pis = getSvci().getDirectories().find(props, pps.pr.props, cutype, truncated);
if (pis != null) {
for (final BwPrincipalInfo pi : pis) {
principals.add(getCalPrincipalInfo(pi));
}
}
}
} catch (final Throwable t) {
throw new WebdavException(t);
}
if (principals == null) {
return new ArrayList<>();
}
return principals;
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method doNoteHeader.
/* ====================================================================
* Private methods
* ==================================================================== */
private String doNoteHeader(final String hdr, final String account) throws WebdavException {
if (hdr == null) {
return account;
}
try {
final String[] hparts = hdr.split(":");
if (hparts.length != 2) {
throw new WebdavBadRequest();
}
final String id = hparts[0];
final NotificationProperties nprops = configs.getNotificationProps();
final String token = hparts[1];
if (id == null) {
throw new WebdavBadRequest();
}
if (!id.equals(nprops.getNotifierId()) || (token == null) || !token.equals(nprops.getNotifierToken())) {
throw new WebdavBadRequest();
}
if (account != null) {
return account;
}
return id;
} catch (final WebdavException wde) {
throw wde;
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method requestFreeBusy.
@Override
public Collection<SchedRecipientResult> requestFreeBusy(final CalDAVEvent val, final boolean iSchedule) throws WebdavException {
try {
ScheduleResult sr;
BwEvent ev = getEvent(val);
if (currentPrincipal != null) {
ev.setOwnerHref(currentPrincipal.getPrincipalRef());
}
if (Icalendar.itipReplyMethodType(ev.getScheduleMethod())) {
sr = getSvci().getScheduler().scheduleResponse(getEvinfo(val));
} else {
sr = getSvci().getScheduler().schedule(getEvinfo(val), null, null, iSchedule);
}
return checkStatus(sr);
} catch (CalFacadeAccessException cfae) {
if (debug) {
error(cfae);
}
throw new WebdavForbidden();
} catch (CalFacadeException cfe) {
if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
throw new WebdavBadRequest("Duplicate-guid");
}
throw new WebdavException(cfe);
} catch (WebdavException wde) {
throw wde;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
Aggregations