1 | package fr.sii.ogham.email.builder; | |
2 | ||
3 | import fr.sii.ogham.core.builder.Builder; | |
4 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilder; | |
5 | import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper; | |
6 | import fr.sii.ogham.core.builder.configurer.Configurer; | |
7 | import fr.sii.ogham.core.builder.context.BuildContext; | |
8 | import fr.sii.ogham.core.builder.env.EnvironmentBuilder; | |
9 | import fr.sii.ogham.core.builder.filler.AbstractAutofillDefaultValueBuilder; | |
10 | import fr.sii.ogham.core.filler.MessageFiller; | |
11 | import fr.sii.ogham.core.filler.SubjectFiller; | |
12 | import fr.sii.ogham.core.subject.provider.FirstSupportingSubjectProvider; | |
13 | import fr.sii.ogham.core.subject.provider.HtmlTitleSubjectProvider; | |
14 | import fr.sii.ogham.core.subject.provider.MultiContentSubjectProvider; | |
15 | import fr.sii.ogham.core.subject.provider.SubjectProvider; | |
16 | import fr.sii.ogham.core.subject.provider.TextPrefixSubjectProvider; | |
17 | import fr.sii.ogham.email.message.Email; | |
18 | ||
19 | /** | |
20 | * Configures how to handle missing {@link Email} subject: if no subject is | |
21 | * explicitly defined on the {@link Email}, Ogham will use the result of this | |
22 | * builder configuration to provide a default subject. | |
23 | * | |
24 | * Default subject can be provided by: | |
25 | * <ul> | |
26 | * <li>Using HTML {@code <title>} header tag as subject</li> | |
27 | * <li>Using first line text if prefixed</li> | |
28 | * <li>Using a property value</li> | |
29 | * </ul> | |
30 | * | |
31 | * @author Aurélien Baudet | |
32 | * | |
33 | */ | |
34 | public class AutofillSubjectBuilder extends AbstractAutofillDefaultValueBuilder<AutofillSubjectBuilder, AutofillEmailBuilder, String> implements Builder<MessageFiller> { | |
35 | private final ConfigurationValueBuilderHelper<AutofillSubjectBuilder, Boolean> enableHtmlTitleValueBuilder; | |
36 | private final ConfigurationValueBuilderHelper<AutofillSubjectBuilder, String> firstLinePrefixValueBuilder; | |
37 | private SubjectProvider customProvider; | |
38 | ||
39 | /** | |
40 | * Initializes with the parent builder and the {@link EnvironmentBuilder}. | |
41 | * The parent builder is used when calling the {@link #and()} method. The | |
42 | * {@link EnvironmentBuilder} is used by {@link #build()} method to evaluate | |
43 | * property values. | |
44 | * | |
45 | * @param parent | |
46 | * the parent builder | |
47 | * @param buildContext | |
48 | * for property resolution | |
49 | */ | |
50 | public AutofillSubjectBuilder(AutofillEmailBuilder parent, BuildContext buildContext) { | |
51 | super(AutofillSubjectBuilder.class, parent, String.class, buildContext); | |
52 | enableHtmlTitleValueBuilder = buildContext.newConfigurationValueBuilder(myself, Boolean.class); | |
53 | firstLinePrefixValueBuilder = buildContext.newConfigurationValueBuilder(myself, String.class); | |
54 | } | |
55 | | |
56 | /** | |
57 | * Enable/disable using HTML {@code <title>} tag to provide a subject on the | |
58 | * {@link Email} if none was explicitly defined. | |
59 | * | |
60 | * <p> | |
61 | * The value set using this method takes precedence over any property and | |
62 | * default value configured using {@link #htmlTitle()}. | |
63 | * | |
64 | * <pre> | |
65 | * .htmlTitle(false) | |
66 | * .htmlTitle() | |
67 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
68 | * .defaultValue(true) | |
69 | * </pre> | |
70 | * | |
71 | * <pre> | |
72 | * .htmlTitle(false) | |
73 | * .htmlTitle() | |
74 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
75 | * .defaultValue(true) | |
76 | * </pre> | |
77 | * | |
78 | * In both cases, {@code htmlTitle(false)} is used. | |
79 | * | |
80 | * <p> | |
81 | * If this method is called several times, only the last value is used. | |
82 | * | |
83 | * <p> | |
84 | * If {@code null} value is set, it is like not setting a value at all. The | |
85 | * property/default value configuration is applied. | |
86 | * | |
87 | * @param enable | |
88 | * enable (true) or disable (false) extraction of HTML title to be used as subject of the email | |
89 | * @return this instance for fluent chaining | |
90 | */ | |
91 | public AutofillSubjectBuilder htmlTitle(Boolean enable) { | |
92 |
1
1. htmlTitle : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE |
enableHtmlTitleValueBuilder.setValue(enable); |
93 |
1
1. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → NO_COVERAGE |
return this; |
94 | } | |
95 | ||
96 | | |
97 | /** | |
98 | * Enable/disable using HTML {@code <title>} tag to provide a subject on the | |
99 | * {@link Email} if none was explicitly defined. | |
100 | * | |
101 | * <p> | |
102 | * This method is mainly used by {@link Configurer}s to register some property keys and/or a default value. | |
103 | * The aim is to let developer be able to externalize its configuration (using system properties, configuration file or anything else). | |
104 | * If the developer doesn't configure any value for the registered properties, the default value is used (if set). | |
105 | * | |
106 | * <pre> | |
107 | * .htmlTitle() | |
108 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
109 | * .defaultValue(true) | |
110 | * </pre> | |
111 | * | |
112 | * <p> | |
113 | * Non-null value set using {@link #htmlTitle(Boolean)} takes | |
114 | * precedence over property values and default value. | |
115 | * | |
116 | * <pre> | |
117 | * .htmlTitle(false) | |
118 | * .htmlTitle() | |
119 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
120 | * .defaultValue(true) | |
121 | * </pre> | |
122 | * | |
123 | * The value {@code false} is used regardless of the value of the properties | |
124 | * and default value. | |
125 | * | |
126 | * <p> | |
127 | * See {@link ConfigurationValueBuilder} for more information. | |
128 | * | |
129 | * | |
130 | * @return the builder to configure property keys/default value | |
131 | */ | |
132 | public ConfigurationValueBuilder<AutofillSubjectBuilder, Boolean> htmlTitle() { | |
133 |
8
1. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → NO_COVERAGE 2. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → KILLED 3. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → KILLED 4. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → KILLED 5. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → KILLED 6. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → KILLED 7. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → KILLED 8. htmlTitle : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::htmlTitle → KILLED |
return enableHtmlTitleValueBuilder; |
134 | } | |
135 | | |
136 | /** | |
137 | * Uses first line of text template to define the email subject (only if a | |
138 | * prefix is defined). | |
139 | * | |
140 | * <p> | |
141 | * The value set using this method takes precedence over any property and | |
142 | * default value configured using {@link #text()}. | |
143 | * | |
144 | * <pre> | |
145 | * .text("MyPrefix:") | |
146 | * .text() | |
147 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
148 | * .defaultValue("Subject:") | |
149 | * </pre> | |
150 | * | |
151 | * <pre> | |
152 | * .text("MyPrefix:") | |
153 | * .text() | |
154 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
155 | * .defaultValue("Subject:") | |
156 | * </pre> | |
157 | * | |
158 | * In both cases, {@code text("MyPrefix:")} is used. | |
159 | * | |
160 | * <p> | |
161 | * If this method is called several times, only the last value is used. | |
162 | * | |
163 | * <p> | |
164 | * If {@code null} value is set, it is like not setting a value at all. The | |
165 | * property/default value configuration is applied. | |
166 | * | |
167 | * @param firstLinePrefix | |
168 | * the prefix used to indicate that subject should be extracted | |
169 | * @return this instance for fluent chaining | |
170 | */ | |
171 | public AutofillSubjectBuilder text(String firstLinePrefix) { | |
172 |
1
1. text : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE |
firstLinePrefixValueBuilder.setValue(firstLinePrefix); |
173 |
1
1. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → NO_COVERAGE |
return this; |
174 | } | |
175 | ||
176 | | |
177 | /** | |
178 | * Uses first line of text template to define the email subject (only if a | |
179 | * prefix is defined). | |
180 | * | |
181 | * <p> | |
182 | * This method is mainly used by {@link Configurer}s to register some property keys and/or a default value. | |
183 | * The aim is to let developer be able to externalize its configuration (using system properties, configuration file or anything else). | |
184 | * If the developer doesn't configure any value for the registered properties, the default value is used (if set). | |
185 | * | |
186 | * <pre> | |
187 | * .text() | |
188 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
189 | * .defaultValue("Subject:") | |
190 | * </pre> | |
191 | * | |
192 | * <p> | |
193 | * Non-null value set using {@link #text(String)} takes | |
194 | * precedence over property values and default value. | |
195 | * | |
196 | * <pre> | |
197 | * .text("MyPrefix:") | |
198 | * .text() | |
199 | * .properties("${custom.property.high-priority}", "${custom.property.low-priority}") | |
200 | * .defaultValue("Subject:") | |
201 | * </pre> | |
202 | * | |
203 | * The value {@code "MyPrefix:"} is used regardless of the value of the properties | |
204 | * and default value. | |
205 | * | |
206 | * <p> | |
207 | * See {@link ConfigurationValueBuilder} for more information. | |
208 | * | |
209 | * | |
210 | * @return the builder to configure property keys/default value | |
211 | */ | |
212 | public ConfigurationValueBuilder<AutofillSubjectBuilder, String> text() { | |
213 |
8
1. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → NO_COVERAGE 2. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → KILLED 3. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → KILLED 4. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → KILLED 5. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → KILLED 6. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → KILLED 7. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → KILLED 8. text : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::text → KILLED |
return firstLinePrefixValueBuilder; |
214 | } | |
215 | ||
216 | /** | |
217 | * Extension point to provide any additional subject provider. See | |
218 | * {@link SubjectProvider} for more information. | |
219 | * | |
220 | * If defined, any previously defined configuration is not used. | |
221 | * | |
222 | * Only one provider can be defined. So you may need to register a | |
223 | * {@link FirstSupportingSubjectProvider} with the list of your custom | |
224 | * providers. | |
225 | * | |
226 | * @param provider | |
227 | * the provider to use | |
228 | * @return this instance for fluent chaining | |
229 | */ | |
230 | public AutofillSubjectBuilder provider(SubjectProvider provider) { | |
231 | customProvider = provider; | |
232 |
1
1. provider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::provider → NO_COVERAGE |
return myself; |
233 | } | |
234 | ||
235 | @Override | |
236 | public MessageFiller build() { | |
237 |
7
1. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::build → SURVIVED 2. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::build → NO_COVERAGE 3. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::build → KILLED 4. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::build → KILLED 5. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::build → KILLED 6. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::build → KILLED 7. build : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::build → KILLED |
return buildContext.register(new SubjectFiller(buildProvider())); |
238 | } | |
239 | ||
240 | private SubjectProvider buildProvider() { | |
241 |
6
1. buildProvider : negated conditional → NO_COVERAGE 2. buildProvider : negated conditional → SURVIVED 3. buildProvider : negated conditional → KILLED 4. buildProvider : negated conditional → KILLED 5. buildProvider : negated conditional → KILLED 6. buildProvider : negated conditional → KILLED |
if (customProvider != null) { |
242 |
1
1. buildProvider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::buildProvider → NO_COVERAGE |
return customProvider; |
243 | } | |
244 | FirstSupportingSubjectProvider provider = buildContext.register(new FirstSupportingSubjectProvider()); | |
245 | String prefix = firstLinePrefixValueBuilder.getValue(); | |
246 |
3
1. buildProvider : negated conditional → NO_COVERAGE 2. buildProvider : negated conditional → SURVIVED 3. buildProvider : negated conditional → KILLED |
if (prefix != null) { |
247 |
3
1. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → SURVIVED 2. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → NO_COVERAGE 3. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → KILLED |
provider.addProvider(buildContext.register(new TextPrefixSubjectProvider(prefix))); |
248 | } | |
249 | boolean htmlTitle = enableHtmlTitleValueBuilder.getValue(false); | |
250 |
3
1. buildProvider : negated conditional → SURVIVED 2. buildProvider : negated conditional → NO_COVERAGE 3. buildProvider : negated conditional → KILLED |
if (htmlTitle) { |
251 |
3
1. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → NO_COVERAGE 2. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → SURVIVED 3. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → KILLED |
provider.addProvider(buildContext.register(new HtmlTitleSubjectProvider())); |
252 | } | |
253 | SubjectProvider multiContentProvider = buildContext.register(new MultiContentSubjectProvider(provider)); | |
254 |
3
1. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → NO_COVERAGE 2. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → SURVIVED 3. buildProvider : removed call to fr/sii/ogham/core/subject/provider/FirstSupportingSubjectProvider::addProvider → KILLED |
provider.addProvider(multiContentProvider); |
255 |
6
1. buildProvider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::buildProvider → NO_COVERAGE 2. buildProvider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::buildProvider → SURVIVED 3. buildProvider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::buildProvider → KILLED 4. buildProvider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::buildProvider → KILLED 5. buildProvider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::buildProvider → KILLED 6. buildProvider : replaced return value with null for fr/sii/ogham/email/builder/AutofillSubjectBuilder::buildProvider → KILLED |
return provider; |
256 | } | |
257 | } | |
Mutations | ||
92 |
1.1 |
|
93 |
1.1 |
|
133 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
172 |
1.1 |
|
173 |
1.1 |
|
213 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
232 |
1.1 |
|
237 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
241 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
242 |
1.1 |
|
246 |
1.1 2.2 3.3 |
|
247 |
1.1 2.2 3.3 |
|
250 |
1.1 2.2 3.3 |
|
251 |
1.1 2.2 3.3 |
|
254 |
1.1 2.2 3.3 |
|
255 |
1.1 2.2 3.3 4.4 5.5 6.6 |