Search in sources :

Example 1 with TopicWatch

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

the class TopicWatchController method updateNotificationType.

/**
 * @return the navigation state of the application
 */
public String updateNotificationType() {
    String navState = null;
    if (watchType == -1 || topicId == -1) {
        return navState;
    }
    try {
        TopicWatch topicWatch = forumsModule.findTopicWatchByUserAndTopic(getUser(userModule), topicId);
        topicWatch.setMode(watchType);
        forumsModule.update(topicWatch);
        navState = "success";
    } catch (Exception e) {
        handleException(e);
    }
    topicId = -1;
    return navState;
}
Also used : TopicWatch(it.vige.rubia.model.TopicWatch) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException)

Example 2 with TopicWatch

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

the class ForumsModuleImpl method createWatch.

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

Aggregations

TopicWatch (it.vige.rubia.model.TopicWatch)2 Poster (it.vige.rubia.model.Poster)1 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)1 NoResultException (javax.persistence.NoResultException)1 NonUniqueResultException (javax.persistence.NonUniqueResultException)1