use of name.abuchen.portfolio.model.PortfolioTransaction.Type in project portfolio by buchen.
the class CSVPortfolioTransactionExtractor method extract.
@Override
void extract(List<Item> items, String[] rawValues, Map<String, Column> field2column) throws ParseException {
// if forex gross amount is available then assume that is the currency
// of the security to be created
// check if we have a security
Security security = getSecurity(rawValues, field2column, s -> {
String currency = getText(Messages.CSVColumn_CurrencyGrossAmount, rawValues, field2column);
if (currency == null || currency.isEmpty())
currency = getText(Messages.CSVColumn_TransactionCurrency, rawValues, field2column);
if (currency != null) {
CurrencyUnit unit = CurrencyUnit.getInstance(currency.trim());
s.setCurrencyCode(unit == null ? getClient().getBaseCurrency() : unit.getCurrencyCode());
}
});
if (security == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingSecurity, // $NON-NLS-1$
new StringJoiner(", ").add(Messages.CSVColumn_ISIN).add(Messages.CSVColumn_TickerSymbol).add(Messages.CSVColumn_WKN).toString()), 0);
// check for the transaction amount
Money amount = getMoney(rawValues, field2column);
// determine type (if not explicitly given by import)
Type type = inferType(rawValues, field2column, amount);
// determine remaining fields
LocalDateTime date = getDate(Messages.CSVColumn_Date, rawValues, field2column);
if (date == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Date), 0);
Long shares = getShares(Messages.CSVColumn_Shares, rawValues, field2column);
Long fees = getAmount(Messages.CSVColumn_Fees, rawValues, field2column);
Long taxes = getAmount(Messages.CSVColumn_Taxes, rawValues, field2column);
String note = getText(Messages.CSVColumn_Note, rawValues, field2column);
Unit grossAmount = extractGrossAmount(rawValues, field2column, amount);
switch(type) {
case BUY:
case SELL:
items.add(createBuySell(rawValues, field2column, type, security, amount, fees, taxes, date, note, shares, grossAmount));
break;
case TRANSFER_IN:
case TRANSFER_OUT:
items.add(createTransfer(security, amount, fees, taxes, date, note, shares, grossAmount));
break;
case DELIVERY_INBOUND:
case DELIVERY_OUTBOUND:
items.add(createDelivery(rawValues, field2column, type, security, amount, fees, taxes, date, note, shares, grossAmount));
break;
default:
throw new IllegalArgumentException(type.toString());
}
}
use of name.abuchen.portfolio.model.PortfolioTransaction.Type in project portfolio by buchen.
the class InsertActionTest method testPortfolioTransactionAttributes.
@Test
public void testPortfolioTransactionAttributes() throws IntrospectionException {
// This test is only a "marker" that fails if the PortfolioTransaction
// is structurally changed. If it is changed, then the ImportAction
// needs to change too.
BeanInfo info = Introspector.getBeanInfo(PortfolioTransaction.class);
Set<String> properties = Arrays.stream(info.getPropertyDescriptors()).filter(p -> p.getWriteMethod() != null).map(p -> p.getName()).collect(Collectors.toSet());
assertThat(properties, hasItem("security"));
assertThat(properties, hasItem("monetaryAmount"));
assertThat(properties, hasItem("currencyCode"));
assertThat(properties, hasItem("amount"));
assertThat(properties, hasItem("shares"));
assertThat(properties, hasItem("dateTime"));
assertThat(properties, hasItem("type"));
assertThat(properties, hasItem("note"));
assertThat(properties.size(), is(8));
}
Aggregations