1

Merge branch 'master' into edit-User

This commit is contained in:
Talha Caliskan
2020-03-18 16:43:33 +01:00
committed by GitHub
24 changed files with 349 additions and 95 deletions

View File

@ -68,6 +68,7 @@ dependencies {
implementation 'io.springfox:springfox-swagger2:2.9.2' implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2' implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'com.github.javafaker:javafaker:1.0.2' implementation 'com.github.javafaker:javafaker:1.0.2'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.2'
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
@ -77,6 +78,8 @@ dependencies {
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.4.0.RELEASE' compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.4.0.RELEASE'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.3'
testImplementation 'org.assertj:assertj-core:3.15.0' testImplementation 'org.assertj:assertj-core:3.15.0'
testImplementation('org.springframework.boot:spring-boot-starter-test') { testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'

View File

@ -7,13 +7,13 @@ import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper; import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.service.APIFormatterService; import mops.gruppen2.service.*;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.SerializationService;
import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
/** /**
@ -36,7 +36,7 @@ public class APIController {
@GetMapping("/updateGroups/{status}") @GetMapping("/updateGroups/{status}")
@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich etwas geändert hat") @ApiOperation(value = "Gibt alle Gruppen zurück in denen sich etwas geändert hat")
public UpdatedGroupRequestMapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException { public UpdatedGroupRequestMapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
List<Event> events = eventService.getNewEvents(status); List<Event> events = eventService.getNewEvents(status);
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events)); UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
@ -46,17 +46,18 @@ public class APIController {
@GetMapping("/getGroupIdsOfUser/{teilnehmer}") @GetMapping("/getGroupIdsOfUser/{teilnehmer}")
@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation(value = "Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet") @ApiOperation(value = "Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
public List<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) throws EventException { public List<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) throws EventException {
return eventService.getGroupsOfUser(teilnehmer); return eventService.getGroupsOfUser(teilnehmer);
} }
@GetMapping("/getGroup/{groupId}") @GetMapping("/getGroup/{groupId}")
@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation(value = "Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück") @ApiOperation(value = "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

@ -3,9 +3,9 @@ package mops.gruppen2.controller;
import mops.gruppen2.config.Gruppen2Config; 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.Role; import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.CreateGroupEvent; import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.UpdateRoleEvent; import mops.gruppen2.domain.event.UpdateRoleEvent;
import mops.gruppen2.security.Account; import mops.gruppen2.security.Account;
@ -18,14 +18,15 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.annotation.SessionScope; import org.springframework.web.context.annotation.SessionScope;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Controller @Controller
@SessionScope @SessionScope
@RequestMapping("/gruppen2") @RequestMapping("/gruppen2")
@ -39,13 +40,15 @@ public class Gruppen2Controller {
private final GroupService groupService; private final GroupService groupService;
private final UserService userService; private final UserService userService;
private final ControllerService controllerService; private final ControllerService controllerService;
private final InviteLinkRepositoryService inviteLinkRepositoryService;
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) { public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService) {
this.keyCloakService = keyCloakService; this.keyCloakService = keyCloakService;
this.eventService = eventService; this.eventService = eventService;
this.groupService = groupService; this.groupService = groupService;
this.userService = userService; this.userService = userService;
this.controllerService = controllerService; this.controllerService = controllerService;
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
} }
/** /**
@ -55,18 +58,40 @@ public class Gruppen2Controller {
* @param model tolles model * @param model tolles model
* @return index.html * @return index.html
*/ */
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("") @GetMapping("")
public String index(KeycloakAuthenticationToken token, Model model) throws EventException { public String index(KeycloakAuthenticationToken token, Model model) 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());
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("gruppen", userService.getUserGroups(user)); model.addAttribute("gruppen", userService.getUserGroups(user));
model.addAttribute("user",user); model.addAttribute("user", user);
return "index"; return "index";
} }
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@GetMapping("/createLecture")
public String createLecture(KeycloakAuthenticationToken token, Model model) {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
return "createLecture";
}
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/createLecture")
public String pCreateLecture(KeycloakAuthenticationToken token,
@RequestParam(value = "title") String title,
@RequestParam(value = "beschreibung") String beschreibung,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam("file") MultipartFile file) throws IOException {
Account account = keyCloakService.createAccountFromPrincipal(token);
List<User> userList = CsvService.read(file.getInputStream());
visibility = visibility == null;
controllerService.createLecture(account, title, beschreibung, visibility, userList);
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/createGroup") @GetMapping("/createGroup")
public String createGroup(KeycloakAuthenticationToken token, Model model) { public String createGroup(KeycloakAuthenticationToken token, Model model) {
@ -74,18 +99,21 @@ public class Gruppen2Controller {
return "create"; return "create";
} }
@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 suchbegriff) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
List<Group> groupse = new ArrayList<>(); List<Group> groupse = new ArrayList<>();
if(suchbegriff!=null) { if (suchbegriff != null) {
groupse = groupService.findGroupWith(suchbegriff); groupse = groupService.findGroupWith(suchbegriff,account);
} }
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("gruppen",groupse); model.addAttribute("gruppen", groupse);
return "search"; return "search";
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/createGroup") @PostMapping("/createGroup")
public String pCreateGroup(KeycloakAuthenticationToken token, public String pCreateGroup(KeycloakAuthenticationToken token,
@RequestParam(value = "title") String title, @RequestParam(value = "title") String title,
@ -93,11 +121,7 @@ public class Gruppen2Controller {
@RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException { @RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
if (visibility == null) { visibility = visibility == null;
visibility = true;
} else {
visibility = false;
}
controllerService.createGroup(account, title, beschreibung, visibility); controllerService.createGroup(account, title, beschreibung, visibility);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
@ -106,11 +130,12 @@ 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 (value="id") Long id) throws EventException, ResponseStatusException { public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable (value="id") Long id) throws EventException, ResponseStatusException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id); Group group = userService.getGroupById(id);
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) {
model.addAttribute("group", group); model.addAttribute("group", group);
model.addAttribute("roles", group.getRoles()); model.addAttribute("roles", group.getRoles());
model.addAttribute("user", user); model.addAttribute("user", user);
@ -120,7 +145,7 @@ 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)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten") @PostMapping("/detailsBeitreten")
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException { public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
@ -132,19 +157,31 @@ public class Gruppen2Controller {
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 (value="id") Long id) throws EventException { public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id); Group group = userService.getGroupById(id);
if (group!=null) { if (group != null) {
model.addAttribute("group", group); model.addAttribute("group", group);
return "detailsNoMember"; return "detailsNoMember";
} }
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)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/acceptinvite/{link}")
public String acceptInvite(KeycloakAuthenticationToken token, Model model, @PathVariable String link) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(inviteLinkRepositoryService.findGroupIdByInvite(link));
if (group != null) {
model.addAttribute("group", group);
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
}
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup") @PostMapping("/leaveGroup")
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) throws EventException { public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
@ -182,5 +219,10 @@ public class Gruppen2Controller {
@RequestParam (value = "user_id") String user_id) throws EventException { @RequestParam (value = "user_id") String user_id) throws EventException {
controllerService.deleteUser(user_id, group_id); controllerService.deleteUser(user_id, group_id);
return "redirect:/gruppen2/details/members/" + group_id; return "redirect:/gruppen2/details/members/" + group_id;
@GetMapping("*")
public String defaultLink() {
return "errorRenameLater";
} }
} }

View File

@ -9,7 +9,7 @@ import javax.servlet.http.HttpServletRequest;
public class MopsController { public class MopsController {
@GetMapping("") @GetMapping("")
public String redirect(){ public String redirect() {
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }

View File

@ -3,10 +3,11 @@ package mops.gruppen2.domain;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Value; import lombok.NoArgsConstructor;
@Value @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"}) @EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
public class User { public class User {
String user_id; String user_id;

View File

@ -1,4 +1,4 @@
package mops.gruppen2.domain; package mops.gruppen2.domain.dto;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;

View File

@ -0,0 +1,16 @@
package mops.gruppen2.domain.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Table("invite")
@Data
@AllArgsConstructor
public class InviteLinkDTO {
@Id
Long link_id;
Long group_id;
String invite_link;
}

View File

@ -1,6 +1,6 @@
package mops.gruppen2.repository; package mops.gruppen2.repository;
import mops.gruppen2.domain.EventDTO; import mops.gruppen2.domain.dto.EventDTO;
import org.springframework.data.jdbc.repository.query.Query; import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
@ -30,4 +30,7 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("SELECT MAX(event_id) FROM event") @Query("SELECT MAX(event_id) FROM event")
public Long getHighesEvent_ID(); public Long getHighesEvent_ID();
@Query("SELECT MAX(group_id) FROM event")
public Long getMaxGroupID();
} }

View File

@ -0,0 +1,17 @@
package mops.gruppen2.repository;
import mops.gruppen2.domain.dto.InviteLinkDTO;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface InviteLinkRepository extends CrudRepository<InviteLinkDTO, Long> {
//@Query("SELECT invite_link FROM invite WHERE group_id = :id")
//String findLinkByGroupID(@Param("id") Long GroupID);
@Query("SELECT group_id FROM invite WHERE invite_link = :link")
Long findGroupIdByLink(@Param("link") String link);
}

View File

@ -1,20 +1,33 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.domain.*; import mops.gruppen2.domain.*;
import mops.gruppen2.domain.Exceptions.EventException; import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.event.*; import mops.gruppen2.domain.event.*;
import mops.gruppen2.security.Account; import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import mops.gruppen2.domain.event.*;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@Service @Service
public class ControllerService { public class ControllerService {
private final EventService eventService; private final EventService eventService;
private final UserService userService;
public ControllerService(EventService eventService, UserService userService) { private final UserService userService;
private final InviteLinkRepositoryService inviteLinkRepositoryService;
public ControllerService(EventService eventService, InviteLinkRepositoryService inviteLinkRepositoryService) {
this.eventService = eventService; this.eventService = eventService;
this.userService = userService; this.inviteLinkRepositoryService = inviteLinkRepositoryService;
} }
/** /**
@ -34,9 +47,10 @@ public class ControllerService {
visibility1 = Visibility.PUBLIC; visibility1 = Visibility.PUBLIC;
} else { } else {
visibility1 = Visibility.PRIVATE; visibility1 = Visibility.PRIVATE;
createInviteLink(group_id);
} }
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.LECTURE, visibility1); CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.SIMPLE, visibility1);
eventService.saveEvent(createGroupEvent); eventService.saveEvent(createGroupEvent);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
@ -46,11 +60,23 @@ public class ControllerService {
updateRole(user.getUser_id(), group_id); updateRole(user.getUser_id(), group_id);
} }
private void createInviteLink(Long group_id) {
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
}
public void addUser(Account account, Long group_id){ public void addUser(Account account, Long group_id){
AddUserEvent addUserEvent = new AddUserEvent(group_id,account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()); AddUserEvent addUserEvent = new AddUserEvent(group_id,account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
eventService.saveEvent(addUserEvent); eventService.saveEvent(addUserEvent);
} }
public void addUserList(List<User> users, Long group_id) {
for (User user : users) {
AddUserEvent addUserEvent = new AddUserEvent(group_id, user.getUser_id(), user.getGivenname(), user.getFamilyname(), user.getEmail());
eventService.saveEvent(addUserEvent);
}
}
public void updateTitle(Account account, Long group_id, String title){ public void updateTitle(Account account, Long group_id, String title){
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title); UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
eventService.saveEvent(updateGroupTitleEvent); eventService.saveEvent(updateGroupTitleEvent);
@ -91,5 +117,26 @@ public class ControllerService {
public void deleteGroupEvent(User user, Long group_id) { public void deleteGroupEvent(User user, Long group_id) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(group_id, user.getUser_id()); DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(group_id, user.getUser_id());
eventService.saveEvent(deleteGroupEvent); eventService.saveEvent(deleteGroupEvent);
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) {
Visibility visibility1;
Long group_id = eventService.checkGroup();
if (visibility) {
visibility1 = Visibility.PUBLIC;
} else {
visibility1 = Visibility.PRIVATE;
}
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);
addUserList(users, group_id);
} }
} }

View File

@ -0,0 +1,24 @@
package mops.gruppen2.service;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import mops.gruppen2.domain.User;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@Service
public class CsvService {
public static List<User> read(InputStream stream) throws IOException {
CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(User.class).withHeader().withColumnReordering(true);
ObjectReader reader = mapper.readerFor(User.class).with(schema);
return reader.<User>readValues(stream).readAll();
}
}

View File

@ -1,8 +1,8 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import mops.gruppen2.domain.EventDTO;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.event.CreateGroupEvent; import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
@ -59,22 +59,17 @@ public class EventService {
} }
/** /**
* Sorgt dafür die Group_id immer um 1 zu erhöhen * Gibt die nächst höhere groupID zurück die belegt werden kann.
* Gibt 1 zurück, falls keine Gruppe vorhanden ist.
* *
* @return Gibt Long zurück * @return Gibt Long zurück
*/ */
public Long checkGroup() { public Long checkGroup() {
Long tmpId = 1L; Long maxGroupID = eventStore.getMaxGroupID();
Iterable<EventDTO> eventDTOS = eventStore.findAll(); if (maxGroupID == null) {
for (EventDTO event : eventDTOS) { return 1L;
if (event.getGroup_id() == null) {
return tmpId;
}
if (tmpId <= event.getGroup_id()) {
tmpId++;
}
} }
return tmpId; return maxGroupID + 1;
} }
/** /**

View File

@ -1,11 +1,12 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.domain.EventDTO; import mops.gruppen2.domain.dto.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.Visibility; 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 mops.gruppen2.security.Account;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -71,15 +72,21 @@ public class GroupService {
return groups.get(group_id); return groups.get(group_id);
} }
private List<Long> removeUserGroups(List<Long> group_ids, List<Long> user_groups) {
for (Long group_id: user_groups) {
group_ids.remove(group_id);
}
return group_ids;
}
/** /**
* sucht alle Zeilen in der DB wo die Visibility gleich true ist und wandelt diese in * sucht alle Zeilen in der DB wo die Visibility true ist und entfernt alle Gruppen des Users.
* eine Liste von Gruppen * Erstellt eine Liste aus Gruppen.
* @return * @return
* @throws EventException * @throws EventException
*/ */
public List<Group> getAllGroupWithVisibilityPublic(String user_id) throws EventException {
public List<Group> getAllGroupWithVisibilityPublic() throws EventException { List<Long> group_ids = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(user_id));
List<Long> group_ids = eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE);
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids); List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
List<Event> events = eventService.translateEventDTOs(eventDTOS); List<Event> events = eventService.translateEventDTOs(eventDTOS);
List<Group> groups = projectEventList(events); List<Group> groups = projectEventList(events);
@ -94,10 +101,10 @@ public class GroupService {
* @return * @return
* @throws EventException * @throws EventException
*/ */
public List<Group> findGroupWith(String search) throws EventException { public List<Group> findGroupWith(String search, Account account) throws EventException {
List<Group> groups = new ArrayList<>(); List<Group> groups = new ArrayList<>();
for (Group group: getAllGroupWithVisibilityPublic()) { for (Group group: getAllGroupWithVisibilityPublic(account.getName())) {
if (group.getTitle().contains(search)|| group.getDescription().contains(search)){ if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())){
groups.add(group); groups.add(group);
} }
} }

View File

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

View File

@ -2,7 +2,6 @@ package mops.gruppen2.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import mops.gruppen2.domain.EventDTO;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
import org.slf4j.Logger; import org.slf4j.Logger;

View File

@ -1,21 +1,19 @@
server.port=8080 server.port=8080
application.name=gruppen2 application.name=gruppen2
logging.pattern.console=[${application.name}],%magenta(%-5level), %d{dd-MM-yyyy HH:mm:ss.SSS}, %highlight(%msg),%thread,%logger.%M%n logging.pattern.console=[${application.name}],%magenta(%-5level), %d{dd-MM-yyyy HH:mm:ss.SSS}, %highlight(%msg),%thread,%logger.%M%n
spring.datasource.url=jdbc:h2:mem:blogdb spring.datasource.url=jdbc:h2:mem:blogdb
spring.datasource.driverClassName=org.h2.Driver spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa spring.datasource.username=sa
spring.datasource.password= spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
logging.level.org.springframework.jdbc.core=DEBUG
keycloak.principal-attribute=preferred_username keycloak.principal-attribute=preferred_username
keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth
keycloak.realm=MOPS keycloak.realm=MOPS
hhu_keycloak.token-uri=https://keycloak.cs.hhu.de/auth/realms/MOPS/protocol/openid-connect/token hhu_keycloak.token-uri=https://keycloak.cs.hhu.de/auth/realms/MOPS/protocol/openid-connect/token
keycloak.resource=gruppenfindung keycloak.resource=gruppenfindung
keycloak.credentials.secret= fc6ebf10-8c63-4e71-a667-4eae4e8209a1 keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1
keycloak.verify-token-audience=true keycloak.verify-token-audience=true
keycloak.use-resource-role-mappings=true keycloak.use-resource-role-mappings=true

View File

@ -10,3 +10,12 @@ CREATE TABLE event
event_payload VARCHAR(2500), event_payload VARCHAR(2500),
visibility BOOLEAN visibility BOOLEAN
); );
DROP TABLE IF EXISTS invite;
CREATE TABLE invite
(
link_id INT PRIMARY KEY AUTO_INCREMENT,
group_id INT NOT NULL,
invite_link varchar(255) NOT NULL
);

View File

@ -22,6 +22,9 @@
<li> <li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a> <a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
</li> </li>
<li th:if="${account.getRoles().contains('orga')}">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
</li>
</ul> </ul>
</nav> </nav>
</header> </header>

View File

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<title>Gruppenerstellung</title>
<th:block th:fragment="headcontent">
<!-- Links, Skripts, Styles hier einfügen! -->
</th:block>
</head>
<body>
<header>
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
<ul>
<li>
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
</li>
<li>
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
</li>
<li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
</li>
<li th:if="${account.getRoles().contains('orga')}" class="active">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
</li>
</ul>
</nav>
</header>
<main th:fragment="bodycontent">
<div class="container-fluid">
<div class="row">
<div class="col-10">
<h1>Veranstaltung erstellen</h1>
<div class="shadow p-2" style=" border: 10px solid aliceblue; background: aliceblue">
<form method="post" action="/gruppen2/createLecture" enctype="multipart/form-data">
<div class="form-group">
<label for="titel">Titel</label>
<input type="text" class="form-control" id="titel" th:name="title" required>
</div>
<div class="form-group">
<label for="beschreibung">Beschreibung</label>
<textarea th:name="beschreibung" class="form-control" id="beschreibung" rows="3" required></textarea>
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" id="visibility" class="custom-control-input" th:name="visibility">
<label class="custom-control-label" for="visibility">Private Gruppe</label>
</div>
<div class="form-group pt-4">
<div class="row">
<div class="col-10">
<div class="custom-file">
<input type="file" class="custom-file-input" id="file" th:name="file">
<label class="custom-file-label" for="file">CSV Datei von Mitgliedern hochladen</label>
</div>
</div>
</div>
</div>
<div class="form-group pt-4">
<button class="btn btn-primary" type="submit" style="background: #52a1eb; border-style: none">Erstellen</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
</body>
</html>

View File

@ -21,6 +21,9 @@
<li> <li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a> <a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
</li> </li>
<li th:if="${account.getRoles().contains('orga')}">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
</li>
</ul> </ul>
</nav> </nav>
</header> </header>

View File

@ -21,6 +21,9 @@
<li> <li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a> <a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
</li> </li>
<li th:if="${account.getRoles().contains('orga')}">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
</li>
</ul> </ul>
</nav> </nav>
</header> </header>

View File

@ -21,7 +21,13 @@
<li> <li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a> <a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
</li> </li>
</ul>-- </ul>
<!-- Fix double point -->
<li th:if="${account.getRoles().contains('orga')}">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
</li>
</ul>
</nav> </nav>
</header> </header>
<main th:fragment="bodycontent"> <main th:fragment="bodycontent">

View File

@ -21,6 +21,9 @@
<li class="active"> <li class="active">
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a> <a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
</li> </li>
<li th:if="${account.getRoles().contains('orga')}">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
</li>
</ul> </ul>
</nav> </nav>
</header> </header>

View File

@ -1,8 +1,8 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.domain.EventDTO;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.dto.EventDTO;
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.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
@ -14,7 +14,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -28,21 +28,6 @@ class EventServiceTest {
eventService = new EventService(mock(SerializationService.class), eventRepositoryMock); eventService = new EventService(mock(SerializationService.class), eventRepositoryMock);
} }
@Test
void checkGroupTest() {
EventDTO eventDTO = new EventDTO();
EventDTO eventDTO1 = new EventDTO();
eventDTO1.setGroup_id(1L);
eventDTO.setUser_id("realer");
eventDTO.setUser_id("faker");
eventDTO.setGroup_id(0L);
List<EventDTO> eventDTOS = new ArrayList<>();
eventDTOS.add(eventDTO);
eventDTOS.add(eventDTO1);
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
assertEquals(eventDTO1.getGroup_id() + 1, eventService.checkGroup());
}
@Test @Test
void getMaxID() { void getMaxID() {
when(eventRepositoryMock.getHighesEvent_ID()).thenReturn(42L); when(eventRepositoryMock.getHighesEvent_ID()).thenReturn(42L);
@ -52,14 +37,7 @@ class EventServiceTest {
@Test @Test
void checkGroupReturnNextValue() { void checkGroupReturnNextValue() {
List<EventDTO> eventDTOS = new ArrayList<>(); when(eventRepositoryMock.getMaxGroupID()).thenReturn(2L);
EventDTO eventDTO1 = new EventDTO();
EventDTO eventDTO2 = new EventDTO();
eventDTO1.setGroup_id(1L);
eventDTO2.setGroup_id(2L);
eventDTOS.add(eventDTO1);
eventDTOS.add(eventDTO2);
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
assertEquals(eventService.checkGroup(), 3L); assertEquals(eventService.checkGroup(), 3L);
} }