use of net.fortuna.ical4j.model.property.Voter 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;
}
}
}
use of net.fortuna.ical4j.model.property.Voter in project bw-calendar-engine by Bedework.
the class IcalUtil method setVoter.
/**
* make a voter
*
* @param val BwAttendee to build from
* @return Attendee
* @throws Throwable
*/
public static Voter setVoter(final BwAttendee val) throws Throwable {
final Voter prop = new Voter(val.getAttendeeUri());
final ParameterList pars = prop.getParameters();
setAttendeeVoter(val, pars);
final String temp = val.getPartstat();
pars.add(new PartStat(temp));
return prop;
}
use of net.fortuna.ical4j.model.property.Voter in project bw-calendar-engine by Bedework.
the class IcalUtil method parseVpollVvoters.
/**
* @param poll the poll entity
* @return Parsed VVOTER components map - key is voter cua.
* @throws Throwable
*/
public static Map<String, VVoter> parseVpollVvoters(final BwEvent poll) throws Throwable {
final StringBuilder sb = new StringBuilder();
// Better if ical4j supported sub-component parsing
sb.append("BEGIN:VCALENDAR\n");
sb.append("PRODID://Bedework.org//BedeWork V3.9//EN\n");
sb.append("VERSION:2.0\n");
sb.append("BEGIN:VPOLL\n");
sb.append("UID:0123\n");
if (!Util.isEmpty(poll.getVvoters())) {
for (final String s : poll.getVvoters()) {
sb.append(s);
}
}
sb.append("END:VPOLL\n");
sb.append("END:VCALENDAR\n");
try {
final StringReader sr = new StringReader(sb.toString());
final Icalendar ic = new Icalendar();
final CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
final UnfoldingReader ufrdr = new UnfoldingReader(sr, true);
final Calendar ical = bldr.build(ufrdr);
final Map<String, VVoter> voters = new HashMap<>();
/* Should be one vpoll object */
final VPoll vpoll = (VPoll) ical.getComponent(Component.VPOLL);
for (final Object o : vpoll.getVoters()) {
final VVoter vvoter = (VVoter) o;
final Voter v = (Voter) vvoter.getProperty(Property.VOTER);
if (v == null) {
continue;
}
voters.put(v.getValue(), vvoter);
}
return voters;
} catch (final ParserException pe) {
throw new IcalMalformedException(pe.getMessage());
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations