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_r380245418
##########
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"),
+ inner_validator_(std::move(val)){
+ }
+ 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 {
+ const auto& tokens = utils::StringUtils::split(input, ",");
+ for(const auto& token: tokens) {
+ if(!inner_validator_.validate(subject, token).valid()){
+ return
ValidationResult::Builder::createBuilder().withSubject(subject).withInput(input).isValid(false).build();
+ }
+ }
+ return
ValidationResult::Builder::createBuilder().withSubject(subject).withInput(input).isValid(true).build();
+ }
+
+ private:
+ T inner_validator_;
+};
+
+class MultiChoiceValidator : PropertyValidator {
+ public:
+ explicit MultiChoiceValidator (const std::set<std::string>& choices)
+ : PropertyValidator("LIST_VALIDATOR"),
Review comment:
Is it OK for `MultiChoiceValidator` to have the same name as
`ListValidator<T>`? I couldn't find validator names referenced in minifi-c2, so
I don't know whether this causes problems with C2.
----------------------------------------------------------------
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