use of org.bedework.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.
the class Events method postProcess.
private EventInfo postProcess(final CoreEventInfo cei) throws CalFacadeException {
if (cei == null) {
return null;
}
// trace("ev: " + ev);
/* If the event is an event reference (an alias) implant it in an event
* proxy and return that object.
*/
BwEvent ev = cei.getEvent();
if (ev instanceof BwEventAnnotation) {
ev = new BwEventProxy((BwEventAnnotation) ev);
}
final Set<EventInfo> overrides = new TreeSet<EventInfo>();
if (cei.getOverrides() != null) {
for (final CoreEventInfo ocei : cei.getOverrides()) {
final BwEventProxy op = (BwEventProxy) ocei.getEvent();
overrides.add(new EventInfo(op));
}
}
final EventInfo ei = new EventInfo(ev, overrides);
/* Reconstruct if any contained items. */
if (cei.getNumContainedItems() > 0) {
for (CoreEventInfo ccei : cei.getContainedItems()) {
BwEvent cv = ccei.getEvent();
ei.addContainedItem(new EventInfo(cv));
}
}
ei.setCurrentAccess(cei.getCurrentAccess());
return ei;
}
use of org.bedework.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.
the class RestoreImpl method getEvent.
@Override
public BwEvent getEvent(final BwPrincipal owner, final String colPath, final String recurrenceId, final String uid) throws Throwable {
startTransaction();
final Collection<CoreEventInfo> ceis = getCal().getEvent(colPath, uid);
if (ceis.size() != 1) {
error("Expected one event for {" + colPath + ", " + recurrenceId + ", " + uid + "} found " + ceis.size());
return null;
}
final CoreEventInfo ei = ceis.iterator().next();
BwEvent ev = null;
if (recurrenceId == null) {
ev = ei.getEvent();
} else {
for (final CoreEventInfo cei : ei.getOverrides()) {
if (cei.getEvent().getRecurrenceId().equals(recurrenceId)) {
ev = cei.getEvent();
break;
}
}
}
if (ev == null) {
return null;
}
if (ev instanceof BwEventAnnotation) {
ev = new BwEventProxy((BwEventAnnotation) ev);
}
return ev;
}
use of org.bedework.calcorei.CoreEventInfo 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.calcorei.CoreEventInfo 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.calcorei.CoreEventInfo in project bw-calendar-engine by Bedework.
the class CoreEvents method getEvent.
@Override
public Collection<CoreEventInfo> getEvent(final String colPath, final String uid) throws CalFacadeException {
final TreeSet<CoreEventInfo> ts = new TreeSet<>();
final int desiredAccess = privRead;
/*
if (colPath != null) {
BwCalendar cal = getEntityCollection(colPath, privRead, scheduling, false);
desiredAccess = ((CalendarWrapper)cal).getLastDesiredAccess();
}
*/
/* This works as follows:
*
* First try to retrieve the master event from the events table.
*
* If not there try the annotations table. If it's there, it's a reference
* to an event owned by somebody else. Otherwise we drew a blank.
*
* If no recurrence id was specified process any recurrence information for
* each event retrieved and return.
*
* Note that the event we retrieved might be a reference to a recurring
* instance. In that case it will inherit the recurrence id. We should check
* for this case and assume we were being asked for that event.
*
* If a recurrence id was specified then, for each master event retrieved,
* we need to retrieve the instance and build a proxy using any appropriate
* overrides.
*/
// First look in the events table for the master(s).
Collection evs = dao.eventQuery(BwEventObj.class, colPath, uid, null, null, // overrides
null, // recurRetrieval);
null);
if (Util.isEmpty(evs)) {
/* Look for an annotation to that event by the current user.
*/
evs = dao.eventQuery(BwEventAnnotation.class, colPath, uid, /*null*/
null, null, // overrides
false, // recurRetrieval);
null);
}
if (Util.isEmpty(evs)) {
return ts;
}
final Collection<CoreEventInfo> ceis = postGetEvents(evs, desiredAccess, returnResultAlways, null);
if (ceis.isEmpty()) {
return ceis;
}
/* If the recurrence id is null, do recurrences for each retrieved event,
* otherwise just retrieve the instance.
*/
final EventsQueryResult eqr = new EventsQueryResult();
eqr.flt = new Filters(cb, null);
eqr.addColPath(colPath);
for (final CoreEventInfo cei : ceis) {
final BwEvent master = cei.getEvent();
if (master.getEntityType() == IcalDefs.entityTypeVavailability) {
for (final String auid : master.getAvailableUids()) {
final Collection<CoreEventInfo> aceis = getEvent(colPath, auid);
if (aceis.size() != 1) {
throwException(CalFacadeException.badResponse);
}
cei.addContainedItem(aceis.iterator().next());
}
ts.add(cei);
} else if (!master.testRecurring()) {
ts.add(cei);
} else {
doRecurrence(cei, null);
ts.add(cei);
}
}
return ts;
}
Aggregations