in services/billing-aws/src/main/java/com/epam/datalab/core/parser/ParserByLine.java [167:248]
public List<Document> parse() throws InitializationException, AdapterException, ParseException {
List<Document> billingData = new ArrayList<>();
try {
if (init()) {
String line;
List<String> row;
ReportLine reportLine;
LOGGER.info("Parsing {}", getAdapterIn().getEntryName());
while ((line = getNextRow()) != null) {
if (getFilter() != null && (line = getFilter().canParse(line)) == null) {
getCurrentStatistics().incrRowFiltered();
continue;
}
row = parseRow(line);
if ((getFilter() != null && (row = getFilter().canTransform(row)) == null)) {
getCurrentStatistics().incrRowFiltered();
continue;
}
try {
if (getCondition() != null && !getCondition().evaluate(row)) {
getCurrentStatistics().incrRowFiltered();
continue;
}
} catch (ParseException e) {
throw new ParseException(e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName() +
SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
} catch (Exception e) {
throw new ParseException("Cannot evaluate condition " + getWhereCondition() + ". " +
e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName() +
SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
}
try {
reportLine = getCommonFormat().toCommonFormat(row);
} catch (ParseException e) {
throw new ParseException("Cannot cast row to common format. " +
e.getLocalizedMessage() + ENTRY_NAME + getCurrentStatistics().getEntryName() +
SOURCE_LINE + getCurrentStatistics().getRowReaded() + "]: " + line, e);
}
if (getFilter() != null && (reportLine = getFilter().canAccept(reportLine)) == null) {
getCurrentStatistics().incrRowFiltered();
continue;
}
getCurrentStatistics().incrRowParsed();
if (getAggregate() != AggregateGranularity.NONE) {
getAggregator().append(reportLine);
} else {
billingData.add(getAdapterOut().writeRow(reportLine));
getCurrentStatistics().incrRowWritten();
}
}
if (getAggregate() != AggregateGranularity.NONE) {
for (int i = 0; i < getAggregator().size(); i++) {
billingData.add(getAdapterOut().writeRow(getAggregator().get(i)));
getCurrentStatistics().incrRowWritten();
}
}
}
} catch (GenericException e) {
close(true);
if (getCurrentStatistics() != null) {
getCurrentStatistics().stop();
}
throw e;
} catch (Exception e) {
close(true);
if (getCurrentStatistics() != null) {
getCurrentStatistics().stop();
}
throw new ParseException("Unknown parser error. " + e.getLocalizedMessage(), e);
}
close(false);
if (getCurrentStatistics() != null) {
getCurrentStatistics().stop();
}
return billingData;
}