szaszm commented on a change in pull request #618: POC: MINIFICPP-985 -
Implement listvalidators
URL: https://github.com/apache/nifi-minifi-cpp/pull/618#discussion_r380234193
##########
File path: libminifi/include/core/PropertyValidation.h
##########
@@ -308,6 +288,66 @@ class TimePeriodValidator : public PropertyValidator {
}
};
+class RegexValidator : public PropertyValidator {
+ public:
+ explicit RegexValidator(const std::string& pattern)
+ : PropertyValidator("REGULAR_EXPRESSION_VALIDATOR"){
+ regex_ = utils::Regex(pattern);
+ }
+ ValidationResult validate(const std::string &subject, const
std::shared_ptr<minifi::state::response::Value> &input) const {
+ return validate(subject, input->getStringValue());
+ }
+
+ ValidationResult validate(const std::string &subject, const std::string
&input) const {
+ bool result = regex_.match(input);
+ return
ValidationResult::Builder::createBuilder().withSubject(subject).withInput(input).isValid(result).build();
+ }
+ private:
+ mutable utils::Regex regex_;
+};
+
+template <typename T, typename
std::enable_if<std::is_base_of<PropertyValidator, T>::value>::type* = nullptr>
+class ListValidator : public PropertyValidator{
+ public:
+ explicit ListValidator(T val)
+ : PropertyValidator("LIST_VALIDATOR"),
Review comment:
The name pattern of non-list validators in nifi seem to be <type>_VALIDATOR,
and the pattern of list validators seem to be <type>_LIST_VALIDATOR. [1]
I suggest cutting the _VALIDATOR suffix from the inner validator, replace it
with _LIST_VALIDATOR suffix and pass that to the base class ctor. I'd also
avoid making `getName()` virtual, since all the derived classes can already
specify their desired names through the base class ctor parameter, so making it
virtual would be a second customization point for the very same thing.
```
std::string replace_last(std::string str, const std::string& search, const
std::string& replacement) {
str.replace(str.find_last_of(search), search.size(), replacement);
return str;
}
template<typename T>
ListValidator<T>::ListValidator(T inner_validator)
:PropertyValidator{ replace_last(inner_validator.getName(),
"_VALIDATOR", "_LIST_VALIDATOR") },
[...]
```
[1]
https://github.com/apache/nifi/blob/master/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
----------------------------------------------------------------
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