1
Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-27 12:57:47 +01:00
parent cc64943663
commit 56a81ce66f
7 changed files with 26 additions and 25 deletions

View File

@ -2,6 +2,7 @@ package mops.gruppen2;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
@ -14,6 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Collections; import java.util.Collections;
@SpringBootApplication @SpringBootApplication
@EnableCaching
@EnableSwagger2 @EnableSwagger2
public class Gruppen2Application { public class Gruppen2Application {

View File

@ -13,6 +13,7 @@ import mops.gruppen2.service.KeyCloakService;
import mops.gruppen2.service.UserService; import mops.gruppen2.service.UserService;
import mops.gruppen2.service.ValidationService; import mops.gruppen2.service.ValidationService;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -80,6 +81,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/createOrga") @PostMapping("/createOrga")
@CacheEvict(value = "groups", allEntries = true)
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token, public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
@RequestParam("title") String title, @RequestParam("title") String title,
@RequestParam("description") String description, @RequestParam("description") String description,
@ -110,6 +112,7 @@ public class WebController {
@RolesAllowed({"ROLE_studentin"}) @RolesAllowed({"ROLE_studentin"})
@PostMapping("/createStudent") @PostMapping("/createStudent")
@CacheEvict(value = "groups", allEntries = true)
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token, public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
@RequestParam("title") String title, @RequestParam("title") String title,
@RequestParam("description") String description, @RequestParam("description") String description,
@ -127,6 +130,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/details/members/addUsersFromCsv") @PostMapping("/details/members/addUsersFromCsv")
@CacheEvict(value = "groups", allEntries = true)
public String addUsersFromCsv(KeycloakAuthenticationToken token, public String addUsersFromCsv(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId, @RequestParam("group_id") String groupId,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException { @RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
@ -166,6 +170,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/details/changeMetadata") @PostMapping("/details/changeMetadata")
@CacheEvict(value = "groups", allEntries = true)
public String pChangeMetadata(KeycloakAuthenticationToken token, public String pChangeMetadata(KeycloakAuthenticationToken token,
@RequestParam("title") String title, @RequestParam("title") String title,
@RequestParam("description") String description, @RequestParam("description") String description,
@ -232,6 +237,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten") @PostMapping("/detailsBeitreten")
@CacheEvict(value = "groups", allEntries = true)
public String joinGroup(KeycloakAuthenticationToken token, public String joinGroup(KeycloakAuthenticationToken token,
Model model, @RequestParam("id") String groupId) throws EventException { Model model, @RequestParam("id") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
@ -263,8 +269,10 @@ public class WebController {
return "detailsNoMember"; return "detailsNoMember";
} }
//TODO: Muss post-mapping sein
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/acceptinvite/{link}") @PostMapping("/acceptinvite/{link}")
@CacheEvict(value = "groups", allEntries = true)
public String acceptInvite(KeycloakAuthenticationToken token, public String acceptInvite(KeycloakAuthenticationToken token,
Model model, Model model,
@PathVariable("link") String link) throws EventException { @PathVariable("link") String link) throws EventException {
@ -280,6 +288,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup") @PostMapping("/leaveGroup")
@CacheEvict(value = "groups", allEntries = true)
public String pLeaveGroup(KeycloakAuthenticationToken token, public String pLeaveGroup(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId) throws EventException { @RequestParam("group_id") String groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
@ -292,6 +301,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/deleteGroup") @PostMapping("/deleteGroup")
@CacheEvict(value = "groups", allEntries = true)
public String pDeleteGroup(KeycloakAuthenticationToken token, public String pDeleteGroup(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId) { @RequestParam("group_id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
@ -320,6 +330,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeRole") @PostMapping("/details/members/changeRole")
@CacheEvict(value = "groups", allEntries = true)
public String changeRole(KeycloakAuthenticationToken token, public String changeRole(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId, @RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) throws EventException { @RequestParam("user_id") String userId) throws EventException {
@ -332,6 +343,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeMaximum") @PostMapping("/details/members/changeMaximum")
@CacheEvict(value = "groups", allEntries = true)
public String changeMaxSize(@RequestParam("maximum") Long maximum, public String changeMaxSize(@RequestParam("maximum") Long maximum,
@RequestParam("group_id") String groupId, @RequestParam("group_id") String groupId,
KeycloakAuthenticationToken token) { KeycloakAuthenticationToken token) {
@ -343,6 +355,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser") @PostMapping("/details/members/deleteUser")
@CacheEvict(value = "groups", allEntries = true)
public String deleteUser(@RequestParam("group_id") String groupId, public String deleteUser(@RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) throws EventException { @RequestParam("user_id") String userId) throws EventException {
User user = new User(userId, "", "", ""); User user = new User(userId, "", "", "");

View File

@ -8,6 +8,7 @@ import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.security.Account; import mops.gruppen2.security.Account;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -77,6 +78,7 @@ public class GroupService {
* @throws EventException Projektionsfehler * @throws EventException Projektionsfehler
*/ */
//TODO Rename //TODO Rename
@Cacheable("groups")
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException { public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent")); List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent"))); groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
@ -100,6 +102,7 @@ public class GroupService {
* *
* @return List of groups * @return List of groups
*/ */
@Cacheable("groups")
public List<Group> getAllLecturesWithVisibilityPublic() { public List<Group> getAllLecturesWithVisibilityPublic() {
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent")); List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent"))); createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
@ -124,6 +127,7 @@ public class GroupService {
* @throws EventException Projektionsfehler * @throws EventException Projektionsfehler
*/ */
//Todo Rename //Todo Rename
@Cacheable("groups")
public List<Group> findGroupWith(String search, Account account) throws EventException { public List<Group> findGroupWith(String search, Account account) throws EventException {
if (search.isEmpty()) { if (search.isEmpty()) {
return getAllGroupWithVisibilityPublic(account.getName()); return getAllGroupWithVisibilityPublic(account.getName());

View File

@ -5,6 +5,7 @@ import mops.gruppen2.domain.User;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupNotFoundException; import mops.gruppen2.domain.exception.GroupNotFoundException;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -25,6 +26,7 @@ public class UserService {
//Test nötig?? //Test nötig??
@Cacheable("groups")
public List<Group> getUserGroups(User user) throws EventException { public List<Group> getUserGroups(User user) throws EventException {
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId()); List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
List<Event> events = groupService.getGroupEvents(groupIds); List<Event> events = groupService.getGroupEvents(groupIds);
@ -41,6 +43,7 @@ public class UserService {
return newGroups; return newGroups;
} }
@Cacheable("groups")
public List<Group> getUserGroups(String userId) throws EventException { public List<Group> getUserGroups(String userId) throws EventException {
return getUserGroups(new User(userId, null, null, null)); return getUserGroups(new User(userId, null, null, null));
} }

View File

@ -19,3 +19,4 @@ keycloak.use-resource-role-mappings=true
keycloak.autodetect-bearer-only=true keycloak.autodetect-bearer-only=true
keycloak.confidential-port=443 keycloak.confidential-port=443
server.error.include-stacktrace=always server.error.include-stacktrace=always
management.endpoints.web.exposure.include=info,health

View File

@ -15,4 +15,5 @@ keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1
keycloak.verify-token-audience=true keycloak.verify-token-audience=true
keycloak.use-resource-role-mappings=true keycloak.use-resource-role-mappings=true
keycloak.autodetect-bearer-only=true keycloak.autodetect-bearer-only=true
keycloak.confidential-port= 443 keycloak.confidential-port=443
management.endpoints.web.exposure.include=info,health

View File

@ -1,23 +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)
);
DROP TABLE IF EXISTS invite;
CREATE TABLE invite
(
invite_id INT PRIMARY KEY AUTO_INCREMENT,
group_id VARCHAR(36) NOT NULL,
invite_link VARCHAR(36) NOT NULL
);