use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class RdatePropUpdater method addDt.
private boolean addDt(final BwDateTime newdt, final Set<BwDateTime> evDts, final ChangeTableEntry cte) {
if (!Util.isEmpty(evDts)) {
for (BwDateTime evDt : evDts) {
if (evDt.getDate().equals(newdt.getDate())) {
// Already there
return false;
}
}
}
evDts.add(newdt);
cte.addAddedValue(newdt);
return true;
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class RdatePropUpdater method removeDt.
private boolean removeDt(final String dtUTC, final Set<BwDateTime> evDts, final ChangeTableEntry cte) {
if (Util.isEmpty(evDts)) {
// Nothing to remove
return false;
}
for (BwDateTime evDt : evDts) {
if (evDt.getDate().equals(dtUTC)) {
evDts.remove(evDt);
cte.addRemovedValue(evDt);
break;
}
}
return true;
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method indexEvent.
private IndexResponse indexEvent(final EventInfo ei) throws CalFacadeException {
try {
/* If it's not recurring or a stand-alone instance index it */
final BwEvent ev = ei.getEvent();
if (!ev.testRecurring() && (ev.getRecurrenceId() == null)) {
return indexEvent(ei, ItemKind.master, ev.getDtstart(), ev.getDtend(), // ev.getRecurrenceId(),
null, null);
}
if (ev.getRecurrenceId() != null) {
error("Not implemented - index of single override");
return null;
}
/* Delete all instances of this event: we'll do a delete by query
* We need to find all with the same path and uid.
*/
/* TODO - do a query for all recurrence ids and delete the ones
we don't want.
*/
deleteEvent(ei);
/* Create a list of all instance date/times before overrides. */
final int maxYears;
final int maxInstances;
final DateLimits dl = new DateLimits();
if (ev.getPublick()) {
maxYears = unauthpars.getMaxYears();
maxInstances = unauthpars.getMaxInstances();
} else {
maxYears = authpars.getMaxYears();
maxInstances = authpars.getMaxInstances();
}
final RecurPeriods rp = RecurUtil.getPeriods(ev, maxYears, maxInstances);
if (rp.instances.isEmpty()) {
// No instances for an alleged recurring event.
return null;
// throw new CalFacadeException(CalFacadeException.noRecurrenceInstances);
}
final String stzid = ev.getDtstart().getTzid();
int instanceCt = maxInstances;
final boolean dateOnly = ev.getDtstart().getDateType();
/* First build a table of overrides so we can skip these later
*/
final Map<String, String> overrides = new HashMap<>();
/*
if (!Util.isEmpty(ei.getOverrideProxies())) {
for (BwEvent ov: ei.getOverrideProxies()) {
overrides.put(ov.getRecurrenceId(), ov.getRecurrenceId());
}
}
*/
final IndexResponse iresp;
if (!Util.isEmpty(ei.getOverrides())) {
for (final EventInfo oei : ei.getOverrides()) {
final BwEvent ov = oei.getEvent();
overrides.put(ov.getRecurrenceId(), ov.getRecurrenceId());
final String start;
if (ov.getDtstart().getDateType()) {
start = ov.getRecurrenceId().substring(0, 8);
} else {
start = ov.getRecurrenceId();
}
final BwDateTime rstart = BwDateTime.makeBwDateTime(ov.getDtstart().getDateType(), start, stzid);
final BwDateTime rend = rstart.addDuration(BwDuration.makeDuration(ov.getDuration()));
/*iresp = */
indexEvent(oei, ItemKind.override, rstart, rend, ov.getRecurrenceId(), dl);
instanceCt--;
}
}
for (final Period p : rp.instances) {
String dtval = p.getStart().toString();
if (dateOnly) {
dtval = dtval.substring(0, 8);
}
final BwDateTime rstart = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
if (overrides.get(rstart.getDate()) != null) {
// Overrides indexed separately - skip this instance.
continue;
}
final String recurrenceId = rstart.getDate();
dtval = p.getEnd().toString();
if (dateOnly) {
dtval = dtval.substring(0, 8);
}
final BwDateTime rend = BwDateTime.makeBwDateTime(dateOnly, dtval, stzid);
/*iresp = */
indexEvent(ei, entity, rstart, rend, recurrenceId, dl);
instanceCt--;
if (instanceCt == 0) {
// That's all you're getting from me
break;
}
}
// </editor-fold>
// <editor-fold desc="Emit the master event with a date range covering the entire period.">
final BwDateTime start = BwDateTime.makeBwDateTime(dateOnly, dl.minStart, stzid);
final BwDateTime end = BwDateTime.makeBwDateTime(dateOnly, dl.maxEnd, stzid);
iresp = indexEvent(ei, ItemKind.master, start, end, null, null);
return iresp;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class DocBuilder method makeBwDateTimes.
private void makeBwDateTimes(final PropertyInfoIndex pi, final Set<BwDateTime> vals) throws CalFacadeException {
try {
if (Util.isEmpty(vals)) {
return;
}
startArray(getJname(pi));
for (final BwDateTime dt : vals) {
indexDate(null, dt);
}
endArray();
} catch (final IndexException e) {
throw new CalFacadeException(e);
}
}
use of org.bedework.calfacade.BwDateTime in project bw-calendar-engine by Bedework.
the class EntityBuilder method restoreBwDateTimeSet.
private Set<BwDateTime> restoreBwDateTimeSet(final PropertyInfoIndex pi) throws CalFacadeException {
final List<Object> vals = getFieldValues(pi);
if (Util.isEmpty(vals)) {
return null;
}
final Set<BwDateTime> tms = new TreeSet<>();
for (final Object o : vals) {
try {
pushFields(o);
final String date = getString(PropertyInfoIndex.LOCAL);
final String utcDate = getString(PropertyInfoIndex.UTC);
final String tzid = getString(PropertyInfoIndex.TZID);
final boolean floating = getBool(PropertyInfoIndex.FLOATING);
final boolean dateType = date.length() == 8;
final BwDateTime tm = BwDateTime.makeBwDateTime(dateType, date, utcDate, tzid, floating);
tms.add(tm);
} catch (final IndexException ie) {
throw new CalFacadeException(ie);
} finally {
popFields();
}
}
return tms;
}
Aggregations