szaszm commented on a change in pull request #797:
URL: https://github.com/apache/nifi-minifi-cpp/pull/797#discussion_r441597164



##########
File path: libminifi/include/core/PropertyValue.h
##########
@@ -202,14 +196,50 @@ class PropertyValue : public state::response::ValueNode {
   auto operator=(const std::string &ref) -> typename std::enable_if<
   std::is_same<T, DataSizeValue >::value ||
   std::is_same<T, TimePeriodValue >::value, PropertyValue&>::type {
-    value_ = std::make_shared<T>(ref);
-    type_id = value_->getTypeIndex();
-    return *this;
+    validator_.clearValidationResult();
+    return WithAssignmentGuard(ref, [&] () -> PropertyValue& {
+      value_ = std::make_shared<T>(ref);
+      type_id = value_->getTypeIndex();
+      return *this;
+    });
+  }
+
+ private:
+  template<typename T>
+  T convertImpl(const char* const type_name) const {
+    if (!isValueUsable()) {
+      throw utils::InvalidValueException("Cannot convert invalid value");
+    }
+    T res;
+    if (value_->convertValue(res)) {
+      return res;
+    }
+    throw utils::ConversionException(std::string("Invalid conversion to ") + 
type_name + " for " + value_->getStringValue());
+  }

Review comment:
       This could use `core::getClassName<T>`. I would also make this public 
and encourage its use over the implicit conversion operators, with a long term 
goal of moving to explicit conversions.

##########
File path: libminifi/include/core/PropertyValue.h
##########
@@ -75,64 +77,52 @@ class PropertyValue : public state::response::ValueNode {
   }
 
   std::shared_ptr<PropertyValidator> getValidator() const {
-    return validator_;
+    return *validator_;
   }
 
   ValidationResult validate(const std::string &subject) const {
-    if (validator_) {
-      return validator_->validate(subject, getValue());
-    } else {
+    auto cachedResult = validator_.isValid();
+    if (cachedResult == CachedValueValidator::Result::SUCCESS) {
       return ValidationResult::Builder::createBuilder().isValid(true).build();
     }
+    if (cachedResult == CachedValueValidator::Result::FAILURE) {
+      return 
ValidationResult::Builder::createBuilder().withSubject(subject).withInput(getValue()->getStringValue()).isValid(false).build();
+    }
+    auto result = validator_->validate(subject, getValue());
+    validator_.setValidationResult(result.valid());
+    return result;

Review comment:
       This logic should move to `CachedValueValidator` and the caching 
behavior should be transparent IMO.




----------------------------------------------------------------
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]


Reply via email to