use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class TimeZonesStoreImpl method updateFromTimeZones.
@Override
public UpdateFromTimeZonesInfo updateFromTimeZones(final String colHref, final int limit, final boolean checkOnly, final UpdateFromTimeZonesInfo info) throws CalFacadeException {
/* Versions < 3.3 don't have recurrences fully implemented so we'll
* ignore those.
*
* Fields that could be affected:
* Event start + end
* rdates and exdates
* Recurrence instances
*
*/
if ((info != null) && !(info instanceof UpdateFromTimeZonesInfoInternal)) {
throw new CalFacadeException(CalFacadeException.illegalObjectClass);
}
boolean redo = false;
final UpdateFromTimeZonesInfoInternal iinfo;
if (info != null) {
if (info.getTotalEventsToCheck() == info.getTotalEventsChecked()) {
redo = true;
}
iinfo = (UpdateFromTimeZonesInfoInternal) info;
} else {
iinfo = new UpdateFromTimeZonesInfoInternal();
}
if (redo || (iinfo.names == null)) {
String lastmod = null;
if (redo) {
lastmod = new LastModified(new DateTime(iinfo.lastmod - 5000)).getValue();
}
// Get event ids from db.
iinfo.lastmod = System.currentTimeMillis();
if (iinfo.names == null) {
iinfo.names = new ArrayList<>();
}
iinfo.totalEventsChecked = 0;
iinfo.totalEventsUpdated = 0;
iinfo.iterator = iinfo.names.iterator();
}
for (int i = 0; i < limit; i++) {
if (!iinfo.iterator.hasNext()) {
break;
}
final String name = iinfo.iterator.next();
/*
// See if event needs update
BwPrincipal owner = svci.getUsersHandler().getPrincipal(ikey.getOwnerHref());
BwDateTime start = checkDateTimeForTZ(ikey.getStart(), owner, iinfo);
BwDateTime end = checkDateTimeForTZ(ikey.getEnd(), owner, iinfo);
if ((start != null) || (end != null)) {
CoreEventInfo cei = ((Events)svci.getEventsHandler()).getEvent(ikey);
BwEvent ev = cei.getEvent();
if (cei != null) {
iinfo.updatedList.add(new BwEventKey(ev.getColPath(),
ev.getUid(),
ev.getRecurrenceId(),
ev.getName(),
ev.getRecurring()));
if (!checkOnly) {
if (start != null) {
BwDateTime evstart = ev.getDtstart();
if (debug) {
trace("Updated start: ev.tzid=" + evstart.getTzid() +
" ev.dtval=" + evstart.getDtval() +
" ev.date=" + evstart.getDate() +
" newdate=" + start.getDate());
}
ev.setDtstart(BwDateTime.makeBwDateTime(evstart.getDateType(),
evstart.getDtval(),
start.getDate(),
evstart.getTzid(),
evstart.getFloating()));
}
if (end != null) {
BwDateTime evend = ev.getDtend();
if (debug) {
trace("Updated end: ev.tzid=" + evend.getTzid() +
" ev.dtval=" + evend.getDtval() +
" ev.date=" + evend.getDate() +
" newdate=" + end.getDate());
}
ev.setDtend(BwDateTime.makeBwDateTime(evend.getDateType(),
evend.getDtval(),
end.getDate(),
evend.getTzid(),
evend.getFloating()));
}
EventInfo ei = new EventInfo(ev);
Collection<CoreEventInfo> overrides = cei.getOverrides();
if (overrides != null) {
for (CoreEventInfo ocei: overrides) {
BwEventProxy op = (BwEventProxy)ocei.getEvent();
ei.addOverride(new EventInfo(op));
}
}
svci.getEventsHandler().update(ei, false, null);
iinfo.totalEventsUpdated++;
}
}
}
*/
iinfo.totalEventsChecked++;
}
if (debug) {
trace(iinfo.toString());
}
return iinfo;
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class CalDavParseUtil method parseBwTimeRange.
/**
* The given node must be a time-range element
* <!ELEMENT time-range EMPTY>
*
* <!ATTLIST time-range start CDATA
* end CDATA>
*
* e.g. <C:time-range start="20040902T000000Z"
* end="20040902T235959Z"/>
*
* @param nd
* @param tzid - timezone to use if specified
* @return TimeRange
* @throws CalFacadeException
*/
public static BwTimeRange parseBwTimeRange(Node nd, String tzid) throws CalFacadeException {
BwDateTime start = null;
BwDateTime end = null;
NamedNodeMap nnm = nd.getAttributes();
if ((nnm == null) || (nnm.getLength() == 0)) {
// Infinite time-range?
throw new CalFacadeBadRequest("Infinite time range");
}
int attrCt = nnm.getLength();
try {
Node nmAttr = nnm.getNamedItem("start");
if (nmAttr != null) {
attrCt--;
if (tzid == null) {
start = BwDateTimeUtil.getDateTimeUTC(nmAttr.getNodeValue());
} else {
start = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(), false, false, tzid);
}
}
nmAttr = nnm.getNamedItem("end");
if (nmAttr != null) {
attrCt--;
if (tzid == null) {
end = BwDateTimeUtil.getDateTimeUTC(nmAttr.getNodeValue());
} else {
end = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(), false, false, tzid);
}
}
} catch (Throwable t) {
throw new CalFacadeBadRequest(t);
}
if (attrCt != 0) {
throw new CalFacadeBadRequest();
}
return new BwTimeRange(start, end);
}
use of org.bedework.calfacade.BwDateTime 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.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class DtStartPropUpdater method applyUpdate.
@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
BwEvent ev = ui.getEvent();
boolean scheduleReply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
// No dates valid for reply
DtstartPropType dt = (DtstartPropType) ui.getProp();
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 (!scheduleReply && (ev.getEntityType() != IcalDefs.entityTypeTodo)) {
return new UpdateResult("Entity requires start date");
}
cte.setDeleted(ev.getDtstart());
ds.start = null;
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (!ev.getNoStart()) {
return new UpdateResult("Entity already has start date - cannot add");
}
ds.start = BwDateTime.makeBwDateTime(dt);
cte.setAdded(ds.start);
return UpdateResult.getOkResult();
}
/* Changing dtstart - either value or parameters */
if (ev.getNoStart()) {
return new UpdateResult("Entity has no start date - cannot change");
}
Holder<BwDateTime> resdt = new Holder<BwDateTime>();
UpdateResult ur = makeDt(ev.getDtstart(), resdt, ui);
if (!ur.getOk()) {
return ur;
}
if (resdt.value != null) {
cte.setChanged(ev.getDtstart(), resdt.value);
ds.start = resdt.value;
}
return UpdateResult.getOkResult();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class ExdatePropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
BwEvent ev = ui.getEvent();
ChangeTableEntry cte = ui.getCte();
Set<BwDateTime> evDts = ev.getExdates();
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 exdate 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);
}
}
Aggregations