1

Merge branch 'master' into refactor-controller

# Conflicts:
#	src/main/java/mops/gruppen2/controller/WebController.java
This commit is contained in:
Christoph
2020-03-25 13:03:22 +01:00
22 changed files with 438 additions and 39 deletions

View File

@ -61,5 +61,4 @@ Für *Studenten* (keycloak Rolle) :
=== Verwendung === Verwendung
Wir werden ein Dockerfile bereitstellen, das heißt ihr könnt die Anwendung einfach starten. Die Anwendung kann mit `docker-compse up` im Wurzelverzeichnis gestartet werden, eine API-Doku befindet sich im Dokumentation-Ordner (das swagger-zip).
Unter localhost:8081/swagger-ui.html findet ihr die API-Dokumentation.

BIN
documentation/swagger.zip Normal file

Binary file not shown.

View File

@ -1,5 +1,7 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.PageNotFoundException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -17,10 +19,10 @@ public class MopsController {
public String logout(HttpServletRequest request) throws Exception { public String logout(HttpServletRequest request) throws Exception {
request.logout(); request.logout();
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
}/* }
@GetMapping("*") @GetMapping("*")
public String defaultLink() { public String defaultLink() throws EventException {
return "error"; throw new PageNotFoundException("\uD83D\uDE41");
}*/ }
} }

View File

@ -1,14 +1,17 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import mops.gruppen2.config.Gruppen2Config;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role; 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.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupFullException;
import mops.gruppen2.domain.exception.GroupNotFoundException; import mops.gruppen2.domain.exception.GroupNotFoundException;
import mops.gruppen2.domain.exception.NoAccessException;
import mops.gruppen2.domain.exception.NoAdminAfterActionException; import mops.gruppen2.domain.exception.NoAdminAfterActionException;
import mops.gruppen2.domain.exception.PageNotFoundException;
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
import mops.gruppen2.domain.exception.WrongFileException; import mops.gruppen2.domain.exception.WrongFileException;
import mops.gruppen2.security.Account; import mops.gruppen2.security.Account;
import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.ControllerService;
@ -26,7 +29,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.annotation.SessionScope; import org.springframework.web.context.annotation.SessionScope;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import java.io.CharConversionException; import java.io.CharConversionException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -147,6 +152,47 @@ public class WebController {
return "redirect:/gruppen2/details/members/" + groupId; return "redirect:/gruppen2/details/members/" + groupId;
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/details/changeMetadata/{id}")
public String changeMetadata(KeycloakAuthenticationToken token, Model model, @PathVariable("id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId));
model.addAttribute("account", account);
UUID parentId = group.getParent();
Group parent = new Group();
if (!group.getMembers().contains(user)) {
if (group.getVisibility() == Visibility.PRIVATE) {
return "privateGroupNoMember";
}
model.addAttribute("group", group);
model.addAttribute("parentId", parentId);
model.addAttribute("parent", parent);
return "detailsNoMember";
}
model.addAttribute("title", group.getTitle());
model.addAttribute("description", group.getDescription());
model.addAttribute("admin", Role.ADMIN);
model.addAttribute("roles", group.getRoles());
model.addAttribute("groupId", group.getId());
model.addAttribute("user", user);
return "changeMetadata";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/details/changeMetadata")
public String pChangeMetadata(KeycloakAuthenticationToken token,
@RequestParam("title") String title,
@RequestParam("description") String description,
@RequestParam("groupId") String groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
controllerService.updateTitle(account, UUID.fromString(groupId), title);
controllerService.updateDescription(account, UUID.fromString(groupId), description);
return "redirect:/gruppen2/details/" + groupId;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/findGroup") @GetMapping("/findGroup")
public String findGroup(KeycloakAuthenticationToken token, public String findGroup(KeycloakAuthenticationToken token,
@ -164,9 +210,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/{id}") @GetMapping("/details/{id}")
public String showGroupDetails(KeycloakAuthenticationToken token, public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("id") String groupId) throws EventException {
Model model,
@PathVariable("id") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
@ -177,7 +221,7 @@ public class WebController {
Group parent = new Group(); Group parent = new Group();
if (group.getTitle() == null) { if (group.getTitle() == null) {
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@details");
} }
if (!group.getMembers().contains(user)) { if (!group.getMembers().contains(user)) {
@ -200,6 +244,12 @@ public class WebController {
model.addAttribute("roles", group.getRoles()); model.addAttribute("roles", group.getRoles());
model.addAttribute("user", user); model.addAttribute("user", user);
model.addAttribute("admin", Role.ADMIN); model.addAttribute("admin", Role.ADMIN);
String URL = request.getRequestURL().toString();
String serverURL = URL.substring(0, URL.indexOf("gruppen2/"));
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
return "detailsMember"; return "detailsMember";
} }
@ -212,12 +262,13 @@ public class WebController {
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
return "redirect:/gruppen2/details/" + groupId; //TODO: hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden throw new UserAlreadyExistsException("Du bist bereits in dieser Gruppe.");
}
if (group.getUserMaximum() < group.getMembers().size()) {
return "error";
} }
controllerService.addUser(account, UUID.fromString(groupId)); controllerService.addUser(account, UUID.fromString(groupId));
if (group.getUserMaximum() < group.getMembers().size()) {
throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten.");
}
//controllerService.addUser(account, groupId);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@ -230,9 +281,11 @@ public class WebController {
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
UUID parentId = group.getParent(); UUID parentId = group.getParent();
Group parent = new Group(); Group parent = new Group();
if (parentId != null) {
if (!controllerService.idIsEmpty(parentId)) {
parent = userService.getGroupById(parentId); parent = userService.getGroupById(parentId);
} }
if (group.getUserMaximum() > group.getMembers().size()) { if (group.getUserMaximum() > group.getMembers().size()) {
model.addAttribute("group", group); model.addAttribute("group", group);
model.addAttribute("parentId", parentId); model.addAttribute("parentId", parentId);
@ -240,11 +293,11 @@ public class WebController {
return "detailsNoMember"; return "detailsNoMember";
} }
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@search");
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/acceptinvite/{link}") @GetMapping("/acceptinvite/{groupId}")
public String acceptInvite(KeycloakAuthenticationToken token, public String acceptInvite(KeycloakAuthenticationToken token,
Model model, @PathVariable String groupId) throws EventException { Model model, @PathVariable String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
@ -253,7 +306,7 @@ public class WebController {
model.addAttribute("group", group); model.addAttribute("group", group);
return "redirect:/gruppen2/detailsSearch?id=" + group.getId(); return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
} }
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@accept");
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@ -280,7 +333,7 @@ public class WebController {
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
if (group.getRoles().get(user.getId()) != Role.ADMIN) { if (group.getRoles().get(user.getId()) != Role.ADMIN) {
return "error"; throw new NoAccessException("");
} }
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId)); controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
@ -346,4 +399,9 @@ public class WebController {
} }
return "redirect:/gruppen2/details/members/" + groupId; return "redirect:/gruppen2/details/members/" + groupId;
} }
@GetMapping("*")
public String defaultLink() throws EventException {
throw new PageNotFoundException("\uD83D\uDE41");
}
} }

View File

@ -32,14 +32,14 @@ public class AddUserEvent extends Event {
} }
@Override @Override
public void applyEvent(Group group) throws EventException { protected void applyEvent(Group group) throws EventException {
User user = new User(this.userId, this.givenname, this.familyname, this.email); User user = new User(this.userId, this.givenname, this.familyname, this.email);
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
throw new UserAlreadyExistsException(this.getClass().toString()); throw new UserAlreadyExistsException(this.getClass().toString());
} }
if (group.getMembers().size() == group.getUserMaximum()){ if (group.getMembers().size() == group.getUserMaximum()) {
throw new GroupFullException(this.getClass().toString()); throw new GroupFullException(this.getClass().toString());
} }

View File

@ -28,7 +28,7 @@ public class CreateGroupEvent extends Event {
} }
@Override @Override
public void applyEvent(Group group) { protected void applyEvent(Group group) {
group.setId(this.groupId); group.setId(this.groupId);
group.setParent(this.groupParent); group.setParent(this.groupParent);
group.setType(this.groupType); group.setType(this.groupType);

View File

@ -15,7 +15,7 @@ public class DeleteGroupEvent extends Event {
} }
@Override @Override
public void applyEvent(Group group) { protected void applyEvent(Group group) {
group.getRoles().clear(); group.getRoles().clear();
group.getMembers().clear(); group.getMembers().clear();
group.setTitle(null); group.setTitle(null);

View File

@ -21,7 +21,7 @@ public class DeleteUserEvent extends Event {
} }
@Override @Override
public void applyEvent(Group group) throws EventException { protected void applyEvent(Group group) throws EventException {
for (User user : group.getMembers()) { for (User user : group.getMembers()) {
if (user.getId().equals(this.userId)) { if (user.getId().equals(this.userId)) {
group.getMembers().remove(user); group.getMembers().remove(user);

View File

@ -24,7 +24,7 @@ public class UpdateGroupDescriptionEvent extends Event {
} }
@Override @Override
public void applyEvent(Group group) { protected void applyEvent(Group group) {
if (this.newGroupDescription.isEmpty()) { if (this.newGroupDescription.isEmpty()) {
throw new NoValueException(this.getClass().toString()); throw new NoValueException(this.getClass().toString());
} }

View File

@ -24,7 +24,7 @@ public class UpdateGroupTitleEvent extends Event {
} }
@Override @Override
public void applyEvent(Group group) { protected void applyEvent(Group group) {
if (this.getNewGroupTitle().isEmpty()) { if (this.getNewGroupTitle().isEmpty()) {
throw new NoValueException(this.getClass().toString()); throw new NoValueException(this.getClass().toString());
} }

View File

@ -25,7 +25,7 @@ public class UpdateRoleEvent extends Event {
} }
@Override @Override
public void applyEvent(Group group) throws UserNotFoundException { protected void applyEvent(Group group) throws UserNotFoundException {
if (group.getRoles().containsKey(this.userId)) { if (group.getRoles().containsKey(this.userId)) {
group.getRoles().put(this.userId, this.newRole); group.getRoles().put(this.userId, this.newRole);
return; return;

View File

@ -5,7 +5,7 @@ import org.springframework.http.HttpStatus;
public class GroupFullException extends EventException { public class GroupFullException extends EventException {
public GroupFullException(String info) { public GroupFullException(String info) {
super(HttpStatus.INTERNAL_SERVER_ERROR, "Der User existiert bereits.", info); super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Gruppe hat die maximale Midgliederanzahl bereits erreicht!", info);
} }
} }

View File

@ -0,0 +1,10 @@
package mops.gruppen2.domain.exception;
import org.springframework.http.HttpStatus;
public class NoAccessException extends EventException {
public NoAccessException(String info) {
super(HttpStatus.FORBIDDEN, "Hier hast du leider keinen Zugriff!", info);
}
}

View File

@ -0,0 +1,10 @@
package mops.gruppen2.domain.exception;
import org.springframework.http.HttpStatus;
public class PageNotFoundException extends EventException {
public PageNotFoundException(String info) {
super(HttpStatus.NOT_FOUND, "Die Seite wurde nicht gefunden!", info);
}
}

View File

@ -0,0 +1,8 @@
package mops.gruppen2.service;
import org.springframework.stereotype.Service;
@Service
public class SearchService {
}

View File

@ -5,7 +5,6 @@ import mops.gruppen2.domain.User;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupNotFoundException; import mops.gruppen2.domain.exception.GroupNotFoundException;
import mops.gruppen2.repository.EventRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -47,7 +46,7 @@ public class UserService {
List<Event> events = groupService.getGroupEvents(groupIds); List<Event> events = groupService.getGroupEvents(groupIds);
return groupService.projectEventList(events).get(0); return groupService.projectEventList(events).get(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@UserService");
} }
} }
} }

View File

@ -18,3 +18,4 @@ keycloak.use-resource-role-mappings=true
keycloak.autodetect-bearer-only=true keycloak.autodetect-bearer-only=true
keycloak.confidential-port=443 keycloak.confidential-port=443
server.error.include-stacktrace=always server.error.include-stacktrace=always
server.port=8080

View File

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en"
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
xmlns="http://www.w3.org/1999/html"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>Gruppenerstellung</title>
<th:block th:fragment="headcontent">
<!-- Links, Skripts, Styles hier einfügen! -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</th:block>
</head>
<body>
<header>
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation"
th:switch="${account.getRoles().contains('orga')}">
<ul>
<li class="active">
<a href="/" th:href="@{/gruppen2}">Gruppen</a>
</li>
<li th:case="${true}">
<a href="/createOrga" th:href="@{/gruppen2/createOrga}">Erstellen</a>
</li>
<li th:case="${false}">
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
</li>
<li>
<a href="/findGroup" th:href="@{/gruppen2/findGroup}">Suche</a>
</li>
</ul>
</nav>
</header>
<main th:fragment="bodycontent">
<div class="container-fluid">
<div class="row">
<div class="col-10">
<h1>Metadaten ändern</h1>
<form action="/gruppen2/details/changeMetadata" method="post">
<div class="shadow-sm p-2"
style=" border: 10px solid aliceblue; background: aliceblue">
<div class="form-group">
<label for="title">Titel</label>
<input class="form-control" id="title" required
th:name="title" th:value="${title}" type="text">
</div>
<div class="form-group">
<label for="description">Beschreibung</label>
<textarea class="form-control" id="description" required rows="3"
th:name="description"
th:text="${description}"></textarea>
</div>
<div class="form-group pt-4">
<button class="btn btn-primary"
style="background: #52a1eb; border-style: none"
th:if="${roles.get(user.getId()) == admin}"
th:name="groupId"
th:value="${groupId}"
type="submit">Speichern
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</main>
</body>
</html>

View File

@ -6,7 +6,8 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Gruppendetails</title> <title>Gruppendetails</title>
<th:block th:fragment="headcontent"> <th:block th:fragment="headcontent">
<!-- Links, Skripts, Styles hier einfügen! --> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
rel="stylesheet">
</th:block> </th:block>
</head> </head>
<body> <body>
@ -31,8 +32,16 @@
<main th:fragment="bodycontent"> <main th:fragment="bodycontent">
<div class="container-fluid"> <div class="container-fluid">
<div> <div>
<div class="shadow-sm p-4 col-8" style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue"> <div class="shadow-sm p-4 col-8"
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word" th:text="${group.getTitle()}"></h1> style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue">
<div class="row">
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word; width: 95%"
th:text="${group.getTitle()}"></h1>
<a class="fa fa-pencil"
style="font-size:30px; width: 5%"
th:href="@{/gruppen2/details/changeMetadata/{id}(id=${group.getId()})}"
th:if="${roles.get(user.getId()) == admin}"></a>
</div>
<h3> <h3>
<span class="badge badge-pill badge-dark" style="background: darkslategray" <span class="badge badge-pill badge-dark" style="background: darkslategray"
th:if='${group.getVisibility() == group.getVisibility().PRIVATE }'>Private Gruppe</span> th:if='${group.getVisibility() == group.getVisibility().PRIVATE }'>Private Gruppe</span>
@ -42,6 +51,23 @@
th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung</span> th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung</span>
<span class="badge badge-pill badge-info" style="background: mediumorchid" <span class="badge badge-pill badge-info" style="background: mediumorchid"
th:text="${parent.getTitle()}">Parent</span> th:text="${parent.getTitle()}">Parent</span>
<div class="input-group mb-3" style="margin-top: 10px"
th:if="${group.getVisibility() == group.getVisibility().PRIVATE}">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-default"
style="background: #52a1eb">Einladungslink:</span>
</div>
<input aria-describedby="basic-addon2" aria-label="Recipient's username"
class="form-control"
id="groupLink" readonly style="background: white" th:value="${link}"
type="text">
<div class="input-group-append">
<button class="btn btn-outline-secondary" onclick="copyLink()"
type="button">Link kopieren
</button>
</div>
</div>
</h3> </h3>
<br> <br>
<div class="shadow-sm p-4" style="background: white"> <div class="shadow-sm p-4" style="background: white">
@ -100,6 +126,16 @@
</div> </div>
</div> </div>
</div> </div>
<script>
function copyLink() {
var copyText = document.getElementById("groupLink");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
}
</script>
</main> </main>
</body> </body>
</html> </html>

View File

@ -27,8 +27,10 @@
</div> </div>
</div> </div>
<button style="color: #52a1eb"> <button class="btn btn-primary"
<a style="color: white" class="btn btn-primary btn-lg" href="#" onclick="window.history.back(-1);return false;" role="button">Zurück</a> style="background: #52a1eb; border-style: none;">
<a href="#" onclick="window.history.back(-1);return false;" role="button"
style="color: white">Zurück</a>
</button> </button>
</div> </div>
</div> </div>

View File

@ -56,8 +56,8 @@
<th scope="col">Mitgliederanzahl</th> <th scope="col">Mitgliederanzahl</th>
</tr> </tr>
</thead> </thead>
<tbody th:each="gruppe : ${gruppen}"> <tbody>
<tr> <tr th:each="gruppe : ${gruppen}">
<th scope="row"> <th scope="row">
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}" <a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}"
th:text="${gruppe.title}">Gruppenname</a> th:text="${gruppe.title}">Gruppenname</a>

View File

@ -0,0 +1,201 @@
package mops.gruppen2;
import com.github.javafaker.Faker;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.DeleteUserEvent;
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 java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class TestBuilder {
private static final Faker faker = new Faker();
/**
* Generiert ein EventLog mit mehreren Gruppen und Usern.
*
* @param count Gruppenanzahl
* @param membercount Gesamte Mitgliederanzahl
* @return Eventliste
*/
public static List<Event> completeGroups(int count, int membercount) {
int memPerGroup = membercount / count;
return IntStream.rangeClosed(0, count)
.parallel()
.mapToObj(i -> completeGroup(memPerGroup))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
public static List<Event> completeGroup(int membercount) {
List<Event> eventList = new ArrayList<>();
UUID groupId = UUID.randomUUID();
eventList.add(createGroupEvent(groupId));
eventList.add(updateGroupTitleEvent(groupId));
eventList.add(updateGroupDescriptionEvent(groupId));
eventList.addAll(addUserEvents(membercount, groupId));
return eventList;
}
public static List<Event> completeGroup() {
return completeGroup(100);
}
/**
* Generiert mehrere CreateGroupEvents, 1 <= groupId <= count.
*
* @param count Anzahl der verschiedenen Gruppen
* @return Eventliste
*/
public static List<CreateGroupEvent> createGroupEvents(int count) {
return IntStream.rangeClosed(0, count)
.parallel()
.mapToObj(i -> createGroupEvent())
.collect(Collectors.toList());
}
public static CreateGroupEvent createGroupEvent(UUID groupId) {
return new CreateGroupEvent(
groupId,
faker.random().hex(),
null,
GroupType.SIMPLE,
Visibility.PUBLIC,
10000000L
);
}
public static CreateGroupEvent createGroupEvent() {
return createGroupEvent(UUID.randomUUID());
}
/**
* Generiert mehrere AddUserEvents für eine Gruppe, 1 <= user_id <= count.
*
* @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.rangeClosed(1, count)
.parallel()
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
.collect(Collectors.toList());
}
public static AddUserEvent addUserEvent(UUID groupId, String userId) {
String firstname = firstname();
String lastname = lastname();
return new AddUserEvent(
groupId,
userId,
firstname,
lastname,
firstname + "." + lastname + "@mail.de"
);
}
public static AddUserEvent addUserEvent(UUID groupId) {
return addUserEvent(groupId, faker.random().hex());
}
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());
Collections.shuffle(shuffle);
for (Event event : shuffle) {
removeEvents.add(new DeleteUserEvent(event.getGroupId(), event.getUserId()));
if (removeEvents.size() >= count) {
break;
}
}
return removeEvents;
}
/**
* Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird.
*
* @param group Gruppe welche geleert wird
* @return Eventliste
*/
public static List<DeleteUserEvent> deleteUserEvents(Group group) {
return group.getMembers().parallelStream()
.map(user -> deleteUserEvent(group.getId(), user.getId()))
.collect(Collectors.toList());
}
public static DeleteUserEvent deleteUserEvent(UUID groupId, String userId) {
return new DeleteUserEvent(
groupId,
userId
);
}
public static UpdateGroupDescriptionEvent updateGroupDescriptionEvent(UUID groupId) {
return new UpdateGroupDescriptionEvent(
groupId,
faker.random().hex(),
quote()
);
}
public static UpdateGroupTitleEvent updateGroupTitleEvent(UUID groupId) {
return new UpdateGroupTitleEvent(
groupId,
faker.random().hex(),
champion()
);
}
public static UpdateRoleEvent randomUpdateRoleEvent(UUID groupId, String userId, Role role) {
return new UpdateRoleEvent(
groupId,
userId,
role
);
}
private static String firstname() {
return clean(faker.name().firstName());
}
private static String lastname() {
return clean(faker.name().lastName());
}
private static String champion() {
return clean(faker.leagueOfLegends().champion());
}
private static String quote() {
return clean(faker.leagueOfLegends().quote());
}
private static String clean(String string) {
return string.replaceAll("['\";,]", "");
}
}