1 | package de.aikiit.mailversendala.csv; | |
2 | ||
3 | import com.google.common.collect.Lists; | |
4 | import org.apache.commons.csv.CSVFormat; | |
5 | import org.apache.commons.csv.CSVRecord; | |
6 | import org.apache.logging.log4j.LogManager; | |
7 | import org.apache.logging.log4j.Logger; | |
8 | ||
9 | import java.io.IOException; | |
10 | import java.io.Reader; | |
11 | import java.util.List; | |
12 | ||
13 | /** | |
14 | * Main class to parse given arguments for mailversendala configuration. | |
15 | */ | |
16 | public class CsvParser { | |
17 | private static final Logger LOG = | |
18 | LogManager.getLogger(CsvParser.class); | |
19 | private final Reader reader; | |
20 | ||
21 | /** | |
22 | * Parse given CSV values internally. | |
23 | * @param csvInput read configuration data as CSV. | |
24 | */ | |
25 | public CsvParser(Reader csvInput) { | |
26 | this.reader = csvInput; | |
27 | } | |
28 | ||
29 | /** | |
30 | * Do the actual parsing of a given CSV configuration. | |
31 | * @return a list of mailings to send out. | |
32 | * @throws IOException in case of errors. | |
33 | */ | |
34 | public List<Mailing> parse() throws IOException { | |
35 | final List<Mailing> results = Lists.newArrayList(); | |
36 |
1
1. parse : negated conditional → KILLED |
if (reader != null) { |
37 | Iterable<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(reader); | |
38 |
1
1. parse : removed call to java/lang/Iterable::forEach → KILLED |
records.forEach(record -> { |
39 | try { | |
40 | Mailing mailing = Mailing.builder().// | |
41 | email(record.get(Headers.EMAIL)).// | |
42 | firstname(record.get(Headers.FIRSTNAME)).// | |
43 | surname(record.get(Headers.SURNAME)).// | |
44 | build(); | |
45 | ||
46 | LOG.debug("Parsed and added mailing: {}", mailing); | |
47 | results.add(mailing); | |
48 | } catch (IllegalArgumentException e) { | |
49 | LOG.error("Unable to parse CSV-row '{}'.", record); | |
50 | } | |
51 | } | |
52 | ); | |
53 | } | |
54 |
1
1. parse : replaced return value with Collections.emptyList for de/aikiit/mailversendala/csv/CsvParser::parse → KILLED |
return results; |
55 | } | |
56 | } | |
Mutations | ||
36 |
1.1 |
|
38 |
1.1 |
|
54 |
1.1 |