greater projectionservice refactoring
This commit is contained in:
@ -42,14 +42,14 @@ public class APIController {
|
|||||||
public GroupRequestWrapper updateGroups(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long lastEventId) throws EventException {
|
public GroupRequestWrapper updateGroups(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long lastEventId) throws EventException {
|
||||||
List<Event> events = eventStoreService.getNewEvents(lastEventId);
|
List<Event> events = eventStoreService.getNewEvents(lastEventId);
|
||||||
|
|
||||||
return APIService.wrap(eventStoreService.getMaxEventId(), projectionService.projectEventList(events));
|
return APIService.wrap(eventStoreService.getMaxEventId(), ProjectionService.projectEventList(events));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getGroupIdsOfUser/{userId}")
|
@GetMapping("/getGroupIdsOfUser/{userId}")
|
||||||
@Secured("ROLE_api_user")
|
@Secured("ROLE_api_user")
|
||||||
@ApiOperation("Gibt alle Gruppen zurück, in denen sich ein Teilnehmer befindet")
|
@ApiOperation("Gibt alle Gruppen zurück, in denen sich ein Teilnehmer befindet")
|
||||||
public List<String> getGroupIdsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String userId) {
|
public List<String> getGroupIdsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String userId) {
|
||||||
return projectionService.getUserGroups(userId).stream()
|
return projectionService.projectGroupsByUser(userId).stream()
|
||||||
.map(group -> group.getId().toString())
|
.map(group -> group.getId().toString())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ public class APIController {
|
|||||||
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||||
public Group getGroupById(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
|
public Group getGroupById(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
|
||||||
List<Event> eventList = eventStoreService.getEventsOfGroup(UUID.fromString(groupId));
|
List<Event> eventList = eventStoreService.getEventsOfGroup(UUID.fromString(groupId));
|
||||||
List<Group> groups = projectionService.projectEventList(eventList);
|
List<Group> groups = ProjectionService.projectEventList(eventList);
|
||||||
|
|
||||||
if (groups.isEmpty()) {
|
if (groups.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -45,7 +45,7 @@ public class GroupCreationController {
|
|||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("lectures", projectionService.getAllLecturesWithVisibilityPublic());
|
model.addAttribute("lectures", projectionService.projectLectures());
|
||||||
|
|
||||||
return "createOrga";
|
return "createOrga";
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ public class GroupCreationController {
|
|||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("lectures", projectionService.getAllLecturesWithVisibilityPublic());
|
model.addAttribute("lectures", projectionService.projectLectures());
|
||||||
|
|
||||||
return "createStudent";
|
return "createStudent";
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class GroupDetailsController {
|
|||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
@PathVariable("id") String groupId) {
|
@PathVariable("id") String groupId) {
|
||||||
|
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
UUID parentId = group.getParent();
|
UUID parentId = group.getParent();
|
||||||
@ -93,7 +93,7 @@ public class GroupDetailsController {
|
|||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
validationService.throwIfNoAdmin(group, user);
|
validationService.throwIfNoAdmin(group, user);
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ public class GroupDetailsController {
|
|||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
validationService.throwIfNoAdmin(group, user);
|
validationService.throwIfNoAdmin(group, user);
|
||||||
validationService.checkFields(title, description);
|
validationService.checkFields(title, description);
|
||||||
@ -135,7 +135,7 @@ public class GroupDetailsController {
|
|||||||
@PathVariable("id") String groupId) {
|
@PathVariable("id") String groupId) {
|
||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
|
|
||||||
validationService.throwIfNoAdmin(group, user);
|
validationService.throwIfNoAdmin(group, user);
|
||||||
@ -156,7 +156,7 @@ public class GroupDetailsController {
|
|||||||
@RequestParam("user_id") String userId) {
|
@RequestParam("user_id") String userId) {
|
||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
User principle = new User(account);
|
User principle = new User(account);
|
||||||
User user = new User(userId, "", "", "");
|
User user = new User(userId, "", "", "");
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ public class GroupDetailsController {
|
|||||||
@RequestParam("group_id") String groupId) {
|
@RequestParam("group_id") String groupId) {
|
||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
validationService.throwIfNewMaximumIsValid(maximum, group);
|
validationService.throwIfNewMaximumIsValid(maximum, group);
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ public class GroupDetailsController {
|
|||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User principle = new User(account);
|
User principle = new User(account);
|
||||||
User user = new User(userId, "", "", "");
|
User user = new User(userId, "", "", "");
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
validationService.throwIfNoAdmin(group, principle);
|
validationService.throwIfNoAdmin(group, principle);
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ public class GroupDetailsController {
|
|||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||||
validationService.throwIfGroupFull(group);
|
validationService.throwIfGroupFull(group);
|
||||||
@ -242,7 +242,7 @@ public class GroupDetailsController {
|
|||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
groupService.deleteUser(account, user, group);
|
groupService.deleteUser(account, user, group);
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ public class GroupDetailsController {
|
|||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
validationService.throwIfNoAdmin(group, user);
|
validationService.throwIfNoAdmin(group, user);
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class GruppenfindungController {
|
|||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("gruppen", projectionService.getUserGroups(user));
|
model.addAttribute("gruppen", projectionService.projectGroupsByUser(user));
|
||||||
model.addAttribute("user", user);
|
model.addAttribute("user", user);
|
||||||
|
|
||||||
return "index";
|
return "index";
|
||||||
|
@ -66,7 +66,7 @@ public class SearchAndInviteController {
|
|||||||
@RequestParam("id") String groupId) {
|
@RequestParam("id") String groupId) {
|
||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
UUID parentId = group.getParent();
|
UUID parentId = group.getParent();
|
||||||
Group parent = groupService.getParent(parentId);
|
Group parent = groupService.getParent(parentId);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
@ -89,7 +89,7 @@ public class SearchAndInviteController {
|
|||||||
Model model,
|
Model model,
|
||||||
@PathVariable("link") String link) {
|
@PathVariable("link") String link) {
|
||||||
|
|
||||||
Group group = projectionService.getGroupById(inviteService.getGroupIdFromLink(link));
|
Group group = projectionService.projectSingleGroupById(inviteService.getGroupIdFromLink(link));
|
||||||
|
|
||||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public class SearchAndInviteController {
|
|||||||
|
|
||||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account);
|
User user = new User(account);
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||||
validationService.throwIfGroupFull(group);
|
validationService.throwIfGroupFull(group);
|
||||||
|
@ -22,4 +22,16 @@ public class User {
|
|||||||
familyname = account.getFamilyname();
|
familyname = account.getFamilyname();
|
||||||
email = account.getEmail();
|
email = account.getEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User identifizieren sich über die Id, mehr wird also manchmal nicht benötigt.
|
||||||
|
*
|
||||||
|
* @param userId Die User Id
|
||||||
|
*/
|
||||||
|
public User(String userId) {
|
||||||
|
id = userId;
|
||||||
|
givenname = "";
|
||||||
|
familyname = "";
|
||||||
|
email = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,64 +14,68 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
|||||||
// ####################################### GROUP IDs #########################################
|
// ####################################### GROUP IDs #########################################
|
||||||
|
|
||||||
@Query("SELECT DISTINCT group_id FROM event"
|
@Query("SELECT DISTINCT group_id FROM event"
|
||||||
+ "WHERE user_id = :userId AND event_type = :type")
|
+ " WHERE user_id = :userId AND event_type = :type")
|
||||||
List<String> findGroupIdsByUserAndType(@Param("userId") String userId,
|
List<String> findGroupIdsByUserAndType(@Param("userId") String userId,
|
||||||
@Param("type") String type);
|
@Param("type") String type);
|
||||||
|
|
||||||
@Query("SELECT DISTINCT group_id FROM event"
|
@Query("SELECT DISTINCT group_id FROM event"
|
||||||
+ "WHERE event_id > :status")
|
+ " WHERE event_id > :status")
|
||||||
List<String> findGroupIdsWhereEventIdGreaterThanStatus(@Param("status") Long status);
|
List<String> findGroupIdsWhereEventIdGreaterThanStatus(@Param("status") Long status);
|
||||||
|
|
||||||
// ####################################### EVENT DTOs ########################################
|
// ####################################### EVENT DTOs ########################################
|
||||||
|
|
||||||
@Query("SELECT * from event"
|
@Query("SELECT * FROM event"
|
||||||
+ "WHERE group_id = :groupId")
|
+ " WHERE group_id IN (:groupIds) ")
|
||||||
List<EventDTO> findEventDTOsByGroup(@Param("groupId") String groupId);
|
List<EventDTO> findEventDTOsByGroup(@Param("groupIds") List<String> groupIds);
|
||||||
|
|
||||||
@Query("SELECT * FROM event"
|
@Query("SELECT * FROM event"
|
||||||
+ "WHERE group_id IN (:groupIds) ")
|
+ " WHERE group_id IN (:userIds) ")
|
||||||
List<EventDTO> findEventDTOsByGroups(@Param("groupIds") List<String> groupIds);
|
List<EventDTO> findEventDTOsByUser(@Param("groupIds") List<String> userIds);
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT * FROM event"
|
@Query("SELECT * FROM event"
|
||||||
+ "WHERE event_type = :type")
|
+ " WHERE event_type IN (:types)")
|
||||||
List<EventDTO> findEventDTOsByType(@Param("type") String type);
|
List<EventDTO> findEventDTOsByType(@Param("types") List<String> types);
|
||||||
|
|
||||||
@Query("SELECT * FROM event"
|
@Query("SELECT * FROM event"
|
||||||
+ "WHERE event_type IN (:types)")
|
+ " WHERE event_type IN (:types) AND group_id IN (:groupIds)")
|
||||||
List<EventDTO> findEventDTOsByTypes(@Param("types") List<String> types);
|
List<EventDTO> findEventDTOsByGroupAndType(@Param("types") List<String> types,
|
||||||
|
@Param("groupIds") List<String> groupIds);
|
||||||
|
|
||||||
@Query("SELECT * FROM event"
|
@Query("SELECT * FROM event"
|
||||||
+ "WHERE event_type = :type AND user_id = :userId")
|
+ " WHERE event_type IN (:types) AND user_id = :userId")
|
||||||
List<EventDTO> findEventDTOsByUserAndType(@Param("type") String type,
|
List<EventDTO> findEventDTOsByUserAndType(@Param("types") List<String> types,
|
||||||
@Param("userId") String userId);
|
@Param("userId") String userId);
|
||||||
|
|
||||||
@Query("SELECT * FROM event"
|
// ################################ LATEST EVENT DTOs ########################################
|
||||||
+ "WHERE event_type IN (:types) AND user_id = :userId")
|
|
||||||
List<EventDTO> findEventDTOsByUserAndTypes(@Param("types") List<String> types,
|
|
||||||
@Param("userId") String userId);
|
|
||||||
|
|
||||||
@Query("WITH ranked_events AS ("
|
@Query("WITH ranked_events AS ("
|
||||||
+ "SELECT *, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY id DESC) AS rn"
|
+ "SELECT *, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY event_id DESC) AS rn"
|
||||||
+ "FROM messages"
|
+ " FROM event"
|
||||||
+ "WHERE user_id = :userId AND event_type IN (AddUserEvent, DeleteUserEvent)"
|
+ " WHERE user_id = :userId AND event_type IN ('AddUserEvent', 'DeleteUserEvent')"
|
||||||
+ ")"
|
+ ")"
|
||||||
+ "SELECT * FROM ranked_events WHERE rn = 1;")
|
+ "SELECT * FROM ranked_events WHERE rn = 1;")
|
||||||
List<EventDTO> findLatestEventDTOsPartitionedByGroupByUser(@Param("userId") String userId);
|
List<EventDTO> findLatestEventDTOsPartitionedByGroupByUser(@Param("userId") String userId);
|
||||||
|
|
||||||
|
@Query("WITH ranked_events AS ("
|
||||||
|
+ "SELECT *, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY event_id DESC) AS rn"
|
||||||
|
+ " FROM event"
|
||||||
|
+ " WHERE event_type IN (:types)"
|
||||||
|
+ ")"
|
||||||
|
+ "SELECT * FROM ranked_events WHERE rn = 1;")
|
||||||
|
List<EventDTO> findLatestEventDTOsPartitionedByGroupByType(@Param("types") List<String> types);
|
||||||
|
|
||||||
// ######################################### COUNT ###########################################
|
// ######################################### COUNT ###########################################
|
||||||
|
|
||||||
@Query("SELECT MAX(event_id) FROM event")
|
@Query("SELECT MAX(event_id) FROM event")
|
||||||
Long findMaxEventId();
|
Long findMaxEventId();
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM event"
|
@Query("SELECT COUNT(*) FROM event"
|
||||||
+ "WHERE event_type = :type AND group_id = :groupId")
|
+ " WHERE event_type = :type AND group_id = :groupId")
|
||||||
Long countEventDTOsByGroupAndType(@Param("type") String type,
|
Long countEventDTOsByGroupAndType(@Param("type") String type,
|
||||||
@Param("groupId") String groupId);
|
@Param("groupId") String groupId);
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM event"
|
@Query("SELECT COUNT(*) FROM event"
|
||||||
+ "WHERE group_id = :groupId AND user_id = :userId AND event_type = :type")
|
+ " WHERE group_id = :groupId AND user_id = :userId AND event_type = :type")
|
||||||
Long countEventDTOsByGroupIdAndUserAndType(@Param("groupId") String groupId,
|
Long countEventDTOsByGroupIdAndUserAndType(@Param("groupId") String groupId,
|
||||||
@Param("userId") String userId,
|
@Param("userId") String userId,
|
||||||
@Param("type") String type);
|
@Param("type") String type);
|
||||||
|
@ -2,6 +2,8 @@ package mops.gruppen2.service;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import mops.gruppen2.domain.dto.EventDTO;
|
import mops.gruppen2.domain.dto.EventDTO;
|
||||||
|
import mops.gruppen2.domain.event.AddUserEvent;
|
||||||
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.domain.exception.BadPayloadException;
|
import mops.gruppen2.domain.exception.BadPayloadException;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
@ -10,6 +12,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -25,6 +29,8 @@ public class EventStoreService {
|
|||||||
this.eventStore = eventStore;
|
this.eventStore = eventStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//########################################### SAVE ###########################################
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erzeugt ein DTO aus einem Event und speicher es.
|
* Erzeugt ein DTO aus einem Event und speicher es.
|
||||||
*
|
*
|
||||||
@ -54,6 +60,14 @@ public class EventStoreService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//########################################### DTOs ###########################################
|
||||||
|
|
||||||
|
public static List<EventDTO> getDTOsFromEvents(List<Event> events) {
|
||||||
|
return events.stream()
|
||||||
|
.map(EventStoreService::getDTOFromEvent)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erzeugt aus einem Event Objekt ein EventDTO Objekt.
|
* Erzeugt aus einem Event Objekt ein EventDTO Objekt.
|
||||||
*
|
*
|
||||||
@ -62,14 +76,17 @@ public class EventStoreService {
|
|||||||
* @return EventDTO (Neues DTO)
|
* @return EventDTO (Neues DTO)
|
||||||
*/
|
*/
|
||||||
public static EventDTO getDTOFromEvent(Event event) {
|
public static EventDTO getDTOFromEvent(Event event) {
|
||||||
String payload = "";
|
|
||||||
try {
|
try {
|
||||||
payload = JsonService.serializeEvent(event);
|
String payload = JsonService.serializeEvent(event);
|
||||||
|
return new EventDTO(null,
|
||||||
|
event.getGroupId().toString(),
|
||||||
|
event.getUserId(),
|
||||||
|
getEventType(event),
|
||||||
|
payload);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
LOG.error("Event ({}) konnte nicht serialisiert werden!", event.getClass());
|
LOG.error("Event ({}) konnte nicht serialisiert werden!", e.getMessage());
|
||||||
|
throw new BadPayloadException(EventStoreService.class.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EventDTO(null, event.getGroupId().toString(), event.getUserId(), getEventType(event), payload);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +106,7 @@ public class EventStoreService {
|
|||||||
try {
|
try {
|
||||||
return JsonService.deserializeEvent(dto.getEvent_payload());
|
return JsonService.deserializeEvent(dto.getEvent_payload());
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
LOG.error("Payload\n {}\n konnte nicht deserialisiert werden!", dto.getEvent_payload());
|
LOG.error("Payload\n {}\n konnte nicht deserialisiert werden!", e.getMessage());
|
||||||
throw new BadPayloadException(EventStoreService.class.toString());
|
throw new BadPayloadException(EventStoreService.class.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,6 +124,8 @@ public class EventStoreService {
|
|||||||
return event.getClass().getName().substring(lastDot + 1);
|
return event.getClass().getName().substring(lastDot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//######################################## GET EVENTS ########################################
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sucht in der DB alle Zeilen raus welche eine der Gruppen_ids hat.
|
* Sucht in der DB alle Zeilen raus welche eine der Gruppen_ids hat.
|
||||||
* Wandelt die Zeilen in Events um und gibt davon eine Liste zurück.
|
* Wandelt die Zeilen in Events um und gibt davon eine Liste zurück.
|
||||||
@ -115,27 +134,32 @@ public class EventStoreService {
|
|||||||
*
|
*
|
||||||
* @return Liste an Events
|
* @return Liste an Events
|
||||||
*/
|
*/
|
||||||
//TODO: EventStoreService
|
|
||||||
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(eventStore.findEventDTOByGroupId(groupId.toString()));
|
eventDTOS.addAll(eventStore.findEventDTOsByGroup(Collections.singletonList(groupId.toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return getEventsFromDTOs(eventDTOS);
|
return getEventsFromDTOs(eventDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Event> getGroupEvents(UUID groupId) {
|
||||||
|
return getEventsFromDTOs(eventStore.findEventDTOsByGroup(Collections.singletonList(groupId.toString())));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Findet alle Events welche ab dem neuen Status hinzugekommen sind.
|
* Findet alle Events, welche ab dem neuen Status hinzugekommen sind.
|
||||||
* Sucht alle Events mit event_id > status
|
* Sucht alle Events mit event_id > status.
|
||||||
*
|
*
|
||||||
* @param status Die Id des zuletzt gespeicherten Events
|
* @param status Die Id des zuletzt gespeicherten Events
|
||||||
*
|
*
|
||||||
* @return Liste von neueren Events
|
* @return Liste von neueren Events
|
||||||
*/
|
*/
|
||||||
public List<Event> getNewEvents(Long status) {
|
public List<Event> getNewEvents(Long status) {
|
||||||
List<String> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
|
List<String> groupIdsThatChanged = eventStore.findGroupIdsWhereEventIdGreaterThanStatus(status);
|
||||||
|
|
||||||
List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
|
List<EventDTO> groupEventDTOS = eventStore.findEventDTOsByGroup(groupIdsThatChanged);
|
||||||
return getEventsFromDTOs(groupEventDTOS);
|
return getEventsFromDTOs(groupEventDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +167,7 @@ public class EventStoreService {
|
|||||||
long highestEvent = 0;
|
long highestEvent = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
highestEvent = eventStore.getHighesEventID();
|
highestEvent = eventStore.findMaxEventId();
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
LOG.debug("Eine maxId von 0 wurde zurückgegeben, da keine Events vorhanden sind.");
|
LOG.debug("Eine maxId von 0 wurde zurückgegeben, da keine Events vorhanden sind.");
|
||||||
}
|
}
|
||||||
@ -159,7 +183,7 @@ public class EventStoreService {
|
|||||||
* @return Liste aus Events
|
* @return Liste aus Events
|
||||||
*/
|
*/
|
||||||
public List<Event> getEventsOfGroup(UUID groupId) {
|
public List<Event> getEventsOfGroup(UUID groupId) {
|
||||||
List<EventDTO> eventDTOList = eventStore.findEventDTOByGroupId(groupId.toString());
|
List<EventDTO> eventDTOList = eventStore.findEventDTOsByGroup(Collections.singletonList(groupId.toString()));
|
||||||
return getEventsFromDTOs(eventDTOList);
|
return getEventsFromDTOs(eventDTOList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +195,7 @@ public class EventStoreService {
|
|||||||
* @return Liste aus GruppenIds
|
* @return Liste aus GruppenIds
|
||||||
*/
|
*/
|
||||||
public List<UUID> findGroupIdsByUser(String userId) {
|
public List<UUID> findGroupIdsByUser(String userId) {
|
||||||
return eventStore.findGroupIdsWhereUserId(userId, "AddUserEvent").stream().map(UUID::fromString).collect(Collectors.toList());
|
return eventStore.findGroupIdsByUserAndType(userId, "AddUserEvent").stream().map(UUID::fromString).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,7 +206,67 @@ public class EventStoreService {
|
|||||||
*
|
*
|
||||||
* @return true or false
|
* @return true or false
|
||||||
*/
|
*/
|
||||||
|
//TODO: irgendwie fischig
|
||||||
boolean userInGroup(UUID groupId, String userId) {
|
boolean userInGroup(UUID groupId, String userId) {
|
||||||
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent") > eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
return eventStore.countEventDTOsByGroupIdAndUserAndType(groupId.toString(), userId, "AddUserEvent")
|
||||||
|
> eventStore.countEventDTOsByGroupIdAndUserAndType(groupId.toString(), userId, "DeleteUserEvent");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> uuidsToString(List<UUID> ids) {
|
||||||
|
return ids.stream()
|
||||||
|
.map(UUID::toString)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert Gruppen-Ids von existierenden (ungelöschten) Gruppen.
|
||||||
|
*
|
||||||
|
* @return GruppenIds (UUID) als Liste
|
||||||
|
*/
|
||||||
|
List<UUID> findExistingGroupIds() {
|
||||||
|
List<Event> createEvents = findLatestEventsFromGroupByType("CreateGroupEvent",
|
||||||
|
"DeleteGroupEvent");
|
||||||
|
|
||||||
|
return createEvents.stream()
|
||||||
|
.filter(event -> event instanceof CreateGroupEvent)
|
||||||
|
.map(Event::getGroupId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert Gruppen-Ids von existierenden (ungelöschten) Gruppen.
|
||||||
|
*
|
||||||
|
* @return GruppenIds (UUID) als Liste
|
||||||
|
*/
|
||||||
|
List<UUID> findExistingUserGroups(String userId) {
|
||||||
|
List<Event> userEvents = findLatestEventsFromGroupByUser(userId);
|
||||||
|
|
||||||
|
return userEvents.stream()
|
||||||
|
.filter(event -> event instanceof AddUserEvent)
|
||||||
|
.map(Event::getGroupId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ######################################## QUERIES ##########################################
|
||||||
|
|
||||||
|
List<Event> findEventsByTypes(String... types) {
|
||||||
|
return getEventsFromDTOs(eventStore.findEventDTOsByType(Arrays.asList(types)));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Event> findEventsByType(String type) {
|
||||||
|
return getEventsFromDTOs(eventStore.findEventDTOsByType(Collections.singletonList(type)));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Event> findEventsByGroupsAndTypes(List<UUID> groupIds, String... types) {
|
||||||
|
return getEventsFromDTOs(eventStore.findEventDTOsByGroupAndType(Arrays.asList(types),
|
||||||
|
uuidsToString(groupIds)));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Event> findLatestEventsFromGroupByUser(String userId) {
|
||||||
|
return getEventsFromDTOs(eventStore.findLatestEventDTOsPartitionedByGroupByUser(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Event> findLatestEventsFromGroupByType(String... types) {
|
||||||
|
return getEventsFromDTOs(eventStore.findLatestEventDTOsPartitionedByGroupByType(Arrays.asList(types)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ public class GroupService {
|
|||||||
//TODO: GroupService/eventbuilderservice
|
//TODO: GroupService/eventbuilderservice
|
||||||
void addUserList(List<User> newUsers, UUID groupId) {
|
void addUserList(List<User> newUsers, UUID groupId) {
|
||||||
for (User user : newUsers) {
|
for (User user : newUsers) {
|
||||||
Group group = projectionService.getGroupById(groupId);
|
Group group = projectionService.projectSingleGroupById(groupId);
|
||||||
if (group.getMembers().contains(user)) {
|
if (group.getMembers().contains(user)) {
|
||||||
LOG.info("Benutzer {} ist bereits in Gruppe", user.getId());
|
LOG.info("Benutzer {} ist bereits in Gruppe", user.getId());
|
||||||
} else {
|
} else {
|
||||||
@ -146,7 +146,7 @@ public class GroupService {
|
|||||||
//TODO: GroupService/eventbuilderservice
|
//TODO: GroupService/eventbuilderservice
|
||||||
public void updateRole(User user, UUID groupId) throws EventException {
|
public void updateRole(User user, UUID groupId) throws EventException {
|
||||||
UpdateRoleEvent updateRoleEvent;
|
UpdateRoleEvent updateRoleEvent;
|
||||||
Group group = projectionService.getGroupById(groupId);
|
Group group = projectionService.projectSingleGroupById(groupId);
|
||||||
validationService.throwIfNotInGroup(group, user);
|
validationService.throwIfNotInGroup(group, user);
|
||||||
|
|
||||||
if (group.getRoles().get(user.getId()) == ADMIN) {
|
if (group.getRoles().get(user.getId()) == ADMIN) {
|
||||||
@ -165,7 +165,7 @@ public class GroupService {
|
|||||||
|
|
||||||
//TODO: GroupService
|
//TODO: GroupService
|
||||||
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) {
|
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) {
|
||||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
List<User> newUserList = CsvService.readCsvFile(file);
|
List<User> newUserList = CsvService.readCsvFile(file);
|
||||||
removeOldUsersFromNewUsers(group.getMembers(), newUserList);
|
removeOldUsersFromNewUsers(group.getMembers(), newUserList);
|
||||||
@ -206,7 +206,7 @@ public class GroupService {
|
|||||||
public Group getParent(UUID parentId) {
|
public Group getParent(UUID parentId) {
|
||||||
Group parent = new Group();
|
Group parent = new Group();
|
||||||
if (!idIsEmpty(parentId)) {
|
if (!idIsEmpty(parentId)) {
|
||||||
parent = projectionService.getGroupById(parentId);
|
parent = projectionService.projectSingleGroupById(parentId);
|
||||||
}
|
}
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import mops.gruppen2.domain.Visibility;
|
|||||||
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 mops.gruppen2.repository.EventRepository;
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -19,19 +18,35 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Liefert verschiedene Projektionen auf Gruppen
|
* Liefert verschiedene Projektionen auf Gruppen.
|
||||||
|
* Benötigt ausschließlich den EventStoreService.
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ProjectionService {
|
public class ProjectionService {
|
||||||
|
|
||||||
private final EventRepository eventRepository;
|
|
||||||
private final EventStoreService eventStoreService;
|
private final EventStoreService eventStoreService;
|
||||||
|
|
||||||
public ProjectionService(EventRepository eventRepository, EventStoreService eventStoreService) {
|
public ProjectionService(EventStoreService eventStoreService) {
|
||||||
this.eventRepository = eventRepository;
|
|
||||||
this.eventStoreService = eventStoreService;
|
this.eventStoreService = eventStoreService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruiert Gruppen aus einer Liste von Events.
|
||||||
|
*
|
||||||
|
* @param events Liste an Events
|
||||||
|
*
|
||||||
|
* @return Liste an Projizierten Gruppen
|
||||||
|
*
|
||||||
|
* @throws EventException Projektionsfehler
|
||||||
|
*/
|
||||||
|
public static List<Group> projectEventList(List<Event> events) throws EventException {
|
||||||
|
Map<UUID, Group> groupMap = new HashMap<>();
|
||||||
|
|
||||||
|
events.forEach(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
|
||||||
|
|
||||||
|
return new ArrayList<>(groupMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt die Gruppe mit der richtigen Id aus der übergebenen Map wieder, existiert diese nicht
|
* Gibt die Gruppe mit der richtigen Id aus der übergebenen Map wieder, existiert diese nicht
|
||||||
* wird die Gruppe erstellt und der Map hizugefügt.
|
* wird die Gruppe erstellt und der Map hizugefügt.
|
||||||
@ -41,7 +56,6 @@ public class ProjectionService {
|
|||||||
*
|
*
|
||||||
* @return Die gesuchte Gruppe
|
* @return Die gesuchte Gruppe
|
||||||
*/
|
*/
|
||||||
//TODO: ProjectionService
|
|
||||||
private static Group getOrCreateGroup(Map<UUID, Group> groups, UUID groupId) {
|
private static 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());
|
||||||
@ -51,105 +65,77 @@ public class ProjectionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wird verwendet bei der Suche nach Gruppen: Titel, Beschreibung werden benötigt.
|
* Projiziert öffentliche Gruppen.
|
||||||
* Außerdem wird beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
|
* Die Gruppen enthalten Metainformationen: Titel, Beschreibung und MaxUserAnzahl.
|
||||||
|
* Außerdem wird noch beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
|
||||||
*
|
*
|
||||||
* @return Liste von projizierten Gruppen
|
* @return Liste von projizierten Gruppen
|
||||||
*
|
*
|
||||||
* @throws EventException Projektionsfehler
|
* @throws EventException Projektionsfehler
|
||||||
*/
|
*/
|
||||||
//TODO: ProjectionService
|
|
||||||
//TODO Rename
|
|
||||||
@Cacheable("groups")
|
@Cacheable("groups")
|
||||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
//TODO: remove userID param
|
||||||
List<Event> groupEvents = EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
public List<Group> projectPublicGroups(String userId) throws EventException {
|
||||||
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
List<UUID> groupIds = eventStoreService.findExistingGroupIds();
|
||||||
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
List<Event> events = eventStoreService.findEventsByGroupsAndTypes(groupIds,
|
||||||
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
"CreateGroupEvent",
|
||||||
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
"UpdateGroupDescriptionEvent",
|
||||||
|
"UpdateGroupTitleEvent",
|
||||||
|
"UpdateUserMaxEvent");
|
||||||
|
|
||||||
List<Group> visibleGroups = projectEventList(groupEvents);
|
List<Group> groups = projectEventList(events);
|
||||||
|
|
||||||
SearchService.sortByGroupType(visibleGroups);
|
SearchService.sortByGroupType(groups); //TODO: auslagern?
|
||||||
|
|
||||||
return visibleGroups.stream()
|
return groups.stream()
|
||||||
.filter(group -> group.getType() != null)
|
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||||
.filter(group -> !eventStoreService.userInGroup(group.getId(), userId))
|
.filter(group -> !eventStoreService.userInGroup(group.getId(), userId)) //TODO: slow
|
||||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
.collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wird verwendet beim Gruppe erstellen bei der Parent-Auswahl: nur Titel benötigt.
|
* Projiziert Vorlesungen.
|
||||||
|
* Projektionen enthalten nur Metainformationen: Titel.
|
||||||
*
|
*
|
||||||
* @return List of groups
|
* @return Liste von Veranstaltungen
|
||||||
*/
|
*/
|
||||||
@Cacheable("groups")
|
@Cacheable("groups")
|
||||||
//TODO: ProjectionService
|
public List<Group> projectLectures() {
|
||||||
public List<Group> getAllLecturesWithVisibilityPublic() {
|
List<UUID> groupIds = eventStoreService.findExistingGroupIds();
|
||||||
List<Event> createEvents = EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
List<Event> events = eventStoreService.findEventsByGroupsAndTypes(groupIds,
|
||||||
createEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
"CreateGroupEvent",
|
||||||
createEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
"UpdateGroupTitleEvent");
|
||||||
createEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
|
||||||
|
|
||||||
List<Group> visibleGroups = projectEventList(createEvents);
|
List<Group> lectures = projectEventList(events);
|
||||||
|
|
||||||
return visibleGroups.stream()
|
return lectures.stream()
|
||||||
.filter(group -> group.getType() == GroupType.LECTURE)
|
.filter(group -> group.getType() == GroupType.LECTURE)
|
||||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
.collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Erzeugt eine neue Map wo Gruppen aus den Events erzeugt und den Gruppen_ids zugeordnet werden.
|
|
||||||
* Die Gruppen werden als Liste zurückgegeben.
|
|
||||||
*
|
|
||||||
* @param events Liste an Events
|
|
||||||
*
|
|
||||||
* @return Liste an Projizierten Gruppen
|
|
||||||
*
|
|
||||||
* @throws EventException Projektionsfehler
|
|
||||||
*/
|
|
||||||
//TODO: ProjectionService
|
|
||||||
public List<Group> projectEventList(List<Event> events) throws EventException {
|
|
||||||
Map<UUID, Group> groupMap = new HashMap<>();
|
|
||||||
|
|
||||||
events.parallelStream()
|
|
||||||
.forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
|
|
||||||
|
|
||||||
return new ArrayList<>(groupMap.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: ProjectionService
|
|
||||||
@Cacheable("groups")
|
@Cacheable("groups")
|
||||||
public List<Group> getUserGroups(String userId) throws EventException {
|
public List<Group> projectGroupsByUser(String userId) throws EventException {
|
||||||
return getUserGroups(new User(userId, "", "", ""));
|
return projectGroupsByUser(new User(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt eine Liste aus Gruppen zurück, in denen sich der übergebene User befindet.
|
* Projiziert Gruppen, in welchen der User aktuell teilnimmt.
|
||||||
|
* Die Gruppen enthalten nur Metainformationen: Titel und Beschreibung.
|
||||||
*
|
*
|
||||||
* @param user Der User
|
* @param user Der User
|
||||||
*
|
*
|
||||||
* @return Liste aus Gruppen
|
* @return Liste aus Gruppen
|
||||||
*/
|
*/
|
||||||
//TODO: ProjectionService
|
|
||||||
//TODO: Nur AddUserEvents + DeleteUserEvents betrachten
|
|
||||||
@Cacheable("groups")
|
@Cacheable("groups")
|
||||||
public List<Group> getUserGroups(User user) {
|
public List<Group> projectGroupsByUser(User user) {
|
||||||
List<UUID> groupIds = eventStoreService.findGroupIdsByUser(user.getId());
|
List<UUID> groupIds = eventStoreService.findExistingUserGroups(user.getId());
|
||||||
List<Event> events = eventStoreService.getGroupEvents(groupIds);
|
List<Event> groupEvents = eventStoreService.findEventsByGroupsAndTypes(groupIds,
|
||||||
List<Group> groups = projectEventList(events);
|
"CreateGroupEvent",
|
||||||
List<Group> newGroups = new ArrayList<>();
|
"UpdateGroupTitleEvent",
|
||||||
|
"UpdateGroupDescriptionEvent",
|
||||||
|
"DeleteGroupEvent");
|
||||||
|
|
||||||
for (Group group : groups) {
|
return projectEventList(groupEvents);
|
||||||
if (group.getMembers().contains(user)) {
|
|
||||||
newGroups.add(group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SearchService.sortByGroupType(newGroups);
|
|
||||||
|
|
||||||
return newGroups;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,16 +147,12 @@ public class ProjectionService {
|
|||||||
*
|
*
|
||||||
* @throws EventException Wenn die Gruppe nicht gefunden wird
|
* @throws EventException Wenn die Gruppe nicht gefunden wird
|
||||||
*/
|
*/
|
||||||
//TODO: ProjectionService
|
public Group projectSingleGroupById(UUID groupId) throws GroupNotFoundException {
|
||||||
public Group getGroupById(UUID groupId) throws EventException {
|
|
||||||
List<UUID> groupIds = new ArrayList<>();
|
|
||||||
groupIds.add(groupId);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Event> events = eventStoreService.getGroupEvents(groupIds);
|
List<Event> events = eventStoreService.getGroupEvents(groupId);
|
||||||
return projectEventList(events).get(0);
|
return projectEventList(events).get(0);
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
throw new GroupNotFoundException("@UserService");
|
throw new GroupNotFoundException(ProjectionService.class.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,9 @@ public class SearchService {
|
|||||||
@Cacheable("groups")
|
@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 projectionService.getAllGroupWithVisibilityPublic(account.getName());
|
return projectionService.projectPublicGroups(account.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectionService.getAllGroupWithVisibilityPublic(account.getName()).parallelStream().filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())).collect(Collectors.toList());
|
return projectionService.projectPublicGroups(account.getName()).parallelStream().filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class ValidationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean checkIfGroupEmpty(UUID groupId) {
|
boolean checkIfGroupEmpty(UUID groupId) {
|
||||||
return projectionService.getGroupById(groupId).getMembers().isEmpty();
|
return projectionService.projectSingleGroupById(groupId).getMembers().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void throwIfNoAdmin(Group group, User user) {
|
public void throwIfNoAdmin(Group group, User user) {
|
||||||
|
@ -4,6 +4,7 @@ import mops.gruppen2.Gruppen2Application;
|
|||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import mops.gruppen2.service.EventStoreService;
|
import mops.gruppen2.service.EventStoreService;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -115,6 +116,7 @@ class APIControllerTest {
|
|||||||
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
|
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username = "api_user", roles = "api_user")
|
@WithMockUser(username = "api_user", roles = "api_user")
|
||||||
void getGroupsOfUser_singleDeletedGroup() {
|
void getGroupsOfUser_singleDeletedGroup() {
|
||||||
|
@ -10,6 +10,7 @@ import mops.gruppen2.domain.Visibility;
|
|||||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -68,7 +69,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPublicGroupWithNoParentAndLimitedNumberTest() {
|
void createPublicGroupWithNoParentAndLimitedNumberTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, null);
|
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
@ -79,7 +80,7 @@ class ControllerServiceTest {
|
|||||||
void createPublicGroupWithNoParentAndUnlimitedNumberTest() {
|
void createPublicGroupWithNoParentAndUnlimitedNumberTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
List<Group> groups = projectionService.getUserGroups(user);
|
List<Group> groups = projectionService.projectGroupsByUser(user);
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
@ -90,7 +91,7 @@ class ControllerServiceTest {
|
|||||||
void createPrivateGroupWithNoParentAndUnlimitedNumberTest() {
|
void createPrivateGroupWithNoParentAndUnlimitedNumberTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
List<Group> groups = projectionService.getUserGroups(user);
|
List<Group> groups = projectionService.projectGroupsByUser(user);
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
@ -101,7 +102,7 @@ class ControllerServiceTest {
|
|||||||
void createPrivateGroupWithNoParentAndLimitedNumberTest() {
|
void createPrivateGroupWithNoParentAndLimitedNumberTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, null);
|
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, null);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
List<Group> groups = projectionService.getUserGroups(user);
|
List<Group> groups = projectionService.projectGroupsByUser(user);
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
@ -112,10 +113,10 @@ class ControllerServiceTest {
|
|||||||
void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException {
|
void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, true, true, null, null, null);
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, true, true, null, null, null);
|
||||||
User user = new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail());
|
User user = new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail());
|
||||||
List<Group> groups1 = projectionService.getUserGroups(user);
|
List<Group> groups1 = projectionService.projectGroupsByUser(user);
|
||||||
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, groups1.get(0).getId());
|
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, groups1.get(0).getId());
|
||||||
User user2 = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user2 = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
List<Group> groups = projectionService.getUserGroups(user2);
|
List<Group> groups = projectionService.projectGroupsByUser(user2);
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
@ -125,9 +126,9 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPublicGroupWithParentAndLimitedNumberTest() throws IOException {
|
void createPublicGroupWithParentAndLimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||||
List<Group> groups1 = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
List<Group> groups1 = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, groups1.get(0).getId());
|
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, groups1.get(0).getId());
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||||
@ -137,9 +138,9 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||||
List<Group> groups1 = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
List<Group> groups1 = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
controllerService.createGroup(account, "test", "hi", null, true, true, null, groups1.get(0).getId());
|
controllerService.createGroup(account, "test", "hi", null, true, true, null, groups1.get(0).getId());
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
@ -149,9 +150,9 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||||
List<Group> groups1 = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
List<Group> groups1 = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
controllerService.createGroup(account, "test", "hi", true, true, true, null, groups1.get(0).getId());
|
controllerService.createGroup(account, "test", "hi", true, true, true, null, groups1.get(0).getId());
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||||
@ -161,7 +162,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account, "test", "hi", null, null, null, 20L, null, null);
|
controllerService.createGroupAsOrga(account, "test", "hi", null, null, null, 20L, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
@ -172,7 +173,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account, "test", "hi", null, null, true, null, null, null);
|
controllerService.createGroupAsOrga(account, "test", "hi", null, null, true, null, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
@ -183,7 +184,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account, "test", "hi", true, null, null, 20L, null, null);
|
controllerService.createGroupAsOrga(account, "test", "hi", true, null, null, 20L, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
@ -194,7 +195,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account, "test", "hi", true, null, true, null, null, null);
|
controllerService.createGroupAsOrga(account, "test", "hi", true, null, true, null, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||||
@ -205,7 +206,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createOrgaLectureGroupAndLimitedNumberTest() throws IOException {
|
void createOrgaLectureGroupAndLimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account, "test", "hi", null, true, null, 20L, null, null);
|
controllerService.createGroupAsOrga(account, "test", "hi", null, true, null, 20L, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
@ -216,7 +217,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
|
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
|
||||||
controllerService.createGroupAsOrga(account, "test", "hi", null, true, true, null, null, null);
|
controllerService.createGroupAsOrga(account, "test", "hi", null, true, true, null, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
@ -225,37 +226,40 @@ class ControllerServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GroupServiceTest
|
//TODO: GroupServiceTest
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void deleteUserTest() {
|
public void deleteUserTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", true, true, true, null, null);
|
controllerService.createGroup(account, "test", "hi", true, true, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
groupService.addUser(account2, groups.get(0).getId());
|
groupService.addUser(account2, groups.get(0).getId());
|
||||||
User user = new User(account.getName(), "", "", "");
|
User user = new User(account.getName(), "", "", "");
|
||||||
groupService.deleteUser(account, user, groups.get(0));
|
groupService.deleteUser(account, user, groups.get(0));
|
||||||
assertTrue(projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
assertTrue(projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GroupServiceTest
|
//TODO: GroupServiceTest
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void updateRoleAdminTest() {
|
public void updateRoleAdminTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
groupService.addUser(account2, groups.get(0).getId());
|
groupService.addUser(account2, groups.get(0).getId());
|
||||||
User user = new User(account.getName(), "", "", "");
|
User user = new User(account.getName(), "", "", "");
|
||||||
groupService.updateRole(user, groups.get(0).getId());
|
groupService.updateRole(user, groups.get(0).getId());
|
||||||
groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account.getName()));
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GroupServiceTest
|
//TODO: GroupServiceTest
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void updateRoleMemberTest() {
|
public void updateRoleMemberTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
groupService.addUser(account2, groups.get(0).getId());
|
groupService.addUser(account2, groups.get(0).getId());
|
||||||
User user = new User(account2.getName(), "", "", "");
|
User user = new User(account2.getName(), "", "", "");
|
||||||
groupService.updateRole(user, groups.get(0).getId());
|
groupService.updateRole(user, groups.get(0).getId());
|
||||||
groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +267,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateRoleNonUserTest() {
|
public void updateRoleNonUserTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
User user = new User(account2.getName(), "", "", "");
|
User user = new User(account2.getName(), "", "", "");
|
||||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.updateRole(user, groups.get(0).getId()));
|
Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.updateRole(user, groups.get(0).getId()));
|
||||||
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ValidationService)\"", exception.getMessage());
|
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ValidationService)\"", exception.getMessage());
|
||||||
@ -273,7 +277,7 @@ class ControllerServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void deleteNonUserTest() {
|
public void deleteNonUserTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
User user = new User(account2.getName(), "", "", "");
|
User user = new User(account2.getName(), "", "", "");
|
||||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.deleteUser(account, user, groups.get(0)));
|
Throwable exception = assertThrows(UserNotFoundException.class, () -> groupService.deleteUser(account, user, groups.get(0)));
|
||||||
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ValidationService)\"", exception.getMessage());
|
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ValidationService)\"", exception.getMessage());
|
||||||
@ -285,23 +289,25 @@ class ControllerServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GroupServiceTest
|
//TODO: GroupServiceTest
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
void passIfLastAdminTest() {
|
void passIfLastAdminTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
groupService.addUser(account2, groups.get(0).getId());
|
groupService.addUser(account2, groups.get(0).getId());
|
||||||
User user = new User(account.getName(), "", "", "");
|
User user = new User(account.getName(), "", "", "");
|
||||||
groups = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
groupService.deleteUser(account, user, groups.get(0));
|
groupService.deleteUser(account, user, groups.get(0));
|
||||||
groups = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GroupServiceTest
|
//TODO: GroupServiceTest
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
void dontPassIfNotLastAdminTest() {
|
void dontPassIfNotLastAdminTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
groupService.addUser(account2, groups.get(0).getId());
|
groupService.addUser(account2, groups.get(0).getId());
|
||||||
User user2 = new User(account2.getName(), "", "", "");
|
User user2 = new User(account2.getName(), "", "", "");
|
||||||
groupService.updateRole(user2, groups.get(0).getId());
|
groupService.updateRole(user2, groups.get(0).getId());
|
||||||
@ -309,21 +315,22 @@ class ControllerServiceTest {
|
|||||||
groupService.changeRoleIfLastAdmin(account, groups.get(0));
|
groupService.changeRoleIfLastAdmin(account, groups.get(0));
|
||||||
User user = new User(account.getName(), "", "", "");
|
User user = new User(account.getName(), "", "", "");
|
||||||
groupService.deleteUser(account, user, groups.get(0));
|
groupService.deleteUser(account, user, groups.get(0));
|
||||||
groups = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GroupServiceTest
|
//TODO: GroupServiceTest
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
void getVeteranMemberTest() {
|
void getVeteranMemberTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = projectionService.projectGroupsByUser(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
groupService.addUser(account2, groups.get(0).getId());
|
groupService.addUser(account2, groups.get(0).getId());
|
||||||
groupService.addUser(account3, groups.get(0).getId());
|
groupService.addUser(account3, groups.get(0).getId());
|
||||||
User user = new User(account.getName(), "", "", "");
|
User user = new User(account.getName(), "", "", "");
|
||||||
groups = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
groupService.deleteUser(account, user, groups.get(0));
|
groupService.deleteUser(account, user, groups.get(0));
|
||||||
groups = projectionService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = projectionService.projectGroupsByUser(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ class GroupServiceTest {
|
|||||||
void rightClassForSuccessfulGroup() {
|
void rightClassForSuccessfulGroup() {
|
||||||
List<Event> eventList = completePrivateGroup(1);
|
List<Event> eventList = completePrivateGroup(1);
|
||||||
|
|
||||||
List<Group> groups = projectionService.projectEventList(eventList);
|
List<Group> groups = ProjectionService.projectEventList(eventList);
|
||||||
assertThat(groups.get(0)).isInstanceOf(Group.class);
|
assertThat(groups.get(0)).isInstanceOf(Group.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ class GroupServiceTest {
|
|||||||
void projectEventList_SingleGroup() {
|
void projectEventList_SingleGroup() {
|
||||||
List<Event> eventList = completePrivateGroup(5);
|
List<Event> eventList = completePrivateGroup(5);
|
||||||
|
|
||||||
List<Group> groups = projectionService.projectEventList(eventList);
|
List<Group> groups = ProjectionService.projectEventList(eventList);
|
||||||
|
|
||||||
assertThat(groups).hasSize(1);
|
assertThat(groups).hasSize(1);
|
||||||
assertThat(groups.get(0).getMembers()).hasSize(5);
|
assertThat(groups.get(0).getMembers()).hasSize(5);
|
||||||
@ -92,7 +92,7 @@ class GroupServiceTest {
|
|||||||
List<Event> eventList = completePrivateGroups(10, 2);
|
List<Event> eventList = completePrivateGroups(10, 2);
|
||||||
eventList.addAll(completePublicGroups(10, 5));
|
eventList.addAll(completePublicGroups(10, 5));
|
||||||
|
|
||||||
List<Group> groups = projectionService.projectEventList(eventList);
|
List<Group> groups = ProjectionService.projectEventList(eventList);
|
||||||
|
|
||||||
assertThat(groups).hasSize(20);
|
assertThat(groups).hasSize(20);
|
||||||
assertThat(groups.stream().map(group -> group.getMembers().size()).reduce(Integer::sum).get()).isEqualTo(70);
|
assertThat(groups.stream().map(group -> group.getMembers().size()).reduce(Integer::sum).get()).isEqualTo(70);
|
||||||
@ -122,7 +122,7 @@ class GroupServiceTest {
|
|||||||
Group group = TestBuilder.apply(test1, test2);
|
Group group = TestBuilder.apply(test1, test2);
|
||||||
|
|
||||||
assertThat(group.getType()).isEqualTo(null);
|
assertThat(group.getType()).isEqualTo(null);
|
||||||
assertThat(projectionService.getAllGroupWithVisibilityPublic("errer")).isEmpty();
|
assertThat(projectionService.projectPublicGroups("errer")).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: ProjectionServiceTest
|
//TODO: ProjectionServiceTest
|
||||||
@ -132,7 +132,7 @@ class GroupServiceTest {
|
|||||||
deleteGroupEvent(uuidMock(0)),
|
deleteGroupEvent(uuidMock(0)),
|
||||||
createPublicGroupEvent());
|
createPublicGroupEvent());
|
||||||
|
|
||||||
assertThat(projectionService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
|
assertThat(projectionService.projectPublicGroups("test1").size()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: ProjectionServiceTest
|
//TODO: ProjectionServiceTest
|
||||||
@ -145,7 +145,7 @@ class GroupServiceTest {
|
|||||||
createPublicGroupEvent(),
|
createPublicGroupEvent(),
|
||||||
createPrivateGroupEvent());
|
createPrivateGroupEvent());
|
||||||
|
|
||||||
assertThat(projectionService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
|
assertThat(projectionService.projectPublicGroups("test1").size()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: ProjectionServiceTest
|
//TODO: ProjectionServiceTest
|
||||||
@ -156,8 +156,8 @@ class GroupServiceTest {
|
|||||||
createPrivateGroupEvent(),
|
createPrivateGroupEvent(),
|
||||||
createPublicGroupEvent());
|
createPublicGroupEvent());
|
||||||
|
|
||||||
assertThat(projectionService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
|
assertThat(projectionService.projectPublicGroups("kobold")).hasSize(1);
|
||||||
assertThat(projectionService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
|
assertThat(projectionService.projectPublicGroups("peter")).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: ProjectionServiceTest
|
//TODO: ProjectionServiceTest
|
||||||
@ -169,7 +169,7 @@ class GroupServiceTest {
|
|||||||
createLectureEvent(),
|
createLectureEvent(),
|
||||||
createLectureEvent());
|
createLectureEvent());
|
||||||
|
|
||||||
assertThat(projectionService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
|
assertThat(projectionService.projectLectures().size()).isEqualTo(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: SearchServiceTest
|
//TODO: SearchServiceTest
|
||||||
|
Reference in New Issue
Block a user