use of org.bedework.calfacade.BwEventProxy in project bw-calendar-engine by Bedework.
the class EventFieldRule method field.
@Override
public void field(final String name) throws Exception {
if (skippedNames.contains(name)) {
return;
}
DateTimeValues dtv = null;
if (top() instanceof DateTimeValues) {
dtv = (DateTimeValues) pop();
}
EventInfo ei = (EventInfo) getTop(EventInfo.class, name);
BwEventAnnotation ann = null;
BwEvent e = ei.getEvent();
if (e instanceof BwEventProxy) {
ann = ((BwEventProxy) e).getRef();
// e = ann;
}
if (shareableContainedEntityTags(e, name)) {
return;
}
try {
if (name.equals("emptyFlags")) {
char[] flags = stringFld().toCharArray();
for (char c : flags) {
if ((c != 'T') && (c != 'F')) {
error("Bad empty flags '" + stringFld() + "' for event " + ann);
}
}
ann.setEmptyFlags(new String(flags));
/* ------------------- Start/end --------------------------- */
} else if (name.equals("noStart")) {
if (ann != null) {
ann.setNoStart(booleanFld());
} else {
e.setNoStart(booleanFld());
}
} else if (name.equals("dtstart")) {
if (ann != null) {
ann.setDtstart(dateTimeFld(dtv));
} else {
e.setDtstart(dateTimeFld(dtv));
}
} else if (name.equals("dtend")) {
if (ann != null) {
ann.setDtend(dateTimeFld(dtv));
} else {
e.setDtend(dateTimeFld(dtv));
}
} else if (name.equals("duration")) {
// XXX Fix bad duration value due to old bug
String dur = stringFld();
char endType = e.getEndType();
if ("PT1S".equals(dur) && (endType == StartEndComponent.endTypeNone)) {
dur = "PT0S";
}
if (ann != null) {
ann.setDuration(dur);
} else {
e.setDuration(dur);
}
} else if (name.equals("endType")) {
if (ann != null) {
ann.setEndType(charFld());
} else {
e.setEndType(charFld());
}
} else if (name.equals("entityType")) {
e.setEntityType(intFld());
} else if (name.equals("name")) {
if (ann != null) {
ann.setName(stringFld());
} else {
e.setName(stringFld());
}
} else if (name.equals("uid")) {
if (ann != null) {
ann.setUid(stringFld());
} else {
e.setUid(stringFld());
}
} else if (name.equals("classification")) {
e.setClassification(stringFld());
} else if (name.equals("link")) {
e.setLink(stringFld());
} else if (name.equals("geo-latitude")) {
BwGeo geo = e.getGeo();
if (geo == null) {
geo = new BwGeo();
e.setGeo(geo);
}
// geo.setLatitude(bigDecimalFld());
geo.setLatitude(bigDecimalFld());
} else if (name.equals("geo-longitude")) {
BwGeo geo = e.getGeo();
if (geo == null) {
geo = new BwGeo();
e.setGeo(geo);
}
// geo.setLongitude(bigDecimalFld());
geo.setLongitude(bigDecimalFld());
} else if (name.equals("status")) {
String status = stringFld();
if ((status != null) && (!status.equals("F"))) {
// 2.3.2
e.setStatus(status);
}
} else if (name.equals("cost")) {
e.setCost(stringFld());
} else if (name.equals("deleted")) {
e.setDeleted(booleanFld());
} else if (name.equals("tombstoned")) {
e.setTombstoned(booleanFld());
} else if (name.equals("dtstamp")) {
e.setDtstamp(stringFld());
} else if (name.equals("lastmod")) {
e.setLastmod(stringFld());
} else if (name.equals("created")) {
e.setCreated(stringFld());
} else if (name.equals("byteSize")) {
e.setByteSize(intFld());
} else if (name.equals("priority")) {
e.setPriority(integerFld());
} else if (name.equals("transparency")) {
e.setTransparency(stringFld());
} else if (name.equals("relatedTo")) {
// e.setRelatedTo(stringFld());
} else if (name.equals("percentComplete")) {
e.setPercentComplete(integerFld());
} else if (name.equals("completed")) {
e.setCompleted(stringFld());
} else if (name.equals("ctoken")) {
e.setCtoken(stringFld());
/* --------------- Recurrence fields ---------------------- */
} else if (name.equals("recurring")) {
e.setRecurring(new Boolean(booleanFld()));
} else if (name.equals("rrule")) {
e.addRrule(stringFld());
} else if (name.equals("exrule")) {
e.addExrule(stringFld());
} else if (name.equals("rdate")) {
e.addRdate(dateTimeFld(dtv));
} else if (name.equals("exdate")) {
e.addExdate(dateTimeFld(dtv));
} else if (name.equals("recurrenceId")) {
e.setRecurrenceId(stringFld());
} else if (name.equals("latestDate")) {
e.setCtoken(stringFld());
/* --------------- Scheduling fields ---------------------- */
} else if (name.equals("organizer")) {
// pre 3.5
} else if (name.equals("sequence")) {
e.setSequence(intFld());
} else if (name.equals("scheduleMethod")) {
e.setScheduleMethod(intFld());
} else if (name.equals("originator")) {
e.setOriginator(stringFld());
} else if (name.equals("recipient")) {
e.addRecipient(stringFld());
} else if (name.equals("scheduleState")) {
e.setScheduleState(intFld());
} else if (name.equals("organizerSchedulingObject")) {
e.setOrganizerSchedulingObject(booleanFld());
} else if (name.equals("attendeeSchedulingObject")) {
e.setAttendeeSchedulingObject(booleanFld());
} else if (name.equals("stag")) {
e.setStag(stringFld());
/* ------------------- vavailability --------------------------- */
} else if (name.equals("busyType")) {
e.setBusyType(intFld());
/* ------------------- vpoll --------------------------- */
} else if (name.equals("pollCandidate")) {
e.setPollCandidate(booleanFld());
} else {
unknownTag(name);
}
} catch (Exception ex) {
error("Error processing event uid " + e.getUid(), ex);
globals.entityError = true;
}
}
use of org.bedework.calfacade.BwEventProxy in project bw-calendar-engine by Bedework.
the class EventRule method begin.
@Override
public void begin(final String ns, final String name, final Attributes att) throws Exception {
super.begin(ns, kind, att);
BwEvent ev = (BwEvent) pop();
boolean override = (kind.equals(objectOverride));
if (ev instanceof BwEventAnnotation) {
BwEventAnnotation ann = (BwEventAnnotation) ev;
ann.setOverride(override);
ev = new BwEventProxy(ann);
if (override) {
/* The override is embedded in the event so the top() should be the master
* Annotations will get the master and target set later.
*/
EventInfo mei = (EventInfo) top();
ann.setTarget(mei.getEvent());
ann.setMaster(mei.getEvent());
} else {
/* Make up empty event object for us to fill in */
BwEvent e = new BwEventObj();
ann.setTarget(e);
ann.setMaster(e);
}
} else if (override) {
error("Restore error - override but not annotation.");
}
EventInfo ei = new EventInfo(ev);
/* Initialise fields that may be missed when restoring earlier data */
ev.setNoStart(false);
push(ei);
}
use of org.bedework.calfacade.BwEventProxy in project bw-calendar-engine by Bedework.
the class EventInfo method findOverride.
/**
* See if the master event has an override with the given recurrence id.
* If not optionally create one.
*
* @param rid
* @param create - true to creat emissing override.
* @return EventInfo for override
* @throws CalFacadeException
*/
public EventInfo findOverride(final String rid, final boolean create) throws CalFacadeException {
if (overrides != null) {
for (EventOverride eo : overrides) {
if (eo.getEvent().getRecurrenceId().equals(rid)) {
return eo.getEventInfo();
}
}
}
if (!create) {
return null;
}
BwEventProxy proxy = BwEventProxy.makeAnnotation(getEvent(), null, true);
proxy.setRecurring(new Boolean(false));
EventInfo oei = new EventInfo(proxy);
proxy.setRecurrenceId(rid);
oei.setNewEvent(true);
addOverride(oei);
return oei;
}
use of org.bedework.calfacade.BwEventProxy in project bw-calendar-engine by Bedework.
the class Events method copyMoveNamed.
@Override
public CopyMoveStatus copyMoveNamed(final EventInfo fromEi, final BwCalendar to, String name, final boolean copy, final boolean overwrite, final boolean newGuidOK) throws CalFacadeException {
BwEvent ev = fromEi.getEvent();
String fromPath = ev.getColPath();
boolean sameCal = fromPath.equals(to.getPath());
if (name == null) {
name = ev.getName();
}
if (sameCal && name.equals(ev.getName())) {
// No-op
return CopyMoveStatus.noop;
}
try {
// Get the target
final EventInfo destEi = get(to.getPath(), name);
if (destEi != null) {
if (!overwrite) {
return CopyMoveStatus.destinationExists;
}
if (!destEi.getEvent().getUid().equals(ev.getUid())) {
// Not allowed to change uid.
return CopyMoveStatus.changedUid;
}
// deleteEvent(destEi.getEvent(), true);
}
if (!copy) {
if (!sameCal) {
/* Not sure why I was doing a delete+add
delete(from, false, false); // Delete unreffed
if (destEi != null) {
delete(destEi.getEvent(), false, false); // Delete unreffed
}
add(to, newEi, true);
*/
BwCalendar from = getCols().get(fromPath);
getCal().moveEvent(ev, from, to);
getCal().touchCalendar(from);
} else {
// Just changing name
ev.setName(name);
}
ev.updateStag(getCurrentTimestamp());
update(fromEi, false, null);
} else {
// Copying the event.
BwEvent newEvent = (BwEvent) ev.clone();
newEvent.setName(name);
// WebDAV ACL say's new event must not carry over access
newEvent.setAccess(null);
EventInfo newEi = new EventInfo(newEvent);
if (fromEi.getOverrideProxies() != null) {
for (BwEventProxy proxy : fromEi.getOverrideProxies()) {
newEi.addOverride(new EventInfo(proxy.clone(newEvent, newEvent)));
}
}
if (sameCal && newGuidOK) {
// Assign a new guid
newEvent.setUid(null);
assignGuid(newEvent);
}
if (destEi != null) {
delete(destEi, false);
}
newEvent.setColPath(to.getPath());
newEvent.updateStag(getCurrentTimestamp());
add(newEi, true, false, false, true);
}
if (destEi != null) {
return CopyMoveStatus.ok;
}
return CopyMoveStatus.created;
} catch (CalFacadeException cfe) {
if (cfe.getMessage().equals(CalFacadeException.duplicateGuid)) {
return CopyMoveStatus.duplicateUid;
}
throw cfe;
}
}
use of org.bedework.calfacade.BwEventProxy in project bw-calendar-engine by Bedework.
the class Events method processExpanded.
private Collection<EventInfo> processExpanded(final Collection<EventInfo> events, final RecurringRetrievalMode recurRetrieval) throws CalFacadeException {
Collection<EventInfo> res = new ArrayList<>();
for (EventInfo ei : events) {
BwEvent ev = ei.getEvent();
if (!ev.getRecurring()) {
res.add(ei);
continue;
}
CurrentAccess ca = ei.getCurrentAccess();
Set<EventInfo> oveis = ei.getOverrides();
if (!Util.isEmpty(oveis)) {
for (EventInfo oei : oveis) {
if (oei.getEvent().inDateTimeRange(recurRetrieval.start.getDate(), recurRetrieval.end.getDate())) {
oei.setRetrievedEvent(ei);
res.add(oei);
}
}
}
/* Generate non-overridden instances. */
final Collection<Recurrence> instances = RecurUtil.getRecurrences(ei, getAuthpars().getMaxYears(), getAuthpars().getMaxInstances(), recurRetrieval.getStartDate(), recurRetrieval.getEndDate());
if (instances == null) {
return res;
}
for (final Recurrence rec : instances) {
if (rec.override != null) {
continue;
}
final BwEventAnnotation ann = new BwEventAnnotation();
ann.setDtstart(rec.start);
ann.setDtend(rec.end);
ann.setRecurrenceId(rec.recurrenceId);
ann.setOwnerHref(ev.getOwnerHref());
// Call it an override
ann.setOverride(true);
ann.setTombstoned(false);
ann.setName(ev.getName());
ann.setUid(ev.getUid());
ann.setTarget(ev);
ann.setMaster(ev);
final BwEvent proxy = new BwEventProxy(ann);
final EventInfo oei = new EventInfo(proxy);
oei.setCurrentAccess(ei.getCurrentAccess());
oei.setRetrievedEvent(ei);
res.add(oei);
}
}
return res;
}
Aggregations