use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class ProcessPrefs method process.
@Override
boolean process() throws Throwable {
String wd = word();
if (wd == null) {
return false;
}
if ("help".equals(wd)) {
addInfo("prefs <preference>* \n" + " set given prefs for current user\n\n" + "<preference> is one or more of\n" + " defaultCategory = \"word\"\n" + " defaultViewMode = \"list\"\n" + " viewPeriod = \"dayView\"\n" + " defaultTzid = \"America/New_York\"\n" + " pageSize = \"10\"\n" + " preferredEndType = \"duration\"\n" + " preferredView = \"All\"\n" + " hour24 = \"false\"");
return true;
}
try {
open();
final BwPreferences prefs = getPrefs();
if (prefs == null) {
error("Unable to fetch prefs for current user");
// No change
return true;
}
Set<String> catUids = new TreeSet<>();
while (wd != null) {
switch(wd) {
case "defaultImageDirectory":
final BwCalendar cal = getCal();
if (cal == null) {
error("Unknown calendar");
return true;
}
prefs.setDefaultImageDirectory(cal.getPath());
break;
case "preferredView":
/*if (cl.getView(str) == null) {
form.getErr().emit(ClientError.unknownView, str);
return forwardNotFound;
}*/
prefs.setPreferredView(quotedVal());
break;
case "defaultCategory":
final String catwd = wordOrQuotedVal();
if (catwd == null) {
error("Expect category uid");
return true;
}
if (catwd.equals("removeall")) {
// Remove all
prefs.removeProperties(BwPreferences.propertyDefaultCategory);
break;
}
final BwCategory cat = getCat(null, catwd);
if (cat == null) {
error("Unknown category " + catwd);
return true;
}
catUids.add(cat.getUid());
break;
case "hour24":
prefs.setHour24(Boolean.valueOf(word()));
break;
case "skin":
prefs.setSkinName(wordOrQuotedVal());
break;
case "skinStyle":
prefs.setSkinStyle(wordOrQuotedVal());
break;
case "email":
prefs.setEmail(quotedVal());
break;
case "preferredEndType":
final String str = word();
if (BwPreferences.preferredEndTypeDuration.equals(str) || BwPreferences.preferredEndTypeDate.equals(str)) {
prefs.setPreferredEndType(str);
} else {
error("Invalid end type " + str);
return true;
}
break;
}
// switch
wd = word();
}
if (!Util.isEmpty(catUids)) {
prefs.setDefaultCategoryUids(catUids);
}
getSvci().getPrefsHandler().update(prefs);
} finally {
close();
}
return true;
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class ProcessRealias method doRealias.
private int doRealias(final EventInfo ei, final String fromHref, final BwXproperty xp, final boolean add, final boolean remove) throws Throwable {
final BwEvent ev = ei.getEvent();
int updated = 0;
boolean changed = false;
if (!add) {
// We need to remove the from alias
boolean found = false;
for (final BwXproperty xpi : ev.getXproperties(BwXproperty.bedeworkAlias)) {
if (xpi.getValue().equals(fromHref)) {
ev.removeXproperty(xpi);
found = true;
changed = true;
break;
}
}
if (!found) {
warn("Unable to find " + fromHref);
}
}
if (!remove) {
// Need to add a new one.
ev.addXproperty(xp);
changed = true;
}
final RealiasResult resp = getSvci().getEventsHandler().reAlias(ei.getEvent());
if (resp.getStatus() != ok) {
warn("Status from reAlias was " + resp.getStatus() + " message was " + resp.getMessage());
return 0;
}
if (!add) {
// Remove all the categories for the from alias
final Set<BwCategory> fromCats = getCols().getCategorySet(fromHref);
if (!Util.isEmpty(fromCats) && !Util.isEmpty(ev.getCategories())) {
for (final BwCategory cat : fromCats) {
if (ev.getCategories().remove(cat)) {
changed = true;
}
}
}
}
/* Now we need to adjust for the new alias
*/
final Set<BwCategory> cats = resp.getCats();
if (!Util.isEmpty(cats)) {
for (final BwCategory cat : cats) {
ev.addCategory(cat);
}
changed = true;
}
ei.clearChangeset();
final EventInfo.UpdateResult ur = getSvci().getEventsHandler().update(ei, true);
if (ur.hasChanged) {
updated++;
}
if (!Util.isEmpty(ei.getOverrides())) {
for (final EventInfo ovei : ei.getOverrides()) {
updated += doRealias(ovei, fromHref, xp, add, remove);
}
}
return updated;
}
Aggregations