use of org.bedework.calfacade.BwEventAnnotation in project bw-calendar-engine by Bedework.
the class CoreEventsDAO method getEventsAnnotationName.
protected BwEventAnnotation getEventsAnnotationName(final String colPath, final String name) throws CalFacadeException {
final HibSession sess = getSess();
sess.createQuery(eventAnnotationsByNameQuery);
sess.setString("name", name);
sess.setString("colPath", colPath);
return (BwEventAnnotation) sess.getUnique();
}
use of org.bedework.calfacade.BwEventAnnotation in project bw-calendar-engine by Bedework.
the class CoreEventsDAO method getEventAnnotations.
public Iterator<BwEventAnnotation> getEventAnnotations() throws CalFacadeException {
final HibSession sess = getSess();
sess.createQuery(getEventAnnotationsQuery);
@SuppressWarnings("unchecked") final Collection<BwEventAnnotation> anns = sess.getList();
return anns.iterator();
}
use of org.bedework.calfacade.BwEventAnnotation 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;
}
}
use of org.bedework.calfacade.BwEventAnnotation in project bw-calendar-engine by Bedework.
the class InReply method updateOrganizerCopy.
private boolean updateOrganizerCopy(final EventInfo colEi, final EventInfo inBoxEi, final String attUri, final ScheduleResult sr) throws CalFacadeException {
final BwEvent inBoxEv = inBoxEi.getEvent();
final BwEvent calEv = colEi.getEvent();
final ChangeTable chg = calEv.getChangeset(getPrincipalHref());
/* Only set true if the inbox copy needs to stay as notification.
* Do not set true for status updates
*/
boolean changed = false;
if (debug) {
trace("Update for attendee " + attUri);
}
if (inBoxEv.getScheduleMethod() != ScheduleMethods.methodTypeReply) {
sr.errorCode = CalFacadeException.schedulingBadMethod;
return false;
}
/* If the incoming sequence is less than that in the organizers event
* then ignore the incoming reply?
*/
/* Update the participation status from the incoming attendee */
BwAttendee calAtt;
final ChangeTableEntry cte = chg.getEntry(PropertyIndex.PropertyInfoIndex.ATTENDEE);
if (!inBoxEv.getSuppressed()) {
calAtt = calEv.findAttendee(attUri);
if (calAtt == null) {
if (debug) {
trace("Not an attendee of " + calEv);
}
sr.errorCode = CalFacadeException.schedulingUnknownAttendee;
sr.extraInfo = attUri;
return false;
}
// For a recurring instance we replace or we update all recurring instances.
final boolean recurringInstance = (calEv instanceof BwEventProxy);
final BwAttendee att = inBoxEv.findAttendee(attUri);
if (calAtt.changedBy(att)) {
changed = true;
if (recurringInstance) {
calEv.removeAttendee(att);
calAtt = (BwAttendee) att.clone();
} else {
att.copyTo(calAtt);
}
cte.addChangedValue(calAtt);
}
calAtt.setScheduleStatus(getRstat(inBoxEv));
if (recurringInstance) {
calEv.addAttendee(calAtt);
}
// XXX Ensure no name change
if (calEv instanceof BwEventProxy) {
final BwEventProxy pr = (BwEventProxy) calEv;
final BwEventAnnotation ann = pr.getRef();
ann.setName(null);
}
}
/* The above changed the master - now we need to update or add any overrides
*/
if (calEv.getRecurring() && (inBoxEi.getOverrides() != null)) {
for (final EventInfo oei : inBoxEi.getOverrides()) {
final BwEvent oev = oei.getEvent();
final EventInfo cei = colEi.findOverride(oev.getRecurrenceId());
/*
if (cei == null) {
// Organizer must have deleted the override.
if (debug) {
trace("Skipping missing override " + oev.getRecurrenceId());
}
continue;
}*/
final BwEvent ocalEv = cei.getEvent();
if (((BwEventProxy) ocalEv).getRef().unsaved()) {
// New Override
try {
final String rid = oev.getRecurrenceId();
Date dt = new DateTime(rid);
if (calEv.getDtstart().getDateType()) {
// RECUR - fix all day recurrences sometime
if (rid.length() > 8) {
// Try to fix up bad all day recurrence ids. - assume a local timezone
((DateTime) dt).setTimeZone(null);
dt = new Date(dt.toString().substring(0, 8));
}
}
final DtStart st = new DtStart(dt);
final String tzid = calEv.getDtstart().getTzid();
if (tzid != null) {
final TimeZone tz = Timezones.getTz(tzid);
st.setTimeZone(tz);
}
ocalEv.setDtstart(BwDateTime.makeBwDateTime(st));
ocalEv.setDuration(calEv.getDuration());
ocalEv.setDtend(ocalEv.getDtstart().addDur(new Dur(calEv.getDuration())));
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
final BwAttendee ovatt = oev.findAttendee(attUri);
calAtt = ocalEv.findAttendee(attUri);
if (calAtt == null) {
// Organizer must have removed the attendee.
if (debug) {
trace("Skipping override " + attUri + " is not attending");
}
continue;
}
if (calAtt.changedBy(ovatt)) {
changed = true;
ocalEv.removeAttendee(ovatt);
calAtt = (BwAttendee) ovatt.clone();
calAtt.setScheduleStatus(getRstat(oev));
ocalEv.addAttendee(calAtt);
cte.addChangedValue(calAtt);
}
}
}
final boolean noinvites = !changed;
colEi.setReplyUpdate(true);
/* Update the organizer copy. This will broadcast the changes tp all
* attendees
*/
getSvc().getEventsHandler().update(colEi, noinvites, attUri);
return changed;
}
use of org.bedework.calfacade.BwEventAnnotation in project bw-calendar-engine by Bedework.
the class CalintfHelper method postGetEvent.
/* Post processing of event access has been checked
*/
protected CoreEventInfo postGetEvent(final BwEvent ev, final Filters f, final Acl.CurrentAccess ca) throws CalFacadeException {
/* XXX-ALARM
if (currentMode == userMode) {
ev.setAlarms(getAlarms(ev, user));
}
*/
BwEvent event;
if (ev instanceof BwEventAnnotation) {
event = new BwEventProxy((BwEventAnnotation) ev);
if ((f != null) && !f.postFilter(ev, currentPrincipal())) {
return null;
}
} else {
event = ev;
}
CoreEventInfo cei = new CoreEventInfo(event, ca);
return cei;
}
Aggregations