Search in sources :

Example 36 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class PriorityPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    PriorityPropType pr = (PriorityPropType) ui.getProp();
    ChangeTableEntry cte = ui.getCte();
    BigInteger val = pr.getInteger();
    BigInteger evVal = null;
    if (ev.getPriority() != null) {
        evVal = BigInteger.valueOf(ev.getPriority());
    }
    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 = ((PriorityPropType) ui.getUpdprop()).getInteger();
    }
    if (val != null) {
        int ival = val.intValue();
        if ((ival < 0) || (ival > 9)) {
            return new UpdateResult("Value for " + ui.getPropName() + " must be >= 0 and <= 9 ");
        }
    }
    if (Util.cmpObjval(val, evVal) != 0) {
        cte.setChanged(evVal, val);
        ev.setPriority(val.intValue());
    }
    return UpdateResult.getOkResult();
}
Also used : BigInteger(java.math.BigInteger) BwEvent(org.bedework.calfacade.BwEvent) PriorityPropType(ietf.params.xml.ns.icalendar_2.PriorityPropType) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 37 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class RdatePropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        BwEvent ev = ui.getEvent();
        ChangeTableEntry cte = ui.getCte();
        Set<BwDateTime> evDts = ev.getRdates();
        DateDatetimePropertyType dt = (DateDatetimePropertyType) ui.getProp();
        String dtUTC = XcalUtil.getUTC(dt, ui.getTzs());
        if (ui.isRemove()) {
            removeDt(dtUTC, evDts, cte);
            return UpdateResult.getOkResult();
        }
        BwDateTime prdt = BwDateTime.makeBwDateTime(dt);
        if (ui.isAdd()) {
            addDt(prdt, evDts, cte);
            return UpdateResult.getOkResult();
        }
        /* Changing rdate maybe just changing the parameters (UTC unchanged) or
       * an actual value change. Second case is really a remove and add
       */
        BwDateTime newdt = BwDateTime.makeBwDateTime((DateDatetimePropertyType) ui.getUpdprop());
        if (prdt.getDate().equals(newdt.getDate())) {
            // tzid or date only?
            if (prdt.getTzid().equals(newdt.getTzid()) && (prdt.getDateType() == newdt.getDateType())) {
                // Unchanged
                return UpdateResult.getOkResult();
            } else {
                evDts.remove(prdt);
                evDts.add(newdt);
                cte.addChangedValue(newdt);
            }
        }
        /* Do remove then add */
        removeDt(prdt.getDate(), evDts, cte);
        addDt(newdt, evDts, cte);
        return UpdateResult.getOkResult();
    } catch (WebdavException we) {
        throw we;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) DateDatetimePropertyType(ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry)

Example 38 with BwEvent

use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.

the class CompletedPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    CompletedPropType pr = (CompletedPropType) ui.getProp();
    ChangeTableEntry cte = ui.getCte();
    String val = XcalUtil.getIcalFormatDateTime(pr.getUtcDateTime());
    String evVal = null;
    if (ev.getCompleted() != null) {
        evVal = ev.getCompleted();
    }
    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 = XcalUtil.getIcalFormatDateTime(((CompletedPropType) ui.getUpdprop()).getUtcDateTime());
    }
    if (Util.cmpObjval(val, evVal) != 0) {
        cte.setChanged(evVal, val);
        ev.setCompleted(val);
    }
    return UpdateResult.getOkResult();
}
Also used : CompletedPropType(ietf.params.xml.ns.icalendar_2.CompletedPropType) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 39 with BwEvent

use of org.bedework.calfacade.BwEvent 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 40 with BwEvent

use of org.bedework.calfacade.BwEvent 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)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10