Merge pull request #156 from hhu-propra2/JavaDocComments
Java doc comments
This commit is contained in:
@ -2,7 +2,6 @@ package mops.gruppen2.config;
|
||||
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
|
@ -62,7 +62,7 @@ public class WebController {
|
||||
*/
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("")
|
||||
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
|
||||
public String index(KeycloakAuthenticationToken token, Model model) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
|
||||
@ -72,7 +72,7 @@ public class WebController {
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@GetMapping("/createOrga")
|
||||
public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -82,7 +82,7 @@ public class WebController {
|
||||
return "createOrga";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@PostMapping("/createOrga")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
|
||||
@ -93,7 +93,7 @@ public class WebController {
|
||||
@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 {
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
@ -123,7 +123,7 @@ public class WebController {
|
||||
@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 {
|
||||
@RequestParam(value = "parent", required = false) String parent) {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
@ -134,7 +134,7 @@ public class WebController {
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/addUsersFromCsv")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String addUsersFromCsv(KeycloakAuthenticationToken token,
|
||||
@ -173,7 +173,7 @@ public class WebController {
|
||||
public String postChangeMetadata(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("groupId") String groupId) throws EventException {
|
||||
@RequestParam("groupId") String groupId) {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
@ -190,7 +190,7 @@ public class WebController {
|
||||
@GetMapping("/findGroup")
|
||||
public String findGroup(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
|
||||
@RequestParam(value = "suchbegriff", required = false) String search) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<Group> groups = new ArrayList<>();
|
||||
groups = validationService.checkSearch(search, groups, account);
|
||||
@ -201,12 +201,12 @@ public class WebController {
|
||||
return "search";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
@PathVariable("id") String groupId) throws EventException {
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -244,7 +244,7 @@ public class WebController {
|
||||
@PostMapping("/detailsBeitreten")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String joinGroup(KeycloakAuthenticationToken token,
|
||||
Model model, @RequestParam("id") String groupId) throws EventException {
|
||||
Model model, @RequestParam("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
@ -262,7 +262,7 @@ public class WebController {
|
||||
@GetMapping("/detailsSearch")
|
||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam("id") String groupId) throws EventException {
|
||||
@RequestParam("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
UUID parentId = group.getParent();
|
||||
@ -286,7 +286,7 @@ public class WebController {
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("link") String link) throws EventException {
|
||||
@PathVariable("link") String link) {
|
||||
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
@ -322,7 +322,7 @@ public class WebController {
|
||||
@PostMapping("/leaveGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) throws EventException {
|
||||
@RequestParam("group_id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
@ -346,11 +346,11 @@ public class WebController {
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/members/{id}")
|
||||
public String editMembers(Model model,
|
||||
KeycloakAuthenticationToken token,
|
||||
@PathVariable("id") String groupId) throws EventException {
|
||||
@PathVariable("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
@ -364,12 +364,12 @@ public class WebController {
|
||||
return "editMembers";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/changeRole")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeRole(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) throws EventException {
|
||||
@RequestParam("user_id") String userId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User principle = new User(account.getName(), "", "", "");
|
||||
@ -386,7 +386,7 @@ public class WebController {
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/changeMaximum")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeMaxSize(@RequestParam("maximum") Long maximum,
|
||||
@ -401,12 +401,12 @@ public class WebController {
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/deleteUser")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String deleteUser(@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId,
|
||||
KeycloakAuthenticationToken token) throws EventException {
|
||||
KeycloakAuthenticationToken token) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User principle = new User(account.getName(), "", "", "");
|
||||
User user = new User(userId, "", "", "");
|
||||
|
@ -9,14 +9,13 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
//TODO Rename Queries + Formatting
|
||||
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
|
||||
@Query("SELECT DISTINCT group_id FROM event WHERE user_id = :id")
|
||||
List<String> findGroup_idsWhereUser_id(@Param("id") String userId);
|
||||
@Query("SELECT distinct group_id FROM event WHERE user_id =:id AND event_type = :type")
|
||||
List<String> findGroupIdsWhereUserId(@Param("id") String userId, @Param("type") String type);
|
||||
|
||||
@Query("SELECT * FROM event WHERE group_id = :id")
|
||||
List<EventDTO> findEventDTOByGroup_id(@Param("id") String groupId);
|
||||
@Query("SELECT * from event WHERE group_id =:id")
|
||||
List<EventDTO> findEventDTOByGroupId(@Param("id") String groupId);
|
||||
|
||||
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :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);
|
||||
|
||||
@Query("SELECT MAX(event_id) FROM event")
|
||||
Long getHighesEvent_ID();
|
||||
Long getHighesEventID();
|
||||
|
||||
@Query("SELECT * FROM event WHERE event_type = :type")
|
||||
List<EventDTO> findAllEventsByType(@Param("type") String type);
|
||||
|
@ -1,6 +1,5 @@
|
||||
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;
|
||||
@ -21,7 +20,6 @@ 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;
|
||||
@ -59,7 +57,7 @@ public class ControllerService {
|
||||
* @param title Gruppentitel
|
||||
* @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);
|
||||
|
||||
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
|
||||
@ -82,7 +80,20 @@ 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 {
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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) {
|
||||
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.isEmpty()) {
|
||||
try {
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
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");
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
|
@ -29,20 +29,24 @@ public class EventService {
|
||||
* @param event Event, welches gespeichert wird
|
||||
*/
|
||||
public void saveEvent(Event event) {
|
||||
eventStore.save(getDTO(event));
|
||||
eventStore.save(getDTOFromEvent(event));
|
||||
}
|
||||
|
||||
public void saveAll(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
|
||||
public final void saveAll(List<Event>... events) {
|
||||
for (List<Event> eventlist : events) {
|
||||
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.
|
||||
*
|
||||
* @param event Event, welches in DTO übersetzt wird
|
||||
* @return EventDTO Neues DTO
|
||||
* @return EventDTO (Neues DTO)
|
||||
*/
|
||||
//TODO Rename: getDTOFromEvent?
|
||||
public EventDTO getDTO(Event event) {
|
||||
public EventDTO getDTOFromEvent(Event event) {
|
||||
String payload = "";
|
||||
try {
|
||||
payload = jsonService.serializeEvent(event);
|
||||
@ -66,6 +69,11 @@ public class EventService {
|
||||
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) {
|
||||
int lastDot = event.getClass().getName().lastIndexOf('.');
|
||||
|
||||
@ -83,7 +91,7 @@ public class EventService {
|
||||
List<String> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
|
||||
|
||||
List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
|
||||
return translateEventDTOs(groupEventDTOS);
|
||||
return getEventsFromDTOs(groupEventDTOS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,8 +100,7 @@ public class EventService {
|
||||
* @param eventDTOS Liste von DTOs
|
||||
* @return Liste von Events
|
||||
*/
|
||||
//TODO Rename: getEventsFromDTO?
|
||||
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS) {
|
||||
public List<Event> getEventsFromDTOs(Iterable<EventDTO> eventDTOS) {
|
||||
List<Event> events = new ArrayList<>();
|
||||
|
||||
for (EventDTO eventDTO : eventDTOS) {
|
||||
@ -107,20 +114,36 @@ public class EventService {
|
||||
}
|
||||
|
||||
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) {
|
||||
List<EventDTO> eventDTOList = eventStore.findEventDTOByGroup_id(groupId.toString());
|
||||
return translateEventDTOs(eventDTOList);
|
||||
List<EventDTO> eventDTOList = eventStore.findEventDTOByGroupId(groupId.toString());
|
||||
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) {
|
||||
return eventStore.findGroup_idsWhereUser_id(userId).stream()
|
||||
return eventStore.findGroupIdsWhereUserId(userId, "AddUserEvent").stream()
|
||||
.map(UUID::fromString)
|
||||
.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) {
|
||||
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
|
||||
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
||||
|
@ -40,9 +40,9 @@ public class GroupService {
|
||||
public List<Event> getGroupEvents(List<UUID> groupIds) {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (!groups.containsKey(groupId)) {
|
||||
groups.put(groupId, new Group());
|
||||
@ -80,11 +87,11 @@ public class GroupService {
|
||||
//TODO Rename
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
||||
List<Event> groupEvents = eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||
|
||||
@ -104,10 +111,10 @@ public class GroupService {
|
||||
*/
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllLecturesWithVisibilityPublic() {
|
||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
List<Event> createEvents = eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
createEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
createEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
createEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(createEvents);
|
||||
|
||||
@ -140,6 +147,10 @@ public class GroupService {
|
||||
.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) {
|
||||
groups.sort((g1, g2) -> {
|
||||
if (g1.getType() == GroupType.LECTURE) {
|
||||
|
@ -12,7 +12,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
//Hallo
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
@ -24,20 +23,23 @@ public class UserService {
|
||||
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")
|
||||
public List<Group> getUserGroups(User user) throws EventException {
|
||||
public List<Group> getUserGroups(User user) {
|
||||
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
|
||||
List<Event> events = groupService.getGroupEvents(groupIds);
|
||||
List<Group> groups = groupService.projectEventList(events);
|
||||
List<Group> newGroups = new ArrayList<>();
|
||||
|
||||
for (Group group : groups) {
|
||||
if (group.getMembers().contains(user)) {
|
||||
newGroups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
groupService.sortByGroupType(newGroups);
|
||||
|
||||
return newGroups;
|
||||
@ -48,6 +50,12 @@ public class UserService {
|
||||
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 {
|
||||
List<UUID> groupIds = new ArrayList<>();
|
||||
groupIds.add(groupId);
|
||||
|
@ -7,7 +7,7 @@
|
||||
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
||||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" rel="stylesheet">
|
||||
<meta charset="UTF-8">
|
||||
<title>Seite nicht gefunden</title>
|
||||
<title th:text="'MOPS - ' + ${error}"></title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mx-auto" style="vertical-align: center; border-radius: 5px; horiz-align: center; top: 50%; left: 50%;">
|
||||
|
@ -69,7 +69,7 @@ class EventServiceTest {
|
||||
void getDTO() {
|
||||
Event event = createPublicGroupEvent();
|
||||
|
||||
EventDTO dto = eventService.getDTO(event);
|
||||
EventDTO dto = eventService.getDTOFromEvent(event);
|
||||
|
||||
assertThat(dto.getGroup_id()).isEqualTo(event.getGroupId().toString());
|
||||
assertThat(dto.getUser_id()).isEqualTo(event.getUserId());
|
||||
|
Reference in New Issue
Block a user