/BatchSave.groovy Secret
Created
April 24, 2022 16:48
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