1 package com.leonarduk.clearcheckbook.file;
2
3 import java.text.ParseException;
4 import java.util.Date;
5 import java.util.Map;
6
7 import org.apache.log4j.Logger;
8
9 import com.leonarduk.clearcheckbook.ClearcheckbookException;
10 import com.leonarduk.utils.DateUtils;
11
12 public class NationwideFilePreprocessor extends TransactionFilePreprocessor {
13
14 private static final Logger _logger = Logger
15 .getLogger(NationwideFilePreprocessor.class);
16
17 /***
18 * "Account Name:","Smart Junior ISA ****07843" <BR>
19 * "Account Balance:","£3720.00" <BR>
20 * "Available Balance: ","£3720.00" <BR>
21 * <BR>
22 * "Date","Transaction type","Description","Paid out","Paid in","Balance" <BR>
23 * "21 Nov 2013","Transfer from","0275/636 848 557","","£120.00","£120.00" <BR>
24 * "25 Nov 2013","Transfer from","07-10-40 54817554 Credit 24 November 2013"
25 * ,"","£3300.00","£3420.00" <BR>
26 * "25 Nov 2013","Transfer from","0275/636 848 557 Credit 24 November 2013",
27 * "","£300.00","£3720.00"
28 */
29 public NationwideFilePreprocessor() {
30 super(4);
31 }
32
33 public NationwideFilePreprocessor(Long id) {
34 super(4,id);
35 }
36
37 @Override
38 protected String getCheckNum(Map<String, String> fieldsMap) {
39 return "";
40 }
41
42 @Override
43 protected String getDate(Map<String, String> fieldsMap)
44 throws ClearcheckbookException {
45 String dateString = fieldsMap.get("date");
46 _logger.debug("getDate:" + dateString + ":" + fieldsMap);
47 Date date;
48 try {
49 date = DateUtils.getDate(dateString, "dd MMM yyyy");
50 } catch (ParseException e) {
51 throw new ClearcheckbookException("Failed to parse date: "
52 + dateString, e);
53 }
54 return DateUtils.getFormattedDate("yyyy-MM-dd", date);
55 }
56
57 @Override
58 protected String getMemo(Map<String, String> fieldsMap) {
59 return "Balance: " + getDouble(fieldsMap.get("balance"));
60 }
61
62 @Override
63 protected String getPayee(Map<String, String> fieldsMap) {
64 return fieldsMap.get("description");
65 }
66
67 @Override
68 protected String getDesription(Map<String, String> fieldsMap) {
69 return fieldsMap.get("transaction type") + " "
70 + fieldsMap.get("description");
71 }
72
73 @Override
74 protected String getAmount(Map<String, String> fieldsMap) {
75 String credit = fieldsMap.get("paid in");
76 String debit = fieldsMap.get("paid out");
77 double amount = 0;
78 if (credit.equals("")) {
79 amount = -1 * getDouble(debit);
80 } else {
81 amount = getDouble(credit);
82 }
83 return String.valueOf(amount);
84 }
85 }