Merge remote-tracking branch 'origin/master' into csv-error-handling
# Conflicts: # src/main/java/mops/gruppen2/controller/Gruppen2Controller.java # src/main/java/mops/gruppen2/domain/User.java # src/main/java/mops/gruppen2/service/ControllerService.java # src/main/resources/templates/createStudent.html
This commit is contained in:
@ -18,8 +18,11 @@ import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static mops.gruppen2.domain.Role.ADMIN;
|
||||
|
||||
|
||||
@Service
|
||||
public class ControllerService {
|
||||
@ -43,7 +46,7 @@ public class ControllerService {
|
||||
* @param title Gruppentitel
|
||||
* @param description Gruppenbeschreibung
|
||||
*/
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility) throws EventException {
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility, Long userMaximum) throws EventException {
|
||||
Visibility visibility1;
|
||||
Long groupId = eventService.checkGroup();
|
||||
|
||||
@ -54,7 +57,7 @@ public class ControllerService {
|
||||
createInviteLink(groupId);
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, groupId);
|
||||
@ -130,10 +133,10 @@ public class ControllerService {
|
||||
throw new UserNotFoundException(this.getClass().toString());
|
||||
}
|
||||
|
||||
if (group.getRoles().get(user.getId()) == Role.ADMIN) {
|
||||
if (group.getRoles().get(user.getId()) == ADMIN) {
|
||||
updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), Role.MEMBER);
|
||||
} else {
|
||||
updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), Role.ADMIN);
|
||||
updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), ADMIN);
|
||||
}
|
||||
eventService.saveEvent(updateRoleEvent);
|
||||
}
|
||||
@ -160,4 +163,56 @@ public class ControllerService {
|
||||
eventService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) throws EventException {
|
||||
Visibility visibility1;
|
||||
Long groupId = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1, 1000L); //this has to be changed also Usermaximum
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, groupId);
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(account.getName(), groupId);
|
||||
addUserList(users, groupId);
|
||||
}
|
||||
|
||||
public boolean passIfLastAdmin(Account account, Long groupId){
|
||||
Group group = userService.getGroupById(groupId);
|
||||
if (group.getMembers().size() <= 1){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isLastAdmin(account, group)){
|
||||
String newAdminId = getVeteranMember(account, group);
|
||||
updateRole(newAdminId, groupId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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()))){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getVeteranMember(Account account, Group group){
|
||||
List<User> mitglieder = group.getMembers();
|
||||
if (mitglieder.get(0).getId().equals(account.getName())){
|
||||
return mitglieder.get(1).getId();
|
||||
}
|
||||
return mitglieder.get(0).getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
@ -66,11 +67,11 @@ public class GroupService {
|
||||
return groups.get(groupId);
|
||||
}
|
||||
|
||||
private List<Long> removeUserGroups(List<Long> groupIds, List<Long> userGroups) {
|
||||
for (Long groupId : userGroups) {
|
||||
groupIds.remove(groupId);
|
||||
private List<Group> removeUserGroups(List<Group> visibleGroups, List<Group> userGroups) {
|
||||
for (Group group : userGroups) {
|
||||
visibleGroups.remove(group);
|
||||
}
|
||||
return groupIds;
|
||||
return visibleGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,10 +82,18 @@ public class GroupService {
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Long> groupIds = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(userId));
|
||||
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(groupIds);
|
||||
List<Event> events = eventService.translateEventDTOs(eventDTOS);
|
||||
return projectEventList(events);
|
||||
User user = new User(userId,null, null, null);
|
||||
List<Event> eventsVisible = eventService.translateEventDTOs(eventRepository.findAllEventsOfGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE)));
|
||||
List<Group> visibleGroups = projectEventList(eventsVisible);
|
||||
List<Event> eventsUser = getGroupEvents(eventRepository.findGroup_idsWhereUser_id(userId));
|
||||
List<Group> groups = projectEventList(eventsUser);
|
||||
List<Group> newGroups = new ArrayList<>();
|
||||
for (Group group : groups) {
|
||||
if (group.getMembers().contains(user)) {
|
||||
newGroups.add(group);
|
||||
}
|
||||
}
|
||||
return removeUserGroups(visibleGroups, newGroups);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user