1

Fix Checkstyle Errors :(

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-18 23:17:57 +01:00
parent 08717611d5
commit a05ffe9e4c
33 changed files with 260 additions and 269 deletions

View File

@ -16,7 +16,7 @@
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
--> -->
<module name = "Checker"> <module name="Checker">
<property name="charset" value="UTF-8"/> <property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/> <property name="severity" value="warning"/>
@ -30,7 +30,7 @@
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter --> <!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter"> <module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.google.suppressionfilter.config}" <property name="file" value="${org.checkstyle.google.suppressionfilter.config}"
default="checkstyle-suppressions.xml" /> default="checkstyle-suppressions.xml"/>
<property name="optional" value="true"/> <property name="optional" value="true"/>
</module> </module>
@ -40,13 +40,15 @@
<property name="eachLine" value="true"/> <property name="eachLine" value="true"/>
</module> </module>
<module name="LineLength"> <!-- <module name="LineLength">-->
<property name="fileExtensions" value="java"/> <!-- <property name="fileExtensions" value="java"/>-->
<property name="max" value="100"/> <!-- <property name="max" value="100"/>-->
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> <!-- <property name="ignorePattern"-->
</module> <!-- value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>-->
<!-- </module>-->
<module name="TreeWalker"> <module name="TreeWalker">
<module name="SuppressWarningsHolder"/>
<module name="OuterTypeFilename"/> <module name="OuterTypeFilename"/>
<module name="IllegalTokenText"> <module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/> <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
@ -234,7 +236,7 @@
<module name="MethodParamPad"> <module name="MethodParamPad">
<property name="tokens" <property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/> SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
</module> </module>
<module name="NoWhitespaceBefore"> <module name="NoWhitespaceBefore">
<property name="tokens" <property name="tokens"
@ -244,15 +246,15 @@
<module name="ParenPad"> <module name="ParenPad">
<property name="tokens" <property name="tokens"
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF, value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL,
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/> METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/>
</module> </module>
<module name="OperatorWrap"> <module name="OperatorWrap">
<property name="option" value="NL"/> <property name="option" value="NL"/>
<property name="tokens" <property name="tokens"
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/> LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
</module> </module>
<module name="AnnotationLocation"> <module name="AnnotationLocation">
<property name="id" value="AnnotationLocationMostCases"/> <property name="id" value="AnnotationLocationMostCases"/>
@ -284,14 +286,14 @@
<property name="allowedAnnotations" value="Override, Test"/> <property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/> <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
</module> </module>
<module name="MissingJavadocMethod"> <!-- <module name="MissingJavadocMethod">-->
<property name="scope" value="public"/> <!-- <property name="scope" value="public"/>-->
<property name="minLineCount" value="2"/> <!-- <property name="minLineCount" value="2"/>-->
<property name="allowedAnnotations" value="Override, Test"/> <!-- <property name="allowedAnnotations" value="Override, Test"/>-->
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/> <!-- <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>-->
</module> <!-- </module>-->
<module name="MethodName"> <module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/> <property name="format" value="^[a-z][a-zA-Z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern" <message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/> value="Method name ''{0}'' must match pattern ''{1}''."/>
</module> </module>
@ -307,7 +309,7 @@
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter --> <!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter"> <module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}" <property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml" /> default="checkstyle-xpath-suppressions.xml"/>
<property name="optional" value="true"/> <property name="optional" value="true"/>
</module> </module>
</module> </module>

View File

@ -54,8 +54,8 @@ public class APIController {
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück") @ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException { public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException {
List<Event> eventList = eventService.getEventsOfGroup(groupId); List<Event> eventList = eventService.getEventsOfGroup(groupId);
List<Group> groups = groupService.projectEventList(eventList); List<Group> groups = groupService.projectEventList(eventList);
return groups.get(0); return groups.get(0);
} }

View File

