19 package org.turro.contacts.service;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.apache.commons.mail.EmailException;
24 import org.turro.action.Contacts;
25 import org.turro.action.queue.NotificationCategory;
26 import org.turro.action.queue.Notifications;
27 import org.turro.assistant.Assistant;
28 import org.turro.assistant.AssistantSet;
29 import org.turro.contacts.ContactService;
30 import org.turro.contacts.db.ContactsPU;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.context.ElephantProperties;
34 import org.turro.elephant.context.IConstructor;
35 import org.turro.elephant.db.WhereClause;
36 import org.turro.entities.Entities;
37 import org.turro.log.SystemLogger;
38 import org.turro.mail.message.MailMessageTemplate;
39 import org.turro.mail.pool.MailMessagePool;
40 import org.turro.mail.provider.MailProviders;
41 import org.turro.mail.queue.AssistantQueueUtils;
42 import org.turro.mail.queue.QueueManager;
43 import org.turro.marker.ElephantMarker;
44 import org.turro.plugin.contacts.IContact;
52 private final static String
53 PROP_CTX =
"service-context",
54 KEY_CATEGORY =
"service.mail.category",
55 KEY_POOL =
"service.mail.pool";
59 private final String category, mailPool;
60 private final boolean useQueue;
64 this.assistants = assistants;
65 this.useQueue = useQueue;
78 private void sendMail(
IContact contact) {
83 createMail(
new Assistant(contact, entity), nc, qm, pool);
86 createMail(assistant, nc, qm, pool);
93 SystemLogger.info().entity(entity).comment(
"sent").log();
96 private void createMail(Assistant assistant, NotificationCategory nc, QueueManager qm, MailMessagePool pool) {
98 if(Contacts.isValidEmail(assistant.email)) {
99 MailMessageTemplate mmt = MailMessageTemplate.of(MailProviders.instance().getProvider(mailPool));
101 mmt.addTo(assistant.email, assistant.name);
102 ElephantMarker em =
new ElephantMarker(Application.getApplication().getConstructor(),
true);
103 em.put(
"service", entity);
104 em.put(
"contact", assistant.contact);
105 em.put(
"email", assistant.email);
106 em.put(
"notifier",
this);
107 mmt.setMessage(em,
"service", assistant.contact);
109 qm.addToQueue(nc, assistant.contact, mmt,
null, mailPool);
115 }
catch (EmailException ex) {
116 Logger.getLogger(
ServiceSender.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
121 return createRef(constructor, service.getTimesSent() >=1 ?
127 return "{liveref:" + redir +
"}";
141 wc.
addClause(
"set timesSent = timesSent + 1");
static NotificationCategory getCategory(String id)
void addContacts(Collection< IContact > contacts)
void addContact(IContact contact, Object relationEntity)
IConstructor getConstructor()
static Application getApplication()
static String getContextProperty(String context, String property)
void addClause(String clause)
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
int executeUpdate(String query)
static MailProviders instance()
MailMessagePool getPool(IConstructor constructor, String name)
static void addFromCategory(String idCategory, AssistantSet assistants)