use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class TranspPropUpdater method applyUpdate.
@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
BwEvent ev = ui.getEvent();
TranspPropType pr = (TranspPropType) ui.getProp();
ChangeTableEntry cte = ui.getCte();
String val = pr.getText();
String evVal = ev.getTransparency();
if (ui.isRemove()) {
if (evVal == null) {
return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
}
val = null;
} else if (ui.isAdd()) {
if (evVal != null) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
}
} else if (!ui.isChange()) {
return new UpdateResult("No update specified for " + ui.getPropName());
} else {
if (!val.equals(evVal)) {
return new UpdateResult("Values don't match for update to " + ui.getPropName());
}
val = ((TranspPropType) ui.getUpdprop()).getText();
}
if (!Util.equalsString(val, evVal)) {
cte.setChanged(evVal, val);
ev.setTransparency(val);
}
return UpdateResult.getOkResult();
}
use of org.bedework.calfacade.BwEvent 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.BwEvent in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method indexEvent.
private IndexResponse indexEvent(final EventInfo ei, final ItemKind kind, final BwDateTime start, final BwDateTime end, final String recurid, final DateLimits dl) throws CalFacadeException {
final BwEvent ev = ei.getEvent();
try {
final DocBuilder db = getDocBuilder();
final EsDocInfo di = db.makeDoc(ei, kind, start, end, recurid);
if (dl != null) {
dl.checkMin(start);
dl.checkMax(end);
}
return indexDoc(di);
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final VersionConflictEngineException vcee) {
if (vcee.getCurrentVersion() == vcee.getProvidedVersion()) {
warn("Failed index with equal version for kind " + kind + " and href " + ev.getHref());
}
return null;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class DocBuilder method getHref.
/* ===================================================================
* package private methods
* =================================================================== */
String getHref(final BwShareableContainedDbentity val) throws CalFacadeException {
if (val instanceof BwEvent) {
return ((BwEvent) val).getHref();
}
if (val instanceof BwCalendar) {
return ((BwCalendar) val).getPath();
}
if (val instanceof FixNamesEntity) {
final FixNamesEntity ent = (FixNamesEntity) val;
ent.fixNames(basicSysprops, principal);
return ent.getHref();
}
throw new CalFacadeException("Unhandled class " + val);
}
use of org.bedework.calfacade.BwEvent 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;
}
Aggregations