1

Merge pull request #156 from hhu-propra2/JavaDocComments

Java doc comments
This commit is contained in:
Talha Caliskan
2020-03-27 16:45:42 +01:00
committed by GitHub
9 changed files with 123 additions and 66 deletions

View File

@ -2,7 +2,6 @@ package mops.gruppen2.config;
import mops.gruppen2.service.EventService; import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService; import mops.gruppen2.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration

View File

@ -62,7 +62,7 @@ public class WebController {
*/ */
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("") @GetMapping("")
public String index(KeycloakAuthenticationToken token, Model model) throws EventException { public String index(KeycloakAuthenticationToken token, Model model) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
@ -72,7 +72,7 @@ public class WebController {
return "index"; return "index";
} }
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_actuator"})
@GetMapping("/createOrga") @GetMapping("/createOrga")
public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) { public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
@ -82,7 +82,7 @@ public class WebController {
return "createOrga"; return "createOrga";
} }
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_actuator"})
@PostMapping("/createOrga") @PostMapping("/createOrga")
@CacheEvict(value = "groups", allEntries = true) @CacheEvict(value = "groups", allEntries = true)
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token, public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
@ -93,7 +93,7 @@ public class WebController {
@RequestParam("userMaximum") Long userMaximum, @RequestParam("userMaximum") Long userMaximum,
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, @RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers,
@RequestParam(value = "parent", required = false) String parent, @RequestParam(value = "parent", required = false) String parent,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException { @RequestParam(value = "file", required = false) MultipartFile file) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
UUID parentUUID = controllerService.getUUID(parent); UUID parentUUID = controllerService.getUUID(parent);
@ -123,7 +123,7 @@ public class WebController {
@RequestParam(value = "visibility", required = false) Boolean visibility, @RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam("userMaximum") Long userMaximum, @RequestParam("userMaximum") Long userMaximum,
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers, @RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers,
@RequestParam(value = "parent", required = false) String parent) throws EventException { @RequestParam(value = "parent", required = false) String parent) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
UUID parentUUID = controllerService.getUUID(parent); UUID parentUUID = controllerService.getUUID(parent);
@ -134,7 +134,7 @@ public class WebController {
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_actuator"})
@PostMapping("/details/members/addUsersFromCsv") @PostMapping("/details/members/addUsersFromCsv")
@CacheEvict(value = "groups", allEntries = true) @CacheEvict(value = "groups", allEntries = true)
public String addUsersFromCsv(KeycloakAuthenticationToken token, public String addUsersFromCsv(KeycloakAuthenticationToken token,
@ -173,7 +173,7 @@ public class WebController {
public String postChangeMetadata(KeycloakAuthenticationToken token, public String postChangeMetadata(KeycloakAuthenticationToken token,
@RequestParam("title") String title, @RequestParam("title") String title,
@RequestParam("description") String description, @RequestParam("description") String description,
@RequestParam("groupId") String groupId) throws EventException { @RequestParam("groupId") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), "", "", ""); User user = new User(account.getName(), "", "", "");
@ -190,7 +190,7 @@ public class WebController {
@GetMapping("/findGroup") @GetMapping("/findGroup")
public String findGroup(KeycloakAuthenticationToken token, public String findGroup(KeycloakAuthenticationToken token,
Model model, Model model,
@RequestParam(value = "suchbegriff", required = false) String search) throws EventException { @RequestParam(value = "suchbegriff", required = false) String search) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
List<Group> groups = new ArrayList<>(); List<Group> groups = new ArrayList<>();
groups = validationService.checkSearch(search, groups, account); groups = validationService.checkSearch(search, groups, account);
@ -201,12 +201,12 @@ public class WebController {
return "search"; return "search";
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/details/{id}") @GetMapping("/details/{id}")
public String showGroupDetails(KeycloakAuthenticationToken token, public String showGroupDetails(KeycloakAuthenticationToken token,
Model model, Model model,
HttpServletRequest request, HttpServletRequest request,
@PathVariable("id") String groupId) throws EventException { @PathVariable("id") String groupId) {
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
@ -244,7 +244,7 @@ public class WebController {
@PostMapping("/detailsBeitreten") @PostMapping("/detailsBeitreten")
@CacheEvict(value = "groups", allEntries = true) @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) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
@ -262,7 +262,7 @@ public class WebController {
@GetMapping("/detailsSearch") @GetMapping("/detailsSearch")
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
Model model, Model model,
@RequestParam("id") String groupId) throws EventException { @RequestParam("id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
UUID parentId = group.getParent(); UUID parentId = group.getParent();
@ -286,7 +286,7 @@ public class WebController {
@GetMapping("/acceptinvite/{link}") @GetMapping("/acceptinvite/{link}")
public String acceptInvite(KeycloakAuthenticationToken token, public String acceptInvite(KeycloakAuthenticationToken token,
Model model, Model model,
@PathVariable("link") String link) throws EventException { @PathVariable("link") String link) {
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link)); Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
validationService.throwIfGroupNotExisting(group.getTitle()); validationService.throwIfGroupNotExisting(group.getTitle());
@ -322,7 +322,7 @@ public class WebController {
@PostMapping("/leaveGroup") @PostMapping("/leaveGroup")
@CacheEvict(value = "groups", allEntries = true) @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) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), "", "", ""); User user = new User(account.getName(), "", "", "");
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
@ -346,11 +346,11 @@ public class WebController {
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/details/members/{id}") @GetMapping("/details/members/{id}")
public String editMembers(Model model, public String editMembers(Model model,
KeycloakAuthenticationToken token, KeycloakAuthenticationToken token,
@PathVariable("id") String groupId) throws EventException { @PathVariable("id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
User user = new User(account.getName(), "", "", ""); User user = new User(account.getName(), "", "", "");
@ -364,12 +364,12 @@ public class WebController {
return "editMembers"; return "editMembers";
} }
@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) @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) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
User principle = new User(account.getName(), "", "", ""); User principle = new User(account.getName(), "", "", "");
@ -386,7 +386,7 @@ public class WebController {
return "redirect:/gruppen2/details/members/" + groupId; return "redirect:/gruppen2/details/members/" + groupId;
} }
@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) @CacheEvict(value = "groups", allEntries = true)
public String changeMaxSize(@RequestParam("maximum") Long maximum, public String changeMaxSize(@RequestParam("maximum") Long maximum,
@ -401,12 +401,12 @@ public class WebController {
return "redirect:/gruppen2/details/members/" + groupId; return "redirect:/gruppen2/details/members/" + groupId;
} }
@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) @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, @RequestParam("user_id") String userId,
KeycloakAuthenticationToken token) throws EventException { KeycloakAuthenticationToken token) {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User principle = new User(account.getName(), "", "", ""); User principle = new User(account.getName(), "", "", "");
User user = new User(userId, "", "", ""); User user = new User(userId, "", "", "");

View File

@ -9,14 +9,13 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository @Repository
//TODO Rename Queries + Formatting
public interface EventRepository extends CrudRepository<EventDTO, Long> { public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("SELECT DISTINCT group_id FROM event WHERE user_id = :id") @Query("SELECT distinct group_id FROM event WHERE user_id =:id AND event_type = :type")
List<String> findGroup_idsWhereUser_id(@Param("id") String userId); List<String> findGroupIdsWhereUserId(@Param("id") String userId, @Param("type") String type);
@Query("SELECT * FROM event WHERE group_id = :id") @Query("SELECT * from event WHERE group_id =:id")
List<EventDTO> findEventDTOByGroup_id(@Param("id") String groupId); List<EventDTO> findEventDTOByGroupId(@Param("id") String groupId);
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status") @Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
List<String> findNewEventSinceStatus(@Param("status") Long status); List<String> findNewEventSinceStatus(@Param("status") Long status);
@ -25,7 +24,7 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
List<EventDTO> findAllEventsOfGroups(@Param("groupIds") List<String> groupIds); List<EventDTO> findAllEventsOfGroups(@Param("groupIds") List<String> groupIds);
@Query("SELECT MAX(event_id) FROM event") @Query("SELECT MAX(event_id) FROM event")
Long getHighesEvent_ID(); Long getHighesEventID();
@Query("SELECT * FROM event WHERE event_type = :type") @Query("SELECT * FROM event WHERE event_type = :type")
List<EventDTO> findAllEventsByType(@Param("type") String type); List<EventDTO> findAllEventsByType(@Param("type") String type);

View File

@ -1,6 +1,5 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role; import mops.gruppen2.domain.Role;
@ -21,7 +20,6 @@ import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.CharConversionException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -59,7 +57,7 @@ public class ControllerService {
* @param title Gruppentitel * @param title Gruppentitel
* @param description Gruppenbeschreibung * @param description Gruppenbeschreibung
*/ */
public UUID createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, 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) {
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate); Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
@ -82,7 +80,20 @@ public class ControllerService {
return groupId; 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 { /**
* Wie createGroup, nur das hier die Gruppe auch als Veranstaltung gesetzt werden kann und CSV Dateien mit Nutzern
* eingelesen werden können.
* @param account Der Nutzer der die Gruppe erstellt
* @param title Parameter für die neue Gruppe
* @param description Parameter für die neue Gruppe
* @param isVisibilityPrivate Parameter für die neue Gruppe
* @param isLecture Parameter für die neue Gruppe
* @param isMaximumInfinite Parameter für die neue Gruppe
* @param userMaximum Parameter für die neue Gruppe
* @param parent Parameter für die neue Gruppe
* @param file Parameter für die neue Gruppe
*/
public void createGroupAsOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) {
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
List<User> newUsers = readCsvFile(file); List<User> newUsers = readCsvFile(file);
@ -140,7 +151,13 @@ public class ControllerService {
} }
} }
/**
* Wenn die maximale Useranzahl unendlich ist, wird das Maximum auf 100000 gesetzt. Praktisch gibt es also Maximla 100000
* Nutzer pro Gruppe.
* @param isMaximumInfinite Gibt an ob es unendlich viele User geben soll
* @param userMaximum Das Maximum an Usern, falls es eins gibt
* @return Maximum an Usern
*/
private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) { private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) {
isMaximumInfinite = isMaximumInfinite != null; isMaximumInfinite = isMaximumInfinite != null;
@ -170,13 +187,13 @@ public class ControllerService {
} }
} }
private List<User> readCsvFile(MultipartFile file) throws EventException, IOException { private List<User> readCsvFile(MultipartFile file) throws EventException{
if(file == null) return new ArrayList<>(); if(file == null) return new ArrayList<>();
if (!file.isEmpty()) { if (!file.isEmpty()) {
try { try {
List<User> userList = CsvService.read(file.getInputStream()); List<User> userList = CsvService.read(file.getInputStream());
return userList.stream().distinct().collect(Collectors.toList()); //filters duplicates from list return userList.stream().distinct().collect(Collectors.toList()); //filters duplicates from list
} catch (UnrecognizedPropertyException | CharConversionException ex) { } catch (IOException ex) {
logger.warning("File konnte nicht gelesen werden"); logger.warning("File konnte nicht gelesen werden");
throw new WrongFileException(file.getOriginalFilename()); throw new WrongFileException(file.getOriginalFilename());
} }

View File

@ -29,20 +29,24 @@ public class EventService {
* @param event Event, welches gespeichert wird * @param event Event, welches gespeichert wird
*/ */
public void saveEvent(Event event) { public void saveEvent(Event event) {
eventStore.save(getDTO(event)); eventStore.save(getDTOFromEvent(event));
} }
public void saveAll(Event... events) { public void saveAll(Event... events) {
for (Event event : events) { for (Event event : events) {
eventStore.save(getDTO(event)); eventStore.save(getDTOFromEvent(event));
} }
} }
/**
* Speichert alle Events aus der übergebenen Liste in der DB.
* @param events Liste an Events die gespeichert werden soll
*/
@SafeVarargs @SafeVarargs
public final void saveAll(List<Event>... events) { public final void saveAll(List<Event>... events) {
for (List<Event> eventlist : events) { for (List<Event> eventlist : events) {
for (Event event : eventlist) { for (Event event : eventlist) {
eventStore.save(getDTO(event)); eventStore.save(getDTOFromEvent(event));
} }
} }
} }
@ -52,10 +56,9 @@ public class EventService {
* Ist die Gruppe öffentlich, dann wird die visibility auf true gesetzt. * Ist die Gruppe öffentlich, dann wird die visibility auf true gesetzt.
* *
* @param event Event, welches in DTO übersetzt wird * @param event Event, welches in DTO übersetzt wird
* @return EventDTO Neues DTO * @return EventDTO (Neues DTO)
*/ */
//TODO Rename: getDTOFromEvent? public EventDTO getDTOFromEvent(Event event) {
public EventDTO getDTO(Event event) {
String payload = ""; String payload = "";
try { try {
payload = jsonService.serializeEvent(event); payload = jsonService.serializeEvent(event);
@ -66,6 +69,11 @@ public class EventService {
return new EventDTO(null, event.getGroupId().toString(), event.getUserId(), getEventType(event), payload); return new EventDTO(null, event.getGroupId().toString(), event.getUserId(), getEventType(event), payload);
} }
/**
* Gibt den Eventtyp als String wieder.
* @param event Event dessen Typ abgefragt werden soll
* @return Der Name des Typs des Events
*/
private String getEventType(Event event) { private String getEventType(Event event) {
int lastDot = event.getClass().getName().lastIndexOf('.'); int lastDot = event.getClass().getName().lastIndexOf('.');
@ -83,7 +91,7 @@ public class EventService {
List<String> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status); List<String> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged); List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
return translateEventDTOs(groupEventDTOS); return getEventsFromDTOs(groupEventDTOS);
} }
/** /**
@ -92,8 +100,7 @@ public class EventService {
* @param eventDTOS Liste von DTOs * @param eventDTOS Liste von DTOs
* @return Liste von Events * @return Liste von Events
*/ */
//TODO Rename: getEventsFromDTO? public List<Event> getEventsFromDTOs(Iterable<EventDTO> eventDTOS) {
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS) {
List<Event> events = new ArrayList<>(); List<Event> events = new ArrayList<>();
for (EventDTO eventDTO : eventDTOS) { for (EventDTO eventDTO : eventDTOS) {
@ -107,20 +114,36 @@ public class EventService {
} }
public Long getMaxEvent_id() { public Long getMaxEvent_id() {
return eventStore.getHighesEvent_ID(); return eventStore.getHighesEventID();
} }
/**
* Gibt eine Liste mit allen Events zurück, die zu der Gruppe gehören.
* @param groupId Gruppe die betrachtet werden soll
* @return Liste aus Events
*/
public List<Event> getEventsOfGroup(UUID groupId) { public List<Event> getEventsOfGroup(UUID groupId) {
List<EventDTO> eventDTOList = eventStore.findEventDTOByGroup_id(groupId.toString()); List<EventDTO> eventDTOList = eventStore.findEventDTOByGroupId(groupId.toString());
return translateEventDTOs(eventDTOList); return getEventsFromDTOs(eventDTOList);
} }
/**
* Gibt eine Liste aus GruppenIds zurück in denen sich der User befindet.
* @param userId Die Id des Users
* @return Liste aus GruppenIds
*/
public List<UUID> findGroupIdsByUser(String userId) { public List<UUID> findGroupIdsByUser(String userId) {
return eventStore.findGroup_idsWhereUser_id(userId).stream() return eventStore.findGroupIdsWhereUserId(userId, "AddUserEvent").stream()
.map(UUID::fromString) .map(UUID::fromString)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* Gibt true zurück, falls der User aktuell in der Gruppe ist, sonst false.
* @param groupId Id der Gruppe
* @param userId Id des zu überprüfenden Users
* @return true or false
*/
public boolean userInGroup(UUID groupId, String userId) { public boolean userInGroup(UUID groupId, String userId) {
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent") return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent"); > eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");

View File

@ -40,9 +40,9 @@ public class GroupService {
public List<Event> getGroupEvents(List<UUID> groupIds) { public List<Event> getGroupEvents(List<UUID> groupIds) {
List<EventDTO> eventDTOS = new ArrayList<>(); List<EventDTO> eventDTOS = new ArrayList<>();
for (UUID groupId : groupIds) { for (UUID groupId : groupIds) {
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(groupId.toString())); eventDTOS.addAll(eventRepository.findEventDTOByGroupId(groupId.toString()));
} }
return eventService.translateEventDTOs(eventDTOS); return eventService.getEventsFromDTOs(eventDTOS);
} }
/** /**
@ -62,6 +62,13 @@ public class GroupService {
return new ArrayList<>(groupMap.values()); return new ArrayList<>(groupMap.values());
} }
/**
* Gibt die Gruppe mit der richtigen Id aus der übergebenen Map wieder, existiert diese nicht
* wird die Gruppe erstellt und der Map hizugefügt.
* @param groups Map aus GruppenIds und Gruppen
* @param groupId Die Id der Gruppe, die zurückgegeben werden soll
* @return Die gesuchte Gruppe
*/
private Group getOrCreateGroup(Map<UUID, Group> groups, UUID groupId) { private Group getOrCreateGroup(Map<UUID, Group> groups, UUID groupId) {
if (!groups.containsKey(groupId)) { if (!groups.containsKey(groupId)) {
groups.put(groupId, new Group()); groups.put(groupId, new Group());
@ -80,11 +87,11 @@ public class GroupService {
//TODO Rename //TODO Rename
@Cacheable("groups") @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.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent"))); groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent"))); groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent"))); groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent"))); groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
List<Group> visibleGroups = projectEventList(groupEvents); List<Group> visibleGroups = projectEventList(groupEvents);
@ -104,10 +111,10 @@ public class GroupService {
*/ */
@Cacheable("groups") @Cacheable("groups")
public List<Group> getAllLecturesWithVisibilityPublic() { public List<Group> getAllLecturesWithVisibilityPublic() {
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent")); List<Event> createEvents = eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent"))); createEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent"))); createEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent"))); createEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
List<Group> visibleGroups = projectEventList(createEvents); List<Group> visibleGroups = projectEventList(createEvents);
@ -140,6 +147,10 @@ public class GroupService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* Sortiert die übergebene Liste an Gruppen, sodass Veranstaltungen am Anfang der Liste sind.
* @param groups Die Liste von Gruppen die sortiert werden soll
*/
public void sortByGroupType(List<Group> groups) { public void sortByGroupType(List<Group> groups) {
groups.sort((g1, g2) -> { groups.sort((g1, g2) -> {
if (g1.getType() == GroupType.LECTURE) { if (g1.getType() == GroupType.LECTURE) {

View File

@ -12,7 +12,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
//Hallo
@Service @Service
public class UserService { public class UserService {
@ -24,20 +23,23 @@ public class UserService {
this.eventService = eventService; this.eventService = eventService;
} }
//Test nötig?? /**
* Gibt eine Liste aus Gruppen zurück, in denen sich der übergebene User befindet.
* @param user Der User
* @return Liste aus Gruppen
*/
@Cacheable("groups") @Cacheable("groups")
public List<Group> getUserGroups(User user) throws EventException { public List<Group> getUserGroups(User user) {
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);
List<Group> groups = groupService.projectEventList(events); List<Group> groups = groupService.projectEventList(events);
List<Group> newGroups = new ArrayList<>(); List<Group> newGroups = new ArrayList<>();
for (Group group : groups) { for (Group group : groups) {
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
newGroups.add(group); newGroups.add(group);
} }
} }
groupService.sortByGroupType(newGroups); groupService.sortByGroupType(newGroups);
return newGroups; return newGroups;
@ -48,6 +50,12 @@ public class UserService {
return getUserGroups(new User(userId, null, null, null)); return getUserGroups(new User(userId, null, null, null));
} }
/**
* Gibt die Gruppe zurück, die zu der übergebenen Id passt.
* @param groupId Die Id der gesuchten Gruppe
* @return Die gesuchte Gruppe
* @throws EventException Wenn die Gruppe nicht gefunden wird
*/
public Group getGroupById(UUID groupId) throws EventException { public Group getGroupById(UUID groupId) throws EventException {
List<UUID> groupIds = new ArrayList<>(); List<UUID> groupIds = new ArrayList<>();
groupIds.add(groupId); groupIds.add(groupId);

View File

@ -7,7 +7,7 @@
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" <link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" rel="stylesheet"> integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" rel="stylesheet">
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Seite nicht gefunden</title> <title th:text="'MOPS - ' + ${error}"></title>
</head> </head>
<body> <body>
<div class="mx-auto" style="vertical-align: center; border-radius: 5px; horiz-align: center; top: 50%; left: 50%;"> <div class="mx-auto" style="vertical-align: center; border-radius: 5px; horiz-align: center; top: 50%; left: 50%;">

View File

@ -69,7 +69,7 @@ class EventServiceTest {
void getDTO() { void getDTO() {
Event event = createPublicGroupEvent(); Event event = createPublicGroupEvent();
EventDTO dto = eventService.getDTO(event); EventDTO dto = eventService.getDTOFromEvent(event);
assertThat(dto.getGroup_id()).isEqualTo(event.getGroupId().toString()); assertThat(dto.getGroup_id()).isEqualTo(event.getGroupId().toString());
assertThat(dto.getUser_id()).isEqualTo(event.getUserId()); assertThat(dto.getUser_id()).isEqualTo(event.getUserId());