martinzink commented on code in PR #1543:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1543#discussion_r1151516542


##########
libminifi/src/properties/Properties.cpp:
##########
@@ -62,6 +63,46 @@ int Properties::getInt(const std::string &key, int 
default_value) const {
   return it != properties_.end() ? std::stoi(it->second.active_value) : 
default_value;
 }
 
+namespace {
+void ensureTimePeriodValidatedPropertyHasExplicitUnit(const 
core::PropertyValidator* const validator, std::string& persisted_value, 
std::string& value, bool& need_to_persist_new_value) {
+  if (validator != core::StandardValidators::get().TIME_PERIOD_VALIDATOR.get())
+    return;
+  if (value.empty() || !std::all_of(value.begin(), value.end(), ::isdigit))
+    return;
+
+  value += " ms";
+  persisted_value = value;
+  need_to_persist_new_value = true;
+}
+
+bool integerValidatedProperty(const core::PropertyValidator* const validator) {
+  return validator == core::StandardValidators::get().INTEGER_VALIDATOR.get()
+      || validator == 
core::StandardValidators::get().UNSIGNED_INT_VALIDATOR.get()
+      || validator == core::StandardValidators::get().LONG_VALIDATOR.get()
+      || validator == 
core::StandardValidators::get().UNSIGNED_LONG_VALIDATOR.get();
+}
+
+void ensureIntegerValidatedPropertyHasNoUnit(const core::PropertyValidator* 
const validator, std::string& persisted_value, std::string& value, bool& 
need_to_persist_new_value) {
+  if (!integerValidatedProperty(validator))
+    return;
+
+  if (auto parsed_time = 
utils::timeutils::StringToDuration<std::chrono::milliseconds>(value)) {
+    value = fmt::format("{}", parsed_time->count());
+    persisted_value = value;
+    need_to_persist_new_value = true;
+  }
+}
+
+void formatConfigurationProperty(std::string_view key, std::string& 
persisted_value, std::string& value, bool& need_to_persist_new_value) {
+  auto configuration_property = 
Configuration::CONFIGURATION_PROPERTIES.find(key);
+  if (configuration_property == Configuration::CONFIGURATION_PROPERTIES.end())
+    return;
+
+  
ensureTimePeriodValidatedPropertyHasExplicitUnit(configuration_property->second,
 persisted_value, value, need_to_persist_new_value);
+  ensureIntegerValidatedPropertyHasNoUnit(configuration_property->second, 
persisted_value, value, need_to_persist_new_value);
+}
+}  // namespace
+

Review Comment:
   good idea, I've added an explanatory comment in 
https://github.com/apache/nifi-minifi-cpp/pull/1543/commits/ee61abd3c1c0efc9f2d460bd691f854f26e9a5aa#diff-f841426e292e70012a81b0fae92f08df7b13120e17b17a92fc360f2f50ec072fR157-R158



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

Reply via email to