use of net.fortuna.ical4j.model.property.Attendee 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 net.fortuna.ical4j.model.property.Attendee in project bw-calendar-engine by Bedework.
the class IcalUtil method setAttendee.
/**
* make an attendee
*
* @param val BwAttendee to build from
* @return Attendee
* @throws Throwable
*/
public static Attendee setAttendee(final BwAttendee val) throws Throwable {
final Attendee prop = new Attendee(val.getAttendeeUri());
final ParameterList pars = prop.getParameters();
setAttendeeVoter(val, pars);
final String temp = val.getPartstat();
if ((temp != null) && !temp.equals(IcalDefs.partstatValNeedsAction)) {
// Not default value.
pars.add(new PartStat(temp));
}
return prop;
}
use of net.fortuna.ical4j.model.property.Attendee in project ofbiz-framework by apache.
the class ICalConverter method loadRelatedParties.
protected static void loadRelatedParties(List<GenericValue> relatedParties, PropertyList componentProps, Map<String, Object> context) {
PropertyList attendees = componentProps.getProperties("ATTENDEE");
for (GenericValue partyValue : relatedParties) {
if ("CAL_ORGANIZER~CAL_OWNER".contains(partyValue.getString("roleTypeId"))) {
// RFC 2445 4.6.1, 4.6.2, and 4.6.3 ORGANIZER can appear only once
replaceProperty(componentProps, createOrganizer(partyValue, context));
} else {
String partyId = partyValue.getString("partyId");
boolean newAttendee = true;
Attendee attendee = null;
Iterator<Attendee> i = UtilGenerics.cast(attendees.iterator());
while (i.hasNext()) {
attendee = i.next();
Parameter xParameter = attendee.getParameter(partyIdXParamName);
if (xParameter != null && partyId.equals(xParameter.getValue())) {
loadPartyAssignment(attendee, partyValue, context);
newAttendee = false;
break;
}
}
if (newAttendee) {
attendee = createAttendee(partyValue, context);
componentProps.add(attendee);
}
}
}
}
use of net.fortuna.ical4j.model.property.Attendee in project zm-mailbox by Zimbra.
the class DefaultTnefToICalendar method addAttendee.
/**
* @param icalOutput
* @param ia
* @param role
* @param cuType
* @param partstat
* @param rsvp
* @throws URISyntaxException
* @throws ParserException
* @throws IOException
* @throws ParseException
*/
private void addAttendee(ContentHandler icalOutput, InternetAddress ia, Role role, CuType cuType, PartStat partstat, boolean rsvp) throws URISyntaxException, ParserException, IOException, ParseException {
String email = ia.getAddress();
String displayName = ia.getPersonal();
Attendee attendee = new Attendee("Mailto:" + email);
if ((displayName != null) && (!displayName.equals(email))) {
Cn cn = new Cn(displayName);
attendee.getParameters().add(cn);
}
if (rsvp) {
attendee.getParameters().add(Rsvp.TRUE);
}
attendee.getParameters().add(role);
attendee.getParameters().add(cuType);
if (partstat != null) {
attendee.getParameters().add(partstat);
}
IcalUtil.addProperty(icalOutput, attendee);
}
use of net.fortuna.ical4j.model.property.Attendee in project zm-mailbox by Zimbra.
the class DefaultTnefToICalendar method addAttendees.
/**
* @param icalOutput
* @param mimeMsg
* @param partstat
* @param replyWanted
* @throws ParserException
* @throws URISyntaxException
* @throws IOException
* @throws ParseException
* @throws MessagingException
*/
private void addAttendees(ContentHandler icalOutput, MimeMessage mimeMsg, PartStat partstat, boolean replyWanted) throws ParserException, URISyntaxException, IOException, ParseException, MessagingException {
// ATTENDEEs
InternetAddress firstFromIA = null;
String firstFromEmailAddr = null;
// Use for SENT-BY if applicable
String senderMailto = null;
String senderCn = null;
javax.mail.Address[] toRecips = null;
javax.mail.Address[] ccRecips = null;
javax.mail.Address[] bccRecips = null;
javax.mail.Address[] msgFroms = null;
javax.mail.Address msgSender = null;
if (mimeMsg != null) {
toRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.TO);
ccRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.CC);
bccRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.BCC);
msgFroms = mimeMsg.getFrom();
msgSender = mimeMsg.getSender();
}
if (msgFroms != null) {
if (msgFroms.length != 1) {
sLog.debug(msgFroms.length + " From: recipients for " + method.getValue());
}
if (msgFroms.length >= 1) {
firstFromIA = (InternetAddress) msgFroms[0];
firstFromEmailAddr = firstFromIA.getAddress();
}
if (msgSender != null) {
String senderAddr = msgSender.toString();
if (msgSender instanceof InternetAddress) {
InternetAddress senderIA = (InternetAddress) msgSender;
senderAddr = senderIA.getAddress();
senderCn = senderIA.getPersonal();
if (!firstFromIA.equals(senderIA)) {
senderMailto = "Mailto:" + senderAddr;
}
}
}
}
if (method.equals(Method.REPLY) || method.equals(Method.COUNTER)) {
// from ATTENDEE to ORGANIZER
if (toRecips != null) {
if (toRecips.length != 1) {
sLog.debug(toRecips.length + " To: recipients for " + method.getValue());
}
if (toRecips.length >= 1) {
InternetAddress ia = (InternetAddress) toRecips[0];
String email = ia.getAddress();
String displayName = ia.getPersonal();
icalOutput.startProperty(Property.ORGANIZER);
icalOutput.propertyValue("Mailto:" + email);
if (displayName != null) {
icalOutput.parameter(Parameter.CN, displayName);
}
icalOutput.endProperty(Property.ORGANIZER);
}
}
if (firstFromEmailAddr != null) {
String displayName = firstFromIA.getPersonal();
icalOutput.startProperty(Property.ATTENDEE);
icalOutput.propertyValue("Mailto:" + firstFromEmailAddr);
if (displayName != null) {
icalOutput.parameter(Parameter.CN, displayName);
}
icalOutput.parameter(Parameter.CUTYPE, CuType.INDIVIDUAL.getValue());
if (partstat != null) {
icalOutput.parameter(Parameter.PARTSTAT, partstat.getValue());
}
if (senderMailto != null) {
icalOutput.parameter(Parameter.SENT_BY, senderMailto);
}
icalOutput.endProperty(Property.ATTENDEE);
}
} else {
// ORGANIZER to ATTENDEEs - REQUEST or CANCEL
InternetAddress organizerEmail = null;
if (firstFromEmailAddr != null) {
SentBy sentBy = null;
Cn cn = null;
if (senderMailto != null) {
sentBy = new SentBy(senderMailto);
}
organizerEmail = firstFromIA;
String displayName = firstFromIA.getPersonal();
if ((displayName != null) && (!displayName.equals(firstFromEmailAddr))) {
cn = new Cn(displayName);
}
Organizer organizer = new Organizer();
organizer.setValue("Mailto:" + firstFromEmailAddr);
if (cn != null) {
organizer.getParameters().add(cn);
}
if (sentBy != null) {
organizer.getParameters().add(sentBy);
}
IcalUtil.addProperty(icalOutput, organizer);
if (icalType == ICALENDAR_TYPE.VEVENT) {
// Assumption - ORGANIZER is an attendee and is attending.
Attendee attendee = new Attendee("Mailto:" + firstFromEmailAddr);
if (cn != null) {
attendee.getParameters().add(cn);
}
attendee.getParameters().add(CuType.INDIVIDUAL);
attendee.getParameters().add(Role.REQ_PARTICIPANT);
if (!method.equals(Method.CANCEL)) {
PartStat orgPartstat = PartStat.ACCEPTED;
if (ccRecips != null) {
for (Address a : ccRecips) {
InternetAddress ia = (InternetAddress) a;
if (organizerEmail.equals(ia)) {
orgPartstat = PartStat.TENTATIVE;
break;
}
}
}
attendee.getParameters().add(orgPartstat);
}
// Was including SENT-BY but probably not appropriate
// for a request
IcalUtil.addProperty(icalOutput, attendee);
}
}
if (toRecips != null) {
for (Address a : toRecips) {
InternetAddress ia = (InternetAddress) a;
if ((organizerEmail != null) && organizerEmail.equals(ia)) {
// No need to add the information twice
continue;
}
addAttendee(icalOutput, ia, Role.REQ_PARTICIPANT, CuType.INDIVIDUAL, partstat, replyWanted);
}
}
if (ccRecips != null) {
for (Address a : ccRecips) {
InternetAddress ia = (InternetAddress) a;
if ((organizerEmail != null) && organizerEmail.equals(ia)) {
// No need to add the information twice
continue;
}
addAttendee(icalOutput, ia, Role.OPT_PARTICIPANT, CuType.INDIVIDUAL, partstat, replyWanted);
}
}
if (bccRecips != null) {
for (Address a : bccRecips) {
InternetAddress ia = (InternetAddress) a;
addAttendee(icalOutput, ia, Role.NON_PARTICIPANT, CuType.RESOURCE, partstat, replyWanted);
}
}
}
if (senderMailto != null) {
XProperty msOlkSender = new XProperty("X-MS-OLK-SENDER", senderMailto);
if (senderCn != null) {
Cn cn = new Cn(senderCn);
msOlkSender.getParameters().add(cn);
}
IcalUtil.addProperty(icalOutput, msOlkSender);
}
}
Aggregations