From 59487fc4c7cbd49287d0d0a21037ebffb948ae4c Mon Sep 17 00:00:00 2001 From: XXNitram Date: Thu, 19 Mar 2020 16:44:08 +0100 Subject: [PATCH 1/4] Fix User class so that csv works --- src/main/java/mops/gruppen2/domain/User.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/mops/gruppen2/domain/User.java b/src/main/java/mops/gruppen2/domain/User.java index 08ff119..bf6c172 100644 --- a/src/main/java/mops/gruppen2/domain/User.java +++ b/src/main/java/mops/gruppen2/domain/User.java @@ -3,14 +3,16 @@ package mops.gruppen2.domain; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter @AllArgsConstructor +@NoArgsConstructor @EqualsAndHashCode(exclude = {"givenname", "familyname", "email"}) public class User { - private final String id; - private final String givenname; - private final String familyname; - private final String email; + private String id; + private String givenname; + private String familyname; + private String email; } From dc11536db347649bb90fa4030a14ed6353198241 Mon Sep 17 00:00:00 2001 From: XXNitram Date: Thu, 19 Mar 2020 16:50:52 +0100 Subject: [PATCH 2/4] Merge Erstellen and Veranstaltung into a single site add two Erstellen sites, one for orga and one for student Co-Authored-By: andibuls Co-Authored-By: Talha Caliskan Co-Authored-By: kasch309 Co-Authored-By: tomvahl Co-Authored-By: Lukas Ettel --- .../controller/Gruppen2Controller.java | 65 ++++++++++--------- .../gruppen2/service/ControllerService.java | 45 +++++++------ .../{createLecture.html => createOrga.html} | 43 ++++++++---- .../{create.html => createStudent.html} | 14 ++-- .../resources/templates/detailsMember.html | 12 ++-- .../resources/templates/detailsNoMember.html | 12 ++-- src/main/resources/templates/editMembers.html | 13 ++-- src/main/resources/templates/index.html | 13 ++-- src/main/resources/templates/search.html | 12 ++-- 9 files changed, 126 insertions(+), 103 deletions(-) rename src/main/resources/templates/{createLecture.html => createOrga.html} (69%) rename src/main/resources/templates/{create.html => createStudent.html} (87%) diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index fa3354d..24137d6 100644 --- a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java +++ b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java @@ -70,19 +70,20 @@ public class Gruppen2Controller { } @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) - @GetMapping("/createLecture") - public String createLecture(KeycloakAuthenticationToken token, Model model) { + @GetMapping("/createOrga") + public String createOrga(KeycloakAuthenticationToken token, Model model) { model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); - return "createLecture"; + return "createOrga"; } @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) - @PostMapping("/createLecture") - public String pCreateLecture(KeycloakAuthenticationToken token, - @RequestParam("title") String title, - @RequestParam("beschreibung") String beschreibung, - @RequestParam(value = "visibility", required = false) Boolean visibility, - @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { + @PostMapping("/createOrga") + public String pCreateOrga(KeycloakAuthenticationToken token, + @RequestParam("title") String title, + @RequestParam("beschreibung") String beschreibung, + @RequestParam(value = "visibility", required = false) Boolean visibility, + @RequestParam(value = "lecture", required = false) Boolean lecture, + @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { Account account = keyCloakService.createAccountFromPrincipal(token); List userList = new ArrayList<>(); @@ -90,7 +91,30 @@ public class Gruppen2Controller { userList = CsvService.read(file.getInputStream()); } visibility = visibility == null; - controllerService.createLecture(account, title, beschreibung, visibility, userList); + lecture = lecture == null; + + controllerService.createOrga(account, title, beschreibung, visibility, lecture, userList); + + return "redirect:/gruppen2/"; + } + + @RolesAllowed({"ROLE_studentin"}) + @GetMapping("/createStudent") + public String createStudent(KeycloakAuthenticationToken token, Model model) { + model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); + return "createStudent"; + } + + @RolesAllowed({"ROLE_studentin"}) + @PostMapping("/createStudent") + public String pCreateStudent(KeycloakAuthenticationToken token, + @RequestParam("title") String title, + @RequestParam("beschreibung") String beschreibung, + @RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException { + + Account account = keyCloakService.createAccountFromPrincipal(token); + visibility = visibility == null; + controllerService.createGroup(account, title, beschreibung, visibility); return "redirect:/gruppen2/"; } @@ -107,13 +131,6 @@ public class Gruppen2Controller { return "redirect:/gruppen2/details/members/" + groupId; } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) - @GetMapping("/createGroup") - public String createGroup(KeycloakAuthenticationToken token, Model model) { - model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); - return "create"; - } - @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 { @@ -127,20 +144,6 @@ public class Gruppen2Controller { return "search"; } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) - @PostMapping("/createGroup") - public String pCreateGroup(KeycloakAuthenticationToken token, - @RequestParam("title") String title, - @RequestParam("beschreibung") String beschreibung, - @RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException { - - Account account = keyCloakService.createAccountFromPrincipal(token); - visibility = visibility == null; - controllerService.createGroup(account, title, beschreibung, visibility); - - return "redirect:/gruppen2/"; - } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @GetMapping("/details/{id}") public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) throws EventException { diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index cd27a39..18fcd0f 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -63,6 +63,32 @@ public class ControllerService { updateRole(account.getName(), groupId); } + public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, List users) throws EventException { + Visibility visibility1; + Long groupId = eventService.checkGroup(); + + if (visibility) { + visibility1 = Visibility.PUBLIC; + } else { + visibility1 = Visibility.PRIVATE; + } + + GroupType groupType; + if (lecture) { + groupType = GroupType.SIMPLE; + } else { + groupType = GroupType.LECTURE; + } + CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, groupType, visibility1); + eventService.saveEvent(createGroupEvent); + + addUser(account, groupId); + updateTitle(account, groupId, title); + updateDescription(account, groupId, description); + updateRole(account.getName(), groupId); + addUserList(users, groupId); + } + private void createInviteLink(Long groupId) { inviteLinkRepositoryService.saveInvite(groupId, UUID.randomUUID()); } @@ -134,23 +160,4 @@ public class ControllerService { eventService.saveEvent(deleteGroupEvent); } - public void createLecture(Account account, String title, String description, Boolean visibility, List users) throws EventException { - Visibility visibility1; - Long groupId = eventService.checkGroup(); - - if (visibility) { - visibility1 = Visibility.PUBLIC; - } else { - visibility1 = Visibility.PRIVATE; - } - - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1); - eventService.saveEvent(createGroupEvent); - - addUser(account, groupId); - updateTitle(account, groupId, title); - updateDescription(account, groupId, description); - updateRole(account.getName(), groupId); - addUserList(users, groupId); - } } diff --git a/src/main/resources/templates/createLecture.html b/src/main/resources/templates/createOrga.html similarity index 69% rename from src/main/resources/templates/createLecture.html rename to src/main/resources/templates/createOrga.html index 04be706..a65a224 100644 --- a/src/main/resources/templates/createLecture.html +++ b/src/main/resources/templates/createOrga.html @@ -16,20 +16,20 @@
-
@@ -37,11 +37,10 @@
-

Veranstaltung erstellen

-
-
+

Gruppenerstellung

+ +
Private Gruppe
+
+ + +
+
+ + +
@@ -76,8 +91,8 @@ type="submit">Erstellen
- -
+
+
@@ -90,4 +105,4 @@ - + \ No newline at end of file diff --git a/src/main/resources/templates/create.html b/src/main/resources/templates/createStudent.html similarity index 87% rename from src/main/resources/templates/create.html rename to src/main/resources/templates/createStudent.html index 2b93f80..43b4abd 100644 --- a/src/main/resources/templates/create.html +++ b/src/main/resources/templates/createStudent.html @@ -11,20 +11,20 @@
-
@@ -33,7 +33,7 @@

Gruppenerstellung

-
+
diff --git a/src/main/resources/templates/detailsMember.html b/src/main/resources/templates/detailsMember.html index 03436d8..012ae60 100644 --- a/src/main/resources/templates/detailsMember.html +++ b/src/main/resources/templates/detailsMember.html @@ -11,20 +11,20 @@
-
diff --git a/src/main/resources/templates/detailsNoMember.html b/src/main/resources/templates/detailsNoMember.html index 5d5684a..20d4f74 100644 --- a/src/main/resources/templates/detailsNoMember.html +++ b/src/main/resources/templates/detailsNoMember.html @@ -10,20 +10,20 @@
-
diff --git a/src/main/resources/templates/editMembers.html b/src/main/resources/templates/editMembers.html index edca787..68a452e 100644 --- a/src/main/resources/templates/editMembers.html +++ b/src/main/resources/templates/editMembers.html @@ -15,20 +15,20 @@
-
@@ -37,7 +37,6 @@
-
-
diff --git a/src/main/resources/templates/search.html b/src/main/resources/templates/search.html index 0d41f05..74dfe2b 100644 --- a/src/main/resources/templates/search.html +++ b/src/main/resources/templates/search.html @@ -10,20 +10,20 @@
-
From cd1d7183e7020cd5989210c1807ee826622442fd Mon Sep 17 00:00:00 2001 From: XXNitram Date: Thu, 19 Mar 2020 16:51:40 +0100 Subject: [PATCH 3/4] Add exceptions for csv errors --- .../controller/Gruppen2Controller.java | 18 ++++++++++++++++-- .../domain/exception/WrongFileException.java | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/main/java/mops/gruppen2/domain/exception/WrongFileException.java diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index 24137d6..c3a2eff 100644 --- a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java +++ b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java @@ -1,11 +1,13 @@ package mops.gruppen2.controller; +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import mops.gruppen2.config.Gruppen2Config; import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Role; import mops.gruppen2.domain.User; import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.GroupNotFoundException; +import mops.gruppen2.domain.exception.WrongFileException; import mops.gruppen2.security.Account; import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.CsvService; @@ -13,6 +15,7 @@ import mops.gruppen2.service.GroupService; import mops.gruppen2.service.InviteLinkRepositoryService; import mops.gruppen2.service.KeyCloakService; import mops.gruppen2.service.UserService; +import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -26,6 +29,7 @@ import org.springframework.web.context.annotation.SessionScope; import org.springframework.web.multipart.MultipartFile; import javax.annotation.security.RolesAllowed; +import java.io.CharConversionException; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -88,7 +92,11 @@ public class Gruppen2Controller { Account account = keyCloakService.createAccountFromPrincipal(token); List userList = new ArrayList<>(); if (!file.isEmpty()) { - userList = CsvService.read(file.getInputStream()); + try { + userList = CsvService.read(file.getInputStream()); + } catch (UnrecognizedPropertyException | CharConversionException ex) { + throw new WrongFileException(file.getOriginalFilename()); + } } visibility = visibility == null; lecture = lecture == null; @@ -125,7 +133,13 @@ public class Gruppen2Controller { @RequestParam(value = "file", required = false) MultipartFile file) throws IOException { List userList = new ArrayList<>(); if (!file.isEmpty()) { - userList = CsvService.read(file.getInputStream()); + try { + userList = CsvService.read(file.getInputStream()); + } catch (UnrecognizedPropertyException | CharConversionException ex) { + throw new WrongFileException(file.getOriginalFilename()); + } catch (IllegalStateException ex) { + throw new WrongFileException(file.getOriginalFilename()); + } } controllerService.addUserList(userList, groupId); return "redirect:/gruppen2/details/members/" + groupId; diff --git a/src/main/java/mops/gruppen2/domain/exception/WrongFileException.java b/src/main/java/mops/gruppen2/domain/exception/WrongFileException.java new file mode 100644 index 0000000..59ab3fb --- /dev/null +++ b/src/main/java/mops/gruppen2/domain/exception/WrongFileException.java @@ -0,0 +1,9 @@ +package mops.gruppen2.domain.exception; + +import org.springframework.http.HttpStatus; + +public class WrongFileException extends EventException { + public WrongFileException(String info) { + super(HttpStatus.INTERNAL_SERVER_ERROR, "Die entsprechende Datei ist keine valide CSV-Datei!", info); + } +} From b24f6d273f5c43daa8d88b2eadeeba0cda0cbfc8 Mon Sep 17 00:00:00 2001 From: XXNitram Date: Thu, 19 Mar 2020 17:24:10 +0100 Subject: [PATCH 4/4] Fix merge with master --- .../controller/Gruppen2Controller.java | 41 ++++++------------- .../gruppen2/service/ControllerService.java | 25 ++--------- src/main/resources/templates/createOrga.html | 11 +++-- .../resources/templates/createStudent.html | 2 +- 4 files changed, 24 insertions(+), 55 deletions(-) diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index 9416047..6946481 100644 --- a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java +++ b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java @@ -16,7 +16,6 @@ import mops.gruppen2.service.GroupService; import mops.gruppen2.service.InviteLinkRepositoryService; import mops.gruppen2.service.KeyCloakService; import mops.gruppen2.service.UserService; -import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -28,7 +27,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.context.annotation.SessionScope; import org.springframework.web.multipart.MultipartFile; - import javax.annotation.security.RolesAllowed; import java.io.CharConversionException; import java.io.IOException; @@ -84,11 +82,12 @@ public class Gruppen2Controller { @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @PostMapping("/createOrga") public String pCreateOrga(KeycloakAuthenticationToken token, - @RequestParam("title") String title, - @RequestParam("beschreibung") String beschreibung, - @RequestParam(value = "visibility", required = false) Boolean visibility, - @RequestParam(value = "lecture", required = false) Boolean lecture, - @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { + @RequestParam("title") String title, + @RequestParam("description") String description, + @RequestParam(value = "visibility", required = false) Boolean visibility, + @RequestParam(value = "lecture", required = false) Boolean lecture, + @RequestParam("userMaximum") Long userMaximum, + @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { Account account = keyCloakService.createAccountFromPrincipal(token); List userList = new ArrayList<>(); @@ -102,7 +101,7 @@ public class Gruppen2Controller { visibility = visibility == null; lecture = lecture == null; - controllerService.createOrga(account, title, beschreibung, visibility, lecture, userList); + controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, userList); return "redirect:/gruppen2/"; } @@ -117,13 +116,14 @@ public class Gruppen2Controller { @RolesAllowed({"ROLE_studentin"}) @PostMapping("/createStudent") public String pCreateStudent(KeycloakAuthenticationToken token, - @RequestParam("title") String title, - @RequestParam("beschreibung") String beschreibung, - @RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException { + @RequestParam("title") String title, + @RequestParam("description") String description, + @RequestParam(value = "visibility", required = false) Boolean visibility, + @RequestParam("userMaximum") Long userMaximum) throws EventException { Account account = keyCloakService.createAccountFromPrincipal(token); visibility = visibility == null; - controllerService.createGroup(account, title, beschreibung, visibility); + controllerService.createGroup(account, title, description, visibility, userMaximum); return "redirect:/gruppen2/"; } @@ -138,8 +138,6 @@ public class Gruppen2Controller { userList = CsvService.read(file.getInputStream()); } catch (UnrecognizedPropertyException | CharConversionException ex) { throw new WrongFileException(file.getOriginalFilename()); - } catch (IllegalStateException ex) { - throw new WrongFileException(file.getOriginalFilename()); } } controllerService.addUserList(userList, groupId); @@ -159,21 +157,6 @@ public class Gruppen2Controller { return "search"; } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) - @PostMapping("/createGroup") - public String pCreateGroup(KeycloakAuthenticationToken token, - @RequestParam("title") String title, - @RequestParam("description") String description, - @RequestParam(value = "visibility", required = false) Boolean visibility, - @RequestParam("userMaximum") Long userMaximum) throws EventException { - - Account account = keyCloakService.createAccountFromPrincipal(token); - visibility = visibility == null; - controllerService.createGroup(account, title, description, visibility, userMaximum); - - return "redirect:/gruppen2/"; - } - @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @GetMapping("/details/{id}") public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) throws EventException { diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index b069319..d46e708 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -66,7 +66,7 @@ public class ControllerService { updateRole(account.getName(), groupId); } - public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, List users) throws EventException { + public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Long maximmum, List users) throws EventException { Visibility visibility1; Long groupId = eventService.checkGroup(); @@ -82,7 +82,8 @@ public class ControllerService { } else { groupType = GroupType.LECTURE; } - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, groupType, visibility1); + + CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, groupType, visibility1, maximmum); eventService.saveEvent(createGroupEvent); addUser(account, groupId); @@ -163,26 +164,6 @@ public class ControllerService { eventService.saveEvent(deleteGroupEvent); } - public void createLecture(Account account, String title, String description, Boolean visibility, List users) throws EventException { - Visibility visibility1; - Long groupId = eventService.checkGroup(); - - if (visibility) { - visibility1 = Visibility.PUBLIC; - } else { - visibility1 = Visibility.PRIVATE; - } - - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1, 1000L); //this has to be changed also Usermaximum - eventService.saveEvent(createGroupEvent); - - addUser(account, groupId); - updateTitle(account, groupId, title); - updateDescription(account, groupId, description); - updateRole(account.getName(), groupId); - addUserList(users, groupId); - } - public boolean passIfLastAdmin(Account account, Long groupId){ Group group = userService.getGroupById(groupId); if (group.getMembers().size() <= 1){ diff --git a/src/main/resources/templates/createOrga.html b/src/main/resources/templates/createOrga.html index a65a224..35b06a9 100644 --- a/src/main/resources/templates/createOrga.html +++ b/src/main/resources/templates/createOrga.html @@ -47,9 +47,14 @@ type="text">
- - + + +
+
+ +

Gruppenerstellung

- +