Merge remote-tracking branch 'origin/master' into add-ValidationService
# Conflicts: # src/main/java/mops/gruppen2/controller/WebController.java # src/main/java/mops/gruppen2/service/ControllerService.java
This commit is contained in:
@ -108,11 +108,8 @@ public class WebController {
|
|||||||
@RequestParam(value = "parent", required = false) String parent) throws EventException {
|
@RequestParam(value = "parent", required = false) String parent) throws EventException {
|
||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
visibility = visibility == null;
|
|
||||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
|
||||||
UUID parentUUID = controllerService.getUUID(parent);
|
UUID parentUUID = controllerService.getUUID(parent);
|
||||||
controllerService.createGroup(account, title, description, visibility, maxInfiniteUsers, userMaximum, parentUUID);
|
controllerService.createGroup(account, title, description, visibility, maxInfiniteUsers, userMaximum, parentUUID);
|
||||||
|
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
package mops.gruppen2.domain.exception;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
public class BadParameterException extends EventException {
|
||||||
|
|
||||||
|
public BadParameterException(String info) {
|
||||||
|
super(HttpStatus.INTERNAL_SERVER_ERROR, "Fehlerhafter Parameter angegeben!", info);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -31,4 +31,13 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
|||||||
|
|
||||||
@Query("SELECT * FROM event WHERE event_type = :type")
|
@Query("SELECT * FROM event WHERE event_type = :type")
|
||||||
List<EventDTO> findAllEventsByType(@Param("type") String type);
|
List<EventDTO> findAllEventsByType(@Param("type") String type);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM event WHERE event_type = :type AND user_id = :userId")
|
||||||
|
List<EventDTO> findEventsByTypeAndUserId(@Param("type") String type, @Param("userId") String userId);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(*) FROM event WHERE event_type = :type AND group_id = :groupId")
|
||||||
|
Long countEventsByTypeAndGroupId(@Param("type") String type, @Param("groupId") String groupId);
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(*) FROM event WHERE group_id = :groupId AND user_id = :userId AND event_type = :type")
|
||||||
|
Long countEventsByGroupIdAndUserIdAndEventType(@Param("groupId") String groupId, @Param("userId") String userId, @Param("type") String type);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
|||||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||||
import mops.gruppen2.domain.exception.EventException;
|
import mops.gruppen2.domain.exception.EventException;
|
||||||
|
import mops.gruppen2.domain.exception.BadParameterException;
|
||||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
import mops.gruppen2.domain.exception.WrongFileException;
|
import mops.gruppen2.domain.exception.WrongFileException;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
@ -44,6 +45,26 @@ public class ControllerService {
|
|||||||
this.logger = Logger.getLogger("controllerServiceLogger");
|
this.logger = Logger.getLogger("controllerServiceLogger");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Überprüft ob alle Felder richtig gesetzt sind.
|
||||||
|
* @param description
|
||||||
|
* @param title
|
||||||
|
* @param userMaximum
|
||||||
|
*/
|
||||||
|
private void checkFields(String description, String title, Long userMaximum ) {
|
||||||
|
if(description == null) {
|
||||||
|
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(title == null) {
|
||||||
|
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userMaximum == null) {
|
||||||
|
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
|
* 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.
|
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
|
||||||
@ -53,20 +74,27 @@ public class ControllerService {
|
|||||||
* @param title Gruppentitel
|
* @param title Gruppentitel
|
||||||
* @param description Gruppenbeschreibung
|
* @param description Gruppenbeschreibung
|
||||||
*/
|
*/
|
||||||
public void createGroup(Account account, String title, String description, Boolean maxInfiniteUsers, Boolean visibility, Long userMaximum, UUID parent) throws EventException {
|
public void createGroup(Account account, String title, String description, Boolean visibility, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException {
|
||||||
Visibility visibility1;
|
Visibility visibility1;
|
||||||
UUID groupId = eventService.checkGroup();
|
UUID groupId = eventService.checkGroup();
|
||||||
|
|
||||||
|
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||||
|
|
||||||
|
|
||||||
|
if(maxInfiniteUsers) {
|
||||||
|
userMaximum = 100000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFields(description, title, userMaximum);
|
||||||
|
|
||||||
|
visibility = visibility == null;
|
||||||
|
|
||||||
if (visibility) {
|
if (visibility) {
|
||||||
visibility1 = Visibility.PUBLIC;
|
visibility1 = Visibility.PUBLIC;
|
||||||
} else {
|
} else {
|
||||||
visibility1 = Visibility.PRIVATE;
|
visibility1 = Visibility.PRIVATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(maxInfiniteUsers){
|
|
||||||
userMaximum = 100000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
|
||||||
eventService.saveEvent(createGroupEvent);
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
|
||||||
@ -78,12 +106,12 @@ public class ControllerService {
|
|||||||
|
|
||||||
public UUID createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException, IOException {
|
public UUID createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException, IOException {
|
||||||
List<User> userList = new ArrayList<>();
|
List<User> userList = new ArrayList<>();
|
||||||
if (userMaximum == null) {
|
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||||
|
if(maxInfiniteUsers) {
|
||||||
userMaximum = 100000L;
|
userMaximum = 100000L;
|
||||||
}
|
}
|
||||||
visibility = visibility == null;
|
visibility = visibility == null;
|
||||||
lecture = lecture != null;
|
lecture = lecture != null;
|
||||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
|
||||||
Visibility visibility1;
|
Visibility visibility1;
|
||||||
UUID groupId = eventService.checkGroup();
|
UUID groupId = eventService.checkGroup();
|
||||||
if (visibility) {
|
if (visibility) {
|
||||||
|
|||||||
@ -127,13 +127,13 @@ public class EventService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> findGroupIdsByUser(String userId) {
|
public List<UUID> findGroupIdsByUser(String userId) {
|
||||||
List<String> groupIDs = eventStore.findGroup_idsWhereUser_id(userId);
|
return eventStore.findGroup_idsWhereUser_id(userId).stream()
|
||||||
|
|
||||||
System.out.println(groupIDs);
|
|
||||||
|
|
||||||
return groupIDs.stream()
|
|
||||||
.map(UUID::fromString)
|
.map(UUID::fromString)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean userInGroup(UUID groupId, String userId) {
|
||||||
|
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
|
||||||
|
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,31 +69,37 @@ public class GroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sucht alle Zeilen in der DB mit visibility=true.
|
* Wird verwendet bei der Suche nach Gruppen: Titel, Beschreibung werden benötigt.
|
||||||
* Erstellt eine Liste aus öffentlichen Gruppen (ohen bereits beigetretenen Gruppen).
|
* Außerdem wird beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
|
||||||
*
|
*
|
||||||
* @return Liste von projizierten Gruppen
|
* @return Liste von projizierten Gruppen
|
||||||
* @throws EventException Projektionsfehler
|
* @throws EventException Projektionsfehler
|
||||||
*/
|
*/
|
||||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||||
List<Group> visibleGroups = projectEventList(createEvents);
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
||||||
|
|
||||||
List<UUID> userGroupIds = eventService.findGroupIdsByUser(userId);
|
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||||
|
|
||||||
return visibleGroups.parallelStream()
|
return visibleGroups.parallelStream()
|
||||||
.filter(group -> group.getType() != null)
|
.filter(group -> group.getType() != null)
|
||||||
.filter(group -> !userGroupIds.contains(group.getId()))
|
.filter(group -> !eventService.userInGroup(group.getId(), userId))
|
||||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wird verwendet beim Gruppe erstellen bei der Parent-Auswahl: nur Titel benötigt.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws EventException
|
||||||
|
*/
|
||||||
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
|
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
|
||||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||||
|
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||||
|
|
||||||
List<Group> visibleGroups = projectEventList(createEvents);
|
List<Group> visibleGroups = projectEventList(createEvents);
|
||||||
@ -115,6 +121,10 @@ public class GroupService {
|
|||||||
* @throws EventException Projektionsfehler
|
* @throws EventException Projektionsfehler
|
||||||
*/
|
*/
|
||||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||||
|
if (search.isEmpty()) {
|
||||||
|
return getAllGroupWithVisibilityPublic(account.getName());
|
||||||
|
}
|
||||||
|
|
||||||
return getAllGroupWithVisibilityPublic(account.getName())
|
return getAllGroupWithVisibilityPublic(account.getName())
|
||||||
.parallelStream()
|
.parallelStream()
|
||||||
.filter(group ->
|
.filter(group ->
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
<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>
|
||||||
<li class="active">
|
<li>
|
||||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||||
</li>
|
</li>
|
||||||
<li th:case="${true}">
|
<li th:case="${true}">
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<li th:case="${false}">
|
<li th:case="${false}">
|
||||||
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li class="active">
|
||||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -53,8 +53,8 @@
|
|||||||
<form method="post" action="/gruppen2/detailsBeitreten">
|
<form method="post" action="/gruppen2/detailsBeitreten">
|
||||||
<button class="btn btn-primary"
|
<button class="btn btn-primary"
|
||||||
style="background: #52a1eb; border-style: none;"
|
style="background: #52a1eb; border-style: none;"
|
||||||
th:href="@{/gruppen2/detailsBeitreten(id=${group.getId()})}"
|
th:href="@{/gruppen2/detailsBeitreten}"
|
||||||
th:name="id" th:value="${group.id}"
|
th:name="id" th:value="${group.getId()}"
|
||||||
type="submit">Gruppe beitreten
|
type="submit">Gruppe beitreten
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
|
|
||||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
|
|
||||||
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
|
||||||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" rel="stylesheet">
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Seite nicht gefunden</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="mx-auto" style="vertical-align: border-radius: 5px; center; horiz-align: center; top: 50%; left: 50%;">
|
|
||||||
<div class="jumbotron" style="background: aliceblue">
|
|
||||||
<div class="container">
|
|
||||||
<h1 class="display-3">Kein Zugriff auf die Gruppe</h1>
|
|
||||||
<p class="lead">Sorry, du hast keine Berechtigung auf diese Funktionen der Gruppe zuzugreifen</p><br>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="container">
|
|
||||||
<p><a class="btn btn-primary btn-lg" href="#" onclick="window.history.back(-1);return false;" role="button">Zurück</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -49,23 +49,26 @@
|
|||||||
<br>
|
<br>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
||||||
<thead th:if="${!gruppen.isEmpty()}">
|
<thead th:if='${!gruppen.isEmpty()}'>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Gruppenname</th>
|
<th scope="col">Gruppenname</th>
|
||||||
<th scope="col">Beschreibung</th>
|
<th scope="col">Beschreibung</th>
|
||||||
<th scope="col">Mitgliederanzahl</th>
|
<th scope="col">Max. Mitgliederanzahl</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="gruppe : ${gruppen}">
|
<tr th:each="gruppe : ${gruppen}" th:switch="${gruppe.getUserMaximum() != 100000}">
|
||||||
<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.getTitle()}">Gruppenname</a>
|
||||||
</th>
|
</th>
|
||||||
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">
|
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">
|
||||||
Beschreibung
|
Beschreibung
|
||||||
</td>
|
</td>
|
||||||
<td th:text="${gruppe.getMembers().size()}">Mitgliederanzahl</td>
|
<td th:case="${true}">
|
||||||
|
<a th:text="${gruppe.getUserMaximum()}"></a>
|
||||||
|
</td>
|
||||||
|
<td th:case="${false}">unbegrenzt</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user