* @return forward
* @throws Exception
*/
public ActionForward removeFavorite(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 remove a user favorite from items that have a policy favorite.");
}
if (sdb.getFavorite(getResourceType().getResourceTypeId(), user, f.getSelectedResource()) == null) {
msgs.add(Globals.ERROR_KEY, new BundleActionMessage("navigation", "removeFromFavorites.error.notFavorite", resource
.getResourceName()));
saveErrors(request, msgs);
return mapping.findForward("refresh");
}
sdb.removeFavorite(getResourceType().getResourceTypeId(), f.getSelectedResource(), user.getPrincipalName());
msgs.add(Globals.MESSAGES_KEY, new BundleActionMessage("navigation", "removeFromFavorites.message.favoriteAdded", resource
.getResourceName()));
saveMessages(request, msgs);
return mapping.findForward("refresh");
}