Search in sources :

Example 1 with SecurityCache

use of name.abuchen.portfolio.datatransfer.SecurityCache 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 2 with SecurityCache

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

the class BaseCSVExtractor method extract.

@Override
public List<Item> extract(int skipLines, List<String[]> rawValues, Map<String, Column> field2column, List<Exception> errors) {
    // careful: the security cache makes the extractor stateful because
    // securities extracted during a previous run will not be created again
    securityCache = new SecurityCache(client);
    List<Item> results = new ArrayList<>();
    // +1 because of end user
    int lineNo = 1 + skipLines;
    for (String[] strings : rawValues) {
        try {
            extract(results, strings, field2column);
        } catch (ParseException | UnsupportedOperationException | IllegalArgumentException e) {
            errors.add(new IOException(MessageFormat.format(Messages.CSVLineXwithMsgY, lineNo, e.getMessage()), e));
        }
        lineNo++;
    }
    results.addAll(securityCache.createMissingSecurityItems(results));
    securityCache = null;
    return results;
}
Also used : SecurityCache(name.abuchen.portfolio.datatransfer.SecurityCache) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) IOException(java.io.IOException)

Aggregations

ArrayList (java.util.ArrayList)2 SecurityCache (name.abuchen.portfolio.datatransfer.SecurityCache)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Extractor (name.abuchen.portfolio.datatransfer.Extractor)1