use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class BwUpdates method applyUpdate.
private UpdateResult applyUpdate(final EventInfo ei, final ComponentSelectionType selPar) throws WebdavException {
/* First two selects just get us in to the events */
ComponentSelectionType sel = selPar;
// Top level must be "vcalendar"
if ((sel == null) || (sel.getVcalendar() == null)) {
return new UpdateResult("Not \"vcalendar\"");
}
// Next - expect "components"
ComponentsSelectionType csel = sel.getComponents();
if (csel == null) {
return new UpdateResult("Not \"component\"");
}
for (ComponentReferenceType c : csel.getRemove()) {
UpdateResult ur = removeOverride(ei, c);
if (!ur.getOk()) {
return ur;
}
}
for (ComponentReferenceType c : csel.getAdd()) {
UpdateResult ur = addOverride(ei, c);
if (!ur.getOk()) {
return ur;
}
}
/* Updates may be applied to the master or any overrides selected by uid and
* recurrence-id
*/
for (ComponentSelectionType cs : csel.getComponent()) {
BaseComponentType ent = cs.getBaseComponent().getValue();
// Must be a component matching the current one.
if (ent == null) {
return new UpdateResult("Missing component to match");
}
Integer entType = entTypes.get(ent.getClass());
if (entType == null) {
return new UpdateResult("Unknown entity type: " + ent.getClass());
}
if (entType != ei.getEvent().getEntityType()) {
return new UpdateResult("No matching entity");
}
List<EventInfo> entities = new ArrayList<EventInfo>();
entities.add(ei);
entities.addAll(ei.getOverrides());
entities = match(// sel,
entities, ent);
if ((entities == null) || (entities.size() == 0)) {
return new UpdateResult("No matching entity");
}
if ((cs.getProperties() == null) && (cs.getComponents() == null)) {
// No properties or components - error
return new UpdateResult("Must select \"components\" and/or \"properties\"");
}
/* At this point we either select properties to change or nested components
*/
if (cs.getComponents() != null) {
UpdateResult ur = applySubCompUpdates(ei, cs.getComponents());
if (!ur.getOk()) {
return ur;
}
}
if (cs.getProperties() != null) {
// Updating properties
UpdateResult ur = updateEventsProperties(entities, cs.getProperties());
if (!ur.getOk()) {
return ur;
}
}
}
return UpdateResult.getOkResult();
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method reindexEvent.
private boolean reindexEvent(final ReindexResponse.Failure resp, final String indexName, final SearchHit sh, final EventInfo ei, final BulkProcessor bulkProcessor) {
try {
/* If it's not recurring or a stand-alone instance index it */
final BwEvent ev = ei.getEvent();
if ((uidsMap != null) && (ev.getLocationUid() == null)) {
final String locuid = uidsMap.get(ev.getUid());
if (locuid != null) {
uidsSet++;
ev.setLocationUid(locuid);
}
}
if (!restoreEvProps(resp, ei)) {
return false;
}
if (!ev.testRecurring() && (ev.getRecurrenceId() == null)) {
final EsDocInfo doc = makeDoc(resp, ei, ItemKind.master, ev.getDtstart(), ev.getDtend(), // ev.getRecurrenceId(),
null, null);
if (doc == null) {
return false;
}
final IndexRequest request = new IndexRequest(indexName, sh.type(), doc.getId());
request.source(doc.getSource());
bulkProcessor.add(request);
return true;
}
if (ev.getRecurrenceId() != null) {
errorReturn(resp, "Not implemented - index of single override");
return false;
}
if (!addOverrides(resp, idxpars.getUserIndexName(), ei)) {
return false;
}
final int maxYears;
final int maxInstances;
final DateLimits dl = new DateLimits();
if (ev.getPublick()) {
maxYears = unauthpars.getMaxYears();
maxInstances = unauthpars.getMaxInstances();
} else {
maxYears = authpars.getMaxYears();
maxInstances = authpars.getMaxInstances();
}
final RecurPeriods rp = RecurUtil.getPeriods(ev, maxYears, maxInstances);
if (rp.instances.isEmpty()) {
errorReturn(resp, "No instances for an alleged recurring event.");
return false;
}
final String stzid = ev.getDtstart().getTzid();
int instanceCt = maxInstances;
final boolean dateOnly = ev.getDtstart().getDateType();
/* First build a table of overrides so we can skip these later
*/
final Map<String, String> overrides = new HashMap<>();
if (!Util.isEmpty(ei.getOverrides())) {
for (final EventInfo oei : ei.getOverrides()) {
final BwEvent ov = oei.getEvent();
overrides.put(ov.getRecurrenceId(), ov.getRecurrenceId());
final String dtstart;
if (ov.getDtstart().getDateType()) {
dtstart = ov.getRecurrenceId().substring(0, 8);
} else {
dtstart = ov.getRecurrenceId();
}
final BwDateTime rstart = BwDateTime.makeBwDateTime(ov.getDtstart().getDateType(), dtstart, stzid);
final BwDateTime rend = rstart.addDuration(BwDuration.makeDuration(ov.getDuration()));
final EsDocInfo doc = makeDoc(resp, oei, ItemKind.override, rstart, rend, ov.getRecurrenceId(), dl);
if (doc == null) {
return false;
}
final IndexRequest request = new IndexRequest(indexName, sh.type(), doc.getId());
request.source(doc.getSource());
bulkProcessor.add(request);
instanceCt--;
}
}
for (final Period p : rp.instances) {
String dtval = p.getStart().toString();
if (dateOnly) {
dtval = dtval.substring(0, 8);
}
final BwDateTime rstart = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
if (overrides.get(rstart.getDate()) != null) {
// Overrides indexed separately - skip this instance.
continue;
}
final String recurrenceId = rstart.getDate();
dtval = p.getEnd().toString();
if (dateOnly) {
dtval = dtval.substring(0, 8);
}
final BwDateTime rend = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
final EsDocInfo doc = makeDoc(resp, ei, entity, rstart, rend, recurrenceId, dl);
if (doc == null) {
return false;
}
final IndexRequest request = new IndexRequest(indexName, sh.type(), doc.getId());
request.source(doc.getSource());
bulkProcessor.add(request);
instanceCt--;
if (instanceCt == 0) {
// That's all you're getting from me
break;
}
}
// </editor-fold>
// <editor-fold desc="Emit the master event with a date range covering the entire period.">
final BwDateTime dtstart = BwDateTime.makeBwDateTime(dateOnly, dl.minStart, stzid);
final BwDateTime dtend = BwDateTime.makeBwDateTime(dateOnly, dl.maxEnd, stzid);
final EsDocInfo doc = makeDoc(resp, ei, ItemKind.master, dtstart, dtend, null, null);
if (doc == null) {
return false;
}
final IndexRequest request = new IndexRequest(indexName, sh.type(), doc.getId());
request.source(doc.getSource());
bulkProcessor.add(request);
// </editor-fold>
return true;
} catch (final Throwable t) {
errorReturn(resp, t);
return false;
}
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class EntityBuilder method makeEvent.
/**
* @param expanded true if we are doing this for an expanded retrieval
* that is, treat everything as instances.
* @return an event object
* @throws CalFacadeException on error
*/
@SuppressWarnings("unchecked")
EventInfo makeEvent(final String id, final boolean expanded) throws CalFacadeException {
final boolean override = !expanded && getBool(PropertyInfoIndex.OVERRIDE);
final boolean tryCache = (currentMode == guestMode) && publick;
final String cacheKey = id + override;
retrievals++;
if (tryCache) {
checkPurge();
final EventCacheEntry ece = eventCache.get(cacheKey);
if (ece != null) {
hits++;
ece.update();
if (debug && ((retrievals % 500) == 0)) {
debug("Retrievals: " + retrievals + " hits: " + hits + " purges: " + purges + " flushes: " + flushes + " size: " + eventCache.size());
}
return ece.ei;
}
}
final BwEvent ev;
if (override) {
ev = new BwEventAnnotation();
final BwEventAnnotation ann = (BwEventAnnotation) ev;
ann.setOverride(true);
} else {
ev = new BwEventObj();
}
final EventInfo ei = new EventInfo(ev);
/*
Float score = (Float)sd.getFirstValue("score");
if (score != null) {
bwkey.setScore(score);
}
*/
restoreSharedEntity(ev);
ev.setDeleted(getBool(PropertyInfoIndex.DELETED));
ev.setName(getString(PropertyInfoIndex.NAME));
ev.setCalSuite(getString(PropertyInfoIndex.CALSUITE));
restoreCategories(ev);
ev.setSummaries((Set<BwString>) restoreBwStringSet(PropertyInfoIndex.SUMMARY, false));
ev.setDescriptions((Set<BwLongString>) restoreBwStringSet(PropertyInfoIndex.DESCRIPTION, true));
ev.setEntityType(makeEntityType(getString(PropertyInfoIndex.ENTITY_TYPE)));
ev.setClassification(getString(PropertyInfoIndex.CLASS));
ev.setLink(getString(PropertyInfoIndex.URL));
ev.setGeo(restoreGeo());
ev.setStatus(getString(PropertyInfoIndex.STATUS));
ev.setCost(getString(PropertyInfoIndex.COST));
ev.setOrganizer(restoreOrganizer());
ev.setDtstamp(getString(PropertyInfoIndex.DTSTAMP));
ev.setLastmod(getString(PropertyInfoIndex.LAST_MODIFIED));
ev.setCreated(getString(PropertyInfoIndex.CREATED));
ev.setStag(getString(PropertyInfoIndex.SCHEDULE_TAG));
ev.setPriority(getInteger(PropertyInfoIndex.PRIORITY));
ev.setSequence(getInt(PropertyInfoIndex.SEQUENCE));
ev.setLocationUid(getString(PropertyInfoIndex.LOCATION_UID));
ev.setUid(getString(PropertyInfoIndex.UID));
ev.setTransparency(getString(PropertyInfoIndex.TRANSP));
ev.setPercentComplete(getInteger(PropertyInfoIndex.PERCENT_COMPLETE));
ev.setCompleted(getString(PropertyInfoIndex.COMPLETED));
ev.setScheduleMethod(getInt(PropertyInfoIndex.SCHEDULE_METHOD));
ev.setOriginator(getString(PropertyInfoIndex.ORIGINATOR));
ev.setScheduleState(getInt(PropertyInfoIndex.SCHEDULE_STATE));
ev.setOrganizerSchedulingObject(getBoolean(PropertyInfoIndex.ORGANIZER_SCHEDULING_OBJECT));
ev.setAttendeeSchedulingObject(getBoolean(PropertyInfoIndex.ATTENDEE_SCHEDULING_OBJECT));
ev.setRelatedTo(restoreRelatedTo());
ev.setXproperties(restoreXprops());
restoreReqStat(ev);
ev.setCtoken(getString(PropertyInfoIndex.CTOKEN));
ev.setRecurring(getBoolean(PropertyInfoIndex.RECURRING));
ev.setRecurrenceId(getString(PropertyInfoIndex.RECURRENCE_ID));
ev.setRrules(getStringSet(PropertyInfoIndex.RRULE));
ev.setExrules(getStringSet(PropertyInfoIndex.EXRULE));
ev.setRdates(restoreBwDateTimeSet(PropertyInfoIndex.RDATE));
ev.setExdates(restoreBwDateTimeSet(PropertyInfoIndex.EXDATE));
ev.setDtstart(unindexDate(PropertyInfoIndex.DTSTART));
ev.setDtend(unindexDate(PropertyInfoIndex.DTEND));
ev.setNoStart(Boolean.parseBoolean(getString(PropertyInfoIndex.NO_START)));
ev.setEndType(getString(PropertyInfoIndex.END_TYPE).charAt(0));
ev.setDuration(getString(PropertyInfoIndex.DURATION));
ev.setAlarms(restoreAlarms());
/* uuu Attachment */
final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
ev.setAttendees(restoreAttendees(vpoll));
ev.setRecipients(getStringSet(PropertyInfoIndex.RECIPIENT));
ev.setComments((Set<BwString>) restoreBwStringSet(PropertyInfoIndex.COMMENT, false));
restoreContacts(ev);
ev.setResources((Set<BwString>) restoreBwStringSet(PropertyInfoIndex.RESOURCES, false));
if (vpoll) {
final Set<String> pollItems = getStringSet(PropertyInfoIndex.POLL_ITEM);
if (!Util.isEmpty(pollItems)) {
for (final String s : pollItems) {
ev.addPollItem(s);
}
}
ev.setPollMode(getString(PropertyInfoIndex.POLL_MODE));
ev.setPollWinner(getInteger(PropertyInfoIndex.POLL_WINNER));
ev.setPollProperties(getString(PropertyInfoIndex.POLL_PROPERTIES));
}
if (tryCache) {
synchronized (eventCache) {
eventCache.put(cacheKey, new EventCacheEntry(cacheKey, ei));
}
}
return ei;
}
use of org.bedework.calfacade.svc.EventInfo 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.svc.EventInfo in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method addOverrides.
private boolean addOverrides(final Response resp, final String indexName, final EventInfo ei) {
try {
final BwEvent ev = ei.getEvent();
if (!ev.testRecurring()) {
return true;
}
/* Fetch any overrides. */
final ESQueryFilter flts = getFilters(null);
final int batchSize = 100;
int start = 0;
while (true) {
// Search original for overrides
final SearchRequestBuilder srb = getClient().prepareSearch(Util.buildPath(false, indexName));
srb.setSearchType(SearchType.QUERY_THEN_FETCH).setPostFilter(flts.overridesOnly(ev.getUid()));
srb.setFrom(start);
srb.setSize(batchSize);
// if (debug) {
// debug("Overrides: targetIndex=" + indexName +
// "; srb=" + srb);
// }
final SearchResponse sresp = srb.execute().actionGet();
if (sresp.status() != RestStatus.OK) {
errorReturn(resp, "Search returned status " + sresp.status());
return false;
}
final SearchHit[] hits = sresp.getHits().getHits();
if ((hits == null) || (hits.length == 0)) {
// No more data - we're done
break;
}
for (final SearchHit hit : hits) {
final String dtype = hit.getType();
if (dtype == null) {
errorReturn(resp, "org.bedework.index.noitemtype");
return false;
}
final String kval = hit.getId();
if (kval == null) {
errorReturn(resp, "org.bedework.index.noitemkey");
return false;
}
final EntityBuilder eb = getEntityBuilder(hit.sourceAsMap());
final Object entity;
switch(dtype) {
case docTypeEvent:
case docTypePoll:
entity = eb.makeEvent(kval, false);
final EventInfo oei = (EventInfo) entity;
final BwEvent oev = oei.getEvent();
if ((uidsMap != null) && (oev.getLocationUid() == null)) {
String locuid = null;
if (uidsOverideMap != null) {
locuid = uidsOverideMap.get(oev.getUid() + "|" + oev.getRecurrenceId());
}
if (locuid == null) {
locuid = uidsMap.get(oev.getUid());
}
if (locuid != null) {
uidOverridesSet++;
oev.setLocationUid(locuid);
}
oev.setLocationUid(locuid);
}
if (!restoreEvProps(resp, oei)) {
return false;
}
if (oev instanceof BwEventAnnotation) {
final BwEventAnnotation ann = (BwEventAnnotation) oev;
final BwEvent proxy = new BwEventProxy(ann);
ann.setTarget(ev);
ann.setMaster(ev);
ei.addOverride(new EventInfo(proxy));
continue;
}
}
// Unexpected type
errorReturn(resp, "Expected override only: " + dtype);
return false;
}
if (hits.length < batchSize) {
// All remaining in this batch - we're done
break;
}
start += batchSize;
}
return true;
} catch (final Throwable t) {
errorReturn(resp, t);
return false;
}
}
Aggregations