| 1 | package de.aikiit.mailversendala.csv; | |
| 2 | ||
| 3 | /* | |
| 4 | * Copyright (c) P. Ottlinger | |
| 5 | * | |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 7 | * you may not use this file except in compliance with the License. | |
| 8 | * You may obtain a copy of the License at | |
| 9 | * | |
| 10 | * https://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | * | |
| 12 | * Unless required by applicable law or agreed to in writing, | |
| 13 | * software distributed under the License is distributed on an | |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | * KIND, either express or implied. See the License for the | |
| 16 | * specific language governing permissions and limitations | |
| 17 | * under the License. | |
| 18 | */ | |
| 19 | ||
| 20 | ||
| 21 | import com.google.common.collect.Lists; | |
| 22 | import org.apache.commons.csv.CSVFormat; | |
| 23 | import org.apache.commons.csv.CSVRecord; | |
| 24 | import org.apache.logging.log4j.LogManager; | |
| 25 | import org.apache.logging.log4j.Logger; | |
| 26 | ||
| 27 | import java.io.IOException; | |
| 28 | import java.io.Reader; | |
| 29 | import java.util.List; | |
| 30 | ||
| 31 | /** | |
| 32 | * Main class to parse given arguments for mailversendala configuration. | |
| 33 | */ | |
| 34 | public class CsvParser { | |
| 35 | private static final Logger LOG = | |
| 36 | LogManager.getLogger(CsvParser.class); | |
| 37 | private final Reader reader; | |
| 38 | ||
| 39 | /** | |
| 40 | * Parse given CSV values internally. | |
| 41 | * @param csvInput read configuration data as CSV. | |
| 42 | */ | |
| 43 | public CsvParser(Reader csvInput) { | |
| 44 | this.reader = csvInput; | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Do the actual parsing of a given CSV configuration. | |
| 49 | * @return a list of mailings to send out. | |
| 50 | * @throws IOException in case of errors. | |
| 51 | */ | |
| 52 | public List<Mailing> parse() throws IOException { | |
| 53 | final List<Mailing> results = Lists.newArrayList(); | |
| 54 |
1
1. parse : negated conditional → KILLED |
if (reader != null) { |
| 55 | Iterable<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(reader); | |
| 56 |
1
1. parse : removed call to java/lang/Iterable::forEach → KILLED |
records.forEach(record -> { |
| 57 | try { | |
| 58 | String email = record.get(Headers.EMAIL); | |
| 59 |
1
1. lambda$parse$0 : negated conditional → KILLED |
if (email.isBlank()) { |
| 60 | throw new IllegalArgumentException("Required field 'email' must not be blank"); | |
| 61 | } | |
| 62 | Mailing mailing = Mailing.builder().// | |
| 63 | email(email).// | |
| 64 | firstname(record.get(Headers.FIRSTNAME)).// | |
| 65 | surname(record.get(Headers.SURNAME)).// | |
| 66 | salutation(record.get(Headers.SALUTATION)).// | |
| 67 | build(); | |
| 68 | ||
| 69 | LOG.debug("Parsed and added mailing: {}", mailing); | |
| 70 | results.add(mailing); | |
| 71 | } catch (IllegalArgumentException e) { | |
| 72 | LOG.error("Unable to parse CSV-row '{}': {}", record, e.getMessage()); | |
| 73 | } | |
| 74 | } | |
| 75 | ); | |
| 76 | } | |
| 77 |
1
1. parse : replaced return value with Collections.emptyList for de/aikiit/mailversendala/csv/CsvParser::parse → KILLED |
return results; |
| 78 | } | |
| 79 | } | |
Mutations | ||
| 54 |
1.1 |
|
| 56 |
1.1 |
|
| 59 |
1.1 |
|
| 77 |
1.1 |