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:
declare own annotation using '@constraint'
@target({elementtype.type}) @retention(retentionpolicy.runtime)
@constraint(validatedby=bankdataexpirationvalidator.class) public @interface bankdataexpiration {implement validation logic implementing
constraintvalidator
interface e.g.bankdataexpirationvalidator
then annotate
users
class above created annotation,@bankdataexpiration
you can create different kinds of validators way , map domain objects.
Comments
Post a Comment