@ -98,14 +98,14 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/details/members/addUsersFromCsv") @PostMapping("/details/members/addUsersFromCsv")
public String addUsersFromCsv(@RequestParam("group_id") Long group_id, public String addUsersFromCsv(@RequestParam("group_id") Long groupId,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException { @RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
List<User> userList = new ArrayList<>(); List<User> userList = new ArrayList<>();
if (!file.isEmpty()) { if (!file.isEmpty()) {
userList = CsvService.read(file.getInputStream()); userList = CsvService.read(file.getInputStream());
} }
controllerService.addUserList(userList, group_id); controllerService.addUserList(userList, groupId);
return "redirect:/gruppen2/details/members/" + group_id; return "redirect:/gruppen2/details/members/" + groupId;
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@ -117,11 +117,11 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/findGroup") @GetMapping("/findGroup")
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException { public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
List<Group> groupse = new ArrayList<>(); List<Group> groupse = new ArrayList<>();
if (suchbegriff != null) { if (search != null) {
groupse = groupService.findGroupWith(suchbegriff, account); groupse = groupService.findGroupWith(search, account);
} }
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("gruppen", groupse); model.addAttribute("gruppen", groupse);
@ -144,10 +144,10 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/{id}") @GetMapping("/details/{id}")
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long id) throws EventException, ResponseStatusException { public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) throws EventException, ResponseStatusException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id); Group group = userService.getGroupById(groupId);
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
if (group != null) { if (group != null) {
@ -162,23 +162,23 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten") @PostMapping("/detailsBeitreten")
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long id) throws EventException { public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(id); Group group = userService.getGroupById(groupId);
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
return "errorRenameLater"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden return "errorRenameLater"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
} }
controllerService.addUser(account, id); controllerService.addUser(account, groupId);
return "redirect:/gruppen2/"; 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("id") Long id) throws EventException { public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id); Group group = userService.getGroupById(groupId);
if (group != null) { if (group != null) {
model.addAttribute("group", group); model.addAttribute("group", group);
return "detailsNoMember"; return "detailsNoMember";
@ -200,18 +200,18 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup") @PostMapping("/leaveGroup")
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long id) throws EventException { public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
controllerService.deleteUser(user.getUser_id(), id); controllerService.deleteUser(user.getId(), groupId);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/members/{id}") @GetMapping("/details/members/{id}")
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable("id") Long id) throws EventException { public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable("id") Long groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(id); Group group = userService.getGroupById(groupId);
if (group.getRoles().get(account.getName()) == Role.ADMIN) { if (group.getRoles().get(account.getName()) == Role.ADMIN) {
model.addAttribute("account", account); model.addAttribute("account", account);
model.addAttribute("members", group.getMembers()); model.addAttribute("members", group.getMembers());
@ -225,17 +225,17 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeRole") @PostMapping("/details/members/changeRole")
public String changeRole(KeycloakAuthenticationToken token, @RequestParam("group_id") Long group_id, public String changeRole(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId,
@RequestParam("user_id") String user_id) throws EventException { @RequestParam("user_id") String userId) throws EventException {
controllerService.updateRole(user_id, group_id); controllerService.updateRole(userId, groupId);
return "redirect:/gruppen2/details/members/" + group_id; return "redirect:/gruppen2/details/members/" + groupId;
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser") @PostMapping("/details/members/deleteUser")
public String deleteUser(KeycloakAuthenticationToken token, @RequestParam("group_id") Long group_id, public String deleteUser(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId,
@RequestParam("user_id") String user_id) throws EventException { @RequestParam("user_id") String userId) throws EventException {
controllerService.deleteUser(user_id, group_id); controllerService.deleteUser(userId, groupId);
return "redirect:/gruppen2/details/members/" + group_id; return "redirect:/gruppen2/details/members/" + groupId;
} }
} }

View File

@ -9,7 +9,7 @@ import lombok.Getter;
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"}) @EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
public class User { public class User {
private final String user_id; private final String id;
private final String givenname; private final String givenname;
private final String familyname; private final String familyname;
private final String email; private final String email;

View File

@ -6,7 +6,7 @@ import mops.gruppen2.domain.Group;
import java.util.List; import java.util.List;
/** /**
* Kombiniert den Status und die Gruppenliste zur ausgabe über die API * Kombiniert den Status und die Gruppenliste zur ausgabe über die API.
*/ */
@AllArgsConstructor @AllArgsConstructor
public class GroupRequestWrapper { public class GroupRequestWrapper {

View File

@ -4,6 +4,7 @@ import lombok.Value;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.relational.core.mapping.Table;
@SuppressWarnings("checkstyle:membername")
@Table("invite") @Table("invite")
@Value @Value
public class InviteLinkDTO { public class InviteLinkDTO {

View File

@ -21,21 +21,22 @@ public class AddUserEvent extends Event {
private String familyname; private String familyname;
private String email; private String email;
public AddUserEvent(Long group_id, String user_id, String givenname, String familyname, String email) { public AddUserEvent(Long groupId, String userId, String givenname, String familyname, String email) {
super(group_id, user_id); super(groupId, userId);
this.givenname = givenname; this.givenname = givenname;
this.familyname = familyname; this.familyname = familyname;
this.email = email; this.email = email;
} }
@Override
public void apply(Group group) throws EventException { public void apply(Group group) throws EventException {
User user = new User(this.user_id, this.givenname, this.familyname, this.email); User user = new User(this.userId, this.givenname, this.familyname, this.email);
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
throw new UserAlreadyExistsException("Der User existiert bereits"); throw new UserAlreadyExistsException("Der User existiert bereits");
} }
group.getMembers().add(user); group.getMembers().add(user);
group.getRoles().put(user_id, Role.MEMBER); group.getRoles().put(userId, Role.MEMBER);
} }
} }

View File

@ -16,15 +16,16 @@ 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 groupId, String userId, Long parent, GroupType type, Visibility visibility) {
super(group_id, user_id); super(groupId, userId);
this.groupParent = parent; this.groupParent = parent;
this.groupType = type; this.groupType = type;
this.groupVisibility = visibility; this.groupVisibility = visibility;
} }
@Override
public void apply(Group group) { public void apply(Group group) {
group.setId(this.group_id); group.setId(this.groupId);
group.setParent(this.groupParent); group.setParent(this.groupParent);
group.setType(this.groupType); group.setType(this.groupType);
group.setVisibility(this.groupVisibility); group.setVisibility(this.groupVisibility);

View File

@ -8,8 +8,8 @@ import mops.gruppen2.domain.Group;
@NoArgsConstructor // For Jackson @NoArgsConstructor // For Jackson
public class DeleteGroupEvent extends Event { public class DeleteGroupEvent extends Event {
public DeleteGroupEvent(long group_id, String user_id) { public DeleteGroupEvent(Long groupId, String userId) {
super(group_id, user_id); super(groupId, userId);
} }
@Override @Override

View File

@ -14,15 +14,16 @@ import mops.gruppen2.domain.exception.UserNotFoundException;
@NoArgsConstructor // For Jackson @NoArgsConstructor // For Jackson
public class DeleteUserEvent extends Event { public class DeleteUserEvent extends Event {
public DeleteUserEvent(Long group_id, String user_id) { public DeleteUserEvent(Long groupId, String userId) {
super(group_id, user_id); super(groupId, userId);
} }
@Override
public void apply(Group group) throws EventException { public void apply(Group group) throws EventException {
for (User user : group.getMembers()) { for (User user : group.getMembers()) {
if (user.getUser_id().equals(this.user_id)) { if (user.getId().equals(this.userId)) {
group.getMembers().remove(user); group.getMembers().remove(user);
group.getRoles().remove(user.getUser_id()); group.getRoles().remove(user.getId());
return; return;
} }
} }

View File

@ -27,8 +27,8 @@ import mops.gruppen2.domain.exception.EventException;
@AllArgsConstructor @AllArgsConstructor
public class Event { public class Event {
protected Long group_id; protected Long groupId;
protected String user_id; protected String userId;
public void apply(Group group) throws EventException {} public void apply(Group group) throws EventException {}
} }

View File

@ -15,11 +15,12 @@ public class UpdateGroupDescriptionEvent extends Event {
private String newGroupDescription; private String newGroupDescription;
public UpdateGroupDescriptionEvent(Long group_id, String user_id, String newGroupDescription) { public UpdateGroupDescriptionEvent(Long groupId, String userId, String newGroupDescription) {
super(group_id, user_id); super(groupId, userId);
this.newGroupDescription = newGroupDescription; this.newGroupDescription = newGroupDescription;
} }
@Override
public void apply(Group group) { public void apply(Group group) {
group.setDescription(this.newGroupDescription); group.setDescription(this.newGroupDescription);
} }

View File

@ -15,11 +15,12 @@ public class UpdateGroupTitleEvent extends Event {
private String newGroupTitle; private String newGroupTitle;
public UpdateGroupTitleEvent(Long group_id, String user_id, String newGroupTitle) { public UpdateGroupTitleEvent(Long groupId, String userId, String newGroupTitle) {
super(group_id, user_id); super(groupId, userId);
this.newGroupTitle = newGroupTitle; this.newGroupTitle = newGroupTitle;
} }
@Override
public void apply(Group group) { public void apply(Group group) {
group.setTitle(this.newGroupTitle); group.setTitle(this.newGroupTitle);
} }

View File

@ -17,16 +17,17 @@ public class UpdateRoleEvent extends Event {
private Role newRole; private Role newRole;
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) { public UpdateRoleEvent(Long groupId, String userId, Role newRole) {
super(group_id, user_id); super(groupId, userId);
this.newRole = newRole; this.newRole = newRole;
} }
@Override
public void apply(Group group) throws UserNotFoundException { public void apply(Group group) throws UserNotFoundException {
if (!group.getRoles().containsKey(user_id)) { if (!group.getRoles().containsKey(userId)) {
throw new UserNotFoundException("Der User wurde nicht gefunden"); throw new UserNotFoundException("Der User wurde nicht gefunden");
} }
group.getRoles().put(this.user_id, this.newRole); group.getRoles().put(this.userId, this.newRole);
} }
} }

View File

@ -12,10 +12,10 @@ import java.util.List;
public interface EventRepository extends CrudRepository<EventDTO, Long> { public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("select distinct group_id from event where user_id =:id") @Query("select distinct group_id from event where user_id =:id")
List<Long> findGroup_idsWhereUser_id(@Param("id") String user_id); List<Long> findGroup_idsWhereUser_id(@Param("id") String userId);
@Query("select * from event where group_id =:id") @Query("select * from event where group_id =:id")
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long group_id); List<EventDTO> findEventDTOByGroup_id(@Param("id") Long groupId);
//@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);

View File

@ -9,7 +9,7 @@ import java.util.List;
@Service @Service
public class APIFormatterService { public class APIFormatterService {
static public GroupRequestWrapper wrap(Long status, List<Group> groupList) { public static GroupRequestWrapper wrap(Long status, List<Group> groupList) {
return new GroupRequestWrapper(status, groupList); return new GroupRequestWrapper(status, groupList);
} }
} }

View File

@ -35,91 +35,90 @@ public class ControllerService {
public void createGroup(Account account, String title, String description, Boolean visibility) throws EventException { public void createGroup(Account account, String title, String description, Boolean visibility) throws EventException {
Visibility visibility1; Visibility visibility1;
Long group_id = eventService.checkGroup(); Long groupId = eventService.checkGroup();
if (visibility) { if (visibility) {
visibility1 = Visibility.PUBLIC; visibility1 = Visibility.PUBLIC;
} else { } else {
visibility1 = Visibility.PRIVATE; visibility1 = Visibility.PRIVATE;
createInviteLink(group_id); createInviteLink(groupId);
} }
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.SIMPLE, visibility1); CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1);
eventService.saveEvent(createGroupEvent); eventService.saveEvent(createGroupEvent);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
addUser(account, group_id); addUser(account, groupId);
updateTitle(account, group_id, title); updateTitle(account, groupId, title);
updateDescription(account, group_id, description); updateDescription(account, groupId, description);
updateRole(user.getUser_id(), group_id); updateRole(account.getName(), groupId);
} }
private void createInviteLink(Long group_id) { private void createInviteLink(Long groupId) {
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID()); inviteLinkRepositoryService.saveInvite(groupId, UUID.randomUUID());
} }
public void addUser(Account account, Long group_id) { public void addUser(Account account, Long groupId) {
AddUserEvent addUserEvent = new AddUserEvent(group_id, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
eventService.saveEvent(addUserEvent); eventService.saveEvent(addUserEvent);
} }
public void addUserList(List<User> users, Long group_id) { public void addUserList(List<User> users, Long groupId) {
for (User user : users) { for (User user : users) {
AddUserEvent addUserEvent = new AddUserEvent(group_id, user.getUser_id(), user.getGivenname(), user.getFamilyname(), user.getEmail()); AddUserEvent addUserEvent = new AddUserEvent(groupId, user.getId(), user.getGivenname(), user.getFamilyname(), user.getEmail());
eventService.saveEvent(addUserEvent); eventService.saveEvent(addUserEvent);
} }
} }
public void updateTitle(Account account, Long group_id, String title) { public void updateTitle(Account account, Long groupId, String title) {
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id, account.getName(), title); UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
eventService.saveEvent(updateGroupTitleEvent); eventService.saveEvent(updateGroupTitleEvent);
} }
public void updateDescription(Account account, Long group_id, String description) { public void updateDescription(Account account, Long groupId, String description) {
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(group_id, account.getName(), description); UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
eventService.saveEvent(updateGroupDescriptionEvent); eventService.saveEvent(updateGroupDescriptionEvent);
} }
public void updateRole(String user_id, Long group_id) throws EventException { public void updateRole(String userId, Long groupId) throws EventException {
UpdateRoleEvent updateRoleEvent; UpdateRoleEvent updateRoleEvent;
Group group = userService.getGroupById(group_id); Group group = userService.getGroupById(groupId);
User user = null; User user = null;
for (User member : group.getMembers()) { for (User member : group.getMembers()) {
if (member.getUser_id().equals(user_id)) { if (member.getId().equals(userId)) {
user = member; user = member;
} }
} }
assert user != null; assert user != null;
if (group.getRoles().get(user.getUser_id()) == Role.ADMIN) { if (group.getRoles().get(user.getId()) == Role.ADMIN) {
updateRoleEvent = new UpdateRoleEvent(group_id, user.getUser_id(), Role.MEMBER); updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), Role.MEMBER);
} else { } else {
updateRoleEvent = new UpdateRoleEvent(group_id, user.getUser_id(), Role.ADMIN); updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), Role.ADMIN);
} }
eventService.saveEvent(updateRoleEvent); eventService.saveEvent(updateRoleEvent);
} }
public void deleteUser(String user_id, Long group_id) throws EventException { public void deleteUser(String userId, Long groupId) throws EventException {
Group group = userService.getGroupById(group_id); Group group = userService.getGroupById(groupId);
User user = null; User user = null;
for (User member : group.getMembers()) { for (User member : group.getMembers()) {
if (member.getUser_id().equals(user_id)) { if (member.getId().equals(userId)) {
user = member; user = member;
} }
} }
assert user != null; assert user != null;
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id, user.getUser_id()); DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
eventService.saveEvent(deleteUserEvent); eventService.saveEvent(deleteUserEvent);
} }
public void deleteGroupEvent(User user, Long group_id) { public void deleteGroupEvent(User user, Long groupId) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(group_id, user.getUser_id()); DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user.getId());
eventService.saveEvent(deleteGroupEvent); eventService.saveEvent(deleteGroupEvent);
} }
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) throws EventException { public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) throws EventException {
Visibility visibility1; Visibility visibility1;
Long group_id = eventService.checkGroup(); Long groupId = eventService.checkGroup();
if (visibility) { if (visibility) {
visibility1 = Visibility.PUBLIC; visibility1 = Visibility.PUBLIC;
@ -127,13 +126,13 @@ public class ControllerService {
visibility1 = Visibility.PRIVATE; visibility1 = Visibility.PRIVATE;
} }
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.LECTURE, visibility1); CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1);
eventService.saveEvent(createGroupEvent); eventService.saveEvent(createGroupEvent);
addUser(account, group_id); addUser(account, groupId);
updateTitle(account, group_id, title); updateTitle(account, groupId, title);
updateDescription(account, group_id, description); updateDescription(account, groupId, description);
updateRole(account.getName(), group_id); updateRole(account.getName(), groupId);
addUserList(users, group_id); addUserList(users, groupId);
} }
} }

