Search in sources :

Example 11 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class DtEndDuePropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    /* For start, end and duration we have to finish up at the end after all
     * changes are made.
     */
    try {
        BwEvent ev = ui.getEvent();
        DateDatetimePropertyType dt = (DateDatetimePropertyType) ui.getProp();
        if (dt instanceof DuePropType) {
            if (ev.getEntityType() != IcalDefs.entityTypeTodo) {
                return new UpdateResult("DUE only valid for tasks");
            }
        } else {
            if (ev.getEntityType() == IcalDefs.entityTypeTodo) {
                return new UpdateResult("DUE required for tasks");
            }
        }
        DatesState ds = (DatesState) ui.getState(DatesState.stateName);
        if (ds == null) {
            ds = new DatesState(ev);
            ui.saveState(DatesState.stateName, ds);
        }
        ChangeTableEntry cte = ui.getCte();
        if (ui.isRemove()) {
            if (ev.getEndType() != StartEndComponent.endTypeDate) {
                return new UpdateResult("Entity has no end date - cannot remove");
            }
            cte.setDeleted(ev.getDtend());
            ds.end = null;
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            if (ev.getEndType() == StartEndComponent.endTypeDate) {
                return new UpdateResult("Entity already has end date - cannot add");
            }
            ds.end = BwDateTime.makeBwDateTime(dt);
            cte.setAdded(ds.end);
            return UpdateResult.getOkResult();
        }
        /* Changing dtend - either value or parameters */
        if (ev.getEndType() != StartEndComponent.endTypeDate) {
            return new UpdateResult("Entity has no end date - cannot change");
        }
        Holder<BwDateTime> resdt = new Holder<BwDateTime>();
        UpdateResult ur = makeDt(ev.getDtend(), resdt, ui);
        if (!ur.getOk()) {
            return ur;
        }
        if (resdt.value != null) {
            cte.setChanged(ev.getDtend(), resdt.value);
            ds.end = resdt.value;
        }
        return UpdateResult.getOkResult();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : DuePropType(ietf.params.xml.ns.icalendar_2.DuePropType) BwDateTime(org.bedework.calfacade.BwDateTime) DateDatetimePropertyType(ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType) Holder(javax.xml.ws.Holder) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 12 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class RelatedToPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    ChangeTableEntry cte = ui.getCte();
    BwEvent ev = ui.getEvent();
    RelatedToPropType pr = (RelatedToPropType) ui.getProp();
    ReltypeParamType rtparm = (ReltypeParamType) UpdaterUtil.getParam(pr, XcalTags.reltype);
    String propRelType = "";
    String propValType;
    String propVal;
    if (rtparm != null) {
        propRelType = rtparm.getText();
    }
    if (pr.getText() != null) {
        propValType = "";
        propVal = pr.getText();
    } else if (pr.getUri() != null) {
        propValType = "URI";
        propVal = pr.getUri();
    } else {
        propValType = "UID";
        propVal = pr.getUid();
    }
    /* We encode related to (maybe) as triples - reltype, value-type, value */
    String[] info = null;
    BwXproperty xprop = null;
    BwRelatedTo relto = ev.getRelatedTo();
    if (relto != null) {
        info = new String[3];
        info[0] = relto.getRelType();
        // default
        info[1] = "";
        info[2] = relto.getValue();
    } else {
        xprop = ev.findXproperty(BwXproperty.bedeworkRelatedTo);
        if (xprop != null) {
            String relx = xprop.getValue();
            if (relx != null) {
                info = Util.decodeArray(relx);
            }
        }
    }
    int pos = findRT(info, propRelType, propValType, propVal);
    if (ui.isAdd()) {
        if (pos >= 0) {
            // Already there
            return UpdateResult.getOkResult();
        }
        int iPos = info.length;
        info = Arrays.copyOf(info, info.length + 3);
        info[iPos] = propRelType;
        info[iPos + 1] = propValType;
        info[iPos + 2] = propVal;
        ev.setRelatedTo(null);
        if (xprop == null) {
            xprop = new BwXproperty(BwXproperty.bedeworkRelatedTo, null, null);
            ev.addXproperty(xprop);
        }
        String newval = Util.encodeArray(info);
        xprop.setValue(newval);
        cte.addAddedValue(newval);
        return UpdateResult.getOkResult();
    }
    if (ui.isRemove()) {
        if (pos < 0) {
            // Nothing to remove
            return UpdateResult.getOkResult();
        }
        if (info.length == 3) {
            // removing only related-to
            ev.setRelatedTo(null);
            ev.removeXproperties(BwXproperty.bedeworkRelatedTo);
            return UpdateResult.getOkResult();
        }
        String[] newInfo = new String[info.length - 3];
        for (int i = 0; i < pos; i++) {
            newInfo[i] = info[i];
        }
        for (int i = pos + 3; i < info.length; i++) {
            newInfo[i] = info[i];
        }
        ev.setRelatedTo(null);
        if (xprop == null) {
            xprop = new BwXproperty(BwXproperty.bedeworkRelatedTo, null, null);
            ev.addXproperty(xprop);
        }
        String newval = Util.encodeArray(newInfo);
        xprop.setValue(newval);
        cte.addRemovedValue(newval);
        return UpdateResult.getOkResult();
    }
    if (ui.isChange()) {
        // Change a value
        if (pos < 0) {
            // Nothing to change
            return new UpdateResult("No comment to change");
        }
        info[pos] = propRelType;
        info[pos + 1] = propValType;
        info[pos + 2] = propVal;
        ev.setRelatedTo(null);
        if (xprop == null) {
            xprop = new BwXproperty(BwXproperty.bedeworkRelatedTo, null, null);
            ev.addXproperty(xprop);
        }
        String newval = Util.encodeArray(info);
        xprop.setValue(newval);
        cte.addChangedValue(newval);
        return UpdateResult.getOkResult();
    }
    return UpdateResult.getOkResult();
}
Also used : RelatedToPropType(ietf.params.xml.ns.icalendar_2.RelatedToPropType) BwRelatedTo(org.bedework.calfacade.BwRelatedTo) BwXproperty(org.bedework.calfacade.BwXproperty) ReltypeParamType(ietf.params.xml.ns.icalendar_2.ReltypeParamType) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 13 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class TranspPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    TranspPropType pr = (TranspPropType) ui.getProp();
    ChangeTableEntry cte = ui.getCte();
    String val = pr.getText();
    String evVal = ev.getTransparency();
    if (ui.isRemove()) {
        if (evVal == null) {
            return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
        }
        val = null;
    } else if (ui.isAdd()) {
        if (evVal != null) {
            return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
        }
    } else if (!ui.isChange()) {
        return new UpdateResult("No update specified for " + ui.getPropName());
    } else {
        if (!val.equals(evVal)) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
        val = ((TranspPropType) ui.getUpdprop()).getText();
    }
    if (!Util.equalsString(val, evVal)) {
        cte.setChanged(evVal, val);
        ev.setTransparency(val);
    }
    return UpdateResult.getOkResult();
}
Also used : TranspPropType(ietf.params.xml.ns.icalendar_2.TranspPropType) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 14 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult 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);
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 15 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class BwUpdates method updateEventProperties.

