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



##########
File path: libminifi/include/core/CachedValueValidator.h
##########
@@ -0,0 +1,129 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LIBMINIFI_INCLUDE_CORE_CACHEDVALUEVALIDATOR_H_
+#define LIBMINIFI_INCLUDE_CORE_CACHEDVALUEVALIDATOR_H_
+
+#include <utility>
+#include <memory>
+#include <string>
+#include "PropertyValidation.h"
+#include "state/Value.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+
+class PropertyValue;
+
+namespace internal {
+
+class CachedValueValidator {
+  friend class core::PropertyValue;
+
+ public:
+  enum class Result {
+    FAILURE,
+    SUCCESS,
+    RECOMPUTE
+  };
+
+  CachedValueValidator() = default;
+
+  CachedValueValidator(const CachedValueValidator& other) : 
validator_(other.validator_) {}
+
+  CachedValueValidator(CachedValueValidator&& other) noexcept : 
validator_(std::move(other.validator_)) {}
+
+  CachedValueValidator& operator=(const CachedValueValidator& other) {
+    if (this == &other) {
+      return *this;
+    }
+    validator_ = other.validator_;
+    validation_result_ = Result::RECOMPUTE;
+    return *this;
+  }
+
+  CachedValueValidator& operator=(CachedValueValidator&& other) {
+    if (this == &other) {
+      return *this;
+    }
+    validator_ = std::move(other.validator_);
+    validation_result_ = Result::RECOMPUTE;
+    return *this;
+  }
+
+  explicit CachedValueValidator(const std::shared_ptr<PropertyValidator>& 
other) : validator_(other) {}
+
+  explicit CachedValueValidator(std::shared_ptr<PropertyValidator>&& other) : 
validator_(std::move(other)) {}
+
+  CachedValueValidator& operator=(const std::shared_ptr<PropertyValidator>& 
new_validator) {
+    validator_ = new_validator;
+    validation_result_ = Result::RECOMPUTE;
+    return *this;
+  }
+
+  CachedValueValidator& operator=(std::shared_ptr<PropertyValidator>&& 
new_validator) {
+    validator_ = std::move(new_validator);
+    validation_result_ = Result::RECOMPUTE;

Review comment:
       done

##########
File path: libminifi/include/core/ConfigurableComponent.h
##########
@@ -215,18 +215,23 @@ bool ConfigurableComponent::getProperty(const std::string 
name, T &value) const
 
   auto &&it = properties_.find(name);
   if (it != properties_.end()) {
-     Property item = it->second;
-     value = static_cast<T>(item.getValue());
-     if (item.getValue().getValue() != nullptr) {
-       logger_->log_debug("Component %s property name %s value %s", name, 
item.getName(), item.getValue().to_string());
-       return true;
-     } else {
-       logger_->log_warn("Component %s property name %s, empty value", name, 
item.getName());
-       return false;
-     }
+    const Property& item = it->second;
+    if (item.getValue().getValue() == nullptr) {
+      // empty value
+      if (item.getRequired()) {
+        logger_->log_debug("Component %s required property %s is empty", name, 
item.getName());
+        throw utils::internal::RequiredPropertyMissingException("Required 
property is empty: " + item.getName());
+      }
+      logger_->log_warn("Component %s property name %s, empty value", name, 
item.getName());

Review comment:
       done

##########
File path: libminifi/include/core/ConfigurableComponent.h
##########
@@ -215,18 +215,23 @@ bool ConfigurableComponent::getProperty(const std::string 
name, T &value) const
 
   auto &&it = properties_.find(name);
   if (it != properties_.end()) {
-     Property item = it->second;
-     value = static_cast<T>(item.getValue());
-     if (item.getValue().getValue() != nullptr) {
-       logger_->log_debug("Component %s property name %s value %s", name, 
item.getName(), item.getValue().to_string());
-       return true;
-     } else {
-       logger_->log_warn("Component %s property name %s, empty value", name, 
item.getName());
-       return false;
-     }
+    const Property& item = it->second;
+    if (item.getValue().getValue() == nullptr) {
+      // empty value
+      if (item.getRequired()) {
+        logger_->log_debug("Component %s required property %s is empty", name, 
item.getName());
+        throw utils::internal::RequiredPropertyMissingException("Required 
property is empty: " + item.getName());

Review comment:
       logging error instead




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to