use of org.bedework.calfacade.indexing.SearchResult 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);
}
use of org.bedework.calfacade.indexing.SearchResult in project bw-calendar-engine by Bedework.
the class ProcessRealias method realiasEvents.
private boolean realiasEvents() throws Throwable {
boolean add = false;
boolean remove = false;
BwXproperty xp = null;
/* Expect from (possibly quoted)
* to (possibly quoted)
*/
try {
open();
final String fromHref = getAliasPath();
if (fromHref == null) {
return false;
}
final String wd = word();
if (wd == null) {
return false;
}
if ("remove".equals(wd)) {
remove = true;
} else {
if ("add".equals(wd)) {
add = true;
} else if ("replace".equals(wd)) {
remove = true;
} else {
error("Expect add | remove | replace");
return false;
}
final BwCalendar col = getCal();
if (col == null) {
return false;
}
/* At the moment an alias is represented by an x-property with
the form:
X-BEDEWORK-ALIAS; \
X-BEDEWORK-PARAM-DISPLAYNAME=Jobs;\
X-BEDEWORK-PARAM-PATH=/public/aliases/Browse By Topic/Jobs;\
X-BEDEWORK-PARAM-ALIASPATH=/public/cals/MainCal:\
/user/agrp_calsuite-MainCampus/Browse By Topic/Jobs"
That is - it appears the displayname comes from the top level
the path is what it points to
the aliaspath is the path of the final target
the value is the path of the alias itself.
*/
final BwCalendar aliasTarget = getAliasTarget(col);
xp = new BwXproperty();
xp.setName("X-BEDEWORK-ALIAS");
xp.setPars("X-BEDEWORK-PARAM-DISPLAYNAME=" + col.getName() + ";X-BEDEWORK-PARAM-PATH=" + col.getAliasUri().substring(BwCalendar.internalAliasUriPrefix.length()) + ";X-BEDEWORK-PARAM-ALIASPATH=" + aliasTarget.getPath());
xp.setValue(col.getPath());
}
final FilterBase fltr = parseQuery("topical_area=\"\t" + fromHref + "\"");
if (fltr == null) {
return false;
}
close();
/* Now we need to process the stuff in batches */
open();
final BwIndexer idx = getIndexer();
final SearchResult sr = idx.search(null, false, fltr, null, null, null, null, batchSize, includeDeleted, RecurringRetrievalMode.entityOnly);
if (sr.getFound() == 0) {
warn("No events found");
return false;
}
for (; ; ) {
final List<SearchResultEntry> sres = idx.getSearchResult(sr, BwIndexer.Position.next, PrivilegeDefs.privAny);
if (Util.isEmpty(sres)) {
break;
}
int updated = 0;
for (final SearchResultEntry sre : sres) {
final Object o = sre.getEntity();
if (!(o instanceof EventInfo)) {
warn("Unhandled entity " + o.getClass());
continue;
}
EventInfo ei = (EventInfo) o;
/* Fetch the persistent version
*/
final String colPath = ei.getEvent().getColPath();
final String name = ei.getEvent().getName();
ei = getEvents().get(colPath, name);
if (ei == null) {
warn("Unable to retrieve persistent copy of " + colPath + " " + name);
continue;
}
updated += doRealias(ei, fromHref, xp, add, remove);
if ((updated % 10) == 0) {
info("done " + updated);
}
}
info("Total updated: " + updated);
}
return true;
} finally {
close();
}
}
Aggregations