01: /*
02: *
03: * (c) Copyright 2004 - 2007 osbl development team.
04: *
05: * This file is part of the osbl (http://osbl.wilken.de).
06: *
07: * the osbl is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.osbl.demo.urlaub.process;
15:
16: import org.concern.LoaderException;
17: import org.osbl.demo.urlaub.model.UrlaubsAntrag;
18: import org.osbl.demo.urlaub.model.Genehmigung;
19: import org.concern.controller.AbstractSynchronousActivity;
20: import org.concern.controller.ActivityExecutionException;
21:
22: import javax.mail.*;
23: import javax.mail.internet.InternetAddress;
24: import javax.mail.internet.MimeMessage;
25: import javax.naming.InitialContext;
26: import javax.naming.NamingException;
27: import java.sql.Timestamp;
28: import java.util.*;
29:
30: public class Benachrichtigen extends
31: AbstractSynchronousActivity<UrlaubsAntrag> {
32: private Session session;
33:
34: public void execute(UrlaubsAntrag subject)
35: throws ActivityExecutionException {
36: try {
37: /*PROTECTED REGION ID(org.osbl.demo.urlaub.process.Benachrichtigen.execute) ENABLED START*/
38: MimeMessage m = new MimeMessage(getSession());
39: m.setFrom(new InternetAddress("spam@wilken.de"));
40: m.setRecipients(Message.RecipientType.TO,
41: new InternetAddress[] { new InternetAddress(
42: "spam@wilken.de") });
43: m.setSubject(getSubject(subject));
44: String entscheidung = subject.getGenehmigung() == Genehmigung.ERTEILT ? "genehmigt"
45: : "abgelehnt";
46: m.setContent("Ihr Urlaubsantrag wurde " + entscheidung,
47: "text/plain; charset=UTF-8");
48: Transport.send(m);
49: subject.setBenachrichtigt(new Timestamp(System
50: .currentTimeMillis()));
51: } catch (MessagingException e) {
52: session = null;
53: throw new ActivityExecutionException(e);
54: } catch (LoaderException e) {
55: throw new ActivityExecutionException(e);
56: }
57: /*PROTECTED REGION END*/
58: }
59:
60: // TODO: user's locale
61: private String getSubject(UrlaubsAntrag subject)
62: throws LoaderException {
63: Map map = controller.getLoader().formatSubjectLines(subject);
64: return (String) map.get("de_DE");
65: }
66:
67: public void escalate(UrlaubsAntrag subject)
68: throws ActivityExecutionException {
69: UrlaubsAntrag urlaubsAntrag = subject;
70: urlaubsAntrag.setBenachrichtigt(new Timestamp(System
71: .currentTimeMillis()));
72: }
73:
74: public Session getSession() throws ActivityExecutionException {
75: if (session == null) {
76: try {
77: String mailSession = (String) getEnvironment().get(
78: "sendmail.session");
79: System.out.println("mailSession = " + mailSession);
80: session = (Session) new InitialContext()
81: .lookup(mailSession);
82: } catch (NamingException e) {
83: throw new ActivityExecutionException(e);
84: }
85: }
86: return session;
87: }
88: }
|