martinzink commented on code in PR #1926:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1926#discussion_r2001012822
##########
minifi-api/include/minifi-cpp/core/Property.h:
##########
@@ -53,158 +47,67 @@ class Property {
Property();
- Property(const PropertyReference&);
+ Property(const PropertyReference &);
virtual ~Property() = default;
- void setTransient() {
- is_transient_ = true;
- }
+ void setTransient() { is_transient_ = true; }
- bool isTransient() const {
- return is_transient_;
- }
+ bool isTransient() const { return is_transient_; }
+ std::vector<std::string> getAllowedValues() const { return allowed_values_; }
+ void setAllowedValues(std::vector<std::string> allowed_values) {
allowed_values_ = std::move(allowed_values); }
+ std::optional<std::string> getDefaultValue() const { return default_value_; }
std::string getName() const;
std::string getDisplayName() const;
std::vector<std::string> getAllowedTypes() const;
std::string getDescription() const;
const PropertyValidator& getValidator() const;
- const PropertyValue &getValue() const;
+ [[nodiscard]] nonstd::expected<std::span<const std::string>,
std::error_code> getAllValues() const;
+ [[nodiscard]] nonstd::expected<std::string_view, std::error_code> getValue()
const;
+ nonstd::expected<void, std::error_code> setValue(std::string value);
+ nonstd::expected<void, std::error_code> appendValue(std::string value);
+ void clearValues();
bool getRequired() const;
bool isSensitive() const;
bool supportsExpressionLanguage() const;
std::vector<std::string> getDependentProperties() const;
std::vector<std::pair<std::string, std::string>> getExclusiveOfProperties()
const;
std::vector<std::string> getValues();
-
- const PropertyValue &getDefaultValue() const {
- return default_value_;
- }
-
- template<typename T = std::string>
- void setValue(const T &value) {
- if (!is_collection_) {
- values_.clear();
- values_.push_back(default_value_);
- } else {
- values_.push_back(default_value_);
- }
- PropertyValue& vn = values_.back();
- vn.setValidator(*validator_);
- vn = value;
- ValidationResult result = vn.validate(name_);
- if (!result.valid) {
- throw utils::internal::InvalidValueException(name_ + " value validation
failed");
- }
+ PropertyReference getReference() const {
+ return PropertyReference(name_, display_name_, description_, is_required_,
is_sensitive_, {}, {}, {}, {}, default_value_, validator_, supports_el_);
Review Comment:
yeah you are right,
https://github.com/apache/nifi-minifi-cpp/commit/e8af0c0f984d301c4958afed19e91563722d95e1
##########
utils/src/core/ConfigurableComponentImpl.cpp:
##########
@@ -0,0 +1,149 @@
+/**
+ *
+ * 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.
+ */
+
+#include "core/ConfigurableComponentImpl.h"
+
+#include "minifi-cpp/core/Property.h"
+#include "utils/PropertyErrors.h"
+
+namespace org::apache::nifi::minifi::core {
+void ConfigurableComponentImpl::setSupportedProperties(std::span<const
core::PropertyReference> properties) {
+ if (!canEdit()) { return; }
+
+ std::lock_guard<std::mutex> lock(configuration_mutex_);
+
+ supported_properties_.clear();
+ for (const auto& item: properties) {
supported_properties_.emplace(item.name, item); }
+}
+
+nonstd::expected<std::string, std::error_code>
ConfigurableComponentImpl::getProperty(const std::string_view name) const {
+ const std::lock_guard<std::mutex> lock(configuration_mutex_);
+ const auto it = supported_properties_.find(name);
+ if (it == supported_properties_.end()) { return
nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty); }
+ const Property& prop = it->second;
+ return prop.getValue() | utils::transform([](const std::string_view
value_view) -> std::string { return std::string{value_view}; });
+}
+
+nonstd::expected<void, std::error_code>
ConfigurableComponentImpl::setProperty(const std::string_view name, std::string
value) {
+ const std::lock_guard<std::mutex> lock(configuration_mutex_);
+ const auto it = supported_properties_.find(name);
+ if (it == supported_properties_.end()) { return
nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty); }
+ Property& prop = it->second;
+
+ return prop.setValue(std::move(value));
+}
+
+nonstd::expected<void, std::error_code>
ConfigurableComponentImpl::clearProperty(const std::string_view name) {
+ const std::lock_guard<std::mutex> lock(configuration_mutex_);
+ const auto it = supported_properties_.find(name);
+ if (it == supported_properties_.end()) { return
nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty); }
+ Property& prop = it->second;
+
+ prop.clearValues();
+ return {};
+}
+
+nonstd::expected<void, std::error_code>
ConfigurableComponentImpl::appendProperty(const std::string_view name,
std::string value) {
+ const std::lock_guard<std::mutex> lock(configuration_mutex_);
+ const auto it = supported_properties_.find(name);
+ if (it == supported_properties_.end()) { return
nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty); }
+ Property& prop = it->second;
+
+ return prop.appendValue(std::move(value));
+}
+
+nonstd::expected<std::string, std::error_code>
ConfigurableComponentImpl::getDynamicProperty(const std::string_view name)
const {
+ const std::lock_guard<std::mutex> lock(configuration_mutex_);
+ if (!supportsDynamicProperties()) {
+ return
nonstd::make_unexpected(PropertyErrorCode::DynamicPropertiesNotSupported);
+ }
+ const auto it = dynamic_properties_.find(name);
+ if (it == dynamic_properties_.end()) { return
nonstd::make_unexpected(PropertyErrorCode::PropertyNotSet); }
+ const Property& prop = it->second;
+ return prop.getValue() | utils::transform([](const std::string_view
value_view) -> std::string { return std::string{value_view}; });
+}
+
+nonstd::expected<void, std::error_code>
ConfigurableComponentImpl::setDynamicProperty(std::string name, std::string
value) {
+ const std::lock_guard<std::mutex> lock(configuration_mutex_);
+ if (!supportsDynamicProperties()) {
+ return
nonstd::make_unexpected(PropertyErrorCode::DynamicPropertiesNotSupported);
+ }
+ Property& prop = dynamic_properties_[std::move(name)];
+ return prop.setValue(std::move(value));
+}
+
+nonstd::expected<void, std::error_code>
ConfigurableComponentImpl::appendDynamicProperty(const std::string_view name,
std::string value) {
+ const std::lock_guard<std::mutex> lock(configuration_mutex_);
+ if (!supportsDynamicProperties()) {
+ return
nonstd::make_unexpected(PropertyErrorCode::DynamicPropertiesNotSupported);
+ }
+ Property& prop = dynamic_properties_[std::string{name}];
+ return prop.appendValue(std::move(value));
+}
+
+std::vector<std::string> ConfigurableComponentImpl::getDynamicPropertyKeys()
const {
+ std::lock_guard<std::mutex> lock(configuration_mutex_);
+
+ return dynamic_properties_ | ranges::views::transform([](const auto& kv) {
return kv.first; }) | ranges::to<std::vector>();
+}
+
+std::map<std::string, std::string>
ConfigurableComponentImpl::getDynamicProperties() const {
+ std::lock_guard<std::mutex> lock(configuration_mutex_);
+ std::map<std::string, std::string> result;
+ for(const auto& [key,value]: dynamic_properties_) {
+ result[key] = value.getValue().value_or("");
+ }
+ return result;
+}
+
+nonstd::expected<PropertyReference, std::error_code>
ConfigurableComponentImpl::getPropertyReference(const std::string_view name)
const {
Review Comment:
sure thing
https://github.com/apache/nifi-minifi-cpp/commit/e8af0c0f984d301c4958afed19e91563722d95e1
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]