View Javadoc

1   package com.leonarduk.clearcheckbook.file;
2   
3   import java.io.IOException;
4   import java.text.ParseException;
5   import java.util.Date;
6   import java.util.LinkedList;
7   import java.util.List;
8   import java.util.Map;
9   
10  import org.apache.log4j.Logger;
11  
12  import com.leonarduk.clearcheckbook.ClearcheckbookException;
13  import com.leonarduk.clearcheckbook.dto.TransactionDataType;
14  import com.leonarduk.utils.DateUtils;
15  
16  public class AMEXFilePreprocessor extends TransactionFilePreprocessor {
17  
18  	private static final Logger _logger = Logger
19  			.getLogger(AMEXFilePreprocessor.class);
20  
21  	/***
22  	 * 
23  	 */
24  	public AMEXFilePreprocessor() {
25  		super(0);
26  	}
27  
28  	public AMEXFilePreprocessor(long accountId) {
29  		super(0, accountId);
30  	}
31  
32  	@Override
33  	protected String getDate(Map<String, String> fieldsMap)
34  			throws ClearcheckbookException {
35  		String dateString = fieldsMap.get("date");
36  		_logger.debug("getDate:" + dateString + ":" + fieldsMap);
37  		Date date;
38  		try {
39  			date = DateUtils.getDate(dateString, "dd/MM/yyyy");
40  		} catch (ParseException e) {
41  			throw new ClearcheckbookException("Failed to parse date: "
42  					+ dateString, e);
43  		}
44  		return DateUtils.getFormattedDate("yyyy-MM-dd", date);
45  	}
46  
47  	@Override
48  	protected String getAmount(Map<String, String> fieldsMap) {
49  		return String.valueOf(-1
50  				* Double.valueOf(fieldsMap
51  						.get(TransactionDataType.Fields.AMOUNT.name()
52  								.toLowerCase())));
53  	}
54  
55  	@Override
56  	public List<String> processHeaderRow(String separator, String line)
57  			throws IOException {
58  		// Read header
59  		List<String> headerFields = new LinkedList<>();
60  		// 21/01/2014,"Reference: AT140220038000010303608"," 56.76",
61  		// "TESCO STORES 2934 NEW MALDEN"," Process Date 22/01/2014",
62  
63  		headerFields.add(TransactionDataType.Fields.DATE.name());
64  		headerFields.add(TransactionDataType.Fields.CHECK_NUM.name());
65  		headerFields.add(TransactionDataType.Fields.AMOUNT.name());
66  		headerFields.add(TransactionDataType.Fields.DESCRIPTION.name());
67  		headerFields.add(TransactionDataType.Fields.MEMO.name());
68  		headerFields.add("IGNORE");
69  
70  		return headerFields;
71  	}
72  	
73  	@Override
74  	protected String getPayee(Map<String, String> fieldsMap) {
75  		return super.getDesription(fieldsMap);
76  	}
77  }