use of org.jaffa.rules.fieldvalidators.ValidatorFactory in project jaffa-framework by jaffa-projects.
the class PersistentConfigValidatorTest method setup.
/**
* Common setup
*
* @throws Exception
*/
@Before
public void setup() throws Exception {
// create app context, do not need to include PersistentContext directly
AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext(JaffaRulesConfig.class, TestModelPersistentConfig.class);
assertNotNull(appContext);
new StaticContext().setApplicationContext(appContext);
// get validator factory bean from combined app context
ValidatorFactory target = appContext.getBean(ValidatorFactory.class);
assertNotNull(target);
Realm realm = new Realm("realm");
realm.setSource("Test");
realm.regex(TestModelPersistent.class.getName());
realm.register();
ClassMetaData classMetaData = new ClassMetaData();
classMetaData.setName(TestModelPersistent.class.getName());
classMetaData.setVariation("DEF");
classMetaData.setExecutionRealm(realm.getName());
classMetaData.register();
}
use of org.jaffa.rules.fieldvalidators.ValidatorFactory in project jaffa-framework by jaffa-projects.
the class PersistentConfig method persistent.
/**
* Initializes the passed in object
*
* @param persistent the object to initialize
* @return the initialized object
*/
protected <T extends Persistent> T persistent(T persistent) throws FrameworkException, ApplicationExceptions {
if (appContext != null && persistent != null) {
// Add validations for the persistent object
ValidatorFactory validatorFactory = (ValidatorFactory) appContext.getBean("ruleValidatorFactory");
if (validatorFactory != null) {
persistent.setValidator(validatorFactory.getValidator(persistent));
}
// register lifecycle handlers
registerLifecycleHandlers(persistent);
}
return persistent;
}
Aggregations