/[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 2896 - (show annotations) (download)
Mon Feb 1 08:32:44 2016 UTC (8 years, 3 months ago) by torben
File size: 2453 byte(s)
Trigger reload when loading file is done
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 ReloadHelper.triggerReload( "Indlaesning/" + source.getDistributor() );
70
71
72
73 } catch(Exception e) {
74
75 String subject = "Error loading data for " + source.getDistributor();
76 String body = "File: " + source.getFilename();
77 body += "<br><br>";
78 body += "Exception:<br>";
79 body += ExceptionUtils.getStackTrace(e);
80 AddressReport.sendMail(subject, body);
81
82 throw e; //rethrow exception
83 } finally {
84
85 try {
86 System.out.println("Cleaning up resources");
87 source.close();
88 } catch (Exception e) {
89 System.out.println("Error during cleanup: " + e.getMessage() );
90 }
91 }
92
93 }
94
95 @Override
96 public String getDescription() {
97 return "AddressTask " + source.getDistributor();
98 }
99
100 @Override
101 public double getPercentCompleted() {
102 return -1;
103 }
104
105 @Override
106 public String getDetail() {
107 return source.getFilename();
108 }
109
110 }

  ViewVC Help
Powered by ViewVC 1.1.20