1 |
package dk.daoas.daoadresseservice; |
package dk.daoas.daoadresseservice; |
2 |
|
|
3 |
import java.sql.SQLException; |
import java.sql.SQLException; |
4 |
|
import java.util.Properties; |
5 |
|
import java.util.logging.Logger; |
6 |
|
|
7 |
|
import javax.mail.Message; |
8 |
|
import javax.mail.Session; |
9 |
|
import javax.mail.Transport; |
10 |
|
import javax.mail.internet.InternetAddress; |
11 |
|
import javax.mail.internet.MimeMessage; |
12 |
import javax.servlet.ServletContext; |
import javax.servlet.ServletContext; |
13 |
|
|
14 |
|
import dk.daoas.daoadresseservice.admin.ServiceConfig; |
15 |
|
import dk.daoas.daoadresseservice.db.DatabaseLayerImplementation; |
16 |
|
|
17 |
public class DataLoader { |
public class DataLoader { |
18 |
|
|
19 |
boolean isRunning = false; |
boolean isRunning = false; |
20 |
|
|
21 |
|
ServiceConfig config; |
22 |
|
|
23 |
ServletContext ctxt; |
ServletContext ctxt; |
24 |
public DataLoader(ServletContext ctxt) { |
public DataLoader(ServletContext ctxt,ServiceConfig conf) { |
25 |
this.ctxt = ctxt; |
this.ctxt = ctxt; |
26 |
|
|
27 |
|
config = conf; |
28 |
} |
} |
29 |
|
|
30 |
public void doLoad() { |
public void doLoad() { |
54 |
|
|
55 |
|
|
56 |
public static class DataLoadWorker implements Runnable { |
public static class DataLoadWorker implements Runnable { |
57 |
|
|
58 |
|
static final Logger logger = Logger.getLogger(DataLoadWorker.class.getName()); |
59 |
|
|
60 |
DataLoader loader; |
DataLoader loader; |
61 |
public DataLoadWorker(DataLoader ld) { |
public DataLoadWorker(DataLoader ld) { |
62 |
this.loader = ld; |
this.loader = ld; |
68 |
|
|
69 |
|
|
70 |
try { |
try { |
71 |
AdressSearch search = new AdressSearch(); |
AddressSearch search = new AddressSearch(new DatabaseLayerImplementation(), loader.config); |
72 |
search.buildSearchStructures(); |
search.buildSearchStructures(); |
73 |
|
|
74 |
AdressSearch oldSearch = (AdressSearch) loader.ctxt.getAttribute("search"); |
AddressSearch oldSearch = (AddressSearch) loader.ctxt.getAttribute("search"); |
75 |
loader.ctxt.setAttribute("search", search); |
loader.ctxt.setAttribute("search", search); |
76 |
|
|
77 |
|
if (loader.config.notifyEmail != null && loader.config.notifyEmail.length() > 0) { |
78 |
|
sendStatusEmail(search, oldSearch); |
79 |
|
} |
80 |
|
|
81 |
if (oldSearch != null) { |
if (oldSearch != null) { |
82 |
oldSearch.clear(); |
oldSearch.clear(); |
83 |
} |
} |
90 |
|
|
91 |
} |
} |
92 |
|
|
93 |
|
protected void sendStatusEmail(AddressSearch newSearch, AddressSearch oldSearch) { |
94 |
|
Properties props = new Properties(); |
95 |
|
props.put("mail.smtp.host", "10.30.1.28"); |
96 |
|
|
97 |
|
try { |
98 |
|
// create some properties and get the default Session |
99 |
|
Session session = Session.getDefaultInstance(props, null); |
100 |
|
session.setDebug(false); |
101 |
|
|
102 |
|
|
103 |
|
// create a message |
104 |
|
|
105 |
|
MimeMessage msg = new MimeMessage(session); |
106 |
|
msg.setFrom( new InternetAddress("no-reply@daoas.dk") ); |
107 |
|
|
108 |
|
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(loader.config.notifyEmail) ); |
109 |
|
msg.setSubject("DaoAdresseService status "); |
110 |
|
msg.setText("--"); |
111 |
|
|
112 |
|
Transport.send(msg); |
113 |
|
} catch (Exception e) { |
114 |
|
logger.warning("Unable to send CircuitBreaker notification mail " + e ); |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
} |
} |
120 |
|
|