use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class IcalTranslator method addToCalendar.
/* ====================================================================
Private methods
==================================================================== */
private void addToCalendar(final Calendar cal, final EventInfo val, final TreeSet<String> added) throws CalFacadeException {
String currentPrincipal = null;
BwPrincipal principal = cb.getPrincipal();
if (principal != null) {
currentPrincipal = principal.getPrincipalRef();
}
BwEvent ev = val.getEvent();
EventTimeZonesRegistry tzreg = new EventTimeZonesRegistry(this, ev);
if (!cb.getTimezonesByReference()) {
/* Add referenced timezones to the calendar */
addIcalTimezones(cal, ev, added, tzreg);
}
if (!ev.getSuppressed()) {
/* Add it to the calendar */
Component comp;
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
comp = VFreeUtil.toVFreeBusy(ev);
} else {
comp = VEventUtil.toIcalComponent(val, false, tzreg, currentPrincipal);
}
cal.getComponents().add((CalendarComponent) comp);
}
if (val.getNumOverrides() > 0) {
for (final EventInfo oei : val.getOverrides()) {
cal.getComponents().add((CalendarComponent) VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
}
}
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class JcalHandler method outJcal.
public static void outJcal(final Writer wtr, final Collection<EventInfo> vals, final int methodType, final IcalendarType pattern, final String currentPrincipal, final EventTimeZonesRegistry tzreg) throws CalFacadeException {
try {
final JsonGenerator jgen = jsonFactory.createJsonGenerator(wtr);
if (Logger.getLogger(JcalHandler.class).isDebugEnabled()) {
jgen.useDefaultPrettyPrinter();
}
jgen.writeStartArray();
calendarProps(jgen, methodType);
// for components
jgen.writeStartArray();
for (final EventInfo ei : vals) {
BwEvent ev = ei.getEvent();
final Component comp;
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
comp = VFreeUtil.toVFreeBusy(ev);
} else {
comp = VEventUtil.toIcalComponent(ei, false, tzreg, currentPrincipal);
}
outComp(jgen, comp);
if (ei.getNumOverrides() > 0) {
for (final EventInfo oei : ei.getOverrides()) {
ev = oei.getEvent();
outComp(jgen, VEventUtil.toIcalComponent(oei, true, tzreg, currentPrincipal));
}
}
}
// for components
jgen.writeEndArray();
jgen.writeEndArray();
jgen.flush();
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.svc.EventInfo 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.svc.EventInfo 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.svc.EventInfo 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