Search in sources :

Example 51 with Extractor

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

the class ReviewExtractedItemsPage method runExtractionJob.

private void runExtractionJob() {
    allEntries.clear();
    tableViewer.setInput(allEntries);
    errorTableViewer.setInput(Collections.emptyList());
    Extractor selectedExtractor = extractor instanceof AssistantPDFExtractor ? getPDFBankExtractor() : extractor;
    if (selectedExtractor == null) {
        setResults(Collections.emptyList(), files.stream().map(f -> new UnsupportedOperationException(f.getName())).collect(Collectors.toList()));
        return;
    }
    try {
        new AbstractClientJob(client, extractor.getLabel()) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.PDFImportWizardMsgExtracting, files.size());
                final List<Exception> errors = new ArrayList<>();
                try {
                    List<ExtractedEntry> entries = // 
                    selectedExtractor.extract(files, errors).stream().map(// 
                    ExtractedEntry::new).collect(Collectors.toList());
                    // Logging them is not a bad idea if the whole method
                    // fails
                    PortfolioPlugin.log(errors);
                    Display.getDefault().asyncExec(() -> setResults(entries, errors));
                } catch (Exception e) {
                    throw new UnsupportedOperationException(e);
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    } catch (Exception e) {
        throw new UnsupportedOperationException(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) List(java.util.List) ArrayList(java.util.ArrayList) Extractor(name.abuchen.portfolio.datatransfer.Extractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) AbstractClientJob(name.abuchen.portfolio.ui.AbstractClientJob)

Example 52 with Extractor

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

the class ReviewExtractedItemsPage method afterPage.

@Override
public void afterPage() {
    preferences.setValue(IMPORT_TARGET_ACCOUNT + extractor.getClass().getSimpleName(), getAccount().getUUID());
    preferences.setValue(IMPORT_TARGET_PORTFOLIO + extractor.getClass().getSimpleName(), getPortfolio().getUUID());
    Extractor e = (Extractor) comboExtractors.getStructuredSelection().getFirstElement();
    if (e != null)
        preferences.setValue(IMPORT_TARGET_EXTRACTOR, e.getClass().getName());
}
Also used : Extractor(name.abuchen.portfolio.datatransfer.Extractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor)

Example 53 with Extractor

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

the class ReviewExtractedItemsPage method preselectDropDowns.

private void preselectDropDowns() {
    // idea: generally one type of document (i.e. from the same bank) will
    // be imported into the same account
    List<Account> activeAccounts = client.getActiveAccounts();
    if (!activeAccounts.isEmpty()) {
        String uuid = preferences.getString(IMPORT_TARGET_ACCOUNT + extractor.getClass().getSimpleName());
        // do not trigger selection listener (-> do not user #setSelection)
        primaryAccount.getCombo().select(IntStream.range(0, activeAccounts.size()).filter(i -> activeAccounts.get(i).getUUID().equals(uuid)).findAny().orElse(0));
        secondaryAccount.getCombo().select(0);
    }
    List<Portfolio> activePortfolios = client.getActivePortfolios();
    if (!activePortfolios.isEmpty()) {
        String uuid = preferences.getString(IMPORT_TARGET_PORTFOLIO + extractor.getClass().getSimpleName());
        // do not trigger selection listener (-> do not user #setSelection)
        primaryPortfolio.getCombo().select(IntStream.range(0, activePortfolios.size()).filter(i -> activePortfolios.get(i).getUUID().equals(uuid)).findAny().orElse(0));
        secondaryPortfolio.getCombo().select(0);
    }
    if (extractor instanceof AssistantPDFExtractor) {
        String clazz = preferences.getString(IMPORT_TARGET_EXTRACTOR);
        List<Extractor> availableExtractors = ((AssistantPDFExtractor) extractor).getAvailableExtractors();
        OptionalInt index = IntStream.range(0, availableExtractors.size()).filter(i -> clazz.equals(availableExtractors.get(i).getClass().getName())).findAny();
        index.ifPresent(ii -> comboExtractors.getCombo().select(ii));
    }
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) StyledString(org.eclipse.jface.viewers.StyledString) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) AbstractWizardPage(name.abuchen.portfolio.ui.wizards.AbstractWizardPage) IStatus(org.eclipse.core.runtime.IStatus) Extractor(name.abuchen.portfolio.datatransfer.Extractor) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Composite(org.eclipse.swt.widgets.Composite) ImportAction(name.abuchen.portfolio.datatransfer.ImportAction) AbstractClientJob(name.abuchen.portfolio.ui.AbstractClientJob) CheckCurrenciesAction(name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction) Button(org.eclipse.swt.widgets.Button) Account(name.abuchen.portfolio.model.Account) MenuManager(org.eclipse.jface.action.MenuManager) Status(org.eclipse.core.runtime.Status) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Styler(org.eclipse.jface.viewers.StyledString.Styler) SWT(org.eclipse.swt.SWT) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) IntStream(java.util.stream.IntStream) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) LocalDateTime(java.time.LocalDateTime) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) TextStyle(org.eclipse.swt.graphics.TextStyle) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Table(org.eclipse.swt.widgets.Table) OptionalInt(java.util.OptionalInt) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArrayList(java.util.ArrayList) Annotated(name.abuchen.portfolio.model.Annotated) Messages(name.abuchen.portfolio.ui.Messages) CheckValidTypesAction(name.abuchen.portfolio.datatransfer.actions.CheckValidTypesAction) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) DetectDuplicatesAction(name.abuchen.portfolio.datatransfer.actions.DetectDuplicatesAction) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Combo(org.eclipse.swt.widgets.Combo) FormLayout(org.eclipse.swt.layout.FormLayout) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Action(org.eclipse.jface.action.Action) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) FormDataFactory(name.abuchen.portfolio.ui.util.FormDataFactory) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) LabelProvider(org.eclipse.jface.viewers.LabelProvider) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) StyledString(org.eclipse.jface.viewers.StyledString) Extractor(name.abuchen.portfolio.datatransfer.Extractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) OptionalInt(java.util.OptionalInt)

