use of name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column in project portfolio by buchen.
the class CSVExtractor method getText.
protected String getText(String name, String[] rawValues, Map<String, Column> field2column) {
Column column = field2column.get(name);
if (column == null)
return null;
int columnIndex = column.getColumnIndex();
if (columnIndex < 0 || columnIndex >= rawValues.length)
return null;
String value = rawValues[columnIndex];
return value != null && value.trim().length() == 0 ? null : value;
}
use of name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column in project portfolio by buchen.
the class CSVImportDefinitionPage method doUpdateErrorMessages.
private void doUpdateErrorMessages() {
Set<Field> fieldsToMap = new HashSet<>(importer.getExtractor().getFields());
for (Column column : importer.getColumns()) fieldsToMap.remove(column.getField());
if (fieldsToMap.isEmpty()) {
setMessage(null);
setPageComplete(true);
} else {
String required = fieldsToMap.stream().filter(f -> !f.isOptional()).map(Field::getName).collect(// $NON-NLS-1$
Collectors.joining(", "));
String optional = fieldsToMap.stream().filter(Field::isOptional).map(Field::getName).collect(// $NON-NLS-1$
Collectors.joining(", "));
boolean onlyOptional = required.length() == 0;
setPageComplete(onlyOptional);
StringBuilder message = new StringBuilder();
if (required.length() > 0)
// $NON-NLS-1$
message.append(MessageFormat.format(Messages.CSVImportErrorMissingFields, required)).append("\n");
if (optional.length() > 0)
message.append(MessageFormat.format(Messages.CSVImportInformationOptionalFields, optional));
setMessage(message.toString(), onlyOptional ? IMessageProvider.INFORMATION : IMessageProvider.ERROR);
}
}
use of name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column in project portfolio by buchen.
the class CSVExtractorTestUtil method buildField2Column.
/**
* Build column config for unit testing, e.g. expect all values exactly in
* the order they have been configured and with the first format option
*/
/* package */
static Map<String, Column> buildField2Column(CSVExtractor extractor) {
Map<String, Column> field2column = new HashMap<>();
int index = 0;
for (Field f : extractor.getFields()) {
Column column = new Column(index++, f.getName());
column.setField(f);
if (f instanceof DateField)
column.setFormat(DateField.FORMATS[0]);
else if (f instanceof AmountField)
column.setFormat(AmountField.FORMATS[0]);
field2column.put(f.getName(), column);
}
return field2column;
}
use of name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column 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))));
}
use of name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column in project portfolio by buchen.
the class CSVExtractor method getISIN.
protected String getISIN(String name, String[] rawValues, Map<String, Column> field2column) {
Column column = field2column.get(name);
if (column == null)
return null;
int columnIndex = column.getColumnIndex();
if (columnIndex < 0 || columnIndex >= rawValues.length)
return null;
String value = rawValues[columnIndex];
if (value == null)
return null;
value = value.trim().toUpperCase();
// $NON-NLS-1$ //$NON-NLS-2$
Pattern pattern = Pattern.compile("\\b(" + Isin.PATTERN + ")\\b");
Matcher matcher = pattern.matcher(value);
if (matcher.find())
value = matcher.group(1);
return value.length() == 0 ? null : value;
}
Aggregations