Merge pull request #159 from hhu-propra2/REFACTOR-checkstyle-java-warnings
Refactor checkstyle java warnings
This commit is contained in:
5
.github/workflows/gradle.yml
vendored
5
.github/workflows/gradle.yml
vendored
@ -4,13 +4,18 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
paths-ignore:
|
||||
- 'documentation/**'
|
||||
- 'mysql/**'
|
||||
- 'README.adoc'
|
||||
- 'Dockerfile'
|
||||
- 'docker-compose.yaml'
|
||||
- '.gitignore'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
127
build.gradle
127
build.gradle
@ -1,90 +1,103 @@
|
||||
import com.github.spotbugs.SpotBugsTask
|
||||
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.2.5.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '2.2.5.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
||||
id 'java'
|
||||
|
||||
id 'com.github.spotbugs' version '3.0.0'
|
||||
id 'checkstyle'
|
||||
id 'com.github.spotbugs' version '3.0.0'
|
||||
id 'checkstyle'
|
||||
id 'pmd'
|
||||
}
|
||||
|
||||
group = 'mops'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '11'
|
||||
|
||||
spotbugs{
|
||||
ignoreFailures = true
|
||||
reportLevel = "high"
|
||||
effort = "max"
|
||||
toolVersion = '4.0.0-RC1'
|
||||
spotbugs {
|
||||
ignoreFailures = true
|
||||
reportLevel = "high"
|
||||
effort = "max"
|
||||
toolVersion = '4.0.0-RC1'
|
||||
}
|
||||
|
||||
tasks.withType(SpotBugsTask) {
|
||||
reports {
|
||||
xml.enabled = false
|
||||
html.enabled = true
|
||||
}
|
||||
reports {
|
||||
xml.enabled = false
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
pmd {
|
||||
consoleOutput = true
|
||||
ignoreFailures = true
|
||||
toolVersion = "6.21.0"
|
||||
rulePriority = 5
|
||||
ruleSets = ["category/java/errorprone.xml",
|
||||
"category/java/bestpractices.xml",
|
||||
"category/java/security.xml",
|
||||
"category/java/performance.xml",
|
||||
"category/java/design.xml"]
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "8.28"
|
||||
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
|
||||
ignoreFailures = true
|
||||
toolVersion = "8.28"
|
||||
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
|
||||
ignoreFailures = true
|
||||
}
|
||||
|
||||
configurations {
|
||||
developmentOnly
|
||||
runtimeClasspath {
|
||||
extendsFrom developmentOnly
|
||||
}
|
||||
compileOnly {
|
||||
extendsFrom annotationProcessor
|
||||
}
|
||||
developmentOnly
|
||||
runtimeClasspath {
|
||||
extendsFrom developmentOnly
|
||||
}
|
||||
compileOnly {
|
||||
extendsFrom annotationProcessor
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://s3.cs.hhu.de/public/mops/'
|
||||
metadataSources {
|
||||
artifact()
|
||||
}
|
||||
}
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = 'https://s3.cs.hhu.de/public/mops/'
|
||||
metadataSources {
|
||||
artifact()
|
||||
}
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
|
||||
implementation 'org.springframework.security.oauth:spring-security-oauth2:2.4.0.RELEASE'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
|
||||
implementation 'org.springframework.security.oauth:spring-security-oauth2:2.4.0.RELEASE'
|
||||
|
||||
implementation 'org.keycloak:keycloak-spring-boot-starter:9.0.0'
|
||||
implementation 'org.keycloak.bom:keycloak-adapter-bom:9.0.0'
|
||||
implementation 'mops:styleguide:2.1.0'
|
||||
implementation 'io.springfox:springfox-swagger2:2.9.2'
|
||||
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
|
||||
implementation 'com.github.javafaker:javafaker:1.0.2'
|
||||
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.3'
|
||||
implementation 'org.keycloak:keycloak-spring-boot-starter:9.0.0'
|
||||
implementation 'org.keycloak.bom:keycloak-adapter-bom:9.0.0'
|
||||
implementation 'mops:styleguide:2.1.0'
|
||||
implementation 'io.springfox:springfox-swagger2:2.9.2'
|
||||
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
|
||||
implementation 'com.github.javafaker:javafaker:1.0.2'
|
||||
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.3'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
runtimeOnly 'com.h2database:h2'
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
runtimeOnly 'com.h2database:h2'
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
|
||||
testImplementation 'org.assertj:assertj-core:3.15.0'
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
testImplementation 'org.springframework.security:spring-security-test'
|
||||
testImplementation 'com.tngtech.archunit:archunit-junit5:0.13.1'
|
||||
testImplementation 'org.assertj:assertj-core:3.15.0'
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
testImplementation 'org.springframework.security:spring-security-test'
|
||||
testImplementation 'com.tngtech.archunit:archunit-junit5:0.13.1'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@
|
||||
<property name="lineWrappingIndentation" value="8"/>
|
||||
<property name="arrayInitIndent" value="4"/>
|
||||
</module>
|
||||
<module name="VariableDeclarationUsageDistance"/>
|
||||
<!-- <module name="VariableDeclarationUsageDistance"/>-->
|
||||
<module name="MethodParamPad">
|
||||
<property name="tokens"
|
||||
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
|
||||
|
@ -1,17 +0,0 @@
|
||||
package mops.gruppen2.config;
|
||||
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class Gruppen2Config {
|
||||
|
||||
final GroupService groupService;
|
||||
final EventService eventService;
|
||||
|
||||
public Gruppen2Config(GroupService groupService, EventService eventService) {
|
||||
this.groupService = groupService;
|
||||
this.eventService = eventService;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package mops.gruppen2.security;
|
||||
package mops.gruppen2.config;
|
||||
|
||||
import org.keycloak.OAuth2Constants;
|
||||
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
|
||||
@ -42,4 +42,4 @@ public class KeycloakConfig {
|
||||
|
||||
return new OAuth2RestTemplate(resourceDetails);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package mops.gruppen2.security;
|
||||
package mops.gruppen2.config;
|
||||
|
||||
import org.keycloak.KeycloakPrincipal;
|
||||
import org.keycloak.adapters.springsecurity.KeycloakSecurityComponents;
|
||||
@ -33,8 +33,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
public void configureGlobal(AuthenticationManagerBuilder auth) {
|
||||
KeycloakAuthenticationProvider keycloakAuthenticationProvider
|
||||
= keycloakAuthenticationProvider();
|
||||
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
|
||||
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
|
||||
auth.authenticationProvider(keycloakAuthenticationProvider);
|
||||
}
|
||||
@ -42,28 +41,26 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
@Bean
|
||||
@Override
|
||||
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
|
||||
return new RegisterSessionAuthenticationStrategy(
|
||||
new SessionRegistryImpl());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public AccessToken getAccessToken() {
|
||||
HttpServletRequest request =
|
||||
((ServletRequestAttributes) RequestContextHolder
|
||||
.currentRequestAttributes()).getRequest();
|
||||
return ((KeycloakPrincipal) request.getUserPrincipal())
|
||||
.getKeycloakSecurityContext().getToken();
|
||||
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
super.configure(http);
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/actuator/**")
|
||||
.hasRole("monitoring")
|
||||
.anyRequest()
|
||||
.permitAll();
|
||||
.antMatchers("/actuator/**")
|
||||
.hasRole("monitoring")
|
||||
.anyRequest()
|
||||
.permitAll();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public AccessToken getAccessToken() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
|
||||
.currentRequestAttributes()).getRequest();
|
||||
return ((KeycloakPrincipal) request.getUserPrincipal())
|
||||
.getKeycloakSecurityContext().getToken();
|
||||
}
|
||||
|
||||
/**
|
@ -24,6 +24,8 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* Ein Beispiel für eine API mit Swagger.
|
||||
*/
|
||||
//TODO: Testing
|
||||
//TODO: API-Service
|
||||
@RestController
|
||||
@RequestMapping("/gruppen2/api")
|
||||
public class APIController {
|
||||
@ -40,16 +42,16 @@ public class APIController {
|
||||
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
||||
@ApiOperation("Gibt alle Gruppen zurück, in denen sich etwas geändert hat")
|
||||
public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
|
||||
return APIFormatterService.wrap(eventService.getMaxEvent_id(), groupService.projectEventList(events));
|
||||
return APIFormatterService.wrap(eventService.getMaxEventId(), groupService.projectEventList(events));
|
||||
}
|
||||
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
||||
@ApiOperation("Gibt alle Gruppen zurück, in denen sich ein Teilnehmer befindet")
|
||||
public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
|
||||
return userService.getUserGroups(teilnehmer).stream()
|
||||
.map(group -> group.getId().toString())
|
||||
|
@ -0,0 +1,120 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
public class GroupCreationController {
|
||||
|
||||
private final GroupService groupService;
|
||||
private final ControllerService controllerService;
|
||||
private final ValidationService validationService;
|
||||
|
||||
public GroupCreationController(GroupService groupService, ControllerService controllerService, ValidationService validationService) {
|
||||
this.groupService = groupService;
|
||||
this.controllerService = controllerService;
|
||||
this.validationService = validationService;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@GetMapping("/createOrga")
|
||||
public String createGroupAsOrga(KeycloakAuthenticationToken token,
|
||||
Model model) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||
|
||||
return "createOrga";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@PostMapping("/createOrga")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam(value = "lecture", required = false) Boolean lecture,
|
||||
@RequestParam("userMaximum") Long userMaximum,
|
||||
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers,
|
||||
@RequestParam(value = "parent", required = false) String parent,
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
|
||||
controllerService.createGroupAsOrga(account,
|
||||
title,
|
||||
description,
|
||||
visibility,
|
||||
lecture,
|
||||
maxInfiniteUsers,
|
||||
userMaximum,
|
||||
parentUUID,
|
||||
file);
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
|
||||
@RolesAllowed("ROLE_studentin")
|
||||
@GetMapping("/createStudent")
|
||||
public String createGroupAsStudent(KeycloakAuthenticationToken token,
|
||||
Model model) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||
|
||||
return "createStudent";
|
||||
}
|
||||
|
||||
@RolesAllowed("ROLE_studentin")
|
||||
@PostMapping("/createStudent")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("userMaximum") Long userMaximum,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers,
|
||||
@RequestParam(value = "parent", required = false) String parent) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
|
||||
controllerService.createGroup(account,
|
||||
title,
|
||||
description,
|
||||
visibility,
|
||||
null,
|
||||
maxInfiniteUsers,
|
||||
userMaximum,
|
||||
parentUUID);
|
||||
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
}
|
@ -0,0 +1,276 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
public class GroupDetailsController {
|
||||
|
||||
private final ControllerService controllerService;
|
||||
private final UserService userService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
|
||||
public GroupDetailsController(ControllerService controllerService, UserService userService, ValidationService validationService, InviteService inviteService) {
|
||||
this.controllerService = controllerService;
|
||||
this.userService = userService;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
UUID parentId = group.getParent();
|
||||
String actualURL = request.getRequestURL().toString();
|
||||
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||
Group parent = controllerService.getParent(parentId);
|
||||
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
|
||||
model.addAttribute("account", account);
|
||||
if (!validationService.checkIfUserInGroup(group, user)) {
|
||||
validationService.throwIfNoAccessToPrivate(group, user);
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
|
||||
if (validationService.checkIfAdmin(group, user)) {
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroupId(group.getId()));
|
||||
}
|
||||
|
||||
return "detailsMember";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/changeMetadata/{id}")
|
||||
public String changeMetadata(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("title", group.getTitle());
|
||||
model.addAttribute("description", group.getDescription());
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("groupId", group.getId());
|
||||
model.addAttribute("user", user);
|
||||
|
||||
return "changeMetadata";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/changeMetadata")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postChangeMetadata(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("groupId") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
validationService.checkFields(title, description);
|
||||
|
||||
controllerService.changeMetaData(account, group, title, description);
|
||||
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/members/{id}")
|
||||
public String editMembers(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User user = new User(account);
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("members", group.getMembers());
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
|
||||
return "editMembers";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/changeRole")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeRole(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User principle = new User(account);
|
||||
User user = new User(userId, "", "", "");
|
||||
|
||||
validationService.throwIfNoAdmin(group, principle);
|
||||
|
||||
controllerService.changeRole(account, user, group);
|
||||
|
||||
if (!validationService.checkIfAdmin(group, principle)) {
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/changeMaximum")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeMaxSize(KeycloakAuthenticationToken token,
|
||||
@RequestParam("maximum") Long maximum,
|
||||
@RequestParam("group_id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNewMaximumIsValid(maximum, group);
|
||||
|
||||
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
|
||||
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/deleteUser")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String deleteUser(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User principle = new User(account);
|
||||
User user = new User(userId, "", "", "");
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, principle);
|
||||
|
||||
controllerService.deleteUser(account, user, group);
|
||||
|
||||
if (!validationService.checkIfUserInGroup(group, principle)) {
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String joinGroup(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||
validationService.throwIfGroupFull(group);
|
||||
|
||||
controllerService.addUser(account, UUID.fromString(groupId));
|
||||
|
||||
model.addAttribute("account", account);
|
||||
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/leaveGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String leaveGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
controllerService.deleteUser(account, user, group);
|
||||
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/deleteGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String deleteGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
||||
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/addUsersFromCsv")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String addUsersFromCsv(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
controllerService.addUsersFromCsv(account, file, groupId);
|
||||
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
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 javax.annotation.security.RolesAllowed;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller
|
||||
public class GruppenfindungController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public GruppenfindungController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public String redirect() {
|
||||
return "redirect:/gruppen2";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/gruppen2")
|
||||
public String index(KeycloakAuthenticationToken token,
|
||||
Model model) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||
model.addAttribute("user", user);
|
||||
|
||||
return "index";
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public String logout(HttpServletRequest request) throws ServletException {
|
||||
request.logout();
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@GetMapping("/gruppen2/*")
|
||||
public String defaultLink() throws PageNotFoundException {
|
||||
throw new PageNotFoundException("\uD83D\uDE41");
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller
|
||||
public class MopsController {
|
||||
|
||||
@GetMapping("")
|
||||
public String redirect() {
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public String logout(HttpServletRequest request) throws Exception {
|
||||
request.logout();
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() throws EventException {
|
||||
throw new PageNotFoundException("\uD83D\uDE41");
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
public class SearchAndInviteController {
|
||||
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
|
||||
public SearchAndInviteController(ValidationService validationService, InviteService inviteService, UserService userService, ControllerService controllerService) {
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/findGroup")
|
||||
public String findGroup(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam(value = "suchbegriff", required = false) String search) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
List<Group> groups = new ArrayList<>();
|
||||
groups = validationService.checkSearch(search, groups, account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", groups);
|
||||
model.addAttribute("inviteService", inviteService);
|
||||
|
||||
return "search";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/detailsSearch")
|
||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = controllerService.getParent(parentId);
|
||||
User user = new User(account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
if (validationService.checkIfUserInGroup(group, user)) {
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("link") String link) {
|
||||
|
||||
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
|
||||
model.addAttribute("account", KeyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("group", group);
|
||||
|
||||
if (group.getVisibility() == Visibility.PUBLIC) {
|
||||
return "redirect:/gruppen2/details/" + group.getId();
|
||||
}
|
||||
|
||||
return "joinprivate";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/acceptinvite")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postAcceptInvite(KeycloakAuthenticationToken token,
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account account = KeyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||
validationService.throwIfGroupFull(group);
|
||||
|
||||
controllerService.addUser(account, UUID.fromString(groupId));
|
||||
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
}
|
@ -1,429 +0,0 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
public class WebController {
|
||||
|
||||
private final KeyCloakService keyCloakService;
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
|
||||
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService, InviteService inviteService) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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("gruppen", userService.getUserGroups(user));
|
||||
model.addAttribute("user", user);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@GetMapping("/createOrga")
|
||||
public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||
return "createOrga";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@PostMapping("/createOrga")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam(value = "lecture", required = false) Boolean lecture,
|
||||
@RequestParam("userMaximum") Long userMaximum,
|
||||
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers,
|
||||
@RequestParam(value = "parent", required = false) String parent,
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
|
||||
controllerService.createGroupAsOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_studentin"})
|
||||
@GetMapping("/createStudent")
|
||||
public String createGroupAsStudent(KeycloakAuthenticationToken token, Model model) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||
return "createStudent";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_studentin"})
|
||||
@PostMapping("/createStudent")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam("userMaximum") Long userMaximum,
|
||||
@RequestParam(value = "maxInfiniteUsers", required = false) Boolean maxInfiniteUsers,
|
||||
@RequestParam(value = "parent", required = false) String parent) {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
|
||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||
|
||||
controllerService.createGroup(account, title, description, visibility, null, maxInfiniteUsers, userMaximum, parentUUID);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/addUsersFromCsv")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String addUsersFromCsv(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
controllerService.addUsersFromCsv(account, file, groupId);
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/changeMetadata/{id}")
|
||||
public String changeMetadata(KeycloakAuthenticationToken token, Model model, @PathVariable("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = new Group();
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("title", group.getTitle());
|
||||
model.addAttribute("description", group.getDescription());
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("groupId", group.getId());
|
||||
model.addAttribute("user", user);
|
||||
return "changeMetadata";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/changeMetadata")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postChangeMetadata(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("groupId") String groupId) {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
validationService.checkFields(title, description);
|
||||
|
||||
controllerService.changeMetaData(account, group, title, description);
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/findGroup")
|
||||
public String findGroup(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam(value = "suchbegriff", required = false) String search) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<Group> groups = new ArrayList<>();
|
||||
groups = validationService.checkSearch(search, groups, account);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", groups);
|
||||
model.addAttribute("inviteService", inviteService);
|
||||
return "search";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
@PathVariable("id") String groupId) {
|
||||
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
UUID parentId = group.getParent();
|
||||
String actualURL = request.getRequestURL().toString();
|
||||
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||
Group parent = controllerService.getParent(parentId);
|
||||
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
|
||||
model.addAttribute("account", account);
|
||||
if (!validationService.checkIfUserInGroup(group, user)) {
|
||||
validationService.throwIfNoAccessToPrivate(group, user);
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
|
||||
if (validationService.checkIfAdmin(group, user)) {
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroupId(group.getId()));
|
||||
}
|
||||
return "detailsMember";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String joinGroup(KeycloakAuthenticationToken token,
|
||||
Model model, @RequestParam("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||
validationService.throwIfGroupFull(group);
|
||||
|
||||
controllerService.addUser(account, UUID.fromString(groupId));
|
||||
|
||||
model.addAttribute("account", account);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/detailsSearch")
|
||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@RequestParam("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = controllerService.getParent(parentId);
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
|
||||
model.addAttribute("account", account);
|
||||
if (validationService.checkIfUserInGroup(group, user)){
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
//TODO: Muss post-mapping sein
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("link") String link) {
|
||||
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||
|
||||
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("group", group);
|
||||
|
||||
if (group.getVisibility() == Visibility.PUBLIC) {
|
||||
return "redirect:/gruppen2/details/" + group.getId();
|
||||
}
|
||||
|
||||
return "joinprivate";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/acceptinvite")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postAcceptInvite(KeycloakAuthenticationToken token,
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account acc = keyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
|
||||
|
||||
if (!validationService.checkIfUserInGroup(userService.getGroupById(UUID.fromString(groupId)), user)) {
|
||||
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
|
||||
}
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/leaveGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
controllerService.deleteUser(account, user, group);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/deleteGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pDeleteGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/members/{id}")
|
||||
public String editMembers(Model model,
|
||||
KeycloakAuthenticationToken token,
|
||||
@PathVariable("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
|
||||
validationService.throwIfNoAdmin(group, user);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("members", group.getMembers());
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
return "editMembers";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/changeRole")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeRole(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
User principle = new User(account.getName(), "", "", "");
|
||||
User user = new User(userId, "", "", "");
|
||||
|
||||
validationService.throwIfNoAdmin(group, principle);
|
||||
|
||||
controllerService.changeRole(account, user, group);
|
||||
|
||||
group = userService.getGroupById(UUID.fromString(groupId));
|
||||
if (!validationService.checkIfAdmin(group, principle)) {
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/changeMaximum")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeMaxSize(@RequestParam("maximum") Long maximum,
|
||||
@RequestParam("group_id") String groupId,
|
||||
KeycloakAuthenticationToken token) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNewMaximumIsValid(maximum, group);
|
||||
|
||||
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/members/deleteUser")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String deleteUser(@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId,
|
||||
KeycloakAuthenticationToken token) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User principle = new User(account.getName(), "", "", "");
|
||||
User user = new User(userId, "", "", "");
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
validationService.throwIfNoAdmin(group, principle);
|
||||
|
||||
controllerService.deleteUser(account, user, group);
|
||||
|
||||
if (!validationService.checkIfUserInGroup(group, principle)) {
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() throws EventException {
|
||||
throw new PageNotFoundException("\uD83D\uDE41");
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package mops.gruppen2.security;
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
import lombok.Value;
|
||||
|
@ -16,6 +16,7 @@ import java.util.UUID;
|
||||
@Setter
|
||||
public class Group {
|
||||
|
||||
//TODO: List to Hashmap
|
||||
private final List<User> members;
|
||||
private final Map<String, Role> roles;
|
||||
private UUID id;
|
||||
@ -27,8 +28,8 @@ public class Group {
|
||||
private UUID parent;
|
||||
|
||||
public Group() {
|
||||
this.members = new ArrayList<>();
|
||||
this.roles = new HashMap<>();
|
||||
members = new ArrayList<>();
|
||||
roles = new HashMap<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
public enum GroupType {
|
||||
SIMPLE, LECTURE
|
||||
SIMPLE,
|
||||
LECTURE
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
public enum Role {
|
||||
ADMIN, MEMBER
|
||||
ADMIN,
|
||||
MEMBER
|
||||
}
|
||||
|
@ -15,4 +15,11 @@ public class User {
|
||||
private String givenname;
|
||||
private String familyname;
|
||||
private String email;
|
||||
|
||||
public User(Account account) {
|
||||
id = account.getName();
|
||||
givenname = account.getGivenname();
|
||||
familyname = account.getFamilyname();
|
||||
email = account.getEmail();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
public enum Visibility {
|
||||
PUBLIC, PRIVATE
|
||||
PUBLIC,
|
||||
PRIVATE
|
||||
}
|
||||
|
@ -39,13 +39,13 @@ public abstract class Event {
|
||||
applyEvent(group);
|
||||
}
|
||||
|
||||
protected abstract void applyEvent(Group group) throws EventException;
|
||||
|
||||
private void checkGroupIdMatch(UUID groupId) {
|
||||
if (groupId == null || this.groupId.equals(groupId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new GroupIdMismatchException(this.getClass().toString());
|
||||
throw new GroupIdMismatchException(getClass().toString());
|
||||
}
|
||||
|
||||
protected abstract void applyEvent(Group group) throws EventException;
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ public class UpdateGroupTitleEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) {
|
||||
if (this.getNewGroupTitle().isEmpty()) {
|
||||
throw new NoValueException(this.getClass().toString());
|
||||
if (newGroupTitle.isEmpty()) {
|
||||
throw new NoValueException(getClass().toString());
|
||||
}
|
||||
|
||||
group.setTitle(this.newGroupTitle);
|
||||
group.setTitle(newGroupTitle);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||
@NoArgsConstructor
|
||||
public class UpdateUserMaxEvent extends Event {
|
||||
|
||||
private Long userMaximum;
|
||||
private Long userMaximum;
|
||||
|
||||
public UpdateUserMaxEvent(UUID groupId, String userId, Long userMaximum) {
|
||||
super(groupId, userId);
|
||||
@ -22,6 +22,6 @@ public class UpdateUserMaxEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
group.setUserMaximum(this.userMaximum);
|
||||
group.setUserMaximum(userMaximum);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package mops.gruppen2.domain.exception;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
public abstract class EventException extends ResponseStatusException {
|
||||
public class EventException extends ResponseStatusException {
|
||||
|
||||
public EventException(HttpStatus status, String msg, String info) {
|
||||
super(status, msg + " (" + info + ")");
|
||||
|
@ -3,6 +3,7 @@ package mops.gruppen2.domain.exception;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class WrongFileException extends EventException {
|
||||
|
||||
public WrongFileException(String info) {
|
||||
super(HttpStatus.BAD_REQUEST, "Die entsprechende Datei ist keine valide CSV-Datei!", info);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
@Query("SELECT * FROM event WHERE event_type = :type")
|
||||
List<EventDTO> findAllEventsByType(@Param("type") String type);
|
||||
|
||||
@Query("SELECT * FROM event WHERE event_type = :type AND user_id = :userId")
|
||||
@Query("SELECT * FROM event WHERE event_type = :type AND user_id = :userId")
|
||||
List<EventDTO> findEventsByTypeAndUserId(@Param("type") String type, @Param("userId") String userId);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM event WHERE event_type = :type AND group_id = :groupId")
|
||||
|
@ -7,7 +7,9 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class APIFormatterService {
|
||||
public final class APIFormatterService {
|
||||
|
||||
private APIFormatterService() {}
|
||||
|
||||
public static GroupRequestWrapper wrap(Long status, List<Group> groupList) {
|
||||
return new GroupRequestWrapper(status, groupList);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
@ -14,18 +15,17 @@ import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import mops.gruppen2.domain.exception.WrongFileException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static mops.gruppen2.domain.Role.ADMIN;
|
||||
@ -34,30 +34,115 @@ import static mops.gruppen2.domain.Role.ADMIN;
|
||||
@Service
|
||||
public class ControllerService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger("controllerServiceLogger");
|
||||
private final EventService eventService;
|
||||
private final UserService userService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
private final Logger logger;
|
||||
|
||||
public ControllerService(EventService eventService, UserService userService, ValidationService validationService, InviteService inviteService) {
|
||||
this.eventService = eventService;
|
||||
this.userService = userService;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
this.logger = Logger.getLogger("controllerServiceLogger");
|
||||
}
|
||||
|
||||
private static User getVeteranMember(Account account, Group group) {
|
||||
List<User> members = group.getMembers();
|
||||
String newAdminId;
|
||||
if (members.get(0).getId().equals(account.getName())) {
|
||||
newAdminId = members.get(1).getId();
|
||||
} else {
|
||||
newAdminId = members.get(0).getId();
|
||||
}
|
||||
return new User(newAdminId, "", "", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wie createGroup, nur das hier die Gruppe auch als Veranstaltung gesetzt werden kann und CSV Dateien mit Nutzern
|
||||
* eingelesen werden können.
|
||||
*
|
||||
* @param account Der Nutzer der die Gruppe erstellt
|
||||
* @param title Parameter für die neue Gruppe
|
||||
* @param description Parameter für die neue Gruppe
|
||||
* @param isVisibilityPrivate Parameter für die neue Gruppe
|
||||
* @param isLecture Parameter für die neue Gruppe
|
||||
* @param isMaximumInfinite Parameter für die neue Gruppe
|
||||
* @param userMaximum Parameter für die neue Gruppe
|
||||
* @param parent Parameter für die neue Gruppe
|
||||
* @param file Parameter für die neue Gruppe
|
||||
*/
|
||||
public void createGroupAsOrga(Account account,
|
||||
String title,
|
||||
String description,
|
||||
Boolean isVisibilityPrivate,
|
||||
Boolean isLecture,
|
||||
Boolean isMaximumInfinite,
|
||||
Long userMaximum,
|
||||
UUID parent,
|
||||
MultipartFile file) {
|
||||
|
||||
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||
|
||||
List<User> newUsers = readCsvFile(file);
|
||||
|
||||
List<User> oldUsers = new ArrayList<>();
|
||||
User user = new User(account);
|
||||
oldUsers.add(user);
|
||||
|
||||
removeOldUsersFromNewUsers(oldUsers, newUsers);
|
||||
|
||||
userMaximum = adjustUserMaximum((long) newUsers.size(), 1L, userMaximum);
|
||||
|
||||
UUID groupId = createGroup(account,
|
||||
title,
|
||||
description,
|
||||
isVisibilityPrivate,
|
||||
isLecture,
|
||||
isMaximumInfinite,
|
||||
userMaximum, parent);
|
||||
|
||||
addUserList(newUsers, groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wenn die maximale Useranzahl unendlich ist, wird das Maximum auf 100000 gesetzt. Praktisch gibt es also Maximla 100000
|
||||
* Nutzer pro Gruppe.
|
||||
*
|
||||
* @param isMaximumInfinite Gibt an ob es unendlich viele User geben soll
|
||||
* @param userMaximum Das Maximum an Usern, falls es eins gibt
|
||||
*
|
||||
* @return Maximum an Usern
|
||||
*/
|
||||
private static Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) {
|
||||
isMaximumInfinite = isMaximumInfinite != null;
|
||||
|
||||
if (isMaximumInfinite) {
|
||||
userMaximum = 100_000L;
|
||||
}
|
||||
|
||||
return userMaximum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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 UUID createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent) {
|
||||
//TODO: remove booleans
|
||||
public UUID createGroup(Account account,
|
||||
String title,
|
||||
String description,
|
||||
Boolean isVisibilityPrivate,
|
||||
Boolean isLecture,
|
||||
Boolean isMaximumInfinite,
|
||||
Long userMaximum,
|
||||
UUID parent) {
|
||||
|
||||
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||
|
||||
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
|
||||
@ -65,7 +150,12 @@ public class ControllerService {
|
||||
|
||||
GroupType groupType = setGroupType(isLecture);
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId,
|
||||
account.getName(),
|
||||
parent,
|
||||
groupType,
|
||||
groupVisibility,
|
||||
userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
inviteService.createLink(groupId);
|
||||
@ -80,38 +170,95 @@ public class ControllerService {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wie createGroup, nur das hier die Gruppe auch als Veranstaltung gesetzt werden kann und CSV Dateien mit Nutzern
|
||||
* eingelesen werden können.
|
||||
* @param account Der Nutzer der die Gruppe erstellt
|
||||
* @param title Parameter für die neue Gruppe
|
||||
* @param description Parameter für die neue Gruppe
|
||||
* @param isVisibilityPrivate Parameter für die neue Gruppe
|
||||
* @param isLecture Parameter für die neue Gruppe
|
||||
* @param isMaximumInfinite Parameter für die neue Gruppe
|
||||
* @param userMaximum Parameter für die neue Gruppe
|
||||
* @param parent Parameter für die neue Gruppe
|
||||
* @param file Parameter für die neue Gruppe
|
||||
*/
|
||||
public void createGroupAsOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) {
|
||||
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
|
||||
|
||||
List<User> newUsers = readCsvFile(file);
|
||||
|
||||
List<User> oldUsers = new ArrayList<>();
|
||||
User user = new User(account.getName(), "", "", "");
|
||||
oldUsers.add(user);
|
||||
|
||||
removeOldUsersFromNewUsers(oldUsers, newUsers);
|
||||
|
||||
userMaximum = adjustUserMaximum((long) newUsers.size(), 1L, userMaximum);
|
||||
|
||||
UUID groupId = createGroup(account, title, description, isVisibilityPrivate, isLecture, isMaximumInfinite, userMaximum, parent);
|
||||
|
||||
addUserList(newUsers, groupId);
|
||||
private static List<User> readCsvFile(MultipartFile file) throws EventException {
|
||||
if (file == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
return userList.stream().distinct().collect(Collectors.toList()); //filters duplicates from list
|
||||
} catch (IOException ex) {
|
||||
LOG.warn("File konnte nicht gelesen werden");
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) throws IOException{
|
||||
private static void removeOldUsersFromNewUsers(List<User> oldUsers, List<User> newUsers) {
|
||||
for (User oldUser : oldUsers) {
|
||||
newUsers.remove(oldUser);
|
||||
}
|
||||
}
|
||||
|
||||
private static Long adjustUserMaximum(Long newUsers, Long oldUsers, Long maxUsers) {
|
||||
if (oldUsers + newUsers > maxUsers) {
|
||||
maxUsers = oldUsers + newUsers;
|
||||
}
|
||||
return maxUsers;
|
||||
}
|
||||
|
||||
private void addUserList(List<User> newUsers, UUID groupId) {
|
||||
for (User user : newUsers) {
|
||||
Group group = userService.getGroupById(groupId);
|
||||
if (group.getMembers().contains(user)) {
|
||||
LOG.info("Benutzer {} ist bereits in Gruppe", user.getId());
|
||||
} else {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, user.getId(), user.getGivenname(), user.getFamilyname(), user.getEmail());
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Visibility setGroupVisibility(Boolean isVisibilityPrivate) {
|
||||
isVisibilityPrivate = isVisibilityPrivate != null;
|
||||
|
||||
if (isVisibilityPrivate) {
|
||||
return Visibility.PRIVATE;
|
||||
} else {
|
||||
return Visibility.PUBLIC;
|
||||
}
|
||||
}
|
||||
|
||||
private static GroupType setGroupType(Boolean isLecture) {
|
||||
isLecture = isLecture != null;
|
||||
if (isLecture) {
|
||||
return GroupType.LECTURE;
|
||||
} else {
|
||||
return GroupType.SIMPLE;
|
||||
}
|
||||
}
|
||||
|
||||
public void addUser(Account account, UUID groupId) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
|
||||
private void updateTitle(Account account, UUID groupId, String title) {
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
|
||||
eventService.saveEvent(updateGroupTitleEvent);
|
||||
}
|
||||
|
||||
public void updateRole(User user, UUID groupId) throws EventException {
|
||||
UpdateRoleEvent updateRoleEvent;
|
||||
Group group = userService.getGroupById(groupId);
|
||||
validationService.throwIfNotInGroup(group, user);
|
||||
|
||||
if (group.getRoles().get(user.getId()) == ADMIN) {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), Role.MEMBER);
|
||||
} else {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), ADMIN);
|
||||
}
|
||||
eventService.saveEvent(updateRoleEvent);
|
||||
}
|
||||
|
||||
private void updateDescription(Account account, UUID groupId, String description) {
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
|
||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||
}
|
||||
|
||||
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) {
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
|
||||
List<User> newUserList = readCsvFile(file);
|
||||
@ -120,15 +267,24 @@ public class ControllerService {
|
||||
UUID groupUUID = getUUID(groupId);
|
||||
|
||||
Long newUserMaximum = adjustUserMaximum((long) newUserList.size(), (long) group.getMembers().size(), group.getUserMaximum());
|
||||
if (newUserMaximum > group.getUserMaximum()){
|
||||
if (newUserMaximum > group.getUserMaximum()) {
|
||||
updateMaxUser(account, groupUUID, newUserMaximum);
|
||||
}
|
||||
|
||||
addUserList(newUserList, groupUUID);
|
||||
}
|
||||
|
||||
public UUID getUUID(String id) {
|
||||
return UUID.fromString(Objects.requireNonNullElse(id, "00000000-0000-0000-0000-000000000000"));
|
||||
}
|
||||
|
||||
public void updateMaxUser(Account account, UUID groupId, Long userMaximum) {
|
||||
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId, account.getName(), userMaximum);
|
||||
eventService.saveEvent(updateUserMaxEvent);
|
||||
}
|
||||
|
||||
public void changeMetaData(Account account, Group group, String title, String description) {
|
||||
if (!title.equals(group.getTitle())){
|
||||
if (!title.equals(group.getTitle())) {
|
||||
updateTitle(account, group.getId(), title);
|
||||
}
|
||||
|
||||
@ -145,114 +301,6 @@ public class ControllerService {
|
||||
return parent;
|
||||
}
|
||||
|
||||
private void removeOldUsersFromNewUsers(List<User> oldUsers, List<User> newUsers) {
|
||||
for (User oldUser : oldUsers) {
|
||||
newUsers.remove(oldUser);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wenn die maximale Useranzahl unendlich ist, wird das Maximum auf 100000 gesetzt. Praktisch gibt es also Maximla 100000
|
||||
* Nutzer pro Gruppe.
|
||||
* @param isMaximumInfinite Gibt an ob es unendlich viele User geben soll
|
||||
* @param userMaximum Das Maximum an Usern, falls es eins gibt
|
||||
* @return Maximum an Usern
|
||||
*/
|
||||
private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) {
|
||||
isMaximumInfinite = isMaximumInfinite != null;
|
||||
|
||||
if (isMaximumInfinite) {
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
return userMaximum;
|
||||
}
|
||||
|
||||
private Visibility setGroupVisibility(Boolean isVisibilityPrivate) {
|
||||
isVisibilityPrivate = isVisibilityPrivate != null;
|
||||
|
||||
if (isVisibilityPrivate) {
|
||||
return Visibility.PRIVATE;
|
||||
} else {
|
||||
return Visibility.PUBLIC;
|
||||
}
|
||||
}
|
||||
|
||||
private GroupType setGroupType(Boolean isLecture) {
|
||||
isLecture = isLecture != null;
|
||||
if (isLecture) {
|
||||
return GroupType.LECTURE;
|
||||
} else {
|
||||
return GroupType.SIMPLE;
|
||||
}
|
||||
}
|
||||
|
||||
private List<User> readCsvFile(MultipartFile file) throws EventException{
|
||||
if(file == null) return new ArrayList<>();
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
return userList.stream().distinct().collect(Collectors.toList()); //filters duplicates from list
|
||||
} catch (IOException ex) {
|
||||
logger.warning("File konnte nicht gelesen werden");
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private Long adjustUserMaximum(Long newUsers, Long oldUsers, Long maxUsers) {
|
||||
if (oldUsers + newUsers > maxUsers) {
|
||||
maxUsers = oldUsers + newUsers;
|
||||
}
|
||||
return maxUsers;
|
||||
}
|
||||
|
||||
public void addUser(Account account, UUID groupId) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
|
||||
public void addUserList(List<User> newUsers, UUID groupId) {
|
||||
for (User user : newUsers) {
|
||||
Group group = userService.getGroupById(groupId);
|
||||
if (group.getMembers().contains(user)) {
|
||||
logger.info("Benutzer " + user.getId() + " ist bereits in Gruppe");
|
||||
} else {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(groupId, user.getId(), user.getGivenname(), user.getFamilyname(), user.getEmail());
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTitle(Account account, UUID groupId, String title) {
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
|
||||
eventService.saveEvent(updateGroupTitleEvent);
|
||||
}
|
||||
|
||||
public void updateDescription(Account account, UUID groupId, String description) {
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
|
||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||
}
|
||||
|
||||
public void updateMaxUser(Account account, UUID groupId, Long userMaximum) {
|
||||
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId, account.getName(), userMaximum);
|
||||
eventService.saveEvent(updateUserMaxEvent);
|
||||
}
|
||||
|
||||
public void updateRole(User user, UUID groupId) throws EventException {
|
||||
UpdateRoleEvent updateRoleEvent;
|
||||
Group group = userService.getGroupById(groupId);
|
||||
validationService.throwIfNotInGroup(group, user);
|
||||
|
||||
if (group.getRoles().get(user.getId()) == ADMIN) {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), Role.MEMBER);
|
||||
} else {
|
||||
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), ADMIN);
|
||||
}
|
||||
eventService.saveEvent(updateRoleEvent);
|
||||
}
|
||||
|
||||
public void deleteUser(Account account, User user, Group group) throws EventException {
|
||||
changeRoleIfLastAdmin(account, group);
|
||||
|
||||
@ -265,6 +313,14 @@ public class ControllerService {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean idIsEmpty(UUID id) {
|
||||
if (id == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return "00000000-0000-0000-0000-000000000000".equals(id.toString());
|
||||
}
|
||||
|
||||
private void deleteUserEvent(User user, UUID groupId) {
|
||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
|
||||
eventService.saveEvent(deleteUserEvent);
|
||||
@ -276,13 +332,6 @@ public class ControllerService {
|
||||
eventService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
public void changeRoleIfLastAdmin(Account account, Group group) {
|
||||
if (group.getMembers().size() <= 1) {
|
||||
return;
|
||||
}
|
||||
promoteVeteranMember(account, group);
|
||||
}
|
||||
|
||||
private void promoteVeteranMember(Account account, Group group) {
|
||||
if (validationService.checkIfLastAdmin(account, group)) {
|
||||
User newAdmin = getVeteranMember(account, group);
|
||||
@ -290,6 +339,13 @@ public class ControllerService {
|
||||
}
|
||||
}
|
||||
|
||||
public void changeRoleIfLastAdmin(Account account, Group group) {
|
||||
if (group.getMembers().size() <= 1) {
|
||||
return;
|
||||
}
|
||||
promoteVeteranMember(account, group);
|
||||
}
|
||||
|
||||
public void changeRole(Account account, User user, Group group) {
|
||||
if (user.getId().equals(account.getName())) {
|
||||
if (group.getMembers().size() <= 1) {
|
||||
@ -300,31 +356,4 @@ public class ControllerService {
|
||||
updateRole(user, group.getId());
|
||||
}
|
||||
|
||||
private User getVeteranMember(Account account, Group group) {
|
||||
List<User> members = group.getMembers();
|
||||
String newAdminId;
|
||||
if (members.get(0).getId().equals(account.getName())) {
|
||||
newAdminId = members.get(1).getId();
|
||||
} else {
|
||||
newAdminId = members.get(0).getId();
|
||||
}
|
||||
return new User(newAdminId, "", "", "");
|
||||
}
|
||||
|
||||
public UUID getUUID(String id) {
|
||||
if (id == null) {
|
||||
return UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
} else {
|
||||
return UUID.fromString(id);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean idIsEmpty(UUID id) {
|
||||
if (id == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return id.toString().equals("00000000-0000-0000-0000-000000000000");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CsvService {
|
||||
public final class CsvService {
|
||||
|
||||
public static List<User> read(InputStream stream) throws IOException {
|
||||
private CsvService() {}
|
||||
|
||||
static List<User> read(InputStream stream) throws IOException {
|
||||
CsvMapper mapper = new CsvMapper();
|
||||
|
||||
CsvSchema schema = mapper.schemaFor(User.class).withHeader().withColumnReordering(true);
|
||||
|
@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import mops.gruppen2.domain.dto.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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -15,6 +17,7 @@ import java.util.stream.Collectors;
|
||||
//TODO: Evtl aufsplitten in EventRepoService und EventService?
|
||||
public class EventService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EventService.class);
|
||||
private final JsonService jsonService;
|
||||
private final EventRepository eventStore;
|
||||
|
||||
@ -38,8 +41,40 @@ public class EventService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt aus einem Event Objekt ein EventDTO Objekt.
|
||||
*
|
||||
* @param event Event, welches in DTO übersetzt wird
|
||||
*
|
||||
* @return EventDTO (Neues DTO)
|
||||
*/
|
||||
public EventDTO getDTOFromEvent(Event event) {
|
||||
String payload = "";
|
||||
try {
|
||||
payload = JsonService.serializeEvent(event);
|
||||
} catch (JsonProcessingException e) {
|
||||
LOG.error("Event ({}) konnte nicht serialisiert werden!", event.getClass());
|
||||
}
|
||||
|
||||
return new EventDTO(null, event.getGroupId().toString(), event.getUserId(), getEventType(event), payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Eventtyp als String wieder.
|
||||
*
|
||||
* @param event Event dessen Typ abgefragt werden soll
|
||||
*
|
||||
* @return Der Name des Typs des Events
|
||||
*/
|
||||
private static String getEventType(Event event) {
|
||||
int lastDot = event.getClass().getName().lastIndexOf('.');
|
||||
|
||||
return event.getClass().getName().substring(lastDot + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert alle Events aus der übergebenen Liste in der DB.
|
||||
*
|
||||
* @param events Liste an Events die gespeichert werden soll
|
||||
*/
|
||||
@SafeVarargs
|
||||
@ -51,40 +86,12 @@ public class EventService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt aus einem Event Objekt ein EventDTO Objekt.
|
||||
* Ist die Gruppe öffentlich, dann wird die visibility auf true gesetzt.
|
||||
*
|
||||
* @param event Event, welches in DTO übersetzt wird
|
||||
* @return EventDTO (Neues DTO)
|
||||
*/
|
||||
public EventDTO getDTOFromEvent(Event event) {
|
||||
String payload = "";
|
||||
try {
|
||||
payload = jsonService.serializeEvent(event);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return new EventDTO(null, event.getGroupId().toString(), event.getUserId(), getEventType(event), payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Eventtyp als String wieder.
|
||||
* @param event Event dessen Typ abgefragt werden soll
|
||||
* @return Der Name des Typs des Events
|
||||
*/
|
||||
private String getEventType(Event event) {
|
||||
int lastDot = event.getClass().getName().lastIndexOf('.');
|
||||
|
||||
return event.getClass().getName().substring(lastDot + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Findet alle Events welche ab dem neuen Status hinzugekommen sind.
|
||||
* Sucht alle Events mit event_id > status
|
||||
*
|
||||
* @param status Die Id des zuletzt gespeicherten Events
|
||||
*
|
||||
* @return Liste von neueren Events
|
||||
*/
|
||||
public List<Event> getNewEvents(Long status) {
|
||||
@ -98,28 +105,31 @@ public class EventService {
|
||||
* Erzeugt aus einer Liste von eventDTOs eine Liste von Events.
|
||||
*
|
||||
* @param eventDTOS Liste von DTOs
|
||||
*
|
||||
* @return Liste von Events
|
||||
*/
|
||||
public List<Event> getEventsFromDTOs(Iterable<EventDTO> eventDTOS) {
|
||||
List<Event> getEventsFromDTOs(Iterable<EventDTO> eventDTOS) {
|
||||
List<Event> events = new ArrayList<>();
|
||||
|
||||
for (EventDTO eventDTO : eventDTOS) {
|
||||
try {
|
||||
events.add(jsonService.deserializeEvent(eventDTO.getEvent_payload()));
|
||||
events.add(JsonService.deserializeEvent(eventDTO.getEvent_payload()));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("Payload\n {}\n konnte nicht deserialisiert werden!", eventDTO.getEvent_payload());
|
||||
}
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
public Long getMaxEvent_id() {
|
||||
public Long getMaxEventId() {
|
||||
return eventStore.getHighesEventID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine Liste mit allen Events zurück, die zu der Gruppe gehören.
|
||||
*
|
||||
* @param groupId Gruppe die betrachtet werden soll
|
||||
*
|
||||
* @return Liste aus Events
|
||||
*/
|
||||
public List<Event> getEventsOfGroup(UUID groupId) {
|
||||
@ -128,24 +138,25 @@ public class EventService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine Liste aus GruppenIds zurück in denen sich der User befindet.
|
||||
* Gibt eine Liste aus GruppenIds zurück, in denen sich der User befindet.
|
||||
*
|
||||
* @param userId Die Id des Users
|
||||
*
|
||||
* @return Liste aus GruppenIds
|
||||
*/
|
||||
public List<UUID> findGroupIdsByUser(String userId) {
|
||||
return eventStore.findGroupIdsWhereUserId(userId, "AddUserEvent").stream()
|
||||
.map(UUID::fromString)
|
||||
.collect(Collectors.toList());
|
||||
return eventStore.findGroupIdsWhereUserId(userId, "AddUserEvent").stream().map(UUID::fromString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt true zurück, falls der User aktuell in der Gruppe ist, sonst false.
|
||||
*
|
||||
* @param groupId Id der Gruppe
|
||||
* @param userId Id des zu überprüfenden Users
|
||||
* @param userId Id des zu überprüfenden Users
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
public boolean userInGroup(UUID groupId, String userId) {
|
||||
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
|
||||
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
||||
boolean userInGroup(UUID groupId, String userId) {
|
||||
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent") > eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
@ -7,7 +8,6 @@ import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -34,9 +34,10 @@ public class GroupService {
|
||||
* Wandelt die Zeilen in Events um und gibt davon eine Liste zurück.
|
||||
*
|
||||
* @param groupIds Liste an IDs
|
||||
*
|
||||
* @return Liste an Events
|
||||
*/
|
||||
//TODO Das vielleicht in den EventRepoService?
|
||||
//TODO: Das vielleicht in den EventRepoService?
|
||||
public List<Event> getGroupEvents(List<UUID> groupIds) {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
for (UUID groupId : groupIds) {
|
||||
@ -45,65 +46,6 @@ public class GroupService {
|
||||
return eventService.getEventsFromDTOs(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 Liste an Events
|
||||
* @return Liste an Projizierten Gruppen
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
public List<Group> projectEventList(List<Event> events) throws EventException {
|
||||
Map<UUID, Group> groupMap = new HashMap<>();
|
||||
|
||||
events.parallelStream()
|
||||
.forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
|
||||
|
||||
return new ArrayList<>(groupMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Gruppe mit der richtigen Id aus der übergebenen Map wieder, existiert diese nicht
|
||||
* wird die Gruppe erstellt und der Map hizugefügt.
|
||||
* @param groups Map aus GruppenIds und Gruppen
|
||||
* @param groupId Die Id der Gruppe, die zurückgegeben werden soll
|
||||
* @return Die gesuchte Gruppe
|
||||
*/
|
||||
private Group getOrCreateGroup(Map<UUID, Group> groups, UUID groupId) {
|
||||
if (!groups.containsKey(groupId)) {
|
||||
groups.put(groupId, new Group());
|
||||
}
|
||||
|
||||
return groups.get(groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird verwendet bei der Suche nach Gruppen: Titel, Beschreibung werden benötigt.
|
||||
* Außerdem wird beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
|
||||
*
|
||||
* @return Liste von projizierten Gruppen
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//TODO Rename
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> groupEvents = eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||
|
||||
sortByGroupType(visibleGroups);
|
||||
|
||||
return visibleGroups.stream()
|
||||
.filter(group -> group.getType() != null)
|
||||
.filter(group -> !eventService.userInGroup(group.getId(), userId))
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird verwendet beim Gruppe erstellen bei der Parent-Auswahl: nur Titel benötigt.
|
||||
*
|
||||
@ -119,18 +61,55 @@ public class GroupService {
|
||||
List<Group> visibleGroups = projectEventList(createEvents);
|
||||
|
||||
return visibleGroups.stream()
|
||||
.filter(group -> group.getType() == GroupType.LECTURE)
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
.filter(group -> group.getType() == GroupType.LECTURE)
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Liste an Events
|
||||
*
|
||||
* @return Liste an Projizierten Gruppen
|
||||
*
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
public List<Group> projectEventList(List<Event> events) throws EventException {
|
||||
Map<UUID, Group> groupMap = new HashMap<>();
|
||||
|
||||
events.parallelStream()
|
||||
.forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
|
||||
|
||||
return new ArrayList<>(groupMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Gruppe mit der richtigen Id aus der übergebenen Map wieder, existiert diese nicht
|
||||
* wird die Gruppe erstellt und der Map hizugefügt.
|
||||
*
|
||||
* @param groups Map aus GruppenIds und Gruppen
|
||||
* @param groupId Die Id der Gruppe, die zurückgegeben werden soll
|
||||
*
|
||||
* @return Die gesuchte Gruppe
|
||||
*/
|
||||
private static Group getOrCreateGroup(Map<UUID, Group> groups, UUID groupId) {
|
||||
if (!groups.containsKey(groupId)) {
|
||||
groups.put(groupId, new Group());
|
||||
}
|
||||
|
||||
return groups.get(groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filtert alle öffentliche Gruppen nach dem Suchbegriff und gibt diese als Liste von Gruppen zurück.
|
||||
* Groß und Kleinschreibung wird nicht beachtet.
|
||||
*
|
||||
* @param search Der Suchstring
|
||||
*
|
||||
* @return Liste von projizierten Gruppen
|
||||
*
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//Todo Rename
|
||||
@ -140,19 +119,44 @@ public class GroupService {
|
||||
return getAllGroupWithVisibilityPublic(account.getName());
|
||||
}
|
||||
|
||||
return getAllGroupWithVisibilityPublic(account.getName())
|
||||
.parallelStream()
|
||||
.filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase())
|
||||
|| group.getDescription().toLowerCase().contains(search.toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
return getAllGroupWithVisibilityPublic(account.getName()).parallelStream().filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird verwendet bei der Suche nach Gruppen: Titel, Beschreibung werden benötigt.
|
||||
* Außerdem wird beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
|
||||
*
|
||||
* @return Liste von projizierten Gruppen
|
||||
*
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//TODO Rename
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> groupEvents = eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
groupEvents.addAll(eventService.getEventsFromDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||
|
||||
sortByGroupType(visibleGroups);
|
||||
|
||||
return visibleGroups.stream()
|
||||
.filter(group -> group.getType() != null)
|
||||
.filter(group -> !eventService.userInGroup(group.getId(), userId))
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sortiert die übergebene Liste an Gruppen, sodass Veranstaltungen am Anfang der Liste sind.
|
||||
*
|
||||
* @param groups Die Liste von Gruppen die sortiert werden soll
|
||||
*/
|
||||
public void sortByGroupType(List<Group> groups) {
|
||||
groups.sort((g1, g2) -> {
|
||||
void sortByGroupType(List<Group> groups) {
|
||||
groups.sort((Group g1, Group g2) -> {
|
||||
if (g1.getType() == GroupType.LECTURE) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||
import mops.gruppen2.domain.exception.InvalidInviteException;
|
||||
import mops.gruppen2.domain.exception.NoInviteExistException;
|
||||
import mops.gruppen2.repository.InviteRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -11,17 +13,18 @@ import java.util.UUID;
|
||||
@Service
|
||||
public class InviteService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InviteService.class);
|
||||
private final InviteRepository inviteRepository;
|
||||
|
||||
public InviteService(InviteRepository inviteRepository) {
|
||||
this.inviteRepository = inviteRepository;
|
||||
}
|
||||
|
||||
public void createLink(UUID groupId) {
|
||||
void createLink(UUID groupId) {
|
||||
inviteRepository.save(new InviteLinkDTO(null, groupId.toString(), UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
public void destroyLink(UUID groupId) {
|
||||
void destroyLink(UUID groupId) {
|
||||
inviteRepository.deleteLinkOfGroup(groupId.toString());
|
||||
}
|
||||
|
||||
@ -29,7 +32,7 @@ public class InviteService {
|
||||
try {
|
||||
return UUID.fromString(inviteRepository.findGroupIdByLink(link));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("Gruppe zu Link ({}) konnte nicht gefunden werden!", link);
|
||||
}
|
||||
|
||||
throw new InvalidInviteException(link);
|
||||
@ -39,7 +42,7 @@ public class InviteService {
|
||||
try {
|
||||
return inviteRepository.findLinkByGroupId(groupId.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("Link zu Gruppe ({}) konnte nicht gefunden werden!", groupId);
|
||||
}
|
||||
|
||||
throw new NoInviteExistException(groupId.toString());
|
||||
|
@ -9,17 +9,21 @@ import org.springframework.stereotype.Service;
|
||||
* Übersetzt JSON-Event-Payloads zu Java-Event-Repräsentationen und zurück.
|
||||
*/
|
||||
@Service
|
||||
public class JsonService {
|
||||
public final class JsonService {
|
||||
|
||||
private JsonService() {}
|
||||
|
||||
/**
|
||||
* Ü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 Bei JSON Fehler
|
||||
*/
|
||||
|
||||
public String serializeEvent(Event event) throws JsonProcessingException {
|
||||
static String serializeEvent(Event event) throws JsonProcessingException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString(event);
|
||||
}
|
||||
@ -28,10 +32,12 @@ public class JsonService {
|
||||
* Ü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 Bei JSON Fehler
|
||||
*/
|
||||
public Event deserializeEvent(String json) throws JsonProcessingException {
|
||||
static Event deserializeEvent(String json) throws JsonProcessingException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(json, Event.class);
|
||||
}
|
||||
|
@ -1,20 +1,23 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import org.keycloak.KeycloakPrincipal;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class KeyCloakService {
|
||||
public final class KeyCloakService {
|
||||
|
||||
private KeyCloakService() {}
|
||||
|
||||
/**
|
||||
* Creates an Account.
|
||||
*
|
||||
* @param token Ein toller token
|
||||
*
|
||||
* @return Account with current userdata
|
||||
*/
|
||||
public Account createAccountFromPrincipal(KeycloakAuthenticationToken token) {
|
||||
public static Account createAccountFromPrincipal(KeycloakAuthenticationToken token) {
|
||||
KeycloakPrincipal principal = (KeycloakPrincipal) token.getPrincipal();
|
||||
return new Account(
|
||||
principal.getName(),
|
||||
|
@ -3,6 +3,4 @@ package mops.gruppen2.service;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SearchService {
|
||||
|
||||
}
|
||||
public class SearchService {}
|
||||
|
@ -23,9 +23,16 @@ public class UserService {
|
||||
this.eventService = eventService;
|
||||
}
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(String userId) throws EventException {
|
||||
return getUserGroups(new User(userId, null, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine Liste aus Gruppen zurück, in denen sich der übergebene User befindet.
|
||||
*
|
||||
* @param user Der User
|
||||
*
|
||||
* @return Liste aus Gruppen
|
||||
*/
|
||||
@Cacheable("groups")
|
||||
@ -45,15 +52,13 @@ public class UserService {
|
||||
return newGroups;
|
||||
}
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(String userId) throws EventException {
|
||||
return getUserGroups(new User(userId, null, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Gruppe zurück, die zu der übergebenen Id passt.
|
||||
*
|
||||
* @param groupId Die Id der gesuchten Gruppe
|
||||
*
|
||||
* @return Die gesuchte Gruppe
|
||||
*
|
||||
* @throws EventException Wenn die Gruppe nicht gefunden wird
|
||||
*/
|
||||
public Group getGroupById(UUID groupId) throws EventException {
|
||||
|
@ -1,11 +1,17 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.exception.*;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import mops.gruppen2.domain.exception.GroupFullException;
|
||||
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||
import mops.gruppen2.domain.exception.NoAccessException;
|
||||
import mops.gruppen2.domain.exception.NoAdminAfterActionException;
|
||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@ -25,6 +31,7 @@ public class ValidationService {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
//TODO: make static or change return + assignment
|
||||
public List<Group> checkSearch(String search, List<Group> groups, Account account) {
|
||||
if (search != null) {
|
||||
groups = groupService.findGroupWith(search, account);
|
||||
@ -38,82 +45,80 @@ public class ValidationService {
|
||||
}
|
||||
}
|
||||
|
||||
public void throwIfNoAccessToPrivate(Group group, User user) {
|
||||
if (!checkIfUserInGroup(group, user) && group.getVisibility() == Visibility.PRIVATE) {
|
||||
throw new NoAccessException("");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkIfUserInGroup(Group group, User user) {
|
||||
return group.getMembers().contains(user);
|
||||
}
|
||||
|
||||
public void throwIfUserAlreadyInGroup(Group group, User user) {
|
||||
if (checkIfUserInGroup(group, user)) {
|
||||
throw new UserAlreadyExistsException("@details");
|
||||
}
|
||||
}
|
||||
|
||||
public void throwIfNotInGroup(Group group, User user) {
|
||||
void throwIfNotInGroup(Group group, User user) {
|
||||
if (!checkIfUserInGroup(group, user)) {
|
||||
throw new UserNotFoundException(this.getClass().toString());
|
||||
throw new UserNotFoundException(getClass().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkIfUserInGroup(Group group, User user) {
|
||||
return group.getMembers().contains(user);
|
||||
}
|
||||
|
||||
public void throwIfGroupFull(Group group) {
|
||||
if (group.getUserMaximum() < group.getMembers().size() + 1) {
|
||||
throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten.");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkIfGroupEmpty(UUID groupId) {
|
||||
boolean checkIfGroupEmpty(UUID groupId) {
|
||||
return userService.getGroupById(groupId).getMembers().isEmpty();
|
||||
}
|
||||
|
||||
public void throwIfNoAdmin(Group group, User user) {
|
||||
throwIfNoAccessToPrivate(group, user);
|
||||
if (group.getRoles().get(user.getId()) != Role.ADMIN) {
|
||||
if (group.getRoles().get(user.getId()) != ADMIN) {
|
||||
throw new NoAccessException("");
|
||||
}
|
||||
}
|
||||
|
||||
public void throwIfNoAccessToPrivate(Group group, User user) {
|
||||
if (!checkIfUserInGroup(group, user) && group.getVisibility() == Visibility.PRIVATE) {
|
||||
throw new NoAccessException("");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkIfAdmin(Group group, User user) {
|
||||
if (checkIfUserInGroup(group, user)) {
|
||||
return group.getRoles().get(user.getId()) == Role.ADMIN;
|
||||
return group.getRoles().get(user.getId()) == ADMIN;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkIfLastAdmin(Account account, Group group) {
|
||||
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) {
|
||||
if (entry.getValue() == ADMIN) {
|
||||
if (!(entry.getKey().equals(account.getName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void throwIfLastAdmin(Account account, Group group) {
|
||||
void throwIfLastAdmin(Account account, Group group) {
|
||||
if (checkIfLastAdmin(account, group)) {
|
||||
throw new NoAdminAfterActionException("Du Otto bist letzter Admin!");
|
||||
}
|
||||
}
|
||||
|
||||
boolean checkIfLastAdmin(Account account, Group group) {
|
||||
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) {
|
||||
if (entry.getValue() == ADMIN && !(entry.getKey().equals(account.getName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft ob alle Felder richtig gesetzt sind.
|
||||
*
|
||||
* @param description Die Beschreibung der Gruppe
|
||||
* @param title Der Titel der Gruppe
|
||||
* @param title Der Titel der Gruppe
|
||||
* @param userMaximum Das user Limit der Gruppe
|
||||
*/
|
||||
public void checkFields(String title, String description, Long userMaximum, Boolean maxInfiniteUsers) {
|
||||
if (description == null || description.trim().length() == 0) {
|
||||
if (description == null || description.trim().isEmpty()) {
|
||||
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (title == null || title.trim().length() == 0) {
|
||||
if (title == null || title.trim().isEmpty()) {
|
||||
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
@ -121,19 +126,17 @@ public class ValidationService {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (userMaximum != null) {
|
||||
if (userMaximum < 1 || userMaximum > 10000L) {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
if (userMaximum != null && (userMaximum < 1 || userMaximum > 10000L)) {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkFields(String title, String description) {
|
||||
if (description == null || description.trim().length() == 0) {
|
||||
if (description == null || description.trim().isEmpty()) {
|
||||
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (title == null || title.trim().length() == 0) {
|
||||
if (title == null || title.trim().isEmpty()) {
|
||||
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,8 @@
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input class="custom-control-input" id="maxInfiniteUsers" th:name="maxInfiniteUsers"
|
||||
type="checkbox">
|
||||
<label class="custom-control-label" for="maxInfiniteUsers">Anzahl unbegrenzt</label>
|
||||
<label class="custom-control-label" for="maxInfiniteUsers">Anzahl
|
||||
unbegrenzt</label>
|
||||
</div>
|
||||
<div class="form-group mt-3" id="userMaximum">
|
||||
<label for="userMaximum">Teilnehmeranzahl</label>
|
||||
@ -66,7 +67,7 @@
|
||||
<input class="custom-control-input" id="visibility" th:name="visibility"
|
||||
type="checkbox">
|
||||
<label class="custom-control-label" for="visibility">Private
|
||||
Gruppe</label>
|
||||
Gruppe</label>
|
||||
</div>
|
||||
<div class="custom-control custom-checkbox" id="lectureCheckbox">
|
||||
<input class="custom-control-input" id="lecture" th:name="lecture"
|
||||
@ -76,7 +77,8 @@
|
||||
<div class="form-group" id="lectureParent">
|
||||
<label for="parent"></label>
|
||||
<select class="form-control" id="parent" name="parent">
|
||||
<option disabled selected="true">--Bitte Veranstaltung auswählen--</option>
|
||||
<option disabled selected="true">--Bitte Veranstaltung auswählen--
|
||||
</option>
|
||||
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
|
||||
</option>
|
||||
</select>
|
||||
@ -88,7 +90,8 @@
|
||||
<input class="custom-file-input" id="file" th:name="file"
|
||||
type="file">
|
||||
<label class="custom-file-label" for="file">CSV Datei von
|
||||
Mitgliedern hochladen</label>
|
||||
Mitgliedern
|
||||
hochladen</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -54,7 +54,8 @@
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input class="custom-control-input" id="maxInfiniteUsers" th:name="maxInfiniteUsers"
|
||||
type="checkbox">
|
||||
<label class="custom-control-label" for="maxInfiniteUsers">Anzahl unbegrenzt</label>
|
||||
<label class="custom-control-label" for="maxInfiniteUsers">Anzahl
|
||||
unbegrenzt</label>
|
||||
</div>
|
||||
<div class="form-group mt-3" id="userMaximum">
|
||||
<label for="userMaximum">Teilnehmeranzahl</label>
|
||||
@ -65,12 +66,13 @@
|
||||
<input class="custom-control-input" id="visibility" th:name="visibility"
|
||||
type="checkbox">
|
||||
<label class="custom-control-label" for="visibility">Private
|
||||
Gruppe</label>
|
||||
Gruppe</label>
|
||||
</div>
|
||||
<div class="form-group" id="lectureParent">
|
||||
<label for="parent"></label>
|
||||
<select class="form-control" id="parent" name="parent">
|
||||
<option disabled selected="true">--Bitte Veranstaltung auswählen--</option>
|
||||
<option disabled selected="true">--Bitte Veranstaltung auswählen--
|
||||
</option>
|
||||
<option th:each="lecture : ${lectures}" th:name="parent" th:value="${lecture.getId()}" th:text="${lecture.getTitle()}">
|
||||
</option>
|
||||
</select>
|
||||
|
@ -112,7 +112,9 @@
|
||||
<div th:if="${group.getRoles().get(user.getId()) == admin}">
|
||||
<form method="get"
|
||||
th:action="@{/gruppen2/details/members/{id}(id=${group.getId()})}">
|
||||
<button class="btn btn-secondary" style="background: slategrey; float: left">Mitglieder bearbeiten</button>
|
||||
<button class="btn btn-secondary" style="background: slategrey; float: left">
|
||||
Mitglieder bearbeiten
|
||||
</button>
|
||||
</form>
|
||||
<br>
|
||||
<br>
|
||||
|
@ -56,7 +56,8 @@
|
||||
<input class="custom-file-input" id="file" th:name="file"
|
||||
type="file">
|
||||
<label class="custom-file-label" for="file">CSV Datei von
|
||||
Mitgliedern hochladen</label>
|
||||
Mitgliedern
|
||||
hochladen</label>
|
||||
</div>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary"
|
||||
@ -114,7 +115,7 @@
|
||||
type="hidden">
|
||||
<button class="btn btn-warning btn-sm" type="submit"
|
||||
style="margin: 5px">Rolle
|
||||
ändern
|
||||
ändern
|
||||
</button>
|
||||
</form>
|
||||
<form method="post"
|
||||
@ -134,7 +135,9 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<form method="get" th:action="@{/gruppen2/details/{id}(id=${group.getId()})}">
|
||||
<button class="btn btn-primary" style="background: #52a1eb; border-style: none" type="submit">Fertig</button>
|
||||
<button class="btn btn-primary" style="background: #52a1eb; border-style: none" type="submit">
|
||||
Fertig
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -35,23 +35,24 @@
|
||||
<h1>Gruppensuche</h1>
|
||||
<div class="shadow-sm p-2"
|
||||
style="border: 10px solid aliceblue; border-radius: 5px; background: aliceblue">
|
||||
<form method="get" th:action="@{/gruppen2/findGroup}">
|
||||
<div class="form-group">
|
||||
<label for="suchleiste">Suchbegriff:</label>
|
||||
<input class="form-control" id="suchleiste"
|
||||
placeholder="z.B. Programmieren, Lerngruppe, ..."
|
||||
th:name="suchbegriff" type="text">
|
||||
</div>
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none"
|
||||
type="submit">Suchen
|
||||
</button>
|
||||
<button class="btn btn-primary"
|
||||
style="background: deepskyblue; border-style: none"
|
||||
type="submit">
|
||||
<a style="color: white" href="/gruppen2/findGroup?suchbegriff=">Alle anzeigen</a>
|
||||
</button>
|
||||
</form>
|
||||
<form method="get" th:action="@{/gruppen2/findGroup}">
|
||||
<div class="form-group">
|
||||
<label for="suchleiste">Suchbegriff:</label>
|
||||
<input class="form-control" id="suchleiste"
|
||||
placeholder="z.B. Programmieren, Lerngruppe, ..."
|
||||
th:name="suchbegriff" type="text">
|
||||
</div>
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none"
|
||||
type="submit">Suchen
|
||||
</button>
|
||||
<button class="btn btn-primary"
|
||||
style="background: deepskyblue; border-style: none"
|
||||
type="submit">
|
||||
<a href="/gruppen2/findGroup?suchbegriff=" style="color: white">Alle
|
||||
anzeigen</a>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<br>
|
||||
<table class="table">
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mops.gruppen2;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
@ -13,7 +14,6 @@ import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
|
||||
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.security.Account;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -29,11 +29,11 @@ public class TestBuilder {
|
||||
|
||||
public static Account account(String name) {
|
||||
return new Account(name,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
null);
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
null);
|
||||
}
|
||||
|
||||
public static Group apply(Group group, Event... events) {
|
||||
@ -52,12 +52,13 @@ public class TestBuilder {
|
||||
* Baut eine UUID.
|
||||
*
|
||||
* @param id Integer id
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public static UUID uuidFromInt(int id) {
|
||||
return UUID.fromString("00000000-0000-0000-0000-"
|
||||
+ "0".repeat(11 - String.valueOf(id).length())
|
||||
+ id);
|
||||
+ "0".repeat(11 - String.valueOf(id).length())
|
||||
+ id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,22 +66,23 @@ public class TestBuilder {
|
||||
*
|
||||
* @param count Gruppenanzahl
|
||||
* @param membercount Mitgliederanzahl pro Gruppe
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> completePublicGroups(int count, int membercount) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> completePublicGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> completePublicGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> completePrivateGroups(int count, int membercount) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> completePrivateGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> completePrivateGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> completePublicGroup(int membercount) {
|
||||
@ -119,29 +121,30 @@ public class TestBuilder {
|
||||
* Generiert mehrere CreateGroupEvents, 1 <= groupId <= count.
|
||||
*
|
||||
* @param count Anzahl der verschiedenen Gruppen
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> createPublicGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> createPrivateGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> createMixedGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> faker.random().nextInt(0, 1) > 0.5
|
||||
? createPublicGroupEvent()
|
||||
: createPrivateGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> faker.random().nextInt(0, 1) > 0.5
|
||||
? createPublicGroupEvent()
|
||||
: createPrivateGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event createPrivateGroupEvent(UUID groupId) {
|
||||
@ -191,13 +194,14 @@ public class TestBuilder {
|
||||
*
|
||||
* @param count Anzahl der Mitglieder
|
||||
* @param groupId Gruppe, zu welcher geaddet wird
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> addUserEvents(int count, UUID groupId) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event addUserEvent(UUID groupId, String userId) {
|
||||
@ -221,8 +225,8 @@ public class TestBuilder {
|
||||
public static List<Event> deleteUserEvents(int count, List<Event> eventList) {
|
||||
List<Event> removeEvents = new ArrayList<>();
|
||||
List<Event> shuffle = eventList.parallelStream()
|
||||
.filter(event -> event instanceof AddUserEvent)
|
||||
.collect(Collectors.toList());
|
||||
.filter(event -> event instanceof AddUserEvent)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Collections.shuffle(shuffle);
|
||||
|
||||
@ -241,12 +245,13 @@ public class TestBuilder {
|
||||
* Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird.
|
||||
*
|
||||
* @param group Gruppe welche geleert wird
|
||||
*
|
||||
* @return Eventliste
|
||||
*/
|
||||
public static List<Event> deleteUserEvents(Group group) {
|
||||
return group.getMembers().parallelStream()
|
||||
.map(user -> deleteUserEvent(group.getId(), user.getId()))
|
||||
.collect(Collectors.toList());
|
||||
.map(user -> deleteUserEvent(group.getId(), user.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event deleteUserEvent(UUID groupId, String userId) {
|
||||
|
@ -14,18 +14,17 @@ public class LayeredArchitectureTest {
|
||||
.layer("Domain").definedBy("..domain..")
|
||||
.layer("Service").definedBy("..service")
|
||||
.layer("Controller").definedBy("..controller..")
|
||||
.layer("Repository").definedBy("..repository..")
|
||||
.layer("Config").definedBy("..config..");
|
||||
.layer("Repository").definedBy("..repository..");
|
||||
|
||||
@ArchTest
|
||||
public static final ArchRule domainLayerShouldOnlyBeAccessedByServiceAndControllerLayer = layeredArchitecture
|
||||
.whereLayer("Domain")
|
||||
.mayOnlyBeAccessedByLayers("Service", "Controller", "Config");
|
||||
.mayOnlyBeAccessedByLayers("Service", "Controller");
|
||||
|
||||
@ArchTest
|
||||
public static final ArchRule serviceLayerShouldOnlyBeAccessedByControllerLayer = layeredArchitecture
|
||||
.whereLayer("Service")
|
||||
.mayOnlyBeAccessedByLayers("Controller", "Config");
|
||||
.mayOnlyBeAccessedByLayers("Controller");
|
||||
|
||||
@ArchTest
|
||||
public static final ArchRule repositoryLayerShouldOnlyBeAccessedByServiceLayer = layeredArchitecture
|
||||
|
@ -1,34 +1,12 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class AddUserEventTest {
|
||||
|
||||
@Test
|
||||
void userAlreadyExistExeption() throws EventException {
|
||||
Group group = new Group();
|
||||
User user = new User("user1", "Stein", "Speck", "@sdasd");
|
||||
group.getMembers().add(user);
|
||||
group.setUserMaximum(10L);
|
||||
UUID id = UUID.randomUUID();
|
||||
Event event1 = new AddUserEvent(id, "user2", "Rock", "Roll", "and");
|
||||
event1.apply(group);
|
||||
void applyEvent() {
|
||||
|
||||
Event event2 = new AddUserEvent(id, "user1", "Rock", "Roll", "and");
|
||||
|
||||
assertThrows(UserAlreadyExistsException.class, () ->
|
||||
event2.apply(group)
|
||||
);
|
||||
assertThat(group.getMembers().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,48 +1,10 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static mops.gruppen2.domain.Role.MEMBER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class DeleteUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyDeleteUser() throws EventException {
|
||||
Group group = new Group();
|
||||
User user = new User("user1", "Stein", "Speck", "@sdasd");
|
||||
group.getMembers().add(user);
|
||||
group.getRoles().put("user1", MEMBER);
|
||||
User user2 = new User("user2", "Rock", "Roll", "and");
|
||||
group.getMembers().add(user2);
|
||||
group.getRoles().put("user2", MEMBER);
|
||||
|
||||
Event event = new DeleteUserEvent(UUID.randomUUID(), "user1");
|
||||
event.apply(group);
|
||||
|
||||
assertThat(group.getMembers().size()).isEqualTo(1);
|
||||
assertThat(group.getRoles().size()).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void userDoesNotExistExeption() {
|
||||
Group group = new Group();
|
||||
User user = new User("user1", "Stein", "Speck", "@sdasd");
|
||||
group.getMembers().add(user);
|
||||
group.getRoles().put("user1", MEMBER);
|
||||
|
||||
Event event = new DeleteUserEvent(UUID.randomUUID(), "user5");
|
||||
assertThrows(UserNotFoundException.class, () ->
|
||||
event.apply(group)
|
||||
);
|
||||
assertThat(group.getMembers().size()).isEqualTo(1);
|
||||
void applyEvent() {
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.Gruppen2Application;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Account;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@Transactional
|
||||
@Rollback
|
||||
class ControllerServiceTest {
|
||||
|
||||
Account account;
|
||||
Account account2;
|
||||
Account account3;
|
||||
@ -136,7 +137,7 @@ class ControllerServiceTest {
|
||||
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
controllerService.createGroup(account, "test", "hi", null, true, true, null,groups1.get(0).getId());
|
||||
controllerService.createGroup(account, "test", "hi", null, true, true, null, groups1.get(0).getId());
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
|
Reference in New Issue
Block a user