use of org.bedework.calfacade.BwEventAnnotation in project bw-calendar-engine by Bedework.
the class Events method makeInstance.
private EventInfo makeInstance(final EventInfo ei, final String recurrenceId) throws CalFacadeException {
final BwEvent ev = ei.getEvent();
if (!ev.getRecurring()) {
return ei;
}
if (!Util.isEmpty(ei.getOverrides())) {
for (final EventInfo oei : ei.getOverrides()) {
if (oei.getEvent().getRecurrenceId().equals(recurrenceId)) {
oei.setRetrievedEvent(ei);
oei.setCurrentAccess(ei.getCurrentAccess());
return oei;
}
}
}
/* Not in the overrides - generate an instance */
final BwDateTime rstart;
final boolean dateOnly = ev.getDtstart().getDateType();
if (dateOnly) {
rstart = BwDateTime.makeBwDateTime(true, recurrenceId.substring(0, 8), null);
} else {
final String stzid = ev.getDtstart().getTzid();
DateTime dt = null;
try {
dt = new DateTime(recurrenceId);
} catch (final ParseException pe) {
throw new CalFacadeException(pe);
}
final DtStart ds = ev.getDtstart().makeDtStart();
dt.setTimeZone(ds.getTimeZone());
rstart = BwDateTime.makeBwDateTime(dt);
}
final BwDateTime rend = rstart.addDuration(BwDuration.makeDuration(ev.getDuration()));
final BwEventAnnotation ann = new BwEventAnnotation();
ann.setDtstart(rstart);
ann.setDtend(rend);
ann.setRecurrenceId(recurrenceId);
ann.setOwnerHref(ev.getOwnerHref());
// Call it an override
ann.setOverride(true);
ann.setTombstoned(false);
ann.setName(ev.getName());
ann.setUid(ev.getUid());
ann.setTarget(ev);
ann.setMaster(ev);
BwEvent proxy = new BwEventProxy(ann);
EventInfo oei = new EventInfo(proxy);
oei.setCurrentAccess(ei.getCurrentAccess());
oei.setRetrievedEvent(ei);
return oei;
}
use of org.bedework.calfacade.BwEventAnnotation 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.calfacade.BwEventAnnotation 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.BwEventAnnotation 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.calfacade.BwEventAnnotation in project bw-calendar-engine by Bedework.
the class CoreEvents method updateProxy.
/* Called by updateEvent to update a proxied event (annotation) or an
* override.
*/
private void updateProxy(final BwEventProxy proxy) throws CalFacadeException {
/* if this is a proxy for a recurrence instance of our own event
then the recurrence instance should point at this override.
Otherwise we just update the event annotation.
*/
final BwEventAnnotation override = proxy.getRef();
if (debug) {
debugMsg("Update override event " + override);
}
BwEvent mstr = override.getTarget();
while (mstr instanceof BwEventAnnotation) {
/* XXX The master may itself be an annotated event. We should really
stop when we get to that point
*/
/*
BwEventProxy tempProxy = new BwEventProxy(mstr);
if (some-condition-holds) {
break;
}
*/
mstr = ((BwEventAnnotation) mstr).getTarget();
}
// if (mstr.getOwner().equals(getUser()) &&
if (mstr.testRecurring()) {
// A recurring event - retrieve the instance
final BwRecurrenceInstance inst = dao.getInstance(mstr, override.getRecurrenceId());
if (inst == null) {
if (debug) {
debugMsg("Cannot locate instance for " + mstr + "with recurrence id " + override.getRecurrenceId());
}
throwException(CalFacadeException.cannotLocateInstance, mstr + "with recurrence id " + override.getRecurrenceId());
// satisfy intellij
return;
}
// XXX Force owner????
override.setOwnerHref(mstr.getOwnerHref());
dao.saveOrUpdate(override);
// sess.flush();
if (inst.getOverride() == null) {
inst.setOverride(override);
dao.save(inst);
}
/* Update the lastmod on the master event */
mstr.setDtstamps(getCurrentTimestamp());
dao.update(mstr);
} else {
dao.saveOrUpdate(override);
}
proxy.setChangeFlag(false);
}
Aggregations