Skip to content

Instantly share code, notes, and snippets.

@14paxton
Created April 24, 2022 16:48
Show Gist options
  • Save 14paxton/b7f8be4d37b29eb2d25e1a2e993f5bf4 to your computer and use it in GitHub Desktop.
Save 14paxton/b7f8be4d37b29eb2d25e1a2e993f5bf4 to your computer and use it in GitHub Desktop.
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