diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
index 4d3c76b..5f8e664 100644
--- a/config/checkstyle/checkstyle.xml
+++ b/config/checkstyle/checkstyle.xml
@@ -57,11 +57,6 @@
-
-
-
-
-
@@ -173,7 +168,7 @@
value="Type name ''{0}'' must match pattern ''{1}''."/>
-
+
@@ -193,7 +188,7 @@
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
-
+
diff --git a/src/main/java/mops/gruppen2/controller/WebController.java b/src/main/java/mops/gruppen2/controller/WebController.java
index 57ef550..f5603dc 100644
--- a/src/main/java/mops/gruppen2/controller/WebController.java
+++ b/src/main/java/mops/gruppen2/controller/WebController.java
@@ -6,13 +6,22 @@ import mops.gruppen2.domain.User;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.PageNotFoundException;
import mops.gruppen2.security.Account;
-import mops.gruppen2.service.*;
+import mops.gruppen2.service.ControllerService;
+import mops.gruppen2.service.GroupService;
+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.stereotype.Controller;
import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.*;
+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;
@@ -208,8 +217,8 @@ public class WebController {
model.addAttribute("user", user);
model.addAttribute("admin", Role.ADMIN);
- String URL = request.getRequestURL().toString();
- String serverURL = URL.substring(0, URL.indexOf("gruppen2/"));
+ String actualURL = request.getRequestURL().toString();
+ String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
return "detailsMember";
@@ -236,10 +245,11 @@ public class WebController {
@RequestParam("id") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(UUID.fromString(groupId));
+ validationService.checkIfGroupFull(group);
+
UUID parentId = group.getParent();
Group parent = validationService.checkParent(parentId);
- validationService.checkIfGroupFull(group);
model.addAttribute("group", group);
model.addAttribute("parentId", parentId);
model.addAttribute("parent", parent);
diff --git a/src/main/java/mops/gruppen2/domain/event/UpdateUserMaxEvent.java b/src/main/java/mops/gruppen2/domain/event/UpdateUserMaxEvent.java
index dcfe143..e3f39fd 100644
--- a/src/main/java/mops/gruppen2/domain/event/UpdateUserMaxEvent.java
+++ b/src/main/java/mops/gruppen2/domain/event/UpdateUserMaxEvent.java
@@ -15,8 +15,8 @@ public class UpdateUserMaxEvent extends Event {
private Long userMaximum;
- public UpdateUserMaxEvent(UUID group_id, String user_id, Long userMaximum) {
- super(group_id, user_id);
+ public UpdateUserMaxEvent(UUID groupId, String userId, Long userMaximum) {
+ super(groupId, userId);
this.userMaximum = userMaximum;
}
diff --git a/src/main/java/mops/gruppen2/domain/exception/BadParameterException.java b/src/main/java/mops/gruppen2/domain/exception/BadParameterException.java
index b1767d2..e933ba6 100644
--- a/src/main/java/mops/gruppen2/domain/exception/BadParameterException.java
+++ b/src/main/java/mops/gruppen2/domain/exception/BadParameterException.java
@@ -4,7 +4,7 @@ import org.springframework.http.HttpStatus;
public class BadParameterException extends EventException {
- public BadParameterException(String info) {
- super(HttpStatus.INTERNAL_SERVER_ERROR, "Fehlerhafter Parameter angegeben!", info);
- }
+ public BadParameterException(String info) {
+ super(HttpStatus.INTERNAL_SERVER_ERROR, "Fehlerhafter Parameter angegeben!", info);
+ }
}
diff --git a/src/main/java/mops/gruppen2/domain/exception/GroupFullException.java b/src/main/java/mops/gruppen2/domain/exception/GroupFullException.java
index 6caef52..014f0d7 100644
--- a/src/main/java/mops/gruppen2/domain/exception/GroupFullException.java
+++ b/src/main/java/mops/gruppen2/domain/exception/GroupFullException.java
@@ -4,8 +4,8 @@ import org.springframework.http.HttpStatus;
public class GroupFullException extends EventException {
- public GroupFullException(String info) {
- super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Gruppe hat die maximale Midgliederanzahl bereits erreicht!", info);
- }
+ public GroupFullException(String info) {
+ super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Gruppe hat die maximale Midgliederanzahl bereits erreicht!", info);
+ }
}
diff --git a/src/main/java/mops/gruppen2/security/KeycloakConfig.java b/src/main/java/mops/gruppen2/security/KeycloakConfig.java
index 56e5c9a..72bb437 100644
--- a/src/main/java/mops/gruppen2/security/KeycloakConfig.java
+++ b/src/main/java/mops/gruppen2/security/KeycloakConfig.java
@@ -42,4 +42,4 @@ public class KeycloakConfig {
return new OAuth2RestTemplate(resourceDetails);
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/mops/gruppen2/security/SecurityConfig.java b/src/main/java/mops/gruppen2/security/SecurityConfig.java
index 745dcdf..f597e47 100644
--- a/src/main/java/mops/gruppen2/security/SecurityConfig.java
+++ b/src/main/java/mops/gruppen2/security/SecurityConfig.java
@@ -6,7 +6,11 @@ import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticatio
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
import org.keycloak.representations.AccessToken;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Scope;
+import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
@@ -44,7 +48,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
@Bean
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST,
- proxyMode = ScopedProxyMode.TARGET_CLASS)
+ proxyMode = ScopedProxyMode.TARGET_CLASS)
public AccessToken getAccessToken() {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder
@@ -57,14 +61,14 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests()
- .antMatchers("/actuator/**")
- .hasRole("monitoring")
- .and()
- .authorizeRequests()
- .antMatchers("/h2-console/**")
- .permitAll()
- .anyRequest()
- .permitAll();
+ .antMatchers("/actuator/**")
+ .hasRole("monitoring")
+ .and()
+ .authorizeRequests()
+ .antMatchers("/h2-console/**")
+ .permitAll()
+ .anyRequest()
+ .permitAll();
http.csrf().disable();
http.headers().frameOptions().disable();
diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java
index aa7fc2b..3d5263f 100644
--- a/src/main/java/mops/gruppen2/service/ControllerService.java
+++ b/src/main/java/mops/gruppen2/service/ControllerService.java
@@ -1,6 +1,5 @@
package mops.gruppen2.service;
-import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role;
@@ -15,15 +14,11 @@ 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.BadParameterException;
import mops.gruppen2.domain.exception.UserNotFoundException;
-import mops.gruppen2.domain.exception.WrongFileException;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-import java.io.CharConversionException;
+
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -56,8 +51,6 @@ public class ControllerService {
*/
public void createGroup(Account account, String title, String description, Boolean visibility, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException {
Visibility visibility1;
- UUID groupId = UUID.randomUUID();
-
maxInfiniteUsers = maxInfiniteUsers != null;
if (maxInfiniteUsers) {
@@ -72,6 +65,7 @@ public class ControllerService {
visibility1 = Visibility.PRIVATE;
}
+ UUID groupId = UUID.randomUUID();
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
eventService.saveEvent(createGroupEvent);
@@ -188,8 +182,8 @@ public class ControllerService {
eventService.saveEvent(deleteUserEvent);
}
- public void deleteGroupEvent(String user_id, UUID groupId) {
- DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user_id);
+ public void deleteGroupEvent(String userId, UUID groupId) {
+ DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
eventService.saveEvent(deleteGroupEvent);
}
@@ -206,8 +200,8 @@ public class ControllerService {
return false;
}
- private boolean isLastAdmin(Account account, Group group){
- for (Map.Entry entry : group.getRoles().entrySet()){
+ private boolean isLastAdmin(Account account, Group group) {
+ for (Map.Entry entry : group.getRoles().entrySet()) {
if (entry.getValue() == ADMIN) {
if (!(entry.getKey().equals(account.getName()))) {
return false;
diff --git a/src/main/java/mops/gruppen2/service/GroupService.java b/src/main/java/mops/gruppen2/service/GroupService.java
index 28ceb33..2cab31b 100644
--- a/src/main/java/mops/gruppen2/service/GroupService.java
+++ b/src/main/java/mops/gruppen2/service/GroupService.java
@@ -56,7 +56,7 @@ public class GroupService {
Map groupMap = new HashMap<>();
events.parallelStream()
- .forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
+ .forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
return new ArrayList<>(groupMap.values());
}
@@ -89,19 +89,18 @@ public class GroupService {
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());
+ .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.
*
- * @return
- * @throws EventException
+ * @return List of groups
*/
- public List getAllLecturesWithVisibilityPublic() throws EventException {
+ public List getAllLecturesWithVisibilityPublic() {
List createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
@@ -110,9 +109,9 @@ public class GroupService {
List 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());
}
diff --git a/src/main/java/mops/gruppen2/service/ValidationService.java b/src/main/java/mops/gruppen2/service/ValidationService.java
index 9b830d5..94f8945 100644
--- a/src/main/java/mops/gruppen2/service/ValidationService.java
+++ b/src/main/java/mops/gruppen2/service/ValidationService.java
@@ -1,19 +1,21 @@
package mops.gruppen2.service;
-import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
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.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.NoValueException;
+import mops.gruppen2.domain.exception.UserAlreadyExistsException;
+import mops.gruppen2.domain.exception.WrongFileException;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
-import javax.swing.text.StyledEditorKit;
-import javax.validation.ValidationException;
-import java.io.CharConversionException;
-import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
@@ -47,13 +49,17 @@ public class ValidationService {
}
public void checkGroup(String title) {
- if (title == null) throw new GroupNotFoundException("@details");
+ if (title == null) {
+ throw new GroupNotFoundException("@details");
+ }
}
public boolean checkIfUserInGroup(Group group, User user) {
if (!group.getMembers().contains(user) && group.getVisibility() == Visibility.PRIVATE) {
throw new NoAccessException("");
- } else return group.getMembers().contains(user);
+ } else {
+ return group.getMembers().contains(user);
+ }
}
public Group checkParent(UUID parentId) {
@@ -118,9 +124,10 @@ public class ValidationService {
/**
* Überprüft ob alle Felder richtig gesetzt sind.
- * @param description
- * @param title
- * @param userMaximum
+ *
+ * @param description Die Beschreibung der Gruppe
+ * @param title Der Titel der Gruppe
+ * @param userMaximum Das user Limit der Gruppe
*/
public void checkFields(String description, String title, Long userMaximum, Boolean maxInfiniteUsers) {
if (description == null) {