Search in sources :

Example 21 with Extractor

use of name.abuchen.portfolio.datatransfer.Extractor in project portfolio by buchen.

the class FinTechGroupBankPDFExtractorTest method testWertpapierKauf.

@Test
public void testWertpapierKauf() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexKauf.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(6));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    assertFirstSecurity(results.stream().filter(i -> i instanceof SecurityItem).findFirst());
    assertFirstTransaction(results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst());
    assertSecondSecurity(// 
    results.stream().filter(i -> i instanceof SecurityItem).collect(Collectors.toList()).get(1));
    assertSecondTransaction(results.stream().filter(i -> i instanceof BuySellEntryItem).collect(Collectors.toList()).get(1));
    assertThirdTransaction(// 
    results.stream().filter(i -> i instanceof BuySellEntryItem).collect(Collectors.toList()).get(2));
    assertFourthTransaction(// 
    results.stream().filter(i -> i instanceof TransactionItem).collect(Collectors.toList()).get(0));
}
Also used : SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Quote(name.abuchen.portfolio.money.Quote) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) List(java.util.List) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) Optional(java.util.Optional) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) IOException(java.io.IOException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Test(org.junit.Test)

Example 22 with Extractor

use of name.abuchen.portfolio.datatransfer.Extractor in project portfolio by buchen.

the class FinTechGroupBankPDFExtractorTest method testWertpapierKauf3.

@Test
public void testWertpapierKauf3() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexKauf3.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    Optional<Item> item;
    // security
    item = results.stream().filter(i -> i instanceof SecurityItem).findFirst();
    assertThat(item.isPresent(), is(true));
    Security security = ((SecurityItem) item.get()).getSecurity();
    assertThat(security.getIsin(), is("IE00B2QWCY14"));
    assertThat(security.getWkn(), is("A0Q1YY"));
    assertThat(security.getName(), is("ISHSIII-S+P SM.CAP600 DLD"));
    PortfolioTransaction transaction = results.stream().filter(i -> i instanceof Extractor.BuySellEntryItem).map(i -> (BuySellEntry) ((Extractor.BuySellEntryItem) i).getSubject()).map(b -> b.getPortfolioTransaction()).findAny().get();
    assertThat(transaction.getType(), is(PortfolioTransaction.Type.BUY));
    assertThat(transaction.getAmount(), is(Values.Amount.factorize(1050)));
    assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2016-12-15T00:00")));
    assertThat(transaction.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", Values.Amount.factorize(0))));
    assertThat(transaction.getShares(), is(Values.Share.factorize(19.334524)));
}
Also used : SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Quote(name.abuchen.portfolio.money.Quote) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) List(java.util.List) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) Optional(java.util.Optional) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 23 with Extractor

use of name.abuchen.portfolio.datatransfer.Extractor in project portfolio by buchen.

the class FinTechGroupBankPDFExtractorTest method testDividendeAusland.

@Test
public void testDividendeAusland() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FinTechGroupBankDividendeAusland1.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    // security
    Optional<Item> item = results.stream().filter(i -> i instanceof SecurityItem).findFirst();
    assertThat(item.isPresent(), is(true));
    Security security = ((SecurityItem) item.get()).getSecurity();
    assertThat(security.getIsin(), is("US8552441094"));
    assertThat(security.getWkn(), is("884437"));
    assertThat(security.getName(), is("STARBUCKS CORP."));
    item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));
    AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(transaction.getSecurity(), is(security));
    assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2017-08-25T00:00")));
    assertThat(transaction.getAmount(), is(Values.Amount.factorize(14.45)));
    assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(7.78))));
    assertThat(transaction.getShares(), is(Values.Share.factorize(105)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Quote(name.abuchen.portfolio.money.Quote) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) List(java.util.List) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) Optional(java.util.Optional) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 24 with Extractor

use of name.abuchen.portfolio.datatransfer.Extractor in project portfolio by buchen.

