use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class VAlarmUtil method processComponentAlarms.
/**
* If there are any alarms for this component add them to the events alarm
* collection
*
* @param cb IcalCallback object
* @param val
* @param ev
* @param currentPrincipal - href for current authenticated user
* @param chg
* @throws CalFacadeException
*/
public static void processComponentAlarms(final IcalCallback cb, final Component val, final BwEvent ev, final String currentPrincipal, final ChangeTable chg) throws CalFacadeException {
try {
ComponentList als = null;
if (val instanceof VEvent) {
als = ((VEvent) val).getAlarms();
} else if (val instanceof VToDo) {
als = ((VToDo) val).getAlarms();
} else if (val instanceof VPoll) {
als = ((VPoll) val).getAlarms();
} else {
return;
}
if ((als == null) || als.isEmpty()) {
return;
}
for (Object o : als) {
if (!(o instanceof VAlarm)) {
throw new IcalMalformedException("Invalid alarm list");
}
VAlarm va = (VAlarm) o;
PropertyList pl = va.getProperties();
if (pl == null) {
// Empty VAlarm
throw new IcalMalformedException("Invalid alarm list");
}
Property prop;
BwAlarm al;
/* XXX Handle mozilla alarm stuff in a way that might work better with other clients.
*
*/
prop = pl.getProperty("X-MOZ-LASTACK");
boolean mozlastAck = prop != null;
String mozSnoozeTime = null;
if (mozlastAck) {
prop = pl.getProperty("X-MOZ-SNOOZE-TIME");
if (prop == null) {
// lastack and no snooze - presume dismiss so delete alarm
continue;
}
// UTC time
mozSnoozeTime = prop.getValue();
}
// All alarm types require action and trigger
prop = pl.getProperty(Property.ACTION);
if (prop == null) {
throw new IcalMalformedException("Invalid alarm");
}
String actionStr = prop.getValue();
TriggerVal tr = getTrigger(pl, "NONE".equals(actionStr));
if (mozSnoozeTime != null) {
tr.trigger = mozSnoozeTime;
tr.triggerDateTime = true;
tr.triggerStart = false;
}
DurationRepeat dr = getDurationRepeat(pl);
if ("EMAIL".equals(actionStr)) {
al = BwAlarm.emailAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"), getReqStr(pl, "DESCRIPTION"), getReqStr(pl, "SUMMARY"), null);
Iterator<?> atts = getReqStrs(pl, "ATTENDEE");
while (atts.hasNext()) {
al.addAttendee(getAttendee(cb, (Attendee) atts.next()));
}
} else if ("AUDIO".equals(actionStr)) {
al = BwAlarm.audioAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"));
} else if ("DISPLAY".equals(actionStr)) {
al = BwAlarm.displayAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "DESCRIPTION"));
} else if ("PROCEDURE".equals(actionStr)) {
al = BwAlarm.procedureAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "ATTACH"), getOptStr(pl, "DESCRIPTION"));
} else if ("NONE".equals(actionStr)) {
al = BwAlarm.noneAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
} else {
al = BwAlarm.otherAlarm(ev, ev.getCreatorHref(), actionStr, tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
}
/* Mozilla is add xprops to the containing event to set the snooze time.
* Seems wrong - there could be multiple alarms.
*
* We possibly want to try this sort of trick..
prop = pl.getProperty("X-MOZ-LASTACK");
boolean mozlastAck = prop != null;
String mozSnoozeTime = null;
if (mozlastAck) {
prop = pl.getProperty("X-MOZ-SNOOZE-TIME");
if (prop == null) {
// lastack and no snooze - presume dismiss so delete alarm
continue;
}
mozSnoozeTime = prop.getValue(); // UTC time
}
...
TriggerVal tr = getTrigger(pl);
if (mozSnoozeTime != null) {
tr.trigger = mozSnoozeTime;
tr.triggerDateTime = true;
tr.triggerStart = false;
}
*/
Iterator it = pl.iterator();
while (it.hasNext()) {
prop = (Property) it.next();
if (prop instanceof XProperty) {
/* ------------------------- x-property --------------------------- */
XProperty xp = (XProperty) prop;
al.addXproperty(new BwXproperty(xp.getName(), xp.getParameters().toString(), xp.getValue()));
continue;
}
if (prop instanceof Uid) {
Uid p = (Uid) prop;
al.addXproperty(BwXproperty.makeIcalProperty(p.getName(), p.getParameters().toString(), p.getValue()));
continue;
}
}
al.setEvent(ev);
al.setOwnerHref(currentPrincipal);
chg.addValue(PropertyInfoIndex.VALARM, al);
}
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class VAlarmUtil method setAlarm.
private static VAlarm setAlarm(final BwEvent ev, final BwAlarm val) throws CalFacadeException {
try {
VAlarm alarm = new VAlarm();
int atype = val.getAlarmType();
String action;
if (atype != BwAlarm.alarmTypeOther) {
action = BwAlarm.alarmTypes[atype];
} else {
List<BwXproperty> xps = val.getXicalProperties("ACTION");
action = xps.get(0).getValue();
}
addProperty(alarm, new Action(action));
if (val.getTriggerDateTime()) {
DateTime dt = new DateTime(val.getTrigger());
addProperty(alarm, new Trigger(dt));
} else {
Trigger tr = new Trigger(new Dur(val.getTrigger()));
if (!val.getTriggerStart()) {
addParameter(tr, Related.END);
} else {
// Not required - it's the default - but we fail some Cyrus tests otherwise
// Apparently Cyrus now handles the default state correctly
// addParameter(tr, Related.START);
}
addProperty(alarm, tr);
}
if (val.getDuration() != null) {
addProperty(alarm, new Duration(new Dur(val.getDuration())));
addProperty(alarm, new Repeat(val.getRepeat()));
}
if (atype == BwAlarm.alarmTypeAudio) {
if (val.getAttach() != null) {
addProperty(alarm, new Attach(new URI(val.getAttach())));
}
} else if (atype == BwAlarm.alarmTypeDisplay) {
// checkRequiredProperty(val.getDescription(), "alarm-description");
if (val.getDescription() != null) {
addProperty(alarm, new Description(val.getDescription()));
} else {
addProperty(alarm, new Description(ev.getSummary()));
}
} else if (atype == BwAlarm.alarmTypeEmail) {
if (val.getAttach() != null) {
addProperty(alarm, new Attach(new URI(val.getAttach())));
}
checkRequiredProperty(val.getDescription(), "alarm-description");
addProperty(alarm, new Description(val.getDescription()));
checkRequiredProperty(val.getSummary(), "alarm-summary");
addProperty(alarm, new Summary(val.getSummary()));
if (val.getNumAttendees() > 0) {
for (BwAttendee att : val.getAttendees()) {
addProperty(alarm, setAttendee(att));
}
}
} else if (atype == BwAlarm.alarmTypeProcedure) {
checkRequiredProperty(val.getAttach(), "alarm-attach");
addProperty(alarm, new Attach(new URI(val.getAttach())));
if (val.getDescription() != null) {
addProperty(alarm, new Description(val.getDescription()));
}
} else {
if (val.getDescription() != null) {
addProperty(alarm, new Description(val.getDescription()));
}
}
if (val.getNumXproperties() > 0) {
/* This event has x-props */
IcalUtil.xpropertiesToIcal(alarm.getProperties(), val.getXproperties());
}
return alarm;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class VEventUtil method toIcalComponent.
/**
* Make an Icalendar component from a BwEvent object. This may produce a
* VEvent, VTodo, VJournal or VPoll.
*
* @param ei the event
* @param isOverride - true if event object is an override
* @param tzreg - timezone registry
* @param currentPrincipal - href for current authenticated user
* @return Component
* @throws CalFacadeException
*/
public static Component toIcalComponent(final EventInfo ei, final boolean isOverride, final TimeZoneRegistry tzreg, final String currentPrincipal) throws CalFacadeException {
if ((ei == null) || (ei.getEvent() == null)) {
return null;
}
final BwEvent val = ei.getEvent();
boolean isInstance = false;
try {
Component xcomp = null;
Calendar cal = null;
final List<BwXproperty> xcompProps = val.getXproperties(BwXproperty.bedeworkIcal);
if (!Util.isEmpty(xcompProps)) {
final BwXproperty xcompProp = xcompProps.get(0);
final String xcompPropVal = xcompProp.getValue();
if (xcompPropVal != null) {
final StringBuilder sb = new StringBuilder();
final Icalendar ic = new Icalendar();
try {
sb.append("BEGIN:VCALENDAR\n");
sb.append(Version.VERSION_2_0.toString());
sb.append("\n");
sb.append(xcompPropVal);
if (!xcompPropVal.endsWith("\n")) {
sb.append("\n");
}
sb.append("END:VCALENDAR\n");
CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
UnfoldingReader ufrdr = new UnfoldingReader(new StringReader(sb.toString()), true);
cal = bldr.build(ufrdr);
} catch (Throwable t) {
error(t);
error("Trying to parse:\n" + xcompPropVal);
}
}
}
Component comp;
PropertyList pl = new PropertyList();
boolean freeBusy = false;
boolean vavail = false;
boolean todo = false;
boolean vpoll = false;
int entityType = val.getEntityType();
if (entityType == IcalDefs.entityTypeEvent) {
comp = new VEvent(pl);
} else if (entityType == IcalDefs.entityTypeTodo) {
comp = new VToDo(pl);
todo = true;
} else if (entityType == IcalDefs.entityTypeJournal) {
comp = new VJournal(pl);
} else if (entityType == IcalDefs.entityTypeFreeAndBusy) {
comp = new VFreeBusy(pl);
freeBusy = true;
} else if (entityType == IcalDefs.entityTypeVavailability) {
comp = new VAvailability(pl);
vavail = true;
} else if (entityType == IcalDefs.entityTypeAvailable) {
comp = new Available(pl);
} else if (entityType == IcalDefs.entityTypeVpoll) {
comp = new VPoll(pl);
vpoll = true;
} else {
throw new CalFacadeException("org.bedework.invalid.entity.type", String.valueOf(entityType));
}
if (cal != null) {
xcomp = cal.getComponent(comp.getName());
}
Property prop;
/* ------------------- RecurrenceID --------------------
* Done early so we know if this is an instance.
*/
String strval = val.getRecurrenceId();
if ((strval != null) && (strval.length() > 0)) {
isInstance = true;
pl.add(new RecurrenceId(makeZonedDt(val, strval)));
}
/* ------------------- Alarms -------------------- */
VAlarmUtil.processEventAlarm(val, comp, currentPrincipal);
/* ------------------- Attachments -------------------- */
if (val.getNumAttachments() > 0) {
for (BwAttachment att : val.getAttachments()) {
pl.add(setAttachment(att));
}
}
/* ------------------- Attendees -------------------- */
if (!vpoll && (val.getNumAttendees() > 0)) {
for (BwAttendee att : val.getAttendees()) {
prop = setAttendee(att);
mergeXparams(prop, xcomp);
pl.add(prop);
}
}
if (val.getNumCategories() > 0) {
// LANG - filter on language - group language in one cat list?
for (BwCategory cat : val.getCategories()) {
prop = new Categories();
TextList cl = ((Categories) prop).getCategories();
cl.add(cat.getWord().getValue());
pl.add(langProp(prop, cat.getWord()));
}
}
/* ------------------- Class -------------------- */
final String pval = val.getClassification();
if (pval != null) {
pl.add(new Clazz(pval));
}
if (val.getNumComments() > 0) {
for (final BwString str : val.getComments()) {
pl.add(langProp(new Comment(str.getValue()), str));
}
}
if ((todo || vpoll) && (val.getCompleted() != null)) {
prop = new Completed(new DateTime(val.getCompleted()));
pl.add(prop);
}
if (val.getNumContacts() > 0) {
for (final BwContact c : val.getContacts()) {
// LANG
prop = new Contact(c.getCn().getValue());
final String l = c.getLink();
if (l != null) {
prop.getParameters().add(new AltRep(l));
}
pl.add(langProp(uidProp(prop, c.getUid()), c.getCn()));
}
}
if (val.getCost() != null) {
IcalUtil.addXproperty(pl, BwXproperty.bedeworkCost, null, val.getCost());
}
/* ------------------- Created -------------------- */
prop = new Created(val.getCreated());
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (val.getDeleted()) {
IcalUtil.addXproperty(pl, BwXproperty.bedeworkDeleted, null, String.valueOf(val.getDeleted()));
}
/* ------------------- Description -------------------- */
BwStringBase bwstr = val.findDescription(null);
if (bwstr != null) {
pl.add(langProp(new Description(bwstr.getValue()), bwstr));
}
if (val.getEndType() == StartEndComponent.endTypeDate) {
if (todo) {
Due due = val.getDtend().makeDue(tzreg);
if (freeBusy | val.getForceUTC()) {
due.setUtc(true);
}
pl.add(due);
} else {
DtEnd dtend = val.getDtend().makeDtEnd(tzreg);
if (freeBusy | val.getForceUTC()) {
dtend.setUtc(true);
}
pl.add(dtend);
}
} else if (val.getEndType() == StartEndComponent.endTypeDuration) {
addProperty(comp, new Duration(new Dur(val.getDuration())));
}
/* ------------------- DtStamp -------------------- */
prop = new DtStamp(new DateTime(val.getDtstamp()));
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (!val.getNoStart()) {
DtStart dtstart = val.getDtstart().makeDtStart(tzreg);
if (freeBusy | val.getForceUTC()) {
dtstart.setUtc(true);
}
pl.add(dtstart);
}
if (freeBusy) {
Collection<BwFreeBusyComponent> fbps = val.getFreeBusyPeriods();
if (fbps != null) {
for (BwFreeBusyComponent fbc : fbps) {
FreeBusy fb = new FreeBusy();
int type = fbc.getType();
if (type == BwFreeBusyComponent.typeBusy) {
addParameter(fb, FbType.BUSY);
} else if (type == BwFreeBusyComponent.typeFree) {
addParameter(fb, FbType.FREE);
} else if (type == BwFreeBusyComponent.typeBusyUnavailable) {
addParameter(fb, FbType.BUSY_UNAVAILABLE);
} else if (type == BwFreeBusyComponent.typeBusyTentative) {
addParameter(fb, FbType.BUSY_TENTATIVE);
} else {
throw new CalFacadeException("Bad free-busy type " + type);
}
PeriodList pdl = fb.getPeriods();
for (Period p : fbc.getPeriods()) {
// XXX inverse.ca plugin cannot handle durations.
Period np = new Period(p.getStart(), p.getEnd());
pdl.add(np);
}
pl.add(fb);
}
}
}
if (!vpoll) {
BwGeo bwgeo = val.getGeo();
if (bwgeo != null) {
Geo geo = new Geo(bwgeo.getLatitude(), bwgeo.getLongitude());
pl.add(geo);
}
}
/* ------------------- LastModified -------------------- */
prop = new LastModified(new DateTime(val.getLastmod()));
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (!vpoll) {
final BwLocation loc = val.getLocation();
if (loc != null) {
prop = new Location(loc.getCombinedValues());
pl.add(langProp(uidProp(prop, loc.getUid()), loc.getAddress()));
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAddr, null, loc.getAddressField());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationRoom, null, loc.getRoomField());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAccessible, null, String.valueOf(loc.getAccessible()));
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield1, null, loc.getSubField1());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield2, null, loc.getSubField2());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationGeo, null, loc.getGeouri());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationStreet, null, loc.getStreet());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationCity, null, loc.getCity());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationState, null, loc.getState());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationZip, null, loc.getZip());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationLink, null, loc.getLink());
}
}
/* ------------------- Organizer -------------------- */
BwOrganizer org = val.getOrganizer();
if (org != null) {
prop = setOrganizer(org);
mergeXparams(prop, xcomp);
pl.add(prop);
}
if (todo) {
Integer pc = val.getPercentComplete();
if (pc != null) {
pl.add(new PercentComplete(pc.intValue()));
}
}
/* ------------------- Priority -------------------- */
Integer prio = val.getPriority();
if (prio != null) {
pl.add(new Priority(prio.intValue()));
}
/* ------------------- RDate -below------------------- */
/* ------------------- RelatedTo -------------------- */
/* We encode related to (maybe) as triples - reltype, value-type, value */
String[] info = null;
BwRelatedTo relto = val.getRelatedTo();
if (relto != null) {
info = new String[3];
info[0] = relto.getRelType();
// default
info[1] = "";
info[2] = relto.getValue();
} else {
String relx = val.getXproperty(BwXproperty.bedeworkRelatedTo);
if (relx != null) {
info = Util.decodeArray(relx);
}
}
if (info != null) {
int i = 0;
while (i < info.length) {
RelatedTo irelto;
String reltype = info[i];
String valtype = info[i + 1];
String relval = info[i + 2];
ParameterList rtpl = null;
if (reltype.length() > 0) {
rtpl = new ParameterList();
rtpl.add(new RelType(reltype));
}
if (valtype.length() > 0) {
if (rtpl == null) {
rtpl = new ParameterList();
}
rtpl.add(new Value(valtype));
}
if (rtpl != null) {
irelto = new RelatedTo(rtpl, relval);
} else {
irelto = new RelatedTo(relval);
}
pl.add(irelto);
i += 3;
}
}
if (val.getNumResources() > 0) {
/* This event has a resource */
prop = new Resources();
TextList rl = ((Resources) prop).getResources();
for (BwString str : val.getResources()) {
// LANG
rl.add(str.getValue());
}
pl.add(prop);
}
if (val.getSequence() > 0) {
pl.add(new Sequence(val.getSequence()));
}
/* ------------------- Status -------------------- */
String status = val.getStatus();
if ((status != null) && !status.equals(BwEvent.statusMasterSuppressed)) {
pl.add(new Status(status));
}
/* ------------------- Summary -------------------- */
bwstr = val.findSummary(null);
if (bwstr != null) {
pl.add(langProp(new Summary(bwstr.getValue()), bwstr));
}
if (!todo && !vpoll) {
strval = val.getPeruserTransparency(currentPrincipal);
if ((strval != null) && (strval.length() > 0)) {
pl.add(new Transp(strval));
}
}
/* ------------------- Uid -------------------- */
pl.add(new Uid(val.getUid()));
/* ------------------- Url -------------------- */
strval = val.getLink();
if (strval != null) {
// Possibly drop this if we do it on input and check all data
strval = strval.trim();
}
if ((strval != null) && (strval.length() > 0)) {
URI uri = Util.validURI(strval);
if (uri != null) {
pl.add(new Url(uri));
}
}
if (val.getNumXproperties() > 0) {
try {
IcalUtil.xpropertiesToIcal(pl, val.getXproperties());
} catch (Throwable t) {
// XXX For the moment swallow these.
error(t);
}
}
if (!vpoll && !isInstance && !isOverride && val.testRecurring()) {
doRecurring(val, pl);
}
if (vavail) {
if (ei.getNumContainedItems() > 0) {
final VAvailability va = (VAvailability) comp;
for (final EventInfo aei : ei.getContainedItems()) {
va.getAvailable().add((Available) toIcalComponent(aei, false, tzreg, currentPrincipal));
}
}
/* ----------- Vavailability - busyType ----------------- */
String s = val.getBusyTypeString();
if (s != null) {
pl.add(new BusyType(s));
}
}
if (vpoll) {
final Integer ival = val.getPollWinner();
if (ival != null) {
pl.add(new PollWinner(ival));
}
strval = val.getPollAcceptResponse();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new AcceptResponse(strval));
}
strval = val.getPollMode();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new PollMode(strval));
}
strval = val.getPollProperties();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new PollProperties(strval));
}
final Map<String, VVoter> vvoters = parseVpollVvoters(val);
for (final VVoter vv : vvoters.values()) {
((VPoll) comp).getVoters().add(vv);
}
final Map<Integer, Component> comps = parseVpollCandidates(val);
for (final Component candidate : comps.values()) {
((VPoll) comp).getCandidates().add(candidate);
}
}
return comp;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class Xutil method xpropertiesToXcal.
/**
* @param pl
* @param xprops
* @param pattern
* @param masterClass
* @param wrapXprops wrap x-properties in bedework object - allows
* us to push them through soap
* @throws Throwable
*/
@SuppressWarnings("deprecation")
public static void xpropertiesToXcal(final List<JAXBElement<? extends BasePropertyType>> pl, final List<BwXproperty> xprops, final BaseComponentType pattern, final Class masterClass, final boolean wrapXprops) throws Throwable {
for (final BwXproperty x : xprops) {
// Skip any timezone we saved in the event.
final String xname = x.getName();
final String val = x.getValue();
if (xname.startsWith(BwXproperty.bedeworkTimezonePrefix)) {
continue;
}
if (xname.equals(BwXproperty.bedeworkExsynchEndtzid)) {
if (!emit(pattern, masterClass, XBedeworkExsynchEndtzidPropType.class)) {
continue;
}
final XBedeworkExsynchEndtzidPropType p = new XBedeworkExsynchEndtzidPropType();
p.setText(val);
pl.add(of.createXBedeworkExsynchEndtzid(p));
continue;
}
if (xname.equals(BwXproperty.bedeworkExsynchLastmod)) {
if (!emit(pattern, masterClass, XBedeworkExsynchLastmodPropType.class)) {
continue;
}
final XBedeworkExsynchLastmodPropType p = new XBedeworkExsynchLastmodPropType();
p.setText(val);
pl.add(of.createXBedeworkExsynchLastmod(p));
continue;
}
if (xname.equals(BwXproperty.bedeworkExsynchOrganizer)) {
continue;
}
if (xname.equals(BwXproperty.bedeworkExsynchStarttzid)) {
if (!emit(pattern, masterClass, XBedeworkExsynchStarttzidPropType.class)) {
continue;
}
final XBedeworkExsynchStarttzidPropType p = new XBedeworkExsynchStarttzidPropType();
p.setText(val);
pl.add(of.createXBedeworkExsynchStarttzid(p));
continue;
}
if (xname.equals(BwXproperty.bedeworkEventRegStart)) {
if (!emit(pattern, masterClass, XBedeworkRegistrationStartPropType.class)) {
continue;
}
final XBedeworkRegistrationStartPropType p = new XBedeworkRegistrationStartPropType();
String tzid = null;
for (final Xpar xp : x.getParameters()) {
if (xp.getName().equalsIgnoreCase("TZID")) {
tzid = xp.getValue();
break;
}
}
XcalUtil.initDt(p, val, tzid);
pl.add(of.createXBedeworkRegistrationStart(p));
continue;
}
if (xname.equals(BwXproperty.bedeworkEventRegEnd)) {
if (!emit(pattern, masterClass, XBedeworkRegistrationEndPropType.class)) {
continue;
}
final XBedeworkRegistrationEndPropType p = new XBedeworkRegistrationEndPropType();
String tzid = null;
for (final Xpar xp : x.getParameters()) {
if (xp.getName().equalsIgnoreCase("TZID")) {
tzid = xp.getValue();
break;
}
}
XcalUtil.initDt(p, val, tzid);
pl.add(of.createXBedeworkRegistrationEnd(p));
continue;
}
if (xname.equals(BwXproperty.bedeworkEventRegMaxTickets)) {
if (!emit(pattern, masterClass, XBedeworkMaxTicketsPropType.class)) {
continue;
}
final XBedeworkMaxTicketsPropType p = new XBedeworkMaxTicketsPropType();
p.setInteger(BigInteger.valueOf(Long.valueOf(val)));
pl.add(of.createXBedeworkMaxTickets(p));
continue;
}
if (xname.equals(BwXproperty.bedeworkEventRegMaxTicketsPerUser)) {
if (!emit(pattern, masterClass, XBedeworkMaxTicketsPerUserPropType.class)) {
continue;
}
final XBedeworkMaxTicketsPerUserPropType p = new XBedeworkMaxTicketsPerUserPropType();
p.setInteger(BigInteger.valueOf(Long.valueOf(val)));
pl.add(of.createXBedeworkMaxTicketsPerUser(p));
continue;
}
if (xname.equals(BwXproperty.bedeworkEventRegWaitListLimit)) {
if (!emit(pattern, masterClass, XBedeworkWaitListLimitPropType.class)) {
continue;
}
final XBedeworkWaitListLimitPropType p = new XBedeworkWaitListLimitPropType();
p.setText(val);
pl.add(of.createXBedeworkWaitListLimit(p));
continue;
}
if (xname.equals(BwXproperty.xBedeworkCategories)) {
if (!emit(pattern, masterClass, XBwCategoriesPropType.class)) {
continue;
}
final XBwCategoriesPropType p = new XBwCategoriesPropType();
p.getText().add(val);
pl.add(of.createXBedeworkCategories(p));
continue;
}
if (xname.equals(BwXproperty.xBedeworkContact)) {
if (!emit(pattern, masterClass, XBwContactPropType.class)) {
continue;
}
final XBwContactPropType p = new XBwContactPropType();
p.setText(val);
pl.add(of.createXBedeworkContact(p));
continue;
}
if (xname.equals(BwXproperty.xBedeworkLocation)) {
if (!emit(pattern, masterClass, XBwLocationPropType.class)) {
continue;
}
final XBwLocationPropType p = new XBwLocationPropType();
p.setText(val);
pl.add(of.createXBedeworkLocation(p));
continue;
}
if (!wrapXprops) {
if (getLog().isDebugEnabled()) {
warn("Not handing x-property " + xname);
}
continue;
}
final XBedeworkWrapperPropType wrapper = new XBedeworkWrapperPropType();
if (x.getParameters() != null) {
for (final Xpar xp : x.getParameters()) {
xparam(wrapper, xp);
}
}
final XBedeworkWrappedNameParamType wnp = new XBedeworkWrappedNameParamType();
wnp.setText(x.getName());
if (wrapper.getParameters() == null) {
wrapper.setParameters(new ArrayOfParameters());
}
wrapper.getParameters().getBaseParameter().add(of.createXBedeworkWrappedName(wnp));
wrapper.setText(val);
pl.add(of.createXBedeworkWrapper(wrapper));
}
}
use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.
the class Events method setScheduleState.
/* Flag this as an attendee scheduling object or an organizer scheduling object
*/
private void setScheduleState(final BwEvent ev, final boolean adding, final boolean schedulingInbox) throws CalFacadeException {
ev.setOrganizerSchedulingObject(false);
ev.setAttendeeSchedulingObject(false);
if ((ev.getEntityType() != IcalDefs.entityTypeEvent) && (ev.getEntityType() != IcalDefs.entityTypeTodo) && (ev.getEntityType() != IcalDefs.entityTypeVpoll)) {
// Not a possible scheduling entity
return;
}
final BwOrganizer org = ev.getOrganizer();
final Set<BwAttendee> atts = ev.getAttendees();
if (Util.isEmpty(atts) || (org == null)) {
return;
}
final String curPrincipal = getSvc().getPrincipal().getPrincipalRef();
final Directories dirs = getSvc().getDirectories();
AccessPrincipal evPrincipal = dirs.caladdrToPrincipal(org.getOrganizerUri());
if ((evPrincipal != null) && (evPrincipal.getPrincipalRef().equals(curPrincipal))) {
ev.setOrganizerSchedulingObject(true);
/* If we are expanding groups do so here */
final ChangeTable chg = ev.getChangeset(getPrincipalHref());
final Set<BwAttendee> groups = new TreeSet<>();
if (!schedulingInbox) {
final ChangeTableEntry cte = chg.getEntry(PropertyInfoIndex.ATTENDEE);
checkAttendees: for (final BwAttendee att : atts) {
if (CuType.GROUP.getValue().equals(att.getCuType())) {
groups.add(att);
}
final AccessPrincipal attPrincipal = getSvc().getDirectories().caladdrToPrincipal(att.getAttendeeUri());
if ((attPrincipal != null) && (attPrincipal.getPrincipalRef().equals(curPrincipal))) {
// It's us
continue;
}
if (att.getPartstat().equals(IcalDefs.partstatValNeedsAction)) {
continue;
}
if (adding) {
// Can't add an event with attendees set to accepted
att.setPartstat(IcalDefs.partstatValNeedsAction);
continue;
}
// Not adding event. Did we add attendee?
if ((cte != null) && !Util.isEmpty(cte.getAddedValues())) {
for (final Object o : cte.getAddedValues()) {
final BwAttendee chgAtt = (BwAttendee) o;
if (chgAtt.getCn().equals(att.getCn())) {
att.setPartstat(IcalDefs.partstatValNeedsAction);
continue checkAttendees;
}
}
}
}
}
try {
/* If this is a vpoll we need the vvoters as we are going to
have to remove the group vvoter entry and clone it for the
attendees we add.
I think this will work for any poll mode - if not we may
have to rethink this approach.
*/
Map<String, VVoter> voters = null;
final boolean vpoll;
if (ev.getEntityType() == IcalDefs.entityTypeVpoll) {
voters = IcalUtil.parseVpollVvoters(ev);
// We'll add them all back
ev.clearVvoters();
vpoll = true;
} else {
vpoll = false;
}
for (final BwAttendee att : groups) {
/* If the group is in one of our domains we can try to expand it.
* We should leave it if it's an external id.
*/
final Holder<Boolean> trunc = new Holder<>();
final List<BwPrincipalInfo> groupPis = dirs.find(att.getAttendeeUri(), att.getCuType(), // expand
true, trunc);
if ((groupPis == null) || (groupPis.size() != 1)) {
continue;
}
final BwPrincipalInfo pi = groupPis.get(0);
if (pi.getMembers() == null) {
continue;
}
VVoter groupVvoter = null;
Voter groupVoter = null;
PropertyList pl = null;
if (vpoll) {
groupVvoter = voters.get(att.getAttendeeUri());
if (groupVvoter == null) {
if (debug) {
warn("No vvoter found for " + att.getAttendeeUri());
}
continue;
}
voters.remove(att.getAttendeeUri());
groupVoter = groupVvoter.getVoter();
pl = groupVvoter.getProperties();
}
// Remove the group
ev.removeAttendee(att);
chg.changed(PropertyInfoIndex.ATTENDEE, att, null);
for (final BwPrincipalInfo mbrPi : pi.getMembers()) {
if (mbrPi.getCaladruri() == null) {
continue;
}
final BwAttendee mbrAtt = new BwAttendee();
mbrAtt.setType(att.getType());
mbrAtt.setAttendeeUri(mbrPi.getCaladruri());
mbrAtt.setCn(mbrPi.getEmail());
mbrAtt.setCuType(mbrPi.getKind());
mbrAtt.setMember(att.getAttendeeUri());
ev.addAttendee(mbrAtt);
chg.addValue(PropertyInfoIndex.ATTENDEE, mbrAtt);
if (vpoll) {
pl.remove(groupVoter);
groupVoter = IcalUtil.setVoter(mbrAtt);
pl.add(groupVoter);
ev.addVvoter(groupVvoter.toString());
}
}
}
if (vpoll) {
// Add back any remaining vvoters
for (VVoter vv : voters.values()) {
ev.addVvoter(vv.toString());
}
}
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
if (ev instanceof BwEventProxy) {
// Only add x-property to master
return;
}
if (CalFacadeDefs.jasigSchedulingAssistant.equals(getPars().getClientId())) {
ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedAssist, null, "true"));
}
return;
}
for (final BwAttendee att : atts) {
/* See if at least one attendee is us */
evPrincipal = getSvc().getDirectories().caladdrToPrincipal(att.getAttendeeUri());
if ((evPrincipal != null) && (evPrincipal.getPrincipalRef().equals(curPrincipal))) {
ev.setAttendeeSchedulingObject(true);
break;
}
}
}
Aggregations