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);
}
}
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());
}
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));
}
}
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;
}
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());
}
Aggregations