the class ImportIBHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) throws IOException {
    Client client = MenuHelper.getActiveClient(part);
    if (client == null)
        return;
    try {
        Extractor extractor = new IBFlexStatementExtractor(client);
        FileDialog fileDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
        fileDialog.setText(extractor.getLabel());
        fileDialog.setFilterNames(new String[] { // $NON-NLS-1$
        MessageFormat.format("{0} ({1})", extractor.getLabel(), extractor.getFilterExtension()) });
        fileDialog.setFilterExtensions(new String[] { extractor.getFilterExtension() });
        fileDialog.open();
        String[] filenames = fileDialog.getFileNames();
        if (filenames.length == 0)
            return;
        List<Extractor.InputFile> files = new ArrayList<>();
        for (String filename : filenames) files.add(new Extractor.InputFile(new File(fileDialog.getFilterPath(), filename)));
        IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
        Dialog wizwardDialog = new WizardDialog(Display.getDefault().getActiveShell(), new ImportExtractedItemsWizard(client, extractor, preferences, files));
        wizwardDialog.open();
    } catch (IllegalArgumentException e) {
        PortfolioPlugin.log(e);
        MessageDialog.openError(shell, Messages.LabelError, e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) IBFlexStatementExtractor(name.abuchen.portfolio.datatransfer.IBFlexStatementExtractor) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ImportExtractedItemsWizard(name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard) IBFlexStatementExtractor(name.abuchen.portfolio.datatransfer.IBFlexStatementExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) Client(name.abuchen.portfolio.model.Client) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Execute(org.eclipse.e4.core.di.annotations.Execute) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 25 with Extractor

use of name.abuchen.portfolio.datatransfer.Extractor in project portfolio by buchen.

the class ImportExtractedItemsWizard method assignFilesToExtractors.

private void assignFilesToExtractors(Map<Extractor, List<Extractor.InputFile>> extractor2files) {
    List<Extractor.InputFile> unknown = new ArrayList<>();
    for (Extractor.InputFile file : files) {
        PDFInputFile inputFile = (PDFInputFile) file;
        Extractor extractor = PDFImportAssistant.detectBankIdentifier(inputFile, extractors);
        if (extractor != null)
            extractor2files.computeIfAbsent(extractor, k -> new ArrayList<>()).add(inputFile);
        else
            unknown.add(inputFile);
    }
    if (!unknown.isEmpty()) {
        Extractor e = new AssistantPDFExtractor(client, new ArrayList<>(extractors));
        extractors.add(e);
        extractor2files.put(e, unknown);
    }
}
Also used : PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) ArrayList(java.util.ArrayList) CommerzbankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.CommerzbankPDFExtractor) BankSLMPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.BankSLMPDFExtractor) ComdirectPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.ComdirectPDFExtractor) DegiroPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.DegiroPDFExtractor) OnvistaPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.OnvistaPDFExtractor) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) INGDiBaExtractor(name.abuchen.portfolio.datatransfer.pdf.INGDiBaExtractor) BaaderBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.BaaderBankPDFExtractor) SBrokerPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.SBrokerPDFExtractor) ConsorsbankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.ConsorsbankPDFExtractor) HelloBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.HelloBankPDFExtractor) DeutscheBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.DeutscheBankPDFExtractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) DABPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.DABPDFExtractor) UnicreditPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.UnicreditPDFExtractor) DkbPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.DkbPDFExtractor) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile)

Aggregations

Extractor (name.abuchen.portfolio.datatransfer.Extractor)55 ArrayList (java.util.ArrayList)52 List (java.util.List)49 PDFInputFile (name.abuchen.portfolio.datatransfer.pdf.PDFInputFile)48 Client (name.abuchen.portfolio.model.Client)48 LocalDateTime (java.time.LocalDateTime)47 Collectors (java.util.stream.Collectors)47 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)47 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)47 Security (name.abuchen.portfolio.model.Security)47 Money (name.abuchen.portfolio.money.Money)47 Values (name.abuchen.portfolio.money.Values)47 IOException (java.io.IOException)46 Optional (java.util.Optional)46 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)46 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)46 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)46 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)46 AssertImportActions (name.abuchen.portfolio.datatransfer.actions.AssertImportActions)46