use of org.bedework.calfacade.svc.BwView in project bw-calendar-engine by Bedework.
the class ProcessCreate method createView.
private boolean createView(final String name) throws Throwable {
if (debug) {
debug("About to create view " + name);
}
if (name == null) {
addError("Must supply name");
return false;
}
try {
open();
final BwView view = new BwView();
view.setName(name);
if (!getSvci().getViewsHandler().add(view, false)) {
error("view " + name + "already exists.");
}
return true;
} finally {
close();
}
}
use of org.bedework.calfacade.svc.BwView in project bw-calendar-engine by Bedework.
the class ProcessDelete method deleteView.
private boolean deleteView(final String name) throws Throwable {
if (debug) {
debug("About to delete view " + name);
}
if (name == null) {
addError("Must supply name");
return false;
}
try {
open();
final BwView view = getSvci().getViewsHandler().find(name);
if (view == null) {
addError("View " + name + " not found");
return false;
}
return getSvci().getViewsHandler().remove(view);
} finally {
close();
}
}
use of org.bedework.calfacade.svc.BwView in project bw-calendar-engine by Bedework.
the class ProcessDelete method deleteAll.
private boolean deleteAll(final String type) throws Throwable {
if (!"views".equals(type)) {
error("Only allow views for delete all");
return true;
}
try {
open();
final Collection<BwView> theViews = getSvci().getViewsHandler().getAll();
if (Util.isEmpty(theViews)) {
info("No views for current user");
return false;
}
final List<BwView> views = new ArrayList<>(theViews);
for (final BwView view : views) {
if (getSvci().getViewsHandler().remove(view)) {
info("Removed view " + view.getName());
} else {
warn("Unable to remove view " + view.getName());
}
}
} finally {
close();
}
return true;
}
use of org.bedework.calfacade.svc.BwView in project bw-calendar-engine by Bedework.
the class OwnerRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
error("OwnerRule called");
BwPrincipal p = doPrincipal();
if (top() instanceof OwnerUidKey) {
OwnerUidKey key = (OwnerUidKey) top();
key.setOwnerHref(p.getPrincipalRef());
globals.inOwnerKey = false;
return;
}
if (top() instanceof BwAdminGroup) {
BwAdminGroup ag = (BwAdminGroup) top();
if (name.equals("owner")) {
ag.setOwnerHref(p.getPrincipalRef());
} else if (name.equals("owner-key")) {
// PRE3.5
ag.setOwnerHref(p.getPrincipalRef());
} else {
ag.setGroupOwnerHref(p.getPrincipalRef());
}
globals.inOwnerKey = false;
return;
}
BwOwnedDbentity o = null;
if (top() == null) {
error("Null stack top when setting owner. Match: " + getDigester().getMatch());
return;
}
if (top() instanceof EventInfo) {
o = ((EventInfo) top()).getEvent();
} else if (!(top() instanceof BwOwnedDbentity)) {
if (top() instanceof BwOrganizer) {
// No owner now
} else if (top() instanceof BwView) {
// No owner now
} else if (top() instanceof SkipThis) {
} else {
// We expect organizer in old data
warn("top() is not BwOwnedDbentity:" + top().getClass().getCanonicalName());
warn(" match: " + getDigester().getMatch());
}
globals.inOwnerKey = false;
return;
} else {
o = (BwOwnedDbentity) top();
}
o.setOwnerHref(p.getPrincipalRef());
globals.inOwnerKey = false;
}
use of org.bedework.calfacade.svc.BwView in project bw-calendar-engine by Bedework.
the class RestoreImpl method restoreUserPrefs.
@Override
public void restoreUserPrefs(final BwPreferences o) throws Throwable {
try {
startTransaction();
/* If the indexer or some other activity is running this can result in
* a preferences object being created. See if one exists.
*/
BwPreferences p = getSvc().getPreferences(o.getOwnerHref());
if (p != null) {
warn("Found instance of preferences for " + o.getOwnerHref());
o.setId(p.getId());
// noinspection UnusedAssignment
p = (BwPreferences) getSvc().merge(o);
} else {
p = o;
/* Ensure views are unsaved objects */
final Collection<BwView> v = p.getViews();
if (v != null) {
for (final BwView view : v) {
view.markUnsaved();
}
}
p.markUnsaved();
}
getCal().saveOrUpdate(o);
} finally {
endTransaction();
}
}
Aggregations