private StockEntity retrieveStock(StockRecordBean record) { StockEntity stockEntity = this.stockData.findByName(record.getStockName()); if (stockEntity == null) { stockEntity = new StockEntity(); stockEntity.setName(record.getStockName()); stockEntity = this.dataStorage.saveStock(stockEntity); } return stockEntity; }
@Override public void loadFile(String fullnamePath, final List<String> acceptedStocks) throws IOException { if (this.logger.isInfoEnabled()) { this.logger.info(String.format("Load data from file name path [%s].", fullnamePath)); } LineIterator lineIterator = FileUtils.lineIterator(new File(fullnamePath), FILE_FORMAT); while (lineIterator.hasNext()) { final String line = lineIterator.next().toLowerCase().trim(); StockRecordBean record = null; try { if (line.length() >= RECORD_SIZE) { record = StockDataLoader.this.parseLine(line); if ((acceptedStocks == null) || acceptedStocks.isEmpty() || acceptedStocks.contains(record.getStockName().toLowerCase())) { if (record.getBdi() == 2) { StockDataLoader.this.loadRecord(record); } else { if (this.logger.isTraceEnabled()) { this.logger.trace(String.format("Record [%s] with DBI not equals 2.", record)); } } } } else { if (this.logger.isInfoEnabled()) { this.logger.info(String.format("First or Last line aren´t loaded [%s].", line)); } } } catch (Exception e) { this.logger.error( String.format( "Problem to parse or save the record [%s] and the bean [%s].", line, record)); this.logger.error(e.getMessage(), e); } } }