use of org.bedework.calfacade.svc.BwCalSuite in project bw-calendar-engine by Bedework.
the class ProcessCalsuite method process.
@Override
boolean process() throws Throwable {
final String wd = word();
if (wd == null) {
return false;
}
if ("help".equals(wd)) {
pstate.addInfo("calsuite <name>\n" + " switch to event owner for calsuite\n" + "calsuite <name> addapprover <account>\n" + " add an approver\n" + "calsuite <name> remapprover <account>\n" + " remove an approver");
return true;
}
final String account;
try {
open();
final BwCalSuite cs = getSvci().getCalSuitesHandler().get(wd);
if (cs == null) {
error("No calsuite with name " + wd);
return true;
}
final BwAdminGroup adminGrp = cs.getGroup();
if (adminGrp == null) {
error("No admin group for calsuite " + wd);
return true;
}
final String ownerHref = adminGrp.getOwnerHref();
if (ownerHref == null) {
error("No owner href in admin group " + adminGrp + " for calsuite " + wd);
return true;
}
final BwPrincipal ownerPr = getSvci().getPrincipal(ownerHref);
if (ownerPr == null) {
error("No user with owner href " + ownerHref + " in admin group " + adminGrp + " for calsuite " + wd);
return true;
}
final String action = word();
account = ownerPr.getAccount();
if (action == null) {
pstate.setCalsuite(cs);
return true;
}
final boolean addAppprover = "addapprover".equals(action);
if (!addAppprover && !"remapprover".equals(action)) {
error("Expected addapprover or remapprover");
return false;
}
final String appAccount = word();
if (appAccount == null) {
error("Expected an account");
}
final BwPreferences prefs = getSvci().getPrefsHandler().get(ownerPr);
final List<String> approvers = prefs.getCalsuiteApproversList();
if (Util.isEmpty(approvers)) {
if (addAppprover) {
prefs.setCalsuiteApprovers(appAccount);
}
} else {
if (addAppprover) {
if (!approvers.contains(appAccount)) {
approvers.add(appAccount);
}
} else {
approvers.remove(appAccount);
}
prefs.setCalsuiteApprovers(String.join(",", approvers));
}
getSvci().getPrefsHandler().update(prefs);
} finally {
close();
}
setUser(account, false);
return true;
}
Aggregations