public void synchronizeUserOrganizationMembership ( DbSession dbSession , UserDto user , ALM alm , Set < String > organizationAlmIds ) { Set < String > userOrganizationUuids = dbClient . organizationMemberDao ( ) . selectOrganizationUuidsByUser ( dbSession , user . getId ( ) ) ; Set < String > userOrganizationUuidsWithMembersSyncEnabled = dbClient . organizationAlmBindingDao ( ) . selectByOrganizationUuids ( dbSession , userOrganizationUuids ) . stream ( ) . filter ( OrganizationAlmBindingDto :: isMembersSyncEnable ) . map ( OrganizationAlmBindingDto :: getOrganizationUuid ) . collect ( toSet ( ) ) ; Set < String > almOrganizationUuidsWithMembersSyncEnabled = dbClient . organizationAlmBindingDao ( ) . selectByOrganizationAlmIds ( dbSession , alm , organizationAlmIds ) . stream ( ) . filter ( OrganizationAlmBindingDto :: isMembersSyncEnable ) . map ( OrganizationAlmBindingDto :: getOrganizationUuid ) . collect ( toSet ( ) ) ; Set < String > organizationUuidsToBeAdded = difference ( almOrganizationUuidsWithMembersSyncEnabled , userOrganizationUuidsWithMembersSyncEnabled ) ; Set < String > organizationUuidsToBeRemoved = difference ( userOrganizationUuidsWithMembersSyncEnabled , almOrganizationUuidsWithMembersSyncEnabled ) ; Map < String , OrganizationDto > allOrganizationsByUuid = dbClient . organizationDao ( ) . selectByUuids ( dbSession , union ( organizationUuidsToBeAdded , organizationUuidsToBeRemoved ) ) . stream ( ) . collect ( uniqueIndex ( OrganizationDto :: getUuid ) ) ; allOrganizationsByUuid . entrySet ( ) . stream ( ) . filter ( entry -> organizationUuidsToBeAdded . contains ( entry . getKey ( ) ) ) . forEach ( entry -> addMemberInDb ( dbSession , entry . getValue ( ) , user ) ) ; allOrganizationsByUuid . entrySet ( ) . stream ( ) . filter ( entry -> organizationUuidsToBeRemoved . contains ( entry . getKey ( ) ) ) . forEach ( entry -> removeMemberInDb ( dbSession , entry . getValue ( ) , user ) ) ; }
Synchronize organization membership of a user from a list of ALM organization specific ids Please note that no commit will not be executed .