tpalfy commented on a change in pull request #4110: NIFI-7226: Add Connection
Factory configuration properties to Publish…
URL: https://github.com/apache/nifi/pull/4110#discussion_r388460868
##########
File path:
nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/processors/AbstractJMSProcessor.java
##########
@@ -291,4 +307,104 @@ protected void setClientId(ProcessContext context, final
SingleConnectionFactory
}
}
+ static class ConnectionFactoryConfigValidator {
+
+ private final ValidationContext validationContext;
+
+ private final PropertyValue connectionFactoryServiceProperty;
+ private final PropertyValue jndiInitialContextFactoryProperty;
+ private final PropertyValue jmsConnectionFactoryImplProperty;
+
+ ConnectionFactoryConfigValidator(ValidationContext validationContext) {
+ this.validationContext = validationContext;
+
+ connectionFactoryServiceProperty =
validationContext.getProperty(CF_SERVICE);
+ jndiInitialContextFactoryProperty =
validationContext.getProperty(JndiJmsConnectionFactoryProperties.JNDI_INITIAL_CONTEXT_FACTORY);
+ jmsConnectionFactoryImplProperty =
validationContext.getProperty(JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL);
+ }
+
+ List<ValidationResult> validateConnectionFactoryConfig() {
+ List<ValidationResult> results = new ArrayList<>();
+
+ if (!(connectionFactoryServiceProperty.isSet() ||
jndiInitialContextFactoryProperty.isSet() ||
jmsConnectionFactoryImplProperty.isSet())) {
+ results.add(new ValidationResult.Builder()
+ .subject("Connection Factory config")
+ .valid(false)
+ .explanation(String.format("either '%s', '%s' or '%s'
must be specified.", CF_SERVICE.getDisplayName(),
+
JndiJmsConnectionFactoryProperties.JNDI_INITIAL_CONTEXT_FACTORY.getDisplayName(),
JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL.getDisplayName()))
+ .build());
+ } else if (connectionFactoryServiceProperty.isSet()) {
+ if (hasLocalJndiJmsConnectionFactoryConfig()) {
+ results.add(new ValidationResult.Builder()
+ .subject("Connection Factory config")
+ .valid(false)
+ .explanation(String.format("cannot set both '%s'
and 'JNDI *' properties.", CF_SERVICE.getDisplayName()))
+ .build());
+ }
+ if (hasLocalJMSConnectionFactoryConfig()) {
+ results.add(new ValidationResult.Builder()
+ .subject("Connection Factory config")
+ .valid(false)
+ .explanation(String.format("cannot set both '%s'
and 'JMS *' properties.", CF_SERVICE.getDisplayName()))
+ .build());
+ }
+ } else if (hasLocalJndiJmsConnectionFactoryConfig() &&
hasLocalJMSConnectionFactoryConfig()) {
+ results.add(new ValidationResult.Builder()
+ .subject("Connection Factory config")
+ .valid(false)
+ .explanation("cannot set both 'JNDI *' and 'JMS *'
properties.")
+ .build());
+ } else if (jndiInitialContextFactoryProperty.isSet()) {
Review comment:
Some code duplication could be eliminated, like this?
```java
} else if (jndiInitialContextFactoryProperty.isSet()) {
validateLocalConnectionFactoryConfig(
results,
JndiJmsConnectionFactoryProperties.JNDI_INITIAL_CONTEXT_FACTORY,
JndiJmsConnectionFactoryProperties.getPropertyDescriptors()
);
} else if (jmsConnectionFactoryImplProperty.isSet()) {
validateLocalConnectionFactoryConfig(
results,
JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL,
JMSConnectionFactoryProperties.getPropertyDescriptors()
);
}
return results;
}
private boolean hasLocalJndiJmsConnectionFactoryConfig() {
return
hasLocalConnectionFactoryConfig(JndiJmsConnectionFactoryProperties.getPropertyDescriptors());
}
private boolean hasLocalJMSConnectionFactoryConfig() {
return
hasLocalConnectionFactoryConfig(JMSConnectionFactoryProperties.getPropertyDescriptors());
}
private boolean
hasLocalConnectionFactoryConfig(List<PropertyDescriptor>
localConnectionFactoryConfigProperties) {
for (PropertyDescriptor propertyDescriptor :
localConnectionFactoryConfigProperties) {
PropertyValue propertyValue =
validationContext.getProperty(propertyDescriptor);
if (propertyValue.isSet()) {
return true;
}
}
return false;
}
private void
validateLocalConnectionFactoryConfig(List<ValidationResult> results,
PropertyDescriptor indicatorProperty, List<PropertyDescriptor> allProperties) {
for (PropertyDescriptor propertyDescriptor : allProperties) {
if (propertyDescriptor.isRequired()) {
PropertyValue propertyValue =
validationContext.getProperty(propertyDescriptor);
if (!propertyValue.isSet()) {
results.add(new ValidationResult.Builder()
.subject("Connection Factory config")
.valid(false)
.explanation(String.format("'%s' must be
specified when '%s' has been configured.", propertyDescriptor.getDisplayName(),
indicatorProperty.getDisplayName()))
.build());
}
}
}
}
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services