7 #include "fwActivities/IActivityValidator.hpp" 8 #include "fwActivities/IObjectValidator.hpp" 10 #include <fwData/Composite.hpp> 11 #include <fwData/Vector.hpp> 13 #include <fwDataCamp/getObject.hpp> 15 #include <fwMedData/ActivitySeries.hpp> 27 validation.first =
true;
28 validation.second =
"";
33 ::fwData::Composite::sptr composite = activity->getData();
44 validation.first =
false;
45 validation.second +=
"\n - The parameter '" + req.name +
"' is required but is not defined.";
47 else if (obj->getClassname() != req.
type)
49 validation.first =
false;
50 validation.second +=
"\n - The parameter '" + req.name +
"' must be a '" + req.
type +
"'.";
57 validation.first =
false;
58 validation.second +=
"\n - The parameter '" + req.name +
"' is not valid: " + val.second;
67 validation.first =
false;
68 validation.second +=
"\n - The parameter '" + req.name +
"' must be a Vector of '" + req.
type +
"'.";
72 unsigned int nbObj =
static_cast<unsigned int >(vector->size());
75 validation.first =
false;
76 validation.second +=
"\n - The parameter '" + req.name +
"' must contain at least " +
77 std::to_string(req.
minOccurs) +
" objects.";
81 validation.first =
false;
82 validation.second +=
"\n - The parameter '" + req.name +
"' must contain at most " +
83 std::to_string(req.
maxOccurs) +
" objects.";
88 for (::fwData::Object::sptr obj : *vector)
92 validation.first =
false;
93 validation.second +=
"\n - The parameter '" + req.name +
94 "' must contain valid objects of type '" + req.
type +
"'.";
97 if (obj->getClassname() != req.
type)
99 validation.first =
false;
100 validation.second +=
"\n - The parameter '" + req.name +
101 "' must contain only objects of type '" + req.
type +
"'.";
110 validation.first =
false;
111 validation.second +=
"\n - The parameter '" + req.name +
"' is not valid: " + val.second;
119 ::fwData::Composite::sptr currentComposite = composite->at<
::fwData::Composite >(req.name);
120 if (!currentComposite)
122 validation.first =
false;
123 validation.second +=
"\n - The parameter '" + req.name +
"' must be a Composite of '" +
128 unsigned int nbObj =
static_cast<unsigned int>(currentComposite->size());
131 validation.first =
false;
132 validation.second +=
"\n - The parameter '" + req.name +
"' must contain at least " +
133 std::to_string(req.
minOccurs) +
" objects.";
137 validation.first =
false;
138 validation.second +=
"\n - The parameter '" + req.name +
"' must contain at most " +
139 std::to_string(req.
minOccurs) +
" objects.";
145 for (
auto elt : *currentComposite)
147 std::string key = elt.first;
148 ::fwData::Object::sptr obj = elt.second;
150 bool keyIsFound =
false;
153 if (key == keyElt.key)
161 validation.first =
false;
162 validation.second +=
"\n - The parameter '" + req.name +
163 "' has an invalid key : '" + key +
"'.";
169 validation.first =
false;
170 validation.second +=
"\n - The parameter '" + req.name +
171 "' must contain valid objects of type '" + req.
type +
"'.";
175 else if (reqKey.path.empty() && obj->getClassname() != req.
type)
177 validation.first =
false;
178 validation.second +=
"\n - The parameter '" + req.name +
179 "' must contain only objects of type '" + req.
type +
"'.";
189 validation.first =
false;
190 validation.second +=
"\n - The parameter '" + req.name +
"' is not valid: " + val.second;
207 validation.first =
true;
208 validation.second =
"";
213 ::fwData::Composite::sptr composite = activity->getData();
217 for (
auto param : appConfigInfo.parameters)
219 if (param.isSeshat())
221 std::string path = param.by;
222 if (path.substr(0,1) ==
"!")
224 path.replace(0, 1,
"@");
226 ::fwData::Object::sptr obj = ::fwDataCamp::getObject(composite, path);
229 validation.first =
false;
230 validation.second +=
"\n - invalid sesh@ path : '" + path +
"'";
241 const std::string &validatorImpl)
const 244 validation.first =
true;
245 validation.second =
"";
247 if (validatorImpl.empty())
249 validation.first =
true;
250 validation.second =
"Validator implementation is empty, assuming it is valid.";
255 ::fwActivities::IValidator::sptr validator = ::fwActivities::validator::factory::New(validatorImpl);
256 ::fwActivities::IObjectValidator::sptr dataValidator = ::fwActivities::IObjectValidator::dynamicCast(validator);
260 validation.first =
false;
261 validation.second =
"Validator '" + validatorImpl +
"' cannot be instantiated";
265 validation = dataValidator->validate(
object);
std::pair< bool, std::string > ValidationType
Defines validation result of an activity. First element tells if the activity is validated or not by ...
Holds Activities configuration.
FWACTIVITIES_API ValidationType checkRequirements(const std::shared_ptr< const ::fwMedData::ActivitySeries > &activity) const
Checks if all the required data are present in the activity series.
unsigned int maxOccurs
minimum number of data required
static FWACTIVITIES_API Activities::sptr getDefault()
Return the default global instance of Activities.
FWACTIVITIES_API ValidationType checkObject(const std::shared_ptr< const ::fwData::Object > &object, const std::string &validatorImpl) const
Calls the object validator if it is defined.
std::string validator
parameter description
std::string type
parameter name
FWACTIVITIES_API ValidationType checkParameters(const std::shared_ptr< const ::fwMedData::ActivitySeries > &activity) const
Checks if all the activity's AppConfig parameters are valid.
This class defines a vector of objects.
KeyType keys
True if the data must be created if it is not present (only if minOccurs = 0 and maxOccurs = 1) ...
unsigned int minOccurs
Implementation of data validator.
Base class for each data object.
std::string container
parameter type (ie. fwMedData::ImageSeries)
Namespace containing activities data and builder.
This class defines a composite object.
bool create
maximum number of data required