Exemplo n.º 1
0
  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 void addUserToInvitedDomains(User user) {

    String email = user.getEmail();

    List<Invitation> invitations = invitationService.getByEmail(email);
    for (Invitation invitation : invitations) {
      if (DomainType.GROUP.equals(invitation.getDomain().getDomainType())) {
        userService.addUserToGroup(
            user,
            invitation.getDomain().getId(),
            UserRole.valueOf(invitation.getRole().getAuthority()));
      } else if (DomainType.ORGANIZATION.equals(invitation.getDomain().getDomainType())) {
        userService.addUserToOrganization(
            user,
            invitation.getDomain().getId(),
            UserRole.valueOf(invitation.getRole().getAuthority()));
      }
    }

    for (Invitation invitation : invitations) {
      invitationService.delete(invitation.getId());
    }
  }
Exemplo n.º 3
0
  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;
  }