emiliosetiadarma commented on code in PR #6204:
URL: https://github.com/apache/nifi/pull/6204#discussion_r921705995
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutEmail.java:
##########
@@ -523,4 +555,57 @@ private InternetAddress[] toInetAddresses(final
ProcessContext context, final Fl
protected void send(final Message msg) throws MessagingException {
Transport.send(msg);
}
+
+ /**
+ * Utility function to return a Map of optional {@code mail._____}
properties that were set dynamically.
+ * @param context the ProcessContext
+ * @return a Map with optional {@code mail._____} properties
+ */
+ private Map<String, String> getDynamicMailProperties(final ProcessContext
context) {
+ final Map<String, String> dynamicMailProperties = new HashMap<>();
+
+ for (final Map.Entry<PropertyDescriptor, String> entry:
context.getProperties().entrySet()) {
+ final PropertyDescriptor descriptor = entry.getKey();
+ if (descriptor.isDynamic()) {
+ final String name = descriptor.getName();
+ final Matcher matcher = MAIL_PROPERTY_PATTERN.matcher(name);
+ if (matcher.matches()) {
+ dynamicMailProperties.put(name, entry.getValue());
+ }
+ }
+ }
+
+ return dynamicMailProperties;
+ }
+
+ private static class DynamicMailPropertyValidator implements Validator {
+ @Override
+ public ValidationResult validate(String subject, String input,
ValidationContext context) {
+ final Matcher matcher = MAIL_PROPERTY_PATTERN.matcher(subject);
+ if (!matcher.matches()) {
+ return new ValidationResult.Builder()
+ .input(input)
+ .subject(subject)
+ .valid(false)
+ .explanation(String.format("[%s] is an invalid
mail._____ property", subject))
+ .build();
+ }
+
+ if (propertyToContext.containsKey(subject)) {
+ return new ValidationResult.Builder()
+ .input(input)
+ .subject(subject)
+ .valid(false)
+ .explanation(String.format("[%s] overwrites required
existing properties", subject))
+ .build();
+ }
+
+ return new ValidationResult.Builder()
+ .subject(subject)
+ .input(input)
+ .valid(true)
+ .explanation("Valid mail._____ property that does not
overwrite existing required properties")
Review Comment:
Making the changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]