Search in sources :

Example 1 with AttendeePropType

use of ietf.params.xml.ns.icalendar_2.AttendeePropType in project bw-calendar-engine by Bedework.

the class ToXEvent method makeAttendee.

/* ====================================================================
                      Private methods
     ==================================================================== */
/**
 * make an attendee
 *
 * @param val
 * @return Attendee
 * @throws Throwable
 */
public static AttendeePropType makeAttendee(final BwAttendee val) throws Throwable {
    AttendeePropType prop = new AttendeePropType();
    prop.setCalAddress(val.getAttendeeUri());
    ArrayOfParameters pars = new ArrayOfParameters();
    JAXBElement<? extends BaseParameterType> param;
    prop.setParameters(pars);
    if (val.getRsvp()) {
        RsvpParamType r = new RsvpParamType();
        r.setBoolean(true);
        param = of.createRsvp(r);
        pars.getBaseParameter().add(param);
    }
    String temp = val.getCn();
    if (temp != null) {
        CnParamType cn = new CnParamType();
        cn.setText(temp);
        param = of.createCn(cn);
        pars.getBaseParameter().add(param);
    }
    temp = val.getPartstat();
    if (temp == null) {
        temp = IcalDefs.partstatValNeedsAction;
    }
    PartstatParamType partstat = new PartstatParamType();
    partstat.setText(temp);
    param = of.createPartstat(partstat);
    pars.getBaseParameter().add(param);
    temp = val.getScheduleStatus();
    if (temp != null) {
        ScheduleStatusParamType ss = new ScheduleStatusParamType();
        ss.setText(temp);
        param = of.createScheduleStatus(ss);
        pars.getBaseParameter().add(param);
    }
    temp = val.getCuType();
    if (temp != null) {
        /*
      CutypeValueType cp;
      try {
        cp = CutypeValueType.fromValue(temp);
      } catch (Throwable t) {
        cp = CutypeValueType.UNKNOWN;
      }
      CutypeParamType c = new CutypeParamType();
      c.setText(cp.name());
      */
        CutypeParamType c = new CutypeParamType();
        c.setText(val.getCuType());
        param = of.createCutype(c);
        pars.getBaseParameter().add(param);
    }
    temp = val.getDelegatedFrom();
    if (temp != null) {
        DelegatedFromParamType df = new DelegatedFromParamType();
        df.getCalAddress().add(temp);
        param = of.createDelegatedFrom(df);
        pars.getBaseParameter().add(param);
    }
    temp = val.getDelegatedTo();
    if (temp != null) {
        DelegatedToParamType dt = new DelegatedToParamType();
        dt.getCalAddress().add(temp);
        param = of.createDelegatedTo(dt);
        pars.getBaseParameter().add(param);
    }
    temp = val.getDir();
    if (temp != null) {
        DirParamType d = new DirParamType();
        d.setUri(temp);
        param = of.createDir(d);
        pars.getBaseParameter().add(param);
    }
    temp = val.getLanguage();
    if (temp != null) {
        LanguageParamType l = new LanguageParamType();
        l.setText(temp);
        param = of.createLanguage(l);
        pars.getBaseParameter().add(param);
    }
    temp = val.getMember();
    if (temp != null) {
        MemberParamType m = new MemberParamType();
        m.getCalAddress().add(temp);
        param = of.createMember(m);
        pars.getBaseParameter().add(param);
    }
    /*
    temp = val.getRole();
    if (temp != null) {
      RoleValueType role;
      try {
        role = RoleValueType.fromValue(temp);
      } catch (Throwable t) {
        role = RoleValueType.REQ_PARTICIPANT;
      }

      RoleParamType r = new RoleParamType();
      r.setText(val.getRole());
      param = of.createRole(r);
      pars.getBaseParameter().add(param);
    }*/
    temp = val.getRole();
    if (temp != null) {
        RoleParamType r = new RoleParamType();
        r.setText(val.getRole());
        param = of.createRole(r);
        pars.getBaseParameter().add(param);
    }
    temp = val.getSentBy();
    if (temp != null) {
        SentByParamType sb = new SentByParamType();
        sb.setCalAddress(temp);
        param = of.createSentBy(sb);
        pars.getBaseParameter().add(param);
    }
    return prop;
}
Also used : DirParamType(ietf.params.xml.ns.icalendar_2.DirParamType) LanguageParamType(ietf.params.xml.ns.icalendar_2.LanguageParamType) PartstatParamType(ietf.params.xml.ns.icalendar_2.PartstatParamType) ArrayOfParameters(ietf.params.xml.ns.icalendar_2.ArrayOfParameters) CutypeParamType(ietf.params.xml.ns.icalendar_2.CutypeParamType) BwString(org.bedework.calfacade.BwString) RoleParamType(ietf.params.xml.ns.icalendar_2.RoleParamType) CnParamType(ietf.params.xml.ns.icalendar_2.CnParamType) MemberParamType(ietf.params.xml.ns.icalendar_2.MemberParamType) ScheduleStatusParamType(ietf.params.xml.ns.icalendar_2.ScheduleStatusParamType) RsvpParamType(ietf.params.xml.ns.icalendar_2.RsvpParamType) DelegatedToParamType(ietf.params.xml.ns.icalendar_2.DelegatedToParamType) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) SentByParamType(ietf.params.xml.ns.icalendar_2.SentByParamType) DelegatedFromParamType(ietf.params.xml.ns.icalendar_2.DelegatedFromParamType)

Example 2 with AttendeePropType

use of ietf.params.xml.ns.icalendar_2.AttendeePropType in project bw-calendar-engine by Bedework.

the class Xalarms method toBwAlarm.

/**
 * The generated alarm may not be a valid alarm if it is being used as a
 * selector. It must have at least the action as a selector.
 *
 * @param alarm
 * @param validate - true if alarm must be valid and complete
 * @return ValarmType
 * @throws CalFacadeException
 */
public static BwAlarm toBwAlarm(final ValarmType alarm, final boolean validate) throws CalFacadeException {
    BwAlarm ba = new BwAlarm();
    /* ============ Action =================== */
    ActionPropType action = (ActionPropType) XcalUtil.findProperty(alarm, XcalTags.action);
    if (action == null) {
        throw new CalFacadeException("Invalid alarm - no action");
    }
    String actionVal = action.getText().toUpperCase();
    int atype = -1;
    for (int i = 0; i < BwAlarm.alarmTypes.length; i++) {
        if (actionVal.equals(BwAlarm.alarmTypes[i])) {
            atype = i;
            break;
        }
    }
    if (atype < 0) {
        throw new CalFacadeException("Unhandled alarm action");
    }
    ba.setAlarmType(atype);
    /* ============ Trigger =================== */
    TriggerPropType tr = (TriggerPropType) XcalUtil.findProperty(alarm, XcalTags.trigger);
    if (tr == null) {
        if (validate) {
            throw new CalFacadeException("Invalid alarm - no action");
        }
    } else {
        if (tr.getDateTime() != null) {
            ba.setTrigger(XcalUtil.getIcalFormatDateTime(tr.getDateTime()));
            ba.setTriggerDateTime(true);
        } else {
            ba.setTrigger(tr.getDuration());
            RelatedParamType r = (RelatedParamType) XcalUtil.findParam(tr, XcalTags.related);
            ba.setTriggerStart((r == null) || (r.getText().toUpperCase().equals("START")));
        }
    }
    /* ============ Duration =================== */
    DurationPropType dur = (DurationPropType) XcalUtil.findProperty(alarm, XcalTags.duration);
    if (dur != null) {
        // MUST have repeat
        RepeatPropType rep = (RepeatPropType) XcalUtil.findProperty(alarm, XcalTags.repeat);
        ba.setDuration(dur.getDuration());
        if (rep == null) {
            if (validate) {
                throw new CalFacadeException("Invalid alarm - no repeat");
            }
        } else {
            ba.setRepeat(rep.getInteger().intValue());
        }
    }
    /* ============ Description ============ */
    if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
        DescriptionPropType desc = (DescriptionPropType) XcalUtil.findProperty(alarm, XcalTags.description);
        if (desc != null) {
            ba.setDescription(desc.getText());
        }
    }
    /* ============ Summary ============ */
    if (atype == BwAlarm.alarmTypeEmail) {
        SummaryPropType s = (SummaryPropType) XcalUtil.findProperty(alarm, XcalTags.summary);
        if (s != null) {
            ba.setSummary(s.getText());
        }
    }
    if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
        AttachPropType a = (AttachPropType) XcalUtil.findProperty(alarm, XcalTags.attach);
        // XXX Onl handle 1 attachment
        if ((a != null) && (a.getUri() != null)) {
            ba.setAttach(a.getUri());
        }
    }
    if (atype == BwAlarm.alarmTypeEmail) {
        for (JAXBElement<? extends BasePropertyType> bpel : alarm.getProperties().getBasePropertyOrTzid()) {
            if (!bpel.getName().equals(XcalTags.attendee)) {
                continue;
            }
            AttendeePropType attp = (AttendeePropType) bpel.getValue();
            BwAttendee batt = new BwAttendee();
            batt.setAttendeeUri(attp.getCalAddress());
            ba.addAttendee(batt);
        }
    }
    return ba;
}
Also used : SummaryPropType(ietf.params.xml.ns.icalendar_2.SummaryPropType) TriggerPropType(ietf.params.xml.ns.icalendar_2.TriggerPropType) AttachPropType(ietf.params.xml.ns.icalendar_2.AttachPropType) DurationPropType(ietf.params.xml.ns.icalendar_2.DurationPropType) DescriptionPropType(ietf.params.xml.ns.icalendar_2.DescriptionPropType) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) RelatedParamType(ietf.params.xml.ns.icalendar_2.RelatedParamType) ActionPropType(ietf.params.xml.ns.icalendar_2.ActionPropType) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) RepeatPropType(ietf.params.xml.ns.icalendar_2.RepeatPropType) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 3 with AttendeePropType

