1

Merge remote-tracking branch 'origin/master' into updateGroupsAPI

# Conflicts:
#	src/main/java/mops/gruppen2/service/EventService.java
This commit is contained in:
LukasEttel
2020-03-13 13:52:53 +01:00
11 changed files with 73 additions and 34 deletions

View File

@ -80,7 +80,7 @@ public class Gruppen2Controller {
Account account = keyCloakService.createAccountFromPrincipal(token);
controllerService.createGroup(account, title, beschreibung);
return "redirect:/gruppen2";
return "redirect:/gruppen2/";
}
}

View File

@ -0,0 +1,13 @@
package mops.gruppen2.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MopsController {
@GetMapping("")
public String redirect(){
return "redirect:/gruppen2/";
}
}

View File

@ -15,7 +15,11 @@ public class UpdateRoleEvent extends Event {
public UpdateRoleEvent(Long event_id, Long group_id, String user_id, Role newRole) {
super(event_id, group_id, user_id);
this.newRole = newRole;
}
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
super(group_id, user_id);
this.newRole = newRole;
}
}

View File

@ -1,10 +1,12 @@
package mops.gruppen2.service;
import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.*;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class ControllerService {
@ -15,15 +17,24 @@ public class ControllerService {
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);
/**
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
* Aus diesen Event Objekten wird eine Liste erzeugt, welche daraufhin mithilfe des EventServices gesichert wird.
*
* @param account Keycloak-Account
* @param title Gruppentitel
* @param description Gruppenbeschreibung
*/
public void createGroup(Account account, String title, String description) {
eventService.saveEvent(createGroupEvent);
eventService.saveEvent(addUserEvent);
eventService.saveEvent(updateGroupTitleEvent);
eventService.saveEvent(updateGroupDescriptionEvent);
List<Event> eventList = new ArrayList<>();
Collections.addAll(eventList, new CreateGroupEvent(eventService.checkGroup(), account.getName(), null , GroupType.LECTURE, Visibility.PUBLIC),
new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()),
new UpdateRoleEvent(eventService.checkGroup(), account.getName(), Role.ADMIN),
new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title),
new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), description));
eventService.saveEventList(eventList);
}
}

View File

@ -95,6 +95,17 @@ public class EventService {
return events;
}
/**
* Sichert eine Liste von Event Objekten mithilfe der Methode saveEvent(Event event)
*
* @param createGroupEvents Liste von Event Objekten
*/
public void saveEventList(List<Event> createGroupEvents) {
for(Event event : createGroupEvents) {
saveEvent(event);
}
}
public Long getMaxEvent_id(){
return eventStore.getHighesEvent_ID();
}

View File

@ -22,11 +22,25 @@ public class SerializationService {
this.eventStore = eventStore;
}
/**
* Übersetzt mithilfe der Jackson-Library eine Java-Event-Repräsentation zu einem JSON-Event-Payload.
*
* @param event Java-Event-Repräsentation
* @return JSON-Event-Payload als String
* @throws JsonProcessingException
*/
public String serializeEvent(Event event) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(event);
}
/**
* Übersetzt mithilfe der Jackson-Library einen JSON-Event-Payload zu einer Java-Event-Repräsentation.
*
* @param json JSON-Event-Payload als String
* @return Java-Event-Repräsentation
* @throws JsonProcessingException
*/
public Event deserializeEvent(String json) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, Event.class);

View File

@ -19,6 +19,8 @@ public class UserService {
this.groupService = groupService;
}
//Test nötig??
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);