private UserDomain createUserDomain( User user, Long domainId, DomainType domainType, UserRole userRole) { UserDomain userDomain = new UserDomain(); userDomain.setUser(user); userDomain.setDomainId(domainId); userDomain.setDomainType(domainType); userDomain.setRole(roleService.getRoleByAuthority(userRole.name())); user.getUserDomains().add(userDomain); return userDomain; }
private User getUser(UserRole organizationUserRole, UserRole groupUserRole) { User user = getUser(); Role orgRole = null; if (organizationUserRole != null) { orgRole = roleService.getRoleByAuthority(organizationUserRole.name()); user.getRoles().add(orgRole); } Role groupRole = null; if (groupUserRole != null) { groupRole = roleService.getRoleByAuthority(groupUserRole.name()); user.getRoles().add(groupRole); } Organization organization = createOrganization(); Application application = createApplication( organization.getCategories().get(0), "Test Application", AppState.GROUP_PUBLISH); Application application2 = createApplication( organization.getCategories().get(0), "Test Application 2", AppState.ORGANIZATION_PUBLISH); Group group = createGroup(organization); group.getOwnedApplications().add(application); group.getOwnedApplications().add(application2); organization.getGroups().add(group); userService.save(user); organizationService.getAll(); if (groupRole != null) { UserDomain userDomainGroup = new UserDomain(); userDomainGroup.setUser(user); userDomainGroup.setDomainId(group.getId()); userDomainGroup.setDomainType(DomainType.GROUP); userDomainGroup.setRole(groupRole); userDomainGroup.setDomainId(group.getId()); user.getUserDomains().add(userDomainGroup); } if (orgRole != null) { UserDomain userDomainOrg = new UserDomain(); userDomainOrg.setUser(user); userDomainOrg.setDomainId(group.getId()); userDomainOrg.setDomainType(DomainType.ORGANIZATION); userDomainOrg.setRole(orgRole); userDomainOrg.setDomainId(organization.getId()); user.getUserDomains().add(userDomainOrg); } userService.save(user); entityManager.flush(); return user; }