use of org.bedework.webdav.servlet.shared.WebdavException 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);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class DateDatetimePropUpdater method makeDt.
protected UpdateResult makeDt(final BwDateTime evdt, final Holder<BwDateTime> resdt, final UpdateInfo ui) throws WebdavException {
try {
String tzid = evdt.getTzid();
String dtval = evdt.getDtval();
boolean dateOnly = evdt.getDateType();
BwDateTime newdt = null;
/* New or changed tzid? */
for (ParameterUpdater.UpdateInfo parui : ui.getParamUpdates()) {
if (parui.getParam() instanceof TzidParamType) {
if (parui.isRemove()) {
tzid = null;
break;
}
if (parui.isAdd()) {
if (tzid != null) {
return new UpdateResult(ui.getPropName().toString() + " already has tzid");
}
tzid = ((TzidParamType) parui.getParam()).getText();
break;
}
if (tzid == null) {
return new UpdateResult(ui.getPropName().toString() + " has no tzid to change");
}
tzid = ((TzidParamType) parui.getUpdparam()).getText();
break;
}
}
if (ui.getUpdprop() != null) {
// Has new value
DateDatetimePropertyType newdts = (DateDatetimePropertyType) ui.getUpdprop();
dateOnly = newdts.getDate() != null;
newdt = BwDateTime.makeBwDateTime(newdts, tzid);
}
if ((newdt == null) && (!Util.equalsString(tzid, evdt.getTzid()))) {
// Tzid changed
newdt = BwDateTime.makeBwDateTime(dateOnly, dtval, tzid);
}
if (newdt != null) {
// Validate
int res = newdt.validate();
if (res == BwDateTime.dtBadDtval) {
return new UpdateResult("Bad date value for " + ui.getPropName());
}
if (res == BwDateTime.dtBadTz) {
return new UpdateResult("Bad tzid for " + ui.getPropName());
}
}
resdt.value = newdt;
return UpdateResult.getOkResult();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException 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);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwCalDAVResource method getBinaryStream.
private InputStream getBinaryStream() throws WebdavException {
if (rsrc == null) {
return null;
}
if (rsrc.getContent() == null) {
intf.getFileContent(this);
}
BwResourceContent bwrc = rsrc.getContent();
if (bwrc == null) {
return null;
}
Blob b = bwrc.getValue();
if (b == null) {
return null;
}
try {
return b.getBinaryStream();
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwCalDAVResource method getNotification.
private NotificationType getNotification() throws WebdavException {
try {
note = Parser.fromXml(getBinaryStream());
if ((note == null) || (note.getNotification() == null)) {
return null;
}
note.getNotification().prefixHrefs(intf.getUrlHandler());
xmlNote = note.toXml(intf.bedeworkExtensionsEnabled());
return note;
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
Aggregations