use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class SchedulingBase method copyEvent.
protected BwEvent copyEvent(final BwEvent origEv, final BwEvent masterEv, final BwPrincipal owner) throws CalFacadeException {
final BwEvent newEv;
BwEventProxy proxy = null;
final String ownerHref = owner.getPrincipalRef();
if (origEv instanceof BwEventProxy) {
proxy = (BwEventProxy) origEv;
if (masterEv == null) {
/* we are being asked to copy an instance of a recurring event - rather than
* a complete recurring event + all overrides - clone the master
*/
newEv = new BwEventObj();
origEv.copyTo(newEv);
newEv.setRecurring(false);
// Return the instance copy
proxy = null;
} else {
// Clone the annotation and set the master and target to our new master
// ANNOTATION
proxy = proxy.clone(masterEv, masterEv);
newEv = proxy.getRef();
}
} else {
// getSvc().reAttach(origEv);
newEv = (BwEvent) origEv.clone();
}
if (!Util.isEmpty(newEv.getAttendees())) {
for (BwAttendee att : newEv.getAttendees()) {
att.setScheduleStatus(null);
}
}
if (newEv.getOrganizer() != null) {
newEv.getOrganizer().setScheduleStatus(null);
}
newEv.setOwnerHref(ownerHref);
newEv.setCreatorHref(ownerHref);
newEv.setDtstamps(getCurrentTimestamp());
if (owner.equals(getPrincipal())) {
if (proxy != null) {
return proxy;
}
return newEv;
}
/* Copy event entities */
BwLocation loc = newEv.getLocation();
if (loc != null) {
loc = (BwLocation) loc.clone();
loc.setOwnerHref(ownerHref);
loc.setCreatorHref(ownerHref);
loc.initUid();
newEv.setLocation(loc);
}
BwContact contact = newEv.getContact();
if (contact != null) {
contact = (BwContact) contact.clone();
contact.setOwnerHref(ownerHref);
contact.setCreatorHref(ownerHref);
contact.initUid();
newEv.setContact(contact);
}
if (proxy != null) {
return proxy;
}
return newEv;
}
use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class AttendeeSchedulingHandler method makeReplyEvent.
protected BwEvent makeReplyEvent(final BwEvent origEv, final String ownerHref) throws CalFacadeException {
BwEvent newEv = new BwEventObj();
if (origEv instanceof BwEventProxy) {
getSvc().reAttach(((BwEventProxy) origEv).getRef());
/* we are being asked to copy an instance of a recurring event - rather than
* a complete recurring event + all overrides - clone the master
*/
} else {
getSvc().reAttach(origEv);
}
newEv.setUid(origEv.getUid());
newEv.setOrganizer(origEv.getOrganizer());
newEv.setRecurrenceId(origEv.getRecurrenceId());
newEv.setSequence(origEv.getSequence());
// Attendee and DTSTAMP set by caller?
newEv.setOwnerHref(ownerHref);
newEv.setCreatorHref(ownerHref);
newEv.setDtstamps(getCurrentTimestamp());
// These to get past validation
newEv.setDtstart(origEv.getDtstart());
newEv.setDtend(origEv.getDtend());
newEv.setEndType(origEv.getEndType());
newEv.setDuration(origEv.getDuration());
newEv.setNoStart(origEv.getNoStart());
newEv.setRecurring(false);
// XXX Temp set summary so we have something to display - this may not be
// the case for incoming events from outside
newEv.setSummary(origEv.getSummary());
return newEv;
}
use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class FreeAndBusyHandler method getFreeBusy.
/* (non-Javadoc)
* @see org.bedework.calsvci.SchedulingI#getFreeBusy(java.util.Collection, org.bedework.calfacade.BwPrincipal, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwOrganizer, java.lang.String)
*/
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> fbset, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final BwOrganizer org, final String uid, final String exceptUid) throws CalFacadeException {
CalendarsI colHandler = getSvc().getCalendarsHandler();
Collection<BwCalendar> cals = null;
if (fbset != null) {
/* Don't check - we do so at the fetch of events
getCal().checkAccess(cal, PrivilegeDefs.privReadFreeBusy, false);
*/
cals = addToFreeBusySet(cals, fbset);
} else if (getPrincipal().equals(who)) {
cals = getFreebusySet();
} else {
/* CalDAV uses Inbox to determine scheduling acccess */
try {
getSpecialCalendar(who, BwCalendar.calTypeInbox, true, PrivilegeDefs.privReadFreeBusy);
} catch (CalFacadeAccessException cae) {
getSpecialCalendar(who, BwCalendar.calTypeInbox, true, PrivilegeDefs.privScheduleFreeBusy);
}
cals = addToFreeBusySet(cals, colHandler.getChildren(colHandler.getHome(who, true)));
}
if (cals == null) {
throw new CalFacadeAccessException();
}
BwEvent fb = new BwEventObj();
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
fb.setOwnerHref(who.getPrincipalRef());
fb.setDtstart(start);
fb.setDtend(end);
fb.setEndType(StartEndComponent.endTypeDate);
if (uid == null) {
assignGuid(fb);
} else {
fb.setUid(uid);
}
fb.setDtstamps(getCurrentTimestamp());
String uri = getSvc().getDirectories().principalToCaladdr(who);
BwAttendee att = new BwAttendee();
att.setAttendeeUri(uri);
fb.addAttendee(att);
fb.setOrganizer((BwOrganizer) org.clone());
Collection<EventInfo> events = new TreeSet<EventInfo>();
/* Only events and freebusy for freebusy reports. */
FilterBase filter = new OrFilter();
try {
filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "event", false));
filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "freeAndBusy", false));
} catch (Throwable t) {
throw new CalFacadeException(t);
}
String userHref = who.getPrincipalRef();
for (BwCalendar c : cals) {
if (!c.getAffectsFreeBusy()) {
continue;
}
// XXX If it's an external subscription we probably just get free busy and
// merge it in.
RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded, start, end);
Collection<BwCalendar> cs = new ArrayList<BwCalendar>();
cs.add(c);
Collection<EventInfo> evs = getEvents(cs, filter, start, end, // retrieveList
null, rrm, true);
// Filter out transparent events
for (EventInfo ei : evs) {
BwEvent ev = ei.getEvent();
if ((exceptUid != null) && exceptUid.equals(ev.getUid())) {
continue;
}
if (!c.getIgnoreTransparency() && IcalDefs.transparencyTransparent.equals(ev.getPeruserTransparency(userHref))) {
// Ignore this one.
continue;
}
if (BwEvent.statusCancelled.equals(ev.getStatus())) {
// Ignore this one.
continue;
}
if (ev.getAttendeeSchedulingObject()) {
att = ev.findAttendee(uri);
if (att != null) {
int pstat = IcalDefs.checkPartstat(att.getPartstat());
if (pstat == IcalDefs.partstatDeclined) {
continue;
}
if (pstat == IcalDefs.partstatNeedsAction) {
continue;
}
}
}
events.add(ei);
}
}
try {
EventPeriods eventPeriods = new EventPeriods(start, end);
for (EventInfo ei : events) {
BwEvent ev = ei.getEvent();
int type;
if (ev.getEntityType() == IcalDefs.entityTypeEvent) {
if (BwEvent.statusCancelled.equals(ev.getStatus())) {
// Ignore this one.
continue;
}
type = BwFreeBusyComponent.typeBusy;
if (ev.getAttendeeSchedulingObject()) {
att = ev.findAttendee(uri);
if (att != null) {
if (IcalDefs.checkPartstat(att.getPartstat()) == IcalDefs.partstatTentative) {
type = BwFreeBusyComponent.typeBusyTentative;
}
}
}
if (BwEvent.statusTentative.equals(ev.getStatus())) {
type = BwFreeBusyComponent.typeBusyTentative;
} else if (BwEvent.statusUnavailable.equals(ev.getStatus())) {
type = BwFreeBusyComponent.typeBusyUnavailable;
}
eventPeriods.addPeriod(ev.getDtstart(), ev.getDtend(), type);
} else if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
Collection<BwFreeBusyComponent> fbcs = ev.getFreeBusyPeriods();
for (BwFreeBusyComponent fbc : fbcs) {
type = fbc.getType();
for (Period p : fbc.getPeriods()) {
eventPeriods.addPeriod(p.getStart(), p.getEnd(), type);
}
}
}
}
/* iterate through the sorted periods combining them where they are
adjacent or overlap */
BwFreeBusyComponent fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusy);
if (fbc != null) {
fb.addFreeBusyPeriod(fbc);
}
fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyUnavailable);
if (fbc != null) {
fb.addFreeBusyPeriod(fbc);
}
fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyTentative);
if (fbc != null) {
fb.addFreeBusyPeriod(fbc);
}
} catch (Throwable t) {
if (debug) {
error(t);
}
throw new CalFacadeException(t);
}
return fb;
}
use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getSpecialFreeBusy.
/* (non-Javadoc)
* @see org.bedework.caldav.server.sysinterface.SysIntf#getSpecialFreeBusy(java.lang.String, java.util.Set, java.lang.String, org.bedework.caldav.util.TimeRange, java.io.Writer)
*/
@Override
public void getSpecialFreeBusy(final String cua, final Set<String> recipients, final String originator, final TimeRange tr, final Writer wtr) throws WebdavException {
BwOrganizer org = new BwOrganizer();
org.setOrganizerUri(cua);
BwEvent ev = new BwEventObj();
ev.setDtstart(getBwDt(tr.getStart()));
ev.setDtend(getBwDt(tr.getEnd()));
ev.setEntityType(IcalDefs.entityTypeFreeAndBusy);
ev.setScheduleMethod(ScheduleMethods.methodTypeRequest);
ev.setRecipients(recipients);
ev.setOriginator(originator);
ev.setOrganizer(org);
Collection<SchedRecipientResult> srrs = requestFreeBusy(new BwCalDAVEvent(this, new EventInfo(ev)), false);
for (SchedRecipientResult srr : srrs) {
// We expect one only
BwCalDAVEvent rfb = (BwCalDAVEvent) srr.freeBusy;
if (rfb != null) {
rfb.getEv().setOrganizer(org);
try {
VFreeBusy vfreeBusy = VFreeUtil.toVFreeBusy(rfb.getEv());
net.fortuna.ical4j.model.Calendar ical = IcalTranslator.newIcal(ScheduleMethods.methodTypeReply);
ical.getComponents().add(vfreeBusy);
IcalTranslator.writeCalendar(ical, wtr);
} catch (Throwable t) {
if (debug) {
error(t);
}
throw new WebdavException(t);
}
}
}
}
use of org.bedework.calfacade.BwEventObj in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getFreeBusy.
/* (non-Javadoc)
* @see org.bedework.caldav.server.sysinterface.SysIntf#getFreeBusy(org.bedework.caldav.server.CalDAVCollection, int, org.bedework.caldav.util.TimeRange)
*/
@Override
public CalDAVEvent getFreeBusy(final CalDAVCollection col, final int depth, final TimeRange timeRange) throws WebdavException {
try {
BwCalendar bwCol = unwrap(col);
int calType = bwCol.getCalType();
if (!bwCol.getCollectionInfo().allowFreeBusy) {
throw new WebdavForbidden(WebdavTags.supportedReport);
}
Collection<BwCalendar> cals = new ArrayList<BwCalendar>();
if (calType == BwCalendar.calTypeCalendarCollection) {
cals.add(bwCol);
} else if (depth == 0) {
/* Cannot return anything */
} else {
for (BwCalendar ch : getSvci().getCalendarsHandler().getChildren(bwCol)) {
// For depth 1 we only add calendar collections
if ((depth > 1) || (ch.getCalType() == BwCalendar.calTypeCalendarCollection)) {
cals.add(ch);
}
}
}
AccessPrincipal owner = col.getOwner();
String orgUri;
if (owner instanceof BwPrincipal) {
orgUri = getSvci().getDirectories().principalToCaladdr((BwPrincipal) owner);
} else {
BwPrincipal p = BwPrincipal.makeUserPrincipal();
p.setAccount(owner.getAccount());
orgUri = getSvci().getDirectories().principalToCaladdr(p);
}
BwOrganizer org = new BwOrganizer();
org.setOrganizerUri(orgUri);
BwEvent fb;
if (cals.isEmpty()) {
// Return an empty object
fb = new BwEventObj();
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
fb.setDtstart(getBwDt(timeRange.getStart()));
fb.setDtend(getBwDt(timeRange.getEnd()));
} else {
fb = getSvci().getScheduler().getFreeBusy(cals, (BwPrincipal) currentPrincipal, getBwDt(timeRange.getStart()), getBwDt(timeRange.getEnd()), org, // uid
null, null);
}
EventInfo ei = new EventInfo(fb);
return new BwCalDAVEvent(this, ei);
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
} catch (WebdavException wde) {
throw wde;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
Aggregations