1 |
package dk.daoas.adressevedligehold; |
package dk.daoas.adressevedligehold; |
2 |
|
|
3 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
4 |
|
|
5 |
import dk.daoas.adressevedligehold.tasks.Task; |
import dk.daoas.adressevedligehold.tasks.Task; |
6 |
import dk.daoas.adressevedligehold.util.TimingHelper; |
import dk.daoas.adressevedligehold.util.TimingHelper; |
7 |
|
|
8 |
|
/* |
9 |
|
* TODO: trigger indlæsning |
10 |
|
* |
11 |
|
*/ |
12 |
|
|
13 |
public class AddressTask extends Task { |
public class AddressTask extends Task { |
14 |
|
|
15 |
AddressSource source; |
AddressSource source; |
20 |
this.source = source; |
this.source = source; |
21 |
this.writeBack = writeBack; |
this.writeBack = writeBack; |
22 |
} |
} |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
@Override |
@Override |
27 |
protected void taskRun() { |
protected void taskRun() throws Exception { |
28 |
|
|
29 |
try { |
try { |
30 |
TimingHelper timer = new TimingHelper(); |
TimingHelper timer = new TimingHelper(); |
31 |
|
|
32 |
|
System.out.println("Validating Source"); |
33 |
|
source.validate(); |
34 |
|
|
35 |
System.out.println("Reading data from DB"); |
System.out.println("Reading data from DB"); |
36 |
AddressManager addrManager = new AddressManager(); |
AddressManager addrManager = new AddressManager(); |
37 |
|
|
67 |
report.sendRapport(); |
report.sendRapport(); |
68 |
|
|
69 |
|
|
70 |
|
if (writeBack) { |
71 |
|
ReloadHelper.triggerReload( "Indlaesning/" + source.getDistributor() ); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
} catch (Exception e) { |
} catch(Exception e) { |
77 |
e.printStackTrace(); |
|
78 |
} |
String subject = "Error loading data for " + source.getDistributor(); |
79 |
|
String body = "File: " + source.getFilename(); |
80 |
|
body += "<br><br>"; |
81 |
try { |
body += "Exception:<br>"; |
82 |
System.out.println("Cleaning up resources"); |
body += ExceptionUtils.getStackTrace(e); |
83 |
source.close(); |
AddressReport.sendMail(subject, body); |
84 |
} catch (Exception e) { |
|
85 |
System.out.println("Error during cleanup: " + e.getMessage() ); |
throw e; //rethrow exception |
86 |
|
} finally { |
87 |
|
|
88 |
|
try { |
89 |
|
System.out.println("Cleaning up resources"); |
90 |
|
source.close(); |
91 |
|
} catch (Exception e) { |
92 |
|
System.out.println("Error during cleanup: " + e.getMessage() ); |
93 |
|
} |
94 |
} |
} |
95 |
|
|
96 |
} |
} |
97 |
|
|
98 |
@Override |
@Override |
101 |
} |
} |
102 |
|
|
103 |
@Override |
@Override |
104 |
public short getPercentCompleted() { |
public double getPercentCompleted() { |
105 |
return 0; |
return -1; |
106 |
} |
} |
107 |
|
|
108 |
@Override |
@Override |