public boolean setupAccount ( Entity e ) { AccountAttributes accountAttributes = new AccountAttributes ( ) ; // 0- reject entity having a composite PK. if ( e . hasCompositePk ( ) ) { return false ; } // 1- detect mandatory username for ( Attribute a : e . getAttributes ( ) . getList ( ) ) { if ( a . isString ( ) && match ( a . getVar ( ) , usernameCandidates ) && a . isUnique ( ) ) { accountAttributes . setUsername ( a ) ; log . debug ( "'Username' candidate: " + a . getVar ( ) + " found on " + e . getName ( ) ) ; break ; } } if ( ! accountAttributes . isUsernameSet ( ) ) { return false ; } // 2- detect mandatory password for ( Attribute a : e . getAttributes ( ) . getList ( ) ) { if ( a . isString ( ) && match ( a . getVar ( ) , passwordCandidates ) ) { accountAttributes . setPassword ( a ) ; log . debug ( "'Password' candidate: " + a . getVar ( ) + " found on " + e . getName ( ) ) ; break ; } } if ( ! accountAttributes . isPasswordSet ( ) ) { return false ; } // from here we have at least an account. e . setAccountAttributes ( accountAttributes ) ; // 3- detect optional email for ( Attribute a : e . getAttributes ( ) . getList ( ) ) { if ( a . isString ( ) && match ( a . getVar ( ) , emailCandidates ) ) { accountAttributes . setEmail ( a ) ; log . debug ( "'Email' candidate: " + a . getVar ( ) + " found on " + e . getName ( ) ) ; break ; } } // 4- detect optional enabled for ( Attribute a : e . getAttributes ( ) . getList ( ) ) { if ( a . isBoolean ( ) && match ( a . getVar ( ) , enabledCandidates ) ) { accountAttributes . setEnabled ( a ) ; log . debug ( "'Enabled' candidate: " + a . getVar ( ) + " found on " + e . getName ( ) ) ; break ; } } // 5- detect Role relation for ( Relation relation : e . getXToMany ( ) . getList ( ) ) { RoleAttributes roleAttributes = getRoleEntity ( relation . getToEntity ( ) ) ; if ( roleAttributes != null ) { relation . getToEntity ( ) . setRoleAttributes ( roleAttributes ) ; accountAttributes . setRoleRelation ( relation ) ; log . debug ( "'Role' relation detected: " + relation . toString ( ) ) ; break ; } } return true ; }
Is this entity the account entity?