Merge branch 'event-db' into html-gruppe
# Conflicts: # src/main/java/mops/gruppen2/controller/Gruppen2Controller.java # src/main/java/mops/gruppen2/entities/Teilnehmer.java
This commit is contained in:
@ -14,7 +14,7 @@ endif::[]
|
|||||||
== Gruppenbildung
|
== Gruppenbildung
|
||||||
|
|
||||||
Für das Abschlussprojekt bilden Sie bitte eine Gruppe im GitHub Classroom, die
|
Für das Abschlussprojekt bilden Sie bitte eine Gruppe im GitHub Classroom, die
|
||||||
aus 7 bis 9 Personen besteht und laden eine entsprechende `gruppe.yml` in AUAS
|
aus 7 bis 9 Personen besteht und laden eine entsprechende `group.yml` in AUAS
|
||||||
hoch. Im Gegensatz zu den normalen Blättern haben Sie volle
|
hoch. Im Gegensatz zu den normalen Blättern haben Sie volle
|
||||||
Administrationsrechte und alle Projekte sind öffentlich um den Austausch mit
|
Administrationsrechte und alle Projekte sind öffentlich um den Austausch mit
|
||||||
anderen Gruppen bei Integrationen zwischen Anwendungen einfacher zu gestalten.
|
anderen Gruppen bei Integrationen zwischen Anwendungen einfacher zu gestalten.
|
||||||
@ -22,18 +22,18 @@ anderen Gruppen bei Integrationen zwischen Anwendungen einfacher zu gestalten.
|
|||||||
IMPORTANT: Bitte entfernen Sie nicht die Organisatoren aus Ihrem Projekt.
|
IMPORTANT: Bitte entfernen Sie nicht die Organisatoren aus Ihrem Projekt.
|
||||||
|
|
||||||
NOTE: Sie finden neben dieser README eine
|
NOTE: Sie finden neben dieser README eine
|
||||||
link:gruppe.yml[Beispiel-Gruppe-YML-Datei]. Füllen Sie diese aus, checken Sie
|
link:group.yml[Beispiel-Gruppe-YML-Datei]. Füllen Sie diese aus, checken Sie
|
||||||
sie ein.
|
sie ein.
|
||||||
|
|
||||||
IMPORTANT: Erstellen Sie direkt eine Abgabe in AUAS. Diese ist *essentiell* für
|
IMPORTANT: Erstellen Sie direkt eine Abgabe in AUAS. Diese ist *essentiell* für
|
||||||
die Teilnahme am Praktikum. Diesmal muss die Abgabe eine ZIP-Datei sein. Die
|
die Teilnahme am Praktikum. Diesmal muss die Abgabe eine ZIP-Datei sein. Die
|
||||||
ZIP-Datei soll die `gruppe.yml` und eine _optionale_ Beschreibung eines eigenen
|
ZIP-Datei soll die `group.yml` und eine _optionale_ Beschreibung eines eigenen
|
||||||
Systems für MOPS beinhalten. Sie können natürlich auch einfach die
|
Systems für MOPS beinhalten. Sie können natürlich auch einfach die
|
||||||
vorgeschlagenen Systeme wählen und müssen keine eigenen Systeme entwerfen.
|
vorgeschlagenen Systeme wählen und müssen keine eigenen Systeme entwerfen.
|
||||||
|
|
||||||
== Systeme
|
== Systeme
|
||||||
|
|
||||||
*Die folgenden Beschreibungen sind keine Spezifikationen, die den Funktionsumfang der Projekte festlegen,* sondern nur ein "Braindump" von den Ideen, die mir zu dem entsprechenden System gekommen sind. Die Beschreibungen sollen Ihnen primär helfen, Systeme auszusuchen, die Sie umsetzen möchten. Wenn Sie einen eigenen Vorschlag für ein System haben, können Sie das auch gerne vorschlagen. Sie müssen dann zusammen mit der `gruppe.yml` Datei einen kurzen Pitch (in etwa wie in diesem Dokument) einreichen, damit wir uns vorstellen können, was Sie machen wollen und den Umfang begutachten.
|
*Die folgenden Beschreibungen sind keine Spezifikationen, die den Funktionsumfang der Projekte festlegen,* sondern nur ein "Braindump" von den Ideen, die mir zu dem entsprechenden System gekommen sind. Die Beschreibungen sollen Ihnen primär helfen, Systeme auszusuchen, die Sie umsetzen möchten. Wenn Sie einen eigenen Vorschlag für ein System haben, können Sie das auch gerne vorschlagen. Sie müssen dann zusammen mit der `group.yml` Datei einen kurzen Pitch (in etwa wie in diesem Dokument) einreichen, damit wir uns vorstellen können, was Sie machen wollen und den Umfang begutachten.
|
||||||
|
|
||||||
=== Online Modulhandbuch
|
=== Online Modulhandbuch
|
||||||
Im Modulhandbuch werden die Beschreibungen für Veranstaltungen angegeben. Die Beschreibungen werden von den Dozierenden angelegt und werden von einer Verantwortlichen geprüft und dann freigeschaltet.
|
Im Modulhandbuch werden die Beschreibungen für Veranstaltungen angegeben. Die Beschreibungen werden von den Dozierenden angelegt und werden von einer Verantwortlichen geprüft und dann freigeschaltet.
|
||||||
|
|||||||
26
build.gradle
26
build.gradle
@ -4,11 +4,18 @@ plugins {
|
|||||||
id 'org.springframework.boot' version '2.2.5.RELEASE'
|
id 'org.springframework.boot' version '2.2.5.RELEASE'
|
||||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'com.github.spotbugs' version "3.0.0"
|
|
||||||
|
id 'com.github.spotbugs' version '3.0.0'
|
||||||
id 'checkstyle'
|
id 'checkstyle'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group = 'mops'
|
||||||
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
sourceCompatibility = '11'
|
||||||
|
|
||||||
spotbugs{
|
spotbugs{
|
||||||
ignoreFailures = true
|
ignoreFailures = true
|
||||||
|
reportLevel = "high"
|
||||||
effort = "max"
|
effort = "max"
|
||||||
toolVersion = '4.0.0-RC1'
|
toolVersion = '4.0.0-RC1'
|
||||||
}
|
}
|
||||||
@ -26,10 +33,6 @@ checkstyle {
|
|||||||
ignoreFailures = true
|
ignoreFailures = true
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'mops'
|
|
||||||
version = '0.0.1-SNAPSHOT'
|
|
||||||
sourceCompatibility = '11'
|
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
developmentOnly
|
developmentOnly
|
||||||
runtimeClasspath {
|
runtimeClasspath {
|
||||||
@ -56,20 +59,25 @@ dependencies {
|
|||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
|
||||||
implementation 'org.keycloak:keycloak-spring-boot-starter:9.0.0'
|
implementation 'org.keycloak:keycloak-spring-boot-starter:9.0.0'
|
||||||
implementation 'org.keycloak.bom:keycloak-adapter-bom:3.3.0.Final'
|
implementation 'org.keycloak.bom:keycloak-adapter-bom:3.3.0.Final'
|
||||||
implementation 'mops:styleguide:2.1.0'
|
implementation 'mops:styleguide:2.1.0'
|
||||||
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
|
implementation 'io.springfox:springfox-swagger2:2.9.2'
|
||||||
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
|
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
|
||||||
|
implementation 'com.github.javafaker:javafaker:1.0.2'
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
runtimeOnly 'com.h2database:h2'
|
runtimeOnly 'com.h2database:h2'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
|
||||||
|
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'
|
||||||
}
|
}
|
||||||
testImplementation 'org.springframework.security:spring-security-test'
|
testImplementation 'org.springframework.security:spring-security-test'
|
||||||
compile('org.springframework.boot:spring-boot-starter-web')
|
testImplementation 'com.tngtech.archunit:archunit-junit5:0.13.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|||||||
@ -229,13 +229,6 @@
|
|||||||
<property name="lineWrappingIndentation" value="8"/>
|
<property name="lineWrappingIndentation" value="8"/>
|
||||||
<property name="arrayInitIndent" value="4"/>
|
<property name="arrayInitIndent" value="4"/>
|
||||||
</module>
|
</module>
|
||||||
<module name="AbbreviationAsWordInName">
|
|
||||||
<property name="ignoreFinal" value="false"/>
|
|
||||||
<property name="allowedAbbreviationLength" value="1"/>
|
|
||||||
<property name="tokens"
|
|
||||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
|
|
||||||
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF"/>
|
|
||||||
</module>
|
|
||||||
<module name="OverloadMethodsDeclarationOrder"/>
|
<module name="OverloadMethodsDeclarationOrder"/>
|
||||||
<module name="VariableDeclarationUsageDistance"/>
|
<module name="VariableDeclarationUsageDistance"/>
|
||||||
<module name="MethodParamPad">
|
<module name="MethodParamPad">
|
||||||
|
|||||||
@ -3,11 +3,16 @@ package mops.gruppen2;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.service.Contact;
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableSwagger2
|
@EnableSwagger2
|
||||||
public class Gruppen2Application {
|
public class Gruppen2Application {
|
||||||
@ -16,8 +21,25 @@ public class Gruppen2Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket productAPI(){
|
public Docket productAPI() {
|
||||||
return new Docket(DocumentationType.SWAGGER_2).select()
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
.apis(RequestHandlerSelectors.basePackage("mops.gruppen2")).build();
|
.select()
|
||||||
|
.paths(PathSelectors.ant("/products/**"))
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("mops.gruppen2"))
|
||||||
|
.build()
|
||||||
|
.apiInfo(apiMetadata());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo apiMetadata() {
|
||||||
|
return new ApiInfo(
|
||||||
|
"Gruppenbildung API",
|
||||||
|
"API zum anfragen/aktualisieren der Gruppendaten.",
|
||||||
|
"0.0.1",
|
||||||
|
"Free to use",
|
||||||
|
new Contact("gruppen2", "https://github.com/hhu-propra2/abschlussprojekt-it-bois", ""),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
Collections.emptyList()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
|
import mops.gruppen2.service.KeyCloakService;
|
||||||
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import javax.annotation.security.RolesAllowed;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/gruppen2")
|
||||||
|
public class Gruppen2Controller {
|
||||||
|
|
||||||
|
private final KeyCloakService keyCloakService;
|
||||||
|
|
||||||
|
public Gruppen2Controller(KeyCloakService keyCloakService) {
|
||||||
|
this.keyCloakService = keyCloakService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Zeigt die index.html an.
|
||||||
|
*
|
||||||
|
* @param token toller token
|
||||||
|
* @param model tolles model
|
||||||
|
* @return index.html
|
||||||
|
*/
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@GetMapping("")
|
||||||
|
public String index(KeycloakAuthenticationToken token, Model model) {
|
||||||
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
return "index";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.github.javafaker.Faker;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import mops.gruppen2.domain.ProductSwaggerExample;
|
||||||
|
import mops.gruppen2.domain.event.AddUserEvent;
|
||||||
|
import mops.gruppen2.service.SerializationService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Beispiel für eine API mit Swagger.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/products")
|
||||||
|
public class SwaggerAPIControllerExample {
|
||||||
|
|
||||||
|
private final Faker faker = new Faker();
|
||||||
|
private final List<ProductSwaggerExample> products = new ArrayList<>();
|
||||||
|
private final SerializationService serializationService;
|
||||||
|
|
||||||
|
public SwaggerAPIControllerExample(SerializationService serializationService) {
|
||||||
|
this.serializationService = serializationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/all")
|
||||||
|
@ApiOperation(value = "Erzeugt eine Liste mit allen gespeicherten Produkten")
|
||||||
|
public List<ProductSwaggerExample> getProducts() {
|
||||||
|
return products;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/{index}")
|
||||||
|
public ProductSwaggerExample getProduct(@ApiParam("Produkt Index") @PathVariable int index) {
|
||||||
|
return products.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/save")
|
||||||
|
public String saveProduct(@RequestBody ProductSwaggerExample product) {
|
||||||
|
products.add(product);
|
||||||
|
|
||||||
|
return "Product saved successfully";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/random")
|
||||||
|
public String saveRandomProduct() {
|
||||||
|
products.add(new ProductSwaggerExample(faker.food().ingredient(), "Empty"));
|
||||||
|
|
||||||
|
return "Product saved successfully";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@GetMapping("/json") //just for testing
|
||||||
|
public void json() {
|
||||||
|
AddUserEvent aEvent = new AddUserEvent(
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
"Eins",
|
||||||
|
faker.leagueOfLegends().location(),
|
||||||
|
faker.name().lastName(),
|
||||||
|
"123@email.de");
|
||||||
|
try {
|
||||||
|
serializationService.serializeEvent(aEvent);
|
||||||
|
serializationService.saveEvent(aEvent);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@ -1,64 +0,0 @@
|
|||||||
package mops.gruppen2.controllers;
|
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
|
||||||
|
|
||||||
import mops.gruppen2.entities.Gruppe;
|
|
||||||
import mops.gruppen2.security.Account;
|
|
||||||
import org.keycloak.KeycloakPrincipal;
|
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.context.annotation.SessionScope;
|
|
||||||
|
|
||||||
@SessionScope
|
|
||||||
@Controller
|
|
||||||
public class Gruppen2Controller {
|
|
||||||
/**
|
|
||||||
* Creates an Account.
|
|
||||||
*
|
|
||||||
* @param token Ein toller token
|
|
||||||
* @return Account with current userdata
|
|
||||||
*/
|
|
||||||
private Account createAccountFromPrincipal(KeycloakAuthenticationToken token) {
|
|
||||||
KeycloakPrincipal principal = (KeycloakPrincipal) token.getPrincipal();
|
|
||||||
return new Account(
|
|
||||||
principal.getName(),
|
|
||||||
principal.getKeycloakSecurityContext().getIdToken().getEmail(),
|
|
||||||
null,
|
|
||||||
principal.getKeycloakSecurityContext().getIdToken().getGivenName(),
|
|
||||||
principal.getKeycloakSecurityContext().getIdToken().getFamilyName(),
|
|
||||||
token.getAccount().getRoles());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Zeigt die index.html an.
|
|
||||||
*
|
|
||||||
* @param token toller token
|
|
||||||
* @param model tolles model
|
|
||||||
* @return index.html
|
|
||||||
*/
|
|
||||||
@GetMapping("/")
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
|
||||||
public String index(KeycloakAuthenticationToken token, Model model) {
|
|
||||||
model.addAttribute("account", createAccountFromPrincipal(token));
|
|
||||||
return "index";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/")
|
|
||||||
public String addGruppe(@ModelAttribute Gruppe gruppe) {
|
|
||||||
System.out.println(gruppe);
|
|
||||||
return "redirect:/";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/createGroup")
|
|
||||||
public String createGruppe(){
|
|
||||||
return "create";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/findGroup")
|
|
||||||
public String findGruppe(){
|
|
||||||
return "search";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
package mops.gruppen2.controllers;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class SwaggerAPIController {
|
|
||||||
@RequestMapping(value = "/products", method = RequestMethod.GET)
|
|
||||||
public List<String> getProducts(){
|
|
||||||
List<String> productList = new ArrayList<>();
|
|
||||||
productList.add("Honey");
|
|
||||||
productList.add("Almond");
|
|
||||||
return productList;
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/products", method = RequestMethod.POST)
|
|
||||||
public String createProduct() {
|
|
||||||
return "Product is saved successfully";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
39
src/main/java/mops/gruppen2/domain/Aggregate.java
Normal file
39
src/main/java/mops/gruppen2/domain/Aggregate.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repräsentiert viele Events als aggregiertes Objekt.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public abstract class Aggregate {
|
||||||
|
|
||||||
|
protected long id;
|
||||||
|
|
||||||
|
public void apply(List<Event> events) {
|
||||||
|
events.forEach(this::applyEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply(Event event) {
|
||||||
|
applyEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ruft die spezifische applyEvent-Methode im entsprechenden Aggregat auf.
|
||||||
|
*
|
||||||
|
* @param event Event, welches aggregiert wird
|
||||||
|
*/
|
||||||
|
private void applyEvent(Event event) {
|
||||||
|
try {
|
||||||
|
Method method = this.getClass().getDeclaredMethod("applyEvent", event.getClass());
|
||||||
|
method.setAccessible(true);
|
||||||
|
method.invoke(this, event);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/main/java/mops/gruppen2/domain/EventDTO.java
Normal file
16
src/main/java/mops/gruppen2/domain/EventDTO.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Value;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
|
@Table("event")
|
||||||
|
@Data
|
||||||
|
public class EventDTO {
|
||||||
|
@Id
|
||||||
|
long event_id;
|
||||||
|
long group_id;
|
||||||
|
String user_id;
|
||||||
|
String event_payload;
|
||||||
|
}
|
||||||
74
src/main/java/mops/gruppen2/domain/Group.java
Normal file
74
src/main/java/mops/gruppen2/domain/Group.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import mops.gruppen2.domain.event.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repräsentiert den aggregierten Zustand einer Gruppe.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Getter
|
||||||
|
public class Group extends Aggregate {
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private final List<User> members;
|
||||||
|
private final Map<User, Role> roles;
|
||||||
|
|
||||||
|
public Group() {
|
||||||
|
this.members = new ArrayList<>();
|
||||||
|
this.roles = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyEvent(CreateGroupEvent event) {
|
||||||
|
title = event.getGroupTitle();
|
||||||
|
description = event.getGroupDescription();
|
||||||
|
id = event.getGroup_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyEvent(UpdateRoleEvent event) {
|
||||||
|
User user;
|
||||||
|
|
||||||
|
Optional<User> userOptional = members.stream()
|
||||||
|
.filter(u -> u.getUser_id().equals(event.getUser_id()))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
if (userOptional.isPresent()) {
|
||||||
|
user = userOptional.get();
|
||||||
|
} else {
|
||||||
|
System.out.println("UserNotFoundException");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roles.containsKey(user) && event.getNewRole() == Role.STUDENT) {
|
||||||
|
roles.remove(user);
|
||||||
|
} else {
|
||||||
|
roles.put(user, event.getNewRole());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyEvent(AddUserEvent event) {
|
||||||
|
User user = new User(event.getUser_id(), event.getGivenname(), event.getFamilyname(), event.getEmail());
|
||||||
|
|
||||||
|
this.members.add(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyEvent(UpdateGroupTitleEvent event) {
|
||||||
|
this.title = event.getNewGroupTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyEvent(UpdateGroupDescriptionEvent event) {
|
||||||
|
this.description = event.getNewGroupDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyEvent(DeleteUserEvent event) {
|
||||||
|
for (User user : members) {
|
||||||
|
if (user.getUser_id().equals(event.getUser_id())) {
|
||||||
|
this.members.remove(user);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
// @ApiModelProperty
|
||||||
|
@Value
|
||||||
|
public class ProductSwaggerExample {
|
||||||
|
|
||||||
|
// @ApiModelProperty
|
||||||
|
String name;
|
||||||
|
String description;
|
||||||
|
}
|
||||||
5
src/main/java/mops/gruppen2/domain/Role.java
Normal file
5
src/main/java/mops/gruppen2/domain/Role.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
public enum Role {
|
||||||
|
ORGA, ADMIN, STUDENT
|
||||||
|
}
|
||||||
14
src/main/java/mops/gruppen2/domain/User.java
Normal file
14
src/main/java/mops/gruppen2/domain/User.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
String user_id;
|
||||||
|
String givenname;
|
||||||
|
String familyname;
|
||||||
|
String email;
|
||||||
|
}
|
||||||
30
src/main/java/mops/gruppen2/domain/event/AddUserEvent.java
Normal file
30
src/main/java/mops/gruppen2/domain/event/AddUserEvent.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Value;
|
||||||
|
import mops.gruppen2.domain.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fügt einen einzelnen Nutzer einer Gruppe hinzu.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Value
|
||||||
|
public class AddUserEvent extends Event {
|
||||||
|
String givenname;
|
||||||
|
String familyname;
|
||||||
|
String email;
|
||||||
|
|
||||||
|
public AddUserEvent(long event_id, long group_id, String user_id, String givenname, String familyname, String email) {
|
||||||
|
super(event_id, group_id, user_id);
|
||||||
|
this.givenname = givenname;
|
||||||
|
this.familyname = familyname;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddUserEvent(long event_id, long group_id, User user) {
|
||||||
|
super(event_id, group_id, user.getUser_id());
|
||||||
|
this.givenname = user.getGivenname();
|
||||||
|
this.familyname = user.getFamilyname();
|
||||||
|
this.email = user.getEmail();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Value
|
||||||
|
public class CreateGroupEvent extends Event {
|
||||||
|
String groupTitle;
|
||||||
|
String groupDescription;
|
||||||
|
|
||||||
|
public CreateGroupEvent(long event_id, long group_id, String user_id, String groupTitle, String groupDescription) {
|
||||||
|
super(event_id, group_id, user_id);
|
||||||
|
this.groupTitle = groupTitle;
|
||||||
|
this.groupDescription = groupDescription;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entfernt ein einzelnes Mitglied einer Gruppe.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Value
|
||||||
|
public class DeleteUserEvent extends Event {
|
||||||
|
|
||||||
|
public DeleteUserEvent(long event_id, long group_id, String user_id) {
|
||||||
|
super(event_id, group_id, user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/main/java/mops/gruppen2/domain/event/Event.java
Normal file
14
src/main/java/mops/gruppen2/domain/event/Event.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import lombok.Value;
|
||||||
|
import lombok.experimental.NonFinal;
|
||||||
|
|
||||||
|
@Value
|
||||||
|
@NonFinal
|
||||||
|
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
|
||||||
|
public class Event {
|
||||||
|
long event_id;
|
||||||
|
long group_id;
|
||||||
|
String user_id;
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ändert nur die Gruppenbeschreibung.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Value
|
||||||
|
public class UpdateGroupDescriptionEvent extends Event {
|
||||||
|
String newGroupDescription;
|
||||||
|
|
||||||
|
public UpdateGroupDescriptionEvent(long event_id, long group_id, String user_id, String newGroupDescription) {
|
||||||
|
super(event_id, group_id, user_id);
|
||||||
|
this.newGroupDescription = newGroupDescription;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ändert nur den Gruppentitel.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Value
|
||||||
|
public class UpdateGroupTitleEvent extends Event {
|
||||||
|
String newGroupTitle;
|
||||||
|
|
||||||
|
public UpdateGroupTitleEvent(long event_id, long group_id, String user_id, String newGroupTitle) {
|
||||||
|
super(event_id, group_id, user_id);
|
||||||
|
this.newGroupTitle = newGroupTitle;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Value;
|
||||||
|
import mops.gruppen2.domain.Role;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktualisiert die Gruppenrolle eines Teilnehmers.
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Value
|
||||||
|
public class UpdateRoleEvent extends Event {
|
||||||
|
|
||||||
|
Role newRole;
|
||||||
|
|
||||||
|
public UpdateRoleEvent(long event_id, long group_id, String user_id, Role newRole) {
|
||||||
|
super(event_id, group_id, user_id);
|
||||||
|
|
||||||
|
this.newRole = newRole;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +0,0 @@
|
|||||||
package mops.gruppen2.entities;
|
|
||||||
|
|
||||||
public class Admin extends Rolle {
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
package mops.gruppen2.entities;
|
|
||||||
|
|
||||||
import mops.gruppen2.events.Event;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public abstract class Aggregat {
|
|
||||||
|
|
||||||
public void applyEvent(Event event) {
|
|
||||||
try {
|
|
||||||
Method method = this.getClass().getDeclaredMethod("applyEvent", event.getClass());
|
|
||||||
method.setAccessible(true);
|
|
||||||
method.invoke(this, event);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
package mops.gruppen2.entities;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import mops.gruppen2.events.CreateGroupEvent;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class Gruppe extends Aggregat {
|
|
||||||
long id;
|
|
||||||
String titel;
|
|
||||||
String beschreibung;
|
|
||||||
List<Teilnehmer> teilnehmersList;
|
|
||||||
|
|
||||||
public void applyEvent(CreateGroupEvent event){
|
|
||||||
this.id = event.getId();
|
|
||||||
this.titel = event.getTitel();
|
|
||||||
this.beschreibung = event.getBeschreibung();
|
|
||||||
this.teilnehmersList= null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
package mops.gruppen2.entities;
|
|
||||||
|
|
||||||
public class Orga extends Rolle {
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package mops.gruppen2.entities;
|
|
||||||
|
|
||||||
public class Rolle {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
package mops.gruppen2.entities;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class Teilnehmer {
|
|
||||||
@Id
|
|
||||||
Long id;
|
|
||||||
String vorname;
|
|
||||||
String nachname;
|
|
||||||
String email;
|
|
||||||
List<Gruppe> Gruppen;
|
|
||||||
|
|
||||||
public Teilnehmer(String vorname, String nachname) {
|
|
||||||
this.vorname = vorname;
|
|
||||||
this.nachname = nachname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package mops.gruppen2.events;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class CreateGroupEvent extends Event {
|
|
||||||
String titel;
|
|
||||||
String beschreibung;
|
|
||||||
|
|
||||||
public CreateGroupEvent(long id, long gruppe_id, long user_id, String titel, String beschreibung) {
|
|
||||||
super(id, gruppe_id, user_id);
|
|
||||||
this.titel = titel;
|
|
||||||
this.beschreibung = beschreibung;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package mops.gruppen2.events;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Event {
|
|
||||||
long id;
|
|
||||||
long gruppe_id;
|
|
||||||
long user_id;
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
package mops.gruppen2.repositories;
|
|
||||||
|
|
||||||
import mops.gruppen2.events.Event;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
|
|
||||||
public interface EventRepository extends CrudRepository<Event, Long> {
|
|
||||||
}
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package mops.gruppen2.repository;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.EventDTO;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||||
|
}
|
||||||
@ -6,7 +6,11 @@ import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticatio
|
|||||||
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
|
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
|
||||||
import org.keycloak.representations.AccessToken;
|
import org.keycloak.representations.AccessToken;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.*;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.context.annotation.ScopedProxyMode;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
|
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
|
||||||
@ -70,8 +74,6 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
|||||||
http.headers().frameOptions().disable();
|
http.headers().frameOptions().disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declaring this class enables us to use the Spring specific
|
* Declaring this class enables us to use the Spring specific
|
||||||
* {@link org.springframework.security.access.annotation.Secured} annotation
|
* {@link org.springframework.security.access.annotation.Secured} annotation
|
||||||
|
|||||||
23
src/main/java/mops/gruppen2/service/GroupService.java
Normal file
23
src/main/java/mops/gruppen2/service/GroupService.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GroupService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruiert eine vollständige Gruppe aus Events, welche dieselbe Gruppe betreffen.
|
||||||
|
*
|
||||||
|
* @param eventList Die Events für diese Gruppe
|
||||||
|
* @return Gruppe auf aktuellem Stand
|
||||||
|
*/
|
||||||
|
Group buildGroupFromEvents(List<Event> eventList) {
|
||||||
|
Group newGroup = new Group();
|
||||||
|
newGroup.apply(eventList);
|
||||||
|
return newGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package mops.gruppen2.services;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.keycloak.KeycloakPrincipal;
|
import org.keycloak.KeycloakPrincipal;
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import mops.gruppen2.domain.EventDTO;
|
||||||
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Übersetzt JSON-Event-Payloads zu Java-Event-Repräsentationen und zurück.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SerializationService {
|
||||||
|
|
||||||
|
private final EventRepository eventStore;
|
||||||
|
private final Logger log = LoggerFactory.getLogger(SerializationService.class);
|
||||||
|
|
||||||
|
public SerializationService(EventRepository eventStore) {
|
||||||
|
this.eventStore = eventStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serializeEvent(Event event) throws JsonProcessingException {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String json = mapper.writeValueAsString(event);
|
||||||
|
log.info(json);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveEvent(Event event){
|
||||||
|
try {
|
||||||
|
EventDTO eventDTO = new EventDTO();
|
||||||
|
eventDTO.setGroup_id(event.getGroup_id());
|
||||||
|
eventDTO.setUser_id(event.getUser_id());
|
||||||
|
eventDTO.setEvent_payload(serializeEvent(event));
|
||||||
|
eventStore.save(eventDTO);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package mops.gruppen2.services;
|
|
||||||
|
|
||||||
import mops.gruppen2.events.CreateGroupEvent;
|
|
||||||
import mops.gruppen2.events.Event;
|
|
||||||
import mops.gruppen2.entities.Gruppe;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class GruppenService {
|
|
||||||
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L,1L,1L,"hello", "foo");
|
|
||||||
|
|
||||||
public GruppenService(){
|
|
||||||
List<Event> eventList = new ArrayList<>();
|
|
||||||
eventList.add(createGroupEvent);
|
|
||||||
Gruppe newGroup = buildGroup(eventList);
|
|
||||||
System.out.println(newGroup.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Gruppe buildGroup(List<Event> eventList){
|
|
||||||
Gruppe newGroup = new Gruppe();
|
|
||||||
eventList.forEach(newGroup::applyEvent);
|
|
||||||
return newGroup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package mops.gruppen2.services;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Übersetzt und baut
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class SerializationService {
|
|
||||||
}
|
|
||||||
@ -14,4 +14,3 @@ keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth
|
|||||||
keycloak.realm=MOPS
|
keycloak.realm=MOPS
|
||||||
keycloak.resource=demo
|
keycloak.resource=demo
|
||||||
keycloak.public-client=true
|
keycloak.public-client=true
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
-- noinspection SqlNoDataSourceInspectionForFile
|
|
||||||
|
|
||||||
insert into TEILNEHMER (VORNAME, NACHNAME, EMAIL) values
|
|
||||||
('Peter', 'Müller', 'Peter@123.de');
|
|
||||||
@ -1,25 +1,11 @@
|
|||||||
-- noinspection SqlNoDataSourceInspectionForFile
|
-- noinspection SqlNoDataSourceInspectionForFile
|
||||||
|
|
||||||
DROP TABLE IF EXISTS teilnehmer;
|
DROP TABLE IF EXISTS event;
|
||||||
CREATE TABLE teilnehmer (
|
|
||||||
teilnehmer_id INT PRIMARY KEY AUTO_INCREMENT,
|
|
||||||
vorname VARCHAR(50) NOT NULL,
|
|
||||||
nachname VARCHAR(50) NOT NULL ,
|
|
||||||
email VARCHAR(255) NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS gruppe;
|
CREATE TABLE event
|
||||||
CREATE TABLE gruppe
|
|
||||||
(
|
(
|
||||||
gruppe_id INTEGER PRIMARY KEY auto_increment,
|
event_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
titel TEXT NOT NULL,
|
group_id INT NOT NULL,
|
||||||
beschreibung TEXT NOT NULL
|
user_id VARCHAR(50),
|
||||||
);
|
event_payload VARCHAR(255)
|
||||||
|
|
||||||
DROP TABLE IF EXISTS teilnahme;
|
|
||||||
CREATE TABLE teilnahme
|
|
||||||
(
|
|
||||||
id INTEGER PRIMARY KEY auto_increment,
|
|
||||||
teilnehmer_dto INTEGER REFERENCES teilnehmer(teilnehmer_id),
|
|
||||||
gruppe_dto INTEGER REFERENCES gruppe(gruppe_id)
|
|
||||||
);
|
);
|
||||||
|
|||||||
78
src/test/java/mops/gruppen2/domain/GroupTest.java
Normal file
78
src/test/java/mops/gruppen2/domain/GroupTest.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.event.AddUserEvent;
|
||||||
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
|
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class GroupTest {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp(){
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Disabled
|
||||||
|
@Test
|
||||||
|
void applyEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createSingleGroup() {
|
||||||
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,2, "asd", "hello", "foo");
|
||||||
|
|
||||||
|
Group group = new Group();
|
||||||
|
group.apply(createGroupEvent);
|
||||||
|
|
||||||
|
assertThat(group.getDescription()).isEqualTo("foo");
|
||||||
|
assertThat(group.getTitle()).isEqualTo("hello");
|
||||||
|
assertThat(group.getId()).isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verwendet CreateGroupEvent
|
||||||
|
@Test
|
||||||
|
void addSingleUser() {
|
||||||
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1,"prof1", "hi", "foo");
|
||||||
|
Group group = new Group();
|
||||||
|
group.apply(createGroupEvent);
|
||||||
|
|
||||||
|
User user = new User("prof", "jens", "bendi", "hi@gmail.com");
|
||||||
|
AddUserEvent addUserEvent = new AddUserEvent(1,1, user);
|
||||||
|
group.apply(addUserEvent);
|
||||||
|
|
||||||
|
assertThat(group.getMembers().get(0)).isEqualTo(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verwendet CreateGroupEvent und AddUserEvent
|
||||||
|
@Test
|
||||||
|
void updateRoleForExistingUser() {
|
||||||
|
// Arrange
|
||||||
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "1L", "gruppe1", "Eine Testgruppe");
|
||||||
|
AddUserEvent addUserEvent = new AddUserEvent(1L, 1L, "5L", "Peter", "Pan", "123@mail.de");
|
||||||
|
|
||||||
|
Group group = new Group();
|
||||||
|
group.apply(createGroupEvent);
|
||||||
|
group.apply(addUserEvent);
|
||||||
|
|
||||||
|
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(1L, 1L, "5L", Role.ORGA);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
group.apply(updateRoleEvent);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertThat(group.getRoles())
|
||||||
|
.containsOnlyKeys(group.getMembers().get(0))
|
||||||
|
.containsValue(Role.ORGA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Disabled
|
||||||
|
@Test
|
||||||
|
void updateRoleForNonExistingUser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package mops.gruppen2.entities;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class GruppeTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void applyEvent() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user