Search in sources :

Example 1 with PortfolioClientFilter

use of name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter in project portfolio by buchen.

the class SecurityTaxAndFeeAccountTransactionsTestCase method checkPortfolioClientFilter.

@Test
public void checkPortfolioClientFilter() {
    Client filteredClient = new PortfolioClientFilter(client.getPortfolios().get(0)).filter(client);
    List<AccountTransaction> txa = filteredClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    // expect 8 transactions: the 4 tax and fees transactions plus the
    // offset transactions to keep the balance zero
    assertThat(txa.size(), is(8));
    // check balance is zero
    ClientSnapshot balance = ClientSnapshot.create(filteredClient, converter, interval.getEndDate());
    assertThat(balance.getMonetaryAssets(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1456.5))));
    assertThat(balance.getAccounts().size(), is(1));
    assertThat(balance.getAccounts().iterator().next().getFunds(), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-09T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10.0)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.0)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-11T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(25.0)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-12T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.0)))))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Collectors(java.util.stream.Collectors) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) IsCloseTo.closeTo(org.hamcrest.number.IsCloseTo.closeTo) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 2 with PortfolioClientFilter

use of name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter in project portfolio by buchen.

the class ClientFilterMenu method buildItem.

private Item buildItem(Object[] selected) {
    List<Portfolio> portfolios = Arrays.stream(selected).filter(o -> o instanceof Portfolio).map(o -> (Portfolio) o).collect(Collectors.toList());
    List<Account> accounts = Arrays.stream(selected).filter(o -> o instanceof Account).map(o -> (Account) o).collect(Collectors.toList());
    String label = // $NON-NLS-1$
    String.join(// $NON-NLS-1$
    ", ", Arrays.stream(selected).map(String::valueOf).collect(Collectors.toList()));
    String uuids = // $NON-NLS-1$
    String.join(// $NON-NLS-1$
    ",", Arrays.stream(selected).map(o -> o instanceof Account ? ((Account) o).getUUID() : ((Portfolio) o).getUUID()).collect(Collectors.toList()));
    return new Item(label, uuids, new PortfolioClientFilter(portfolios, accounts));
}
Also used : Arrays(java.util.Arrays) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) LinkedList(java.util.LinkedList) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) IMenuManager(org.eclipse.jface.action.IMenuManager) Collections(java.util.Collections) IMenuListener(org.eclipse.jface.action.IMenuListener) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Client (name.abuchen.portfolio.model.Client)2 PortfolioClientFilter (name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter)2 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Consumer (java.util.function.Consumer)1 Stream (java.util.stream.Stream)1 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)1 Account (name.abuchen.portfolio.model.Account)1 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)1 Classification (name.abuchen.portfolio.model.Classification)1