java - Buissness validation logic -


is there nice solution validate domains after changing?

for example: in our buisiness case got users domain object. userglobal has expiration timeframe (activefrom , activeto). when admin changing timeframe needs check serval other domains bankdataexpiration timeframes, contract timeframes etc.... today use big ugly block checks in 1 class.

some pseudo code:

public class usersservice {     public void onuserchange(users users) {          checkcontracts();         checkbankdata();         // other validation checks....     } } 

after whole ugly check thing, possible data should change automatically. example of timeframes cut.

but of hurts "single responsibility principle" , unreadable , unmaintainable. there nice , clever solution out there, didn't find yet?

we thought interface checking , validation autowired via spring beans. got trouble hibernates session handling. changed reletad data in session error apeard, user changed data , tries revalidate it. validation passes , changed objects comitted too.

i hope question not general :s

you can create own custom validators. follow below steps:

  1. declare own annotation using '@constraint'

    @target({elementtype.type}) @retention(retentionpolicy.runtime)
    @constraint(validatedby=bankdataexpirationvalidator.class) public @interface bankdataexpiration {

  2. implement validation logic implementing constraintvalidator interface e.g. bankdataexpirationvalidator

  3. then annotate users class above created annotation, @bankdataexpiration

you can create different kinds of validators way , map domain objects.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -