1

Merge branch 'slight-chganges' into killertester

# Conflicts:
#	src/test/java/mops/gruppen2/service/EventServiceTest.java
This commit is contained in:
Christoph
2020-03-24 15:35:35 +01:00
31 changed files with 488 additions and 483 deletions

View File

@ -5,7 +5,14 @@ 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.*;
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 mops.gruppen2.domain.exception.UserNotFoundException;
import mops.gruppen2.security.Account;
@ -24,13 +31,11 @@ public class ControllerService {
private final EventService eventService;
private final UserService userService;
private final InviteLinkRepositoryService inviteLinkRepositoryService;
private final Logger logger;
public ControllerService(EventService eventService, UserService userService, InviteLinkRepositoryService inviteLinkRepositoryService) {
public ControllerService(EventService eventService, UserService userService) {
this.eventService = eventService;
this.userService = userService;
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
this.logger = Logger.getLogger("controllerServiceLogger");
}
@ -43,15 +48,14 @@ public class ControllerService {
* @param title Gruppentitel
* @param description Gruppenbeschreibung
*/
public void createGroup(Account account, String title, String description, Boolean visibility, Boolean maxInfiniteUsers, Long userMaximum, Long parent) throws EventException {
public void createGroup(Account account, String title, String description, Boolean maxInfiniteUsers, Boolean visibility, Long userMaximum, UUID parent) throws EventException {
Visibility visibility1;
Long groupId = eventService.checkGroup();
UUID groupId = eventService.checkGroup();
if (visibility) {
visibility1 = Visibility.PUBLIC;
} else {
visibility1 = Visibility.PRIVATE;
createInviteLink(groupId);
}
if(maxInfiniteUsers){
@ -67,9 +71,9 @@ public class ControllerService {
updateRole(account.getName(), groupId);
}
public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, Long parent, List<User> users) throws EventException {
public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent, List<User> users) throws EventException {
Visibility visibility1;
Long groupId = eventService.checkGroup();
UUID groupId = eventService.checkGroup();
if (visibility) {
visibility1 = Visibility.PUBLIC;
@ -99,17 +103,13 @@ public class ControllerService {
addUserList(users, groupId);
}
private void createInviteLink(Long groupId) {
inviteLinkRepositoryService.saveInvite(groupId, UUID.randomUUID());
}
public void addUser(Account account, Long groupId) {
public void addUser(Account account, UUID groupId) {
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
eventService.saveEvent(addUserEvent);
}
public void addUserList(List<User> users, Long groupId) {
public void addUserList(List<User> users, UUID groupId) {
for (User user : users) {
Group group = userService.getGroupById(groupId);
if (group.getMembers().contains(user)) {
@ -121,22 +121,22 @@ public class ControllerService {
}
}
public void updateTitle(Account account, Long groupId, String title) {
public void updateTitle(Account account, UUID groupId, String title) {
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
eventService.saveEvent(updateGroupTitleEvent);
}
public void updateDescription(Account account, Long groupId, String description) {
public void updateDescription(Account account, UUID groupId, String description) {
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
eventService.saveEvent(updateGroupDescriptionEvent);
}
public void updateMaxUser(Account account, Long groupId, Long userMaximum) {
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId,account.getName(),userMaximum);
public void updateMaxUser(Account account, UUID groupId, Long userMaximum) {
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId, account.getName(), userMaximum);
eventService.saveEvent(updateUserMaxEvent);
}
public void updateRole(String userId, Long groupId) throws EventException {
public void updateRole(String userId, UUID groupId) throws EventException {
UpdateRoleEvent updateRoleEvent;
Group group = userService.getGroupById(groupId);
User user = null;
@ -158,7 +158,7 @@ public class ControllerService {
eventService.saveEvent(updateRoleEvent);
}
public void deleteUser(String userId, Long groupId) throws EventException {
public void deleteUser(String userId, UUID groupId) throws EventException {
Group group = userService.getGroupById(groupId);
User user = null;
for (User member : group.getMembers()) {
@ -175,18 +175,18 @@ public class ControllerService {
eventService.saveEvent(deleteUserEvent);
}
public void deleteGroupEvent(String user_id, Long groupId) {
public void deleteGroupEvent(String user_id, UUID groupId) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user_id);
eventService.saveEvent(deleteGroupEvent);
}
public boolean passIfLastAdmin(Account account, Long groupId){
public boolean passIfLastAdmin(Account account, UUID groupId) {
Group group = userService.getGroupById(groupId);
if (group.getMembers().size() <= 1){
if (group.getMembers().size() <= 1) {
return true;
}
if (isLastAdmin(account, group)){
if (isLastAdmin(account, group)) {
String newAdminId = getVeteranMember(account, group);
updateRole(newAdminId, groupId);
}
@ -195,8 +195,8 @@ public class ControllerService {
private boolean isLastAdmin(Account account, Group group){
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()){
if (entry.getValue().equals(ADMIN)){
if (!(entry.getKey().equals(account.getName()))){
if (entry.getValue() == ADMIN) {
if (!(entry.getKey().equals(account.getName()))) {
return false;
}
}
@ -204,12 +204,28 @@ public class ControllerService {
return true;
}
private String getVeteranMember(Account account, Group group){
private String getVeteranMember(Account account, Group group) {
List<User> mitglieder = group.getMembers();
if (mitglieder.get(0).getId().equals(account.getName())){
if (mitglieder.get(0).getId().equals(account.getName())) {
return mitglieder.get(1).getId();
}
return mitglieder.get(0).getId();
}
public UUID getUUID(String id) {
if (id == null) {
return UUID.fromString("00000000-0000-0000-0000-000000000000");
} else {
return UUID.fromString(id);
}
}
public boolean idIsEmpty(UUID id) {
if (id == null) {
return true;
}
return id.toString().equals("00000000-0000-0000-0000-000000000000");
}
}

View File

@ -8,6 +8,8 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
public class EventService {
@ -45,7 +47,7 @@ public class EventService {
e.printStackTrace();
}
return new EventDTO(null, event.getGroupId(), event.getUserId(), getEventType(event), payload);
return new EventDTO(null, event.getGroupId().toString(), event.getUserId(), getEventType(event), payload);
}
private String getEventType(Event event) {
@ -60,14 +62,16 @@ public class EventService {
*
* @return Long GruppenId
*/
public Long checkGroup() {
Long maxGroupID = eventStore.getMaxGroupID();
public UUID checkGroup() {
return UUID.randomUUID();
/*Long maxGroupID = eventStore.getMaxGroupID();
if (maxGroupID == null) {
return 1L;
}
return maxGroupID + 1;
return maxGroupID + 1;*/
}
/**
@ -77,7 +81,7 @@ public class EventService {
* @return Liste von neueren Events
*/
public List<Event> getNewEvents(Long status) {
List<Long> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
List<String> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
List<EventDTO> groupEventDTOS = eventStore.findAllEventsOfGroups(groupIdsThatChanged);
return translateEventDTOs(groupEventDTOS);
@ -107,13 +111,19 @@ public class EventService {
return eventStore.getHighesEvent_ID();
}
public List<Long> getGroupsOfUser(String userID) {
return eventStore.findGroup_idsWhereUser_id(userID);
}
public List<Event> getEventsOfGroup(Long groupId) {
List<EventDTO> eventDTOList = eventStore.findEventDTOByGroup_id(groupId);
public List<Event> getEventsOfGroup(UUID groupId) {
List<EventDTO> eventDTOList = eventStore.findEventDTOByGroup_id(groupId.toString());
return translateEventDTOs(eventDTOList);
}
public List<UUID> findGroupIdsByUser(String userId) {
List<String> groupIDs = eventStore.findGroup_idsWhereUser_id(userId);
System.out.println(groupIDs);
return groupIDs.stream()
.map(UUID::fromString)
.collect(Collectors.toList());
}
}

View File

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@ -34,10 +35,10 @@ public class GroupService {
* @param groupIds Liste an IDs
* @return Liste an Events
*/
public List<Event> getGroupEvents(List<Long> groupIds) {
public List<Event> getGroupEvents(List<UUID> groupIds) {
List<EventDTO> eventDTOS = new ArrayList<>();
for (Long groupId : groupIds) {
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(groupId));
for (UUID groupId : groupIds) {
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(groupId.toString()));
}
return eventService.translateEventDTOs(eventDTOS);
}
@ -51,7 +52,7 @@ public class GroupService {
* @throws EventException Projektionsfehler
*/
public List<Group> projectEventList(List<Event> events) throws EventException {
Map<Long, Group> groupMap = new HashMap<>();
Map<UUID, Group> groupMap = new HashMap<>();
events.parallelStream()
.forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
@ -59,7 +60,7 @@ public class GroupService {
return new ArrayList<>(groupMap.values());
}
private Group getOrCreateGroup(Map<Long, Group> groups, long groupId) {
private Group getOrCreateGroup(Map<UUID, Group> groups, UUID groupId) {
if (!groups.containsKey(groupId)) {
groups.put(groupId, new Group());
}
@ -81,7 +82,7 @@ public class GroupService {
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
List<Group> visibleGroups = projectEventList(createEvents);
List<Long> userGroupIds = eventRepository.findGroup_idsWhereUser_id(userId);
List<UUID> userGroupIds = eventService.findGroupIdsByUser(userId);
return visibleGroups.parallelStream()
.filter(group -> group.getType() != null)
@ -98,6 +99,7 @@ public class GroupService {
List<Group> visibleGroups = projectEventList(createEvents);
return visibleGroups.parallelStream()
.filter(group -> group.getType() != null)
.filter(group -> group.getType() == GroupType.LECTURE)
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
.collect(Collectors.toList());
@ -120,5 +122,4 @@ public class GroupService {
group.getDescription().toLowerCase().contains(search.toLowerCase()))
.collect(Collectors.toList());
}
}

View File

@ -1,26 +0,0 @@
package mops.gruppen2.service;
import mops.gruppen2.domain.dto.InviteLinkDTO;
import mops.gruppen2.repository.InviteLinkRepository;
import org.springframework.stereotype.Service;
import java.util.UUID;
@Service
public class InviteLinkRepositoryService {
private final InviteLinkRepository inviteLinkRepository;
public InviteLinkRepositoryService(InviteLinkRepository inviteLinkRepository) {
this.inviteLinkRepository = inviteLinkRepository;
}
public long findGroupIdByInvite(String link) {
return inviteLinkRepository.findGroupIdByLink(link);
}
public void saveInvite(Long groupId, UUID link) {
inviteLinkRepository.save(new InviteLinkDTO(null, groupId, link.toString()));
}
}

View File

@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
//Hallo
@Service
@ -17,16 +18,18 @@ public class UserService {
private final EventRepository eventRepository;
private final GroupService groupService;
private final EventService eventService;
public UserService(EventRepository eventRepository, GroupService groupService) {
public UserService(EventRepository eventRepository, GroupService groupService, EventService eventService) {
this.eventRepository = eventRepository;
this.groupService = groupService;
this.eventService = eventService;
}
//Test nötig??
public List<Group> getUserGroups(User user) throws EventException {
List<Long> groupIds = eventRepository.findGroup_idsWhereUser_id(user.getId());
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
List<Event> events = groupService.getGroupEvents(groupIds);
List<Group> groups = groupService.projectEventList(events);
List<Group> newGroups = new ArrayList<>();
@ -38,8 +41,8 @@ public class UserService {
return newGroups;
}
public Group getGroupById(Long groupId) throws EventException {
List<Long> groupIds = new ArrayList<>();
public Group getGroupById(UUID groupId) throws EventException {
List<UUID> groupIds = new ArrayList<>();
groupIds.add(groupId);
try {