/[projects]/dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressTask.java
ViewVC logotype

Contents of /dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressTask.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2856 - (show annotations) (download)
Thu Jan 28 10:27:13 2016 UTC (8 years, 3 months ago) by torben
File size: 2370 byte(s)
Send mail on exceptions

1 package dk.daoas.adressevedligehold;
2
3 import org.apache.commons.lang3.exception.ExceptionUtils;
4
5 import dk.daoas.adressevedligehold.tasks.Task;
6 import dk.daoas.adressevedligehold.util.TimingHelper;
7
8 /*
9 * TODO: trigger indlæsning
10 *
11 */
12
13 public class AddressTask extends Task {
14
15 AddressSource source;
16 boolean writeBack;
17
18 public AddressTask(AddressSource source, boolean writeBack) {
19
20 this.source = source;
21 this.writeBack = writeBack;
22 }
23
24
25
26 @Override
27 protected void taskRun() throws Exception {
28
29 try {
30 TimingHelper timer = new TimingHelper();
31
32 System.out.println("Validating Source");
33 source.validate();
34
35 System.out.println("Reading data from DB");
36 AddressManager addrManager = new AddressManager();
37
38 System.out.println("Data is ready");
39
40 EntryUgedage ugedage = new EntryUgedage(); //saml op på hvilke ugedage der er blevet behandlet
41
42
43 int entryCount = 0;
44
45 AddressSourceEntry entry;
46 while ( (entry = source.getNextEntry()) != null) {
47 if (super.abort) {
48 break;
49 }
50
51 addrManager.visit(entry);
52 ugedage.merge(entry.ugedage);
53 entryCount++;
54 }
55
56 addrManager.closeUnvisitedAddresses( source.getDistributor(), ugedage );
57
58
59
60 if (writeBack) {
61 addrManager.writeBackChanges();
62 } else {
63 addrManager.dumpChanged();
64 }
65
66 AddressReport report = new AddressReport(addrManager, entryCount, ugedage, source, timer, writeBack);
67 report.sendRapport();
68
69
70
71 } catch(Exception e) {
72
73 String subject = "Error loading data for " + source.getDistributor();
74 String body = "File: " + source.getFilename();
75 body += "<br><br>";
76 body += "Exception:<br>";
77 body += ExceptionUtils.getStackTrace(e);
78 AddressReport.sendMail(subject, body);
79
80 throw e; //rethrow exception
81 } finally {
82
83 try {
84 System.out.println("Cleaning up resources");
85 source.close();
86 } catch (Exception e) {
87 System.out.println("Error during cleanup: " + e.getMessage() );
88 }
89 }
90
91 }
92
93 @Override
94 public String getDescription() {
95 return "AddressTask " + source.getDistributor();
96 }
97
98 @Override
99 public short getPercentCompleted() {
100 return 0;
101 }
102
103 @Override
104 public String getDetail() {
105 return source.getFilename();
106 }
107
108 }

  ViewVC Help
Powered by ViewVC 1.1.20