BrightSide Workbench Full Report + Source Code
RelationAcceptedNotification.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.contacts.relation;
20 
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.apache.commons.mail.EmailException;
24 import org.turro.action.MailSenders;
25 import org.turro.action.queue.NotificationCategory;
26 import org.turro.assistant.Assistant;
27 import org.turro.assistant.AssistantSet;
28 import org.turro.auth.Authentication;
29 import org.turro.contacts.BusinessRelation;
30 import org.turro.elephant.context.Application;
31 import org.turro.elephant.context.ElephantContext;
32 import org.turro.elephant.context.IConstructor;
33 import org.turro.i18n.I_;
34 import org.turro.mail.message.MailMessageTemplate;
35 import org.turro.mail.provider.MailProviders;
36 import org.turro.mail.queue.GenericElephantNotification;
37 import org.turro.mail.queue.QueueManager;
38 import org.turro.marker.ElephantMarker;
39 import org.turro.plugin.contacts.IContact;
40 
46 
47  protected final BusinessRelation relation;
48  protected final IConstructor constructor;
49  protected final IContact loggedContact;
50 
52  this.relation = relation;
55  }
56 
57  public void send() {
58  addToQueue("relation-accepted", I_.get("Relation accepted"));
59  }
60 
61  private void addToQueue(String template, String reason) {
62  QueueManager qm = new QueueManager();
64  for(Assistant assistant : getAssistants()) {
65  try {
66  if(qm.contactMayWant(assistant.contact, nc.getIdCategory())) {
68  mmt.setProcessLiveLinks(false);
69  mmt.setRoot("/profile");
70  mmt.setSubject(getSubject(reason));
71  mmt.addTo(assistant.email, assistant.name);
73  em.put("notifier", this);
74  em.put("relation", relation);
75  mmt.setMessage(em, template, assistant.contact);
76  qm.addToQueue(nc, assistant.contact, mmt, reason, null);
77  }
78  } catch (EmailException ex) {
79  Logger.getLogger(RelationAcceptedNotification.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
80  }
81  }
82  }
83 
85  AssistantSet as = new AssistantSet();
87  return as;
88  }
89 
90  protected String getSubject(String reason) {
91  return String.format("[%s] %s",
92  reason,
94  }
95 
96 }
void addContact(IContact contact, Object relationEntity)
static String get(String msg)
Definition: I_.java:41
MailProvider getProvider(String name)
MailItem addToQueue(NotificationCategory category, IContact contact, MailMessage mmt, String reason, String poolName)
boolean contactMayWant(IContact contact, String idCategory)
Object put(Object key, Object value)