| 1 | package fr.sii.ogham.email.builder; | |
| 2 | ||
| 3 | import java.util.HashMap; | |
| 4 | import java.util.Map; | |
| 5 | ||
| 6 | import fr.sii.ogham.core.builder.Builder; | |
| 7 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper; | |
| 8 | import fr.sii.ogham.core.builder.context.BuildContext; | |
| 9 | import fr.sii.ogham.core.builder.env.EnvironmentBuilder; | |
| 10 | import fr.sii.ogham.core.filler.EveryFillerDecorator; | |
| 11 | import fr.sii.ogham.core.filler.MessageFiller; | |
| 12 | import fr.sii.ogham.core.fluent.AbstractParent; | |
| 13 | import fr.sii.ogham.email.filler.EmailFiller; | |
| 14 | import fr.sii.ogham.email.message.Email; | |
| 15 | ||
| 16 | /** | |
| 17 | * Configures how Ogham will add default values to the {@link Email} if some | |
| 18 | * information is missing. | |
| 19 | * | |
| 20 | * If sender address is missing, a default one can be defined in configuration | |
| 21 | * properties. | |
| 22 | * | |
| 23 | * If recipient address is missing, a default one can be defined in | |
| 24 | * configuration properties. | |
| 25 | * | |
| 26 | * If subject is missing, a default one can be defined either: | |
| 27 | * <ul> | |
| 28 | * <li>In HTML title</li> | |
| 29 | * <li>In first line of text template</li> | |
| 30 | * <li>Using a default value defined in configuration properties</li> | |
| 31 | * </ul> | |
| 32 | * | |
| 33 | * @author Aurélien Baudet | |
| 34 | * @see EmailFiller | |
| 35 | * | |
| 36 | */ | |
| 37 | public class AutofillEmailBuilder extends AbstractParent<EmailBuilder> implements Builder<MessageFiller> { | |
| 38 | private final BuildContext buildContext; | |
| 39 | private AutofillSubjectBuilder subjectBuilder; | |
| 40 | private AutofillDefaultEmailAddressBuilder<String> fromBuilder; | |
| 41 | private AutofillDefaultEmailAddressBuilder<String[]> toBuilder; | |
| 42 | private AutofillDefaultEmailAddressBuilder<String[]> ccBuilder; | |
| 43 | private AutofillDefaultEmailAddressBuilder<String[]> bccBuilder; | |
| 44 | ||
| 45 | /** | |
| 46 | * Initializes with the parent builder and the {@link EnvironmentBuilder}. | |
| 47 | * The parent builder is used when calling the {@link #and()} method. The | |
| 48 | * {@link EnvironmentBuilder} is used by {@link #build()} method to evaluate | |
| 49 | * property values. | |
| 50 | * | |
| 51 | * @param parent | |
| 52 | * the parent builder | |
| 53 | * @param buildContext | |
| 54 | * for property resolution | |
| 55 | */ | |
| 56 | public AutofillEmailBuilder(EmailBuilder parent, BuildContext buildContext) { | |
| 57 | super(parent); | |
| 58 | this.buildContext = buildContext; | |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * Configures how to handle missing {@link Email} subject: if no subject is | |
| 63 | * explicitly defined on the {@link Email}, Ogham will use the result of | |
| 64 | * this builder configuration to provide a default subject. | |
| 65 | * | |
| 66 | * Default subject can be provided by: | |
| 67 | * <ul> | |
| 68 | * <li>Using HTML {@code <title>} header tag as subject</li> | |
| 69 | * <li>Using first line text if prefixed</li> | |
| 70 | * <li>Using a property value</li> | |
| 71 | * </ul> | |
| 72 | * | |
| 73 | * | |
| 74 | * @return the builder to configure default subject handling | |
| 75 | */ | |
| 76 | public AutofillSubjectBuilder subject() { | |
| 77 |
1
1. subject : negated conditional → RUN_ERROR |
if (subjectBuilder == null) { |
| 78 | subjectBuilder = new AutofillSubjectBuilder(this, buildContext); | |
| 79 | } | |
| 80 |
1
1. subject : replaced return value with null for fr/sii/ogham/email/builder/AutofillEmailBuilder::subject → RUN_ERROR |
return subjectBuilder; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Configures how to handle missing {@link Email} sender address: if no | |
| 85 | * sender address is explicitly defined on the {@link Email}, Ogham will use | |
| 86 | * the result of this builder configuration to provide a default sender | |
| 87 | * address. | |
| 88 | * | |
| 89 | * @return the builder to configure default sender address handling | |
| 90 | */ | |
| 91 | public AutofillDefaultEmailAddressBuilder<String> from() { | |
| 92 |
1
1. from : negated conditional → RUN_ERROR |
if (fromBuilder == null) { |
| 93 | fromBuilder = new AutofillDefaultEmailAddressBuilder<>(this, String.class, buildContext); | |
| 94 | } | |
| 95 |
1
1. from : replaced return value with null for fr/sii/ogham/email/builder/AutofillEmailBuilder::from → RUN_ERROR |
return fromBuilder; |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Configures how to handle missing {@link Email} recipient address: if no | |
| 100 | * "to" address is explicitly defined on the {@link Email}, Ogham will use | |
| 101 | * the result of this builder configuration to provide a default "to" | |
| 102 | * address. | |
| 103 | * | |
| 104 | * @return the builder to configure default address handling | |
| 105 | */ | |
| 106 | public AutofillDefaultEmailAddressBuilder<String[]> to() { | |
| 107 |
1
1. to : negated conditional → RUN_ERROR |
if (toBuilder == null) { |
| 108 | toBuilder = new AutofillDefaultEmailAddressBuilder<>(this, String[].class, buildContext); | |
| 109 | } | |
| 110 |
1
1. to : replaced return value with null for fr/sii/ogham/email/builder/AutofillEmailBuilder::to → RUN_ERROR |
return toBuilder; |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * Configures how to handle missing {@link Email} recipient address: if no | |
| 115 | * "cc" address is explicitly defined on the {@link Email}, Ogham will use | |
| 116 | * the result of this builder configuration to provide a default "cc" | |
| 117 | * address. | |
| 118 | * | |
| 119 | * @return the builder to configure default address handling | |
| 120 | */ | |
| 121 | public AutofillDefaultEmailAddressBuilder<String[]> cc() { | |
| 122 |
1
1. cc : negated conditional → RUN_ERROR |
if (ccBuilder == null) { |
| 123 | ccBuilder = new AutofillDefaultEmailAddressBuilder<>(this, String[].class, buildContext); | |
| 124 | } | |
| 125 |
1
1. cc : replaced return value with null for fr/sii/ogham/email/builder/AutofillEmailBuilder::cc → RUN_ERROR |
return ccBuilder; |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * Configures how to handle missing {@link Email} recipient address: if no | |
| 130 | * "bcc" address is explicitly defined on the {@link Email}, Ogham will use | |
| 131 | * the result of this builder configuration to provide a default "bcc" | |
| 132 | * address. | |
| 133 | * | |
| 134 | * @return the builder to configure default address handling | |
| 135 | */ | |
| 136 | public AutofillDefaultEmailAddressBuilder<String[]> bcc() { | |
| 137 |
1
1. bcc : negated conditional → RUN_ERROR |
if (bccBuilder == null) { |
| 138 | bccBuilder = new AutofillDefaultEmailAddressBuilder<>(this, String[].class, buildContext); | |
| 139 | } | |
| 140 |
1
1. bcc : replaced return value with null for fr/sii/ogham/email/builder/AutofillEmailBuilder::bcc → RUN_ERROR |
return bccBuilder; |
| 141 | } | |
| 142 | ||
| 143 | @Override | |
| 144 | public MessageFiller build() { | |
| 145 | EveryFillerDecorator filler = buildContext.register(new EveryFillerDecorator()); | |
| 146 |
1
1. build : negated conditional → RUN_ERROR |
if (subjectBuilder != null) { |
| 147 | filler.addFiller(subjectBuilder.build()); | |
| 148 | } | |
| 149 | filler.addFiller(buildContext.register(new EmailFiller(buildDefaultValueProps()))); | |
| 150 |
1
1. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillEmailBuilder::build → RUN_ERROR |
return filler; |
| 151 | } | |
| 152 | ||
| 153 | private Map<String, ConfigurationValueBuilderHelper<?, ?>> buildDefaultValueProps() { | |
| 154 | Map<String, ConfigurationValueBuilderHelper<?, ?>> props = new HashMap<>(); | |
| 155 |
1
1. buildDefaultValueProps : negated conditional → RUN_ERROR |
if (subjectBuilder != null) { |
| 156 | props.put("subject", (ConfigurationValueBuilderHelper<?, String>) subjectBuilder.defaultValue()); | |
| 157 | } | |
| 158 |
1
1. buildDefaultValueProps : negated conditional → RUN_ERROR |
if (fromBuilder != null) { |
| 159 | props.put("from", (ConfigurationValueBuilderHelper<?, String>) fromBuilder.defaultValue()); | |
| 160 | } | |
| 161 |
1
1. buildDefaultValueProps : negated conditional → RUN_ERROR |
if (toBuilder != null) { |
| 162 | props.put("to", (ConfigurationValueBuilderHelper<?, String[]>) toBuilder.defaultValue()); | |
| 163 | } | |
| 164 |
1
1. buildDefaultValueProps : negated conditional → RUN_ERROR |
if (ccBuilder != null) { |
| 165 | props.put("cc", (ConfigurationValueBuilderHelper<?, String[]>) ccBuilder.defaultValue()); | |
| 166 | } | |
| 167 |
1
1. buildDefaultValueProps : negated conditional → RUN_ERROR |
if (bccBuilder != null) { |
| 168 | props.put("bcc", (ConfigurationValueBuilderHelper<?, String[]>) bccBuilder.defaultValue()); | |
| 169 | } | |
| 170 |
1
1. buildDefaultValueProps : replaced return value with Collections.emptyMap for fr/sii/ogham/email/builder/AutofillEmailBuilder::buildDefaultValueProps → RUN_ERROR |
return props; |
| 171 | } | |
| 172 | } | |
Mutations | ||
| 77 |
1.1 |
|
| 80 |
1.1 |
|
| 92 |
1.1 |
|
| 95 |
1.1 |
|
| 107 |
1.1 |
|
| 110 |
1.1 |
|
| 122 |
1.1 |
|
| 125 |
1.1 |
|
| 137 |
1.1 |
|
| 140 |
1.1 |
|
| 146 |
1.1 |
|
| 150 |
1.1 |
|
| 155 |
1.1 |
|
| 158 |
1.1 |
|
| 161 |
1.1 |
|
| 164 |
1.1 |
|
| 167 |
1.1 |
|
| 170 |
1.1 |