use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.
the class BwUpdates method addRemove.
private UpdateResult addRemove(final EventInfo ei, final Component subComponent, final boolean add, final List<PropertyReferenceType> refs, final IcalCallback cb) throws WebdavException {
for (PropertyReferenceType r : refs) {
BasePropertyType bprop;
QName pname;
if (r.getBaseProperty() == null) {
return new UpdateResult("No new value for add");
}
bprop = r.getBaseProperty().getValue();
pname = r.getBaseProperty().getName();
PropertyUpdater pu = getUpdater(bprop);
if (pu == null) {
return new UpdateResult("No updater for property: " + pname);
}
PropertyUpdateInfo ui = new PropertyUpdateInfo(bprop, pname, cb, ei, subComponent, state, userHref);
UpdateResult ur;
if (add) {
ur = ui.setAdd(r);
} else {
ur = ui.setRemove(r);
}
if (ur != null) {
return ur;
}
ur = pu.applyUpdate(ui);
if (!ur.getOk()) {
return ur;
}
}
return UpdateResult.getOkResult();
}
use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.
the class BwUpdates method removeSubComp.
private UpdateResult removeSubComp(final EventInfo ei, final ComponentReferenceType sel) throws WebdavException {
Component subc = findSubComponent(ei, sel.getBaseComponent().getValue());
if (subc == null) {
return new UpdateResult("Invalid sub-component selection for remove");
}
ei.getAlarms().remove(subc.getAlarm());
return UpdateResult.getOkResult();
}
use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.
the class BwUpdates method validateDates.
private UpdateResult validateDates(final EventInfo ei) throws WebdavException {
DatesState ds = (DatesState) state.get(DatesState.stateName);
if (ds == null) {
return UpdateResult.getOkResult();
}
BwEvent ev = ei.getEvent();
boolean task = ev.getEntityType() == IcalDefs.entityTypeTodo;
PropertyInfoIndex endPi;
ChangeTable chg = ei.getChangeset(userHref);
if (task) {
endPi = PropertyInfoIndex.DUE;
} else {
endPi = PropertyInfoIndex.DTEND;
}
try {
boolean scheduleReply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
if (ds.start == null) {
if (!scheduleReply && !task) {
return new UpdateResult("org.bedework.error.nostartdate");
}
/* A todo can have no date and time. set start to now, end to
* many years from now and the noStart flag.
*
* Such an entry has to appear only on the current day.
*/
if (ds.end != null) {
ds.start = ds.end;
} else {
Date now = new Date(new java.util.Date().getTime());
DtStart dtStart = new DtStart(now);
dtStart.getParameters().add(Value.DATE);
ds.start = BwDateTime.makeBwDateTime(dtStart);
}
if (!ev.getNoStart() || !CalFacadeUtil.eqObjval(ev.getDtstart(), ds.start)) {
chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), null);
ev.setDtstart(ds.start);
ev.setNoStart(true);
}
} else if (ev.getNoStart() || !ds.start.equals(ev.getDtstart())) {
chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), ds.start);
ev.setNoStart(false);
ev.setDtstart(ds.start);
}
char endType = StartEndComponent.endTypeNone;
if (ds.end != null) {
if ((ev.getEndType() != StartEndComponent.endTypeDate) || !CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
chg.changed(endPi, ev.getDtend(), ds.end);
endType = StartEndComponent.endTypeDate;
ev.setDtend(ds.end);
}
} else if (scheduleReply || task) {
// about 10 years
Dur years = new Dur(520);
Date now = new Date(new java.util.Date().getTime());
DtEnd dtEnd = new DtEnd(new Date(years.getTime(now)));
dtEnd.getParameters().add(Value.DATE);
ds.end = BwDateTime.makeBwDateTime(dtEnd);
if (!CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
chg.changed(endPi, ev.getDtend(), ds.end);
ev.setDtend(ds.end);
}
}
/**
* If we were given a duration store it in the event and calculate
* an end to the event - which we should not have been given.
*/
if (ds.duration != null) {
if (endType != StartEndComponent.endTypeNone) {
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
// Apple is sending both - duration indicates the minimum
// freebusy duration. Ignore for now.
} else {
return new UpdateResult(CalFacadeException.endAndDuration);
}
}
endType = StartEndComponent.endTypeDuration;
if (!ds.duration.equals(ev.getDuration())) {
chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), ds.duration);
ev.setDuration(ds.duration);
}
ev.setDtend(BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), ev.getDtstart().getDateType(), new Dur(ds.duration)));
} else if (!scheduleReply && (endType == StartEndComponent.endTypeNone) && !task) {
/* No duration and no end specified.
* Set the end values to the start values + 1 for dates
*/
boolean dateOnly = ev.getDtstart().getDateType();
Dur dur;
if (dateOnly) {
// 1 day
dur = new Dur(1, 0, 0, 0);
} else {
// No duration
dur = new Dur(0, 0, 0, 0);
}
BwDateTime bwDtEnd = BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), dateOnly, dur);
if (!CalFacadeUtil.eqObjval(ev.getDtend(), bwDtEnd)) {
chg.changed(endPi, ev.getDtend(), bwDtEnd);
ev.setDtend(bwDtEnd);
}
}
if ((endType != StartEndComponent.endTypeDuration) && (ev.getDtstart() != null) && (ev.getDtend() != null)) {
// Calculate a duration
String durVal = BwDateTime.makeDuration(ev.getDtstart(), ev.getDtend()).toString();
if (!durVal.equals(ev.getDuration())) {
chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), durVal);
ev.setDuration(durVal);
}
}
ev.setEndType(endType);
return UpdateResult.getOkResult();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult 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 org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.
the class AlarmDurationPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
BwAlarm alarm = ui.getSubComponent().getAlarm();
DurationPropType dur = (DurationPropType) ui.getProp();
if (ui.isRemove()) {
if (alarm.getDuration() == null) {
return new UpdateResult("Entity has no duration - cannot remove");
}
alarm.setDuration(null);
flagChange(alarm, ui);
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (alarm.getDuration() != null) {
return new UpdateResult("Entity already has duration - cannot add");
}
alarm.setDuration(dur.getDuration());
flagChange(alarm, ui);
return UpdateResult.getOkResult();
}
/* Changing duration */
dur = (DurationPropType) ui.getUpdprop();
if (!dur.getDuration().equals(alarm.getDuration())) {
alarm.setDuration(dur.getDuration());
flagChange(alarm, ui);
}
return UpdateResult.getOkResult();
}
Aggregations