use of ietf.params.xml.ns.icalendar_2.AttendeePropType in project bw-calendar-engine by Bedework.

the class AttendeePropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        ChangeTableEntry cte = ui.getCte();
        BwEvent ev = ui.getEvent();
        Set<BwAttendee> atts = ev.getAttendees();
        AttendeePropType pr = (AttendeePropType) ui.getProp();
        String attUri = ui.getIcalCallback().getCaladdr(ui.getIcalCallback().getPrincipal().getPrincipalRef());
        /* Must have an organizer propery */
        BwOrganizer org = ev.getOrganizer();
        if (org == null) {
            return new UpdateResult("No organizer for attendee update");
        }
        boolean isOrganizer = attUri.equals(org.getOrganizerUri());
        if (!isOrganizer) {
            /* Options are pretty limited here - change partstat only to our own entry
         */
            if (!pr.getCalAddress().equals(attUri)) {
                return new UpdateResult("Cannot update other attendees");
            }
            if (ui.isAdd() || ui.isRemove()) {
                return new UpdateResult("Cannot add or remove attendees");
            }
            if (!ui.isChange()) {
                // Nothing to do
                return UpdateResult.getOkResult();
            }
            // return new UpdateResult("unimplemented - attendee update");
            throw new WebdavException("Unimplemented - attendees update");
        }
        if (ui.isAdd()) {
            if (!Util.isEmpty(atts)) {
                for (BwAttendee att : atts) {
                    if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                        // Already there
                        return UpdateResult.getOkResult();
                    }
                }
            }
            BwAttendee newAtt = makeAttendee(pr);
            ev.addAttendee(newAtt);
            cte.addAddedValue(newAtt);
            return UpdateResult.getOkResult();
        }
        if (ui.isRemove()) {
            if (Util.isEmpty(atts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            BwAttendee remAtt = makeAttendee(pr);
            if (ev.removeAttendee(remAtt)) {
                cte.addRemovedValue(remAtt);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            // Change a value
            if (Util.isEmpty(atts)) {
                // Nothing to change
                return new UpdateResult("No comment to change");
            }
            for (BwAttendee att : atts) {
                if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                    // Found
                    throw new WebdavException("Unimplemented - attendees update");
                // return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Aggregations

AttendeePropType (ietf.params.xml.ns.icalendar_2.AttendeePropType)3 BwAttendee (org.bedework.calfacade.BwAttendee)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 ActionPropType (ietf.params.xml.ns.icalendar_2.ActionPropType)1 ArrayOfParameters (ietf.params.xml.ns.icalendar_2.ArrayOfParameters)1 AttachPropType (ietf.params.xml.ns.icalendar_2.AttachPropType)1 CnParamType (ietf.params.xml.ns.icalendar_2.CnParamType)1 CutypeParamType (ietf.params.xml.ns.icalendar_2.CutypeParamType)1 DelegatedFromParamType (ietf.params.xml.ns.icalendar_2.DelegatedFromParamType)1 DelegatedToParamType (ietf.params.xml.ns.icalendar_2.DelegatedToParamType)1 DescriptionPropType (ietf.params.xml.ns.icalendar_2.DescriptionPropType)1 DirParamType (ietf.params.xml.ns.icalendar_2.DirParamType)1 DurationPropType (ietf.params.xml.ns.icalendar_2.DurationPropType)1 LanguageParamType (ietf.params.xml.ns.icalendar_2.LanguageParamType)1 MemberParamType (ietf.params.xml.ns.icalendar_2.MemberParamType)1 PartstatParamType (ietf.params.xml.ns.icalendar_2.PartstatParamType)1 RelatedParamType (ietf.params.xml.ns.icalendar_2.RelatedParamType)1 RepeatPropType (ietf.params.xml.ns.icalendar_2.RepeatPropType)1 RoleParamType (ietf.params.xml.ns.icalendar_2.RoleParamType)1 RsvpParamType (ietf.params.xml.ns.icalendar_2.RsvpParamType)1