martinzink commented on code in PR #2186: URL: https://github.com/apache/nifi-minifi-cpp/pull/2186#discussion_r3636924852
########## minifi_rust/minifi_native/src/api/process_context.rs: ########## @@ -0,0 +1,151 @@ +// 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 +// +// https://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. + +use crate::StandardPropertyValidator::*; +use crate::api::RawControllerService; +use crate::api::component_definition_traits::ComponentIdentifier; +use crate::api::flow_file::FlowFile; +use crate::api::property::GetControllerService; +use crate::{ + ControllerServiceApi, ControllerServiceDefinition, EnableControllerService, GetProperty, + MinifiError, Property, +}; +use std::str::FromStr; +use std::time::Duration; + +pub trait ProcessContext { + type FlowFile: FlowFile; + + fn get_property( + &self, + property: &Property, + flow_file: Option<&Self::FlowFile>, + ) -> Result<Option<String>, MinifiError>; + + fn get_bool_property( + &self, + property: &Property, + flow_file: Option<&Self::FlowFile>, + ) -> Result<Option<bool>, MinifiError> { + if property.validator != BoolValidator { + return Err(MinifiError::validation_err(format!( + "to use get_bool_property {:?} must have BoolValidator", + property + ))); + } + + if let Some(property_val) = self.get_property(property, flow_file)? { + Ok(Some(bool::from_str(&property_val)?)) + } else { + Ok(None) + } + } + + fn get_duration_property( + &self, + property: &Property, + flow_file: Option<&Self::FlowFile>, + ) -> Result<Option<Duration>, MinifiError> { + if property.validator != TimePeriodValidator { + return Err(MinifiError::validation_err(format!( + "to use get_duration_property {:?} must have TimePeriodValidator", + property + ))); + } + + if let Some(property_val) = self.get_property(property, flow_file)? { + Ok(Some(humantime::parse_duration(property_val.as_str())?)) + } else { + Ok(None) + } + } + + fn get_size_property( + &self, + property: &Property, + flow_file: Option<&Self::FlowFile>, + ) -> Result<Option<u64>, MinifiError> { + if property.validator != DataSizeValidator { + return Err(MinifiError::validation_err(format!( + "to use get_size_property {:?} must have DataSizeValidator", + property + ))); + } + if let Some(property_val) = self.get_property(property, flow_file)? { + Ok(Some(byte_unit::Byte::from_str(&property_val)?.as_u64())) Review Comment: Good point, probably not. 👍 We should address this in a followup PR. -- 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]
