use of org.bedework.calfacade.BwEvent 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.BwEvent in project bw-calendar-engine by Bedework.
the class IScheduleHandler method sendExternalRequest.
/* External iSchedule requests */
protected void sendExternalRequest(final ScheduleResult sr, final EventInfo ei, final Collection<UserInbox> inboxes) throws CalFacadeException {
/* Each entry in inboxes should have the same hostinfo */
HostInfo hi = null;
final BwEvent ev = ei.getEvent();
final boolean freeBusyRequest = ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy;
Set<String> recipients = null;
/*
class Request {
HostInfo hi;
String url;
String content;
}
*/
final HashMap<String, UserInbox> uimap = new HashMap<>();
/* For realtime or caldav we make up a single meeting request or freebusy request.
* For freebusy url we just execute one url at a time
*/
for (final UserInbox ui : inboxes) {
if (hi == null) {
// First time
hi = ui.host;
if (hi.getSupportsBedework() || hi.getSupportsCaldav() || hi.getSupportsISchedule()) {
recipients = new TreeSet<>();
}
}
if (recipients == null) {
// request per recipient - only freebusy
if (debug) {
trace("freebusy request to " + hi.getFbUrl() + " for " + ui.recipient);
}
} else {
recipients.add(ui.recipient);
uimap.put(ui.recipient, ui);
}
}
if (recipients == null) {
// No ischedule requests
return;
}
if (debug) {
final String meth;
if (freeBusyRequest) {
meth = "freebusy";
} else {
meth = "meeting";
}
trace(meth + " request to " + hi.getFbUrl() + " for " + recipients);
}
final EventInfo cei = copyEventInfo(ei, getPrincipal());
cei.getEvent().setRecipients(recipients);
final Response r;
if (freeBusyRequest) {
try {
r = getCalDavClient().getFreeBusy(hi, cei);
} catch (final CalFacadeException cfe) {
error(cfe);
return;
}
for (final ResponseElement re : r.getResponses()) {
final UserInbox ui = uimap.get(re.getRecipient());
if (ui == null) {
continue;
}
if (re.getCalData() == null) {
ui.setStatus(ScheduleStates.scheduleUnprocessed);
continue;
}
ui.freeBusy = re.getCalData().getEvent();
ui.setStatus(ScheduleStates.scheduleOk);
sr.externalRcs.remove(ui.recipient);
}
return;
}
try {
r = getCalDavClient().scheduleMeeting(hi, cei);
} catch (final CalFacadeException cfe) {
error(cfe);
return;
}
for (final ResponseElement re : r.getResponses()) {
final UserInbox ui = uimap.get(re.getRecipient());
if (ui == null) {
continue;
}
ui.setStatus(ScheduleStates.scheduleOk);
sr.externalRcs.remove(ui.recipient);
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class IscheduleClient method makeMeetingRequest.
private IscheduleOut makeMeetingRequest(final HostInfo hi, final EventInfo ei) throws CalFacadeException {
final BwEvent ev = ei.getEvent();
final IscheduleOut iout = makeIout(hi, "text/calendar", "POST");
addOriginator(iout, ev);
addRecipients(iout, ev);
final Calendar cal = trans.toIcal(ei, ev.getScheduleMethod());
final StringWriter sw = new StringWriter();
IcalTranslator.writeCalendar(cal, sw);
iout.addContentLine(sw.toString());
return iout;
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class ProcessMove method moveEvent.
private void moveEvent(final String fromPath, final String toPath, final String name, final Collection<BwCategory> cats, final Collection<String> aliases, final boolean setname) throws Throwable {
final EventInfo ei = getEvent(fromPath, name);
final BwEvent ev = ei.getEvent();
if (debug) {
final StringBuilder sb = new StringBuilder("Moving event ");
sb.append(ev.getUid());
if (ev.getRecurring()) {
sb.append(" recurring");
}
sb.append(" from ");
sb.append(fromPath);
sb.append(" to ");
sb.append(toPath);
debug(sb.toString());
}
ev.setColPath(toPath);
for (final BwCategory cat : cats) {
ev.addCategory(cat);
}
for (final String alias : aliases) {
final BwXproperty x = new BwXproperty();
x.setName(BwXproperty.bedeworkAlias);
x.setValue(alias);
ev.addXproperty(x);
}
if (setname) {
final String nm = ev.getName();
final String nnm = ev.getUid() + ".ics";
if (!nm.equals(nnm)) {
ev.setName(nnm);
}
}
if (ei.getOverrideProxies() != null) {
for (final BwEvent oev : ei.getOverrideProxies()) {
oev.setColPath(toPath);
}
}
try {
getSvci().getEventsHandler().update(ei, false, null);
} catch (final CalFacadeDupNameException cdne) {
pstate.addError("Duplicate name " + ev.getName() + " uid: " + ev.getUid() + " from: " + fromPath);
}
}
use of org.bedework.calfacade.BwEvent 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);
}
}
}
}
Aggregations