| 1 | package de.aikiit.mailversendala; | |
| 2 | ||
| 3 | import de.aikiit.mailversendala.csv.CsvParser; | |
| 4 | import de.aikiit.mailversendala.csv.Mailing; | |
| 5 | import org.apache.commons.mail.EmailException; | |
| 6 | import org.apache.logging.log4j.LogManager; | |
| 7 | import org.apache.logging.log4j.Logger; | |
| 8 | import org.assertj.core.util.Strings; | |
| 9 | ||
| 10 | import java.io.File; | |
| 11 | import java.io.FileReader; | |
| 12 | import java.io.IOException; | |
| 13 | import java.nio.charset.StandardCharsets; | |
| 14 | import java.util.List; | |
| 15 | import java.util.concurrent.atomic.AtomicInteger; | |
| 16 | ||
| 17 | /** | |
| 18 |  * Encapsulates the actual CSV parsing and mailing generation. | |
| 19 |  */ | |
| 20 | public class Mailversendala { | |
| 21 |     private static final Logger LOG = | |
| 22 |             LogManager.getLogger(Mailversendala.class); | |
| 23 | ||
| 24 |     /** | |
| 25 |      * Send out mails with the given configuration and return result object afterwards. | |
| 26 |      * @param configuration application configuration. | |
| 27 |      * @return result object of the current application run. | |
| 28 |      * @throws IOException in case of errors. | |
| 29 |      */ | |
| 30 |     public static MailingResult sendOut(MailConfig configuration) throws IOException { | |
| 31 |         LOG.info("**** MAILVERSENDALA: Starting .... ****"); | |
| 32 | ||
| 33 |         String csvPath = configuration.getCsvPath(); | |
| 34 |         MailingResult result = new MailingResult(); | |
| 35 | ||
| 36 |         LOG.info("Consuming CSV: {}", csvPath); | |
| 37 | ||
| 38 | 1
1. sendOut : negated conditional → KILLED |         if (!Strings.isNullOrEmpty(csvPath)) { | 
| 39 |             LOG.info(configuration.getCsvPath()); | |
| 40 | ||
| 41 |             File asFile = new File(configuration.getCsvPath()); | |
| 42 | 1
1. sendOut : negated conditional → KILLED |             if (asFile.exists()) { | 
| 43 |                 try (FileReader r = new FileReader(asFile, StandardCharsets.UTF_8)) { | |
| 44 |                     CsvParser parser = new CsvParser(r); | |
| 45 |                     final List<Mailing> mailings = parser.parse(); | |
| 46 | ||
| 47 |                     final int total = mailings.size(); | |
| 48 |                     LOG.info("Will send out {} mails ... hold on tight :-)", total); | |
| 49 | ||
| 50 | 1
1. sendOut : removed call to java/util/List::forEach → KILLED |                     mailings.forEach(mailing -> { | 
| 51 |                         try { | |
| 52 | 1
1. lambda$sendOut$0 : removed call to de/aikiit/mailversendala/SendOut::send → SURVIVED |                             new SendOut(mailing).send(); | 
| 53 | 1
1. lambda$sendOut$0 : removed call to de/aikiit/mailversendala/MailingResult::addSuccess → KILLED |                             result.addSuccess(); | 
| 54 |                             LOG.info("Successfully send out {}.mail", result.getMailCounter().orElse(new AtomicInteger(0))); | |
| 55 |                         } catch (EmailException e) { | |
| 56 | 1
1. lambda$sendOut$0 : removed call to de/aikiit/mailversendala/MailingResult::addError → NO_COVERAGE |                             result.addError(); | 
| 57 |                             LOG.error("Problem while sending out {}", mailing, e); | |
| 58 |                         } | |
| 59 |                     }); | |
| 60 | ||
| 61 |                     LOG.info("**** MAILVERSENDALA-report: {} total mails ****", total); | |
| 62 |                     LOG.info("**** MAILVERSENDALA-report: {} successfully send out ****", result.getMailCounter().orElse(new AtomicInteger(0))); | |
| 63 |                     LOG.info("**** MAILVERSENDALA-report: {} errors ****", result.getErrorCounter().orElse(new AtomicInteger(0))); | |
| 64 |                 } | |
| 65 | ||
| 66 |             } else { | |
| 67 |                 LOG.warn("Nothing to do - please configure your CSV path properly, either as environment variable or as a runtime parameter. Example: java -Dcsvpath=foo -jar fatJar.jar"); | |
| 68 |             } | |
| 69 |         } | |
| 70 |         LOG.info("**** MAILVERSENDALA: Application shutdown .... ****"); | |
| 71 | 1
1. sendOut : replaced return value with null for de/aikiit/mailversendala/Mailversendala::sendOut → KILLED |         return result; | 
| 72 |     } | |
| 73 | } | |
| Mutations | ||
| 38 | 1.1 | |
| 42 | 1.1 | |
| 50 | 1.1 | |
| 52 | 1.1 | |
| 53 | 1.1 | |
| 56 | 1.1 | |
| 71 | 1.1 |