Search in sources :

Example 1 with QuestionCreated

use of org.mamute.event.QuestionCreated in project mamute by caelum.

the class QuestionController method newQuestion.

@Post
@CustomBrutauthRules({ LoggedRule.class, InputRule.class })
public void newQuestion(String title, MarkedText description, String tagNames, boolean watching, List<Long> attachmentsIds) {
    List<Attachment> attachments = this.attachments.load(attachmentsIds);
    attachmentsValidator.validate(attachments);
    List<String> splitedTags = splitter.splitTags(tagNames);
    List<Tag> foundTags = tagsManager.findOrCreate(splitedTags);
    validate(foundTags, splitedTags);
    QuestionInformation information = new QuestionInformation(title, description, currentUser, foundTags, "new question");
    brutalValidator.validate(information);
    User author = currentUser.getCurrent();
    Question question = new Question(information, author);
    result.include("question", question);
    validator.onErrorUse(Results.page()).of(this.getClass()).questionForm();
    questions.save(question);
    index.indexQuestion(question);
    question.add(attachments);
    ReputationEvent reputationEvent = new ReputationEvent(EventType.CREATED_QUESTION, question, author);
    author.increaseKarma(reputationEvent.getKarmaReward());
    reputationEvents.save(reputationEvent);
    if (watching) {
        watchers.add(question, new Watcher(author));
    }
    questionCreated.fire(new QuestionCreated(question));
    result.include("mamuteMessages", asList(messageFactory.build("alert", "question.quality_reminder")));
    result.redirectTo(this).showQuestion(question, question.getSluggedTitle());
}
Also used : Watcher(org.mamute.model.watch.Watcher) QuestionCreated(org.mamute.event.QuestionCreated) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Aggregations

CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Post (br.com.caelum.vraptor.Post)1 QuestionCreated (org.mamute.event.QuestionCreated)1 Watcher (org.mamute.model.watch.Watcher)1