use of org.bedework.calfacade.BwDateTime 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.BwDateTime in project bw-calendar-engine by Bedework.
the class InRequest method updateAttendeeFields.
private boolean updateAttendeeFields(final EventInfo ourCopy, final EventInfo inBoxEi, final String attUri) throws CalFacadeException {
BwEvent ourEv = ourCopy.getEvent();
BwEvent inEv = inBoxEi.getEvent();
boolean flagNeedsReply = false;
ChangeTable chg = ourCopy.getChangeset(getPrincipalHref());
for (PropertyInfoIndex ipi : PropertyInfoIndex.values()) {
BwIcalPropertyInfoEntry bipie = BwIcalPropertyInfo.getPinfo(ipi);
if (bipie == null) {
continue;
}
if ((ourEv.getEntityType() == IcalDefs.entityTypeEvent) && !bipie.getEventProperty()) {
continue;
}
if ((ourEv.getEntityType() == IcalDefs.entityTypeTodo) && !bipie.getTodoProperty()) {
continue;
}
switch(ipi) {
case UNKNOWN_PROPERTY:
break;
case CLASS:
if (chg.changed(ipi, ourEv.getClassification(), inEv.getClassification())) {
ourEv.setClassification(inEv.getClassification());
}
break;
case COMPLETED:
/* Todo only */
if (chg.changed(ipi, ourEv.getCompleted(), inEv.getCompleted())) {
ourEv.setCompleted(inEv.getCompleted());
}
break;
case CREATED:
break;
case DESCRIPTION:
/*
for (BwLongString s: inEv.getDescriptions()) {
chg.addValue(Property.DESCRIPTION, s);
}
*/
if (chg.changed(ipi, ourEv.getDescription(), inEv.getDescription())) {
ourEv.setDescription(inEv.getDescription());
}
break;
case DTEND:
/* Event only */
case DUE:
/* Todo only */
BwDateTime dt = inEv.getDtend();
if (!CalFacadeUtil.eqObjval(ourEv.getDtend(), dt)) {
ourEv.setDtend(dt);
chg.changed(ipi, ourEv.getDtend(), dt);
}
char c = inEv.getEndType();
if (c != ourEv.getEndType()) {
ourEv.setEndType(c);
chg.changed(PropertyInfoIndex.END_TYPE, ourEv.getEndType(), c);
}
break;
case DTSTAMP:
break;
case DTSTART:
dt = inEv.getDtstart();
if (!CalFacadeUtil.eqObjval(ourEv.getDtstart(), dt)) {
ourEv.setDtstart(dt);
chg.changed(ipi, ourEv.getDtstart(), dt);
}
break;
case DURATION:
if (chg.changed(ipi, ourEv.getDuration(), inEv.getDuration())) {
ourEv.setDuration(inEv.getDuration());
}
break;
case GEO:
if (chg.changed(ipi, ourEv.getGeo(), inEv.getGeo())) {
ourEv.setGeo(inEv.getGeo());
}
break;
case LAST_MODIFIED:
break;
case LOCATION:
if (chg.changed(ipi, ourEv.getLocation(), inEv.getLocation())) {
ourEv.setLocation((BwLocation) inEv.getLocation().clone());
}
break;
case ORGANIZER:
if (chg.changed(ipi, ourEv.getOrganizer(), inEv.getOrganizer())) {
ourEv.setOrganizer((BwOrganizer) inEv.getOrganizer().clone());
}
break;
case PRIORITY:
if (chg.changed(ipi, ourEv.getPriority(), inEv.getPriority())) {
ourEv.setPriority(inEv.getPriority());
}
break;
case RECURRENCE_ID:
break;
case SEQUENCE:
if (chg.changed(ipi, ourEv.getSequence(), inEv.getSequence())) {
ourEv.setSequence(inEv.getSequence());
}
break;
case STATUS:
if (chg.changed(ipi, ourEv.getStatus(), inEv.getStatus())) {
ourEv.setStatus(inEv.getStatus());
}
break;
case SUMMARY:
/*
for (BwString s: inEv.getSummaries()) {
chg.addValue(Property.SUMMARY, s);
}
*/
if (chg.changed(ipi, ourEv.getSummary(), inEv.getSummary())) {
ourEv.setSummary(inEv.getSummary());
}
break;
case PERCENT_COMPLETE:
/* Todo only */
if (chg.changed(ipi, ourEv.getPercentComplete(), inEv.getPercentComplete())) {
ourEv.setPercentComplete(inEv.getPercentComplete());
}
break;
case UID:
break;
case URL:
if (chg.changed(ipi, ourEv.getLink(), inEv.getLink())) {
ourEv.setLink(inEv.getLink());
}
break;
case TRANSP:
/* Event only - done with attendee */
break;
case ATTACH:
break;
case ATTENDEE:
String transparency = ourEv.getTransparency();
BwAttendee ourAtt = null;
for (BwAttendee inAtt : inEv.getAttendees()) {
BwAttendee att = (BwAttendee) inAtt.clone();
att.setScheduleStatus(null);
String inAttUri = att.getAttendeeUri();
BwAttendee evAtt = ourEv.findAttendee(inAttUri);
if (inAttUri.equals(attUri)) {
// It's ours
ourAtt = att;
if ((att.getPartstat() == null) || att.getPartstat().equals(IcalDefs.partstatValNeedsAction)) {
transparency = IcalDefs.transparencyTransparent;
// Apple ical seems to expect an x-prop.
flagNeedsReply = true;
}
// att.setScheduleStatus(IcalDefs.deliveryStatusSuccess);
}
/* See if it's in the current set and if anything significant changed
for (BwAttendee calAtt: ourEv.getAttendees()) {
if (calAtt.getAttendeeUri().equals(inAttUri)) {
if (calAtt.changedBy(inAtt, false)) {
ourEv.setSignificantChange(true);
}
}
}*/
final ChangeTableEntry cte = chg.getEntry(PropertyInfoIndex.ATTENDEE);
if (evAtt != null) {
cte.addChangedValue(att);
} else {
cte.addAddedValue(att);
}
}
if (ourAtt == null) {
// Error?
if (debug) {
trace("InSchedule - no attendee for " + ourEv.getOwnerHref());
}
return false;
}
if (chg.changed(PropertyInfoIndex.TRANSP, ourEv.getTransparency(), transparency)) {
ourEv.setTransparency(transparency);
}
break;
case CATEGORIES:
if (!Util.isEmpty(inEv.getCategories())) {
for (BwCategory cat : inEv.getCategories()) {
chg.addValue(ipi, cat);
}
}
break;
case COMMENT:
for (BwString s : inEv.getComments()) {
chg.addValue(ipi, s);
}
break;
case CONTACT:
for (final BwContact ct : inEv.getContacts()) {
chg.addValue(ipi, ct.clone());
}
break;
case EXDATE:
// Don't updaye exdate - we add cancelled overrides
break;
case EXRULE:
// Only for master events
if (ourEv instanceof BwEventProxy) {
break;
}
for (final String s : inEv.getExrules()) {
chg.addValue(ipi, s);
}
break;
case REQUEST_STATUS:
break;
case RELATED_TO:
if (chg.changed(ipi, ourEv.getRelatedTo(), inEv.getRelatedTo())) {
ourEv.setRelatedTo(inEv.getRelatedTo());
}
break;
case RESOURCES:
for (BwString bs : inEv.getResources()) {
chg.addValue(ipi, bs);
}
break;
case RDATE:
// Only for master events
if (ourEv instanceof BwEventProxy) {
break;
}
for (BwDateTime bdt : inEv.getRdates()) {
chg.addValue(ipi, bdt);
}
break;
case RRULE:
// Only for master events
if (ourEv instanceof BwEventProxy) {
break;
}
for (String s : inEv.getRrules()) {
chg.addValue(ipi, s);
}
break;
case XPROP:
for (BwXproperty x : inEv.getXproperties()) {
chg.addValue(ipi, x);
}
break;
case FREEBUSY:
case TZID:
case TZNAME:
case TZOFFSETFROM:
case TZOFFSETTO:
case TZURL:
case ACTION:
case REPEAT:
case TRIGGER:
break;
// non ical
case COLLECTION:
// non ical
case COST:
// non ical
case CREATOR:
// non ical
case OWNER:
case // non ical
ENTITY_TYPE:
break;
case // Component
VALARM:
break;
// Param
case LANG:
case // Param
TZIDPAR:
break;
case PUBLISH_URL:
case POLL_ITEM_ID:
case END_TYPE:
case ETAG:
case HREF:
case XBEDEWORK_COST:
case CALSCALE:
case METHOD:
case PRODID:
case VERSION:
case ACL:
case AFFECTS_FREE_BUSY:
case ALIAS_URI:
case ATTENDEE_SCHEDULING_OBJECT:
case CALTYPE:
case COL_PROPERTIES:
case COLPATH:
case CTOKEN:
case DISPLAY:
case DOCTYPE:
case EVENTREG_END:
case EVENTREG_MAX_TICKETS:
case EVENTREG_MAX_TICKETS_PER_USER:
case EVENTREG_START:
case EVENTREG_WAIT_LIST_LIMIT:
case FILTER_EXPR:
case IGNORE_TRANSP:
case IMAGE:
case INDEX_END:
case INDEX_START:
case INSTANCE:
case LAST_REFRESH:
case LAST_REFRESH_STATUS:
case LOCATION_UID:
case LOCATION_STR:
break;
default:
warn("Not handling icalendar property " + ipi);
}
// switch
}
if (chg.changed(PropertyInfoIndex.COST, ourEv.getCost(), inEv.getCost())) {
ourEv.setCost(inEv.getCost());
}
/* Now see if we need to flag a schedule-tag change. We do so only if
* a. A property other than the attendee changed
* b. An attendee was added or removed
*/
Collection<ChangeTableEntry> changes = chg.getEntries();
ChangeTableEntry attChanges = null;
ourEv.setSignificantChange(false);
for (ChangeTableEntry cte : changes) {
if (!cte.getChanged()) {
continue;
}
if (cte.getIndex() == PropertyInfoIndex.ATTENDEE) {
attChanges = cte;
continue;
}
ourEv.setSignificantChange(true);
}
if (debug) {
trace("After change check getSignificantChange=" + ourEv.getSignificantChange());
}
if (flagNeedsReply) {
// Apple ical seems to expect an x-prop.
// chg.addValue(PropertyInfoIndex.XPROP,
// new BwXproperty(BwXproperty.appleNeedsReply,
// null, "TRUE"));
}
chg.processChanges(ourEv, true);
if (debug) {
trace(chg.toString());
}
/* The attendee change entry will now reflect the changes made to the
* attendee list. See if any significant change was made there.
*/
if (attChanges != null) {
if (!Util.isEmpty(attChanges.getAddedValues()) || !Util.isEmpty(attChanges.getRemovedValues())) {
ourEv.setSignificantChange(true);
} else {
/* TODO - go through the changed entries and look for our entry. See
* if we are being asked to reply - this can probably be done earlier.
*/
}
}
if (debug) {
trace("After attendee change check getSignificantChange=" + ourEv.getSignificantChange());
}
return true;
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class CalintfImpl method getFreeBusy.
/* ====================================================================
* Free busy
* ==================================================================== */
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> cals, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final boolean returnAll, final boolean ignoreTransparency) throws CalFacadeException {
if (who.getKind() != WhoDefs.whoTypeUser) {
throw new CalFacadeException("Unsupported: non user principal for free-busy");
}
final Collection<CoreEventInfo> events = getFreeBusyEntities(cals, start, end, ignoreTransparency);
final BwEvent fb = new BwEventObj();
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
fb.setOwnerHref(who.getPrincipalRef());
fb.setDtstart(start);
fb.setDtend(end);
try {
final TreeSet<EventPeriod> eventPeriods = new TreeSet<>();
for (final CoreEventInfo ei : events) {
final BwEvent ev = ei.getEvent();
// Ignore if times were specified and this event is outside the times
final BwDateTime estart = ev.getDtstart();
final BwDateTime eend = ev.getDtend();
/* Don't report out of the requested period */
final String dstart;
final String dend;
if (estart.before(start)) {
dstart = start.getDtval();
} else {
dstart = estart.getDtval();
}
if (eend.after(end)) {
dend = end.getDtval();
} else {
dend = eend.getDtval();
}
final DateTime psdt = new DateTime(dstart);
final DateTime pedt = new DateTime(dend);
psdt.setUtc(true);
pedt.setUtc(true);
int type = BwFreeBusyComponent.typeBusy;
if (BwEvent.statusTentative.equals(ev.getStatus())) {
type = BwFreeBusyComponent.typeBusyTentative;
}
eventPeriods.add(new EventPeriod(psdt, pedt, type));
}
/* iterate through the sorted periods combining them where they are
adjacent or overlap */
Period p = null;
/* For the moment just build a single BwFreeBusyComponent
*/
BwFreeBusyComponent fbc = null;
int lastType = 0;
for (final EventPeriod ep : eventPeriods) {
if (debug) {
debug(ep.toString());
}
if (p == null) {
p = new Period(ep.getStart(), ep.getEnd());
lastType = ep.getType();
} else if ((lastType != ep.getType()) || ep.getStart().after(p.getEnd())) {
// Non adjacent periods
if (fbc == null) {
fbc = new BwFreeBusyComponent();
fbc.setType(lastType);
fb.addFreeBusyPeriod(fbc);
}
fbc.addPeriod(p.getStart(), p.getEnd());
if (lastType != ep.getType()) {
fbc = null;
}
p = new Period(ep.getStart(), ep.getEnd());
lastType = ep.getType();
} else if (ep.getEnd().after(p.getEnd())) {
// Extend the current period
p = new Period(p.getStart(), ep.getEnd());
}
// else it falls within the existing period
}
if (p != null) {
if ((fbc == null) || (lastType != fbc.getType())) {
fbc = new BwFreeBusyComponent();
fbc.setType(lastType);
fb.addFreeBusyPeriod(fbc);
}
fbc.addPeriod(p.getStart(), p.getEnd());
}
} catch (final Throwable t) {
if (debug) {
error(t);
}
throw new CalFacadeException(t);
}
return fb;
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class ExdatePropUpdater method addDt.
private boolean addDt(final BwDateTime newdt, final Set<BwDateTime> evDts, final ChangeTableEntry cte) {
if (!Util.isEmpty(evDts)) {
for (BwDateTime evDt : evDts) {
if (evDt.getDate().equals(newdt.getDate())) {
// Already there
return false;
}
}
}
evDts.add(newdt);
cte.addAddedValue(newdt);
return true;
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class ExdatePropUpdater method removeDt.
private boolean removeDt(final String dtUTC, final Set<BwDateTime> evDts, final ChangeTableEntry cte) {
if (Util.isEmpty(evDts)) {
// Nothing to remove
return false;
}
for (BwDateTime evDt : evDts) {
if (evDt.getDate().equals(dtUTC)) {
evDts.remove(evDt);
cte.addRemovedValue(evDt);
break;
}
}
return true;
}
Aggregations