use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class ESQueryFilter method makeFilter.
private FilterBuilder makeFilter(final FilterBase f) throws CalFacadeException {
if (f == null) {
return null;
}
if (f instanceof BooleanFilter) {
final BooleanFilter bf = (BooleanFilter) f;
if (!bf.getValue()) {
return new MatchNone();
} else {
return new MatchAllFilterBuilder();
}
}
if (f instanceof AndFilter) {
final List<FilterBuilder> fbs = makeFilters(f.getChildren(), true);
if (fbs.size() == 1) {
return fbs.get(0);
}
final AndFilterBuilder afb = new AndFilterBuilder();
afb.filterName(f.getName());
for (final FilterBuilder fb : fbs) {
if (fb instanceof TermOrTerms) {
afb.add(makeFilter((TermOrTerms) fb));
} else {
afb.add(fb);
}
}
return afb;
}
if (f instanceof OrFilter) {
final List<FilterBuilder> fbs = makeFilters(f.getChildren(), false);
if (fbs.size() == 1) {
return fbs.get(0);
}
final OrFilterBuilder ofb = new OrFilterBuilder();
ofb.filterName(f.getName());
for (final FilterBuilder fb : fbs) {
if (fb instanceof TermOrTerms) {
ofb.add(((TermOrTerms) fb).makeFb());
} else {
ofb.add(fb);
}
}
return ofb;
}
if (f instanceof BwViewFilter) {
return doView((BwViewFilter) f);
}
if (f instanceof BwHrefFilter) {
queryLimited = true;
final TermFilterBuilder tfb = FilterBuilders.termFilter(hrefJname, ((BwHrefFilter) f).getHref());
tfb.filterName(f.getName());
return tfb;
}
if (!(f instanceof PropertyFilter)) {
return null;
}
final PropertyFilter pf = (PropertyFilter) f;
/*
if (pf.getPropertyIndex() == PropertyInfoIndex.CATEGORY_PATH) {
// Special case this one.
return new TermOrTerms(PropertyInfoIndex.CATEGORY_PATH.getJname(),
((ObjectFilter)pf).getEntity());
}*/
final BwIcalPropertyInfo.BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
if (pi == null) {
throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
}
final String fieldName;
final PropertyInfoIndex pii = pf.getPropertyIndex();
if (pf.getParentPropertyIndex() != null) {
fieldName = makePropertyRef(pf.getParentPropertyIndex(), pii);
} else {
fieldName = getJname(pii);
}
if (f instanceof PresenceFilter) {
final PresenceFilter prf = (PresenceFilter) f;
if (prf.getTestPresent()) {
return makeFilter(pf.getPropertyIndexes(), null, pf.getIntKey(), pf.getStrKey(), OperationType.presence, pf.getNot());
}
return makeFilter(pf.getPropertyIndexes(), null, pf.getIntKey(), pf.getStrKey(), OperationType.absence, pf.getNot());
}
if (pf instanceof TimeRangeFilter) {
return makeFilter(pf.getPropertyIndexes(), ((TimeRangeFilter) pf).getEntity(), pf.getIntKey(), pf.getStrKey(), OperationType.timeRange, pf.getNot());
}
if (pf instanceof BwCollectionFilter) {
if (!pf.getNot()) {
queryLimited = true;
}
final BwCalendar col = ((BwCollectionFilter) pf).getEntity();
return new TermOrTerms(colpathJname, col.getPath(), pf.getNot(), f.getName());
}
if (pf instanceof EntityTypeFilter) {
final EntityTypeFilter etf = (EntityTypeFilter) pf;
return new TermOrTerms(entityTypeJname, IcalDefs.entityTypeNames[etf.getEntity()], pf.getNot(), f.getName());
}
if (pf instanceof EntityTimeRangeFilter) {
final EntityTimeRangeFilter etrf = (EntityTimeRangeFilter) pf;
final TimeRange tr = etrf.getEntity();
String start = null;
String end = null;
if (tr.getStart() != null) {
start = tr.getStart().toString();
}
if (tr.getEnd() != null) {
end = tr.getEnd().toString();
}
return addDateRangeFilter(null, etrf.getEntityType(), start, end);
}
if (pii == PropertyInfoIndex.COLLECTION) {
if (!pf.getNot()) {
queryLimited = true;
}
}
if (pf instanceof ObjectFilter) {
final OperationType op;
if (((ObjectFilter) pf).getPrefixMatch()) {
op = OperationType.prefix;
} else {
op = OperationType.compare;
}
return makeFilter(pf.getPropertyIndexes(), getValue((ObjectFilter) pf), pf.getIntKey(), pf.getStrKey(), op, pf.getNot());
}
return null;
/*
if (f instanceof TimeRangeFilter) {
addThisJoin(pi);
return;
}
if (f instanceof BwObjectFilter) {
addThisJoin(pi);
return;
}*/
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class EntityBuilder method makeCollection.
BwCalendar makeCollection() throws CalFacadeException {
final BwCalendar col = new BwCalendar();
restoreSharedEntity(col);
col.setName(getString(PropertyInfoIndex.NAME));
col.setPath(getString(PropertyInfoIndex.HREF));
col.setCreated(getString(PropertyInfoIndex.CREATED));
col.setLastmod(new BwCollectionLastmod(col, getString(PropertyInfoIndex.LAST_MODIFIED)));
col.setSummary(getString(PropertyInfoIndex.SUMMARY));
col.setDescription(getString(PropertyInfoIndex.DESCRIPTION));
col.setAffectsFreeBusy(getBool(PropertyInfoIndex.AFFECTS_FREE_BUSY));
col.setAliasUri(getString(PropertyInfoIndex.ALIAS_URI));
col.setCalType(getInt(PropertyInfoIndex.CALTYPE));
col.setDisplay(getBool(PropertyInfoIndex.DISPLAY));
col.setFilterExpr(getString(PropertyInfoIndex.FILTER_EXPR));
col.setIgnoreTransparency(getBool(PropertyInfoIndex.IGNORE_TRANSP));
col.setLastRefresh(getString(PropertyInfoIndex.LAST_REFRESH));
col.setLastRefreshStatus(getString(PropertyInfoIndex.LAST_REFRESH_STATUS));
col.setRefreshRate(getInt(PropertyInfoIndex.REFRESH_RATE));
col.setRemoteId(getString(PropertyInfoIndex.REMOTE_ID));
col.setRemotePw(getString(PropertyInfoIndex.REMOTE_PW));
col.setUnremoveable(getBool(PropertyInfoIndex.UNREMOVEABLE));
restoreProperties(col);
restoreCategories(col);
return col;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreEvents method deleteEvent.
@Override
public DelEventResult deleteEvent(final EventInfo ei, final boolean scheduling, final boolean reallyDelete) throws CalFacadeException {
final DelEventResult der = new DelEventResult(false, 0);
BwEvent ev = ei.getEvent();
final boolean isMaster = ev.testRecurring() && (ev.getRecurrenceId() == null);
final boolean isInstance = (ev.getRecurrenceId() != null) && (ev instanceof BwEventProxy);
if (!isInstance && ev.unsaved()) {
final CoreEventInfo cei = getEvent(ev.getColPath(), ev.getName(), RecurringRetrievalMode.overrides);
if (cei == null) {
return der;
}
ev = cei.getEvent();
}
final long startTime = System.currentTimeMillis();
final int desiredAccess;
final boolean shared;
try {
final BwCalendar col = getEntityCollection(ev.getColPath(), privAny, scheduling, false);
shared = col.getPublick() || col.getShared();
if (!scheduling) {
desiredAccess = privUnbind;
} else {
/* Delete message while tidying up in/outbox.
* Set desiredAccess to something that works.
* */
final CalendarWrapper cw = (CalendarWrapper) col;
desiredAccess = cw.getLastDesiredAccess();
}
ac.checkAccess(ev, desiredAccess, false);
} catch (final CalFacadeException cfe) {
dao.rollback();
throw cfe;
}
if (!reallyDelete && ev.getTombstoned()) {
// no-op - just pretend
der.eventDeleted = true;
return der;
}
if (isMaster) {
// Master event - delete all instances and overrides.
deleteInstances(ev, shared);
notifyDelete(reallyDelete, ev, shared);
if (reallyDelete) {
dao.delete(ev);
} else {
tombstoneEvent(ev);
}
der.eventDeleted = true;
stat(StatsEvent.deleteTime, startTime);
unindexEntity(ei);
return der;
}
if (isInstance) {
/* Deleting a single instance. Delete any overrides, delete the instance
* and add an exdate to the master.
*/
final BwEventProxy proxy = (BwEventProxy) ev;
final BwEventAnnotation ann = proxy.getRef();
BwEvent master = ann.getMaster();
if (master.unsaved()) {
final CoreEventInfo cei = getEvent(master.getColPath(), master.getName(), RecurringRetrievalMode.overrides);
if (cei == null) {
return der;
}
master = cei.getEvent();
}
/* Fetch the instance so we can delete it */
final BwRecurrenceInstance inst = dao.getInstance(master, ev.getRecurrenceId());
if (inst == null) {
stat(StatsEvent.deleteTime, startTime);
return der;
}
notifyDelete(true, ev, shared);
dao.delete(inst);
if (!ann.unsaved()) {
// der.alarmsDeleted = deleteAlarms(ann);
ann.getAttendees().clear();
dao.delete(ann);
}
final BwDateTime instDate = inst.getDtstart();
if (!master.getRdates().remove(instDate)) {
// Wasn't an rdate event
master.addExdate(instDate);
}
master.updateLastmod();
dao.update(master);
der.eventDeleted = true;
stat(StatsEvent.deleteTime, startTime);
indexEntity(ei.getRetrievedEvent());
return der;
}
// Single non recurring event.
BwEvent deletee = ev;
if (ev instanceof BwEventProxy) {
// Deleting an annotation
deletee = ((BwEventProxy) ev).getRef();
}
// I think we need something like this -- fixReferringAnnotations(deletee);
// XXX This could be wrong.
/* If this is a proxy we should only delete alarmas attached to the
* proxy - any attached to the underlying event should be left alone.
*/
// der.alarmsDeleted = deleteAlarms(deletee);
// sess.delete(sess.merge(deletee));
notifyDelete(reallyDelete, ev, shared);
if (reallyDelete) {
clearCollection(ev.getAttendees());
dao.delete(deletee);
} else {
tombstoneEvent(deletee);
}
der.eventDeleted = true;
stat(StatsEvent.deleteTime, startTime);
unindexEntity(ei);
return der;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreEvents method getSynchEvents.
@Override
public Set<CoreEventInfo> getSynchEvents(final String path, final String token) throws CalFacadeException {
if (path == null) {
dao.rollback();
throw new CalFacadeBadRequest("Missing path");
}
final String fpath = fixPath(path);
final BwCalendar col = getCollection(fpath);
ac.checkAccess(col, privAny, false);
@SuppressWarnings("unchecked") final List<BwEvent> evs = dao.getSynchEventObjects(fpath, token);
if (debug) {
trace(" ----------- number evs = " + evs.size());
}
final Set<CoreEventInfo> res = new TreeSet<>();
for (final BwEvent ev : evs) {
final CurrentAccess ca = new CurrentAccess(true);
res.add(new CoreEventInfo(ev, ca));
}
return res;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreEvents method getEvents.
@Override
public Collection<CoreEventInfo> getEvents(final Collection<BwCalendar> calendars, final FilterBase filter, final BwDateTime startDate, final BwDateTime endDate, final List<BwIcalPropertyInfoEntry> retrieveList, final DeletedState delState, RecurringRetrievalMode recurRetrieval, final boolean freeBusy) throws CalFacadeException {
/* Ensure dates are limited explicitly or implicitly */
recurRetrieval = defaultRecurringRetrieval(recurRetrieval, startDate, endDate);
if (debug) {
trace("getEvents for start=" + startDate + " end=" + endDate);
}
FilterBase fltr = filter;
if (!Util.isEmpty(calendars)) {
FilterBase colfltr = null;
for (final BwCalendar c : calendars) {
colfltr = FilterBase.addOrChild(colfltr, new BwCollectionFilter(null, c));
}
fltr = FilterBase.addAndChild(fltr, colfltr);
}
int desiredAccess = privRead;
if (freeBusy) {
// DORECUR - freebusy events must have enough info for expansion
desiredAccess = privReadFreeBusy;
}
final List<PropertyInfoIndex> properties = new ArrayList<>(2);
properties.add(PropertyInfoIndex.DTSTART);
properties.add(PropertyInfoIndex.UTC);
final List<SortTerm> sort = new ArrayList<>(1);
sort.add(new SortTerm(properties, true));
String start = null;
String end = null;
if (startDate != null) {
start = startDate.getDate();
}
if (endDate != null) {
end = endDate.getDate();
}
final SearchResult sr = // query
getIndexer(null).search(// query
null, false, fltr, sort, // defaultFilterContext
null, start, end, -1, delState, recurRetrieval);
final List<SearchResultEntry> sres = sr.getIndexer().getSearchResult(sr, 0, -1, desiredAccess);
final TreeSet<CoreEventInfo> ceis = new TreeSet<>();
for (final SearchResultEntry sre : sres) {
final Object o = sre.getEntity();
if (!(o instanceof EventInfo)) {
continue;
}
final EventInfo ei = (EventInfo) o;
final BwEvent ev = ei.getEvent();
restoreCategories(ev);
final CoreEventInfo cei = postGetEvent(ev, null, ei.getCurrentAccess());
if (cei == null) {
continue;
}
ceis.add(cei);
}
return buildVavail(ceis);
}
Aggregations