use of org.bedework.calfacade.BwEvent 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.BwEvent in project bw-calendar-engine by Bedework.
the class BwEventUtil method makeNewEvent.
private static EventInfo makeNewEvent(final IcalCallback cb, final int entityType, final String uid, final String colPath) throws CalFacadeException {
final BwEvent ev = new BwEventObj();
final EventInfo evinfo = new EventInfo(ev);
// ev.setDtstamps();
ev.setEntityType(entityType);
ev.setCreatorHref(cb.getPrincipal().getPrincipalRef());
ev.setOwnerHref(cb.getOwner().getPrincipalRef());
ev.setUid(uid);
ev.setColPath(colPath);
final ChangeTable chg = evinfo.getChangeset(cb.getPrincipal().getPrincipalRef());
// get that out of the way
chg.changed(PropertyInfoIndex.UID, null, uid);
evinfo.setNewEvent(true);
return evinfo;
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class BwEventUtil method processCandidates.
private static void processCandidates(final VPoll val, final EventInfo vpoll, final ChangeTable changes) throws CalFacadeException {
try {
final ComponentList cands = val.getCandidates();
if ((cands == null) || cands.isEmpty()) {
return;
}
final Iterator it = cands.iterator();
final Set<Integer> pids = new TreeSet<>();
final BwEvent event = vpoll.getEvent();
if (!Util.isEmpty(event.getPollItems())) {
event.clearPollItems();
}
while (it.hasNext()) {
final Component comp = (Component) it.next();
final String pollItem = comp.toString();
event.addPollItem(pollItem);
changes.addValue(PropertyInfoIndex.POLL_ITEM, pollItem);
final Property p = comp.getProperty(Property.POLL_ITEM_ID);
if (p == null) {
throw new CalFacadeException("XXX - no poll item id");
}
final int pid = ((PollItemId) p).getPollitemid();
if (pids.contains(pid)) {
throw new CalFacadeException("XXX - duplicate poll item id " + pid);
}
pids.add(pid);
// EventInfo cand = toEvent(cb, cal, ical, (Component)o, true,
// false);
// cand.getEvent().setOwnerHref(vpoll.getEvent().getOwnerHref());
// vpoll.addContainedItem(cand);
}
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class BwEventUtil method findMaster.
/* See if the master event is already in the collection of events
* we've processed for this calendar. Only called if we have an event
* with a recurrence id
*/
private static EventInfo findMaster(final String guid, final Collection evs) {
if (evs == null) {
return null;
}
Iterator it = evs.iterator();
while (it.hasNext()) {
EventInfo ei = (EventInfo) it.next();
BwEvent ev = ei.getEvent();
if ((ev.getRecurrenceId() == null) && guid.equals(ev.getUid())) /* &&
ei.getNewEvent() */
{
return ei;
}
}
return null;
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class BwFreeBusyUtil method toFreeBusy.
/**
* @param cb
* @param val
* @return BwFreeBusy
* @throws CalFacadeException
*/
public static EventInfo toFreeBusy(final IcalCallback cb, final VFreeBusy val) throws CalFacadeException {
if (val == null) {
return null;
}
boolean debug = getLog().isDebugEnabled();
try {
PropertyList pl = val.getProperties();
if (pl == null) {
// Empty VEvent
return null;
}
BwEvent fb = new BwEventObj();
EventInfo ei = new EventInfo(fb);
ChangeTable chg = ei.getChangeset(cb.getPrincipal().getPrincipalRef());
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
setDates(cb.getPrincipal().getPrincipalRef(), ei, (DtStart) pl.getProperty(Property.DTSTART), (DtEnd) pl.getProperty(Property.DTEND), (Duration) pl.getProperty(Property.DURATION));
Iterator it = pl.iterator();
while (it.hasNext()) {
Property prop = (Property) it.next();
String pval = prop.getValue();
if ((pval != null) && (pval.length() == 0)) {
pval = null;
}
PropertyInfoIndex pi = PropertyInfoIndex.fromName(prop.getName());
if (pi == null) {
debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
continue;
}
switch(pi) {
case ATTENDEE:
/* ------------------- Attendee -------------------- */
BwAttendee att = getAttendee(cb, (Attendee) prop);
fb.addAttendee(att);
chg.addValue(pi, att);
break;
case COMMENT:
/* ------------------- Comment -------------------- */
// LANG
fb.addComment(null, pval);
chg.addValue(pi, pval);
case DTEND:
break;
case DTSTAMP:
/* ------------------- DtStamp -------------------- */
chg.changed(pi, fb.getDtstamp(), pval);
fb.setDtstamp(pval);
case DTSTART:
break;
case FREEBUSY:
/* ------------------- freebusy -------------------- */
FreeBusy fbusy = (FreeBusy) prop;
PeriodList perpl = fbusy.getPeriods();
Parameter par = getParameter(fbusy, "FBTYPE");
int fbtype;
if (par == null) {
fbtype = BwFreeBusyComponent.typeBusy;
} else if (par.equals(FbType.BUSY)) {
fbtype = BwFreeBusyComponent.typeBusy;
} else if (par.equals(FbType.BUSY_TENTATIVE)) {
fbtype = BwFreeBusyComponent.typeBusyTentative;
} else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
fbtype = BwFreeBusyComponent.typeBusyUnavailable;
} else if (par.equals(FbType.FREE)) {
fbtype = BwFreeBusyComponent.typeFree;
} else {
if (debug) {
debugMsg("Unsupported parameter " + par.getName());
}
throw new IcalMalformedException("parameter " + par.getName());
}
BwFreeBusyComponent fbc = new BwFreeBusyComponent();
fbc.setType(fbtype);
Iterator perit = perpl.iterator();
while (perit.hasNext()) {
Period per = (Period) perit.next();
fbc.addPeriod(per);
}
fb.addFreeBusyPeriod(fbc);
chg.addValue(pi, fbc);
break;
case ORGANIZER:
/* ------------------- Organizer -------------------- */
BwOrganizer org = getOrganizer(cb, (Organizer) prop);
fb.setOrganizer(org);
chg.addValue(pi, org);
break;
case UID:
/* ------------------- Uid -------------------- */
chg.changed(pi, fb.getUid(), pval);
fb.setUid(pval);
break;
default:
if (debug) {
debugMsg("Unsupported property with class " + prop.getClass() + " and value " + pval);
}
}
}
return ei;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations