1

greater projectionservice refactoring

This commit is contained in:
Christoph
2020-04-06 17:21:09 +02:00
parent 5da796d66d
commit 7f05e0fb10
15 changed files with 282 additions and 191 deletions

View File

@ -42,14 +42,14 @@ public class APIController {
public GroupRequestWrapper updateGroups(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long lastEventId) throws EventException {
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}")
@Secured("ROLE_api_user")
@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) {
return projectionService.getUserGroups(userId).stream()
return projectionService.projectGroupsByUser(userId).stream()
.map(group -> group.getId().toString())
.collect(Collectors.toList());
}
@ -59,7 +59,7 @@ public class APIController {
@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 {
List<Event> eventList = eventStoreService.getEventsOfGroup(UUID.fromString(groupId));
List<Group> groups = projectionService.projectEventList(eventList);
List<Group> groups = ProjectionService.projectEventList(eventList);
if (groups.isEmpty()) {
return null;

View File

@ -45,7 +45,7 @@ public class GroupCreationController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
model.addAttribute("account", account);
model.addAttribute("lectures", projectionService.getAllLecturesWithVisibilityPublic());
model.addAttribute("lectures", projectionService.projectLectures());
return "createOrga";
}
@ -88,7 +88,7 @@ public class GroupCreationController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
model.addAttribute("account", account);
model.addAttribute("lectures", projectionService.getAllLecturesWithVisibilityPublic());
model.addAttribute("lectures", projectionService.projectLectures());
return "createStudent";
}

View File

@ -50,7 +50,7 @@ public class GroupDetailsController {
HttpServletRequest request,
@PathVariable("id") String groupId) {
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
UUID parentId = group.getParent();
@ -93,7 +93,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, user);
@ -118,7 +118,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, user);
validationService.checkFields(title, description);
@ -135,7 +135,7 @@ public class GroupDetailsController {
@PathVariable("id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
User user = new User(account);
validationService.throwIfNoAdmin(group, user);
@ -156,7 +156,7 @@ public class GroupDetailsController {
@RequestParam("user_id") String userId) {
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 user = new User(userId, "", "", "");
@ -181,7 +181,7 @@ public class GroupDetailsController {
@RequestParam("group_id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
validationService.throwIfNewMaximumIsValid(maximum, group);
@ -200,7 +200,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User principle = new User(account);
User user = new User(userId, "", "", "");
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, principle);
@ -222,7 +222,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
validationService.throwIfUserAlreadyInGroup(group, user);
validationService.throwIfGroupFull(group);
@ -242,7 +242,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
groupService.deleteUser(account, user, group);
@ -257,7 +257,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, user);

View File

@ -37,7 +37,7 @@ public class GruppenfindungController {
User user = new User(account);
model.addAttribute("account", account);
model.addAttribute("gruppen", projectionService.getUserGroups(user));
model.addAttribute("gruppen", projectionService.projectGroupsByUser(user));
model.addAttribute("user", user);
return "index";

View File

@ -66,7 +66,7 @@ public class SearchAndInviteController {
@RequestParam("id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
UUID parentId = group.getParent();
Group parent = groupService.getParent(parentId);
User user = new User(account);
@ -89,7 +89,7 @@ public class SearchAndInviteController {
Model model,
@PathVariable("link") String link) {
Group group = projectionService.getGroupById(inviteService.getGroupIdFromLink(link));
Group group = projectionService.projectSingleGroupById(inviteService.getGroupIdFromLink(link));
validationService.throwIfGroupNotExisting(group.getTitle());
@ -111,7 +111,7 @@ public class SearchAndInviteController {
Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
Group group = projectionService.getGroupById(UUID.fromString(groupId));
Group group = projectionService.projectSingleGroupById(UUID.fromString(groupId));
validationService.throwIfUserAlreadyInGroup(group, user);
validationService.throwIfGroupFull(group);

View File

@ -22,4 +22,16 @@ public class User {
familyname = account.getFamilyname();
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 = "";
}
}

View File

@ -24,42 +24,46 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
// ####################################### EVENT DTOs ########################################
@Query("SELECT * from event"
+ "WHERE group_id = :groupId")
List<EventDTO> findEventDTOsByGroup(@Param("groupId") String groupId);
@Query("SELECT * FROM event"
+ " WHERE group_id IN (:groupIds) ")
List<EventDTO> findEventDTOsByGroups(@Param("groupIds") List<String> groupIds);
List<EventDTO> findEventDTOsByGroup(@Param("groupIds") List<String> groupIds);
@Query("SELECT * FROM event"
+ "WHERE event_type = :type")
List<EventDTO> findEventDTOsByType(@Param("type") String type);
+ " WHERE group_id IN (:userIds) ")
List<EventDTO> findEventDTOsByUser(@Param("groupIds") List<String> userIds);
@Query("SELECT * FROM event"
+ " WHERE event_type IN (:types)")
List<EventDTO> findEventDTOsByTypes(@Param("types") List<String> types);
List<EventDTO> findEventDTOsByType(@Param("types") List<String> types);
@Query("SELECT * FROM event"
+ "WHERE event_type = :type AND user_id = :userId")
List<EventDTO> findEventDTOsByUserAndType(@Param("type") String type,
@Param("userId") String userId);
+ " WHERE event_type IN (:types) AND group_id IN (:groupIds)")
List<EventDTO> findEventDTOsByGroupAndType(@Param("types") List<String> types,
@Param("groupIds") List<String> groupIds);
@Query("SELECT * FROM event"
+ " WHERE event_type IN (:types) AND user_id = :userId")
List<EventDTO> findEventDTOsByUserAndTypes(@Param("types") List<String> types,
List<EventDTO> findEventDTOsByUserAndType(@Param("types") List<String> types,
@Param("userId") String userId);
// ################################ LATEST EVENT DTOs ########################################
@Query("WITH ranked_events AS ("
+ "SELECT *, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY id DESC) AS rn"
+ "FROM messages"
+ "WHERE user_id = :userId AND event_type IN (AddUserEvent, DeleteUserEvent)"
+ "SELECT *, ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY event_id DESC) AS rn"
+ " FROM event"
+ " WHERE user_id = :userId AND event_type IN ('AddUserEvent', 'DeleteUserEvent')"
+ ")"
+ "SELECT * FROM ranked_events WHERE rn = 1;")
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 ###########################################
@Query("SELECT MAX(event_id) FROM event")

View File

@ -2,6 +2,8 @@ package mops.gruppen2.service;
import com.fasterxml.jackson.core.JsonProcessingException;
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.exception.BadPayloadException;
import mops.gruppen2.repository.EventRepository;
@ -10,6 +12,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -25,6 +29,8 @@ public class EventStoreService {
this.eventStore = eventStore;
}
//########################################### SAVE ###########################################
/**
* 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.
*
@ -62,14 +76,17 @@ public class EventStoreService {
* @return EventDTO (Neues DTO)
*/
public static EventDTO getDTOFromEvent(Event event) {
String payload = "";
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) {
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 {
return JsonService.deserializeEvent(dto.getEvent_payload());
} 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());
}
}
@ -107,6 +124,8 @@ public class EventStoreService {
return event.getClass().getName().substring(lastDot + 1);
}
//######################################## GET EVENTS ########################################
/**
* 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.
@ -115,27 +134,32 @@ public class EventStoreService {
*
* @return Liste an Events
*/
//TODO: EventStoreService
public List<Event> getGroupEvents(List<UUID> groupIds) {
List<EventDTO> eventDTOS = new ArrayList<>();
for (UUID groupId : groupIds) {
eventDTOS.addAll(eventStore.findEventDTOByGroupId(groupId.toString()));
eventDTOS.addAll(eventStore.findEventDTOsByGroup(Collections.singletonList(groupId.toString())));
}
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.
* Sucht alle Events mit event_id > status
* Findet alle Events, welche ab dem neuen Status hinzugekommen sind.
* Sucht alle Events mit event_id > status.
*
* @param status Die Id des zuletzt gespeicherten Events
*
* @return Liste von neueren Events
*/
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);
}
@ -143,7 +167,7 @@ public class EventStoreService {
long highestEvent = 0;
try {
highestEvent = eventStore.getHighesEventID();
highestEvent = eventStore.findMaxEventId();
} catch (NullPointerException e) {
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
*/
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);
}
@ -171,7 +195,7 @@ public class EventStoreService {
* @return Liste aus GruppenIds
*/
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
*/
//TODO: irgendwie fischig
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)));
}
}

