Search in sources :

Example 46 with Extractor

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

the class FinTechGroupBankPDFExtractorTest method testWertpapierKauf4.

@Test
public void testWertpapierKauf4() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexKauf4.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("LU0392494992"));
    assertThat(security.getWkn(), is("ETF113"));
    assertThat(security.getName(), is("C.-MSCI NO.AM.TRN U.ETF I"));
    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(800)));
    assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2017-06-16T00:00")));
    assertThat(transaction.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", Values.Amount.factorize(0))));
    assertThat(transaction.getShares(), is(Values.Share.factorize(13.268957)));
}
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 47 with Extractor

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

the class FinTechGroupBankPDFExtractorTest method testWertpapierVerkauf4.

@Test
public void testWertpapierVerkauf4() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexVerkauf4.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    List<PortfolioTransaction> tx = // 
    results.stream().filter(i -> i instanceof BuySellEntryItem).map(i -> ((BuySellEntry) i.getSubject()).getPortfolioTransaction()).collect(Collectors.toList());
    assertThat(tx.size(), is(1));
    assertThat(tx, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2018-01-09T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.SELL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.95)))))));
}
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) 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) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) 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) Test(org.junit.Test)

Example 48 with Extractor

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

the class FinTechGroupBankPDFExtractorTest method testWertpapierKauf10.

@Test
public void testWertpapierKauf10() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexKauf10.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("LU0274211480"));
    assertThat(security.getWkn(), is("DBX1DA"));
    assertThat(security.getName(), is("DB X-TRACK.DAX ETF(DR)1C"));
    item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(BuySellEntry.class));
    BuySellEntry entry = (BuySellEntry) item.get().getSubject();
    assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.BUY));
    assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.BUY));
    assertThat(entry.getPortfolioTransaction().getAmount(), is(Values.Amount.factorize(1000.00)));
    assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2018-01-02T00:00")));
    assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE), is(Money.of("EUR", Values.Amount.factorize(0))));
    assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(7.979324)));
}
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) 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) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 49 with Extractor

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

the class FinTechGroupBankPDFExtractorTest method testErtragsgutschrift3.

@Test
public void testErtragsgutschrift3() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexErtragsgutschrift3.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("DE0006335003"));
    assertThat(security.getWkn(), is("633500"));
    assertThat(security.getName(), is("KRONES AG O.N."));
    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-06-23T00:00")));
    assertThat(transaction.getAmount(), is(Values.Amount.factorize(17.13)));
    assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(6.12))));
    assertThat(transaction.getShares(), is(Values.Share.factorize(15)));
}
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 50 with Extractor

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

the class PDFImportAssistant method detectBankIdentifier.

public static Extractor detectBankIdentifier(PDFInputFile inputFile, List<Extractor> extractors) {
    String author = inputFile.getAuthor();
    String text = inputFile.getText();
    for (Extractor extractor : extractors) {
        if (!(extractor instanceof AbstractPDFExtractor))
            continue;
        String a = ((AbstractPDFExtractor) extractor).getPDFAuthor();
        if (a != null && a.equals(author))
            return extractor;
    }
    // PDF import assistant - Level 2 - Precheck if specific securities
    // could cause faulty detection
    // ISIN DE0005088108 = Baader Bank Aktie detect the bank
    // identifier "Baader Bank"
    Matcher matcherISIN = Pattern.compile(// $NON-NLS-1$
    "DE0005088108|DE0005428007|DE000CBK1001|FR0000131104|INE007B01023|DE000FTG1111|CH0001351862|CH0001350328|CH0001354296|CH0001352720|CH0001350112|CH0318681860|CH0001343885|FR0000131104|INE007B01023").matcher(text);
    if (matcherISIN.find())
        return null;
    for (Extractor extractor : extractors) {
        if (!(extractor instanceof AbstractPDFExtractor))
            continue;
        List<String> bankIdentifier = ((AbstractPDFExtractor) extractor).getBankIdentifier();
        if (bankIdentifier.isEmpty() && text.contains(extractor.getLabel()))
            return extractor;
        for (String identifier : bankIdentifier) {
            if (identifier.isEmpty())
                continue;
            if (text.contains(identifier))
                return extractor;
        }
    }
    return null;
}
Also used : AbstractPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AbstractPDFExtractor) Matcher(java.util.regex.Matcher) Extractor(name.abuchen.portfolio.datatransfer.Extractor) AbstractPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AbstractPDFExtractor)

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