use of ietf.params.xml.ns.icalendar_2.BaseComponentType in project bw-calendar-engine by Bedework.
the class BwUpdates method applyUpdate.
private UpdateResult applyUpdate(final EventInfo ei, final ComponentSelectionType selPar) throws WebdavException {
/* First two selects just get us in to the events */
ComponentSelectionType sel = selPar;
// Top level must be "vcalendar"
if ((sel == null) || (sel.getVcalendar() == null)) {
return new UpdateResult("Not \"vcalendar\"");
}
// Next - expect "components"
ComponentsSelectionType csel = sel.getComponents();
if (csel == null) {
return new UpdateResult("Not \"component\"");
}
for (ComponentReferenceType c : csel.getRemove()) {
UpdateResult ur = removeOverride(ei, c);
if (!ur.getOk()) {
return ur;
}
}
for (ComponentReferenceType c : csel.getAdd()) {
UpdateResult ur = addOverride(ei, c);
if (!ur.getOk()) {
return ur;
}
}
/* Updates may be applied to the master or any overrides selected by uid and
* recurrence-id
*/
for (ComponentSelectionType cs : csel.getComponent()) {
BaseComponentType ent = cs.getBaseComponent().getValue();
// Must be a component matching the current one.
if (ent == null) {
return new UpdateResult("Missing component to match");
}
Integer entType = entTypes.get(ent.getClass());
if (entType == null) {
return new UpdateResult("Unknown entity type: " + ent.getClass());
}
if (entType != ei.getEvent().getEntityType()) {
return new UpdateResult("No matching entity");
}
List<EventInfo> entities = new ArrayList<EventInfo>();
entities.add(ei);
entities.addAll(ei.getOverrides());
entities = match(// sel,
entities, ent);
if ((entities == null) || (entities.size() == 0)) {
return new UpdateResult("No matching entity");
}
if ((cs.getProperties() == null) && (cs.getComponents() == null)) {
// No properties or components - error
return new UpdateResult("Must select \"components\" and/or \"properties\"");
}
/* At this point we either select properties to change or nested components
*/
if (cs.getComponents() != null) {
UpdateResult ur = applySubCompUpdates(ei, cs.getComponents());
if (!ur.getOk()) {
return ur;
}
}
if (cs.getProperties() != null) {
// Updating properties
UpdateResult ur = updateEventsProperties(entities, cs.getProperties());
if (!ur.getOk()) {
return ur;
}
}
}
return UpdateResult.getOkResult();
}
use of ietf.params.xml.ns.icalendar_2.BaseComponentType in project bw-calendar-engine by Bedework.
the class BwUpdates method findSubComponent.
private Component findSubComponent(final EventInfo ei, final BaseComponentType bc) throws WebdavException {
try {
BwEvent ev = ei.getEvent();
int etype = ev.getEntityType();
if (bc instanceof ValarmType) {
if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
return null;
}
/* Look for the alarm - we match on the whole component */
BwAlarm matched = null;
BwAlarm pattern = Xalarms.toBwAlarm((ValarmType) bc, false);
if ((pattern == null) || (ev.getNumAlarms() == 0)) {
return null;
}
for (BwAlarm al : ev.getAlarms()) {
if (al.matches(pattern)) {
if (matched != null) {
// Multiple matches - bad
return null;
}
matched = al;
}
}
return new PropertyUpdateComponent(ei, matched);
}
return null;
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of ietf.params.xml.ns.icalendar_2.BaseComponentType in project bw-calendar-engine by Bedework.
the class BwUpdates method getCompSelector.
private CompSelector getCompSelector(final BaseComponentType selComp) throws WebdavException {
CompSelector cs = new CompSelector();
for (JAXBElement<? extends BasePropertyType> prop : selComp.getProperties().getBasePropertyOrTzid()) {
if (prop.getName().equals(XcalTags.uid)) {
cs.uid = ((UidPropType) prop.getValue()).getText();
if ((cs.uid != null) && (cs.recurrenceId != null)) {
return cs;
}
continue;
}
if (prop.getName().equals(XcalTags.recurrenceId)) {
RecurrenceIdPropType rid = (RecurrenceIdPropType) prop.getValue();
XcalUtil.DtTzid dtTzid = XcalUtil.getDtTzid(rid);
try {
cs.recurrenceId = BwDateTime.makeBwDateTime(dtTzid.dateOnly, dtTzid.dt, dtTzid.tzid);
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
if ((cs.uid != null) && (cs.recurrenceId != null)) {
return cs;
}
continue;
}
}
return cs;
}
use of ietf.params.xml.ns.icalendar_2.BaseComponentType in project bw-calendar-engine by Bedework.
the class BwUpdates method addSubComp.
private UpdateResult addSubComp(final EventInfo ei, final ComponentReferenceType sel) throws WebdavException {
try {
BwEvent ev = ei.getEvent();
int etype = ev.getEntityType();
BaseComponentType bc = sel.getBaseComponent().getValue();
if (bc instanceof ValarmType) {
if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
return new UpdateResult("Invalid entity type for alarm add");
}
BwAlarm al = Xalarms.toBwAlarm((ValarmType) bc, false);
if (al == null) {
return new UpdateResult("Invalid alarm for add");
}
ev.addAlarm(al);
return UpdateResult.getOkResult();
}
return new UpdateResult("Invalid entity type for add");
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of ietf.params.xml.ns.icalendar_2.BaseComponentType in project bw-calendar-engine by Bedework.
the class Xalarms method toXAlarm.
/**
* @param ev
* @param val
* @param pattern
* @param masterClass
* @return ValarmType
* @throws CalFacadeException
*/
public static ValarmType toXAlarm(final BwEvent ev, final BwAlarm val, final BaseComponentType pattern, final Class masterClass) throws CalFacadeException {
try {
ValarmType alarm = new ValarmType();
int atype = val.getAlarmType();
alarm.setProperties(new ArrayOfProperties());
List<JAXBElement<? extends BasePropertyType>> pl = alarm.getProperties().getBasePropertyOrTzid();
if (emit(pattern, masterClass, ValarmType.class, ActionPropType.class)) {
ActionPropType a = new ActionPropType();
a.setText(BwAlarm.alarmTypes[val.getAlarmType()]);
pl.add(of.createAction(a));
}
if (emit(pattern, masterClass, ValarmType.class, TriggerPropType.class)) {
TriggerPropType t = new TriggerPropType();
if (val.getTriggerDateTime()) {
// t.setDateTime(val.getTrigger());
t.setDateTime(XcalUtil.getXMlUTCCal(val.getTrigger()));
} else {
t.setDuration(val.getTrigger());
if (!val.getTriggerStart()) {
ArrayOfParameters pars = getAop(t);
RelatedParamType r = new RelatedParamType();
r.setText(IcalDefs.alarmTriggerRelatedEnd);
JAXBElement<RelatedParamType> param = of.createRelated(r);
pars.getBaseParameter().add(param);
}
}
pl.add(of.createTrigger(t));
}
if (emit(pattern, masterClass, ValarmType.class, DurationPropType.class)) {
if (val.getDuration() != null) {
DurationPropType dur = new DurationPropType();
dur.setDuration(val.getDuration());
pl.add(of.createDuration(dur));
RepeatPropType rep = new RepeatPropType();
rep.setInteger(BigInteger.valueOf(val.getRepeat()));
pl.add(of.createRepeat(rep));
}
}
/* Description */
if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
// Both require description
String desc = val.getDescription();
if (desc == null) {
if (ev != null) {
if (ev.getDescription() != null) {
desc = ev.getDescription();
} else {
desc = ev.getSummary();
}
}
}
if (desc == null) {
desc = " ";
}
DescriptionPropType d = new DescriptionPropType();
d.setText(desc);
pl.add(of.createDescription(d));
}
/* Summary */
if (atype == BwAlarm.alarmTypeEmail) {
SummaryPropType s = new SummaryPropType();
s.setText(val.getSummary());
pl.add(of.createSummary(s));
}
if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
if (val.getAttach() != null) {
AttachPropType a = new AttachPropType();
a.setUri(val.getAttach());
pl.add(of.createAttach(a));
}
}
/* Attendees */
if (atype == BwAlarm.alarmTypeEmail) {
if (val.getNumAttendees() > 0) {
for (BwAttendee att : val.getAttendees()) {
pl.add(of.createAttendee(ToXEvent.makeAttendee(att)));
}
}
}
if (val.getNumXproperties() > 0) {
/* This alarm has x-props */
}
return alarm;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations