From 5736de146d12b7a6105c627c6046f00fd49fecc6 Mon Sep 17 00:00:00 2001 From: AndiBuls Date: Wed, 25 Mar 2020 15:38:37 +0100 Subject: [PATCH 01/36] refactor createGroup and createOrga Co-authored-by: LukasEttel tomvahl --- .../gruppen2/service/ControllerService.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index 1e57d6d..e3e32a4 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -74,28 +74,15 @@ public class ControllerService { * @param title Gruppentitel * @param description Gruppenbeschreibung */ - public void createGroup(Account account, String title, String description, Boolean visibility, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException { - Visibility visibility1; + public void createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isMaximumInfinite, Long userMaximum, UUID parent) throws EventException { + Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate); UUID groupId = eventService.checkGroup(); - maxInfiniteUsers = maxInfiniteUsers != null; - - - if(maxInfiniteUsers) { - userMaximum = 100000L; - } + userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); checkFields(description, title, userMaximum); - visibility = visibility == null; - - if (visibility) { - visibility1 = Visibility.PUBLIC; - } else { - visibility1 = Visibility.PRIVATE; - } - - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum); + CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, groupVisibility, userMaximum); eventService.saveEvent(createGroupEvent); addUser(account, groupId); @@ -104,12 +91,10 @@ public class ControllerService { updateRole(account.getName(), groupId); } - public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent, MultipartFile file) throws EventException, IOException { + public void createOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) throws EventException, IOException { List userList = new ArrayList<>(); - maxInfiniteUsers = maxInfiniteUsers != null; - if(maxInfiniteUsers) { - userMaximum = 100000L; - } + + userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); checkFields(description, title, userMaximum); @@ -124,24 +109,11 @@ public class ControllerService { throw new WrongFileException(file.getOriginalFilename()); } } - visibility = visibility == null; - lecture = lecture != null; - Visibility visibility1; UUID groupId = eventService.checkGroup(); - if (visibility) { - visibility1 = Visibility.PUBLIC; - } else { - visibility1 = Visibility.PRIVATE; - } + Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate); + GroupType groupType = setGroupType(isLecture); - GroupType groupType; - if (lecture) { - groupType = GroupType.LECTURE; - } else { - groupType = GroupType.SIMPLE; - } - - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, visibility1, userMaximum); + CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum); eventService.saveEvent(createGroupEvent); addUser(account, groupId); @@ -151,6 +123,34 @@ public class ControllerService { addUserList(userList, groupId); } + 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; + } + } public void addUser(Account account, UUID groupId) { AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); From 95e3c38dd9fc03ae45b12db620af25deec7f8449 Mon Sep 17 00:00:00 2001 From: AndiBuls Date: Wed, 25 Mar 2020 16:30:22 +0100 Subject: [PATCH 02/36] refactor createOrga Co-authored-by: LukasEttel --- .../gruppen2/service/ControllerService.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index e3e32a4..777ccc6 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.logging.Logger; +import java.util.stream.Collectors; import static mops.gruppen2.domain.Role.ADMIN; @@ -92,23 +93,16 @@ public class ControllerService { } public void createOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) throws EventException, IOException { - List userList = new ArrayList<>(); - userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); checkFields(description, title, userMaximum); - if (!file.isEmpty()) { - try { - userList = CsvService.read(file.getInputStream()); - if (userList.size() > userMaximum) { - userMaximum = (long) userList.size() + userMaximum; - } - } catch (UnrecognizedPropertyException | CharConversionException ex) { - logger.warning("File konnte nicht gelesen werden"); - throw new WrongFileException(file.getOriginalFilename()); - } + List userList = readCsvFile(file); + + if (userList.size() > userMaximum) { + userMaximum = (long) userList.size() + 1; } + UUID groupId = eventService.checkGroup(); Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate); GroupType groupType = setGroupType(isLecture); @@ -152,6 +146,19 @@ public class ControllerService { } } + public List readCsvFile(MultipartFile file) throws EventException, IOException { + if (!file.isEmpty()) { + try { + List 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<>(); + } + public void addUser(Account account, UUID groupId) { AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); eventService.saveEvent(addUserEvent); From 57df0263d4b91132780931f9029b49fcd20582b1 Mon Sep 17 00:00:00 2001 From: killerber4t Date: Wed, 25 Mar 2020 16:52:43 +0100 Subject: [PATCH 03/36] refactor ValidationService --- src/main/java/mops/gruppen2/controller/WebController.java | 1 + .../domain/event/UpdateGroupDescriptionEvent.java | 2 +- .../mops/gruppen2/domain/event/UpdateGroupTitleEvent.java | 2 +- .../java/mops/gruppen2/service/ValidationService.java | 8 ++++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/mops/gruppen2/controller/WebController.java b/src/main/java/mops/gruppen2/controller/WebController.java index 57ef550..4db0721 100644 --- a/src/main/java/mops/gruppen2/controller/WebController.java +++ b/src/main/java/mops/gruppen2/controller/WebController.java @@ -46,6 +46,7 @@ public class WebController { * @param model tolles model * @return index.html */ + @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @GetMapping("") public String index(KeycloakAuthenticationToken token, Model model) throws EventException { diff --git a/src/main/java/mops/gruppen2/domain/event/UpdateGroupDescriptionEvent.java b/src/main/java/mops/gruppen2/domain/event/UpdateGroupDescriptionEvent.java index 1510213..4eae31f 100644 --- a/src/main/java/mops/gruppen2/domain/event/UpdateGroupDescriptionEvent.java +++ b/src/main/java/mops/gruppen2/domain/event/UpdateGroupDescriptionEvent.java @@ -20,7 +20,7 @@ public class UpdateGroupDescriptionEvent extends Event { public UpdateGroupDescriptionEvent(UUID groupId, String userId, String newGroupDescription) { super(groupId, userId); - this.newGroupDescription = newGroupDescription; + this.newGroupDescription = newGroupDescription.trim(); } @Override diff --git a/src/main/java/mops/gruppen2/domain/event/UpdateGroupTitleEvent.java b/src/main/java/mops/gruppen2/domain/event/UpdateGroupTitleEvent.java index 14d59e3..b3a57ba 100644 --- a/src/main/java/mops/gruppen2/domain/event/UpdateGroupTitleEvent.java +++ b/src/main/java/mops/gruppen2/domain/event/UpdateGroupTitleEvent.java @@ -20,7 +20,7 @@ public class UpdateGroupTitleEvent extends Event { public UpdateGroupTitleEvent(UUID groupId, String userId, String newGroupTitle) { super(groupId, userId); - this.newGroupTitle = newGroupTitle; + this.newGroupTitle = newGroupTitle.trim(); } @Override diff --git a/src/main/java/mops/gruppen2/service/ValidationService.java b/src/main/java/mops/gruppen2/service/ValidationService.java index 9b830d5..0f4b867 100644 --- a/src/main/java/mops/gruppen2/service/ValidationService.java +++ b/src/main/java/mops/gruppen2/service/ValidationService.java @@ -123,16 +123,20 @@ public class ValidationService { * @param userMaximum */ public void checkFields(String description, String title, Long userMaximum, Boolean maxInfiniteUsers) { - if (description == null) { + if (description == null || description.trim().length() == 0) { throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben"); } - if (title == null) { + if (title == null || title.trim().length() == 0) { throw new BadParameterException("Der Titel wurde nicht korrekt angegeben"); } if (userMaximum == null && maxInfiniteUsers == null) { throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben"); } + + if (userMaximum < 1 || userMaximum > 10000L) { + throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben"); + } } } From d1c886558094bfca8a29e60484014299a2269311 Mon Sep 17 00:00:00 2001 From: AndiBuls Date: Wed, 25 Mar 2020 17:05:06 +0100 Subject: [PATCH 04/36] html fix title alignment in detailsMember.html Co-authored-by: LukasEttel tomvahl XXNitram [Mahgs] Christoph killerber4t kasch309 --- .../mops/gruppen2/controller/WebController.java | 2 +- src/main/resources/templates/detailsMember.html | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/mops/gruppen2/controller/WebController.java b/src/main/java/mops/gruppen2/controller/WebController.java index 57ef550..3fe06ad 100644 --- a/src/main/java/mops/gruppen2/controller/WebController.java +++ b/src/main/java/mops/gruppen2/controller/WebController.java @@ -82,7 +82,7 @@ public class WebController { UUID parentUUID = controllerService.getUUID(parent); List userList = new ArrayList<>(); validationService.checkFields(description, title, userMaximum, maxInfiniteUsers); - Group group = userService.getGroupById(controllerService.createOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID)); + Group group = userService.getGroupById(controllerService.createOrga(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/"; diff --git a/src/main/resources/templates/detailsMember.html b/src/main/resources/templates/detailsMember.html index dac015f..664cfc7 100644 --- a/src/main/resources/templates/detailsMember.html +++ b/src/main/resources/templates/detailsMember.html @@ -35,12 +35,16 @@
-

- +
+

+
+
+ +

Date: Thu, 26 Mar 2020 13:50:22 +0100 Subject: [PATCH 05/36] Refactor of all createGroups complete Co-authored-by: AndiBuls --- .../gruppen2/controller/WebController.java | 45 +++++++++-------- .../gruppen2/service/ControllerService.java | 49 +++++++++---------- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/main/java/mops/gruppen2/controller/WebController.java b/src/main/java/mops/gruppen2/controller/WebController.java index 3fe06ad..0e7df85 100644 --- a/src/main/java/mops/gruppen2/controller/WebController.java +++ b/src/main/java/mops/gruppen2/controller/WebController.java @@ -59,7 +59,7 @@ public class WebController { @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @GetMapping("/createOrga") - public String createOrga(KeycloakAuthenticationToken token, Model model) { + public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) { Account account = keyCloakService.createAccountFromPrincipal(token); model.addAttribute("account", account); model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic()); @@ -68,29 +68,28 @@ public class WebController { @RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @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 = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, - @RequestParam(value = "parent", required = false) String parent, - @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { + public String postCrateGroupAsOrga(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 = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, + @RequestParam(value = "parent", required = false) String parent, + @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { Account account = keyCloakService.createAccountFromPrincipal(token); UUID parentUUID = controllerService.getUUID(parent); - List userList = new ArrayList<>(); + validationService.checkFields(description, title, userMaximum, maxInfiniteUsers); - Group group = userService.getGroupById(controllerService.createOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file)); - userList = validationService.checkFile(file, userList, group.getId().toString(), group, account); - controllerService.addUserList(userList, group.getId()); + controllerService.createGroupAsOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file); + return "redirect:/gruppen2/"; } @RolesAllowed({"ROLE_studentin"}) @GetMapping("/createStudent") - public String createStudent(KeycloakAuthenticationToken token, Model model) { + public String createGroupAsStudent(KeycloakAuthenticationToken token, Model model) { Account account = keyCloakService.createAccountFromPrincipal(token); model.addAttribute("account", account); model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic()); @@ -99,18 +98,18 @@ public class WebController { @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, - @RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, - @RequestParam(value = "parent", required = false) String parent) throws EventException { + 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 = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, + @RequestParam(value = "parent", required = false) String parent) throws EventException { Account account = keyCloakService.createAccountFromPrincipal(token); UUID parentUUID = controllerService.getUUID(parent); 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/"; } diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index 649b331..df6af35 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -55,33 +55,13 @@ public class ControllerService { * @param title Gruppentitel * @param description Gruppenbeschreibung */ - public void createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isMaximumInfinite, Long userMaximum, UUID parent) throws EventException { + public UUID createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent) throws EventException { + userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); + Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate); UUID groupId = UUID.randomUUID(); - userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); - - CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, groupVisibility, userMaximum); - eventService.saveEvent(createGroupEvent); - - addUser(account, groupId); - updateTitle(account, groupId, title); - updateDescription(account, groupId, description); - updateRole(account.getName(), groupId); - } - - public UUID createOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) throws EventException, IOException { - userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); - - List userList = readCsvFile(file); - - if (userList.size() > userMaximum) { - userMaximum = (long) userList.size() + 1; - } - - UUID groupId = UUID.randomUUID(); - Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate); - GroupType groupType = setGroupType(isLecture); + GroupType groupType = setGroupType(isLecture); CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum); eventService.saveEvent(createGroupEvent); @@ -94,6 +74,18 @@ public class ControllerService { return groupId; } + public void createGroupAsOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) throws EventException, IOException { + userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); + + List userList = readCsvFile(file); + userMaximum = adjustUserMaximum((long) userList.size(), 1L, userMaximum); + + UUID groupId = createGroup(account, title, description, isVisibilityPrivate, isLecture, isMaximumInfinite, userMaximum, parent); + + addUserList(userList, groupId); + } + + private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) { isMaximumInfinite = isMaximumInfinite != null; @@ -123,7 +115,7 @@ public class ControllerService { } } - public List readCsvFile(MultipartFile file) throws EventException, IOException { + private List readCsvFile(MultipartFile file) throws EventException, IOException { if (!file.isEmpty()) { try { List userList = CsvService.read(file.getInputStream()); @@ -136,6 +128,13 @@ public class ControllerService { 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) { AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); eventService.saveEvent(addUserEvent); From 7b9af1320c7d4a3a5021b4ce93e688b615e856df Mon Sep 17 00:00:00 2001 From: Lukas Ettel <34522828+LukasEttel@users.noreply.github.com> Date: Thu, 26 Mar 2020 14:06:13 +0100 Subject: [PATCH 06/36] Refactor of all createGroups complete Co-authored-by: AndiBuls --- src/main/java/mops/gruppen2/service/ControllerService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index 2f4de87..4557bb2 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -1,5 +1,6 @@ package mops.gruppen2.service; +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import mops.gruppen2.domain.Group; import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.Role; @@ -15,10 +16,14 @@ import mops.gruppen2.domain.event.UpdateRoleEvent; import mops.gruppen2.domain.event.UpdateUserMaxEvent; import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.UserNotFoundException; +import mops.gruppen2.domain.exception.WrongFileException; import mops.gruppen2.security.Account; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import java.io.CharConversionException; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; From 4f833c3c5f87b8d0b9434b8afa38b33ec513082a Mon Sep 17 00:00:00 2001 From: XXNitram Date: Thu, 26 Mar 2020 14:12:53 +0100 Subject: [PATCH 07/36] Refactor WrongFileException --- .../java/mops/gruppen2/domain/exception/WrongFileException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/mops/gruppen2/domain/exception/WrongFileException.java b/src/main/java/mops/gruppen2/domain/exception/WrongFileException.java index 59ab3fb..b2e69f4 100644 --- a/src/main/java/mops/gruppen2/domain/exception/WrongFileException.java +++ b/src/main/java/mops/gruppen2/domain/exception/WrongFileException.java @@ -4,6 +4,6 @@ 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); + super(HttpStatus.BAD_REQUEST, "Die entsprechende Datei ist keine valide CSV-Datei!", info); } } From 1cc52d7dce0c26c3c7116e523db410fe4d7c76d4 Mon Sep 17 00:00:00 2001 From: XXNitram Date: Thu, 26 Mar 2020 14:14:06 +0100 Subject: [PATCH 08/36] Fix checkFields Co-Authored-By: Talha Caliskan --- .../java/mops/gruppen2/service/ValidationService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/mops/gruppen2/service/ValidationService.java b/src/main/java/mops/gruppen2/service/ValidationService.java index bc6864f..d08765e 100644 --- a/src/main/java/mops/gruppen2/service/ValidationService.java +++ b/src/main/java/mops/gruppen2/service/ValidationService.java @@ -142,8 +142,12 @@ public class ValidationService { throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben"); } - if (userMaximum < 1 || userMaximum > 10000L) { - throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben"); + if (userMaximum != null) { + if (userMaximum < 1 || userMaximum > 10000L) { + throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben"); + } + } + } } } } From 677ed4e37bddcce6acabe72abebcbd38da5c0486 Mon Sep 17 00:00:00 2001 From: XXNitram Date: Thu, 26 Mar 2020 14:14:45 +0100 Subject: [PATCH 09/36] Add validation for setting a new userMaximum Co-Authored-By: Talha Caliskan --- .../mops/gruppen2/controller/WebController.java | 1 + .../mops/gruppen2/service/ValidationService.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/mops/gruppen2/controller/WebController.java b/src/main/java/mops/gruppen2/controller/WebController.java index 0ae0631..b0e4437 100644 --- a/src/main/java/mops/gruppen2/controller/WebController.java +++ b/src/main/java/mops/gruppen2/controller/WebController.java @@ -327,6 +327,7 @@ public class WebController { @RequestParam("group_id") String groupId, KeycloakAuthenticationToken token) { Account account = keyCloakService.createAccountFromPrincipal(token); + validationService.checkIfNewMaximumIsValid(maximum, groupId); controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum); return "redirect:/gruppen2/details/members/" + groupId; } diff --git a/src/main/java/mops/gruppen2/service/ValidationService.java b/src/main/java/mops/gruppen2/service/ValidationService.java index d08765e..94148c7 100644 --- a/src/main/java/mops/gruppen2/service/ValidationService.java +++ b/src/main/java/mops/gruppen2/service/ValidationService.java @@ -148,6 +148,19 @@ public class ValidationService { } } } + + public void checkIfNewMaximumIsValid(Long newUserMaximum, String groupId) { + Group group = userService.getGroupById(UUID.fromString(groupId)); + if (newUserMaximum == null) { + throw new BadParameterException("Es wurde keine neue maximale Teilnehmeranzahl angegeben!"); + } + + if (newUserMaximum < 1 || newUserMaximum > 10000L) { + throw new BadParameterException("Die neue maximale Teilnehmeranzahl wurde nicht korrekt angegeben!"); + } + + if (group.getMembers().size() > newUserMaximum) { + throw new BadParameterException("Die neue maximale Teilnehmeranzahl ist kleiner als die aktuelle Teilnehmeranzahl!"); } } } From c88990a3edb08457d4e626d8b47b28006c9b9ddf Mon Sep 17 00:00:00 2001 From: Lukas Ettel <34522828+LukasEttel@users.noreply.github.com> Date: Thu, 26 Mar 2020 14:42:32 +0100 Subject: [PATCH 10/36] Refactor of all createGroups complete Co-authored-by: AndiBuls --- .../gruppen2/service/ControllerService.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index 4557bb2..6e0147d 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -18,6 +18,7 @@ import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.UserNotFoundException; import mops.gruppen2.domain.exception.WrongFileException; import mops.gruppen2.security.Account; +import org.keycloak.jose.jwk.JWK; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -61,7 +62,7 @@ public class ControllerService { Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate); UUID groupId = UUID.randomUUID(); - GroupType groupType = setGroupType(isLecture); + GroupType groupType = setGroupType(isLecture); CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum); eventService.saveEvent(createGroupEvent); @@ -77,19 +78,32 @@ public class ControllerService { public void createGroupAsOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) throws EventException, IOException { userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); - List userList = readCsvFile(file); - userMaximum = adjustUserMaximum((long) userList.size(), 1L, userMaximum); + List newUsers = readCsvFile(file); + + List 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(userList, groupId); + addUserList(newUsers, groupId); + } + + private void removeOldUsersFromNewUsers(List oldUsers, List newUsers){ + for(User oldUser : oldUsers) { + newUsers.remove(oldUser); + } } private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) { isMaximumInfinite = isMaximumInfinite != null; - if(isMaximumInfinite) { + if (isMaximumInfinite) { userMaximum = 100000L; } @@ -128,7 +142,7 @@ public class ControllerService { return new ArrayList<>(); } - private Long adjustUserMaximum(Long newUsers, Long oldUsers, Long maxUsers){ + private Long adjustUserMaximum(Long newUsers, Long oldUsers, Long maxUsers) { if (oldUsers + newUsers > maxUsers) { maxUsers = oldUsers + newUsers; } From 5394b5d47ae0933477dcc685ef897cf16bc1a63c Mon Sep 17 00:00:00 2001 From: Lukas Ettel <34522828+LukasEttel@users.noreply.github.com> Date: Thu, 26 Mar 2020 14:52:11 +0100 Subject: [PATCH 11/36] Refactor of all createGroups complete Co-authored-by: AndiBuls --- src/main/java/mops/gruppen2/service/ControllerService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index 1d10c63..0198c75 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -92,8 +92,8 @@ public class ControllerService { addUserList(newUsers, groupId); } - private void removeOldUsersFromNewUsers(List oldUsers, List newUsers){ - for(User oldUser : oldUsers) { + private void removeOldUsersFromNewUsers(List oldUsers, List newUsers) { + for (User oldUser : oldUsers) { newUsers.remove(oldUser); } } From 33e3d9d3f59e07e46589170bcc4b56bb4a62051b Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 26 Mar 2020 16:06:40 +0100 Subject: [PATCH 12/36] docker profiles, docker compose, mysql entrypoint, security Co-authored-by: Christoph --- Dockerfile | 6 ++++-- build.gradle | 10 +++------ docker-compose.yaml | 6 ++++-- .../gruppen2/security/SecurityConfig.java | 21 ++++++++----------- src/main/resources/application-dev.properties | 8 +++---- .../resources/application-docker.properties | 8 +++---- src/main/resources/schema-h2.sql | 10 +++++++++ src/main/resources/schema.sql | 14 ------------- 8 files changed, 38 insertions(+), 45 deletions(-) create mode 100644 src/main/resources/schema-h2.sql delete mode 100644 src/main/resources/schema.sql diff --git a/Dockerfile b/Dockerfile index 47d4184..cf75fef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ FROM gradle:jdk11 AS build COPY --chown=gradle:gradle . /home/gradle/src WORKDIR /home/gradle/src +RUN chmod +x ./pull-wait-for-it.sh RUN gradle bootJar --no-daemon FROM openjdk:11-jre-slim RUN mkdir /app COPY --from=build /home/gradle/src/build/libs/*.jar /app/gruppen2.jar -ENTRYPOINT ["java"] -CMD ["-Dspring.profiles.active=docker", "-jar", "/app/gruppen2.jar"] +COPY --from=build /home/gradle/src/wait-for-it.sh /app/wait-for-it.sh +#ENTRYPOINT ["java"] +#CMD ["-Dspring.profiles.active=docker", "-jar", "/app/gruppen2.jar"] diff --git a/build.gradle b/build.gradle index c401fe5..f65225b 100644 --- a/build.gradle +++ b/build.gradle @@ -59,8 +59,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' - - compile group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-client', version: '2.2.5.RELEASE' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + implementation 'org.springframework.security.oauth:spring-security-oauth2:2.4.0.RELEASE' implementation 'org.keycloak:keycloak-spring-boot-starter:9.0.0' implementation 'org.keycloak.bom:keycloak-adapter-bom:9.0.0' @@ -68,7 +68,7 @@ dependencies { implementation 'io.springfox:springfox-swagger2:2.9.2' implementation 'io.springfox:springfox-swagger-ui:2.9.2' implementation 'com.github.javafaker:javafaker:1.0.2' - implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.2' + implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.3' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' @@ -76,10 +76,6 @@ dependencies { runtimeOnly 'com.h2database:h2' runtimeOnly 'mysql:mysql-connector-java' - compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.4.0.RELEASE' - - compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.3' - testImplementation 'org.assertj:assertj-core:3.15.0' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' diff --git a/docker-compose.yaml b/docker-compose.yaml index 0b833ba..f1dea7a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,12 +10,14 @@ services: restart: always volumes: - './mysql/db/storage:/var/lib/mysql' + - './mysql/db/entrypoint:/docker-entrypoint-initdb.d/' ports: - '3306:3306' - gruppen2app: + gruppenapp: build: . - container_name: 'gruppen2app' + container_name: 'gruppenapp' depends_on: - dbmysql + command: ["/app/wait-for-it.sh", "dbmysql:3306", "--", "java", "-Dspring.profiles.active=docker", "-jar", "/app/gruppen2.jar"] ports: - '8081:8080' diff --git a/src/main/java/mops/gruppen2/security/SecurityConfig.java b/src/main/java/mops/gruppen2/security/SecurityConfig.java index f597e47..981103e 100644 --- a/src/main/java/mops/gruppen2/security/SecurityConfig.java +++ b/src/main/java/mops/gruppen2/security/SecurityConfig.java @@ -48,7 +48,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter { @Bean @Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, - proxyMode = ScopedProxyMode.TARGET_CLASS) + proxyMode = ScopedProxyMode.TARGET_CLASS) public AccessToken getAccessToken() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder @@ -61,17 +61,14 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { super.configure(http); http.authorizeRequests() - .antMatchers("/actuator/**") - .hasRole("monitoring") - .and() - .authorizeRequests() - .antMatchers("/h2-console/**") - .permitAll() - .anyRequest() - .permitAll(); - - http.csrf().disable(); - http.headers().frameOptions().disable(); + .antMatchers("/actuator/**") + .hasRole("monitoring") + .anyRequest() + .permitAll() + .and() + .csrf() + .ignoringAntMatchers("/gruppen2/createOrga") + .ignoringAntMatchers("/gruppen2/details/members/addUsersFromCsv"); } /** diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 6e40c9e..b18e217 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -1,12 +1,13 @@ application.name=gruppen2 logging.pattern.console=[${application.name}],%magenta(%-5level), %d{dd-MM-yyyy HH:mm:ss.SSS}, %highlight(%msg),%thread,%logger.%M%n +spring.datasource.platform=h2 spring.datasource.url=jdbc:h2:mem:blogdb -spring.datasource.driverClassName=org.h2.Driver +spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect -spring.h2.console.enabled=true -logging.level.org.springframework.jdbc.core=DEBUG +spring.h2.console.enabled=false +logging.level.org.springframework.jdbc.core=INFO keycloak.principal-attribute=preferred_username keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth keycloak.realm=MOPS @@ -18,4 +19,3 @@ keycloak.use-resource-role-mappings=true keycloak.autodetect-bearer-only=true keycloak.confidential-port=443 server.error.include-stacktrace=always -server.port=8080 diff --git a/src/main/resources/application-docker.properties b/src/main/resources/application-docker.properties index 52656f7..253b9c9 100644 --- a/src/main/resources/application-docker.properties +++ b/src/main/resources/application-docker.properties @@ -1,17 +1,17 @@ application.name=gruppen2 logging.pattern.console=[${application.name}],%magenta(%-5level), %d{dd-MM-yyyy HH:mm:ss.SSS}, %highlight(%msg),%thread,%logger.%M%n - -spring.datasource.initialization-mode=always +spring.datasource.platform=mysql +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.initialization-mode=NEVER spring.datasource.url=jdbc:mysql://dbmysql:3306/gruppen2 spring.datasource.username=root spring.datasource.password=geheim - keycloak.principal-attribute=preferred_username keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth keycloak.realm=MOPS hhu_keycloak.token-uri=https://keycloak.cs.hhu.de/auth/realms/MOPS/protocol/openid-connect/token keycloak.resource=gruppenfindung -keycloak.credentials.secret= fc6ebf10-8c63-4e71-a667-4eae4e8209a1 +keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1 keycloak.verify-token-audience=true keycloak.use-resource-role-mappings=true keycloak.autodetect-bearer-only=true diff --git a/src/main/resources/schema-h2.sql b/src/main/resources/schema-h2.sql new file mode 100644 index 0000000..5616313 --- /dev/null +++ b/src/main/resources/schema-h2.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS event; + +CREATE TABLE event +( + event_id INT PRIMARY KEY AUTO_INCREMENT, + group_id VARCHAR(36) NOT NULL, + user_id VARCHAR(50), + event_type VARCHAR(32), + event_payload VARCHAR(2500) +); diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql deleted file mode 100644 index a750aa3..0000000 --- a/src/main/resources/schema.sql +++ /dev/null @@ -1,14 +0,0 @@ --- noinspection SqlDialectInspectionForFile - --- noinspection SqlNoDataSourceInspectionForFile - -DROP TABLE IF EXISTS event; - -CREATE TABLE event -( - event_id INT PRIMARY KEY AUTO_INCREMENT, - group_id VARCHAR(36) NOT NULL, - user_id VARCHAR(50), - event_type VARCHAR(32), - event_payload VARCHAR(2500) -); From 083044bbbb2e6ff708ddd2dda5307b646bc19db8 Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 26 Mar 2020 16:28:28 +0100 Subject: [PATCH 13/36] update dockerfile: pull wait-for-it from github Co-authored-by: Christoph --- Dockerfile | 4 ++++ pull-wait-for-it.sh | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 pull-wait-for-it.sh diff --git a/Dockerfile b/Dockerfile index cf75fef..a18d8b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,11 @@ FROM gradle:jdk11 AS build COPY --chown=gradle:gradle . /home/gradle/src WORKDIR /home/gradle/src + RUN chmod +x ./pull-wait-for-it.sh +RUN ./pull-wait-for-it.sh +RUN chmod +x ./wait-for-it.sh + RUN gradle bootJar --no-daemon FROM openjdk:11-jre-slim diff --git a/pull-wait-for-it.sh b/pull-wait-for-it.sh new file mode 100644 index 0000000..773c9fe --- /dev/null +++ b/pull-wait-for-it.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ ! -f wait-for-it.sh ]; then + wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh +fi From 63c924dbb92311a0a335aa4274ad955eeb078318 Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 26 Mar 2020 16:30:29 +0100 Subject: [PATCH 14/36] add mysql schema entrypoint Co-authored-by: Christoph --- mysql/db/entrypoint/schema.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 mysql/db/entrypoint/schema.sql diff --git a/mysql/db/entrypoint/schema.sql b/mysql/db/entrypoint/schema.sql new file mode 100644 index 0000000..d3c06d4 --- /dev/null +++ b/mysql/db/entrypoint/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE event +( + event_id INT PRIMARY KEY AUTO_INCREMENT, + group_id VARCHAR(36) NOT NULL, + user_id VARCHAR(50), + event_type VARCHAR(36), + event_payload JSON +); From 666bab0c0311e6077da5d22be67d83bcd6e43bce Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 26 Mar 2020 16:35:31 +0100 Subject: [PATCH 15/36] entrypoint Co-authored-by: Christoph --- .gitignore | 2 +- mysql/db/entrypoint/schema.sql | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 mysql/db/entrypoint/schema.sql diff --git a/.gitignore b/.gitignore index 26e2888..3866aae 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,4 @@ out/ .floo .flooignore -/mysql/* +/mysql/db/storage/ diff --git a/mysql/db/entrypoint/schema.sql b/mysql/db/entrypoint/schema.sql new file mode 100644 index 0000000..d3c06d4 --- /dev/null +++ b/mysql/db/entrypoint/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE event +( + event_id INT PRIMARY KEY AUTO_INCREMENT, + group_id VARCHAR(36) NOT NULL, + user_id VARCHAR(50), + event_type VARCHAR(36), + event_payload JSON +); From dbe3cc7f51c32863eb82efd0569a2261ebf2237e Mon Sep 17 00:00:00 2001 From: "[Mahgs]" Date: Thu, 26 Mar 2020 16:37:28 +0100 Subject: [PATCH 16/36] added show all to search.html --- src/main/resources/templates/search.html | 37 ++++++++++++++---------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/resources/templates/search.html b/src/main/resources/templates/search.html index 2ac45d6..f6117f8 100644 --- a/src/main/resources/templates/search.html +++ b/src/main/resources/templates/search.html @@ -10,7 +10,8 @@
-