From b1e5cbaf866211c75c44ac8def388c7be5a01c22 Mon Sep 17 00:00:00 2001 From: Nirus2000 Date: Thu, 4 Apr 2024 10:15:54 +0200 Subject: [PATCH] Improve Credit Suisse AG PDF-Importer Format source to standard eclipse format Improve regulare expressions Remove obsolet source --- .../CreditSuisseAGExtractorTest.java | 12 +- .../datatransfer/pdf/BankSLMPDFExtractor.java | 2 +- .../pdf/CreditSuisseAGPDFExtractor.java | 555 ++++++++++-------- 3 files changed, 314 insertions(+), 255 deletions(-) diff --git a/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/creditsuisseag/CreditSuisseAGExtractorTest.java b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/creditsuisseag/CreditSuisseAGExtractorTest.java index 463f1037b2..d634a40d6c 100644 --- a/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/creditsuisseag/CreditSuisseAGExtractorTest.java +++ b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/creditsuisseag/CreditSuisseAGExtractorTest.java @@ -48,7 +48,7 @@ public void testWertpapierKauf01() Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst() .orElseThrow(IllegalArgumentException::new).getSecurity(); assertThat(security.getIsin(), is("US46284V1017")); - assertNull(security.getWkn()); + assertThat(security.getWkn(), is("26754105")); assertNull(security.getTickerSymbol()); assertThat(security.getName(), is("Registered Shs Iron Mountain Inc")); assertThat(security.getCurrencyCode(), is(CurrencyUnit.USD)); @@ -112,7 +112,7 @@ public void testWertpapierKauf02() Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst() .orElseThrow(IllegalArgumentException::new).getSecurity(); assertThat(security.getIsin(), is("XS1055787680")); - assertNull(security.getWkn()); + assertThat(security.getWkn(), is("24160639")); assertNull(security.getTickerSymbol()); assertThat(security.getName(), is("6.25 % Fixed Rate Notes Norddeutsche")); assertThat(security.getCurrencyCode(), is(CurrencyUnit.USD)); @@ -176,7 +176,7 @@ public void testWertpapierVerkauf01() Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst() .orElseThrow(IllegalArgumentException::new).getSecurity(); assertThat(security.getIsin(), is("GB00B03MLX29")); - assertNull(security.getWkn()); + assertThat(security.getWkn(), is("1987674")); assertNull(security.getTickerSymbol()); assertThat(security.getName(), is("Akt. -A- Royal Dutch Shell PLC")); assertThat(security.getCurrencyCode(), is(CurrencyUnit.EUR)); @@ -220,7 +220,7 @@ public void testWertpapierVerkauf02() Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst() .orElseThrow(IllegalArgumentException::new).getSecurity(); assertThat(security.getIsin(), is("US88163VAD10")); - assertNull(security.getWkn()); + assertThat(security.getWkn(), is("2429251")); assertNull(security.getTickerSymbol()); assertThat(security.getName(), is("6.15 % Notes Teva Pharmaceutical Finance")); assertThat(security.getCurrencyCode(), is(CurrencyUnit.USD)); @@ -283,7 +283,7 @@ public void testDividende01() Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst() .orElseThrow(IllegalArgumentException::new).getSecurity(); assertThat(security.getIsin(), is("XS1055787680")); - assertNull(security.getWkn()); + assertThat(security.getWkn(), is("24160639")); assertNull(security.getTickerSymbol()); assertThat(security.getName(), is("6.25 % FIXED RATE NOTES NORDDEUTSCHE")); assertThat(security.getCurrencyCode(), is(CurrencyUnit.USD)); @@ -326,7 +326,7 @@ public void testDividende02() Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst() .orElseThrow(IllegalArgumentException::new).getSecurity(); assertThat(security.getIsin(), is("US46284V1017")); - assertNull(security.getWkn()); + assertThat(security.getWkn(), is("26754105")); assertNull(security.getTickerSymbol()); assertThat(security.getName(), is("REGISTERED SHS IRON MOUNTAIN INC")); assertThat(security.getCurrencyCode(), is(CurrencyUnit.USD)); diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/BankSLMPDFExtractor.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/BankSLMPDFExtractor.java index 176ddebdc1..f9c8b32b48 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/BankSLMPDFExtractor.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/BankSLMPDFExtractor.java @@ -95,7 +95,7 @@ private void addBuySellTransaction() // @formatter:on .section("shares") // .find("Wir haben.*") - .match("^(?[\\.',\\d]+) .*$") // + .match("^(?[\\.'\\d]+) .*$") // .assign((t, v) -> t.setShares(asShares(v.get("shares")))) // @formatter:off diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/CreditSuisseAGPDFExtractor.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/CreditSuisseAGPDFExtractor.java index 56fbf0bce0..b18af70f7e 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/CreditSuisseAGPDFExtractor.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/CreditSuisseAGPDFExtractor.java @@ -40,102 +40,124 @@ private void addBuySellTransaction() this.addDocumentTyp(type); Transaction pdfTransaction = new Transaction<>(); - pdfTransaction.subject(() -> { - BuySellEntry entry = new BuySellEntry(); - entry.setType(PortfolioTransaction.Type.BUY); - return entry; - }); Block firstRelevantLine = new Block("^Ihr (Kauf|Verkauf) .*$"); type.addBlock(firstRelevantLine); firstRelevantLine.set(pdfTransaction); - pdfTransaction - // Is type --> "Verkauf" change from BUY to SELL - .section("type").optional() - .match("^Ihr (?(Kauf|Verkauf)) .*$") - .assign((t, v) -> { - if ("Verkauf".equals(v.get("type"))) - t.setType(PortfolioTransaction.Type.SELL); - }) - - // 900 Registered Shs Iron Mountain Inc USD 0.01 - // Valor 26754105, IRM, ISIN US46284V1017 - // Kurswert USD 27,270.00 - .section("name", "isin", "currency").optional() - .match("^(?[\\.,\\d]+) (?.*) [\\w]{3} [\\.,\\d]+$") - .match("^.* ISIN (?[\\w]{12})$") - .match("^Kurswert (?[\\w]{3}) [\\.,\\d]+$") - .assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))) - - // USD 200,000 6.25 % Fixed Rate Notes Norddeutsche - // Landesbank Girozentrale 2014-10.4.24 Reg-S - // Subord. - // Valor 24160639, NDKH, ISIN XS1055787680 - // Kurswert USD 183,000.00 - .section("name", "isin", "currency").optional() - .match("^[\\w]{3} [\\.,\\d]+ (?.*)$") - .match("^.* ISIN (?[\\w]{12})$") - .match("^Kurswert (?[\\w]{3}) [\\.,\\d]+$") - .assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))) - - .oneOf( - // USD 200,000 6.25 % Fixed Rate Notes Norddeutsche - section -> section - .attributes("shares") - .match("^[\\w]{3} (?[\\.,\\d]+) [\\.,\\d]+ % (?.*)$") - .assign((t, v) -> { - // Percentage quotation, workaround for bonds - BigDecimal shares = asExchangeRate(v.get("shares")); - t.setShares(Values.Share.factorize(shares.doubleValue() / 100)); - }) - , - // 900 Registered Shs Iron Mountain Inc USD 0.01 - section -> section - .attributes("shares") - .match("^(?[\\.,\\d]+) .*$") - .assign((t, v) -> t.setShares(asShares(v.get("shares")))) - ) - - // Ausführungszeit - // 103 14800075391312 18:32:46 XNYS USD 30.30 - .section("time").optional() - .find("Ausf.hrungszeit") - .match("^.* (?