use of org.bedework.calfacade.BwString in project bw-calendar-engine by Bedework.
the class XbwContactPropUpdater method checkContact.
private boolean checkContact(final UpdateInfo ui, final BwEvent ev, final Set<BwContact> contacts, final String lang, final String val) throws CalFacadeException {
final BwString sval = new BwString(lang, val);
final BwContact contact = ui.getIcalCallback().findContact(sval);
if (contact == null) {
return false;
}
for (final BwContact c : contacts) {
if (c.getCn().equals(sval)) {
// Already present
return true;
}
}
ev.addContact(contact);
ui.getCte(PropertyIndex.PropertyInfoIndex.CONTACT).addAddedValue(contact);
return true;
}
use of org.bedework.calfacade.BwString in project bw-calendar-engine by Bedework.
the class XbwLocPropUpdater method checkLocation.
private boolean checkLocation(final UpdateInfo ui, final BwEvent ev, final String lang, final String val, final String keyName) throws CalFacadeException {
final boolean locPresent = ev.getLocation() != null;
final BwLocation loc;
if (keyName == null) {
final BwString sval = new BwString(lang, val);
loc = ui.getIcalCallback().getLocation(sval);
if (loc == null) {
return false;
}
} else {
final GetEntityResponse<BwLocation> resp = ui.getIcalCallback().fetchLocationByKey(keyName, val);
if (resp.getStatus() != ok) {
return false;
}
loc = resp.getEntity();
}
ev.setLocation(loc);
if (locPresent) {
ui.getCte(PropertyIndex.PropertyInfoIndex.LOCATION).addChangedValue(loc);
} else {
ui.getCte(PropertyIndex.PropertyInfoIndex.LOCATION).addValue(loc);
}
return true;
}
use of org.bedework.calfacade.BwString in project bw-calendar-engine by Bedework.
the class LangTextListPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
BwEvent ev = ui.getEvent();
Collection<String> adds = new ArrayList<String>();
Collection<String> removes = new ArrayList<String>();
/* Figure out what we need to add/remove */
TextListPropertyType prop = (TextListPropertyType) ui.getProp();
String lang = UpdaterUtil.getLang(ui.getProp());
if (ui.isAdd()) {
adds.addAll(prop.getText());
} else if (ui.isRemove()) {
removes.addAll(prop.getText());
} else {
// Diff the prop value and the updProp value
TextListPropertyType updProp = (TextListPropertyType) ui.getUpdprop();
List<String> oldVals = prop.getText();
List<String> updVals = updProp.getText();
for (String s : updVals) {
if (!oldVals.contains(s)) {
adds.add(s);
}
}
for (String s : oldVals) {
if (!updVals.contains(s)) {
removes.add(s);
}
}
}
for (String s : adds) {
addValue(ev, new BwString(lang, s), ui);
}
for (String s : removes) {
if (!removeValue(ev, new BwString(lang, s), ui)) {
break;
}
}
return UpdateResult.getOkResult();
}
use of org.bedework.calfacade.BwString in project bw-calendar-engine by Bedework.
the class LocationPropUpdater method applyUpdate.
@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final BwEvent ev = ui.getEvent();
final ChangeTableEntry cte = ui.getCte();
BwString val = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
final BwLocation evLoc = ev.getLocation();
BwString evVal = null;
if (evLoc != null) {
evVal = evLoc.getAddress();
}
if (ui.isRemove()) {
if (evVal == null) {
return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
}
val = null;
} else if (ui.isAdd()) {
if (evVal != null) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
}
} else if (!ui.isChange()) {
final ParameterUpdater.UpdateInfo langUpd = UpdaterUtil.findLangUpdate(ui.getParamUpdates());
if (langUpd == null) {
return new UpdateResult("No update specified for " + ui.getPropName());
}
String lang = val.getLang();
if (langUpd.isRemove()) {
lang = null;
} else if (langUpd.isAdd()) {
lang = ((TextParameterType) langUpd.getParam()).getText();
} else if (langUpd.getUpdparam() != null) {
lang = ((TextParameterType) langUpd.getUpdparam()).getText();
}
if (!Util.equalsString(lang, val.getLang())) {
val = new BwString(lang, val.getValue());
}
} else {
if (!val.equals(evVal)) {
return new UpdateResult("Values don't match for update to " + ui.getPropName());
}
val = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
}
if (val == null) {
cte.setDeleted(ev.getLocation());
ev.setLocation(null);
} else if (Util.cmpObjval(val, evVal) != 0) {
BwLocation loc = ui.getIcalCallback().findLocation(val);
if (loc == null) {
loc = BwLocation.makeLocation();
loc.setAddress(val);
ui.getIcalCallback().addLocation(loc);
}
if (cte.setChanged(evLoc, loc)) {
ev.setLocation(loc);
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwString in project bw-calendar-engine by Bedework.
the class EntityBuilder method makeEvent.
/**
* @param expanded true if we are doing this for an expanded retrieval
* that is, treat everything as instances.
* @return an event object
* @throws CalFacadeException on error
*/
@SuppressWarnings("unchecked")
EventInfo makeEvent(final String id, final boolean expanded) throws CalFacadeException {
final boolean override = !expanded && getBool(PropertyInfoIndex.OVERRIDE);
final boolean tryCache = (currentMode == guestMode) && publick;
final String cacheKey = id + override;
retrievals++;
if (tryCache) {
checkPurge();
final EventCacheEntry ece = eventCache.get(cacheKey);
if (ece != null) {
hits++;
ece.update();
if (debug && ((retrievals % 500) == 0)) {
debug("Retrievals: " + retrievals + " hits: " + hits + " purges: " + purges + " flushes: " + flushes + " size: " + eventCache.size());
}
return ece.ei;
}
}
final BwEvent ev;
if (override) {
ev = new BwEventAnnotation();
final BwEventAnnotation ann = (BwEventAnnotation) ev;
ann.setOverride(true);
} else {
ev = new BwEventObj();
}
final EventInfo ei = new EventInfo(ev);
/*
Float score = (Float)sd.getFirstValue("score");
if (score != null) {
bwkey.setScore(score);
}
*/
restoreSharedEntity(ev);
ev.setDeleted(getBool(PropertyInfoIndex.DELETED));
ev.setName(getString(PropertyInfoIndex.NAME));
ev.setCalSuite(getString(PropertyInfoIndex.CALSUITE));
restoreCategories(ev);
ev.setSummaries((Set<BwString>) restoreBwStringSet(PropertyInfoIndex.SUMMARY, false));
ev.setDescriptions((Set<BwLongString>) restoreBwStringSet(PropertyInfoIndex.DESCRIPTION, true));
ev.setEntityType(makeEntityType(getString(PropertyInfoIndex.ENTITY_TYPE)));
ev.setClassification(getString(PropertyInfoIndex.CLASS));
ev.setLink(getString(PropertyInfoIndex.URL));
ev.setGeo(restoreGeo());
ev.setStatus(getString(PropertyInfoIndex.STATUS));
ev.setCost(getString(PropertyInfoIndex.COST));
ev.setOrganizer(restoreOrganizer());
ev.setDtstamp(getString(PropertyInfoIndex.DTSTAMP));
ev.setLastmod(getString(PropertyInfoIndex.LAST_MODIFIED));
ev.setCreated(getString(PropertyInfoIndex.CREATED));
ev.setStag(getString(PropertyInfoIndex.SCHEDULE_TAG));
ev.setPriority(getInteger(PropertyInfoIndex.PRIORITY));
ev.setSequence(getInt(PropertyInfoIndex.SEQUENCE));
ev.setLocationUid(getString(PropertyInfoIndex.LOCATION_UID));
ev.setUid(getString(PropertyInfoIndex.UID));
ev.setTransparency(getString(PropertyInfoIndex.TRANSP));
ev.setPercentComplete(getInteger(PropertyInfoIndex.PERCENT_COMPLETE));
ev.setCompleted(getString(PropertyInfoIndex.COMPLETED));
ev.setScheduleMethod(getInt(PropertyInfoIndex.SCHEDULE_METHOD));
ev.setOriginator(getString(PropertyInfoIndex.ORIGINATOR));
ev.setScheduleState(getInt(PropertyInfoIndex.SCHEDULE_STATE));
ev.setOrganizerSchedulingObject(getBoolean(PropertyInfoIndex.ORGANIZER_SCHEDULING_OBJECT));
ev.setAttendeeSchedulingObject(getBoolean(PropertyInfoIndex.ATTENDEE_SCHEDULING_OBJECT));
ev.setRelatedTo(restoreRelatedTo());
ev.setXproperties(restoreXprops());
restoreReqStat(ev);
ev.setCtoken(getString(PropertyInfoIndex.CTOKEN));
ev.setRecurring(getBoolean(PropertyInfoIndex.RECURRING));
ev.setRecurrenceId(getString(PropertyInfoIndex.RECURRENCE_ID));
ev.setRrules(getStringSet(PropertyInfoIndex.RRULE));
ev.setExrules(getStringSet(PropertyInfoIndex.EXRULE));
ev.setRdates(restoreBwDateTimeSet(PropertyInfoIndex.RDATE));
ev.setExdates(restoreBwDateTimeSet(PropertyInfoIndex.EXDATE));
ev.setDtstart(unindexDate(PropertyInfoIndex.DTSTART));
ev.setDtend(unindexDate(PropertyInfoIndex.DTEND));
ev.setNoStart(Boolean.parseBoolean(getString(PropertyInfoIndex.NO_START)));
ev.setEndType(getString(PropertyInfoIndex.END_TYPE).charAt(0));
ev.setDuration(getString(PropertyInfoIndex.DURATION));
ev.setAlarms(restoreAlarms());
/* uuu Attachment */
final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
ev.setAttendees(restoreAttendees(vpoll));
ev.setRecipients(getStringSet(PropertyInfoIndex.RECIPIENT));
ev.setComments((Set<BwString>) restoreBwStringSet(PropertyInfoIndex.COMMENT, false));
restoreContacts(ev);
ev.setResources((Set<BwString>) restoreBwStringSet(PropertyInfoIndex.RESOURCES, false));
if (vpoll) {
final Set<String> pollItems = getStringSet(PropertyInfoIndex.POLL_ITEM);
if (!Util.isEmpty(pollItems)) {
for (final String s : pollItems) {
ev.addPollItem(s);
}
}
ev.setPollMode(getString(PropertyInfoIndex.POLL_MODE));
ev.setPollWinner(getInteger(PropertyInfoIndex.POLL_WINNER));
ev.setPollProperties(getString(PropertyInfoIndex.POLL_PROPERTIES));
}
if (tryCache) {
synchronized (eventCache) {
eventCache.put(cacheKey, new EventCacheEntry(cacheKey, ei));
}
}
return ei;
}
Aggregations