Example 54 with Extractor

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

the class AbstractPDFExtractor method extract.

@Override
public List<Item> extract(List<Extractor.InputFile> files, List<Exception> errors) {
    // careful: security cache makes extractor stateful
    securityCache = new SecurityCache(client);
    List<Item> results = new ArrayList<>();
    for (Extractor.InputFile f : files) {
        if (!(f instanceof PDFInputFile))
            throw new IllegalArgumentException();
        PDFInputFile inputFile = (PDFInputFile) f;
        String text = inputFile.getText();
        results.addAll(extract(inputFile.getFile().getName(), text, errors));
    }
    results.addAll(securityCache.createMissingSecurityItems(results));
    securityCache = null;
    return results;
}
Also used : SecurityCache(name.abuchen.portfolio.datatransfer.SecurityCache) ArrayList(java.util.ArrayList) Extractor(name.abuchen.portfolio.datatransfer.Extractor)

Example 55 with Extractor

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

the class ImportExtractedItemsWizard method addPages.

@Override
public void addPages() {
    // assign files to extractors and create a page for each extractor that
    // has a file
    Map<Extractor, List<Extractor.InputFile>> extractor2files = new HashMap<>();
    if (extractors.size() == 1) {
        extractor2files.put(extractors.get(0), files);
    } else if (isLegacyMode) {
        Extractor e = new AssistantPDFExtractor(client, new ArrayList<>(extractors));
        extractors.add(e);
        extractor2files.put(e, files);
    } else {
        assignFilesToExtractors(extractor2files);
    }
    for (Extractor extractor : extractors) {
        List<Extractor.InputFile> files4extractor = extractor2files.get(extractor);
        if (files4extractor == null || files4extractor.isEmpty())
            continue;
        ReviewExtractedItemsPage page = new ReviewExtractedItemsPage(client, extractor, preferences, files4extractor);
        pages.add(page);
        addPage(page);
    }
    AbstractWizardPage.attachPageListenerTo(getContainer());
}
Also used : HashMap(java.util.HashMap) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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