use of name.abuchen.portfolio.datatransfer.csv.CSVImporter.FieldFormat in project portfolio by buchen.
the class CSVExtractor method getEnum.
@SuppressWarnings("unchecked")
protected final <E extends Enum<E>> E getEnum(String name, Class<E> type, String[] rawValues, Map<String, Column> field2column) throws ParseException {
String value = getText(name, rawValues, field2column);
if (value == null)
return null;
FieldFormat ff = field2column.get(name).getFormat();
if (ff != null && ff.getFormat() != null)
return (E) ff.getFormat().parseObject(value);
else
return Enum.valueOf(type, value);
}
use of name.abuchen.portfolio.datatransfer.csv.CSVImporter.FieldFormat in project portfolio by buchen.
the class CSVAccountTransactionExtractorTest method testDetectionOfFeeRefunds.
@Test
public void testDetectionOfFeeRefunds() {
Client client = new Client();
CSVExtractor extractor = new CSVAccountTransactionExtractor(client);
// setup custom mapping from string -> type
Map<String, Column> field2column = buildField2Column(extractor);
Column typeColumn = field2column.get(Messages.CSVColumn_Type);
@SuppressWarnings("unchecked") EnumField<AccountTransaction.Type> field = (EnumField<AccountTransaction.Type>) typeColumn.getField();
EnumMapFormat<AccountTransaction.Type> format = field.createFormat();
format.map().put(AccountTransaction.Type.FEES_REFUND, "Gebührenerstattung");
format.map().put(AccountTransaction.Type.FEES, "Gebühren");
typeColumn.setFormat(new FieldFormat(Messages.CSVColumn_Type, format));
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(0, //
Arrays.<String[]>asList(new String[] { "2017-04-21", "", "", "", "10", "", "Gebührenerstattung", "", "", "", "" }, new String[] { "2017-04-21", "", "", "", "20", "", "Gebühren", "", "", "", "" }), field2column, errors);
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);
AccountTransaction t1 = (AccountTransaction) //
results.stream().filter(//
i -> i instanceof TransactionItem).filter(i -> ((AccountTransaction) ((TransactionItem) i).getSubject()).getType() == AccountTransaction.Type.FEES_REFUND).findAny().get().getSubject();
assertThat(t1.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10))));
AccountTransaction t2 = (AccountTransaction) //
results.stream().filter(//
i -> i instanceof TransactionItem).filter(i -> ((AccountTransaction) ((TransactionItem) i).getSubject()).getType() == AccountTransaction.Type.FEES).findAny().get().getSubject();
assertThat(t2.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(20))));
}
Aggregations