change EventDTO, add AddUserEventController, add the search function in UI and backend
This commit is contained in:
@ -2,6 +2,7 @@ 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.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
@ -18,6 +19,8 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/gruppen2")
|
@RequestMapping("/gruppen2")
|
||||||
@ -31,6 +34,7 @@ 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 List<Group> groups = new ArrayList<>();
|
||||||
|
|
||||||
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) {
|
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) {
|
||||||
this.keyCloakService = keyCloakService;
|
this.keyCloakService = keyCloakService;
|
||||||
@ -69,9 +73,18 @@ public class Gruppen2Controller {
|
|||||||
@GetMapping("/findGroup")
|
@GetMapping("/findGroup")
|
||||||
public String findGroup(KeycloakAuthenticationToken token, Model model) {
|
public String findGroup(KeycloakAuthenticationToken token, Model model) {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
model.addAttribute("gruppen",groups);
|
||||||
return "search";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@PostMapping("/findGroup")
|
||||||
|
public String searchGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff") String suchbegriff) throws EventException {
|
||||||
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
groups = groupService.findGroupWith(suchbegriff);
|
||||||
|
return "redirect:/gruppen2/findGroup";
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/createGroup")
|
@PostMapping("/createGroup")
|
||||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||||
@RequestParam(value = "title") String title,
|
@RequestParam(value = "title") String title,
|
||||||
|
|||||||
@ -12,4 +12,5 @@ public class EventDTO {
|
|||||||
Long group_id;
|
Long group_id;
|
||||||
String user_id;
|
String user_id;
|
||||||
String event_payload;
|
String event_payload;
|
||||||
|
boolean visibility;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ public class Event {
|
|||||||
Long group_id;
|
Long group_id;
|
||||||
String user_id;
|
String user_id;
|
||||||
|
|
||||||
|
|
||||||
public Event(Long group_id,String user_id){
|
public Event(Long group_id,String user_id){
|
||||||
this.group_id = group_id;
|
this.group_id = group_id;
|
||||||
this.user_id = user_id;
|
this.user_id = user_id;
|
||||||
|
|||||||
@ -16,6 +16,10 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
|||||||
|
|
||||||
@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 group_id);
|
||||||
|
|
||||||
@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
|
@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
|
||||||
public Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||||
|
|
||||||
|
@Query("select * from event where visibility =:vis")
|
||||||
|
List<EventDTO> findEventDTOByVisibility(@Param("vis") Boolean visibility);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
@ -26,4 +27,9 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(updateGroupTitleEvent);
|
eventService.saveEvent(updateGroupTitleEvent);
|
||||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addUser(Account account, Group group){
|
||||||
|
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(),group.getId(),account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||||
|
eventService.saveEvent(addUserEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,12 @@ 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.EventDTO;
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
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;
|
||||||
import org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -29,15 +32,25 @@ public class EventService {
|
|||||||
eventStore.save(eventDTO);
|
eventStore.save(eventDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* @return EventDTO
|
* @return EventDTO
|
||||||
*/
|
*/
|
||||||
public EventDTO getDTO(Event event){
|
public EventDTO getDTO(Event event) {
|
||||||
EventDTO eventDTO = new EventDTO();
|
EventDTO eventDTO = new EventDTO();
|
||||||
eventDTO.setGroup_id(event.getGroup_id());
|
eventDTO.setGroup_id(event.getGroup_id());
|
||||||
eventDTO.setUser_id(event.getUser_id());
|
eventDTO.setUser_id(event.getUser_id());
|
||||||
|
if(event instanceof CreateGroupEvent) {
|
||||||
|
if(((CreateGroupEvent) event).getGroupVisibility() == Visibility.PRIVATE) {
|
||||||
|
eventDTO.setVisibility(false);
|
||||||
|
}else {
|
||||||
|
eventDTO.setVisibility(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
eventDTO.setEvent_payload(serializationService.serializeEvent(event));
|
eventDTO.setEvent_payload(serializationService.serializeEvent(event));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
@ -75,7 +88,7 @@ public class EventService {
|
|||||||
return translateEventDTOs(eventDTOS);
|
return translateEventDTOs(eventDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Erzeugt aus der Datenbank eine Liste von Events
|
/** Erzeugt aus einer Liste von eventDTOs eine Liste von Events
|
||||||
*
|
*
|
||||||
* @param eventDTOS
|
* @param eventDTOS
|
||||||
* @return Liste von Events
|
* @return Liste von Events
|
||||||
@ -86,7 +99,6 @@ public class EventService {
|
|||||||
for (EventDTO eventDTO : eventDTOS) {
|
for (EventDTO eventDTO : eventDTOS) {
|
||||||
try {
|
try {
|
||||||
events.add(serializationService.deserializeEvent(eventDTO.getEvent_payload()));
|
events.add(serializationService.deserializeEvent(eventDTO.getEvent_payload()));
|
||||||
|
|
||||||
}catch (JsonProcessingException e) {
|
}catch (JsonProcessingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -94,4 +106,5 @@ public class EventService {
|
|||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,12 @@ public class GroupService {
|
|||||||
this.eventRepository = eventRepository;
|
this.eventRepository = eventRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 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.
|
||||||
|
*
|
||||||
|
* @param group_ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public List<Event> getGroupEvents(List<Long> group_ids) {
|
public List<Event> getGroupEvents(List<Long> group_ids) {
|
||||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
@ -32,8 +38,13 @@ public class GroupService {
|
|||||||
return events = eventService.translateEventDTOs(eventDTOS);
|
return events = eventService.translateEventDTOs(eventDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Erzeugt eine neue Map wo Gruppen aus den Events erzeugt und den Gruppen_ids zugeordnet werden.
|
||||||
|
* Die Gruppen werden als Liste zurückgegeben
|
||||||
|
*
|
||||||
|
* @param events
|
||||||
|
* @return
|
||||||
|
* @throws EventException
|
||||||
|
*/
|
||||||
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<>();
|
||||||
|
|
||||||
@ -44,7 +55,13 @@ public class GroupService {
|
|||||||
return new ArrayList<>(groupMap.values());
|
return new ArrayList<>(groupMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/** guckt in der Map anhand der Id nach ob die Gruppe schon in der Map vorhanden ist, wenn nicht wird eine neue
|
||||||
|
* Gruppe erzeugt
|
||||||
|
*
|
||||||
|
* @param groups
|
||||||
|
* @param group_id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private Group getOrCreateGroup(Map<Long, Group> groups, long group_id) {
|
private Group getOrCreateGroup(Map<Long, Group> groups, long group_id) {
|
||||||
if (!groups.containsKey(group_id)) {
|
if (!groups.containsKey(group_id)) {
|
||||||
groups.put(group_id, new Group());
|
groups.put(group_id, new Group());
|
||||||
@ -52,4 +69,33 @@ public class GroupService {
|
|||||||
|
|
||||||
return groups.get(group_id);
|
return groups.get(group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sucht alle Zeilen in der DB wo die Visibility gleich true ist und wandelt diese in
|
||||||
|
* eine Liste von Gruppen
|
||||||
|
* @return
|
||||||
|
* @throws EventException
|
||||||
|
*/
|
||||||
|
public List<Group> getAllGroupWithVisibilityPublic() throws EventException {
|
||||||
|
return projectEventList(eventService.translateEventDTOs(eventRepository.findEventDTOByVisibility(Boolean.FALSE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filtert alle öffentliche Gruppen nach dem suchbegriff und gibt diese als Liste von Gruppen zurück.
|
||||||
|
* Groß und kleinschreibung wird beachtet.
|
||||||
|
* @param search
|
||||||
|
* @return
|
||||||
|
* @throws EventException
|
||||||
|
*/
|
||||||
|
public List<Group> findGroupWith(String search) throws EventException {
|
||||||
|
List<Group> groups = new ArrayList<>();
|
||||||
|
for (Group group: getAllGroupWithVisibilityPublic()) {
|
||||||
|
if (group.getTitle().contains(search)){
|
||||||
|
groups.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ public class SerializationService {
|
|||||||
this.eventStore = eventStore;
|
this.eventStore = eventStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String serializeEvent(Event event) throws JsonProcessingException {
|
public String serializeEvent(Event event) throws JsonProcessingException {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
return mapper.writeValueAsString(event);
|
return mapper.writeValueAsString(event);
|
||||||
|
|||||||
@ -7,5 +7,6 @@ CREATE TABLE event
|
|||||||
event_id INT PRIMARY KEY AUTO_INCREMENT,
|
event_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
group_id INT NOT NULL,
|
group_id INT NOT NULL,
|
||||||
user_id VARCHAR(50),
|
user_id VARCHAR(50),
|
||||||
event_payload VARCHAR(255)
|
event_payload VARCHAR(255),
|
||||||
|
visibility BOOLEAN
|
||||||
);
|
);
|
||||||
|
|||||||
@ -29,13 +29,13 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<h1>Gruppensuche</h1>
|
<h1>Gruppensuche</h1>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<form action="/findGroup" method="get">
|
<form action="/gruppen2/findGroup" method="post">
|
||||||
<div style="border: 10px solid aliceblue; background: aliceblue">
|
<div style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Suchbegriff:</label>
|
<label>Suchbegriff:</label>
|
||||||
<input class="form-control" type="text" value="" name="suchbegriff" placeholder="z.B. Programmieren, Lerngruppe, ...">
|
<input class="form-control" placeholder="z.B. Programmieren, Lerngruppe, ..." th:name="suchbegriff" type="text">
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="btn btn-primary" style="background: #52a1eb; border-style: none">Suchen</button>
|
<button type="submit" class="btn btn-primary" style="background: #52a1eb; border-style: none">Suchen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<br>
|
<br>
|
||||||
@ -49,18 +49,12 @@
|
|||||||
<th scope="col">Mitgliederanzahl</th>
|
<th scope="col">Mitgliederanzahl</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody th:each="gruppe : ${gruppen}">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">LA1 Kursgruppe</th>
|
<th scope="row" th:text="${gruppe.title}">Gruppenname</th>
|
||||||
<td>Gruppe für den Kurs LA1</td>
|
<td th:text="${gruppe.getDescription()}">Beschreibung</td>
|
||||||
<td>Öffentlich</td>
|
<td th:text="${gruppe.getVisibility()}">Öffentlich</td>
|
||||||
<td>318</td>
|
<td th:text="${gruppe.getMembers().size()}">Mitgliederanzahl</td>
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Lerngruppe LA1</th>
|
|
||||||
<td>Lerngruppe zur Bearbeitung von Übungszetteln</td>
|
|
||||||
<td>Privat</td>
|
|
||||||
<td>6</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.EventDTO;
|
import mops.gruppen2.domain.EventDTO;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.GroupType;
|
||||||
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
import mops.gruppen2.domain.event.AddUserEvent;
|
||||||
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -37,4 +39,19 @@ class EventServiceTest {
|
|||||||
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
|
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
|
||||||
assertEquals(eventDTO1.getGroup_id()+1, eventService.checkGroup());
|
assertEquals(eventDTO1.getGroup_id()+1, eventService.checkGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDTOOffentlichTest(){
|
||||||
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), "test", null , GroupType.LECTURE, Visibility.PUBLIC);
|
||||||
|
EventDTO eventDTO = eventService.getDTO(createGroupEvent);
|
||||||
|
assertEquals(eventDTO.isVisibility(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDTOPrivatTest(){
|
||||||
|
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), "test","franz","mueller","a@a");
|
||||||
|
EventDTO eventDTO = eventService.getDTO(addUserEvent);
|
||||||
|
assertEquals(eventDTO.isVisibility(), false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user