throws ParseException
{
if (!(target instanceof Portfolio))
throw new IllegalArgumentException();
Portfolio portfolio = (Portfolio) target;
Date date = convertDate(Messages.CSVColumn_Date, rawValues, field2column);
if (date == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Date),
0);
Long amount = convertAmount(Messages.CSVColumn_Value, rawValues, field2column);
if (amount == null)
throw new ParseException(
MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Value), 0);
Long fees = convertAmount(Messages.CSVColumn_Fees, rawValues, field2column);
if (fees == null)
fees = Long.valueOf(0);
Long taxes = convertAmount(Messages.CSVColumn_Taxes, rawValues, field2column);
if (taxes == null)
taxes = Long.valueOf(0);
String isin = getTextValue(Messages.CSVColumn_ISIN, rawValues, field2column);
String tickerSymbol = getTextValue(Messages.CSVColumn_TickerSymbol, rawValues, field2column);
String wkn = getTextValue(Messages.CSVColumn_WKN, rawValues, field2column);
if (isin == null && tickerSymbol == null && wkn == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingOneOfManyFields,
Messages.CSVColumn_ISIN + ", " + Messages.CSVColumn_TickerSymbol + ", " //$NON-NLS-1$ //$NON-NLS-2$
+ Messages.CSVColumn_WKN), 0);
Long shares = convertShares(Messages.CSVColumn_Shares, rawValues, field2column);
if (shares == null)
throw new ParseException(
MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Shares), 0);
PortfolioTransaction.Type type = convertEnum(Messages.CSVColumn_Type, PortfolioTransaction.Type.class,
rawValues, field2column);
PortfolioTransaction transaction = new PortfolioTransaction();
transaction.setDate(date);
transaction.setAmount(Math.abs(amount));
transaction.setSecurity(lookupSecurity(client, isin, tickerSymbol, wkn, true));
transaction.setShares(Math.abs(shares));
transaction.setFees(Math.abs(fees));
transaction.setTaxes(Math.abs(taxes));
if (type != null)
transaction.setType(type);
else
transaction.setType(amount < 0 ? PortfolioTransaction.Type.BUY : PortfolioTransaction.Type.SELL);
portfolio.addTransaction(transaction);
}