| 1 | package fr.sii.ogham.core.translator.resource; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.Arrays; | |
| 5 | import java.util.List; | |
| 6 | ||
| 7 | import org.slf4j.Logger; | |
| 8 | import org.slf4j.LoggerFactory; | |
| 9 | ||
| 10 | import fr.sii.ogham.core.resource.Resource; | |
| 11 | import fr.sii.ogham.email.exception.attachment.translator.ResourceTranslatorException; | |
| 12 | ||
| 13 | /** | |
| 14 | * Decorator that loop through all delegate translators to transform the | |
| 15 | * attachment resource of the message. Every translator will be called to update | |
| 16 | * the resource. Each translator receive the resource that may be updated by the | |
| 17 | * previous translator. | |
| 18 | * | |
| 19 | * @author Aurélien Baudet | |
| 20 | * | |
| 21 | */ | |
| 22 | public class EveryResourceTranslator implements AttachmentResourceTranslator { | |
| 23 | private static final Logger LOG = LoggerFactory.getLogger(EveryResourceTranslator.class); | |
| 24 | ||
| 25 | /** | |
| 26 | * The list of translators used to update the message content | |
| 27 | */ | |
| 28 | private List<AttachmentResourceTranslator> translators; | |
| 29 | ||
| 30 | /** | |
| 31 | * Initialize the decorator with none, one or several translator | |
| 32 | * implementations. The registration order may be important. | |
| 33 | * | |
| 34 | * @param translators | |
| 35 | * the translators to register | |
| 36 | */ | |
| 37 | public EveryResourceTranslator(AttachmentResourceTranslator... translators) { | |
| 38 | this(new ArrayList<>(Arrays.asList(translators))); | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * Initialize the decorator with the provided translator implementations. | |
| 43 | * The registration order may be important. | |
| 44 | * | |
| 45 | * @param translators | |
| 46 | * the translators to register | |
| 47 | */ | |
| 48 | public EveryResourceTranslator(List<AttachmentResourceTranslator> translators) { | |
| 49 | super(); | |
| 50 | this.translators = translators; | |
| 51 | } | |
| 52 | ||
| 53 | @Override | |
| 54 | public Resource translate(Resource resource) throws ResourceTranslatorException { | |
| 55 | Resource result = resource; | |
| 56 | for (AttachmentResourceTranslator translator : translators) { | |
| 57 | LOG.debug("Applying translator {} on resource {}", translator, resource); | |
| 58 | result = translator.translate(result); | |
| 59 | } | |
| 60 |
3
1. translate : replaced return value with null for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::translate → NO_COVERAGE 2. translate : replaced return value with null for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::translate → KILLED 3. translate : replaced return value with null for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::translate → KILLED |
return result; |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Register a new translator. The translator is added at the end. | |
| 65 | * | |
| 66 | * @param translator | |
| 67 | * the translator to register | |
| 68 | */ | |
| 69 | public void addTranslator(AttachmentResourceTranslator translator) { | |
| 70 | translators.add(translator); | |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Get the registered translators. | |
| 75 | * | |
| 76 | * @return the list of translators | |
| 77 | */ | |
| 78 | public List<AttachmentResourceTranslator> getTranslators() { | |
| 79 |
2
1. getTranslators : replaced return value with Collections.emptyList for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::getTranslators → SURVIVED 2. getTranslators : replaced return value with Collections.emptyList for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::getTranslators → NO_COVERAGE |
return translators; |
| 80 | } | |
| 81 | ||
| 82 | @Override | |
| 83 | public String toString() { | |
| 84 | StringBuilder builder = new StringBuilder(); | |
| 85 | builder.append("EveryResourceTranslator [translators=").append(translators).append("]"); | |
| 86 |
3
1. toString : replaced return value with "" for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::toString → NO_COVERAGE 2. toString : replaced return value with "" for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::toString → SURVIVED 3. toString : replaced return value with "" for fr/sii/ogham/core/translator/resource/EveryResourceTranslator::toString → TIMED_OUT |
return builder.toString(); |
| 87 | } | |
| 88 | } | |
Mutations | ||
| 60 |
1.1 2.2 3.3 |
|
| 79 |
1.1 2.2 |
|
| 86 |
1.1 2.2 3.3 |