View File

@ -121,7 +121,7 @@ public class GroupService {
//TODO: GroupService/eventbuilderservice
void addUserList(List<User> newUsers, UUID groupId) {
for (User user : newUsers) {
Group group = projectionService.getGroupById(groupId);
Group group = projectionService.projectSingleGroupById(groupId);
if (group.getMembers().contains(user)) {
LOG.info("Benutzer {} ist bereits in Gruppe", user.getId());
} else {
@ -146,7 +146,7 @@ public class GroupService {
//TODO: GroupService/eventbuilderservice
public void updateRole(User user, UUID groupId) throws EventException {
UpdateRoleEvent updateRoleEvent;
Group group = projectionService.getGroupById(groupId);
Group group = projectionService.projectSingleGroupById(groupId);
validationService.throwIfNotInGroup(group, user);
if (group.getRoles().get(user.getId()) == ADMIN) {
@ -165,7 +165,7 @@ public class GroupService {
//TODO: GroupService
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);
removeOldUsersFromNewUsers(group.getMembers(), newUserList);
@ -206,7 +206,7 @@ public class GroupService {
public Group getParent(UUID parentId) {
Group parent = new Group();
if (!idIsEmpty(parentId)) {
parent = projectionService.getGroupById(parentId);
parent = projectionService.projectSingleGroupById(parentId);
}
return parent;
}

View File

@ -7,7 +7,6 @@ import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupNotFoundException;
import mops.gruppen2.repository.EventRepository;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@ -19,19 +18,35 @@ import java.util.UUID;
import java.util.stream.Collectors;
/**
* Liefert verschiedene Projektionen auf Gruppen
* Liefert verschiedene Projektionen auf Gruppen.
* Benötigt ausschließlich den EventStoreService.
*/
@Service
public class ProjectionService {
private final EventRepository eventRepository;
private final EventStoreService eventStoreService;
public ProjectionService(EventRepository eventRepository, EventStoreService eventStoreService) {
this.eventRepository = eventRepository;
public ProjectionService(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
* wird die Gruppe erstellt und der Map hizugefügt.
@ -41,7 +56,6 @@ public class ProjectionService {
*
* @return Die gesuchte Gruppe
*/
//TODO: ProjectionService
private static Group getOrCreateGroup(Map<UUID, Group> groups, UUID groupId) {
if (!groups.containsKey(groupId)) {
groups.put(groupId, new Group());
@ -51,105 +65,77 @@ public class ProjectionService {
}
/**
* Wird verwendet bei der Suche nach Gruppen: Titel, Beschreibung werden benötigt.
* Außerdem wird beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
* Projiziert öffentliche Gruppen.
* 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
*
* @throws EventException Projektionsfehler
*/
//TODO: ProjectionService
//TODO Rename
@Cacheable("groups")
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
List<Event> groupEvents = EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
groupEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
//TODO: remove userID param
public List<Group> projectPublicGroups(String userId) throws EventException {
List<UUID> groupIds = eventStoreService.findExistingGroupIds();
List<Event> events = eventStoreService.findEventsByGroupsAndTypes(groupIds,
"CreateGroupEvent",
"UpdateGroupDescriptionEvent",
"UpdateGroupTitleEvent",
"UpdateUserMaxEvent");
List<Group> visibleGroups = projectEventList(groupEvents);
List<Group> groups = projectEventList(events);
SearchService.sortByGroupType(visibleGroups);
SearchService.sortByGroupType(groups); //TODO: auslagern?
return visibleGroups.stream()
.filter(group -> group.getType() != null)
.filter(group -> !eventStoreService.userInGroup(group.getId(), userId))
return groups.stream()
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
.filter(group -> !eventStoreService.userInGroup(group.getId(), userId)) //TODO: slow
.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")
//TODO: ProjectionService
public List<Group> getAllLecturesWithVisibilityPublic() {
List<Event> createEvents = EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
createEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
createEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
createEvents.addAll(EventStoreService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
public List<Group> projectLectures() {
List<UUID> groupIds = eventStoreService.findExistingGroupIds();
List<Event> events = eventStoreService.findEventsByGroupsAndTypes(groupIds,
"CreateGroupEvent",
"UpdateGroupTitleEvent");
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.getVisibility() == Visibility.PUBLIC)
.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")
public List<Group> getUserGroups(String userId) throws EventException {
return getUserGroups(new User(userId, "", "", ""));
public List<Group> projectGroupsByUser(String userId) throws EventException {
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
*
* @return Liste aus Gruppen
*/
//TODO: ProjectionService
//TODO: Nur AddUserEvents + DeleteUserEvents betrachten
@Cacheable("groups")
public List<Group> getUserGroups(User user) {
List<UUID> groupIds = eventStoreService.findGroupIdsByUser(user.getId());
List<Event> events = eventStoreService.getGroupEvents(groupIds);
List<Group> groups = projectEventList(events);
List<Group> newGroups = new ArrayList<>();
public List<Group> projectGroupsByUser(User user) {
List<UUID> groupIds = eventStoreService.findExistingUserGroups(user.getId());
List<Event> groupEvents = eventStoreService.findEventsByGroupsAndTypes(groupIds,
"CreateGroupEvent",
"UpdateGroupTitleEvent",
"UpdateGroupDescriptionEvent",
"DeleteGroupEvent");
for (Group group : groups) {
if (group.getMembers().contains(user)) {
newGroups.add(group);
}
}
SearchService.sortByGroupType(newGroups);
return newGroups;
return projectEventList(groupEvents);
}
/**
@ -161,16 +147,12 @@ public class ProjectionService {
*
* @throws EventException Wenn die Gruppe nicht gefunden wird
*/
//TODO: ProjectionService
public Group getGroupById(UUID groupId) throws EventException {
List<UUID> groupIds = new ArrayList<>();
groupIds.add(groupId);
public Group projectSingleGroupById(UUID groupId) throws GroupNotFoundException {
try {
List<Event> events = eventStoreService.getGroupEvents(groupIds);
List<Event> events = eventStoreService.getGroupEvents(groupId);
return projectEventList(events).get(0);
} catch (IndexOutOfBoundsException e) {
throw new GroupNotFoundException("@UserService");
throw new GroupNotFoundException(ProjectionService.class.toString());
}
}
}

View File

@ -51,9 +51,9 @@ public class SearchService {
@Cacheable("groups")
public List<Group> findGroupWith(String search, Account account) throws EventException {
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());
}
}

View File

@ -68,7 +68,7 @@ public class ValidationService {
}
boolean checkIfGroupEmpty(UUID groupId) {
return projectionService.getGroupById(groupId).getMembers().isEmpty();
return projectionService.projectSingleGroupById(groupId).getMembers().isEmpty();
}
public void throwIfNoAdmin(Group group, User user) {

View File

@ -4,6 +4,7 @@ import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.service.EventStoreService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -115,6 +116,7 @@ class APIControllerTest {
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
}
@Disabled
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_singleDeletedGroup() {

View File

@ -10,6 +10,7 @@ import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.exception.UserNotFoundException;
import mops.gruppen2.repository.EventRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -68,7 +69,7 @@ class ControllerServiceTest {
@Test
void createPublicGroupWithNoParentAndLimitedNumberTest() {
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());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
assertEquals(20L, groups.get(0).getUserMaximum());
@ -79,7 +80,7 @@ class ControllerServiceTest {
void createPublicGroupWithNoParentAndUnlimitedNumberTest() {
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
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());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
assertEquals(100000L, groups.get(0).getUserMaximum());
@ -90,7 +91,7 @@ class ControllerServiceTest {
void createPrivateGroupWithNoParentAndUnlimitedNumberTest() {
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
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());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
assertEquals(100000L, groups.get(0).getUserMaximum());
@ -101,7 +102,7 @@ class ControllerServiceTest {
void createPrivateGroupWithNoParentAndLimitedNumberTest() {
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, null);
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());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
assertEquals(20L, groups.get(0).getUserMaximum());
@ -112,10 +113,10 @@ class ControllerServiceTest {
void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException {
controllerService.createGroupAsOrga(account2, "test", "hi", null, true, true, null, null, null);
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());
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());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
assertEquals(20L, groups.get(0).getUserMaximum());
@ -125,9 +126,9 @@ class ControllerServiceTest {
@Test
void createPublicGroupWithParentAndLimitedNumberTest() throws IOException {
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());
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());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
assertEquals(20L, groups.get(0).getUserMaximum());
@ -137,9 +138,9 @@ class ControllerServiceTest {
@Test
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
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());
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());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
assertEquals(100000L, groups.get(0).getUserMaximum());
@ -149,9 +150,9 @@ class ControllerServiceTest {
@Test
void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException {
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());
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());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
assertEquals(100000L, groups.get(0).getUserMaximum());
@ -161,7 +162,7 @@ class ControllerServiceTest {
@Test
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
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());
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -172,7 +173,7 @@ class ControllerServiceTest {
@Test
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
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());
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -183,7 +184,7 @@ class ControllerServiceTest {
@Test
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
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());
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
@ -194,7 +195,7 @@ class ControllerServiceTest {
@Test
void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
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());
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
@ -205,7 +206,7 @@ class ControllerServiceTest {
@Test
void createOrgaLectureGroupAndLimitedNumberTest() throws IOException {
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());
assertEquals(GroupType.LECTURE, groups.get(0).getType());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -216,7 +217,7 @@ class ControllerServiceTest {
@Test
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
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());
assertEquals(GroupType.LECTURE, groups.get(0).getType());
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
@ -225,37 +226,40 @@ class ControllerServiceTest {
}
//TODO: GroupServiceTest
@Disabled
@Test
public void deleteUserTest() {
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());
User user = new User(account.getName(), "", "", "");
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
@Disabled
@Test
public void updateRoleAdminTest() {
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());
User user = new User(account.getName(), "", "", "");
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()));
}
//TODO: GroupServiceTest
@Disabled
@Test
public void updateRoleMemberTest() {
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());
User user = new User(account2.getName(), "", "", "");
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()));
}
@ -263,7 +267,7 @@ class ControllerServiceTest {
@Test
public void updateRoleNonUserTest() {
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(), "", "", "");
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());
@ -273,7 +277,7 @@ class ControllerServiceTest {
@Test
public void deleteNonUserTest() {
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(), "", "", "");
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());
@ -285,23 +289,25 @@ class ControllerServiceTest {
}
//TODO: GroupServiceTest
@Disabled
@Test
void passIfLastAdminTest() {
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());
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));
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()));
}
//TODO: GroupServiceTest
@Disabled
@Test
void dontPassIfNotLastAdminTest() {
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());
User user2 = new User(account2.getName(), "", "", "");
groupService.updateRole(user2, groups.get(0).getId());
@ -309,21 +315,22 @@ class ControllerServiceTest {
groupService.changeRoleIfLastAdmin(account, groups.get(0));
User user = new User(account.getName(), "", "", "");
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()));
}
//TODO: GroupServiceTest
@Disabled
@Test
void getVeteranMemberTest() {
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(account3, groups.get(0).getId());
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));
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.MEMBER, groups.get(0).getRoles().get(account3.getName()));
}

View File

@ -70,7 +70,7 @@ class GroupServiceTest {
void rightClassForSuccessfulGroup() {
List<Event> eventList = completePrivateGroup(1);
List<Group> groups = projectionService.projectEventList(eventList);
List<Group> groups = ProjectionService.projectEventList(eventList);
assertThat(groups.get(0)).isInstanceOf(Group.class);
}
@ -79,7 +79,7 @@ class GroupServiceTest {
void projectEventList_SingleGroup() {
List<Event> eventList = completePrivateGroup(5);
List<Group> groups = projectionService.projectEventList(eventList);
List<Group> groups = ProjectionService.projectEventList(eventList);
assertThat(groups).hasSize(1);
assertThat(groups.get(0).getMembers()).hasSize(5);
@ -92,7 +92,7 @@ class GroupServiceTest {
List<Event> eventList = completePrivateGroups(10, 2);
eventList.addAll(completePublicGroups(10, 5));
List<Group> groups = projectionService.projectEventList(eventList);
List<Group> groups = ProjectionService.projectEventList(eventList);
assertThat(groups).hasSize(20);
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);
assertThat(group.getType()).isEqualTo(null);
assertThat(projectionService.getAllGroupWithVisibilityPublic("errer")).isEmpty();
assertThat(projectionService.projectPublicGroups("errer")).isEmpty();
}
//TODO: ProjectionServiceTest
@ -132,7 +132,7 @@ class GroupServiceTest {
deleteGroupEvent(uuidMock(0)),
createPublicGroupEvent());
assertThat(projectionService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
assertThat(projectionService.projectPublicGroups("test1").size()).isEqualTo(1);
}
//TODO: ProjectionServiceTest
@ -145,7 +145,7 @@ class GroupServiceTest {
createPublicGroupEvent(),
createPrivateGroupEvent());
assertThat(projectionService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
assertThat(projectionService.projectPublicGroups("test1").size()).isEqualTo(3);
}
//TODO: ProjectionServiceTest
@ -156,8 +156,8 @@ class GroupServiceTest {
createPrivateGroupEvent(),
createPublicGroupEvent());
assertThat(projectionService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
assertThat(projectionService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
assertThat(projectionService.projectPublicGroups("kobold")).hasSize(1);
assertThat(projectionService.projectPublicGroups("peter")).hasSize(2);
}
//TODO: ProjectionServiceTest
@ -169,7 +169,7 @@ class GroupServiceTest {
createLectureEvent(),
createLectureEvent());
assertThat(projectionService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
assertThat(projectionService.projectLectures().size()).isEqualTo(4);
}
//TODO: SearchServiceTest