-
-
Save 14paxton/b7f8be4d37b29eb2d25e1a2e993f5bf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def updateCreateUserRoleGroups(User user, List<RoleGroup> roleGroupList) { | |
if (!user || !roleGroupList) return [] | |
def currentSession = sessionFactory.getCurrentSession() | |
def promiseMap = new PromiseMap() | |
roleGroupList.each { roleGroup -> | |
def exists = UserRoleGroup.exists(user.id as Long, roleGroup.id as Long) | |
promiseMap["${roleGroup.displayName.trim().toUpperCase().replaceAll(~/\s/, "_")}"] = { | |
if (!exists) { | |
UserRoleGroup.withNewTransaction { status -> | |
currentSession.save(new UserRoleGroup(user: user, roleGroup: roleGroup)) | |
} | |
} | |
} | |
} | |
promiseMap.onError { def error -> | |
log.error("error updating user role groups for user ${user?.id} , $error") | |
} | |
promiseMap.get() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment