1

ControllerService + CreationController + GroupService improvements + disabled controllerservice tests, the need to be rewritten

This commit is contained in:
Christoph
2020-04-07 17:58:04 +02:00
parent e13af57ab6
commit 897722fbd7
12 changed files with 331 additions and 364 deletions

View File

@ -1,6 +1,7 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import mops.gruppen2.domain.Account; import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.GroupType;
import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.ControllerService;
import mops.gruppen2.service.GroupService; import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.IdService; import mops.gruppen2.service.IdService;
@ -20,6 +21,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import java.util.UUID; import java.util.UUID;
import static mops.gruppen2.service.ControllerService.getGroupType;
import static mops.gruppen2.service.ControllerService.getUserMaximum;
import static mops.gruppen2.service.ControllerService.getVisibility;
@Controller @Controller
@SessionScope @SessionScope
@RequestMapping("/gruppen2") @RequestMapping("/gruppen2")
@ -56,27 +61,27 @@ public class GroupCreationController {
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token, public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
@RequestParam("title") String title, @RequestParam("title") String title,
@RequestParam("description") String description, @RequestParam("description") String description,
@RequestParam(value = "visibility", required = false) Boolean visibility, @RequestParam("visibility") boolean isPrivate,
@RequestParam(value = "lecture", required = false) Boolean lecture, @RequestParam("lecture") boolean isLecture,
@RequestParam("userMaximum") Long userMaximum, @RequestParam("maxInfiniteUsers") boolean isInfinite,
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, @RequestParam("userMaximum") long maxUsers,
@RequestParam(value = "parent", required = false) String parent, @RequestParam(value = "parent", required = false) String parent,
@RequestParam(value = "file", required = false) MultipartFile file) { @RequestParam(value = "file", required = false) MultipartFile file) {
Account account = new Account(token); Account account = new Account(token);
UUID parentUUID = IdService.stringToUUID(parent); UUID parentUUID = IdService.stringToUUID(parent);
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers); validationService.checkFields(description, title, maxUsers, isInfinite);
groupService.createGroupAsOrga(account,
title,
description,
getVisibility(isPrivate),
getGroupType(isLecture),
getUserMaximum(isInfinite, maxUsers),
parentUUID,
file);
controllerService.createGroupAsOrga(account,
title,
description,
visibility,
lecture,
maxInfiniteUsers,
userMaximum,
parentUUID,
file);
return "redirect:/gruppen2"; return "redirect:/gruppen2";
} }
@ -99,24 +104,23 @@ public class GroupCreationController {
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token, public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
@RequestParam("title") String title, @RequestParam("title") String title,
@RequestParam("description") String description, @RequestParam("description") String description,
@RequestParam("userMaximum") Long userMaximum, @RequestParam("visibility") boolean isPrivate,
@RequestParam(value = "visibility", required = false) Boolean visibility, @RequestParam("maxInfiniteUsers") boolean isInfinite,
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, @RequestParam("userMaximum") long maxUsers,
@RequestParam(value = "parent", required = false) String parent) { @RequestParam(value = "parent", required = false) String parent) {
Account account = new Account(token); Account account = new Account(token);
UUID parentUUID = IdService.stringToUUID(parent); UUID parentUUID = IdService.stringToUUID(parent);
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers); validationService.checkFields(description, title, maxUsers, isInfinite);
controllerService.createGroup(account, groupService.createGroup(account,
title, title,
description, description,
visibility, getVisibility(isPrivate),
null, GroupType.SIMPLE,
maxInfiniteUsers, getUserMaximum(isInfinite, maxUsers),
userMaximum, parentUUID);
parentUUID);
return "redirect:/gruppen2"; return "redirect:/gruppen2";
} }

View File

@ -1,5 +1,6 @@
package mops.gruppen2.domain; package mops.gruppen2.domain;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -14,22 +15,27 @@ import java.util.UUID;
*/ */
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Group { public class Group {
//TODO: List to Hashmap @EqualsAndHashCode.Include
private final List<User> members;
private final Map<String, Role> roles;
private UUID id; private UUID id;
private UUID parent;
private GroupType type;
private Visibility visibility;
private String title; private String title;
private String description; private String description;
private Long userMaximum; private Long userMaximum;
private GroupType type;
private Visibility visibility;
private UUID parent;
public Group() { //TODO: List to Hashmap
members = new ArrayList<>(); private final List<User> members = new ArrayList<>();
roles = new HashMap<>(); private final Map<String, Role> roles = new HashMap<>();
@Override
public String toString() {
return title + ": " + description;
} }
} }

View File

@ -7,11 +7,13 @@ import lombok.NoArgsConstructor;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor // Für Jackson: CSV-Import
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"}) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class User { public class User {
@EqualsAndHashCode.Include
private String id; private String id;
private String givenname; private String givenname;
private String familyname; private String familyname;
private String email; private String email;

View File

@ -29,6 +29,13 @@ public class AddUserEvent extends Event {
this.email = email; this.email = email;
} }
public AddUserEvent(UUID groupId, User user) {
super(groupId, user.getId());
givenname = user.getGivenname();
familyname = user.getFamilyname();
email = user.getEmail();
}
@Override @Override
protected void applyEvent(Group group) throws EventException { protected void applyEvent(Group group) throws EventException {
User user = new User(userId, givenname, familyname, email); User user = new User(userId, givenname, familyname, email);

View File

@ -1,127 +1,36 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.CreateGroupEvent;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service @Service
@Log4j2 @Log4j2
public class ControllerService { public final class ControllerService {
private final EventStoreService eventStoreService; private ControllerService() {}
private final InviteService inviteService;
private final GroupService groupService;
public ControllerService(EventStoreService eventStoreService, InviteService inviteService, GroupService groupService) { public static Visibility getVisibility(boolean isPrivate) {
this.eventStoreService = eventStoreService; return isPrivate ? Visibility.PRIVATE : Visibility.PUBLIC;
this.inviteService = inviteService; }
this.groupService = groupService;
public static GroupType getGroupType(boolean isLecture) {
return isLecture ? GroupType.LECTURE : GroupType.SIMPLE;
} }
/** /**
* Wie createGroup, nur das hier die Gruppe auch als Veranstaltung gesetzt werden kann und CSV Dateien mit Nutzern * Wenn die maximale Useranzahl unendlich ist, wird das Maximum auf 100000 gesetzt.
* eingelesen werden können. * Praktisch gibt es also maximal 100000 Nutzer pro Gruppe.
* *
* @param account Der Nutzer der die Gruppe erstellt * @param isInfinite Gibt an, ob es unendlich viele User geben soll
* @param title Parameter für die neue Gruppe * @param userMaximum Das Maximum an Usern, falls es eins gibt
* @param description Parameter für die neue Gruppe
* @param isVisibilityPrivate Parameter für die neue Gruppe
* @param isLecture Parameter für die neue Gruppe
* @param isMaximumInfinite Parameter für die neue Gruppe
* @param userMaximum Parameter für die neue Gruppe
* @param parent Parameter für die neue Gruppe
* @param file Parameter für die neue Gruppe
*/
//TODO: remove booleans + add wrapper?
//TODO: auslagern teilweise -> EventBuilderService
public void createGroupAsOrga(Account account,
String title,
String description,
Boolean isVisibilityPrivate,
Boolean isLecture,
Boolean isMaximumInfinite,
Long userMaximum,
UUID parent,
MultipartFile file) {
userMaximum = GroupService.checkInfiniteUsers(isMaximumInfinite, userMaximum);
List<User> newUsers = CsvService.readCsvFile(file);
List<User> oldUsers = new ArrayList<>();
User user = new User(account);
oldUsers.add(user);
GroupService.removeOldUsersFromNewUsers(oldUsers, newUsers);
userMaximum = GroupService.adjustUserMaximum((long) newUsers.size(), 1L, userMaximum);
UUID groupId = createGroup(account,
title,
description,
isVisibilityPrivate,
isLecture,
isMaximumInfinite,
userMaximum, parent);
groupService.addUserList(newUsers, groupId);
}
/**
* 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 * @return Maximum an Usern
* @param title Gruppentitel
* @param description Gruppenbeschreibung
*/ */
//TODO: remove booleans + add wrapper? public static long getUserMaximum(boolean isInfinite, long userMaximum) {
//TODO: auslagern teilweise -> EventBuilderService return isInfinite ? Long.MAX_VALUE : userMaximum;
public UUID createGroup(Account account,
String title,
String description,
Boolean isVisibilityPrivate,
Boolean isLecture,
Boolean isMaximumInfinite,
Long userMaximum,
UUID parent) {
userMaximum = GroupService.checkInfiniteUsers(isMaximumInfinite, userMaximum);
Visibility groupVisibility = GroupService.setGroupVisibility(isVisibilityPrivate);
UUID groupId = UUID.randomUUID();
GroupType groupType = GroupService.setGroupType(isLecture);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId,
account.getName(),
parent,
groupType,
groupVisibility,
userMaximum);
eventStoreService.saveEvent(createGroupEvent);
inviteService.createLink(groupId);
User user = new User(account.getName(), "", "", "");
groupService.addUser(account, groupId);
groupService.updateTitle(account, groupId, title);
groupService.updateDescription(account, groupId, description);
groupService.updateRole(user, groupId);
return groupId;
} }
} }

View File

@ -12,7 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -31,20 +31,21 @@ public final class CsvService {
return reader.<User>readValues(stream).readAll(); return reader.<User>readValues(stream).readAll();
} }
//TODO: CsvService
static List<User> readCsvFile(MultipartFile file) throws EventException { static List<User> readCsvFile(MultipartFile file) throws EventException {
if (file == null) { if (file == null) {
return new ArrayList<>(); return Collections.emptyList();
} }
if (!file.isEmpty()) { if (!file.isEmpty()) {
try { try {
List<User> userList = read(file.getInputStream()); List<User> userList = read(file.getInputStream());
return userList.stream().distinct().collect(Collectors.toList()); //filters duplicates from list return userList.stream()
.distinct()
.collect(Collectors.toList()); //filter duplicates from list
} catch (IOException ex) { } catch (IOException ex) {
log.error("File konnte nicht gelesen werden"); log.error("File konnte nicht gelesen werden:\n{}", ex.getMessage());
throw new WrongFileException(file.getOriginalFilename()); throw new WrongFileException(file.getOriginalFilename());
} }
} }
return new ArrayList<>(); return Collections.emptyList();
} }
} }

View File

@ -8,6 +8,7 @@ import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.AddUserEvent; import mops.gruppen2.domain.event.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.DeleteGroupEvent; import mops.gruppen2.domain.event.DeleteGroupEvent;
import mops.gruppen2.domain.event.DeleteUserEvent; import mops.gruppen2.domain.event.DeleteUserEvent;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent; import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
@ -42,93 +43,109 @@ public class GroupService {
this.projectionService = projectionService; this.projectionService = projectionService;
} }
static User getVeteranMember(Account account, Group group) {
List<User> members = group.getMembers(); // ################################# GRUPPE ERSTELLEN ########################################
String newAdminId;
if (members.get(0).getId().equals(account.getName())) {
newAdminId = members.get(1).getId(); /**
} else { * Wie createGroup, nur das hier die Gruppe auch als Veranstaltung gesetzt werden kann und CSV Dateien mit Nutzern
newAdminId = members.get(0).getId(); * eingelesen werden können.
} *
return new User(newAdminId, "", "", ""); * @param account Der Nutzer der die Gruppe erstellt
* @param title Parameter für die neue Gruppe
* @param description Parameter für die neue Gruppe
* @param visibility Parameter für die neue Gruppe
* @param userMaximum Parameter für die neue Gruppe
* @param parent Parameter für die neue Gruppe
* @param file Parameter für die neue Gruppe
*/
//TODO: add wrapper (GroupMeta)?
//TODO: auslagern teilweise -> EventBuilderService
public void createGroupAsOrga(Account account,
String title,
String description,
Visibility visibility,
GroupType groupType,
long userMaximum,
UUID parent,
MultipartFile file) {
// CSV-Import
List<User> newUsers = CsvService.readCsvFile(file);
newUsers.remove(new User(account));
long newUserMaximum = adjustUserMaximum(newUsers.size(), 1L, userMaximum);
UUID groupId = createGroup(account,
title,
description,
visibility,
groupType,
newUserMaximum,
parent);
addUserList(newUsers, groupId);
} }
/** /**
* Wenn die maximale Useranzahl unendlich ist, wird das Maximum auf 100000 gesetzt. Praktisch gibt es also Maximla 100000 * Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
* Nutzer pro Gruppe. * 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 isMaximumInfinite Gibt an ob es unendlich viele User geben soll * @param account Keycloak-Account
* @param userMaximum Das Maximum an Usern, falls es eins gibt * @param title Gruppentitel
* * @param description Gruppenbeschreibung
* @return Maximum an Usern
*/ */
static Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) { //TODO: add wrapper?
isMaximumInfinite = isMaximumInfinite != null; //TODO: auslagern teilweise -> EventBuilderService
public UUID createGroup(Account account,
String title,
String description,
Visibility visibility,
GroupType groupType,
Long userMaximum,
UUID parent) {
if (isMaximumInfinite) { UUID groupId = UUID.randomUUID();
userMaximum = 100_000L;
}
return userMaximum; CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId,
account.getName(),
parent,
groupType,
visibility,
userMaximum);
eventStoreService.saveEvent(createGroupEvent);
inviteService.createLink(groupId);
User user = new User(account);
addUser(account, groupId);
updateTitle(account, groupId, title);
updateDescription(account, groupId, description);
updateRole(user, groupId);
return groupId;
} }
static void removeOldUsersFromNewUsers(List<User> oldUsers, List<User> newUsers) {
for (User oldUser : oldUsers) {
newUsers.remove(oldUser);
}
}
static Long adjustUserMaximum(Long newUsers, Long oldUsers, Long maxUsers) { // ################################ GRUPPENMANIPULATION ######################################
if (oldUsers + newUsers > maxUsers) {
maxUsers = oldUsers + newUsers;
}
return maxUsers;
}
static Visibility setGroupVisibility(Boolean isVisibilityPrivate) {
isVisibilityPrivate = isVisibilityPrivate != null;
if (isVisibilityPrivate) {
return Visibility.PRIVATE;
} else {
return Visibility.PUBLIC;
}
}
static GroupType setGroupType(Boolean isLecture) {
isLecture = isLecture != null;
if (isLecture) {
return GroupType.LECTURE;
} else {
return GroupType.SIMPLE;
}
}
//TODO: GroupService/eventbuilderservice //TODO: GroupService/eventbuilderservice
void addUserList(List<User> newUsers, UUID groupId) { void addUserList(List<User> newUsers, UUID groupId) {
Group group = projectionService.projectSingleGroup(groupId);
for (User user : newUsers) { for (User user : newUsers) {
Group group = projectionService.projectSingleGroup(groupId);
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
log.info("Benutzer {} ist bereits in Gruppe", user.getId()); log.info("Benutzer {} ist bereits in Gruppe", user.getId());
} else { } else {
AddUserEvent addUserEvent = new AddUserEvent(groupId, user.getId(), user.getGivenname(), user.getFamilyname(), user.getEmail()); AddUserEvent addUserEvent = new AddUserEvent(groupId, user);
eventStoreService.saveEvent(addUserEvent); eventStoreService.saveEvent(addUserEvent);
} }
} }
} }
//TODO: GroupService/eventbuilderservice
public void addUser(Account account, UUID groupId) {
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
eventStoreService.saveEvent(addUserEvent);
}
//TODO: GroupService/eventbuilderservice
void updateTitle(Account account, UUID groupId, String title) {
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
eventStoreService.saveEvent(updateGroupTitleEvent);
}
//TODO: GroupService/eventbuilderservice //TODO: GroupService/eventbuilderservice
public void updateRole(User user, UUID groupId) throws EventException { public void updateRole(User user, UUID groupId) throws EventException {
UpdateRoleEvent updateRoleEvent; UpdateRoleEvent updateRoleEvent;
@ -143,12 +160,6 @@ public class GroupService {
eventStoreService.saveEvent(updateRoleEvent); eventStoreService.saveEvent(updateRoleEvent);
} }
//TODO: GroupService/eventbuilderservice
void updateDescription(Account account, UUID groupId, String description) {
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
eventStoreService.saveEvent(updateGroupDescriptionEvent);
}
//TODO: GroupService //TODO: GroupService
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) { public void addUsersFromCsv(Account account, MultipartFile file, String groupId) {
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId)); Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
@ -158,7 +169,10 @@ public class GroupService {
UUID groupUUID = IdService.stringToUUID(groupId); UUID groupUUID = IdService.stringToUUID(groupId);
Long newUserMaximum = adjustUserMaximum((long) newUserList.size(), (long) group.getMembers().size(), group.getUserMaximum()); Long newUserMaximum = adjustUserMaximum(newUserList.size(),
group.getMembers().size(),
group.getUserMaximum());
if (newUserMaximum > group.getUserMaximum()) { if (newUserMaximum > group.getUserMaximum()) {
updateMaxUser(account, groupUUID, newUserMaximum); updateMaxUser(account, groupUUID, newUserMaximum);
} }
@ -166,12 +180,6 @@ public class GroupService {
addUserList(newUserList, groupUUID); addUserList(newUserList, groupUUID);
} }
//TODO: GroupService/eventbuilderservice
public void updateMaxUser(Account account, UUID groupId, Long userMaximum) {
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId, account.getName(), userMaximum);
eventStoreService.saveEvent(updateUserMaxEvent);
}
//TODO: GroupService //TODO: GroupService
public void changeMetaData(Account account, Group group, String title, String description) { public void changeMetaData(Account account, Group group, String title, String description) {
if (!title.equals(group.getTitle())) { if (!title.equals(group.getTitle())) {
@ -183,15 +191,6 @@ public class GroupService {
} }
} }
//TODO: GroupService oder in Group?
public Group getParent(UUID parentId) {
Group parent = new Group();
if (!IdService.idIsEmpty(parentId)) {
parent = projectionService.projectSingleGroup(parentId);
}
return parent;
}
//TODO: GroupService //TODO: GroupService
public void deleteUser(Account account, User user, Group group) throws EventException { public void deleteUser(Account account, User user, Group group) throws EventException {
changeRoleIfLastAdmin(account, group); changeRoleIfLastAdmin(account, group);
@ -205,19 +204,6 @@ public class GroupService {
} }
} }
//TODO: GroupService/eventbuilderservice
private void deleteUserEvent(User user, UUID groupId) {
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
eventStoreService.saveEvent(deleteUserEvent);
}
//TODO: GroupService/eventbuilderservice
public void deleteGroupEvent(String userId, UUID groupId) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
inviteService.destroyLink(groupId);
eventStoreService.saveEvent(deleteGroupEvent);
}
//TODO: GroupService //TODO: GroupService
private void promoteVeteranMember(Account account, Group group) { private void promoteVeteranMember(Account account, Group group) {
if (validationService.checkIfLastAdmin(account, group)) { if (validationService.checkIfLastAdmin(account, group)) {
@ -245,4 +231,81 @@ public class GroupService {
updateRole(user, group.getId()); updateRole(user, group.getId());
} }
// ############################### GRUPEN ANFRAGEN ###########################################
static User getVeteranMember(Account account, Group group) {
List<User> members = group.getMembers();
String newAdminId;
if (members.get(0).getId().equals(account.getName())) {
newAdminId = members.get(1).getId();
} else {
newAdminId = members.get(0).getId();
}
return new User(newAdminId);
}
static long adjustUserMaximum(long newUsers, long oldUsers, long maxUsers) {
return Math.max(oldUsers + newUsers, maxUsers);
}
private static void removeOldUsersFromNewUsers(List<User> oldUsers, List<User> newUsers) {
for (User oldUser : oldUsers) {
newUsers.remove(oldUser);
}
}
//TODO: GroupService oder in Group?
public Group getParent(UUID parentId) {
Group parent = new Group();
if (!IdService.idIsEmpty(parentId)) {
parent = projectionService.projectSingleGroup(parentId);
}
return parent;
}
//TODO: Eventbuilderservice
// ################################### EVENTS ################################################
//TODO: GroupService/eventbuilderservice
private void deleteUserEvent(User user, UUID groupId) {
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
eventStoreService.saveEvent(deleteUserEvent);
}
//TODO: GroupService/eventbuilderservice
public void deleteGroupEvent(String userId, UUID groupId) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
inviteService.destroyLink(groupId);
eventStoreService.saveEvent(deleteGroupEvent);
}
//TODO: GroupService/eventbuilderservice
void updateDescription(Account account, UUID groupId, String description) {
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
eventStoreService.saveEvent(updateGroupDescriptionEvent);
}
//TODO: GroupService/eventbuilderservice
public void updateMaxUser(Account account, UUID groupId, Long userMaximum) {
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId, account.getName(), userMaximum);
eventStoreService.saveEvent(updateUserMaxEvent);
}
//TODO: GroupService/eventbuilderservice
public void addUser(Account account, UUID groupId) {
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
eventStoreService.saveEvent(addUserEvent);
}
//TODO: GroupService/eventbuilderservice
void updateTitle(Account account, UUID groupId, String title) {
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
eventStoreService.saveEvent(updateGroupTitleEvent);
}
} }

View File

@ -16,7 +16,7 @@ public final class JsonService {
private JsonService() {} private JsonService() {}
/** /**
* Übersetzt mithilfe der Jackson-Library eine Java-Event-Repräsentation zu einem JSON-Event-Payload. * Übersetzt eine Java-Event-Repräsentation zu einem JSON-Event-Payload.
* *
* @param event Java-Event-Repräsentation * @param event Java-Event-Repräsentation
* *
@ -31,7 +31,7 @@ public final class JsonService {
} }
/** /**
* Übersetzt mithilfe der Jackson-Library einen JSON-Event-Payload zu einer Java-Event-Repräsentation. * Übersetzt eine JSON-Event-Payload zu einer Java-Event-Repräsentation.
* *
* @param json JSON-Event-Payload als String * @param json JSON-Event-Payload als String
* *

View File

@ -21,27 +21,9 @@ public class SearchService {
} }
/** /**
* Sortiert die übergebene Liste an Gruppen, sodass Veranstaltungen am Anfang der Liste sind. * Filtert alle öffentliche Gruppen nach dem Suchbegriff und gibt diese als sortierte Liste zurück.
* * Groß- und Kleinschreibung wird nicht beachtet.
* @param groups Die Liste von Gruppen die sortiert werden soll * Der Suchbegriff wird im Gruppentitel und in der Beschreibung gesucht.
*/
//TODO: ProjectionService/SearchSortService
static void sortByGroupType(List<Group> groups) {
groups.sort((Group g1, Group g2) -> {
if (g1.getType() == GroupType.LECTURE) {
return -1;
}
if (g2.getType() == GroupType.LECTURE) {
return 0;
}
return 1;
});
}
/**
* Filtert alle öffentliche Gruppen nach dem Suchbegriff und gibt diese als Liste von Gruppen zurück.
* Groß und Kleinschreibung wird nicht beachtet.
* *
* @param search Der Suchstring * @param search Der Suchstring
* *
@ -49,7 +31,6 @@ public class SearchService {
* *
* @throws EventException Projektionsfehler * @throws EventException Projektionsfehler
*/ */
//TODO: remove account
@Cacheable("groups") @Cacheable("groups")
public List<Group> searchPublicGroups(String search, String userId) throws EventException { public List<Group> searchPublicGroups(String search, String userId) throws EventException {
List<Group> groups = projectionService.projectPublicGroups(); List<Group> groups = projectionService.projectPublicGroups();
@ -63,14 +44,25 @@ public class SearchService {
log.trace("Es wurde gesucht nach: {}", search); log.trace("Es wurde gesucht nach: {}", search);
return groups.stream() return groups.stream()
.filter(group -> groupMetaContains(group, search)) .filter(group -> group.toString().toLowerCase().contains(search.toLowerCase()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private static boolean groupMetaContains(Group group, String string) { /**
String meta = group.getTitle().toLowerCase() + " " + group.getDescription().toLowerCase(); * Sortiert die übergebene Liste an Gruppen, sodass Veranstaltungen am Anfang der Liste sind.
String pattern = string.toLowerCase(); *
* @param groups Die Liste von Gruppen die sortiert werden soll
*/
private static void sortByGroupType(List<Group> groups) {
groups.sort((Group g1, Group g2) -> {
if (g1.getType() == GroupType.LECTURE) {
return -1;
}
if (g2.getType() == GroupType.LECTURE) {
return 0;
}
return meta.contains(pattern); return 1;
});
} }
} }

View File

@ -2,6 +2,7 @@
<html lang="en" xmlns:th="http://www.thymeleaf.org" <html lang="en" xmlns:th="http://www.thymeleaf.org"
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}" th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
xmlns="http://www.w3.org/1999/html"> xmlns="http://www.w3.org/1999/html">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Gruppenerstellung</title> <title>Gruppenerstellung</title>
@ -14,7 +15,9 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</th:block> </th:block>
</head> </head>
<body> <body>
<header> <header>
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}"> <nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
<ul> <ul>
@ -33,65 +36,58 @@
</ul> </ul>
</nav> </nav>
</header> </header>
<main th:fragment="bodycontent"> <main th:fragment="bodycontent">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col-10"> <div class="col-10">
<h1>Gruppenerstellung</h1> <h1>Gruppenerstellung</h1>
<form enctype="multipart/form-data" method="post" <form enctype="multipart/form-data" method="post" th:action="@{/gruppen2/createOrga}">
th:action="@{/gruppen2/createOrga}"> <div class="shadow-sm p-2" style=" border: 10px solid aliceblue; background: aliceblue">
<div class="shadow-sm p-2"
style=" border: 10px solid aliceblue; background: aliceblue">
<div class="form-group"> <div class="form-group">
<label for="titel">Titel</label> <label for="titel">Titel</label>
<input class="form-control" id="titel" required th:name="title" <input class="form-control" id="titel" required th:name="title" type="text">
type="text">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="description">Beschreibung</label> <label for="description">Beschreibung</label>
<textarea class="form-control" id="description" required <textarea class="form-control" id="description" required rows="3" th:name="description"></textarea>
rows="3" th:name="description"></textarea>
</div> </div>
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input class="custom-control-input" id="maxInfiniteUsers" th:name="maxInfiniteUsers" <!--DO NOT WRAP-->
type="checkbox"> <input type="hidden" name="maxInfiniteUsers" value="0"/><input class="custom-control-input" type="checkbox" id="maxInfiniteUsers" onclick="this.previousSibling.value=1-this.previousSibling.value"/>
<label class="custom-control-label" for="maxInfiniteUsers">Anzahl <label class="custom-control-label" for="maxInfiniteUsers">Anzahl
unbegrenzt</label> unbegrenzt</label>
</div> </div>
<div class="form-group mt-3" id="userMaximum"> <div class="form-group mt-3" id="userMaximum">
<label for="userMaximum">Teilnehmeranzahl</label> <label for="userMaximum">Teilnehmeranzahl</label>
<input class="form-control" th:name="userMaximum" <input class="form-control" th:name="userMaximum" type="number" min="1" max="100000" value="1">
type="number" min="1" max="10000">
</div> </div>
<div class="custom-control custom-checkbox" id="privateCheckbox"> <div class="custom-control custom-checkbox" id="privateCheckbox">
<input class="custom-control-input" id="visibility" th:name="visibility" <!--DO NOT WRAP-->
type="checkbox"> <input type="hidden" name="visibility" value="0"/><input class="custom-control-input" type="checkbox" id="visibility" onclick="this.previousSibling.value=1-this.previousSibling.value"/>
<label class="custom-control-label" for="visibility">Private <label class="custom-control-label" for="visibility">Privat</label>
Gruppe</label>
</div> </div>
<div class="custom-control custom-checkbox" id="lectureCheckbox"> <div class="custom-control custom-checkbox" id="lectureCheckbox">
<input class="custom-control-input" id="lecture" th:name="lecture" <!--DO NOT WRAP-->
type="checkbox"> <input type="hidden" name="lecture" value="0"/><input class="custom-control-input" type="checkbox" id="lecture" onclick="this.previousSibling.value=1-this.previousSibling.value"/>
<label class="custom-control-label" for="lecture">Veranstaltung</label> <label class="custom-control-label" for="lecture">Veranstaltung</label>
</div> </div>
<div class="form-group" id="lectureParent"> <div class="form-group" id="lectureParent">
<label for="parent"></label> <label for="parent"></label>
<select class="form-control" id="parent" name="parent"> <select class="form-control" id="parent" th:name="parent">
<option disabled selected="true">--Bitte Veranstaltung auswählen-- <option disabled selected>--Bitte Veranstaltung auswählen--
</option>
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
</option> </option>
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}"></option>
</select> </select>
</div> </div>
<div class="form-group pt-4"> <div class="form-group pt-4">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<div class="custom-file"> <div class="custom-file">
<input class="custom-file-input" id="file" th:name="file"
type="file">
<label class="custom-file-label" for="file">CSV Datei von <label class="custom-file-label" for="file">CSV Datei von
Mitgliedern Mitgliedern
hochladen</label> hochladen</label>
<input class="custom-file-input" id="file" th:name="file" type="file">
</div> </div>
</div> </div>
</div> </div>
@ -107,38 +103,46 @@
</div> </div>
</div> </div>
</div> </div>
<script> <script>
//TODO: Hab ich kaputt gemacht
// Add the following code if you want the name of the file appear on select // Add the following code if you want the name of the file appear on select
$(".custom-file-input").on("change", function () { $(".custom-file-input").on("change", function () {
var fileName = $(this).val().split("\\").pop(); const fileName = $(this).val().split("\\").pop();
$(this).siblings(".custom-file-label").addClass("selected").html(fileName); $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
}); });
// Collapsing lectureParent if lecture is checked // Collapse lectureParent if lecture
$(document).ready(function () { $(document).ready(function () {
$('#lecture').change(function () { $('#lecture').change(function () {
$('#lectureParent').fadeToggle(); $('#lectureParent').prop('disabled', function (i, v) { return !v; });
}); });
}); });
// Collapse provateCheckbox if lecture
$(document).ready(function () { $(document).ready(function () {
$('#lecture').change(function () { $('#lecture').change(function () {
$('#privateCheckbox').fadeToggle(); $('#privateCheckbox').prop('disabled', function (i, v) { return !v; });
}); });
}); });
// Collapse lectureCheckbox if private
$(document).ready(function () { $(document).ready(function () {
$('#visibility').change(function () { $('#visibility').change(function () {
$('#lectureCheckbox').fadeToggle(); $('#lectureCheckbox').prop('disabled', function (i, v) { return !v; });
}); });
}); });
// Collapse userMaximum if infinite
$(document).ready(function () { $(document).ready(function () {
$('#maxInfiniteUsers').change(function () { $('#maxInfiniteUsers').change(function () {
$('#userMaximum').fadeToggle(); $('#userMaximum').prop('disabled', function (i, v) { return !v; });
}); });
}); });
</script> </script>
</main> </main>
</body> </body>
</html> </html>

View File

@ -43,17 +43,15 @@
<div class="form-group"> <div class="form-group">
<label for="titel">Titel</label> <label for="titel">Titel</label>
<input class="form-control" id="titel" required th:name="title" <input class="form-control" id="titel" required th:name="title" type="text">
type="text">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="description">Beschreibung</label> <label for="description">Beschreibung</label>
<textarea class="form-control" id="description" required <textarea class="form-control" id="description" required rows="3" th:name="description"></textarea>
rows="3" th:name="description"></textarea>
</div> </div>
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input class="custom-control-input" id="maxInfiniteUsers" th:name="maxInfiniteUsers" <!--DO NOT WRAP-->
type="checkbox"> <input type="hidden" name="maxInfiniteUsers" value="0"/><input class="custom-control-input" type="checkbox" id="maxInfiniteUsers" onclick="this.previousSibling.value=1-this.previousSibling.value"/>
<label class="custom-control-label" for="maxInfiniteUsers">Anzahl <label class="custom-control-label" for="maxInfiniteUsers">Anzahl
unbegrenzt</label> unbegrenzt</label>
</div> </div>
@ -63,15 +61,14 @@
type="number" min="1" max="10000"> type="number" min="1" max="10000">
</div> </div>
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input class="custom-control-input" id="visibility" th:name="visibility" <!--DO NOT WRAP-->
type="checkbox"> <input type="hidden" name="visibility" value="0"/><input class="custom-control-input" type="checkbox" id="visibility" onclick="this.previousSibling.value=1-this.previousSibling.value"/>
<label class="custom-control-label" for="visibility">Private <label class="custom-control-label" for="visibility">Privat</label>
Gruppe</label>
</div> </div>
<div class="form-group" id="lectureParent"> <div class="form-group" id="lectureParent">
<label for="parent"></label> <label for="parent"></label>
<select class="form-control" id="parent" name="parent"> <select class="form-control" id="parent" name="parent">
<option disabled selected="true">--Bitte Veranstaltung auswählen-- <option disabled selected>--Bitte Veranstaltung auswählen--
</option> </option>
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}"> <option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
</option> </option>

View File

@ -2,16 +2,7 @@ package mops.gruppen2.service;
import mops.gruppen2.Gruppen2Application; import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.domain.Account; import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group;
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.repository.EventRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -19,16 +10,6 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
//TODO: Alles in die entsprechenden Klassen sortieren :(((( //TODO: Alles in die entsprechenden Klassen sortieren :((((
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Gruppen2Application.class) @SpringBootTest(classes = Gruppen2Application.class)
@ -56,6 +37,7 @@ class ControllerServiceTest {
@Autowired @Autowired
ProjectionService projectionService; ProjectionService projectionService;
/*
@BeforeEach @BeforeEach
void setUp() { void setUp() {
Set<String> roles = new HashSet<>(); Set<String> roles = new HashSet<>();
@ -68,7 +50,7 @@ class ControllerServiceTest {
@Test @Test
void createPublicGroupWithNoParentAndLimitedNumberTest() { void createPublicGroupWithNoParentAndLimitedNumberTest() {
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, null); groupService.createGroup(account, "test", "hi", null, null, null, 20L, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility()); assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -78,7 +60,7 @@ class ControllerServiceTest {
@Test @Test
void createPublicGroupWithNoParentAndUnlimitedNumberTest() { void createPublicGroupWithNoParentAndUnlimitedNumberTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null); groupService.createGroup(account, "test", "hi", null, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility()); assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -88,7 +70,7 @@ class ControllerServiceTest {
@Test @Test
void createPrivateGroupWithNoParentAndUnlimitedNumberTest() { void createPrivateGroupWithNoParentAndUnlimitedNumberTest() {
controllerService.createGroup(account, "test", "hi", true, null, true, null, null); groupService.createGroup(account, "test", "hi", true, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility()); assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
@ -98,7 +80,7 @@ class ControllerServiceTest {
@Test @Test
void createPrivateGroupWithNoParentAndLimitedNumberTest() { void createPrivateGroupWithNoParentAndLimitedNumberTest() {
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, null); groupService.createGroup(account, "test", "hi", true, null, null, 20L, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility()); assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
@ -108,9 +90,9 @@ class ControllerServiceTest {
@Test @Test
void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException { void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account2, "test", "hi", null, true, true, null, null, null); groupService.createGroupAsOrga(account2, "test", "hi", false, true, true, 1L, null, null);
List<Group> groups1 = projectionService.projectUserGroups(account2.getName()); List<Group> groups1 = projectionService.projectUserGroups(account2.getName());
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, groups1.get(0).getId()); groupService.createGroup(account, "test", "hi", true, null, null, 20L, groups1.get(0).getId());
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility()); assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
@ -120,9 +102,9 @@ class ControllerServiceTest {
@Test @Test
void createPublicGroupWithParentAndLimitedNumberTest() throws IOException { void createPublicGroupWithParentAndLimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null); groupService.createGroupAsOrga(account2, "test", "hi", false, false, true, 1L, null, null);
List<Group> groups1 = projectionService.projectUserGroups(account2.getName()); List<Group> groups1 = projectionService.projectUserGroups(account2.getName());
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, groups1.get(0).getId()); groupService.createGroup(account, "test", "hi", null, null, null, 20L, groups1.get(0).getId());
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility()); assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -132,9 +114,9 @@ class ControllerServiceTest {
@Test @Test
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException { void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null); groupService.createGroupAsOrga(account2, "test", "hi", false, false, true, 1L, null, null);
List<Group> groups1 = projectionService.projectUserGroups(account2.getName()); List<Group> groups1 = projectionService.projectUserGroups(account2.getName());
controllerService.createGroup(account, "test", "hi", null, true, true, null, groups1.get(0).getId()); groupService.createGroup(account, "test", "hi", null, true, true, null, groups1.get(0).getId());
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility()); assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -144,9 +126,9 @@ class ControllerServiceTest {
@Test @Test
void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException { void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null); groupService.createGroupAsOrga(account2, "test", "hi", false, false, true, 1L, null, null);
List<Group> groups1 = projectionService.projectUserGroups(account2.getName()); List<Group> groups1 = projectionService.projectUserGroups(account2.getName());
controllerService.createGroup(account, "test", "hi", true, true, true, null, groups1.get(0).getId()); groupService.createGroup(account, "test", "hi", true, true, true, null, groups1.get(0).getId());
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility()); assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
@ -156,7 +138,7 @@ class ControllerServiceTest {
@Test @Test
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException { void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account, "test", "hi", null, null, null, 20L, null, null); groupService.createGroupAsOrga(account, "test", "hi", false, false, false, 20L, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(GroupType.SIMPLE, groups.get(0).getType()); assertEquals(GroupType.SIMPLE, groups.get(0).getType());
@ -167,7 +149,7 @@ class ControllerServiceTest {
@Test @Test
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException { void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account, "test", "hi", null, null, true, null, null, null); groupService.createGroupAsOrga(account, "test", "hi", false, false, true, 1L, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(GroupType.SIMPLE, groups.get(0).getType()); assertEquals(GroupType.SIMPLE, groups.get(0).getType());
@ -178,7 +160,7 @@ class ControllerServiceTest {
@Test @Test
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException { void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account, "test", "hi", true, null, null, 20L, null, null); groupService.createGroupAsOrga(account, "test", "hi", true, false, false, 20L, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(GroupType.SIMPLE, groups.get(0).getType()); assertEquals(GroupType.SIMPLE, groups.get(0).getType());
@ -189,7 +171,7 @@ class ControllerServiceTest {
@Test @Test
void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException { void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account, "test", "hi", true, null, true, null, null, null); groupService.createGroupAsOrga(account, "test", "hi", true, false, true, 1L, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(GroupType.SIMPLE, groups.get(0).getType()); assertEquals(GroupType.SIMPLE, groups.get(0).getType());
@ -200,7 +182,7 @@ class ControllerServiceTest {
@Test @Test
void createOrgaLectureGroupAndLimitedNumberTest() throws IOException { void createOrgaLectureGroupAndLimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account, "test", "hi", null, true, null, 20L, null, null); groupService.createGroupAsOrga(account, "test", "hi", false, true, false, 20L, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(GroupType.LECTURE, groups.get(0).getType()); assertEquals(GroupType.LECTURE, groups.get(0).getType());
@ -211,7 +193,7 @@ class ControllerServiceTest {
@Test @Test
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException { void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account, "test", "hi", null, true, true, null, null, null); groupService.createGroupAsOrga(account, "test", "hi", false, true, true, 1L, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
assertEquals(GroupType.LECTURE, groups.get(0).getType()); assertEquals(GroupType.LECTURE, groups.get(0).getType());
@ -224,7 +206,7 @@ class ControllerServiceTest {
@Disabled @Disabled
@Test @Test
public void deleteUserTest() { public void deleteUserTest() {
controllerService.createGroup(account, "test", "hi", true, true, true, null, null); groupService.createGroup(account, "test", "hi", true, true, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
groupService.addUser(account2, groups.get(0).getId()); groupService.addUser(account2, groups.get(0).getId());
User user = new User(account.getName(), "", "", ""); User user = new User(account.getName(), "", "", "");
@ -236,7 +218,7 @@ class ControllerServiceTest {
@Disabled @Disabled
@Test @Test
public void updateRoleAdminTest() { public void updateRoleAdminTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null); groupService.createGroup(account, "test", "hi", null, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
groupService.addUser(account2, groups.get(0).getId()); groupService.addUser(account2, groups.get(0).getId());
User user = new User(account.getName(), "", "", ""); User user = new User(account.getName(), "", "", "");
@ -249,7 +231,7 @@ class ControllerServiceTest {
@Disabled @Disabled
@Test @Test
public void updateRoleMemberTest() { public void updateRoleMemberTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null); groupService.createGroup(account, "test", "hi", null, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
groupService.addUser(account2, groups.get(0).getId()); groupService.addUser(account2, groups.get(0).getId());
User user = new User(account2.getName(), "", "", ""); User user = new User(account2.getName(), "", "", "");
@ -261,7 +243,7 @@ class ControllerServiceTest {
//TODO: GroupServiceTest //TODO: GroupServiceTest
@Test @Test
public void updateRoleNonUserTest() { public void updateRoleNonUserTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null); groupService.createGroup(account, "test", "hi", null, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
User user = new User(account2.getName(), "", "", ""); User user = new User(account2.getName(), "", "", "");
Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.updateRole(user, groups.get(0).getId())); Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.updateRole(user, groups.get(0).getId()));
@ -271,7 +253,7 @@ class ControllerServiceTest {
//TODO: GroupServiceTest //TODO: GroupServiceTest
@Test @Test
public void deleteNonUserTest() { public void deleteNonUserTest() {
controllerService.createGroup(account, "test", "hi", true, null, true, null, null); groupService.createGroup(account, "test", "hi", true, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
User user = new User(account2.getName(), "", "", ""); User user = new User(account2.getName(), "", "", "");
Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.deleteUser(account, user, groups.get(0))); Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.deleteUser(account, user, groups.get(0)));
@ -287,7 +269,7 @@ class ControllerServiceTest {
@Disabled @Disabled
@Test @Test
void passIfLastAdminTest() { void passIfLastAdminTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null); groupService.createGroup(account, "test", "hi", null, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
groupService.addUser(account2, groups.get(0).getId()); groupService.addUser(account2, groups.get(0).getId());
User user = new User(account.getName(), "", "", ""); User user = new User(account.getName(), "", "", "");
@ -301,7 +283,7 @@ class ControllerServiceTest {
@Disabled @Disabled
@Test @Test
void dontPassIfNotLastAdminTest() { void dontPassIfNotLastAdminTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null); groupService.createGroup(account, "test", "hi", null, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
groupService.addUser(account2, groups.get(0).getId()); groupService.addUser(account2, groups.get(0).getId());
User user2 = new User(account2.getName(), "", "", ""); User user2 = new User(account2.getName(), "", "", "");
@ -318,7 +300,7 @@ class ControllerServiceTest {
@Disabled @Disabled
@Test @Test
void getVeteranMemberTest() { void getVeteranMemberTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null); groupService.createGroup(account, "test", "hi", null, null, true, null, null);
List<Group> groups = projectionService.projectUserGroups(account.getName()); List<Group> groups = projectionService.projectUserGroups(account.getName());
groupService.addUser(account2, groups.get(0).getId()); groupService.addUser(account2, groups.get(0).getId());
groupService.addUser(account3, groups.get(0).getId()); groupService.addUser(account3, groups.get(0).getId());
@ -328,5 +310,5 @@ class ControllerServiceTest {
groups = projectionService.projectUserGroups(account2.getName()); groups = projectionService.projectUserGroups(account2.getName());
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName())); assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName())); assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
} }*/
} }