/**
 * The current selector is for the event properties.
 *
 * <p>We might have one or more updates - add or remove
 *
 * <p>We might also have one or more selects which allow for change of values
 *
 * @param ei
 * @param subComponent - non null if this is a sub-component update
 * @param sel - matching the "properties" element
 * @return true for updated OK
 * @throws WebdavException
 */
private UpdateResult updateEventProperties(final EventInfo ei, final Component subComponent, final PropertiesSelectionType sel) throws WebdavException {
    for (final PropertySelectionType psel : sel.getProperty()) {
        /* psel represents a selection on a property which must exist and for
       * which we must have an updater.
       *
       * We may be applying changes to the property with a change update and/or
       * updating the parameters through one or more a selections on the
       * parameters.
       */
        final BasePropertyType bprop;
        final QName pname;
        if (psel.getBaseProperty() == null) {
            return new UpdateResult("No selection property supplied");
        }
        bprop = psel.getBaseProperty().getValue();
        pname = psel.getBaseProperty().getName();
        final 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 = null;
        /* There is possibly no change - for example we are changing the tzid for
       * the dtstart
       */
        if (psel.getChange() != null) {
            ur = ui.setChange(psel.getChange());
            if (ur != null) {
                return ur;
            }
        }
        /* Look for updates to property parameters and add them to the property
       * updater info.
       */
        if (psel.getParameters() != null) {
            ui.setParameterUpdates(psel.getParameters());
        }
        // There may be no change
        ur = pu.applyUpdate(ui);
        if (!ur.getOk()) {
            return ur;
        }
    }
    /* Next adds
     */
    UpdateResult ur = addRemove(ei, subComponent, true, sel.getAdd(), cb);
    if (!ur.getOk()) {
        return ur;
    }
    /* Next removes
     */
    ur = addRemove(ei, subComponent, false, sel.getRemove(), cb);
    if (!ur.getOk()) {
        return ur;
    }
    /* We now need to validate the result to ensure the changes leave a
     * consistent entity. Date/time changes in particular can have a number
     * of side effects.
     */
    ur = validateDates(ei);
    if (!ur.getOk()) {
        return ur;
    }
    if (debug) {
        ei.getChangeset(userHref).dumpEntries();
    }
    return UpdateResult.getOkResult();
}
Also used : BasePropertyType(ietf.params.xml.ns.icalendar_2.BasePropertyType) QName(javax.xml.namespace.QName) PropertySelectionType(org.oasis_open.docs.ws_calendar.ns.soap.PropertySelectionType) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Aggregations

UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)31 BwEvent (org.bedework.calfacade.BwEvent)23 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)20 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)11 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)11 BwString (org.bedework.calfacade.BwString)6 TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)4 BwAlarm (org.bedework.calfacade.BwAlarm)4 BwDateTime (org.bedework.calfacade.BwDateTime)4 BwXproperty (org.bedework.calfacade.BwXproperty)4 BaseComponentType (ietf.params.xml.ns.icalendar_2.BaseComponentType)2 BasePropertyType (ietf.params.xml.ns.icalendar_2.BasePropertyType)2 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)2 DurationPropType (ietf.params.xml.ns.icalendar_2.DurationPropType)2 BigInteger (java.math.BigInteger)2 QName (javax.xml.namespace.QName)2 Holder (javax.xml.ws.Holder)2 ParameterUpdater (org.bedework.caldav.bwserver.ParameterUpdater)2 BwContact (org.bedework.calfacade.BwContact)2 BwLocation (org.bedework.calfacade.BwLocation)2