--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressTask.java 2016/01/24 21:48:55 2838 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressTask.java 2016/01/28 10:27:13 2856 @@ -1,8 +1,15 @@ package dk.daoas.adressevedligehold; +import org.apache.commons.lang3.exception.ExceptionUtils; + import dk.daoas.adressevedligehold.tasks.Task; import dk.daoas.adressevedligehold.util.TimingHelper; +/* + * TODO: trigger indlæsning + * + */ + public class AddressTask extends Task { AddressSource source; @@ -13,12 +20,18 @@ this.source = source; this.writeBack = writeBack; } + + @Override - protected void taskRun() { + protected void taskRun() throws Exception { try { TimingHelper timer = new TimingHelper(); + + System.out.println("Validating Source"); + source.validate(); + System.out.println("Reading data from DB"); AddressManager addrManager = new AddressManager(); @@ -55,17 +68,26 @@ - } catch (Exception e) { - e.printStackTrace(); - } - - - try { - System.out.println("Cleaning up resources"); - source.close(); - } catch (Exception e) { - System.out.println("Error during cleanup: " + e.getMessage() ); + } catch(Exception e) { + + String subject = "Error loading data for " + source.getDistributor(); + String body = "File: " + source.getFilename(); + body += "

"; + body += "Exception:
"; + body += ExceptionUtils.getStackTrace(e); + AddressReport.sendMail(subject, body); + + throw e; //rethrow exception + } finally { + + try { + System.out.println("Cleaning up resources"); + source.close(); + } catch (Exception e) { + System.out.println("Error during cleanup: " + e.getMessage() ); + } } + } @Override