View File

@ -23,9 +23,9 @@ public class EventService {
} }
/** /**
* sichert ein Event Objekt indem es ein EventDTO Objekt erzeugt * Erzeugt ein DTO aus einem Event und speicher es.
* *
* @param event * @param event Event, welches gespeichert wird
*/ */
public void saveEvent(Event event) { public void saveEvent(Event event) {
EventDTO eventDTO = getDTO(event); EventDTO eventDTO = getDTO(event);
@ -36,8 +36,8 @@ public class EventService {
* Erzeugt aus einem Event Objekt ein EventDTO Objekt. * Erzeugt aus einem Event Objekt ein EventDTO Objekt.
* Ist die Gruppe öffentlich, dann wird die visibility auf true gesetzt. * Ist die Gruppe öffentlich, dann wird die visibility auf true gesetzt.
* *
* @param event * @param event Event, welches in DTO übersetzt wird
* @return EventDTO * @return EventDTO Neues DTO
*/ */
public EventDTO getDTO(Event event) { public EventDTO getDTO(Event event) {
boolean visibility = false; boolean visibility = false;
@ -52,14 +52,14 @@ public class EventService {
e.printStackTrace(); e.printStackTrace();
} }
return new EventDTO(null, event.getGroup_id(), event.getUser_id(), payload, visibility); return new EventDTO(null, event.getGroupId(), event.getUserId(), payload, visibility);
} }
/** /**
* Gibt die nächst höhere groupID zurück die belegt werden kann. * Gibt die nächst höhere groupID zurück die belegt werden kann.
* Gibt 1 zurück, falls keine Gruppe vorhanden ist. * Gibt 1 zurück, falls keine Gruppe vorhanden ist.
* *
* @return Gibt Long zurück * @return Long GruppenId
*/ */
public Long checkGroup() { public Long checkGroup() {
Long maxGroupID = eventStore.getMaxGroupID(); Long maxGroupID = eventStore.getMaxGroupID();
@ -70,10 +70,10 @@ public class EventService {
} }
/** /**
* Findet alle Events welche ab dem neuen Status hinzugekommen sind * Findet alle Events welche ab dem neuen Status hinzugekommen sind.
* *
* @param status * @param status Die Id des zuletzt gespeicherten Events
* @return Liste von Events * @return Liste von neueren Events
*/ */
public List<Event> getNewEvents(Long status) { public List<Event> getNewEvents(Long status) {
List<Long> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status); List<Long> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
@ -83,9 +83,9 @@ public class EventService {
} }
/** /**
* Erzeugt aus einer Liste von eventDTOs eine Liste von Events * Erzeugt aus einer Liste von eventDTOs eine Liste von Events.
* *
* @param eventDTOS * @param eventDTOS Liste von DTOs
* @return Liste von Events * @return Liste von Events
*/ */
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS) { public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS) {
@ -102,12 +102,12 @@ public class EventService {
} }
/** /**
* Sichert eine Liste von Event Objekten mithilfe der Methode saveEvent(Event event) * Sichert eine Liste von Event Objekten mithilfe der Methode saveEvent(Event event).
* *
* @param createGroupEvents Liste von Event Objekten * @param eventList Liste von Event Objekten
*/ */
public void saveEventList(List<Event> createGroupEvents) { public void saveEventList(List<Event> eventList) {
for (Event event : createGroupEvents) { for (Event event : eventList) {
saveEvent(event); saveEvent(event);
} }
} }

View File

@ -28,13 +28,13 @@ public class GroupService {
* Sucht in der DB alle Zeilen raus welche eine der Gruppen_ids hat. * 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. * Wandelt die Zeilen in Events um und gibt davon eine Liste zurück.
* *
* @param group_ids * @param groupIds Liste an IDs
* @return * @return Liste an Events
*/ */
public List<Event> getGroupEvents(List<Long> group_ids) { public List<Event> getGroupEvents(List<Long> groupIds) {
List<EventDTO> eventDTOS = new ArrayList<>(); List<EventDTO> eventDTOS = new ArrayList<>();
for (Long group_id : group_ids) { for (Long groupId : groupIds) {
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id)); eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(groupId));
} }
return eventService.translateEventDTOs(eventDTOS); return eventService.translateEventDTOs(eventDTOS);
} }
@ -43,67 +43,58 @@ public class GroupService {
* 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.
* Die Gruppen werden als Liste zurückgegeben * Die Gruppen werden als Liste zurückgegeben
* *
* @param events * @param events Liste an Events
* @return * @return Liste an Projizierten Gruppen
* @throws EventException * @throws EventException Projektionsfehler
*/ */
public List<Group> projectEventList(List<Event> events) throws EventException { public List<Group> projectEventList(List<Event> events) throws EventException {
Map<Long, Group> groupMap = new HashMap<>(); Map<Long, Group> groupMap = new HashMap<>();
for (Event event : events) { for (Event event : events) {
Group group = getOrCreateGroup(groupMap, event.getGroup_id()); Group group = getOrCreateGroup(groupMap, event.getGroupId());
event.apply(group); event.apply(group);
} }
return new ArrayList<>(groupMap.values()); return new ArrayList<>(groupMap.values());
} }
/** private Group getOrCreateGroup(Map<Long, Group> groups, long groupId) {
* guckt in der Map anhand der Id nach ob die Gruppe schon in der Map vorhanden ist, wenn nicht wird eine neue if (!groups.containsKey(groupId)) {
* Gruppe erzeugt groups.put(groupId, new Group());
*
* @param groups
* @param group_id
* @return
*/
private Group getOrCreateGroup(Map<Long, Group> groups, long group_id) {
if (!groups.containsKey(group_id)) {
groups.put(group_id, new Group());
} }
return groups.get(group_id); return groups.get(groupId);
} }
private List<Long> removeUserGroups(List<Long> group_ids, List<Long> user_groups) { private List<Long> removeUserGroups(List<Long> groupIds, List<Long> userGroups) {
for (Long group_id : user_groups) { for (Long groupId : userGroups) {
group_ids.remove(group_id); groupIds.remove(groupId);
} }
return group_ids; return groupIds;
} }
/** /**
* sucht alle Zeilen in der DB wo die Visibility true ist und entfernt alle Gruppen des Users. * Sucht alle Zeilen in der DB mit visibility=true.
* Erstellt eine Liste aus Gruppen. * Erstellt eine Liste aus öffentlichen Gruppen (ohen bereits beigetretenen Gruppen).
* *
* @return * @return Liste von projizierten Gruppen
* @throws EventException * @throws EventException Projektionsfehler
*/ */
public List<Group> getAllGroupWithVisibilityPublic(String user_id) throws EventException { public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
List<Long> group_ids = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(user_id)); List<Long> groupIds = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(userId));
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids); List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(groupIds);
List<Event> events = eventService.translateEventDTOs(eventDTOS); List<Event> events = eventService.translateEventDTOs(eventDTOS);
List<Group> groups = projectEventList(events); return projectEventList(events);
return groups;
} }
/** /**
* Filtert alle öffentliche Gruppen nach dem suchbegriff und gibt diese als Liste von Gruppen zurück. * Filtert alle öffentliche Gruppen nach dem Suchbegriff und gibt diese als Liste von Gruppen zurück.
* Groß und kleinschreibung wird beachtet. * Groß und Kleinschreibung wird nicht beachtet.
* *
* @param search * @param search Der Suchstring
* @return * @return Liste von projizierten Gruppen
* @throws EventException * @throws EventException Projektionsfehler
*/ */
public List<Group> findGroupWith(String search, Account account) throws EventException { public List<Group> findGroupWith(String search, Account account) throws EventException {
List<Group> groups = new ArrayList<>(); List<Group> groups = new ArrayList<>();

View File

@ -19,8 +19,8 @@ public class InviteLinkRepositoryService {
return inviteLinkRepository.findGroupIdByLink(link); return inviteLinkRepository.findGroupIdByLink(link);
} }
public void saveInvite(Long group_id, UUID link) { public void saveInvite(Long groupId, UUID link) {
inviteLinkRepository.save(new InviteLinkDTO(null, group_id, link.toString())); inviteLinkRepository.save(new InviteLinkDTO(null, groupId, link.toString()));
} }
} }

View File

@ -16,7 +16,7 @@ public class JsonService {
* *
* @param event Java-Event-Repräsentation * @param event Java-Event-Repräsentation
* @return JSON-Event-Payload als String * @return JSON-Event-Payload als String
* @throws JsonProcessingException * @throws JsonProcessingException Bei JSON Fehler
*/ */
public String serializeEvent(Event event) throws JsonProcessingException { public String serializeEvent(Event event) throws JsonProcessingException {
@ -29,7 +29,7 @@ public class JsonService {
* *
* @param json JSON-Event-Payload als String * @param json JSON-Event-Payload als String
* @return Java-Event-Repräsentation * @return Java-Event-Repräsentation
* @throws JsonProcessingException * @throws JsonProcessingException Bei JSON Fehler
*/ */
public Event deserializeEvent(String json) throws JsonProcessingException { public Event deserializeEvent(String json) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();

View File

@ -25,8 +25,8 @@ public class UserService {
//Test nötig?? //Test nötig??
public List<Group> getUserGroups(User user) throws EventException { public List<Group> getUserGroups(User user) throws EventException {
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user.getUser_id()); List<Long> groupIds = eventRepository.findGroup_idsWhereUser_id(user.getId());
List<Event> events = groupService.getGroupEvents(group_ids); List<Event> events = groupService.getGroupEvents(groupIds);
List<Group> groups = groupService.projectEventList(events); List<Group> groups = groupService.projectEventList(events);
List<Group> newGroups = new ArrayList<>(); List<Group> newGroups = new ArrayList<>();
for (Group group : groups) { for (Group group : groups) {
@ -37,10 +37,10 @@ public class UserService {
return newGroups; return newGroups;
} }
public Group getGroupById(Long group_id) throws EventException { public Group getGroupById(Long groupId) throws EventException {
List<Long> group_ids = new ArrayList<>(); List<Long> groupIds = new ArrayList<>();
group_ids.add(group_id); groupIds.add(groupId);
List<Event> events = groupService.getGroupEvents(group_ids); List<Event> events = groupService.getGroupEvents(groupIds);
return groupService.projectEventList(events).get(0); return groupService.projectEventList(events).get(0);
} }
} }

View File

@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" <html lang="en"
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"> th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Gruppendetails</title> <title>Gruppendetails</title>
@ -13,16 +14,16 @@
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation"> <nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
<ul> <ul>
<li class="active"> <li class="active">
<a th:href="@{/gruppen2}" href="/">Gruppen</a> <a href="/" th:href="@{/gruppen2}">Gruppen</a>
</li> </li>
<li> <li>
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a> <a href="/createGroup" th:href="@{/gruppen2/createGroup}">Erstellen</a>
</li> </li>
<li> <li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a> <a href="/findGroup" th:href="@{/gruppen2/findGroup}">Suche</a>
</li> </li>
<li th:if="${account.getRoles().contains('orga')}"> <li th:if="${account.getRoles().contains('orga')}">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a> <a href="/createLecture" th:href="@{/gruppen2/createLecture}">Veranstaltung</a>
</li> </li>
</ul> </ul>
</nav> </nav>
@ -46,12 +47,12 @@
<p style="overflow-wrap: break-word" th:text="${group.getDescription()}"></p> <p style="overflow-wrap: break-word" th:text="${group.getDescription()}"></p>
</div> </div>
<br> <br>
<div class="text-right btn-toolbar" style="float: right" role="toolbar"> <div class="text-right btn-toolbar" role="toolbar" style="float: right">
<button class="btn btn-primary" <button class="btn btn-primary"
style="background: dodgerblue; border: none; margin: 5px"> style="background: dodgerblue; border: none; margin: 5px">
<a th:href="@{/gruppen2}" style="color: white">Zurück</a> <a style="color: white" th:href="@{/gruppen2}">Zurück</a>
</button> </button>
<form method="post" action="/gruppen2/leaveGroup"> <form action="/gruppen2/leaveGroup" method="post">
<button class="btn btn-danger" style="border-style: none; margin: 5px" <button class="btn btn-danger" style="border-style: none; margin: 5px"
th:name="group_id" th:value="${group.getId()}" th:name="group_id" th:value="${group.getId()}"
type="submit">Gruppe verlassen type="submit">Gruppe verlassen
@ -62,7 +63,7 @@
<div class="col-3" style="white-space: nowrap"> <div class="col-3" style="white-space: nowrap">
<div style="display: inline-block; margin: 0"> <div style="display: inline-block; margin: 0">
<h2>Mitglieder</h2> <h2>Mitglieder</h2>
<div th:if='${group.getRoles().get(user.getUser_id()) == admin}'> <div th:if="${group.getRoles().get(user.getId()) == admin}">
<form method="get" <form method="get"
th:action="@{/gruppen2/details/members/{id}(id=${group.getId()})}"> th:action="@{/gruppen2/details/members/{id}(id=${group.getId()})}">
<button class="btn btn-secondary" <button class="btn btn-secondary"

View File

@ -5,13 +5,12 @@ import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule; import com.tngtech.archunit.lang.ArchRule;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class }) @AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class ControllerTest { public class ControllerTest {
@ArchTest @ArchTest

View File

@ -8,7 +8,7 @@ import com.tngtech.archunit.lang.ArchRule;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class }) @AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class DomainTest { public class DomainTest {
@ArchTest @ArchTest

View File

@ -6,7 +6,7 @@ import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule; import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.library.Architectures; import com.tngtech.archunit.library.Architectures;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class }) @AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class LayeredArchitectureTest { public class LayeredArchitectureTest {
private static Architectures.LayeredArchitecture layeredArchitecture = Architectures private static Architectures.LayeredArchitecture layeredArchitecture = Architectures

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class }) @AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class RepositoryTest { public class RepositoryTest {
@ArchTest @ArchTest

View File

@ -8,7 +8,7 @@ import org.springframework.stereotype.Service;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class }) @AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class ServiceTest { public class ServiceTest {
@ArchTest @ArchTest

View File

@ -1,8 +1,18 @@
package mops.gruppen2.builder; package mops.gruppen2.builder;
import com.github.javafaker.Faker; import com.github.javafaker.Faker;
import mops.gruppen2.domain.*; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.event.*; 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.DeleteUserEvent;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.domain.event.UpdateRoleEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -10,9 +20,9 @@ import java.util.List;
public class EventBuilder { public class EventBuilder {
/** /**
* Generiert ein EventLog mit mehreren Gruppen nud Usern * Generiert ein EventLog mit mehreren Gruppen nud Usern.
* *
* @param count Gruppenanzahl * @param count Gruppenanzahl
* @param membercount Gesamte Mitgliederanzahl * @param membercount Gesamte Mitgliederanzahl
* @return * @return
*/ */
@ -26,23 +36,23 @@ public class EventBuilder {
return eventList; return eventList;
} }
public static List<Event> completeGroup(long group_id, int membercount) { public static List<Event> completeGroup(long groupId, int membercount) {
List<Event> eventList = new ArrayList<>(); List<Event> eventList = new ArrayList<>();
eventList.add(EventBuilder.createGroupEvent(group_id)); eventList.add(EventBuilder.createGroupEvent(groupId));
eventList.add(EventBuilder.updateGroupTitleEvent(group_id)); eventList.add(EventBuilder.updateGroupTitleEvent(groupId));
eventList.add(EventBuilder.updateGroupDescriptionEvent(group_id)); eventList.add(EventBuilder.updateGroupDescriptionEvent(groupId));
eventList.addAll(EventBuilder.addUserEvents(membercount, group_id)); eventList.addAll(EventBuilder.addUserEvents(membercount, groupId));
return eventList; return eventList;
} }
public static CreateGroupEvent createGroupEvent(long group_id) { public static CreateGroupEvent createGroupEvent(long groupId) {
Faker faker = new Faker(); Faker faker = new Faker();
return new CreateGroupEvent( return new CreateGroupEvent(
group_id, groupId,
faker.random().hex(), faker.random().hex(),
null, null,
GroupType.SIMPLE, GroupType.SIMPLE,
@ -51,10 +61,10 @@ public class EventBuilder {
} }
/** /**
* Generiert mehrere CreateGroupEvents, 1 <= group_id <= count * Generiert mehrere CreateGroupEvents, 1 <= groupId <= count.
* *
* @param count Anzahl der verschiedenen Gruppen. * @param count Anzahl der verschiedenen Gruppen
* @return * @return Eventliste
*/ */
public static List<CreateGroupEvent> createGroupEvents(int count) { public static List<CreateGroupEvent> createGroupEvents(int count) {
List<CreateGroupEvent> eventList = new ArrayList<>(); List<CreateGroupEvent> eventList = new ArrayList<>();
@ -66,15 +76,15 @@ public class EventBuilder {
return eventList; return eventList;
} }
public static AddUserEvent addUserEvent(long group_id, String user_id) { public static AddUserEvent addUserEvent(long groupId, String userId) {
Faker faker = new Faker(); Faker faker = new Faker();
String firstname = faker.name().firstName(); String firstname = faker.name().firstName();
String lastname = faker.name().lastName(); String lastname = faker.name().lastName();
return new AddUserEvent( return new AddUserEvent(
group_id, groupId,
user_id, userId,
firstname, firstname,
lastname, lastname,
firstname + "." + lastname + "@mail.de" firstname + "." + lastname + "@mail.de"
@ -82,73 +92,69 @@ public class EventBuilder {
} }
/** /**
* Generiert mehrere AddUserEvents für eine Gruppe, 1 <= user_id <= count * Generiert mehrere AddUserEvents für eine Gruppe, 1 <= user_id <= count.
* *
* @param count * @param count Anzahl der Mitglieder
* @param group_id * @param groupId Gruppe, zu welcher geaddet wird
* @return * @return Eventliste
*/ */
public static List<Event> addUserEvents(int count, long group_id) { public static List<Event> addUserEvents(int count, long groupId) {
List<Event> eventList = new ArrayList<>(); List<Event> eventList = new ArrayList<>();
for (int i = 1; i <= count; i++) { for (int i = 1; i <= count; i++) {
eventList.add(EventBuilder.addUserEvent(group_id, "" + i)); eventList.add(EventBuilder.addUserEvent(groupId, "" + i));
} }
return eventList; return eventList;
} }
public static DeleteUserEvent deleteUserEvent(long group_id, String user_id) { public static DeleteUserEvent deleteUserEvent(long groupId, String userId) {
Faker faker = new Faker();
return new DeleteUserEvent( return new DeleteUserEvent(
group_id, groupId,
user_id userId
); );
} }
/** /**
* Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird * Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird.
* *
* @param group Gruppe welche geleert wird * @param group Gruppe welche geleert wird
* @return * @return Eventliste
*/ */
public static List<DeleteUserEvent> deleteUserEvents(Group group) { public static List<DeleteUserEvent> deleteUserEvents(Group group) {
List<DeleteUserEvent> eventList = new ArrayList<>(); List<DeleteUserEvent> eventList = new ArrayList<>();
for (User user : group.getMembers()) { for (User user : group.getMembers()) {
eventList.add(EventBuilder.deleteUserEvent(group.getId(), user.getUser_id())); eventList.add(EventBuilder.deleteUserEvent(group.getId(), user.getId()));
} }
return eventList; return eventList;
} }
public static UpdateGroupDescriptionEvent updateGroupDescriptionEvent(long group_id) { public static UpdateGroupDescriptionEvent updateGroupDescriptionEvent(long groupId) {
Faker faker = new Faker(); Faker faker = new Faker();
return new UpdateGroupDescriptionEvent( return new UpdateGroupDescriptionEvent(
group_id, groupId,
faker.random().hex(), faker.random().hex(),
faker.leagueOfLegends().quote() faker.leagueOfLegends().quote()
); );
} }
public static UpdateGroupTitleEvent updateGroupTitleEvent(long group_id) { public static UpdateGroupTitleEvent updateGroupTitleEvent(long groupId) {
Faker faker = new Faker(); Faker faker = new Faker();
return new UpdateGroupTitleEvent( return new UpdateGroupTitleEvent(
group_id, groupId,
faker.random().hex(), faker.random().hex(),
faker.leagueOfLegends().champion() faker.leagueOfLegends().champion()
); );
} }
public static UpdateRoleEvent randomUpdateRoleEvent(long group_id, String user_id, Role role) { public static UpdateRoleEvent randomUpdateRoleEvent(long groupId, String userId, Role role) {
Faker faker = new Faker();
return new UpdateRoleEvent( return new UpdateRoleEvent(
group_id, groupId,
user_id, userId,
role role
); );
} }

View File

@ -12,21 +12,18 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class AddUserEventTest { class AddUserEventTest {
@Test @Test
public void userAllreadyExistExeption() throws EventException { void userAlreadyExistExeption() throws EventException {
Group group = new Group(); Group group = new Group();
User user = new User("user1", "Stein", "Speck", "@sdasd");
User user = new User("user1","Stein", "Speck", "@sdasd");
group.getMembers().add(user); group.getMembers().add(user);
Event event1 = new AddUserEvent(4L, "user2", "Rock", "Roll", "and"); Event event1 = new AddUserEvent(4L, "user2", "Rock", "Roll", "and");
event1.apply(group); event1.apply(group);
Event event2 = new AddUserEvent(4L, "user1", "Rock", "Roll", "and"); Event event2 = new AddUserEvent(4L, "user1", "Rock", "Roll", "and");
assertThrows(UserAlreadyExistsException.class, ()-> assertThrows(UserAlreadyExistsException.class, () ->
event2.apply(group) event2.apply(group)
); );
assertThat(group.getMembers().size()).isEqualTo(2); assertThat(group.getMembers().size()).isEqualTo(2);
} }

View File

@ -15,19 +15,14 @@ class DeleteUserEventTest {
@Test @Test
void applyDeleteUser() throws EventException { void applyDeleteUser() throws EventException {
Group group = new Group(); Group group = new Group();
User user = new User("user1", "Stein", "Speck", "@sdasd");
User user = new User("user1","Stein", "Speck", "@sdasd");
group.getMembers().add(user); group.getMembers().add(user);
group.getRoles().put("user1", MEMBER); group.getRoles().put("user1", MEMBER);
User user2 = new User("user2", "Rock", "Roll", "and");
User user2 = new User("user2","Rock", "Roll", "and");
group.getMembers().add(user2); group.getMembers().add(user2);
group.getRoles().put("user2", MEMBER); group.getRoles().put("user2", MEMBER);
Event event = new DeleteUserEvent(1L, "user1"); Event event = new DeleteUserEvent(1L, "user1");
event.apply(group); event.apply(group);
assertThat(group.getMembers().size()).isEqualTo(1); assertThat(group.getMembers().size()).isEqualTo(1);
@ -38,18 +33,14 @@ class DeleteUserEventTest {
@Test @Test
void userDoesNotExistExeption() { void userDoesNotExistExeption() {
Group group = new Group(); Group group = new Group();
User user = new User("user1", "Stein", "Speck", "@sdasd");
User user = new User("user1","Stein", "Speck", "@sdasd");
group.getMembers().add(user); group.getMembers().add(user);
group.getRoles().put("user1", MEMBER); group.getRoles().put("user1", MEMBER);
Event event = new DeleteUserEvent(17L,"user5"); Event event = new DeleteUserEvent(17L, "user5");
assertThrows(UserNotFoundException.class, () ->
assertThrows(UserNotFoundException.class, ()->
event.apply(group) event.apply(group)
); );
assertThat(group.getMembers().size()).isEqualTo(1); assertThat(group.getMembers().size()).isEqualTo(1);
} }
} }

View File

@ -21,24 +21,25 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
class EventServiceTest { class EventServiceTest {
private EventRepository eventRepository;
private EventService eventService; private EventService eventService;
private EventRepository eventRepositoryMock = mock(EventRepository.class);
@BeforeEach @BeforeEach
void setUp() { void setUp() {
eventService = new EventService(mock(JsonService.class), eventRepositoryMock); eventRepository = mock(EventRepository.class);
eventService = new EventService(mock(JsonService.class), eventRepository);
} }
@Test @Test
void getMaxID() { void getMaxID() {
when(eventRepositoryMock.getHighesEvent_ID()).thenReturn(42L); when(eventRepository.getHighesEvent_ID()).thenReturn(42L);
assertEquals(eventService.getMaxEvent_id(), 42L); assertEquals(eventService.getMaxEvent_id(), 42L);
} }
@Test @Test
void checkGroupReturnNextValue() { void checkGroupReturnNextValue() {
when(eventRepositoryMock.getMaxGroupID()).thenReturn(2L); when(eventRepository.getMaxGroupID()).thenReturn(2L);
assertEquals(eventService.checkGroup(), 3L); assertEquals(eventService.checkGroup(), 3L);
} }
@ -46,7 +47,7 @@ class EventServiceTest {
@Test @Test
void checkGroupReturnOneIfDBIsEmpty() { void checkGroupReturnOneIfDBIsEmpty() {
List<EventDTO> eventDTOS = new ArrayList<>(); List<EventDTO> eventDTOS = new ArrayList<>();
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS); when(eventRepository.findAll()).thenReturn(eventDTOS);
assertEquals(eventService.checkGroup(), 1); assertEquals(eventService.checkGroup(), 1);
} }

View File

@ -5,12 +5,9 @@ import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.AddUserEvent; import mops.gruppen2.domain.event.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent; import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.DeleteGroupEvent;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
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 java.util.ArrayList; import java.util.ArrayList;
@ -20,23 +17,23 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
class GroupServiceTest { class GroupServiceTest {
GroupService groupService;
EventRepository eventRepository; private GroupService groupService;
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
groupService = new GroupService(mock(EventService.class), eventRepository); groupService = new GroupService(mock(EventService.class), mock(EventRepository.class));
} }
@Test @Test
void rightClassForSucsessfulGroup() throws Exception { void rightClassForSuccessfulGroup() throws Exception {
List<Event> eventList = new ArrayList<>(); List<Event> eventList = new ArrayList<>();
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(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); List<Group> groups = groupService.projectEventList(eventList);
assertThat(groups.get(0)).isInstanceOf(Group.class);
} }
} }