1

remove simple to fix warnings

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-29 00:15:22 +01:00
parent eb11751663
commit 98607dcf49
33 changed files with 672 additions and 545 deletions

View File

@ -4,7 +4,6 @@ import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.PageNotFoundException;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.ControllerService;
@ -27,25 +26,27 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
//TODO: Remove duplicate Injections
@Controller
@SessionScope
@RequestMapping("/gruppen2")
public class WebController {
private final KeyCloakService keyCloakService;
private final GroupService groupService;
private final UserService userService;
private final ControllerService controllerService;
private final ValidationService validationService;
private final InviteService inviteService;
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService, InviteService inviteService) {
this.keyCloakService = keyCloakService;
public WebController(GroupService groupService,
UserService userService,
ControllerService controllerService,
ValidationService validationService,
InviteService inviteService) {
this.groupService = groupService;
this.userService = userService;
this.controllerService = controllerService;
@ -58,30 +59,43 @@ public class WebController {
*
* @param token toller token
* @param model tolles model
*
* @return index.html
*/
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("")
public String index(KeycloakAuthenticationToken token, Model model) {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
public String index(KeycloakAuthenticationToken token,
Model model) {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Account account = KeyCloakService.createAccountFromPrincipal(token);
//TODO: new Contructor/method
User user = new User(account.getName(),
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
model.addAttribute("account", account);
model.addAttribute("gruppen", userService.getUserGroups(user));
model.addAttribute("user", user);
return "index";
}
//TODO: CreateController
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
@GetMapping("/createOrga")
public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) {
Account account = keyCloakService.createAccountFromPrincipal(token);
public String createGroupAsOrga(KeycloakAuthenticationToken token,
Model model) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
model.addAttribute("account", account);
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
return "createOrga";
}
//TODO: CreateController
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
@PostMapping("/createOrga")
@CacheEvict(value = "groups", allEntries = true)
@ -95,65 +109,93 @@ public class WebController {
@RequestParam(value = "parent", required = false) String parent,
@RequestParam(value = "file", required = false) MultipartFile file) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
UUID parentUUID = controllerService.getUUID(parent);
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
controllerService.createGroupAsOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file);
return "redirect:/gruppen2/";
controllerService.createGroupAsOrga(account,
title,
description,
visibility,
lecture,
maxInfiniteUsers,
userMaximum,
parentUUID,
file);
return "redirect:/gruppen2";
}
@RolesAllowed({"ROLE_studentin"})
//TODO: CreateController
@RolesAllowed("ROLE_studentin")
@GetMapping("/createStudent")
public String createGroupAsStudent(KeycloakAuthenticationToken token, Model model) {
Account account = keyCloakService.createAccountFromPrincipal(token);
public String createGroupAsStudent(KeycloakAuthenticationToken token,
Model model) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
model.addAttribute("account", account);
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
return "createStudent";
}
@RolesAllowed({"ROLE_studentin"})
//TODO: CreateController
@RolesAllowed("ROLE_studentin")
@PostMapping("/createStudent")
@CacheEvict(value = "groups", allEntries = true)
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
@RequestParam("title") String title,
@RequestParam("description") String description,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam("userMaximum") Long userMaximum,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers,
@RequestParam(value = "parent", required = false) String parent) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
UUID parentUUID = controllerService.getUUID(parent);
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
controllerService.createGroup(account, title, description, visibility, null, maxInfiniteUsers, userMaximum, parentUUID);
return "redirect:/gruppen2/";
controllerService.createGroup(account,
title,
description,
visibility,
null,
maxInfiniteUsers,
userMaximum,
parentUUID);
return "redirect:/gruppen2";
}
//TODO: CreateController
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
@PostMapping("/details/members/addUsersFromCsv")
@CacheEvict(value = "groups", allEntries = true)
public String addUsersFromCsv(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
Account account = keyCloakService.createAccountFromPrincipal(token);
@RequestParam(value = "file", required = false) MultipartFile file) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
controllerService.addUsersFromCsv(account, file, groupId);
return "redirect:/gruppen2/details/members/" + groupId;
}
//TODO: DetailsController
@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());
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));
UUID parentId = group.getParent();
Group parent = new Group();
validationService.throwIfNoAdmin(group, user);
@ -164,9 +206,11 @@ public class WebController {
model.addAttribute("roles", group.getRoles());
model.addAttribute("groupId", group.getId());
model.addAttribute("user", user);
return "changeMetadata";
}
//TODO: DetailsController
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/details/changeMetadata")
@CacheEvict(value = "groups", allEntries = true)
@ -175,7 +219,8 @@ public class WebController {
@RequestParam("description") String description,
@RequestParam("groupId") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
//TODO: new Constructor/Method
User user = new User(account.getName(), "", "", "");
Group group = userService.getGroupById(UUID.fromString(groupId));
@ -183,21 +228,25 @@ public class WebController {
validationService.checkFields(title, description);
controllerService.changeMetaData(account, group, title, description);
return "redirect:/gruppen2/details/" + groupId;
}
//TODO: SearchController
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/findGroup")
public String findGroup(KeycloakAuthenticationToken token,
Model model,
@RequestParam(value = "suchbegriff", required = false) String search) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
List<Group> groups = new ArrayList<>();
groups = validationService.checkSearch(search, groups, account);
model.addAttribute("account", account);
model.addAttribute("gruppen", groups);
model.addAttribute("inviteService", inviteService);
return "search";
}
@ -209,8 +258,11 @@ public class WebController {
@PathVariable("id") String groupId) {
Group group = userService.getGroupById(UUID.fromString(groupId));
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(),
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
UUID parentId = group.getParent();
String actualURL = request.getRequestURL().toString();
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
@ -237,6 +289,7 @@ public class WebController {
if (validationService.checkIfAdmin(group, user)) {
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroupId(group.getId()));
}
return "detailsMember";
}
@ -244,9 +297,14 @@ public class WebController {
@PostMapping("/detailsBeitreten")
@CacheEvict(value = "groups", allEntries = true)
public String joinGroup(KeycloakAuthenticationToken token,
Model model, @RequestParam("id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Model model,
@RequestParam("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));
validationService.throwIfUserAlreadyInGroup(group, user);
@ -255,7 +313,8 @@ public class WebController {
controllerService.addUser(account, UUID.fromString(groupId));
model.addAttribute("account", account);
return "redirect:/gruppen2/";
return "redirect:/gruppen2";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@ -263,14 +322,16 @@ public class WebController {
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
Model model,
@RequestParam("id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId));
UUID parentId = group.getParent();
Group parent = controllerService.getParent(parentId);
//TODO: Replace
User user = new User(account.getName(), "", "", "");
model.addAttribute("account", account);
if (validationService.checkIfUserInGroup(group, user)){
if (validationService.checkIfUserInGroup(group, user)) {
return "redirect:/gruppen2/details/" + groupId;
}
@ -281,17 +342,17 @@ public class WebController {
return "detailsNoMember";
}
//TODO: Muss post-mapping sein
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/acceptinvite/{link}")
public String acceptInvite(KeycloakAuthenticationToken token,
Model model,
@PathVariable("link") String link) {
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
validationService.throwIfGroupNotExisting(group.getTitle());
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("account", KeyCloakService.createAccountFromPrincipal(token));
model.addAttribute("group", group);
if (group.getVisibility() == Visibility.PUBLIC) {
@ -307,15 +368,18 @@ public class WebController {
public String postAcceptInvite(KeycloakAuthenticationToken token,
@RequestParam("id") String groupId) {
Account acc = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
User user = new User(account.getName(),
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
if (!validationService.checkIfUserInGroup(userService.getGroupById(UUID.fromString(groupId)), user)) {
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
controllerService.addUser(KeyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
}
return "redirect:/gruppen2/";
return "redirect:/gruppen2";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@ -323,12 +387,14 @@ public class WebController {
@CacheEvict(value = "groups", allEntries = true)
public String pLeaveGroup(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), "", "", "");
Group group = userService.getGroupById(UUID.fromString(groupId));
controllerService.deleteUser(account, user, group);
return "redirect:/gruppen2/";
return "redirect:/gruppen2";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@ -336,22 +402,28 @@ public class WebController {
@CacheEvict(value = "groups", allEntries = true)
public String pDeleteGroup(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(),
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, user);
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
return "redirect:/gruppen2/";
return "redirect:/gruppen2";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/details/members/{id}")
public String editMembers(Model model,
KeycloakAuthenticationToken token,
public String editMembers(KeycloakAuthenticationToken token,
Model model,
@PathVariable("id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId));
User user = new User(account.getName(), "", "", "");
@ -361,6 +433,7 @@ public class WebController {
model.addAttribute("members", group.getMembers());
model.addAttribute("group", group);
model.addAttribute("admin", Role.ADMIN);
return "editMembers";
}
@ -370,7 +443,8 @@ public class WebController {
public String changeRole(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId));
User principle = new User(account.getName(), "", "", "");
User user = new User(userId, "", "", "");
@ -379,35 +453,38 @@ public class WebController {
controllerService.changeRole(account, user, group);
group = userService.getGroupById(UUID.fromString(groupId));
if (!validationService.checkIfAdmin(group, principle)) {
return "redirect:/gruppen2/details/" + groupId;
}
return "redirect:/gruppen2/details/members/" + groupId;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/details/members/changeMaximum")
@CacheEvict(value = "groups", allEntries = true)
public String changeMaxSize(@RequestParam("maximum") Long maximum,
@RequestParam("group_id") String groupId,
KeycloakAuthenticationToken token) {
Account account = keyCloakService.createAccountFromPrincipal(token);
public String changeMaxSize(KeycloakAuthenticationToken token,
@RequestParam("maximum") Long maximum,
@RequestParam("group_id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfNewMaximumIsValid(maximum, group);
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
return "redirect:/gruppen2/details/members/" + groupId;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/details/members/deleteUser")
@CacheEvict(value = "groups", allEntries = true)
public String deleteUser(@RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId,
KeycloakAuthenticationToken token) {
Account account = keyCloakService.createAccountFromPrincipal(token);
public String deleteUser(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User principle = new User(account.getName(), "", "", "");
User user = new User(userId, "", "", "");
Group group = userService.getGroupById(UUID.fromString(groupId));
@ -417,13 +494,14 @@ public class WebController {
controllerService.deleteUser(account, user, group);
if (!validationService.checkIfUserInGroup(group, principle)) {
return "redirect:/gruppen2/";
return "redirect:/gruppen2";
}
return "redirect:/gruppen2/details/members/" + groupId;
}
@GetMapping("*")
public String defaultLink() throws EventException {
public String defaultLink() throws PageNotFoundException {
throw new PageNotFoundException("\uD83D\uDE41");
}
}