CatapultServer  v0.5.0.1 (Elephant)
AggregateValidatorBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "ValidatorTypes.h"
25 #include <vector>
26 
27 namespace catapult { namespace validators {
28 
30  template<typename TNotification, typename... TArgs>
32  private:
33  using NotificationValidatorPointer = std::unique_ptr<const NotificationValidatorT<TNotification, TArgs...>>;
34  using NotificationValidatorPointerVector = std::vector<NotificationValidatorPointer>;
35  using AggregateValidatorPointer = std::unique_ptr<const AggregateNotificationValidatorT<TNotification, TArgs...>>;
36 
37  public:
40  m_validators.push_back(std::move(pValidator));
41  return *this;
42  }
43 
46  return std::make_unique<DefaultAggregateNotificationValidator>(std::move(m_validators), isSuppressedFailure);
47  }
48 
49  private:
51  public:
54  const ValidationResultPredicate& isSuppressedFailure)
55  : m_validators(std::move(validators))
56  , m_isSuppressedFailure(isSuppressedFailure)
57  , m_name(utils::ReduceNames(utils::ExtractNames(m_validators)))
58  {}
59 
60  public:
61  const std::string& name() const override {
62  return m_name;
63  }
64 
65  std::vector<std::string> names() const override {
67  }
68 
69  ValidationResult validate(const TNotification& notification, TArgs&&... args) const override {
70  auto aggregateResult = ValidationResult::Success;
71  for (const auto& pValidator : m_validators) {
72  auto result = pValidator->validate(notification, std::forward<TArgs>(args)...);
73 
74  // ignore suppressed failures
75  if (m_isSuppressedFailure(result))
76  continue;
77 
78  // exit on other failures
79  if (IsValidationResultFailure(result))
80  return result;
81 
82  AggregateValidationResult(aggregateResult, result);
83  }
84 
85  return aggregateResult;
86  }
87 
88  private:
91  std::string m_name;
92  };
93 
94  private:
96  };
97 }}
catapult::validators::AggregateValidatorBuilder::add
AggregateValidatorBuilder & add(NotificationValidatorPointer &&pValidator)
Adds pValidator to the builder and allows chaining.
Definition: AggregateValidatorBuilder.h:39
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator::m_validators
NotificationValidatorPointerVector m_validators
Definition: AggregateValidatorBuilder.h:89
catapult::utils::ExtractNames
std::vector< std::string > ExtractNames(const TNamedObjects &namedObjects)
Extracts all names from namedObjects.
Definition: NamedObject.h:46
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator::m_isSuppressedFailure
ValidationResultPredicate m_isSuppressedFailure
Definition: AggregateValidatorBuilder.h:90
catapult::validators::AggregateValidatorBuilder< catapult::model::Notification, TArgs... >::AggregateValidatorPointer
std::unique_ptr< const AggregateNotificationValidatorT< catapult::model::Notification, TArgs... > > AggregateValidatorPointer
Definition: AggregateValidatorBuilder.h:35
catapult::validators::NotificationValidatorT
A strongly typed notification validator.
Definition: NotificationValidator.h:30
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator::m_name
std::string m_name
Definition: AggregateValidatorBuilder.h:91
catapult::validators::ValidationResult
ValidationResult
Enumeration of all possible validation results.
Definition: ValidationResult.h:51
catapult::utils::ReduceNames
std::string ReduceNames(const std::vector< std::string > &names)
Reduces names into a single string.
Definition: NamedObject.h:56
catapult::validators::AggregateValidatorBuilder::m_validators
NotificationValidatorPointerVector m_validators
Definition: AggregateValidatorBuilder.h:95
catapult::validators::AggregateValidatorBuilder::build
AggregateValidatorPointer build(const ValidationResultPredicate &isSuppressedFailure)
Builds a strongly typed notification validator that ignores suppressed failures according to isSuppre...
Definition: AggregateValidatorBuilder.h:45
catapult::validators::AggregateValidatorBuilder
A strongly typed aggregate notification validator builder.
Definition: AggregateValidatorBuilder.h:31
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator::name
const std::string & name() const override
Gets the validator name.
Definition: AggregateValidatorBuilder.h:61
catapult::validators::AggregateValidationResult
void AggregateValidationResult(std::atomic< ValidationResult > &aggregate, ValidationResult value)
Aggregates result into aggregate.
Definition: AggregateValidationResult.cpp:62
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator::validate
ValidationResult validate(const TNotification &notification, TArgs &&... args) const override
Validates a single notification with contextual information args.
Definition: AggregateValidatorBuilder.h:69
catapult::validators::AggregateNotificationValidatorT
A strongly typed aggregate notification validator.
Definition: AggregateNotificationValidator.h:29
AggregateValidationResult.h
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator::names
std::vector< std::string > names() const override
Gets the names of all sub validators.
Definition: AggregateValidatorBuilder.h:65
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator::DefaultAggregateNotificationValidator
DefaultAggregateNotificationValidator(NotificationValidatorPointerVector &&validators, const ValidationResultPredicate &isSuppressedFailure)
Definition: AggregateValidatorBuilder.h:52
NamedObject.h
catapult::validators::AggregateValidatorBuilder::DefaultAggregateNotificationValidator
Definition: AggregateValidatorBuilder.h:50
catapult::validators::ValidationResultPredicate
predicate< ValidationResult > ValidationResultPredicate
Validation result predicate.
Definition: ValidatorTypes.h:42
ValidatorTypes.h
catapult::validators::ValidationResult::Success
Validation succeeded.
catapult::validators::AggregateValidatorBuilder< catapult::model::Notification, TArgs... >::NotificationValidatorPointerVector
std::vector< NotificationValidatorPointer > NotificationValidatorPointerVector
Definition: AggregateValidatorBuilder.h:34
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::validators::IsValidationResultFailure
constexpr bool IsValidationResultFailure(ValidationResult result)
Returns a value indicating whether the validation result is a failure.
Definition: ValidationResult.h:95
catapult::validators::AggregateValidatorBuilder< catapult::model::Notification, TArgs... >::NotificationValidatorPointer
std::unique_ptr< const NotificationValidatorT< catapult::model::Notification, TArgs... > > NotificationValidatorPointer
Definition: AggregateValidatorBuilder.h:33