diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index e2b7107..6946481 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.domain.exception.NoAdminAfterActionException; import mops.gruppen2.security.Account; import mops.gruppen2.service.ControllerService; @@ -25,8 +27,8 @@ 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; import java.util.ArrayList; import java.util.List; @@ -71,27 +73,57 @@ 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("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<>(); 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; - controllerService.createLecture(account, title, beschreibung, visibility, userList); + lecture = lecture == null; + + controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, 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("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/"; } @@ -102,19 +134,16 @@ 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()); + } } controllerService.addUserList(userList, groupId); 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 { @@ -128,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/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); + } +} diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index 9316fe9..d46e708 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -66,6 +66,33 @@ public class ControllerService { updateRole(account.getName(), groupId); } + 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(); + + 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, maximmum); + 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()); } @@ -137,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/createLecture.html b/src/main/resources/templates/createOrga.html similarity index 61% rename from src/main/resources/templates/createLecture.html rename to src/main/resources/templates/createOrga.html index 04be706..35b06a9 100644 --- a/src/main/resources/templates/createLecture.html +++ b/src/main/resources/templates/createOrga.html @@ -16,20 +16,20 @@
-
@@ -37,20 +37,24 @@
-

Veranstaltung erstellen

-
-
+

Gruppenerstellung

+ +
- - + + +
+
+ +
Private Gruppe
+
+ + +
+
+ + +
@@ -76,8 +96,8 @@ type="submit">Erstellen
- -
+
+
@@ -90,4 +110,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 88% rename from src/main/resources/templates/create.html rename to src/main/resources/templates/createStudent.html index 65901cf..90777bc 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 593bff5..5d833de 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 94d2373..ece315e 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 0a892c6..386374c 100644 --- a/src/main/resources/templates/editMembers.html +++ b/src/main/resources/templates/editMembers.html @@ -15,20 +15,20 @@
-
@@ -46,7 +46,6 @@
-
-
diff --git a/src/main/resources/templates/search.html b/src/main/resources/templates/search.html index 1a9b51c..ef093d7 100644 --- a/src/main/resources/templates/search.html +++ b/src/main/resources/templates/search.html @@ -10,20 +10,20 @@
-