Merge remote-tracking branch 'origin/master' into JavaDocComments
# Conflicts: # src/main/java/mops/gruppen2/controller/WebController.java # src/main/java/mops/gruppen2/service/ControllerService.java
This commit is contained in:
@ -68,7 +68,7 @@ public class WebController {
|
|||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||||
@GetMapping("/createOrga")
|
@GetMapping("/createOrga")
|
||||||
public String createOrga(KeycloakAuthenticationToken token, Model model) {
|
public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||||
@ -77,7 +77,7 @@ public class WebController {
|
|||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||||
@PostMapping("/createOrga")
|
@PostMapping("/createOrga")
|
||||||
public String pCreateOrga(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(value = "visibility", required = false) Boolean visibility,
|
||||||
@ -89,17 +89,16 @@ public class WebController {
|
|||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
UUID parentUUID = controllerService.getUUID(parent);
|
UUID parentUUID = controllerService.getUUID(parent);
|
||||||
List<User> userList = new ArrayList<>();
|
|
||||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||||
Group group = userService.getGroupById(controllerService.createOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID));
|
controllerService.createGroupAsOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file);
|
||||||
userList = validationService.checkFile(file, userList, group.getId().toString(), group, account);
|
|
||||||
controllerService.addUserList(userList, group.getId());
|
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_studentin"})
|
@RolesAllowed({"ROLE_studentin"})
|
||||||
@GetMapping("/createStudent")
|
@GetMapping("/createStudent")
|
||||||
public String createStudent(KeycloakAuthenticationToken token, Model model) {
|
public String createGroupAsStudent(KeycloakAuthenticationToken token, Model model) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||||
@ -108,7 +107,7 @@ public class WebController {
|
|||||||
|
|
||||||
@RolesAllowed({"ROLE_studentin"})
|
@RolesAllowed({"ROLE_studentin"})
|
||||||
@PostMapping("/createStudent")
|
@PostMapping("/createStudent")
|
||||||
public String pCreateStudent(KeycloakAuthenticationToken token,
|
public String postCreateGroupAsStudent(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(value = "visibility", required = false) Boolean visibility,
|
||||||
@ -119,7 +118,7 @@ public class WebController {
|
|||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
UUID parentUUID = controllerService.getUUID(parent);
|
UUID parentUUID = controllerService.getUUID(parent);
|
||||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||||
controllerService.createGroup(account, title, description, visibility, maxInfiniteUsers, userMaximum, parentUUID);
|
controllerService.createGroup(account, title, description, visibility, null, maxInfiniteUsers, userMaximum, parentUUID);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.Role;
|
import mops.gruppen2.domain.Role;
|
||||||
@ -15,14 +16,19 @@ 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.UserNotFoundException;
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
|
import mops.gruppen2.domain.exception.WrongFileException;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.CharConversionException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static mops.gruppen2.domain.Role.ADMIN;
|
import static mops.gruppen2.domain.Role.ADMIN;
|
||||||
|
|
||||||
@ -49,57 +55,15 @@ 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 visibility, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) {
|
public UUID createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent) {
|
||||||
Visibility visibility1;
|
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
|
||||||
|
|
||||||
if (maxInfiniteUsers) {
|
|
||||||
userMaximum = 100000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
visibility = visibility == null;
|
|
||||||
|
|
||||||
if (visibility) {
|
|
||||||
visibility1 = Visibility.PUBLIC;
|
|
||||||
} else {
|
|
||||||
visibility1 = Visibility.PRIVATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
|
||||||
UUID groupId = UUID.randomUUID();
|
UUID groupId = UUID.randomUUID();
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
|
|
||||||
eventService.saveEvent(createGroupEvent);
|
|
||||||
|
|
||||||
addUser(account, groupId);
|
GroupType groupType = setGroupType(isLecture);
|
||||||
updateTitle(account, groupId, title);
|
|
||||||
updateDescription(account, groupId, description);
|
|
||||||
updateRole(account.getName(), groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) {
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum);
|
||||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
|
||||||
|
|
||||||
if (maxInfiniteUsers) {
|
|
||||||
userMaximum = 100000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
visibility = visibility == null;
|
|
||||||
lecture = lecture != null;
|
|
||||||
Visibility visibility1;
|
|
||||||
UUID groupId = UUID.randomUUID();
|
|
||||||
if (visibility) {
|
|
||||||
visibility1 = Visibility.PUBLIC;
|
|
||||||
} else {
|
|
||||||
visibility1 = Visibility.PRIVATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GroupType groupType;
|
|
||||||
if (lecture) {
|
|
||||||
groupType = GroupType.LECTURE;
|
|
||||||
} else {
|
|
||||||
groupType = GroupType.SIMPLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, visibility1, userMaximum);
|
|
||||||
eventService.saveEvent(createGroupEvent);
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
|
||||||
addUser(account, groupId);
|
addUser(account, groupId);
|
||||||
@ -110,6 +74,79 @@ public class ControllerService {
|
|||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void createGroupAsOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) {
|
||||||
|
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||||
|
|
||||||
|
List<User> newUsers = readCsvFile(file);
|
||||||
|
|
||||||
|
List<User> oldUsers = new ArrayList<>();
|
||||||
|
User user = new User(account.getName(), "", "", "");
|
||||||
|
oldUsers.add(user);
|
||||||
|
|
||||||
|
removeOldUsersFromNewUsers(oldUsers, newUsers);
|
||||||
|
|
||||||
|
userMaximum = adjustUserMaximum((long) newUsers.size(), 1L, userMaximum);
|
||||||
|
|
||||||
|
UUID groupId = createGroup(account, title, description, isVisibilityPrivate, isLecture, isMaximumInfinite, userMaximum, parent);
|
||||||
|
|
||||||
|
addUserList(newUsers, groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeOldUsersFromNewUsers(List<User> oldUsers, List<User> newUsers) {
|
||||||
|
for (User oldUser : oldUsers) {
|
||||||
|
newUsers.remove(oldUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) {
|
||||||
|
isMaximumInfinite = isMaximumInfinite != null;
|
||||||
|
|
||||||
|
if (isMaximumInfinite) {
|
||||||
|
userMaximum = 100000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
return userMaximum;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Visibility setGroupVisibility(Boolean isVisibilityPrivate) {
|
||||||
|
isVisibilityPrivate = isVisibilityPrivate != null;
|
||||||
|
|
||||||
|
if (isVisibilityPrivate) {
|
||||||
|
return Visibility.PRIVATE;
|
||||||
|
} else {
|
||||||
|
return Visibility.PUBLIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GroupType setGroupType(Boolean isLecture) {
|
||||||
|
isLecture = isLecture != null;
|
||||||
|
if (isLecture) {
|
||||||
|
return GroupType.LECTURE;
|
||||||
|
} else {
|
||||||
|
return GroupType.SIMPLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<User> readCsvFile(MultipartFile file) throws EventException, IOException {
|
||||||
|
if (!file.isEmpty()) {
|
||||||
|
try {
|
||||||
|
List<User> userList = CsvService.read(file.getInputStream());
|
||||||
|
return userList.stream().distinct().collect(Collectors.toList()); //filters duplicates from list
|
||||||
|
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
||||||
|
logger.warning("File konnte nicht gelesen werden");
|
||||||
|
throw new WrongFileException(file.getOriginalFilename());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long adjustUserMaximum(Long newUsers, Long oldUsers, Long maxUsers) {
|
||||||
|
if (oldUsers + newUsers > maxUsers) {
|
||||||
|
maxUsers = oldUsers + newUsers;
|
||||||
|
}
|
||||||
|
return maxUsers;
|
||||||
|
}
|
||||||
|
|
||||||
public void addUser(Account account, UUID groupId) {
|
public void addUser(Account account, UUID groupId) {
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
|||||||
@ -35,13 +35,17 @@
|
|||||||
<div class="shadow-sm p-4 col-8"
|
<div class="shadow-sm p-4 col-8"
|
||||||
style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue">
|
style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="col-11">
|
||||||
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word; width: 95%"
|
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word; width: 95%"
|
||||||
th:text="${group.getTitle()}"></h1>
|
th:text="${group.getTitle()}"></h1>
|
||||||
|
</div>
|
||||||
|
<div class="col-1">
|
||||||
<a class="fa fa-pencil"
|
<a class="fa fa-pencil"
|
||||||
style="font-size:30px; width: 5%"
|
style="font-size:30px; width: 5%"
|
||||||
th:href="@{/gruppen2/details/changeMetadata/{id}(id=${group.getId()})}"
|
th:href="@{/gruppen2/details/changeMetadata/{id}(id=${group.getId()})}"
|
||||||
th:if="${roles.get(user.getId()) == admin}"></a>
|
th:if="${roles.get(user.getId()) == admin}"></a>
|
||||||
</div>
|
</div>
|
||||||
|
</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user