use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getFiles.
/* (non-Javadoc)
* @see org.bedework.caldav.server.SysIntf#getFiles(org.bedework.caldav.server.CalDAVCollection)
*/
@Override
public Collection<CalDAVResource> getFiles(final CalDAVCollection coll) throws WebdavException {
try {
Collection<BwResource> bwrs = getSvci().getResourcesHandler().getAll(coll.getPath());
if (bwrs == null) {
return null;
}
Collection<CalDAVResource> rs = new ArrayList<CalDAVResource>();
for (BwResource r : bwrs) {
rs.add(new BwCalDAVResource(this, r));
}
return rs;
} catch (CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
} catch (Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class CalintfImpl method getResource.
/* ====================================================================
* resources
* ==================================================================== */
@Override
public BwResource getResource(final String name, final BwCalendar coll, final int desiredAccess) throws CalFacadeException {
final BwResource res = entityDao.getResource(name, coll, desiredAccess);
if (res == null) {
return null;
}
final CurrentAccess ca = checkAccess(res, desiredAccess, true);
if (!ca.getAccessAllowed()) {
return null;
}
return res;
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class CalSvc method getSynchItems.
private String getSynchItems(final BwCalendar col, final String vpath, final String token, final Set<SynchReportItem> items, final boolean recurse) throws CalFacadeException {
final Events eventsH = (Events) getEventsHandler();
final ResourcesImpl resourcesH = (ResourcesImpl) getResourcesHandler();
final Calendars colsH = (Calendars) getCalendarsHandler();
String newToken = "";
BwCalendar resolvedCol = col;
if (debug) {
trace("sync token: " + token + " col: " + resolvedCol.getPath());
}
if (col.getTombstoned()) {
return token;
}
if (col.getInternalAlias()) {
resolvedCol = getCalendarsHandler().resolveAlias(col, true, false);
}
if (resolvedCol.getTombstoned()) {
return token;
}
/* Each collection could be:
* a. A calendar collection or special - like Inbox -
* only need to look for events.
* b. Other collections. Need to look for events, resources and collections.
*/
final boolean eventsOnly = resolvedCol.getCollectionInfo().onlyCalEntities;
final Set<EventInfo> evs = eventsH.getSynchEvents(resolvedCol.getPath(), token);
for (final EventInfo ei : evs) {
if (!ei.getEvent().getTombstoned() && !eventsH.isVisible(col, ei.getEvent().getName())) {
continue;
}
final SynchReportItem sri = new SynchReportItem(vpath, ei);
items.add(sri);
if (sri.getToken().compareTo(newToken) > 0) {
newToken = sri.getToken();
}
}
if (!eventsOnly) {
// Look for resources
final List<BwResource> ress = resourcesH.getSynchResources(resolvedCol.getPath(), token);
for (final BwResource r : ress) {
final SynchReportItem sri = new SynchReportItem(vpath, r);
items.add(sri);
if (sri.getToken().compareTo(newToken) > 0) {
newToken = sri.getToken();
}
}
}
final Set<SynchReportItem> colItems = new TreeSet<>();
final Set<BwCalendar> cols = colsH.getSynchCols(resolvedCol.getPath(), token);
final List<BwCalendar> aliases = new ArrayList<>();
for (final BwCalendar c : cols) {
final int calType = c.getCalType();
if (calType == BwCalendar.calTypePendingInbox) {
continue;
}
if ((token != null) && (calType == BwCalendar.calTypeAlias)) {
aliases.add(c);
continue;
}
final SynchReportItem sri = new SynchReportItem(vpath, c, canSync(c));
colItems.add(sri);
items.add(sri);
if (sri.getToken().compareTo(newToken) > 0) {
newToken = sri.getToken();
}
if (debug) {
trace(" token=" + sri.getToken() + " for " + c.getPath());
}
}
if (!Util.isEmpty(aliases)) {
/* Resolve each one and see if the target is a candidate
*/
for (final BwCalendar c : aliases) {
final BwCalendar resolved = getCalendarsHandler().resolveAlias(c, true, false);
if (resolved == null) {
continue;
}
if (c.getTombstoned() && !getCal().testSynchCol(c, token)) {
continue;
}
if (!getCal().testSynchCol(resolved, token)) {
continue;
}
final SynchReportItem sri = new SynchReportItem(vpath, c, canSync(c), resolved.getLastmod().getTagValue());
colItems.add(sri);
items.add(sri);
if (sri.getToken().compareTo(newToken) > 0) {
newToken = sri.getToken();
}
}
}
if (!recurse) {
return newToken;
}
if (Util.isEmpty(colItems)) {
return newToken;
}
for (final SynchReportItem sri : colItems) {
if (!sri.getCanSync()) {
continue;
}
final BwCalendar sricol = sri.getCol();
final String t = getSynchItems(sricol, Util.buildPath(true, vpath, "/", sricol.getName()), token, items, true);
if (t.compareTo(newToken) > 0) {
newToken = t;
}
}
return newToken;
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class Notifications method removeAll.
@Override
public void removeAll(final String principalHref) throws CalFacadeException {
if (principalHref == null) {
return;
}
final BwCalendar ncol = getCols().getSpecial(principalHref, BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return;
}
/* Remove resources */
final ResourcesI resI = getSvc().getResourcesHandler();
final Collection<BwResource> rs = resI.getAll(ncol.getPath());
if (!Util.isEmpty(rs)) {
for (final BwResource r : rs) {
resI.delete(Util.buildPath(false, r.getColPath(), "/", r.getName()));
}
}
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class Notifications method getMatching.
@Override
public List<NotificationType> getMatching(final QName type) throws CalFacadeException {
final List<NotificationType> res = new ArrayList<>();
final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return res;
}
final Collection<BwResource> rsrc = getSvc().getResourcesHandler().getAll(ncol.getPath());
if (Util.isEmpty(rsrc)) {
return res;
}
if (rsrc.size() > 100) {
warn("Large resource collection for " + ncol.getPath());
}
for (final BwResource r : rsrc) {
if (type != null) {
final NotificationInfo ni = NotificationType.fromContentType(r.getContentType());
if ((ni == null) || !type.equals(ni.type)) {
continue;
}
}
final NotificationType nt = makeNotification(r);
if (nt != null) {
res.add(nt);
}
}
return res;
}
Aggregations