public ActionForward favorite(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
AbstractResourcesForm f = (AbstractResourcesForm) form;
ActionMessages msgs = new ActionMessages();
User user = LogonControllerFactory.getInstance().getUser(request);
SystemDatabase sdb = SystemDatabaseFactory.getInstance();
if (getSessionInfo(request).getNavigationContext() != SessionInfo.USER_CONSOLE_CONTEXT) {
throw new Exception("Favorites may only be set in the user console.");
}
Resource resource = getResourceById(f.getSelectedResource());
if(ResourceUtil.filterResourceIdsForGlobalFavorites(PolicyDatabaseFactory.getInstance().getGrantedResourcesOfType(getSessionInfo(request).getUser(),
resource.getResourceType()), resource.getResourceType()).contains(new Integer(resource.getResourceId()))) {
throw new Exception("Cannot set a user favorite for items that have a policy favorite.");
}
if (sdb.getFavorite(getResourceType().getResourceTypeId(), user, f.getSelectedResource()) != null) {
msgs.add(Globals.ERROR_KEY, new BundleActionMessage("navigation", "addToFavorites.error.alreadyFavorite", resource
.getResourceName()));
saveErrors(request, msgs);
return mapping.findForward("refresh");
}
sdb.addFavorite(getResourceType().getResourceTypeId(), f.getSelectedResource(), user.getPrincipalName());
msgs.add(Globals.MESSAGES_KEY, new BundleActionMessage("navigation", "addToFavorites.message.favoriteAdded", resource
.getResourceName()));
saveMessages(request, msgs);
return mapping.findForward("refresh");
}