BrightSide Workbench Full Report + Source Code
Forums.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.forum;
20 
21 import java.util.List;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.apache.commons.mail.EmailException;
25 import org.turro.assistant.AssistantConstants;
26 import org.turro.assistant.ParticipationWalker;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.db.ElephantPU;
29 import org.turro.elephant.db.WhereClause;
30 import org.turro.elephant.entities.db.Post;
31 import org.turro.elephant.entities.db.Topic;
32 import org.turro.entities.Entities;
33 import org.turro.entities.ITreeEntity;
34 import org.turro.i18n.I_;
35 import org.turro.jpa.Dao;
36 import org.turro.mail.queue.GenericElephantNotification;
37 import org.turro.mail.sender.MailQueue;
38 import org.turro.participation.ParticipationReason;
39 import org.turro.plugin.contacts.IContact;
40 
45 public class Forums {
46 
47  public static List<Topic> getTopics(String entityPath) {
48  Dao dao = new ElephantPU();
49  WhereClause wc = new WhereClause();
50  wc.addClause("select t from Topic as t");
51  wc.addClause("where t.entityPath like :entityPath");
52  wc.addNamedValue("entityPath", entityPath);
53  return dao.getResultList(wc);
54  }
55 
56  public static void markAsUnseenExceptFor(ITreeEntity entity, IContact contact) {
58  walker.walkUpTree(entity, e -> walker.deleteExceptFor(e, contact, ParticipationReason.REASON_SEEN));
59  }
60 
61  public static void markAsSeenFor(ITreeEntity entity, IContact contact) {
63  walker.walkDownTree(entity, e -> walker.createFor(e, contact, ParticipationReason.REASON_SEEN));
64  }
65 
66  public static void notify(Topic topic) {
67  try {
68  new MailQueue()
69  .setRoot("/forum")
72  .setReason(I_.get("Forum"))
73  .put("topic", topic)
74  .put("entityUrl", Entities.getController(topic).getEntityUrl())
75  .sendTemplate("topic", I_.get("New content"));
76  } catch (EmailException ex) {
77  Logger.getLogger(Forums.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
78  }
79  }
80 
81  public static void notify(Post post) {
82  try {
83  Topic topic = post.getTopic();
84  new MailQueue()
85  .setRoot("/forum")
88  .setReason(I_.get("Forum"))
89  .put("topic", topic)
90  .put("post", post)
91  .put("entityUrl", Entities.getController(topic).getEntityUrl())
92  .sendTemplate("topic", I_.get("New content"));
93  } catch (EmailException ex) {
94  Logger.getLogger(Forums.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
95  }
96  }
97 
98  private Forums() {}
99 
100 }
void walkUpTree(ITreeEntity entity, Consumer< ITreeEntity > execute)
void createFor(Object entity, IContact contact, ParticipationReason reason)
void deleteExceptFor(Object entity, IContact contact, ParticipationReason reason)
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static void markAsUnseenExceptFor(ITreeEntity entity, IContact contact)
Definition: Forums.java:56
static List< Topic > getTopics(String entityPath)
Definition: Forums.java:47
static void notify(Topic topic)
Definition: Forums.java:66
static void markAsSeenFor(ITreeEntity entity, IContact contact)
Definition: Forums.java:61
static void notify(Post post)
Definition: Forums.java:81
static String get(String msg)
Definition: I_.java:41
T addByEntity(Object entity, Object data)