@ -1,4 +1,4 @@
|
||||
package mops.gruppen2.security;
|
||||
package mops.gruppen2.config;
|
||||
|
||||
import org.keycloak.OAuth2Constants;
|
||||
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
|
||||
@ -42,4 +42,4 @@ public class KeycloakConfig {
|
||||
|
||||
return new OAuth2RestTemplate(resourceDetails);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package mops.gruppen2.security;
|
||||
package mops.gruppen2.config;
|
||||
|
||||
import org.keycloak.KeycloakPrincipal;
|
||||
import org.keycloak.adapters.springsecurity.KeycloakSecurityComponents;
|
@ -1,6 +1,6 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
@ -50,10 +50,7 @@ public class GroupDetailsController {
|
||||
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(),
|
||||
account.getGivenname(),
|
||||
account.getFamilyname(),
|
||||
account.getEmail());
|
||||
User user = new User(account);
|
||||
UUID parentId = group.getParent();
|
||||
String actualURL = request.getRequestURL().toString();
|
||||
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||
@ -91,10 +88,7 @@ public class GroupDetailsController {
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(),
|
||||
account.getGivenname(),
|
||||
account.getFamilyname(),
|
||||
account.getEmail());
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
@ -119,8 +113,7 @@ public class GroupDetailsController {
|
||||
@RequestParam("groupId") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
//TODO: new Constructor/Method
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
@ -139,7 +132,7 @@ public class GroupDetailsController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
User user = new User(account);
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
@ -160,7 +153,7 @@ public class GroupDetailsController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User principle = new User(account.getName(), "", "", "");
|
||||
User principle = new User(account);
|
||||
User user = new User(userId, "", "", "");
|
||||
|
||||
validationService.throwIfNoAdmin(group, principle);
|
||||
@ -199,7 +192,7 @@ public class GroupDetailsController {
|
||||
@RequestParam("user_id") String userId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User principle = new User(account.getName(), "", "", "");
|
||||
User principle = new User(account);
|
||||
User user = new User(userId, "", "", "");
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
@ -222,10 +215,7 @@ public class GroupDetailsController {
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(),
|
||||
account.getGivenname(),
|
||||
account.getFamilyname(),
|
||||
account.getEmail());
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||
@ -245,7 +235,7 @@ public class GroupDetailsController {
|
||||
@RequestParam("group_id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
controllerService.deleteUser(account, user, group);
|
||||
@ -260,10 +250,7 @@ public class GroupDetailsController {
|
||||
@RequestParam("group_id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(),
|
||||
account.getGivenname(),
|
||||
account.getFamilyname(),
|
||||
account.getEmail());
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
@ -1,8 +1,8 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
@ -35,10 +35,7 @@ public class GruppenfindungController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
//TODO: new Contructor/method
|
||||
User user = new User(account.getName(),
|
||||
account.getGivenname(),
|
||||
account.getFamilyname(),
|
||||
account.getEmail());
|
||||
User user = new User(account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||
|
@ -1,9 +1,9 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
@ -69,8 +69,7 @@ public class SearchAndInviteController {
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = controllerService.getParent(parentId);
|
||||
//TODO: Replace
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
User user = new User(account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
if (validationService.checkIfUserInGroup(group, user)) {
|
||||
@ -111,12 +110,7 @@ public class SearchAndInviteController {
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
User user = new User(account.getName(),
|
||||
account.getGivenname(),
|
||||
account.getFamilyname(),
|
||||
account.getEmail());
|
||||
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||
|
@ -1,4 +1,4 @@
|
||||
package mops.gruppen2.security;
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
import lombok.Value;
|
||||
|
@ -15,4 +15,11 @@ public class User {
|
||||
private String givenname;
|
||||
private String familyname;
|
||||
private String email;
|
||||
|
||||
public User(Account account) {
|
||||
id = account.getName();
|
||||
givenname = account.getGivenname();
|
||||
familyname = account.getFamilyname();
|
||||
email = account.getEmail();
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||
@NoArgsConstructor
|
||||
public class UpdateUserMaxEvent extends Event {
|
||||
|
||||
private Long userMaximum;
|
||||
private Long userMaximum;
|
||||
|
||||
public UpdateUserMaxEvent(UUID groupId, String userId, Long userMaximum) {
|
||||
super(groupId, userId);
|
||||
@ -22,6 +22,6 @@ public class UpdateUserMaxEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
group.setUserMaximum(this.userMaximum);
|
||||
group.setUserMaximum(userMaximum);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
@ -15,7 +16,6 @@ import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.WrongFileException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -72,20 +72,35 @@ public class ControllerService {
|
||||
* @param parent Parameter für die neue Gruppe
|
||||
* @param file Parameter für die neue Gruppe
|
||||
*/
|
||||
public void createGroupAsOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) {
|
||||
public void createGroupAsOrga(Account account,
|
||||
String title,
|
||||
String description,
|
||||
Boolean isVisibilityPrivate,
|
||||
Boolean isLecture,
|
||||
Boolean isMaximumInfinite,
|
||||
Long userMaximum,
|
||||
UUID parent,
|
||||
MultipartFile file) {
|
||||
|
||||
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||
|
||||
List<User> newUsers = readCsvFile(file);
|
||||
|
||||
List<User> oldUsers = new ArrayList<>();
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
User user = new User(account);
|
||||
oldUsers.add(user);
|
||||
|
||||
removeOldUsersFromNewUsers(oldUsers, newUsers);
|
||||
|
||||
userMaximum = adjustUserMaximum((long) newUsers.size(), 1L, userMaximum);
|
||||
|
||||
UUID groupId = createGroup(account, title, description, isVisibilityPrivate, isLecture, isMaximumInfinite, userMaximum, parent);
|
||||
UUID groupId = createGroup(account,
|
||||
title,
|
||||
description,
|
||||
isVisibilityPrivate,
|
||||
isLecture,
|
||||
isMaximumInfinite,
|
||||
userMaximum, parent);
|
||||
|
||||
addUserList(newUsers, groupId);
|
||||
}
|
||||
@ -99,7 +114,7 @@ public class ControllerService {
|
||||
*
|
||||
* @return Maximum an Usern
|
||||
*/
|
||||
private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) {
|
||||
private static Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) {
|
||||
isMaximumInfinite = isMaximumInfinite != null;
|
||||
|
||||
if (isMaximumInfinite) {
|
||||
@ -109,6 +124,52 @@ public class ControllerService {
|
||||
return userMaximum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
|
||||
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
|
||||
* Aus diesen Event-Objekten wird eine Liste erzeugt, welche daraufhin mithilfe des EventServices gesichert wird.
|
||||
*
|
||||
* @param account Keycloak-Account
|
||||
* @param title Gruppentitel
|
||||
* @param description Gruppenbeschreibung
|
||||
*/
|
||||
//TODO: remove booleans
|
||||
public UUID createGroup(Account account,
|
||||
String title,
|
||||
String description,
|
||||
Boolean isVisibilityPrivate,
|
||||
Boolean isLecture,
|
||||
Boolean isMaximumInfinite,
|
||||
Long userMaximum,
|
||||
UUID parent) {
|
||||
|
||||
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||
|
||||
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
|
||||
UUID groupId = UUID.randomUUID();
|
||||
|
||||
GroupType groupType = setGroupType(isLecture);
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId,
|
||||
account.getName(),
|
||||
parent,
|
||||
groupType,
|
||||
groupVisibility,
|
||||
userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
inviteService.createLink(groupId);
|
||||
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
|
||||
addUser(account, groupId);
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(user, groupId);
|
||||
|
||||
return groupId;
|
||||
}
|
||||
|
||||
private static List<User> readCsvFile(MultipartFile file) throws EventException {
|
||||
if (file == null) {
|
||||
return new ArrayList<>();
|
||||
@ -138,39 +199,6 @@ public class ControllerService {
|
||||
return maxUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
|
||||
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
|
||||
* Aus diesen Event Objekten wird eine Liste erzeugt, welche daraufhin mithilfe des EventServices gesichert wird.
|
||||
*
|
||||
* @param account Keycloak-Account
|
||||
* @param title Gruppentitel
|
||||
* @param description Gruppenbeschreibung
|
||||
*/
|
||||
//TODO: remove booleans
|
||||
public UUID createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent) {
|
||||
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||
|
||||
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
|
||||
UUID groupId = UUID.randomUUID();
|
||||
|
||||
GroupType groupType = setGroupType(isLecture);
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
inviteService.createLink(groupId);
|
||||
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
|
||||
addUser(account, groupId);
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(user, groupId);
|
||||
|
||||
return groupId;
|
||||
}
|
||||
|
||||
private void addUserList(List<User> newUsers, UUID groupId) {
|
||||
for (User user : newUsers) {
|
||||
Group group = userService.getGroupById(groupId);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
@ -7,7 +8,6 @@ import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -60,7 +60,10 @@ public class GroupService {
|
||||
|
||||
List<Group> visibleGroups = projectEventList(createEvents);
|
||||
|
||||
return visibleGroups.stream().filter(group -> group.getType() == GroupType.LECTURE).filter(group -> group.getVisibility() == Visibility.PUBLIC).collect(Collectors.toList());
|
||||
return visibleGroups.stream()
|
||||
.filter(group -> group.getType() == GroupType.LECTURE)
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +79,8 @@ public class GroupService {
|
||||
public List<Group> projectEventList(List<Event> events) throws EventException {
|
||||
Map<UUID, Group> groupMap = new HashMap<>();
|
||||
|
||||
events.parallelStream().forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
|
||||
events.parallelStream()
|
||||
.forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
|
||||
|
||||
return new ArrayList<>(groupMap.values());
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import org.keycloak.KeycloakPrincipal;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
@ -11,7 +12,6 @@ import mops.gruppen2.domain.exception.NoAccessException;
|
||||
import mops.gruppen2.domain.exception.NoAdminAfterActionException;
|
||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@ -99,10 +99,8 @@ public class ValidationService {
|
||||
|
||||
boolean checkIfLastAdmin(Account account, Group group) {
|
||||
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) {
|
||||
if (entry.getValue() == ADMIN) {
|
||||
if (!(entry.getKey().equals(account.getName()))) {
|
||||
return false;
|
||||
}
|
||||
if (entry.getValue() == ADMIN && !(entry.getKey().equals(account.getName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -128,10 +126,8 @@ public class ValidationService {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (userMaximum != null) {
|
||||
if (userMaximum < 1 || userMaximum > 10000L) {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
if (userMaximum != null && (userMaximum < 1 || userMaximum > 10000L)) {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mops.gruppen2;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
@ -13,7 +14,6 @@ import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.security.Account;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -29,11 +29,11 @@ public class TestBuilder {
|
||||
|
||||
public static Account account(String name) {
|
||||
return new Account(name,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
null);
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
null);
|
||||
}
|
||||
|
||||
public static Group apply(Group group, Event... events) {
|
||||
@ -52,12 +52,13 @@ public class TestBuilder {
|
||||
* Baut eine UUID.
|
||||
*
|
||||
* @param id Integer id
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public static UUID uuidFromInt(int id) {
|
||||
return UUID.fromString("00000000-0000-0000-0000-"
|
||||
+ "0".repeat(11 - String.valueOf(id).length())
|
||||
+ id);
|
||||
+ "0".repeat(11 - String.valueOf(id).length())
|
||||
+ id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,22 +66,23 @@ public class TestBuilder {
|
||||
*
|
||||
* @param count Gruppenanzahl
|
||||
* @param membercount Mitgliederanzahl pro Gruppe
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> completePublicGroups(int count, int membercount) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> completePublicGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> completePublicGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> completePrivateGroups(int count, int membercount) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> completePrivateGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> completePrivateGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> completePublicGroup(int membercount) {
|
||||
@ -119,29 +121,30 @@ public class TestBuilder {
|
||||
* Generiert mehrere CreateGroupEvents, 1 <= groupId <= count.
|
||||
*
|
||||
* @param count Anzahl der verschiedenen Gruppen
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> createPublicGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> createPrivateGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> createMixedGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> faker.random().nextInt(0, 1) > 0.5
|
||||
? createPublicGroupEvent()
|
||||
: createPrivateGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> faker.random().nextInt(0, 1) > 0.5
|
||||
? createPublicGroupEvent()
|
||||
: createPrivateGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event createPrivateGroupEvent(UUID groupId) {
|
||||
@ -191,13 +194,14 @@ public class TestBuilder {
|
||||
*
|
||||
* @param count Anzahl der Mitglieder
|
||||
* @param groupId Gruppe, zu welcher geaddet wird
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> addUserEvents(int count, UUID groupId) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event addUserEvent(UUID groupId, String userId) {
|
||||
@ -221,8 +225,8 @@ public class TestBuilder {
|
||||
public static List<Event> deleteUserEvents(int count, List<Event> eventList) {
|
||||
List<Event> removeEvents = new ArrayList<>();
|
||||
List<Event> shuffle = eventList.parallelStream()
|
||||
.filter(event -> event instanceof AddUserEvent)
|
||||
.collect(Collectors.toList());
|
||||
.filter(event -> event instanceof AddUserEvent)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Collections.shuffle(shuffle);
|
||||
|
||||
@ -241,12 +245,13 @@ public class TestBuilder {
|
||||
* Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird.
|
||||
*
|
||||
* @param group Gruppe welche geleert wird
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> deleteUserEvents(Group group) {
|
||||
return group.getMembers().parallelStream()
|
||||
.map(user -> deleteUserEvent(group.getId(), user.getId()))
|
||||
.collect(Collectors.toList());
|
||||
.map(user -> deleteUserEvent(group.getId(), user.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event deleteUserEvent(UUID groupId, String userId) {
|
||||
|
@ -1,34 +1,12 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class AddUserEventTest {
|
||||
|
||||
@Test
|
||||
void userAlreadyExistExeption() throws EventException {
|
||||
Group group = new Group();
|
||||
User user = new User("user1", "Stein", "Speck", "@sdasd");
|
||||
group.getMembers().add(user);
|
||||
group.setUserMaximum(10L);
|
||||
UUID id = UUID.randomUUID();
|
||||
Event event1 = new AddUserEvent(id, "user2", "Rock", "Roll", "and");
|
||||
event1.apply(group);
|
||||
void applyEvent() {
|
||||
|
||||
Event event2 = new AddUserEvent(id, "user1", "Rock", "Roll", "and");
|
||||
|
||||
assertThrows(UserAlreadyExistsException.class, () ->
|
||||
event2.apply(group)
|
||||
);
|
||||
assertThat(group.getMembers().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,48 +1,10 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static mops.gruppen2.domain.Role.MEMBER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class DeleteUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyDeleteUser() throws EventException {
|
||||
Group group = new Group();
|
||||
User user = new User("user1", "Stein", "Speck", "@sdasd");
|
||||
group.getMembers().add(user);
|
||||
group.getRoles().put("user1", MEMBER);
|
||||
User user2 = new User("user2", "Rock", "Roll", "and");
|
||||
group.getMembers().add(user2);
|
||||
group.getRoles().put("user2", MEMBER);
|
||||
|
||||
Event event = new DeleteUserEvent(UUID.randomUUID(), "user1");
|
||||
event.apply(group);
|
||||
|
||||
assertThat(group.getMembers().size()).isEqualTo(1);
|
||||
assertThat(group.getRoles().size()).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void userDoesNotExistExeption() {
|
||||
Group group = new Group();
|
||||
User user = new User("user1", "Stein", "Speck", "@sdasd");
|
||||
group.getMembers().add(user);
|
||||
group.getRoles().put("user1", MEMBER);
|
||||
|
||||
Event event = new DeleteUserEvent(UUID.randomUUID(), "user5");
|
||||
assertThrows(UserNotFoundException.class, () ->
|
||||
event.apply(group)
|
||||
);
|
||||
assertThat(group.getMembers().size()).isEqualTo(1);
|
||||
void applyEvent() {
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.Gruppen2Application;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@Transactional
|
||||
@Rollback
|
||||
class ControllerServiceTest {
|
||||
|
||||
Account account;
|
||||
Account account2;
|
||||
Account account3;
|
||||
@ -136,7 +137,7 @@ class ControllerServiceTest {
|
||||
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
controllerService.createGroup(account, "test", "hi", null, true, true, null,groups1.get(0).getId());
|
||||
controllerService.createGroup(account, "test", "hi", null, true, true, null, groups1.get(0).getId());
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
|
Reference in New Issue
Block a user