Search in sources :

Example 11 with BwRecurrenceInstance

use of org.bedework.calfacade.BwRecurrenceInstance in project bw-calendar-engine by Bedework.

the class CoreEventsDAO method getInstance.

protected BwRecurrenceInstance getInstance(final BwEvent ev, final String rid) throws CalFacadeException {
    final HibSession sess = getSess();
    sess.createQuery(recurrenceInstanceQuery);
    sess.setEntity("master", ev);
    sess.setString("rid", rid);
    return (BwRecurrenceInstance) sess.getUnique();
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance)

Example 12 with BwRecurrenceInstance

use of org.bedework.calfacade.BwRecurrenceInstance in project bw-calendar-engine by Bedework.

the class SchedulingBase method copyEventInfo.

/**
 * Same as copyEventInfo(EventInfo, BwPrincipal) except it only copies
 * significant changes.
 *
 * @param ei
 * @param significantChangesOnly
 * @param owner
 * @return a copy of the event.
 * @throws CalFacadeException
 */
protected EventInfo copyEventInfo(final EventInfo ei, final boolean significantChangesOnly, final BwPrincipal owner) throws CalFacadeException {
    BwEvent ev = ei.getEvent();
    BwEvent newEv = copyEvent(ev, null, owner);
    StringBuilder changeInfo = new StringBuilder();
    changeInfo.append(ev.getDtstamp());
    final boolean cancel = ev.getScheduleMethod() == ScheduleMethods.methodTypeCancel;
    final boolean adding = ei.getUpdResult().adding;
    final boolean reply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
    if (cancel) {
        changeInfo.append(";CANCEL");
    } else if (adding) {
        changeInfo.append(";CREATE");
    } else if (reply) {
        changeInfo.append(";REPLY");
    } else {
        changeInfo.append(";UPDATE");
    }
    if (adding || cancel) {
        changeInfo.append(";MASTER");
    } else {
        addChangeInfo(ei, changeInfo, "MASTER");
    }
    if (!ev.getRecurring()) {
        setChangeInfo(newEv, changeInfo);
        return new EventInfo(newEv);
    }
    if (cancel) {
        /* Collect any attendees in overrides not in the copied master */
        Set<EventInfo> overrides = ei.getOverrides();
        if (overrides != null) {
            for (EventInfo oei : overrides) {
                for (BwAttendee ovatt : oei.getEvent().getAttendees()) {
                    if (newEv.findAttendee(ovatt.getAttendeeUri()) == null) {
                        newEv.addAttendee((BwAttendee) ovatt.clone());
                    }
                }
            }
        }
        setChangeInfo(newEv, changeInfo);
        return new EventInfo(newEv);
    }
    boolean fromOrganizer = ev.getOrganizerSchedulingObject();
    boolean attendeeInMaster = false;
    String uri = getSvc().getDirectories().principalToCaladdr(owner);
    if (fromOrganizer) {
        attendeeInMaster = ev.findAttendee(uri) != null;
    }
    /* Save the status - we may change to master-suppressed */
    String masterStatus = newEv.getStatus();
    /* We may suppress the master event if there is no significant change and
     * we only want significant changes or if the attendee is not an attendee
     * of the master event.
     */
    boolean masterSuppressed = false;
    boolean significant = ei.getChangeset(getPrincipalHref()).getSignificantChange();
    if (fromOrganizer && !attendeeInMaster) {
        masterSuppressed = true;
    }
    List<String> deletedRecurids = null;
    if (masterSuppressed) {
        // Attendee will appear in overrides. Remove rules and r/exdates
        if (!Util.isEmpty(ei.getUpdResult().deletedInstances)) {
            deletedRecurids = new ArrayList<>();
            for (BwRecurrenceInstance ri : ei.getUpdResult().deletedInstances) {
                deletedRecurids.add(ri.getRecurrenceId());
            }
        }
        if (newEv.getRrules() != null) {
            newEv.getRrules().clear();
        }
        if (newEv.getRdates() != null) {
            newEv.getRdates().clear();
        }
        if (newEv.getExrules() != null) {
            newEv.getExrules().clear();
        }
        if (newEv.getExdates() != null) {
            newEv.getExdates().clear();
        }
        newEv.setSuppressed(true);
    }
    Set<EventInfo> overrides = ei.getOverrides();
    Set<EventInfo> newovs = new TreeSet<>();
    if (overrides != null) {
        for (EventInfo oei : overrides) {
            BwEvent oev = oei.getEvent();
            boolean attendeeInOverride = oev.findAttendee(uri) != null;
            if (!masterSuppressed && attendeeInMaster && attendeeInOverride) {
                if (significantChangesOnly) {
                    significant = oei.getChangeset(getPrincipalHref()).getSignificantChange();
                    if (!oei.getNewEvent() && !significant) {
                        continue;
                    }
                }
            }
            if (fromOrganizer) {
                if (!masterSuppressed && attendeeInMaster) {
                    /* If the attendee is not in this override, add an exdate to the master
             */
                    if (!attendeeInOverride) {
                        String rid = oev.getRecurrenceId();
                        BwDateTime bwrdt = BwDateTime.fromUTC(rid.length() == 8, rid);
                        newEv.addExdate(bwrdt);
                        continue;
                    }
                } else if (attendeeInOverride) {
                    /* Add this override as an rdate */
                    String rid = oev.getRecurrenceId();
                    BwDateTime bwrdt = BwDateTime.fromUTC(rid.length() == 8, rid);
                    newEv.addRdate(bwrdt);
                    if ((deletedRecurids != null) && deletedRecurids.contains(oev.getRecurrenceId())) {
                        oev.setStatus(BwEvent.statusCancelled);
                    } else if ((oev.getStatus() != null) && oev.getStatus().equals(BwEvent.statusMasterSuppressed)) {
                        // Not overridden - set to saved master value
                        oev.setStatus(masterStatus);
                    }
                    oev.setSequence(ev.getSequence());
                } else {
                    continue;
                }
            }
            if (adding || cancel) {
                changeInfo.append(";RID=");
                changeInfo.append(oev.getRecurrenceId());
            } else {
                addChangeInfo(ei, changeInfo, oev.getRecurrenceId());
            }
            newovs.add(new EventInfo(copyEvent(oev, newEv, owner)));
        }
    }
    setChangeInfo(newEv, changeInfo);
    return new EventInfo(newEv, newovs);
}
Also used : BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance) EventInfo(org.bedework.calfacade.svc.EventInfo) BwDateTime(org.bedework.calfacade.BwDateTime) TreeSet(java.util.TreeSet) BwEvent(org.bedework.calfacade.BwEvent) BwAttendee(org.bedework.calfacade.BwAttendee)

Aggregations

BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)12 BwDateTime (org.bedework.calfacade.BwDateTime)8 BwEvent (org.bedework.calfacade.BwEvent)7 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)6 BwEventProxy (org.bedework.calfacade.BwEventProxy)5 Period (net.fortuna.ical4j.model.Period)3 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)3 BwCalendar (org.bedework.calfacade.BwCalendar)3 RecurPeriods (org.bedework.icalendar.RecurUtil.RecurPeriods)3 TreeSet (java.util.TreeSet)2 Dur (net.fortuna.ical4j.model.Dur)2 CollectionInfo (org.bedework.calfacade.BwCalendar.CollectionInfo)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 DateTime (net.fortuna.ical4j.model.DateTime)1 TimeZone (net.fortuna.ical4j.model.TimeZone)1 CurrentAccess (org.bedework.access.Acl.CurrentAccess)1