01: package com.technoetic.xplanner.actions;
02:
03: import java.util.Properties;
04: import javax.servlet.http.HttpServletRequest;
05:
06: import org.apache.log4j.Logger;
07: import org.apache.struts.Globals;
08: import org.apache.struts.util.MessageResources;
09:
10: import com.technoetic.xplanner.XPlannerProperties;
11: import com.technoetic.xplanner.domain.Integration;
12: import com.technoetic.xplanner.domain.Person;
13: import com.technoetic.xplanner.domain.repository.HibernateObjectRepository;
14: import com.technoetic.xplanner.domain.repository.MetaRepository;
15: import com.technoetic.xplanner.mail.EmailMessage;
16: import com.technoetic.xplanner.mail.EmailMessageFactory;
17:
18: public class IntegrationEmailNotifier implements IntegrationListener {
19: private Logger log = Logger.getLogger(getClass());
20:
21: Properties properties;
22: MetaRepository metaRepository;
23:
24: public void setProperties(Properties properties) {
25: this .properties = properties;
26: }
27:
28: public void setMetaRepository(MetaRepository metaRepository) {
29: this .metaRepository = metaRepository;
30: }
31:
32: public void onEvent(int eventType, Integration integration,
33: HttpServletRequest request) {
34: if (eventType == INTEGRATION_READY_EVENT) {
35: try {
36: MessageResources resources = (MessageResources) request
37: .getAttribute(Globals.MESSAGES_KEY);
38: EmailMessage email = new EmailMessageFactory(
39: metaRepository.getRepository(Person.class))
40: .createMessage();
41: email.setFrom(properties
42: .getProperty(XPlannerProperties.EMAIL_FROM));
43: email.setRecipient(integration.getPersonId());
44: email.setCcRecipients(properties
45: .getProperty("xplanner.integration.mail.cc"));
46: email
47: .setSubject(resources
48: .getMessage("integrations.notification.subject"));
49: String link = request.getScheme() + "://"
50: + request.getServerName() + ":"
51: + request.getServerPort()
52: + request.getContextPath()
53: + "/do/view/integrations?projectId="
54: + integration.getProjectId();
55: email.setBody(resources.getMessage(
56: "integrations.notification.text", link));
57: email.send();
58: } catch (Exception ex) {
59: log.error("couldn't send notification", ex);
60: }
61: }
62: }
63: }
|