Merge remote-tracking branch 'origin/master' into group-invite-links
# Conflicts: # src/main/java/mops/gruppen2/controller/Gruppen2Controller.java # src/main/java/mops/gruppen2/repository/EventRepository.java # src/main/java/mops/gruppen2/service/ControllerService.java # src/main/java/mops/gruppen2/service/GroupService.java
This commit is contained in:
@ -4,6 +4,7 @@ import mops.gruppen2.config.Gruppen2Config;
|
|||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import mops.gruppen2.service.*;
|
import mops.gruppen2.service.*;
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
@ -55,7 +56,7 @@ public class Gruppen2Controller {
|
|||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("gruppen", userService.getUserGroups(user.getUser_id()));
|
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||||
model.addAttribute("user",user);
|
model.addAttribute("user",user);
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
@ -107,6 +108,15 @@ public class Gruppen2Controller {
|
|||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@PostMapping("/detailsBeitreten")
|
||||||
|
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||||
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal (token);
|
||||||
|
controllerService.addUser(account,id);
|
||||||
|
return "redirect:/gruppen2/";
|
||||||
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
@GetMapping("/detailsSearch")
|
@GetMapping("/detailsSearch")
|
||||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||||
@ -130,4 +140,11 @@ public class Gruppen2Controller {
|
|||||||
}
|
}
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
}
|
}
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@PostMapping("/leaveGroup")
|
||||||
|
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) {
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
|
controllerService.deleteUser(account, id);
|
||||||
|
return "redirect:/gruppen2/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
package mops.gruppen2.domain;
|
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import lombok.Getter;
|
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
|
||||||
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
|
||||||
import mops.gruppen2.domain.event.Event;
|
|
||||||
|
|
||||||
import javax.swing.table.TableRowSorter;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import static java.lang.String.format;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Repräsentiert viele Events als aggregiertes Objekt.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
public abstract class Aggregate {
|
|
||||||
|
|
||||||
protected long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ruft die spezifische applyEvent-Methode im entsprechenden Aggregat auf.
|
|
||||||
*
|
|
||||||
* @param event Event, welches aggregiert wird
|
|
||||||
*/
|
|
||||||
public void applyEvent(Event event) throws EventException {
|
|
||||||
try {
|
|
||||||
Method method = this.getClass().getDeclaredMethod("applyEvent", event.getClass());
|
|
||||||
method.setAccessible(true);
|
|
||||||
method.invoke(this, event);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
EventException f = (EventException) e.getTargetException();
|
|
||||||
throw f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
package mops.gruppen2.domain.Exceptions;
|
|
||||||
|
|
||||||
import mops.gruppen2.domain.event.Event;
|
|
||||||
|
|
||||||
public class GroupDoesNotExistException extends EventException {
|
|
||||||
public GroupDoesNotExistException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +1,9 @@
|
|||||||
package mops.gruppen2.domain;
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
||||||
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
@ -13,7 +15,10 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Getter
|
@Getter
|
||||||
public class Group extends Aggregate {
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Group {
|
||||||
|
private long id;
|
||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private final List<User> members;
|
private final List<User> members;
|
||||||
@ -28,58 +33,4 @@ public class Group extends Aggregate {
|
|||||||
this.roles = new HashMap<>();
|
this.roles = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyEvent(CreateGroupEvent event) {
|
|
||||||
id = event.getGroup_id();
|
|
||||||
visibility = event.getGroupVisibility();
|
|
||||||
parent = event.getGroupParent();
|
|
||||||
type = event.getGroupType();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyEvent(UpdateRoleEvent event) throws UserNotFoundException {
|
|
||||||
User user;
|
|
||||||
|
|
||||||
Optional<User> userOptional = members.stream()
|
|
||||||
.filter(u -> u.getUser_id().equals(event.getUser_id()))
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
if (userOptional.isPresent()) {
|
|
||||||
user = userOptional.get();
|
|
||||||
} else {
|
|
||||||
throw new UserNotFoundException("Nutzer wurde nicht gefunden!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (roles.containsKey(user) && event.getNewRole() == Role.MEMBER) {
|
|
||||||
roles.remove(user);
|
|
||||||
} else {
|
|
||||||
roles.put(user.getUser_id(), event.getNewRole());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyEvent(AddUserEvent event) throws UserAlreadyExistsException {
|
|
||||||
User user = new User(event.getUser_id(), event.getGivenname(), event.getFamilyname(), event.getEmail());
|
|
||||||
|
|
||||||
if (!this.members.contains(user)) {
|
|
||||||
this.members.add(user);
|
|
||||||
} else {
|
|
||||||
throw new UserAlreadyExistsException("Nutzer bereits in Gruppe vorhanden!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyEvent(UpdateGroupTitleEvent event) {
|
|
||||||
this.title = event.getNewGroupTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyEvent(UpdateGroupDescriptionEvent event) {
|
|
||||||
this.description = event.getNewGroupDescription();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyEvent(DeleteUserEvent event) throws UserNotFoundException {
|
|
||||||
User user = new User(event.getUser_id(), "", "", "");
|
|
||||||
|
|
||||||
if (this.members.contains(user)) {
|
|
||||||
this.members.remove(user);
|
|
||||||
} else {
|
|
||||||
throw new UserNotFoundException("Nutzer wurde nicht gefunden!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,10 @@ package mops.gruppen2.domain.event;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.Role;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,13 +20,6 @@ public class AddUserEvent extends Event {
|
|||||||
String familyname;
|
String familyname;
|
||||||
String email;
|
String email;
|
||||||
|
|
||||||
public AddUserEvent(Long event_id, Long group_id, String user_id, String givenname, String familyname, String email) {
|
|
||||||
super(event_id, group_id, user_id);
|
|
||||||
this.givenname = givenname;
|
|
||||||
this.familyname = familyname;
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddUserEvent(Long group_id, String user_id, String givenname, String familyname, String email) {
|
public AddUserEvent(Long group_id, String user_id, String givenname, String familyname, String email) {
|
||||||
super(group_id, user_id);
|
super(group_id, user_id);
|
||||||
this.givenname = givenname;
|
this.givenname = givenname;
|
||||||
@ -30,10 +27,14 @@ public class AddUserEvent extends Event {
|
|||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddUserEvent(Long event_id, Long group_id, User user) {
|
public void apply(Group group) throws EventException{
|
||||||
super(event_id, group_id, user.getUser_id());
|
User user = new User(this.user_id, this.givenname, this.familyname, this.email);
|
||||||
this.givenname = user.getGivenname();
|
|
||||||
this.familyname = user.getFamilyname();
|
if (group.getMembers().contains(user)){
|
||||||
this.email = user.getEmail();
|
throw new UserAlreadyExistsException("Der User existiert bereits");
|
||||||
|
}
|
||||||
|
|
||||||
|
group.getMembers().add(user);
|
||||||
|
group.getRoles().put(user_id, Role.MEMBER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package mops.gruppen2.domain.event;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
|
||||||
@ -14,10 +15,19 @@ public class CreateGroupEvent extends Event {
|
|||||||
private Long groupParent;
|
private Long groupParent;
|
||||||
private GroupType groupType;
|
private GroupType groupType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public CreateGroupEvent(Long group_id, String user_id, Long parent, GroupType type, Visibility visibility) {
|
public CreateGroupEvent(Long group_id, String user_id, Long parent, GroupType type, Visibility visibility) {
|
||||||
super(group_id, user_id);
|
super(group_id, user_id);
|
||||||
this.groupParent = parent;
|
this.groupParent = parent;
|
||||||
this.groupType = type;
|
this.groupType = type;
|
||||||
this.groupVisibility = visibility;
|
this.groupVisibility = visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void apply(Group group) {
|
||||||
|
group.setId(this.group_id);
|
||||||
|
group.setParent(this.groupParent);
|
||||||
|
group.setType(this.groupType);
|
||||||
|
group.setVisibility(this.groupVisibility);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,24 @@ package mops.gruppen2.domain.event;
|
|||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Value
|
@Value
|
||||||
public class DeleteGroupEvent extends Event {
|
public class DeleteGroupEvent extends Event {
|
||||||
|
|
||||||
public DeleteGroupEvent(long event_id, long group_id, String user_id) {
|
public DeleteGroupEvent(long group_id, String user_id) {
|
||||||
super(event_id, group_id, user_id);
|
super(group_id, user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Group group) {
|
||||||
|
group.getRoles().clear();
|
||||||
|
group.getMembers().clear();
|
||||||
|
group.setTitle(null);
|
||||||
|
group.setDescription(null);
|
||||||
|
group.setVisibility(null);
|
||||||
|
group.setType(null);
|
||||||
|
group.setParent(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,30 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
public class DeleteUserEvent extends Event {
|
public class DeleteUserEvent extends Event {
|
||||||
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
|
public DeleteUserEvent(Long group_id, String user_id) {
|
||||||
super(event_id, group_id, user_id);
|
super(group_id, user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeleteUserEvent() {}
|
public void apply(Group group) throws EventException {
|
||||||
|
for (User user : group.getMembers()) {
|
||||||
|
if (user.getUser_id().equals(this.user_id)) {
|
||||||
|
group.getMembers().remove(user);
|
||||||
|
group.getRoles().remove(user.getUser_id());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new UserNotFoundException("Der User existiert nicht");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,11 +6,13 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@JsonTypeInfo(
|
@JsonTypeInfo(
|
||||||
include = JsonTypeInfo.As.PROPERTY,
|
include = JsonTypeInfo.As.PROPERTY,
|
||||||
use = JsonTypeInfo.Id.NAME,
|
use = JsonTypeInfo.Id.NAME,
|
||||||
@ -26,13 +28,10 @@ import lombok.Setter;
|
|||||||
})
|
})
|
||||||
@Setter
|
@Setter
|
||||||
public class Event {
|
public class Event {
|
||||||
Long event_id;
|
|
||||||
Long group_id;
|
Long group_id;
|
||||||
String user_id;
|
String user_id;
|
||||||
|
|
||||||
|
|
||||||
public Event(Long group_id,String user_id){
|
public void apply(Group group) throws EventException {
|
||||||
this.group_id = group_id;
|
|
||||||
this.user_id = user_id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package mops.gruppen2.domain.event;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ändert nur die Gruppenbeschreibung.
|
* Ändert nur die Gruppenbeschreibung.
|
||||||
@ -13,13 +14,12 @@ import lombok.NoArgsConstructor;
|
|||||||
public class UpdateGroupDescriptionEvent extends Event {
|
public class UpdateGroupDescriptionEvent extends Event {
|
||||||
String newGroupDescription;
|
String newGroupDescription;
|
||||||
|
|
||||||
public UpdateGroupDescriptionEvent(Long event_id, Long group_id, String user_id, String newGroupDescription) {
|
|
||||||
super(event_id, group_id, user_id);
|
|
||||||
this.newGroupDescription = newGroupDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateGroupDescriptionEvent(Long group_id, String user_id, String newGroupDescription) {
|
public UpdateGroupDescriptionEvent(Long group_id, String user_id, String newGroupDescription) {
|
||||||
super(group_id, user_id);
|
super(group_id, user_id);
|
||||||
this.newGroupDescription = newGroupDescription;
|
this.newGroupDescription = newGroupDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void apply(Group group) {
|
||||||
|
group.setDescription(this.newGroupDescription);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package mops.gruppen2.domain.event;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ändert nur den Gruppentitel.
|
* Ändert nur den Gruppentitel.
|
||||||
@ -13,13 +14,13 @@ import lombok.NoArgsConstructor;
|
|||||||
public class UpdateGroupTitleEvent extends Event {
|
public class UpdateGroupTitleEvent extends Event {
|
||||||
String newGroupTitle;
|
String newGroupTitle;
|
||||||
|
|
||||||
public UpdateGroupTitleEvent(Long event_id, Long group_id, String user_id, String newGroupTitle) {
|
|
||||||
super(event_id, group_id, user_id);
|
|
||||||
this.newGroupTitle = newGroupTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateGroupTitleEvent(Long group_id, String user_id, String newGroupTitle) {
|
public UpdateGroupTitleEvent(Long group_id, String user_id, String newGroupTitle) {
|
||||||
super(group_id, user_id);
|
super(group_id, user_id);
|
||||||
this.newGroupTitle = newGroupTitle;
|
this.newGroupTitle = newGroupTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void apply(Group group) {
|
||||||
|
group.setTitle(this.newGroupTitle);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
package mops.gruppen2.domain.event;
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.Role;
|
import mops.gruppen2.domain.Role;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aktualisiert die Gruppenrolle eines Teilnehmers.
|
* Aktualisiert die Gruppenrolle eines Teilnehmers.
|
||||||
@ -13,14 +19,16 @@ public class UpdateRoleEvent extends Event {
|
|||||||
|
|
||||||
Role newRole;
|
Role newRole;
|
||||||
|
|
||||||
public UpdateRoleEvent(Long event_id, Long group_id, String user_id, Role newRole) {
|
|
||||||
super(event_id, group_id, user_id);
|
|
||||||
this.newRole = newRole;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
|
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
|
||||||
super(group_id, user_id);
|
super(group_id, user_id);
|
||||||
this.newRole = newRole;
|
this.newRole = newRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void apply(Group group) throws UserNotFoundException{
|
||||||
|
if (!group.getRoles().containsKey(user_id)){
|
||||||
|
throw new UserNotFoundException("Der User wurde nicht gefunden");
|
||||||
|
}
|
||||||
|
group.getRoles().put(this.user_id, this.newRole);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,8 +19,8 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
|||||||
//@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
|
//@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
|
||||||
//Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
//Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||||
|
|
||||||
@Query("select * from event where visibility =:vis")
|
@Query("select distinct group_id from event where visibility =:vis")
|
||||||
List<EventDTO> findEventDTOByVisibility(@Param("vis") Boolean visibility);
|
List<Long> findGroup_idsWhereVisibility(@Param("vis") Boolean visibility);
|
||||||
|
|
||||||
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
|
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
|
||||||
public List<Long> findNewEventSinceStatus(@Param("status") Long status);
|
public List<Long> findNewEventSinceStatus(@Param("status") Long status);
|
||||||
|
|||||||
@ -34,31 +34,51 @@ public class ControllerService {
|
|||||||
* @param description Gruppenbeschreibung
|
* @param description Gruppenbeschreibung
|
||||||
*/
|
*/
|
||||||
public void createGroup(Account account, String title, String description, Boolean visibility) {
|
public void createGroup(Account account, String title, String description, Boolean visibility) {
|
||||||
Long groupID = eventService.checkGroup();
|
Long group_id = eventService.checkGroup();
|
||||||
Visibility visibility1;
|
Visibility visibility1;
|
||||||
if (visibility) {
|
if (visibility) {
|
||||||
visibility1 = Visibility.PUBLIC;
|
visibility1 = Visibility.PUBLIC;
|
||||||
} else {
|
} else {
|
||||||
visibility1 = Visibility.PRIVATE;
|
visibility1 = Visibility.PRIVATE;
|
||||||
createInviteLink(groupID);
|
createInviteLink(group_id);
|
||||||
}
|
}
|
||||||
List<Event> eventList = new ArrayList<>();
|
|
||||||
Collections.addAll(eventList, new CreateGroupEvent(groupID, account.getName(), null, GroupType.LECTURE, visibility1),
|
|
||||||
new AddUserEvent(groupID, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()),
|
|
||||||
new UpdateRoleEvent(groupID, account.getName(), Role.ADMIN),
|
|
||||||
new UpdateGroupTitleEvent(groupID, account.getName(), title),
|
|
||||||
new UpdateGroupDescriptionEvent(groupID, account.getName(), description),
|
|
||||||
new UpdateRoleEvent(groupID, account.getName(), Role.ADMIN));
|
|
||||||
|
|
||||||
eventService.saveEventList(eventList);
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.LECTURE, visibility1);
|
||||||
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
|
||||||
|
addUser(account, group_id);
|
||||||
|
updateTitle(account, group_id, title);
|
||||||
|
updateDescription(account, group_id, description);
|
||||||
|
updateRole(account, group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createInviteLink(Long group_id) {
|
private void createInviteLink(Long group_id) {
|
||||||
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
|
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(Account account, Group group) {
|
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), group.getId(), account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
public void addUser(Account account, Long group_id){
|
||||||
|
AddUserEvent addUserEvent = new AddUserEvent(group_id,account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||||
eventService.saveEvent(addUserEvent);
|
eventService.saveEvent(addUserEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateTitle(Account account, Long group_id, String title){
|
||||||
|
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
|
||||||
|
eventService.saveEvent(updateGroupTitleEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDescription(Account account, Long group_id, String description){
|
||||||
|
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(group_id,account.getName(),description);
|
||||||
|
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateRole(Account account,Long group_id){
|
||||||
|
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(group_id,account.getName(),Role.ADMIN);
|
||||||
|
eventService.saveEvent(updateRoleEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteUser(Account account, Long group_id){
|
||||||
|
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
||||||
|
eventService.saveEvent(deleteUserEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.EventDTO;
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.dto.EventDTO;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -31,11 +32,10 @@ public class GroupService {
|
|||||||
*/
|
*/
|
||||||
public List<Event> getGroupEvents(List<Long> group_ids) {
|
public List<Event> getGroupEvents(List<Long> group_ids) {
|
||||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||||
List<Event> events = new ArrayList<>();
|
|
||||||
for (Long group_id: group_ids) {
|
for (Long group_id: group_ids) {
|
||||||
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id));
|
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id));
|
||||||
}
|
}
|
||||||
return events = eventService.translateEventDTOs(eventDTOS);
|
return eventService.translateEventDTOs(eventDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Erzeugt eine neue Map wo Gruppen aus den Events erzeugt und den Gruppen_ids zugeordnet werden.
|
/** Erzeugt eine neue Map wo Gruppen aus den Events erzeugt und den Gruppen_ids zugeordnet werden.
|
||||||
@ -49,7 +49,8 @@ public class GroupService {
|
|||||||
Map<Long, Group> groupMap = new HashMap<>();
|
Map<Long, Group> groupMap = new HashMap<>();
|
||||||
|
|
||||||
for (Event event : events) {
|
for (Event event : events) {
|
||||||
getOrCreateGroup(groupMap, event.getGroup_id()).applyEvent(event);
|
Group group = getOrCreateGroup(groupMap, event.getGroup_id());
|
||||||
|
event.apply(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<>(groupMap.values());
|
return new ArrayList<>(groupMap.values());
|
||||||
@ -76,8 +77,13 @@ public class GroupService {
|
|||||||
* @return
|
* @return
|
||||||
* @throws EventException
|
* @throws EventException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public List<Group> getAllGroupWithVisibilityPublic() throws EventException {
|
public List<Group> getAllGroupWithVisibilityPublic() throws EventException {
|
||||||
return projectEventList(eventService.translateEventDTOs(eventRepository.findEventDTOByVisibility(Boolean.TRUE)));
|
List<Long> group_ids = eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE);
|
||||||
|
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
|
||||||
|
List<Event> events = eventService.translateEventDTOs(eventDTOS);
|
||||||
|
List<Group> groups = projectEventList(events);
|
||||||
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +97,7 @@ public class GroupService {
|
|||||||
public List<Group> findGroupWith(String search) throws EventException {
|
public List<Group> findGroupWith(String search) throws EventException {
|
||||||
List<Group> groups = new ArrayList<>();
|
List<Group> groups = new ArrayList<>();
|
||||||
for (Group group: getAllGroupWithVisibilityPublic()) {
|
for (Group group: getAllGroupWithVisibilityPublic()) {
|
||||||
if (group.getTitle().contains(search)){
|
if (group.getTitle().contains(search)|| group.getDescription().contains(search)){
|
||||||
groups.add(group);
|
groups.add(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,14 @@ package mops.gruppen2.service;
|
|||||||
|
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
//Hallo
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
|
|
||||||
@ -22,10 +23,17 @@ public class UserService {
|
|||||||
|
|
||||||
//Test nötig??
|
//Test nötig??
|
||||||
|
|
||||||
public List<Group> getUserGroups(String user_id) throws EventException {
|
public List<Group> getUserGroups(User user) throws EventException {
|
||||||
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user_id);
|
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user.getUser_id());
|
||||||
List<Event> events = groupService.getGroupEvents(group_ids);
|
List<Event> events = groupService.getGroupEvents(group_ids);
|
||||||
return groupService.projectEventList(events);
|
List<Group> groups = groupService.projectEventList(events);
|
||||||
|
List<Group> newGroups = new ArrayList<>();
|
||||||
|
for (Group group: groups) {
|
||||||
|
if(group.getMembers().contains(user)){
|
||||||
|
newGroups.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group getGroupById(Long group_id) throws EventException {
|
public Group getGroupById(Long group_id) throws EventException {
|
||||||
|
|||||||
@ -27,8 +27,9 @@
|
|||||||
<main th:fragment="bodycontent">
|
<main th:fragment="bodycontent">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-9" style="border: 10px solid aliceblue; background: aliceblue">
|
|
||||||
<form action="/" method="get">
|
<div class="col-9">
|
||||||
|
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
||||||
<p style="font-weight: bold">
|
<p style="font-weight: bold">
|
||||||
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if="${group.getVisibility() == group.getVisibility().PRIVATE }">Private Gruppe</span>
|
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if="${group.getVisibility() == group.getVisibility().PRIVATE }">Private Gruppe</span>
|
||||||
@ -38,12 +39,13 @@
|
|||||||
<p th:text="${group.getDescription()}"></p>
|
<p th:text="${group.getDescription()}"></p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<button class="btn btn-danger" type="danger" style="border-style: none;">Gruppe verlassen</button>
|
<form method="post" action="/gruppen2/leaveGroup">
|
||||||
</div>
|
<button th:value="${group.getId()}" th:name="group_id" class="btn btn-danger" type="submit" style="border-style: none;">Gruppe verlassen</button>
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="col-3" style="white-space: nowrap">
|
<div class="col-3" style="white-space: nowrap">
|
||||||
<div>
|
<div>
|
||||||
<h2 style="display: inline-block; margin: 0">Mitglieder</h2>
|
<h2 style="display: inline-block; margin: 0">Mitglieder</h2>
|
||||||
|
|||||||
@ -27,8 +27,8 @@
|
|||||||
<main th:fragment="bodycontent">
|
<main th:fragment="bodycontent">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-9" style="border: 10px solid aliceblue; background: aliceblue">
|
<div class="col-9">
|
||||||
<form action="/" method="get">
|
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
||||||
<p style="font-weight: bold">
|
<p style="font-weight: bold">
|
||||||
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if="${group.getVisibility() == group.getVisibility().PRIVATE }">Private Gruppe</span>
|
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if="${group.getVisibility() == group.getVisibility().PRIVATE }">Private Gruppe</span>
|
||||||
@ -38,13 +38,15 @@
|
|||||||
<p th:text="${group.getDescription()}"></p>
|
<p th:text="${group.getDescription()}"></p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<button class="btn btn-primary" style="border-style: none;">Gruppe beitreten</button>
|
<form method="post" action="/gruppen2/detailsBeitreten">
|
||||||
</div>
|
<button type="submit" th:href="@{/gruppen2/detailsBeitreten(id=${group.getId()})}" th:name="id" th:value="${group.id}" class="btn btn-primary" style="border-style: none;">Gruppe beitreten</button>
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -31,10 +31,11 @@
|
|||||||
<h1>Meine Gruppen</h1>
|
<h1>Meine Gruppen</h1>
|
||||||
<form action="/" method="get">
|
<form action="/" method="get">
|
||||||
<div th:each="gruppe: ${gruppen}">
|
<div th:each="gruppe: ${gruppen}">
|
||||||
<div class="shadow-sm p-4" style="border: 1px solid white; background: white">
|
<div class="shadow-sm p-4" style="border: none; background: aliceblue">
|
||||||
<h3 style="color: dodgerblue; font-weight: bold;">
|
<h3 style="color: dodgerblue; font-weight: bold;">
|
||||||
<a th:href="@{/gruppen2/details(id=${gruppe.getId()})}" th:text="${gruppe.getTitle()}"></a>
|
<a th:href="@{/gruppen2/details(id=${gruppe.getId()})}" th:text="${gruppe.getTitle()}"></a>
|
||||||
</h3>
|
</h3>
|
||||||
|
<p th:text="${gruppe.getDescription()}"></p>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -73,7 +73,6 @@ public class EventBuilder {
|
|||||||
String lastname = faker.name().lastName();
|
String lastname = faker.name().lastName();
|
||||||
|
|
||||||
return new AddUserEvent(
|
return new AddUserEvent(
|
||||||
faker.random().nextLong(),
|
|
||||||
group_id,
|
group_id,
|
||||||
user_id,
|
user_id,
|
||||||
firstname,
|
firstname,
|
||||||
@ -103,7 +102,6 @@ public class EventBuilder {
|
|||||||
Faker faker = new Faker();
|
Faker faker = new Faker();
|
||||||
|
|
||||||
return new DeleteUserEvent(
|
return new DeleteUserEvent(
|
||||||
faker.random().nextLong(),
|
|
||||||
group_id,
|
group_id,
|
||||||
user_id
|
user_id
|
||||||
);
|
);
|
||||||
@ -129,7 +127,6 @@ public class EventBuilder {
|
|||||||
Faker faker = new Faker();
|
Faker faker = new Faker();
|
||||||
|
|
||||||
return new UpdateGroupDescriptionEvent(
|
return new UpdateGroupDescriptionEvent(
|
||||||
faker.random().nextLong(),
|
|
||||||
group_id,
|
group_id,
|
||||||
faker.random().hex(),
|
faker.random().hex(),
|
||||||
faker.leagueOfLegends().quote()
|
faker.leagueOfLegends().quote()
|
||||||
@ -140,7 +137,6 @@ public class EventBuilder {
|
|||||||
Faker faker = new Faker();
|
Faker faker = new Faker();
|
||||||
|
|
||||||
return new UpdateGroupTitleEvent(
|
return new UpdateGroupTitleEvent(
|
||||||
faker.random().nextLong(),
|
|
||||||
group_id,
|
group_id,
|
||||||
faker.random().hex(),
|
faker.random().hex(),
|
||||||
faker.leagueOfLegends().champion()
|
faker.leagueOfLegends().champion()
|
||||||
@ -151,7 +147,6 @@ public class EventBuilder {
|
|||||||
Faker faker = new Faker();
|
Faker faker = new Faker();
|
||||||
|
|
||||||
return new UpdateRoleEvent(
|
return new UpdateRoleEvent(
|
||||||
faker.random().nextLong(),
|
|
||||||
group_id,
|
group_id,
|
||||||
user_id,
|
user_id,
|
||||||
role
|
role
|
||||||
|
|||||||
@ -5,14 +5,16 @@ import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
|||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
class GroupTest {
|
|
||||||
|
|
||||||
|
class GroupTest {
|
||||||
|
/*
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
}
|
}
|
||||||
@ -148,5 +150,5 @@ class GroupTest {
|
|||||||
group.applyEvent(updateGroupDescriptionEvent);
|
group.applyEvent(updateGroupDescriptionEvent);
|
||||||
|
|
||||||
assertThat("Tolle Beschreibung").isEqualTo("Tolle Beschreibung");
|
assertThat("Tolle Beschreibung").isEqualTo("Tolle Beschreibung");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static mops.gruppen2.domain.Role.MEMBER;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class AddUserEventTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void userAllreadyExistExeption() throws EventException {
|
||||||
|
Group group = new Group();
|
||||||
|
|
||||||
|
User user = new User("user1","Stein", "Speck", "@sdasd");
|
||||||
|
|
||||||
|
group.getMembers().add(user);
|
||||||
|
|
||||||
|
Event event1 = new AddUserEvent(4L, "user2", "Rock", "Roll", "and");
|
||||||
|
event1.apply(group);
|
||||||
|
|
||||||
|
Event event2 = new AddUserEvent(4L, "user1", "Rock", "Roll", "and");
|
||||||
|
|
||||||
|
assertThrows(UserAlreadyExistsException.class, ()->
|
||||||
|
event2.apply(group)
|
||||||
|
);
|
||||||
|
assertThat(group.getMembers().size()).isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
|
||||||
|
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static mops.gruppen2.domain.Role.MEMBER;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class DeleteUserEventTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applyDeleteUser() throws EventException {
|
||||||
|
Group group = new Group();
|
||||||
|
|
||||||
|
User user = new User("user1","Stein", "Speck", "@sdasd");
|
||||||
|
|
||||||
|
group.getMembers().add(user);
|
||||||
|
group.getRoles().put("user1", MEMBER);
|
||||||
|
|
||||||
|
User user2 = new User("user2","Rock", "Roll", "and");
|
||||||
|
|
||||||
|
group.getMembers().add(user2);
|
||||||
|
group.getRoles().put("user2", MEMBER);
|
||||||
|
|
||||||
|
Event event = new DeleteUserEvent(1L, "user1");
|
||||||
|
|
||||||
|
event.apply(group);
|
||||||
|
|
||||||
|
assertThat(group.getMembers().size()).isEqualTo(1);
|
||||||
|
assertThat(group.getRoles().size()).isEqualTo(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void userDoesNotExistExeption() {
|
||||||
|
Group group = new Group();
|
||||||
|
|
||||||
|
User user = new User("user1","Stein", "Speck", "@sdasd");
|
||||||
|
|
||||||
|
group.getMembers().add(user);
|
||||||
|
group.getRoles().put("user1", MEMBER);
|
||||||
|
|
||||||
|
Event event = new DeleteUserEvent(17L,"user5");
|
||||||
|
|
||||||
|
assertThrows(UserNotFoundException.class, ()->
|
||||||
|
event.apply(group)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThat(group.getMembers().size()).isEqualTo(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
@ -29,36 +28,6 @@ class GroupServiceTest {
|
|||||||
groupService = new GroupService(mock(EventService.class), eventRepository);
|
groupService = new GroupService(mock(EventService.class), eventRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
|
||||||
void applyEventOnGroupThatIsDeleted() throws Exception {
|
|
||||||
List<Event> eventList = new ArrayList<>();
|
|
||||||
|
|
||||||
eventList.add(new CreateGroupEvent(1L,"Ulli", null, GroupType.LECTURE, Visibility.PRIVATE));
|
|
||||||
|
|
||||||
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
|
||||||
|
|
||||||
eventList.add(new AddUserEvent(900L, 10L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
|
||||||
|
|
||||||
|
|
||||||
Assertions.assertThrows(GroupDoesNotExistException.class, () -> {
|
|
||||||
groupService.projectEventList(eventList);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
|
||||||
void returnDeletedGroup() throws Exception {
|
|
||||||
List<Event> eventList = new ArrayList<>();
|
|
||||||
|
|
||||||
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE));
|
|
||||||
|
|
||||||
eventList.add(new DeleteGroupEvent(44, 1L, "loescher78"));
|
|
||||||
|
|
||||||
List<Group> list = new ArrayList<>();
|
|
||||||
|
|
||||||
assertThat(groupService.projectEventList(eventList)).isEqualTo(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void rightClassForSucsessfulGroup() throws Exception {
|
void rightClassForSucsessfulGroup() throws Exception {
|
||||||
@ -66,7 +35,7 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE));
|
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE));
|
||||||
|
|
||||||
eventList.add(new AddUserEvent(900L, 1L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
eventList.add(new AddUserEvent(1L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
||||||
|
|
||||||
assertThat(groupService.projectEventList(eventList).get(0)).isInstanceOf(Group.class);
|
assertThat(groupService.projectEventList(eventList).get(0)).isInstanceOf(Group.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,65 +23,8 @@ class SerializationServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void serializeEventTest() throws JsonProcessingException {
|
void serializeEventTest() throws JsonProcessingException {
|
||||||
Event event = new Event(1L,1L,"1");
|
Event event = new Event(1L,"1");
|
||||||
|
|
||||||
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"Event\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}");
|
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"Event\",\"group_id\":1,\"user_id\":\"1\"}");
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deserializeAddUserEventToRightClass() throws JsonProcessingException {
|
|
||||||
String json = "{\"type\":\"AddUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
|
||||||
|
|
||||||
Event event = serializationService.deserializeEvent(json);
|
|
||||||
|
|
||||||
assertThat(event).isInstanceOf(AddUserEvent.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deserializeDeleteUserEventToRightClass() throws JsonProcessingException {
|
|
||||||
String json = "{\"type\":\"DeleteUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
|
||||||
|
|
||||||
Event event = serializationService.deserializeEvent(json);
|
|
||||||
|
|
||||||
assertThat(event).isInstanceOf(DeleteUserEvent.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deserializeUpdateGroupDescriptionEventToRightClass() throws JsonProcessingException {
|
|
||||||
String json = "{\"type\":\"UpdateGroupDescriptionEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\",\"newGroupDescription\":\"test\"}";
|
|
||||||
|
|
||||||
Event event = serializationService.deserializeEvent(json);
|
|
||||||
|
|
||||||
assertThat(event).isInstanceOf(UpdateGroupDescriptionEvent.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deserializeUpdateGroupTitleEventToRightClass() throws JsonProcessingException {
|
|
||||||
String json = "{\"type\":\"UpdateGroupTitleEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\",\"newGroupTitle\":\"test\"}";
|
|
||||||
|
|
||||||
Event event = serializationService.deserializeEvent(json);
|
|
||||||
|
|
||||||
assertThat(event).isInstanceOf(UpdateGroupTitleEvent.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deserializeUpdateRoleEventToRightClass() throws JsonProcessingException {
|
|
||||||
System.out.println(serializationService.serializeEvent(new UpdateRoleEvent(1L, 1L, "1", Role.ADMIN)));
|
|
||||||
|
|
||||||
String json = "{\"type\":\"UpdateRoleEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":1,\"newRole\":\"ADMIN\"}";
|
|
||||||
|
|
||||||
Event event = serializationService.deserializeEvent(json);
|
|
||||||
|
|
||||||
assertThat(event).isInstanceOf(UpdateRoleEvent.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
|
||||||
void deserializeCreateGroupEventToRightClass() throws JsonProcessingException {
|
|
||||||
String json = "{\"type\":\"CreateGroupEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\",\"type\":\"test\",\"visibility\":\"test\"}";
|
|
||||||
|
|
||||||
Event event = serializationService.deserializeEvent(json);
|
|
||||||
|
|
||||||
assertThat(event).isInstanceOf(CreateGroupEvent.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user