Merge remote-tracking branch 'origin/master' into updateGroupsAPI
# Conflicts: # src/main/java/mops/gruppen2/repository/EventRepository.java
This commit is contained in:
@ -1,14 +1,16 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
import mops.gruppen2.config.Gruppen2Config;
|
import mops.gruppen2.config.Gruppen2Config;
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
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.UpdateGroupDescriptionEvent;
|
||||||
|
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import mops.gruppen2.service.EventService;
|
import mops.gruppen2.service.*;
|
||||||
import mops.gruppen2.service.GroupService;
|
|
||||||
import mops.gruppen2.service.KeyCloakService;
|
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@ -27,11 +29,15 @@ public class Gruppen2Controller {
|
|||||||
private final KeyCloakService keyCloakService;
|
private final KeyCloakService keyCloakService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
private final GroupService groupService;
|
private final GroupService groupService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final ControllerService controllerService;
|
||||||
|
|
||||||
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService) {
|
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) {
|
||||||
this.keyCloakService = keyCloakService;
|
this.keyCloakService = keyCloakService;
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
this.groupService = groupService;
|
this.groupService = groupService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.controllerService = controllerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,8 +49,12 @@ public class Gruppen2Controller {
|
|||||||
*/
|
*/
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public String index(KeycloakAuthenticationToken token, Model model) {
|
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
model.addAttribute("gruppen", userService.getUserGroups(user.getUser_id()));
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,15 +77,10 @@ public class Gruppen2Controller {
|
|||||||
@RequestParam(value = "title") String title,
|
@RequestParam(value = "title") String title,
|
||||||
@RequestParam(value = "beschreibung") String beschreibung) {
|
@RequestParam(value = "beschreibung") String beschreibung) {
|
||||||
|
|
||||||
|
|
||||||
//Refoctor
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), account.getName(), null ,GroupType.LECTURE, Visibility.PUBLIC);
|
controllerService.createGroup(account, title, beschreibung);
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
|
||||||
eventService.saveEvent(createGroupEvent);
|
|
||||||
eventService.saveEvent(addUserEvent);
|
|
||||||
|
|
||||||
return "redirect:/";
|
return "redirect:/gruppen2";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,9 +9,7 @@ import lombok.Value;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
|
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
String user_id;
|
String user_id;
|
||||||
|
|
||||||
String givenname;
|
String givenname;
|
||||||
String familyname;
|
String familyname;
|
||||||
String email;
|
String email;
|
||||||
|
|||||||
@ -17,4 +17,9 @@ public class UpdateGroupDescriptionEvent extends Event {
|
|||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
this.newGroupDescription = newGroupDescription;
|
this.newGroupDescription = newGroupDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UpdateGroupDescriptionEvent(Long group_id, String user_id, String newGroupDescription) {
|
||||||
|
super(group_id, user_id);
|
||||||
|
this.newGroupDescription = newGroupDescription;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,4 +17,9 @@ public class UpdateGroupTitleEvent extends Event {
|
|||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
this.newGroupTitle = newGroupTitle;
|
this.newGroupTitle = newGroupTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UpdateGroupTitleEvent(Long group_id, String user_id, String newGroupTitle) {
|
||||||
|
super(group_id, user_id);
|
||||||
|
this.newGroupTitle = newGroupTitle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,12 @@ import java.util.List;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
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")
|
||||||
|
List<Long> findGroup_idsWhereUser_id(@Param("id") String user_id);
|
||||||
|
|
||||||
|
@Query("select * from event where group_id =:id")
|
||||||
|
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long group_id);
|
||||||
|
|
||||||
@Query("SELECT * FROM event WHERE event_id > :status")
|
@Query("SELECT * FROM event WHERE event_id > :status")
|
||||||
public Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
public Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||||
|
|
||||||
|
|||||||
29
src/main/java/mops/gruppen2/service/ControllerService.java
Normal file
29
src/main/java/mops/gruppen2/service/ControllerService.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.GroupType;
|
||||||
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
import mops.gruppen2.domain.event.*;
|
||||||
|
import mops.gruppen2.security.Account;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ControllerService {
|
||||||
|
|
||||||
|
private final EventService eventService;
|
||||||
|
|
||||||
|
public ControllerService(EventService eventService) {
|
||||||
|
this.eventService = eventService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createGroup(Account account, String title, String beschreibung) {
|
||||||
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), account.getName(), null , GroupType.LECTURE, Visibility.PUBLIC);
|
||||||
|
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||||
|
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title);
|
||||||
|
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), beschreibung);
|
||||||
|
|
||||||
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
eventService.saveEvent(addUserEvent);
|
||||||
|
eventService.saveEvent(updateGroupTitleEvent);
|
||||||
|
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,13 +20,20 @@ public class EventService {
|
|||||||
this.eventStore = eventStore;
|
this.eventStore = eventStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** sichert ein Event Objekt indem es ein EventDTO Objekt erzeugt
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
public void saveEvent(Event event){
|
public void saveEvent(Event event){
|
||||||
EventDTO eventDTO = getDTO(event);
|
EventDTO eventDTO = getDTO(event);
|
||||||
eventStore.save(eventDTO);
|
eventStore.save(eventDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Erzeugt aus einem Event Objekt ein EventDTO Objekt
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
* @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());
|
||||||
@ -39,6 +46,10 @@ public class EventService {
|
|||||||
return eventDTO;
|
return eventDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sorgt dafür die Group_id immer um 1 zu erhöhen
|
||||||
|
*
|
||||||
|
* @return Gibt Long zurück
|
||||||
|
*/
|
||||||
public Long checkGroup() {
|
public Long checkGroup() {
|
||||||
Long tmpId = 1L;
|
Long tmpId = 1L;
|
||||||
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
Iterable<EventDTO> eventDTOS = eventStore.findAll();
|
||||||
@ -53,7 +64,11 @@ public class EventService {
|
|||||||
return tmpId;
|
return tmpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Findet alle Events welche ab dem neuen Status hinzugekommen sind
|
||||||
|
*
|
||||||
|
* @param status
|
||||||
|
* @return Liste von Events
|
||||||
|
*/
|
||||||
public List<Event> getNewEvents(Long status){
|
public List<Event> getNewEvents(Long status){
|
||||||
Iterable<EventDTO> newEventDTOS = eventStore.findNewEventSinceStatus(status);
|
Iterable<EventDTO> newEventDTOS = eventStore.findNewEventSinceStatus(status);
|
||||||
List<Long> groupIdsThatChanged = this.getAllGroupIds(newEventDTOS);
|
List<Long> groupIdsThatChanged = this.getAllGroupIds(newEventDTOS);
|
||||||
@ -62,7 +77,12 @@ public class EventService {
|
|||||||
return translateEventDTOs(groupEventDTOS);
|
return translateEventDTOs(groupEventDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS){
|
/** Erzeugt aus der Datenbank eine Liste von Events
|
||||||
|
*
|
||||||
|
* @param eventDTOS
|
||||||
|
* @return Liste von Events
|
||||||
|
*/
|
||||||
|
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS){
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
|
|
||||||
for (EventDTO eventDTO : eventDTOS) {
|
for (EventDTO eventDTO : eventDTOS) {
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.EventDTO;
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -14,11 +16,23 @@ import java.util.Map;
|
|||||||
public class GroupService {
|
public class GroupService {
|
||||||
|
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final EventRepository eventRepository;
|
||||||
|
|
||||||
public GroupService(EventService eventService) {
|
public GroupService(EventService eventService, EventRepository eventRepository) {
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
|
this.eventRepository = eventRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Event> getGroupEvents(List<Long> group_ids) {
|
||||||
|
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||||
|
List<Event> events = new ArrayList<>();
|
||||||
|
for (Long group_id: group_ids) {
|
||||||
|
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id));
|
||||||
|
}
|
||||||
|
return events = eventService.translateEventDTOs(eventDTOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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<>();
|
||||||
|
|||||||
27
src/main/java/mops/gruppen2/service/UserService.java
Normal file
27
src/main/java/mops/gruppen2/service/UserService.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
|
||||||
|
final EventRepository eventRepository;
|
||||||
|
final GroupService groupService;
|
||||||
|
|
||||||
|
public UserService(EventRepository eventRepository, GroupService groupService) {
|
||||||
|
this.eventRepository = eventRepository;
|
||||||
|
this.groupService = groupService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Group> getUserGroups(String user_id) throws EventException {
|
||||||
|
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user_id);
|
||||||
|
List<Event> events = groupService.getGroupEvents(group_ids);
|
||||||
|
return groupService.projectEventList(events);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -28,9 +28,11 @@
|
|||||||
<h1>Meine Gruppen</h1>
|
<h1>Meine Gruppen</h1>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<form action="/" method="get">
|
<form action="/" method="get">
|
||||||
<div style="border: 10px solid aliceblue; background: aliceblue">
|
<div th:each="gruppe: ${gruppen}">
|
||||||
<h4 style="color: dodgerblue; font-weight: bold">Titel der Gruppe</h4>
|
<div style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
<p>Beschreibung der Gruppe ...</p>
|
<h4 th:href="url" style="color: dodgerblue; font-weight: bold" th:text="${gruppe.getTitle()}"></h4>
|
||||||
|
<p th:text="${gruppe.getDescription()}"></p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
||||||
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
@ -9,28 +8,28 @@ 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.DeleteGroupEvent;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.configuration.IMockitoConfiguration;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
class GroupServiceTest {
|
class GroupServiceTest {
|
||||||
GroupService groupService;
|
GroupService groupService;
|
||||||
|
EventRepository eventRepository;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
groupService = new GroupService(mock(EventService.class));
|
groupService = new GroupService(mock(EventService.class), eventRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
void applyEventOnGroupThatIsDeleted() throws Exception {
|
void applyEventOnGroupThatIsDeleted() throws Exception {
|
||||||
List<Event> eventList = new ArrayList<>();
|
List<Event> eventList = new ArrayList<>();
|
||||||
@ -47,6 +46,7 @@ class GroupServiceTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
void returnDeletedGroup() throws Exception {
|
void returnDeletedGroup() throws Exception {
|
||||||
List<Event> eventList = new ArrayList<>();
|
List<Event> eventList = new ArrayList<>();
|
||||||
@ -70,5 +70,4 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
assertThat(groupService.projectEventList(eventList).get(0)).isInstanceOf(Group.class);
|
assertThat(groupService.projectEventList(eventList).get(0)).isInstanceOf(Group.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user