Search in sources :

Example 1 with ForumWatch

use of it.vige.rubia.model.ForumWatch in project rubia-forums by flashboss.

the class ForumWatchController method updateNotificationType.

/**
 * @return the name of the operation
 */
public String updateNotificationType() {
    try {
        String wt = getRequestParameter(p_notified_watch_type);
        if (wt != null && wt.trim().length() > 0) {
            watchMode = parseInt(wt);
        } else {
            watchMode = -1;
        }
    } catch (NumberFormatException e) {
        handleException(e);
        watchMode = -1;
    }
    try {
        ForumWatch forumWatch = forumsModule.findForumWatchByUserAndForum(getUser(userModule), selectedForum);
        forumWatch.setMode(watchMode);
        forumsModule.update(forumWatch);
    } catch (Exception e) {
        handleException(e);
    }
    selectedForum = -1;
    return "";
}
Also used : ForumWatch(it.vige.rubia.model.ForumWatch) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException)

Example 2 with ForumWatch

use of it.vige.rubia.model.ForumWatch in project rubia-forums by flashboss.

the class ForumWatchController method deActivateWatch.

/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String deActivateWatch() {
    String navState = null;
    try {
        int watchId = -1;
        String w = getRequestParameter(p_watchId);
        if (w != null && w.trim().length() > 0) {
            watchId = parseInt(w);
        }
        if (watchId == -1) {
            String f = getRequestParameter(p_forumId);
            if (f != null && f.trim().length() > 0) {
                int forumId = parseInt(f);
                ForumWatch forumWatch = forumsModule.findForumWatchByUserAndForum(getUser(userModule), forumId);
                watchId = forumWatch != null ? forumWatch.getId().intValue() : -1;
            }
        }
        if (watchId != -1) {
            forumsModule.removeWatch(forumsModule.findForumWatchById(watchId));
        }
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : ForumWatch(it.vige.rubia.model.ForumWatch) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 3 with ForumWatch

use of it.vige.rubia.model.ForumWatch in project rubia-forums by flashboss.

the class ForumsModuleImpl method createWatch.

@Override
public void createWatch(Poster poster, Forum forum, int mode) throws ModuleException {
    try {
        if (poster == null) {
            throw new ModuleException("poster must not be null");
        }
        if (forum == null) {
            throw new ModuleException("forum must not be null");
        }
        Poster posterOld = findPosterByUserId(poster.getUserId());
        if (posterOld == null) {
            em.persist(poster);
        }
        em.merge(poster);
        ForumWatch forumWatch = new ForumWatch();
        forumWatch.setPoster(poster);
        forumWatch.setForum(forum);
        forumWatch.setMode(mode);
        em.persist(forumWatch);
        // it is required
        em.flush();
    // for clustered versions
    } catch (Exception e) {
        String errorMessage = "Cannot create forum watch";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : ForumWatch(it.vige.rubia.model.ForumWatch) Poster(it.vige.rubia.model.Poster) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Aggregations

ForumWatch (it.vige.rubia.model.ForumWatch)3 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)2 SecureActionForum (it.vige.rubia.auth.SecureActionForum)1 Poster (it.vige.rubia.model.Poster)1 Interceptors (javax.interceptor.Interceptors)1 NoResultException (javax.persistence.NoResultException)1 NonUniqueResultException (javax.persistence.NonUniqueResultException)1