some uuid improvements
This commit is contained in:
@ -10,7 +10,6 @@ import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.service.APIFormatterService;
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -18,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Ein Beispiel für eine API mit Swagger.
|
||||
@ -35,7 +35,7 @@ public class APIController {
|
||||
}
|
||||
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
@Secured("ROLE_api_user")
|
||||
//@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
||||
public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
@ -44,17 +44,19 @@ public class APIController {
|
||||
}
|
||||
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
@Secured("ROLE_api_user")
|
||||
//@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
||||
public List<UUID> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
|
||||
return eventService.findGroupIdsByUser(teilnehmer);
|
||||
public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
|
||||
return eventService.findGroupIdsByUser(teilnehmer).stream()
|
||||
.map(UUID::toString)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
@Secured("ROLE_api_user")
|
||||
//@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable UUID groupId) throws EventException {
|
||||
List<Event> eventList = eventService.getEventsOfGroup(groupId);
|
||||
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
|
||||
List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId));
|
||||
List<Group> groups = groupService.projectEventList(eventList);
|
||||
|
||||
return groups.get(0);
|
||||
|
@ -17,6 +17,8 @@ import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -33,7 +35,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@ -45,14 +46,14 @@ public class Gruppen2Controller {
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
private final Gruppen2Config gruppen2Config;
|
||||
private final Logger logger;
|
||||
private final Logger logger = LoggerFactory.getLogger("Gruppen2ControllerLogger");
|
||||
;
|
||||
|
||||
public Gruppen2Controller(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, Gruppen2Config gruppen2Config) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
logger = Logger.getLogger("Gruppen2ControllerLogger");
|
||||
this.gruppen2Config = gruppen2Config;
|
||||
}
|
||||
|
||||
@ -100,21 +101,19 @@ public class Gruppen2Controller {
|
||||
try {
|
||||
userList = CsvService.read(file.getInputStream());
|
||||
if(userList.size() > userMaximum){
|
||||
userMaximum = Long.valueOf(userList.size()) + userMaximum;
|
||||
userMaximum = (long) userList.size() + userMaximum;
|
||||
}
|
||||
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
||||
logger.warning("File konnte nicht gelesen werden");
|
||||
logger.warn("File konnte nicht gelesen werden");
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
visibility = visibility == null;
|
||||
lecture = lecture != null;
|
||||
|
||||
if (lecture || parent == null) {
|
||||
parent = "00000000-0000-0000-0000-000000000000";
|
||||
}
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
|
||||
controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, UUID.fromString(parent), userList);
|
||||
controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, parentUUID, userList);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
@ -139,7 +138,10 @@ public class Gruppen2Controller {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
visibility = visibility == null;
|
||||
controllerService.createGroup(account, title, description, visibility, userMaximum, UUID.fromString(parent));
|
||||
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
|
||||
controllerService.createGroup(account, title, description, visibility, userMaximum, parentUUID);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
@ -156,13 +158,18 @@ public class Gruppen2Controller {
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
controllerService.addUserList(userList, UUID.fromString(groupId));
|
||||
|
||||
UUID groupUUID = controllerService.getUUID(groupId);
|
||||
|
||||
controllerService.addUserList(userList, groupUUID);
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/findGroup")
|
||||
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
|
||||
public String findGroup(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<Group> groupse = new ArrayList<>();
|
||||
if (search != null) {
|
||||
@ -175,7 +182,9 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") String groupId) throws EventException {
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("id") String groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -183,47 +192,45 @@ public class Gruppen2Controller {
|
||||
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = new Group();
|
||||
|
||||
if (group.getTitle() == null) {
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
}
|
||||
|
||||
if (!group.getMembers().contains(user)) {
|
||||
if (group.getVisibility() == Visibility.PRIVATE){
|
||||
if (group.getVisibility() == Visibility.PRIVATE) {
|
||||
return "privateGroupNoMember";
|
||||
}
|
||||
if (group != null) {
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
return "detailsNoMember";
|
||||
}
|
||||
return "detailsNoMember";
|
||||
}
|
||||
if (parentId != null && !parentId.equals(UUID.fromString("00000000-0000-0000-0000-000000000000"))) {
|
||||
parent = userService.getGroupById(parentId);
|
||||
}
|
||||
if (group != null) {
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
return "detailsMember";
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
if (!controllerService.idIsEmpty(parentId)) {
|
||||
parent = userService.getGroupById(parentId);
|
||||
}
|
||||
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
return "detailsMember";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam("id") String groupId) throws EventException {
|
||||
public String joinGroup(KeycloakAuthenticationToken token,
|
||||
Model model, @RequestParam("id") String groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
if (group.getMembers().contains(user)) {
|
||||
return "error"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
|
||||
return "error"; //TODO: hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
|
||||
}
|
||||
if (group.getUserMaximum() < group.getMembers().size()) {
|
||||
return "error";
|
||||
@ -234,18 +241,23 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/detailsSearch")
|
||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") String groupId) throws EventException {
|
||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam("id") String groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = new Group();
|
||||
|
||||
if (parentId != null) {
|
||||
parent = userService.getGroupById(parentId);
|
||||
}
|
||||
if (group != null && group.getUserMaximum() > group.getMembers().size()) {
|
||||
|
||||
if (group.getUserMaximum() > group.getMembers().size()) {
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
|
||||
return "detailsNoMember";
|
||||
}
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
@ -253,7 +265,8 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token, Model model, @PathVariable String groupId) throws EventException {
|
||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||
Model model, @PathVariable String groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
if (group != null) {
|
||||
@ -265,20 +278,24 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/leaveGroup")
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") String groupId) throws EventException {
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
controllerService.passIfLastAdmin(account, UUID.fromString(groupId));
|
||||
controllerService.deleteUser(user.getId(), UUID.fromString(groupId));
|
||||
if (userService.getGroupById(UUID.fromString(groupId)).getMembers().size() == 0) {
|
||||
|
||||
if (userService.getGroupById(UUID.fromString(groupId)).getMembers().isEmpty()) {
|
||||
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
||||
}
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/deleteGroup")
|
||||
public String pDeleteGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") String groupId) {
|
||||
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());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
@ -291,7 +308,9 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/members/{id}")
|
||||
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable("id") String groupId) throws EventException {
|
||||
public String editMembers(Model model,
|
||||
KeycloakAuthenticationToken token,
|
||||
@PathVariable("id") String groupId) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
@ -312,7 +331,8 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/changeRole")
|
||||
public String changeRole(KeycloakAuthenticationToken token, @RequestParam("group_id") String groupId,
|
||||
public String changeRole(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) throws EventException {
|
||||
|
||||
|
||||
@ -333,7 +353,7 @@ public class Gruppen2Controller {
|
||||
public String deleteUser(@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) throws EventException {
|
||||
controllerService.deleteUser(userId, UUID.fromString(groupId));
|
||||
if (userService.getGroupById(UUID.fromString(groupId)).getMembers().size() == 0) {
|
||||
if (userService.getGroupById(UUID.fromString(groupId)).getMembers().isEmpty()) {
|
||||
controllerService.deleteGroupEvent(userId, UUID.fromString(groupId));
|
||||
}
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
|
@ -189,12 +189,28 @@ public class ControllerService {
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getVeteranMember(Account account, Group group){
|
||||
private String getVeteranMember(Account account, Group group) {
|
||||
List<User> mitglieder = group.getMembers();
|
||||
if (mitglieder.get(0).getId().equals(account.getName())){
|
||||
if (mitglieder.get(0).getId().equals(account.getName())) {
|
||||
return mitglieder.get(1).getId();
|
||||
}
|
||||
return mitglieder.get(0).getId();
|
||||
}
|
||||
|
||||
public UUID getUUID(String id) {
|
||||
if (id == null) {
|
||||
return UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
} else {
|
||||
return UUID.fromString(id);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean idIsEmpty(UUID id) {
|
||||
if (id == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return id.toString().equals("00000000-0000-0000-0000-000000000000");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user