badpayloadexception + more reordering ugh
This commit is contained in:
@ -9,9 +9,7 @@ import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.service.APIService;
|
||||
import mops.gruppen2.service.EventStoreService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.ProjectionService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -31,14 +29,10 @@ import java.util.stream.Collectors;
|
||||
public class APIController {
|
||||
|
||||
private final EventStoreService eventStoreService;
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
private final ProjectionService projectionService;
|
||||
|
||||
public APIController(EventStoreService eventStoreService, GroupService groupService, UserService userService, ProjectionService projectionService) {
|
||||
public APIController(EventStoreService eventStoreService, ProjectionService projectionService) {
|
||||
this.eventStoreService = eventStoreService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
@ -55,9 +49,9 @@ public class APIController {
|
||||
@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 userService.getUserGroups(userId).stream()
|
||||
.map(group -> group.getId().toString())
|
||||
.collect(Collectors.toList());
|
||||
return projectionService.getUserGroups(userId).stream()
|
||||
.map(group -> group.getId().toString())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
|
@ -64,7 +64,7 @@ public class GroupCreationController {
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
UUID parentUUID = GroupService.getUUID(parent);
|
||||
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
|
||||
@ -105,7 +105,7 @@ public class GroupCreationController {
|
||||
@RequestParam(value = "parent", required = false) String parent) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
UUID parentUUID = GroupService.getUUID(parent);
|
||||
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
|
||||
|
@ -5,10 +5,10 @@ import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ProjectionService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -31,16 +31,16 @@ import java.util.UUID;
|
||||
@RequestMapping("/gruppen2")
|
||||
public class GroupDetailsController {
|
||||
|
||||
private final ControllerService controllerService;
|
||||
private final UserService userService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
private final GroupService groupService;
|
||||
private final ProjectionService projectionService;
|
||||
|
||||
public GroupDetailsController(ControllerService controllerService, UserService userService, ValidationService validationService, InviteService inviteService) {
|
||||
this.controllerService = controllerService;
|
||||
this.userService = userService;
|
||||
public GroupDetailsController(ValidationService validationService, InviteService inviteService, GroupService groupService, ProjectionService projectionService) {
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
this.groupService = groupService;
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@ -50,13 +50,13 @@ public class GroupDetailsController {
|
||||
HttpServletRequest request,
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
UUID parentId = group.getParent();
|
||||
String actualURL = request.getRequestURL().toString();
|
||||
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||
Group parent = controllerService.getParent(parentId);
|
||||
Group parent = groupService.getParent(parentId);
|
||||
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
|
||||
@ -93,7 +93,7 @@ public class GroupDetailsController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
@ -118,12 +118,12 @@ public class GroupDetailsController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
validationService.checkFields(title, description);
|
||||
|
||||
controllerService.changeMetaData(account, group, title, description);
|
||||
groupService.changeMetaData(account, group, title, description);
|
||||
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class GroupDetailsController {
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(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 = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
User principle = new User(account);
|
||||
User user = new User(userId, "", "", "");
|
||||
|
||||
@ -164,7 +164,7 @@ public class GroupDetailsController {
|
||||
|
||||
//TODO: checkIfAdmin checkt nicht, dass die rolle geändert wurde. oder die rolle wird nicht geändert
|
||||
|
||||
controllerService.changeRole(account, user, group);
|
||||
groupService.changeRole(account, user, group);
|
||||
|
||||
if (!validationService.checkIfAdmin(group, principle)) {
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
@ -181,11 +181,11 @@ public class GroupDetailsController {
|
||||
@RequestParam("group_id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNewMaximumIsValid(maximum, group);
|
||||
|
||||
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
|
||||
groupService.updateMaxUser(account, UUID.fromString(groupId), maximum);
|
||||
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
@ -200,11 +200,11 @@ public class GroupDetailsController {
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User principle = new User(account);
|
||||
User user = new User(userId, "", "", "");
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, principle);
|
||||
|
||||
controllerService.deleteUser(account, user, group);
|
||||
groupService.deleteUser(account, user, group);
|
||||
|
||||
if (!validationService.checkIfUserInGroup(group, principle)) {
|
||||
return "redirect:/gruppen2";
|
||||
@ -222,12 +222,12 @@ public class GroupDetailsController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||
validationService.throwIfGroupFull(group);
|
||||
|
||||
controllerService.addUser(account, UUID.fromString(groupId));
|
||||
groupService.addUser(account, UUID.fromString(groupId));
|
||||
|
||||
model.addAttribute("account", account);
|
||||
|
||||
@ -242,9 +242,9 @@ public class GroupDetailsController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
controllerService.deleteUser(account, user, group);
|
||||
groupService.deleteUser(account, user, group);
|
||||
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
@ -257,11 +257,11 @@ public class GroupDetailsController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
||||
groupService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
||||
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
@ -274,7 +274,7 @@ public class GroupDetailsController {
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
controllerService.addUsersFromCsv(account, file, groupId);
|
||||
groupService.addUsersFromCsv(account, file, groupId);
|
||||
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ProjectionService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@ -17,10 +17,10 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@Controller
|
||||
public class GruppenfindungController {
|
||||
|
||||
private final UserService userService;
|
||||
private final ProjectionService projectionService;
|
||||
|
||||
public GruppenfindungController(UserService userService) {
|
||||
this.userService = userService;
|
||||
public GruppenfindungController(ProjectionService projectionService) {
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
@ -37,7 +37,7 @@ public class GruppenfindungController {
|
||||
User user = new User(account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||
model.addAttribute("gruppen", projectionService.getUserGroups(user));
|
||||
model.addAttribute("user", user);
|
||||
|
||||
return "index";
|
||||
|
@ -4,10 +4,10 @@ import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ProjectionService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -32,14 +32,14 @@ public class SearchAndInviteController {
|
||||
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
private final GroupService groupService;
|
||||
private final ProjectionService projectionService;
|
||||
|
||||
public SearchAndInviteController(ValidationService validationService, InviteService inviteService, UserService userService, ControllerService controllerService) {
|
||||
public SearchAndInviteController(ValidationService validationService, InviteService inviteService, GroupService groupService, ProjectionService projectionService) {
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
this.groupService = groupService;
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@ -66,9 +66,9 @@ public class SearchAndInviteController {
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = controllerService.getParent(parentId);
|
||||
Group parent = groupService.getParent(parentId);
|
||||
User user = new User(account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
@ -89,7 +89,7 @@ public class SearchAndInviteController {
|
||||
Model model,
|
||||
@PathVariable("link") String link) {
|
||||
|
||||
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||
Group group = projectionService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
|
||||
@ -111,12 +111,12 @@ public class SearchAndInviteController {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||
validationService.throwIfGroupFull(group);
|
||||
|
||||
controllerService.addUser(account, UUID.fromString(groupId));
|
||||
groupService.addUser(account, UUID.fromString(groupId));
|
||||
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class BadPayloadException extends EventException {
|
||||
|
||||
public BadPayloadException(String info) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Payload konnte nicht übersetzt werden!", info);
|
||||
}
|
||||
}
|
@ -1,20 +1,10 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.event.AddUserEvent;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.DeleteGroupEvent;
|
||||
import mops.gruppen2.domain.event.DeleteUserEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -22,26 +12,23 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import static mops.gruppen2.domain.Role.ADMIN;
|
||||
|
||||
|
||||
@Service
|
||||
public class ControllerService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger("controllerServiceLogger");
|
||||
private final EventStoreService eventStoreService;
|
||||
private final UserService userService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
private final GroupService groupService;
|
||||
|
||||
public ControllerService(EventStoreService eventStoreService, UserService userService, ValidationService validationService, InviteService inviteService) {
|
||||
public ControllerService(EventStoreService eventStoreService, ValidationService validationService, InviteService inviteService, GroupService groupService) {
|
||||
this.eventStoreService = eventStoreService;
|
||||
this.userService = userService;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +77,7 @@ public class ControllerService {
|
||||
isMaximumInfinite,
|
||||
userMaximum, parent);
|
||||
|
||||
addUserList(newUsers, groupId);
|
||||
groupService.addUserList(newUsers, groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,158 +119,12 @@ public class ControllerService {
|
||||
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
|
||||
addUser(account, groupId);
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(user, groupId);
|
||||
groupService.addUser(account, groupId);
|
||||
groupService.updateTitle(account, groupId, title);
|
||||
groupService.updateDescription(account, groupId, description);
|
||||
groupService.updateRole(user, groupId);
|
||||
|
||||
return groupId;
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
private void addUserList(List<User> newUsers, UUID groupId) {
|
||||
for (User user : newUsers) {
|
||||
Group group = userService.getGroupById(groupId);
|
||||
if (group.getMembers().contains(user)) {
|
||||
LOG.info("Benutzer {} ist bereits in Gruppe", user.getId());
|
||||
} else {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, user.getId(), user.getGivenname(), user.getFamilyname(), user.getEmail());
|
||||
eventStoreService.saveEvent(addUserEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void addUser(Account account, UUID groupId) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
eventStoreService.saveEvent(addUserEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
private void updateTitle(Account account, UUID groupId, String title) {
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
|
||||
eventStoreService.saveEvent(updateGroupTitleEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void updateRole(User user, UUID groupId) throws EventException {
|
||||
UpdateRoleEvent updateRoleEvent;
|
||||
Group group = userService.getGroupById(groupId);
|
||||
validationService.throwIfNotInGroup(group, user);
|
||||
|
||||
if (group.getRoles().get(user.getId()) == ADMIN) {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), Role.MEMBER);
|
||||
} else {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), ADMIN);
|
||||
}
|
||||
eventStoreService.saveEvent(updateRoleEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
private void updateDescription(Account account, UUID groupId, String description) {
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
|
||||
eventStoreService.saveEvent(updateGroupDescriptionEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) {
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
List<User> newUserList = CsvService.readCsvFile(file);
|
||||
GroupService.removeOldUsersFromNewUsers(group.getMembers(), newUserList);
|
||||
|
||||
UUID groupUUID = getUUID(groupId);
|
||||
|
||||
Long newUserMaximum = GroupService.adjustUserMaximum((long) newUserList.size(), (long) group.getMembers().size(), group.getUserMaximum());
|
||||
if (newUserMaximum > group.getUserMaximum()) {
|
||||
updateMaxUser(account, groupUUID, newUserMaximum);
|
||||
}
|
||||
|
||||
addUserList(newUserList, groupUUID);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public UUID getUUID(String id) {
|
||||
return UUID.fromString(Objects.requireNonNullElse(id, "00000000-0000-0000-0000-000000000000"));
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void updateMaxUser(Account account, UUID groupId, Long userMaximum) {
|
||||
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId, account.getName(), userMaximum);
|
||||
eventStoreService.saveEvent(updateUserMaxEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void changeMetaData(Account account, Group group, String title, String description) {
|
||||
if (!title.equals(group.getTitle())) {
|
||||
updateTitle(account, group.getId(), title);
|
||||
}
|
||||
|
||||
if (!description.equals(group.getDescription())) {
|
||||
updateDescription(account, group.getId(), description);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: GroupService oder in Group?
|
||||
public Group getParent(UUID parentId) {
|
||||
Group parent = new Group();
|
||||
if (!GroupService.idIsEmpty(parentId)) {
|
||||
parent = userService.getGroupById(parentId);
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void deleteUser(Account account, User user, Group group) throws EventException {
|
||||
changeRoleIfLastAdmin(account, group);
|
||||
|
||||
validationService.throwIfNotInGroup(group, user);
|
||||
|
||||
deleteUserEvent(user, group.getId());
|
||||
|
||||
if (validationService.checkIfGroupEmpty(group.getId())) {
|
||||
deleteGroupEvent(user.getId(), group.getId());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
private void deleteUserEvent(User user, UUID groupId) {
|
||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
|
||||
eventStoreService.saveEvent(deleteUserEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void deleteGroupEvent(String userId, UUID groupId) {
|
||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
|
||||
inviteService.destroyLink(groupId);
|
||||
eventStoreService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
private void promoteVeteranMember(Account account, Group group) {
|
||||
if (validationService.checkIfLastAdmin(account, group)) {
|
||||
User newAdmin = GroupService.getVeteranMember(account, group);
|
||||
updateRole(newAdmin, group.getId());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void changeRoleIfLastAdmin(Account account, Group group) {
|
||||
if (group.getMembers().size() <= 1) {
|
||||
return;
|
||||
}
|
||||
promoteVeteranMember(account, group);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void changeRole(Account account, User user, Group group) {
|
||||
if (user.getId().equals(account.getName())) {
|
||||
if (group.getMembers().size() <= 1) {
|
||||
validationService.throwIfLastAdmin(account, group);
|
||||
}
|
||||
promoteVeteranMember(account, group);
|
||||
}
|
||||
updateRole(user, group.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class EventBuilderService {
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package mops.gruppen2.service;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.BadPayloadException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -39,6 +40,20 @@ public class EventStoreService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert alle Events aus der übergebenen Liste in der DB.
|
||||
*
|
||||
* @param events Liste an Events die gespeichert werden soll
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final void saveAll(List<Event>... events) {
|
||||
for (List<Event> eventlist : events) {
|
||||
for (Event event : eventlist) {
|
||||
eventStore.save(getDTOFromEvent(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt aus einem Event Objekt ein EventDTO Objekt.
|
||||
*
|
||||
@ -46,7 +61,7 @@ public class EventStoreService {
|
||||
*
|
||||
* @return EventDTO (Neues DTO)
|
||||
*/
|
||||
public EventDTO getDTOFromEvent(Event event) {
|
||||
public static EventDTO getDTOFromEvent(Event event) {
|
||||
String payload = "";
|
||||
try {
|
||||
payload = JsonService.serializeEvent(event);
|
||||
@ -57,6 +72,28 @@ public class EventStoreService {
|
||||
return new EventDTO(null, event.getGroupId().toString(), event.getUserId(), getEventType(event), payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt aus einer Liste von eventDTOs eine Liste von Events.
|
||||
*
|
||||
* @param eventDTOS Liste von DTOs
|
||||
*
|
||||
* @return Liste von Events
|
||||
*/
|
||||
static List<Event> getEventsFromDTOs(List<EventDTO> eventDTOS) {
|
||||
return eventDTOS.stream()
|
||||
.map(EventStoreService::getEventFromDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static Event getEventFromDTO(EventDTO dto) throws BadPayloadException {
|
||||
try {
|
||||
return JsonService.deserializeEvent(dto.getEvent_payload());
|
||||
} catch (JsonProcessingException e) {
|
||||
LOG.error("Payload\n {}\n konnte nicht deserialisiert werden!", dto.getEvent_payload());
|
||||
throw new BadPayloadException(EventStoreService.class.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Eventtyp als String wieder.
|
||||
*
|
||||
@ -71,17 +108,20 @@ public class EventStoreService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert alle Events aus der übergebenen Liste in der DB.
|
||||
* 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.
|
||||
*
|
||||
* @param events Liste an Events die gespeichert werden soll
|
||||
* @param groupIds Liste an IDs
|
||||
*
|
||||
* @return Liste an Events
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final void saveAll(List<Event>... events) {
|
||||
for (List<Event> eventlist : events) {
|
||||
for (Event event : eventlist) {
|
||||
eventStore.save(getDTOFromEvent(event));
|
||||
}
|
||||
//TODO: EventStoreService
|
||||
public List<Event> getGroupEvents(List<UUID> groupIds) {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
for (UUID groupId : groupIds) {
|
||||
eventDTOS.addAll(eventStore.findEventDTOByGroupId(groupId.toString()));
|
||||
}
|
||||
return getEventsFromDTOs(eventDTOS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,26 +139,6 @@ public class EventStoreService {
|
||||
return getEventsFromDTOs(groupEventDTOS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt aus einer Liste von eventDTOs eine Liste von Events.
|
||||
*
|
||||
* @param eventDTOS Liste von DTOs
|
||||
*
|
||||
* @return Liste von Events
|
||||
*/
|
||||
List<Event> getEventsFromDTOs(Iterable<EventDTO> eventDTOS) {
|
||||
List<Event> events = new ArrayList<>();
|
||||
|
||||
for (EventDTO eventDTO : eventDTOS) {
|
||||
try {
|
||||
events.add(JsonService.deserializeEvent(eventDTO.getEvent_payload()));
|
||||
} catch (JsonProcessingException e) {
|
||||
LOG.error("Payload\n {}\n konnte nicht deserialisiert werden!", eventDTO.getEvent_payload());
|
||||
}
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
public long getMaxEventId() {
|
||||
long highestEvent = 0;
|
||||
|
||||
|
@ -3,17 +3,29 @@ package mops.gruppen2.service;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.event.AddUserEvent;
|
||||
import mops.gruppen2.domain.event.DeleteGroupEvent;
|
||||
import mops.gruppen2.domain.event.DeleteUserEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import static mops.gruppen2.domain.Role.ADMIN;
|
||||
|
||||
/**
|
||||
* Behandelt Aufgaben, welche sich auf eine Gruppe beziehen
|
||||
*/
|
||||
@ -22,10 +34,18 @@ public class GroupService {
|
||||
|
||||
private final EventStoreService eventStoreService;
|
||||
private final EventRepository eventRepository;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
private final ProjectionService projectionService;
|
||||
|
||||
public GroupService(EventStoreService eventStoreService, EventRepository eventRepository) {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GroupService.class);
|
||||
|
||||
public GroupService(EventStoreService eventStoreService, EventRepository eventRepository, ValidationService validationService, InviteService inviteService, ProjectionService projectionService) {
|
||||
this.eventStoreService = eventStoreService;
|
||||
this.eventRepository = eventRepository;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
static User getVeteranMember(Account account, Group group) {
|
||||
@ -98,21 +118,150 @@ public class GroupService {
|
||||
return "00000000-0000-0000-0000-000000000000".equals(id.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param groupIds Liste an IDs
|
||||
*
|
||||
* @return Liste an Events
|
||||
*/
|
||||
//TODO: Das vielleicht in den EventRepoService?
|
||||
public List<Event> getGroupEvents(List<UUID> groupIds) {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
for (UUID groupId : groupIds) {
|
||||
eventDTOS.addAll(eventRepository.findEventDTOByGroupId(groupId.toString()));
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
void addUserList(List<User> newUsers, UUID groupId) {
|
||||
for (User user : newUsers) {
|
||||
Group group = projectionService.getGroupById(groupId);
|
||||
if (group.getMembers().contains(user)) {
|
||||
LOG.info("Benutzer {} ist bereits in Gruppe", user.getId());
|
||||
} else {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, user.getId(), user.getGivenname(), user.getFamilyname(), user.getEmail());
|
||||
eventStoreService.saveEvent(addUserEvent);
|
||||
}
|
||||
}
|
||||
return eventStoreService.getEventsFromDTOs(eventDTOS);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void addUser(Account account, UUID groupId) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
eventStoreService.saveEvent(addUserEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
void updateTitle(Account account, UUID groupId, String title) {
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
|
||||
eventStoreService.saveEvent(updateGroupTitleEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void updateRole(User user, UUID groupId) throws EventException {
|
||||
UpdateRoleEvent updateRoleEvent;
|
||||
Group group = projectionService.getGroupById(groupId);
|
||||
validationService.throwIfNotInGroup(group, user);
|
||||
|
||||
if (group.getRoles().get(user.getId()) == ADMIN) {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), Role.MEMBER);
|
||||
} else {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), ADMIN);
|
||||
}
|
||||
eventStoreService.saveEvent(updateRoleEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
void updateDescription(Account account, UUID groupId, String description) {
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
|
||||
eventStoreService.saveEvent(updateGroupDescriptionEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) {
|
||||
Group group = projectionService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
List<User> newUserList = CsvService.readCsvFile(file);
|
||||
removeOldUsersFromNewUsers(group.getMembers(), newUserList);
|
||||
|
||||
UUID groupUUID = getUUID(groupId);
|
||||
|
||||
Long newUserMaximum = adjustUserMaximum((long) newUserList.size(), (long) group.getMembers().size(), group.getUserMaximum());
|
||||
if (newUserMaximum > group.getUserMaximum()) {
|
||||
updateMaxUser(account, groupUUID, newUserMaximum);
|
||||
}
|
||||
|
||||
addUserList(newUserList, groupUUID);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public static UUID getUUID(String id) {
|
||||
return UUID.fromString(Objects.requireNonNullElse(id, "00000000-0000-0000-0000-000000000000"));
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void updateMaxUser(Account account, UUID groupId, Long userMaximum) {
|
||||
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId, account.getName(), userMaximum);
|
||||
eventStoreService.saveEvent(updateUserMaxEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void changeMetaData(Account account, Group group, String title, String description) {
|
||||
if (!title.equals(group.getTitle())) {
|
||||
updateTitle(account, group.getId(), title);
|
||||
}
|
||||
|
||||
if (!description.equals(group.getDescription())) {
|
||||
updateDescription(account, group.getId(), description);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: GroupService oder in Group?
|
||||
public Group getParent(UUID parentId) {
|
||||
Group parent = new Group();
|
||||
if (!idIsEmpty(parentId)) {
|
||||
parent = projectionService.getGroupById(parentId);
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void deleteUser(Account account, User user, Group group) throws EventException {
|
||||
changeRoleIfLastAdmin(account, group);
|
||||
|
||||
validationService.throwIfNotInGroup(group, user);
|
||||
|
||||
deleteUserEvent(user, group.getId());
|
||||
|
||||
if (validationService.checkIfGroupEmpty(group.getId())) {
|
||||
deleteGroupEvent(user.getId(), group.getId());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
private void deleteUserEvent(User user, UUID groupId) {
|
||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
|
||||
eventStoreService.saveEvent(deleteUserEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService/eventbuilderservice
|
||||
public void deleteGroupEvent(String userId, UUID groupId) {
|
||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
|
||||
inviteService.destroyLink(groupId);
|
||||
eventStoreService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
private void promoteVeteranMember(Account account, Group group) {
|
||||
if (validationService.checkIfLastAdmin(account, group)) {
|
||||
User newAdmin = getVeteranMember(account, group);
|
||||
updateRole(newAdmin, group.getId());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void changeRoleIfLastAdmin(Account account, Group group) {
|
||||
if (group.getMembers().size() <= 1) {
|
||||
return;
|
||||
}
|
||||
promoteVeteranMember(account, group);
|
||||
}
|
||||
|
||||
//TODO: GroupService
|
||||
public void changeRole(Account account, User user, Group group) {
|
||||
if (user.getId().equals(account.getName())) {
|
||||
if (group.getMembers().size() <= 1) {
|
||||
validationService.throwIfLastAdmin(account, group);
|
||||
}
|
||||
promoteVeteranMember(account, group);
|
||||
}
|
||||
updateRole(user, group.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,11 @@ package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.User;
|
||||
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;
|
||||
@ -60,11 +62,11 @@ public class 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")));
|
||||
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")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||
|
||||
@ -85,10 +87,10 @@ public class ProjectionService {
|
||||
@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")));
|
||||
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")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(createEvents);
|
||||
|
||||
@ -117,4 +119,59 @@ public class ProjectionService {
|
||||
|
||||
return new ArrayList<>(groupMap.values());
|
||||
}
|
||||
|
||||
//TODO: ProjectionService
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(String userId) throws EventException {
|
||||
return getUserGroups(new User(userId, "", "", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine Liste aus Gruppen zurück, in denen sich der übergebene User befindet.
|
||||
*
|
||||
* @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<>();
|
||||
|
||||
for (Group group : groups) {
|
||||
if (group.getMembers().contains(user)) {
|
||||
newGroups.add(group);
|
||||
}
|
||||
}
|
||||
SearchService.sortByGroupType(newGroups);
|
||||
|
||||
return newGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Gruppe zurück, die zu der übergebenen Id passt.
|
||||
*
|
||||
* @param groupId Die Id der gesuchten Gruppe
|
||||
*
|
||||
* @return Die gesuchte Gruppe
|
||||
*
|
||||
* @throws EventException Wenn die Gruppe nicht gefunden wird
|
||||
*/
|
||||
//TODO: ProjectionService
|
||||
public Group getGroupById(UUID groupId) throws EventException {
|
||||
List<UUID> groupIds = new ArrayList<>();
|
||||
groupIds.add(groupId);
|
||||
|
||||
try {
|
||||
List<Event> events = eventStoreService.getGroupEvents(groupIds);
|
||||
return projectEventList(events).get(0);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new GroupNotFoundException("@UserService");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,78 +0,0 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final GroupService groupService;
|
||||
private final EventStoreService eventStoreService;
|
||||
private final ProjectionService projectionService;
|
||||
|
||||
public UserService(GroupService groupService, EventStoreService eventStoreService, ProjectionService projectionService) {
|
||||
this.groupService = groupService;
|
||||
this.eventStoreService = eventStoreService;
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(String userId) throws EventException {
|
||||
return getUserGroups(new User(userId, "", "", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine Liste aus Gruppen zurück, in denen sich der übergebene User befindet.
|
||||
*
|
||||
* @param user Der User
|
||||
*
|
||||
* @return Liste aus Gruppen
|
||||
*/
|
||||
//TODO: Nur AddUserEvents + DeleteUserEvents betrachten
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(User user) {
|
||||
List<UUID> groupIds = eventStoreService.findGroupIdsByUser(user.getId());
|
||||
List<Event> events = groupService.getGroupEvents(groupIds);
|
||||
List<Group> groups = projectionService.projectEventList(events);
|
||||
List<Group> newGroups = new ArrayList<>();
|
||||
|
||||
for (Group group : groups) {
|
||||
if (group.getMembers().contains(user)) {
|
||||
newGroups.add(group);
|
||||
}
|
||||
}
|
||||
SearchService.sortByGroupType(newGroups);
|
||||
|
||||
return newGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Gruppe zurück, die zu der übergebenen Id passt.
|
||||
*
|
||||
* @param groupId Die Id der gesuchten Gruppe
|
||||
*
|
||||
* @return Die gesuchte Gruppe
|
||||
*
|
||||
* @throws EventException Wenn die Gruppe nicht gefunden wird
|
||||
*/
|
||||
public Group getGroupById(UUID groupId) throws EventException {
|
||||
List<UUID> groupIds = new ArrayList<>();
|
||||
groupIds.add(groupId);
|
||||
|
||||
try {
|
||||
List<Event> events = groupService.getGroupEvents(groupIds);
|
||||
return projectionService.projectEventList(events).get(0);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new GroupNotFoundException("@UserService");
|
||||
}
|
||||
}
|
||||
}
|
@ -23,12 +23,12 @@ import static mops.gruppen2.domain.Role.ADMIN;
|
||||
@Service
|
||||
public class ValidationService {
|
||||
|
||||
private final UserService userService;
|
||||
private final SearchService searchService;
|
||||
private final ProjectionService projectionService;
|
||||
|
||||
public ValidationService(UserService userService, SearchService searchService) {
|
||||
this.userService = userService;
|
||||
public ValidationService(SearchService searchService, ProjectionService projectionService) {
|
||||
this.searchService = searchService;
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
//TODO: make static or change return + assignment
|
||||
@ -68,7 +68,7 @@ public class ValidationService {
|
||||
}
|
||||
|
||||
boolean checkIfGroupEmpty(UUID groupId) {
|
||||
return userService.getGroupById(groupId).getMembers().isEmpty();
|
||||
return projectionService.getGroupById(groupId).getMembers().isEmpty();
|
||||
}
|
||||
|
||||
public void throwIfNoAdmin(Group group, User user) {
|
||||
|
@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
//TODO: Alles in die entsprechenden Klassen sortieren :((((
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = Gruppen2Application.class)
|
||||
@Transactional
|
||||
@ -37,12 +38,15 @@ class ControllerServiceTest {
|
||||
Account account;
|
||||
Account account2;
|
||||
Account account3;
|
||||
@Autowired
|
||||
ControllerService controllerService;
|
||||
@Autowired
|
||||
EventStoreService eventStoreService;
|
||||
UserService userService;
|
||||
@Autowired
|
||||
ValidationService validationService;
|
||||
@Autowired
|
||||
EventRepository eventRepository;
|
||||
@Autowired
|
||||
GroupService groupService;
|
||||
@Autowired
|
||||
InviteService inviteService;
|
||||
@ -53,11 +57,6 @@ class ControllerServiceTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
eventStoreService = new EventStoreService(eventRepository);
|
||||
groupService = new GroupService(eventStoreService, eventRepository);
|
||||
userService = new UserService(groupService, eventStoreService, projectionService);
|
||||
validationService = new ValidationService(userService, searchService);
|
||||
controllerService = new ControllerService(eventStoreService, userService, validationService, inviteService);
|
||||
Set<String> roles = new HashSet<>();
|
||||
roles.add("l");
|
||||
account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles);
|
||||
@ -69,7 +68,7 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPublicGroupWithNoParentAndLimitedNumberTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -80,7 +79,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 = userService.getUserGroups(user);
|
||||
List<Group> groups = projectionService.getUserGroups(user);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
@ -91,7 +90,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 = userService.getUserGroups(user);
|
||||
List<Group> groups = projectionService.getUserGroups(user);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
@ -102,7 +101,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 = userService.getUserGroups(user);
|
||||
List<Group> groups = projectionService.getUserGroups(user);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
@ -113,10 +112,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 = userService.getUserGroups(user);
|
||||
List<Group> groups1 = projectionService.getUserGroups(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 = userService.getUserGroups(user2);
|
||||
List<Group> groups = projectionService.getUserGroups(user2);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
@ -126,9 +125,9 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPublicGroupWithParentAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
List<Group> groups1 = projectionService.getUserGroups(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 = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -138,9 +137,9 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
List<Group> groups1 = projectionService.getUserGroups(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 = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -150,9 +149,9 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
List<Group> groups1 = projectionService.getUserGroups(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 = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -162,7 +161,7 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, null, null, 20L, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -173,7 +172,7 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -184,7 +183,7 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", true, null, null, 20L, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -195,7 +194,7 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", true, null, true, null, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -206,7 +205,7 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createOrgaLectureGroupAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, true, null, 20L, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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());
|
||||
@ -217,7 +216,7 @@ class ControllerServiceTest {
|
||||
@Test
|
||||
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, true, true, null, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(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,53 +224,58 @@ class ControllerServiceTest {
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
public void deleteUserTest() {
|
||||
controllerService.createGroup(account, "test", "hi", true, true, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
groupService.addUser(account2, groups.get(0).getId());
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
controllerService.deleteUser(account, user, groups.get(0));
|
||||
assertTrue(userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
||||
groupService.deleteUser(account, user, groups.get(0));
|
||||
assertTrue(projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
public void updateRoleAdminTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
groupService.addUser(account2, groups.get(0).getId());
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
controllerService.updateRole(user, groups.get(0).getId());
|
||||
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
groupService.updateRole(user, groups.get(0).getId());
|
||||
groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account.getName()));
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
public void updateRoleMemberTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
groupService.addUser(account2, groups.get(0).getId());
|
||||
User user = new User(account2.getName(), "", "", "");
|
||||
controllerService.updateRole(user, groups.get(0).getId());
|
||||
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
groupService.updateRole(user, groups.get(0).getId());
|
||||
groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
public void updateRoleNonUserTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
User user = new User(account2.getName(), "", "", "");
|
||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.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());
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
public void deleteNonUserTest() {
|
||||
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
User user = new User(account2.getName(), "", "", "");
|
||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.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());
|
||||
}
|
||||
|
||||
@ -280,43 +284,46 @@ class ControllerServiceTest {
|
||||
assertEquals("hi", description);
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
void passIfLastAdminTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
groupService.addUser(account2, groups.get(0).getId());
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
controllerService.deleteUser(account, user, groups.get(0));
|
||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
groups = projectionService.getUserGroups(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()));
|
||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
void dontPassIfNotLastAdminTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
List<Group> groups = projectionService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
groupService.addUser(account2, groups.get(0).getId());
|
||||
User user2 = new User(account2.getName(), "", "", "");
|
||||
controllerService.updateRole(user2, groups.get(0).getId());
|
||||
controllerService.addUser(account3, groups.get(0).getId());
|
||||
controllerService.changeRoleIfLastAdmin(account, groups.get(0));
|
||||
groupService.updateRole(user2, groups.get(0).getId());
|
||||
groupService.addUser(account3, groups.get(0).getId());
|
||||
groupService.changeRoleIfLastAdmin(account, groups.get(0));
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
controllerService.deleteUser(account, user, groups.get(0));
|
||||
groups = userService.getUserGroups(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()));
|
||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||
}
|
||||
|
||||
//TODO: GroupServiceTest
|
||||
@Test
|
||||
void getVeteranMemberTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
controllerService.addUser(account3, groups.get(0).getId());
|
||||
List<Group> groups = projectionService.getUserGroups(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 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
controllerService.deleteUser(account, user, groups.get(0));
|
||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
groups = projectionService.getUserGroups(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()));
|
||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||
}
|
||||
|
@ -51,10 +51,14 @@ class GroupServiceTest {
|
||||
ProjectionService projectionService;
|
||||
@Autowired
|
||||
private EventStoreService eventStoreService;
|
||||
@Autowired
|
||||
private ValidationService validationService;
|
||||
@Autowired
|
||||
private InviteService inviteService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
groupService = new GroupService(eventStoreService, eventRepository);
|
||||
groupService = new GroupService(eventStoreService, eventRepository, validationService, inviteService, projectionService);
|
||||
eventRepository.deleteAll();
|
||||
//noinspection SqlResolve
|
||||
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
|
||||
@ -94,6 +98,7 @@ class GroupServiceTest {
|
||||
assertThat(groups.stream().map(group -> group.getMembers().size()).reduce(Integer::sum).get()).isEqualTo(70);
|
||||
}
|
||||
|
||||
//TODO: EventStoreServiceTest
|
||||
@Test
|
||||
void getGroupEvents() {
|
||||
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||
@ -102,9 +107,9 @@ class GroupServiceTest {
|
||||
|
||||
List<UUID> groupIds = Arrays.asList(uuidMock(0), uuidMock(1));
|
||||
|
||||
assertThat(groupService.getGroupEvents(groupIds)).hasSize(2);
|
||||
assertThat(groupService.getGroupEvents(groupIds).get(0).getGroupId()).isEqualTo(uuidMock(0));
|
||||
assertThat(groupService.getGroupEvents(groupIds).get(1).getGroupId()).isEqualTo(uuidMock(1));
|
||||
assertThat(eventStoreService.getGroupEvents(groupIds)).hasSize(2);
|
||||
assertThat(eventStoreService.getGroupEvents(groupIds).get(0).getGroupId()).isEqualTo(uuidMock(0));
|
||||
assertThat(eventStoreService.getGroupEvents(groupIds).get(1).getGroupId()).isEqualTo(uuidMock(1));
|
||||
}
|
||||
|
||||
//TODO: ProjectionServiceTest
|
||||
|
Reference in New Issue
Block a user