public Result < Void > addUserRole ( AuthzTrans trans , UserRoleDAO . Data urData ) { Result < Void > rv ; if ( Question . ADMIN . equals ( urData . rname ) ) { rv = mayAddAdmin ( trans , urData . ns , urData . user ) ; } else if ( Question . OWNER . equals ( urData . rname ) ) { rv = mayAddOwner ( trans , urData . ns , urData . user ) ; } else { rv = checkValidID ( trans , new Date ( ) , urData . user ) ; } if ( rv . notOK ( ) ) { return rv ; } // Check if record exists if ( q . userRoleDAO . read ( trans , urData ) . isOKhasData ( ) ) { return Result . err ( Status . ERR_ConflictAlreadyExists , "User Role exists" ) ; } if ( q . roleDAO . read ( trans , urData . ns , urData . rname ) . notOKorIsEmpty ( ) ) { return Result . err ( Status . ERR_RoleNotFound , "Role [%s.%s] does not exist" , urData . ns , urData . rname ) ; } urData . expires = trans . org ( ) . expiration ( null , Expiration . UserInRole , urData . user ) . getTime ( ) ; Result < UserRoleDAO . Data > udr = q . userRoleDAO . create ( trans , urData ) ; switch ( udr . status ) { case OK : return Result . ok ( ) ; default : return Result . err ( udr ) ; } }
Add a User to Role