use of org.bedework.calfacade.BwLocation in project bw-calendar-engine by Bedework.
the class XbwLocPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xlocs = ev.getXproperties(xBedeworkLocation);
// Should only be one or zero
final BwXproperty xloc;
if (Util.isEmpty(xlocs)) {
xloc = null;
} else {
xloc = xlocs.get(0);
}
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = ((TextPropertyType) ui.getProp()).getText();
final BaseParameterType keyParam = XcalUtil.findParam(ui.getProp(), XcalTags.xBedeworkLocationKey);
final String keyName;
if (keyParam != null) {
keyName = ((TextParameterType) keyParam).getText();
} else {
keyName = null;
}
final BwLocation evLoc = ev.getLocation();
if (ui.isRemove()) {
if (xlocs == null) {
// Nothing to remove
return UpdateResult.getOkResult();
}
// TODO - match values?
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
if (evLoc != null) {
ev.setLocation(null);
cte.addRemovedValue(evLoc);
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (xloc != null) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
}
if (!checkLocation(ui, ev, lang, xval, null)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addAddedValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
if (xloc == null) {
return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot change");
}
if (CalFacadeUtil.cmpObjval(xval, xloc.getValue()) != 0) {
return new UpdateResult("Values don't match for update to " + ui.getPropName());
}
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
if (!checkLocation(ui, ev, nlang, nxval, keyName)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
if (keyName != null) {
nxp.getParameters().add(new Xpar(XcalTags.xBedeworkLocationKey.getLocalPart(), keyName));
}
ev.addXproperty(nxp);
cte.addAddedValue(nxp);
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwLocation in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method fetchLocationByKey.
@Override
public GetEntityResponse<BwLocation> fetchLocationByKey(final String name, final String val) {
final GetEntityResponse<BwLocation> resp = new GetEntityResponse<>();
try {
final SearchHit hit = fetchEntity(docTypeLocation, getFilters(null).locationKeyFilter(name, val));
if (hit == null) {
return notFound(resp);
}
final EntityBuilder eb = getEntityBuilder(hit.sourceAsMap());
final BwLocation loc = eb.makeLocation();
if (loc == null) {
return notFound(resp);
}
resp.setEntity(loc);
return resp;
} catch (final CalFacadeException cfe) {
return errorReturn(resp, cfe);
}
}
use of org.bedework.calfacade.BwLocation in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method restoreEvProps.
private boolean restoreEvProps(final Response resp, final EventInfo ei) {
final BwEvent ev = ei.getEvent();
try {
final Set<String> catUids = ev.getCategoryUids();
if (!Util.isEmpty(catUids)) {
for (final String uid : catUids) {
BwCategory evprop = categories.get(uid);
if (evprop == null) {
evprop = fetchCat(uid, PropertyInfoIndex.UID);
if (evprop == null) {
warn("Unable to fetch category " + uid + " for event " + ev.getHref());
errorReturn(resp, "Unable to fetch category " + uid);
continue;
}
}
ev.addCategory(evprop);
}
}
final Set<String> contactUids = ev.getContactUids();
if (!Util.isEmpty(contactUids)) {
for (final String uid : contactUids) {
BwContact evprop = contacts.get(uid);
if (evprop == null) {
evprop = fetchContact(uid, PropertyInfoIndex.UID);
if (evprop == null) {
warn("Unable to fetch contact " + uid + " for event " + ev.getHref());
errorReturn(resp, "Unable to fetch contact " + uid);
continue;
}
}
ev.addContact(evprop);
}
}
final String uid = ev.getLocationUid();
if (uid != null) {
BwLocation evprop = locations.get(uid);
if (evprop == null) {
evprop = fetchLocation(uid, PropertyInfoIndex.UID);
if (evprop == null) {
warn("Unable to fetch location " + uid + " for event " + ev.getHref());
errorReturn(resp, "Unable to fetch location " + uid);
}
}
if (evprop != null) {
ev.setLocation(evprop);
}
}
return resp.getStatus() == ok;
} catch (final Throwable t) {
errorReturn(resp, t);
return false;
}
}
use of org.bedework.calfacade.BwLocation in project bw-calendar-engine by Bedework.
the class DocBuilder method makeDoc.
/* Return the docinfo for the indexer */
EsDocInfo makeDoc(final EventInfo ei, final ItemKind kind, final BwDateTime start, final BwDateTime end, final String recurid) throws CalFacadeException {
try {
final BwEvent ev = ei.getEvent();
final long version = ev.getMicrosecsVersion();
if (start == null) {
warn("No start for " + ev);
return null;
}
if (end == null) {
warn("No end for " + ev);
return null;
}
/* Start doc and do common collection/event fields */
startObject();
makeShareableContained(ev);
makeField(PropertyInfoIndex.DELETED, ev.getDeleted());
makeField(PropertyInfoIndex.NAME, ev.getName());
makeField(PropertyInfoIndex.HREF, ev.getHref());
makeField(PropertyInfoIndex.CALSUITE, ev.getCalSuite());
indexCategories(ev.getCategories());
makeField(PropertyInfoIndex.ENTITY_TYPE, IcalDefs.entityTypeNames[ev.getEntityType()]);
indexBwStrings(PropertyInfoIndex.DESCRIPTION, ev.getDescriptions());
indexBwStrings(PropertyInfoIndex.SUMMARY, ev.getSummaries());
makeField(PropertyInfoIndex.CLASS, ev.getClassification());
makeField(PropertyInfoIndex.URL, ev.getLink());
indexGeo(ev.getGeo());
makeField(PropertyInfoIndex.STATUS, ev.getStatus());
makeField(PropertyInfoIndex.COST, ev.getCost());
indexOrganizer(ev.getOrganizer());
makeField(PropertyInfoIndex.DTSTAMP, ev.getDtstamp());
makeField(PropertyInfoIndex.LAST_MODIFIED, ev.getLastmod());
makeField(PropertyInfoIndex.CREATED, ev.getCreated());
makeField(PropertyInfoIndex.SCHEDULE_TAG, ev.getStag());
makeField(PropertyInfoIndex.PRIORITY, ev.getPriority());
if (ev.getSequence() != 0) {
makeField(PropertyInfoIndex.SEQUENCE, ev.getSequence());
}
final BwLocation loc = ev.getLocation();
if (loc != null) {
loc.fixNames(basicSysprops, principal);
makeField(PropertyInfoIndex.LOCATION_UID, loc.getUid());
String s = null;
if (loc.getAddress() != null) {
s = loc.getAddress().getValue();
}
if (loc.getSubaddress() != null) {
if (s == null) {
s = loc.getSubaddress().getValue();
} else {
s = s + " " + loc.getSubaddress().getValue();
}
}
if (s != null) {
makeField(PropertyInfoIndex.LOCATION_STR, s);
}
} else {
// Try the uid
final String locuid = ev.getLocationUid();
if (locuid != null) {
makeField(PropertyInfoIndex.LOCATION_UID, locuid);
}
}
makeField(PropertyInfoIndex.UID, ev.getUid());
makeField(PropertyInfoIndex.TRANSP, ev.getTransparency());
makeField(PropertyInfoIndex.PERCENT_COMPLETE, ev.getPercentComplete());
makeField(PropertyInfoIndex.COMPLETED, ev.getCompleted());
makeField(PropertyInfoIndex.SCHEDULE_METHOD, ev.getScheduleMethod());
makeField(PropertyInfoIndex.ORIGINATOR, ev.getOriginator());
makeField(PropertyInfoIndex.SCHEDULE_STATE, ev.getScheduleState());
makeField(PropertyInfoIndex.ORGANIZER_SCHEDULING_OBJECT, ev.getOrganizerSchedulingObject());
makeField(PropertyInfoIndex.ATTENDEE_SCHEDULING_OBJECT, ev.getAttendeeSchedulingObject());
indexRelatedTo(ev.getRelatedTo());
indexXprops(ev);
indexReqStat(ev.getRequestStatuses());
makeField(PropertyInfoIndex.CTOKEN, ev.getCtoken());
makeField(PropertyInfoIndex.RECURRING, ev.getRecurring());
if (recurid != null) {
makeField(PropertyInfoIndex.RECURRENCE_ID, recurid);
}
makeField(PropertyInfoIndex.RRULE, ev.getRrules());
makeField(PropertyInfoIndex.EXRULE, ev.getExrules());
makeBwDateTimes(PropertyInfoIndex.RDATE, ev.getRdates());
makeBwDateTimes(PropertyInfoIndex.EXDATE, ev.getExdates());
if (kind == ItemKind.entity) {
indexDate(PropertyInfoIndex.DTSTART, start);
indexDate(PropertyInfoIndex.DTEND, end);
indexDate(PropertyInfoIndex.INDEX_START, start);
indexDate(PropertyInfoIndex.INDEX_END, end);
makeField(PropertyInfoIndex.INSTANCE, true);
} else {
if (kind == ItemKind.override) {
makeField(PropertyInfoIndex.OVERRIDE, true);
} else {
makeField(PropertyInfoIndex.MASTER, true);
}
indexDate(PropertyInfoIndex.DTSTART, ev.getDtstart());
indexDate(PropertyInfoIndex.DTEND, ev.getDtend());
indexDate(PropertyInfoIndex.INDEX_START, start);
indexDate(PropertyInfoIndex.INDEX_END, end);
}
makeField(PropertyInfoIndex.NO_START, String.valueOf(ev.getNoStart()));
makeField(PropertyInfoIndex.END_TYPE, String.valueOf(ev.getEndType()));
makeField(PropertyInfoIndex.DURATION, ev.getDuration());
indexAlarms(start, ev.getAlarms());
/* Attachment */
final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
if (ev.getNumAttendees() > 0) {
indexAttendees(ev.getAttendees(), vpoll);
}
makeField(PropertyInfoIndex.RECIPIENT, ev.getRecipients());
indexBwStrings(PropertyInfoIndex.COMMENT, ev.getComments());
indexContacts(ev.getContacts());
indexBwStrings(PropertyInfoIndex.RESOURCES, ev.getResources());
/* freebusy */
/* Available */
/* vpoll */
final String docType;
if (vpoll) {
docType = BwIndexer.docTypePoll;
if (!Util.isEmpty(ev.getPollItems())) {
makeField(PropertyInfoIndex.POLL_ITEM, ev.getPollItems());
}
makeField(PropertyInfoIndex.POLL_MODE, ev.getPollMode());
makeField(PropertyInfoIndex.POLL_WINNER, ev.getPollWinner());
makeField(PropertyInfoIndex.POLL_PROPERTIES, ev.getPollProperties());
} else {
docType = BwIndexer.docTypeEvent;
}
endObject();
return makeDocInfo(docType, version, keys.makeKeyVal(getItemType(ei, kind), ei.getEvent().getHref(), recurid));
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwLocation in project bw-calendar-engine by Bedework.
the class EntityBuilder method makeLocation.
BwLocation makeLocation() throws CalFacadeException {
final BwLocation ent = new BwLocation();
restoreSharedEntity(ent);
ent.setUid(getString(PropertyInfoIndex.UID));
ent.setAddress((BwString) restoreBwString(PropertyInfoIndex.ADDRESS, false));
ent.setSubaddress((BwString) restoreBwString(PropertyInfoIndex.SUBADDRESS, false));
ent.setLink(getString(PropertyInfoIndex.URL));
return ent;
}
Aggregations