1

Formatting

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-18 20:18:03 +01:00
parent 01c0cac2a2
commit 2ba913f2c8
40 changed files with 354 additions and 245 deletions

View File

@ -1,11 +1,5 @@
package mops.gruppen2;
import lombok.Setter;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@ -18,7 +12,6 @@ import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Collections;
import java.util.List;
@SpringBootApplication
@EnableSwagger2

View File

@ -1,15 +1,10 @@
package mops.gruppen2.config;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
@Configuration
public class Gruppen2Config {

View File

@ -7,13 +7,16 @@ import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.apiWrapper.UpdatedGroupRequestMapper;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.service.*;
import mops.gruppen2.service.APIFormatterService;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.SerializationService;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**

View File

@ -6,15 +6,27 @@ import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.*;
import mops.gruppen2.service.ControllerService;
import mops.gruppen2.service.CsvService;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.InviteLinkRepositoryService;
import mops.gruppen2.service.KeyCloakService;
import mops.gruppen2.service.UserService;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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 org.springframework.web.server.ResponseStatusException;
import javax.annotation.security.RolesAllowed;
import java.io.IOException;
import java.util.ArrayList;
@ -25,13 +37,14 @@ import java.util.List;
@RequestMapping("/gruppen2")
public class Gruppen2Controller {
Gruppen2Config gruppen2Config;
private final KeyCloakService keyCloakService;
private final EventService eventService;
private final GroupService groupService;
private final UserService userService;
private final ControllerService controllerService;
private final InviteLinkRepositoryService inviteLinkRepositoryService;
@Autowired
Gruppen2Config gruppen2Config;
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService) {
this.keyCloakService = keyCloakService;
@ -70,10 +83,10 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/createLecture")
public String pCreateLecture(KeycloakAuthenticationToken token,
@RequestParam(value = "title") String title,
@RequestParam(value = "beschreibung") String beschreibung,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
@RequestParam(value = "title") String title,
@RequestParam(value = "beschreibung") String beschreibung,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
List<User> userList = new ArrayList<>();
@ -88,7 +101,7 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/details/members/addUsersFromCsv")
public String addUsersFromCsv(@RequestParam (value = "group_id") Long group_id,
public String addUsersFromCsv(@RequestParam(value = "group_id") Long group_id,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
List<User> userList = new ArrayList<>();
if (!file.isEmpty()) {
@ -111,7 +124,7 @@ public class Gruppen2Controller {
Account account = keyCloakService.createAccountFromPrincipal(token);
List<Group> groupse = new ArrayList<>();
if (suchbegriff != null) {
groupse = groupService.findGroupWith(suchbegriff,account);
groupse = groupService.findGroupWith(suchbegriff, account);
}
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("gruppen", groupse);
@ -134,7 +147,7 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/{id}")
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable (value="id") Long id) throws EventException, ResponseStatusException {
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable(value = "id") Long id) throws EventException, ResponseStatusException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id);
@ -154,11 +167,13 @@ public class Gruppen2Controller {
@PostMapping("/detailsBeitreten")
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Account account = keyCloakService.createAccountFromPrincipal (token);
User user = new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(id);
if(group.getMembers().contains(user)) return "errorRenameLater"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
controllerService.addUser(account,id);
if (group.getMembers().contains(user)) {
return "errorRenameLater"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
}
controllerService.addUser(account, id);
return "redirect:/gruppen2/";
}
@ -188,7 +203,7 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup")
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) throws EventException {
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam(value = "group_id") Long id) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
controllerService.deleteUser(user.getUser_id(), id);
@ -197,10 +212,10 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/members/{id}")
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable (value="id") Long id) throws EventException {
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable(value = "id") Long id) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(id);
if(group.getRoles().get(account.getName()) == Role.ADMIN) {
if (group.getRoles().get(account.getName()) == Role.ADMIN) {
model.addAttribute("account", account);
model.addAttribute("members", group.getMembers());
model.addAttribute("group", group);
@ -213,16 +228,16 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeRole")
public String changeRole(KeycloakAuthenticationToken token, @RequestParam (value = "group_id") Long group_id,
@RequestParam (value = "user_id") String user_id) throws EventException {
public String changeRole(KeycloakAuthenticationToken token, @RequestParam(value = "group_id") Long group_id,
@RequestParam(value = "user_id") String user_id) throws EventException {
controllerService.updateRole(user_id, group_id);
return "redirect:/gruppen2/details/members/" + group_id;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser")
public String deleteUser(KeycloakAuthenticationToken token,@RequestParam (value = "group_id") Long group_id,
@RequestParam (value = "user_id") String user_id) throws EventException {
public String deleteUser(KeycloakAuthenticationToken token, @RequestParam(value = "group_id") Long group_id,
@RequestParam(value = "user_id") String user_id) throws EventException {
controllerService.deleteUser(user_id, group_id);
return "redirect:/gruppen2/details/members/" + group_id;
}

View File

@ -1,6 +1,7 @@
package mops.gruppen2.domain.Exceptions;
public class EventException extends Exception {
private String msg;
public EventException(String msg) {

View File

@ -1,7 +1,8 @@
package mops.gruppen2.domain.Exceptions;
public class UserAlreadyExistsException extends EventException {
public UserAlreadyExistsException(String msg){
super(msg);
public UserAlreadyExistsException(String msg) {
super(msg);
}
}

View File

@ -1,7 +1,8 @@
package mops.gruppen2.domain.Exceptions;
public class UserNotFoundException extends EventException{
public UserNotFoundException(String msg){
public class UserNotFoundException extends EventException {
public UserNotFoundException(String msg) {
super(msg);
}
}

View File

@ -4,11 +4,11 @@ import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
import mops.gruppen2.domain.event.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Repräsentiert den aggregierten Zustand einer Gruppe.
@ -18,12 +18,12 @@ import java.util.*;
@Setter
@AllArgsConstructor
public class Group {
private final List<User> members;
private final Map<String, Role> roles;
private long id;
private String title;
private String description;
private final List<User> members;
private final Map<String, Role> roles;
private GroupType type;
private Visibility visibility;
private Long parent;

View File

@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
public class User {
String user_id;
String givenname;
String familyname;

View File

@ -11,6 +11,7 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
public class UpdatedGroupRequestMapper {
private Long status;
private List<Group> groupList;
}
}

View File

@ -7,6 +7,7 @@ import org.springframework.data.relational.core.mapping.Table;
@Table("event")
@Data
public class EventDTO {
@Id
Long event_id;
Long group_id;

View File

@ -9,6 +9,7 @@ import org.springframework.data.relational.core.mapping.Table;
@Data
@AllArgsConstructor
public class InviteLinkDTO {
@Id
Long link_id;
Long group_id;

View File

@ -16,6 +16,7 @@ import mops.gruppen2.domain.User;
@AllArgsConstructor
@NoArgsConstructor
public class AddUserEvent extends Event {
String givenname;
String familyname;
String email;
@ -27,10 +28,10 @@ public class AddUserEvent extends Event {
this.email = email;
}
public void apply(Group group) throws EventException{
public void apply(Group group) throws EventException {
User user = new User(this.user_id, this.givenname, this.familyname, this.email);
if (group.getMembers().contains(user)){
if (group.getMembers().contains(user)) {
throw new UserAlreadyExistsException("Der User existiert bereits");
}

View File

@ -11,12 +11,11 @@ import mops.gruppen2.domain.Visibility;
@AllArgsConstructor
@NoArgsConstructor
public class CreateGroupEvent extends Event {
private Visibility groupVisibility;
private Long groupParent;
private GroupType groupType;
public CreateGroupEvent(Long group_id, String user_id, Long parent, GroupType type, Visibility visibility) {
super(group_id, user_id);
this.groupParent = parent;

View File

@ -1,11 +1,11 @@
package mops.gruppen2.domain.event;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Group;
/**
* Entfernt ein einzelnes Mitglied einer Gruppe.
@ -13,6 +13,7 @@ import mops.gruppen2.domain.Group;
@Getter
@NoArgsConstructor
public class DeleteUserEvent extends Event {
public DeleteUserEvent(Long group_id, String user_id) {
super(group_id, user_id);
}

View File

@ -19,15 +19,16 @@ import mops.gruppen2.domain.Group;
property = "type"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = AddUserEvent.class, name = "AddUserEvent"),
@JsonSubTypes.Type(value = CreateGroupEvent.class, name = "CreateGroupEvent"),
@JsonSubTypes.Type(value = DeleteUserEvent.class, name = "DeleteUserEvent"),
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
})
@JsonSubTypes.Type(value = AddUserEvent.class, name = "AddUserEvent"),
@JsonSubTypes.Type(value = CreateGroupEvent.class, name = "CreateGroupEvent"),
@JsonSubTypes.Type(value = DeleteUserEvent.class, name = "DeleteUserEvent"),
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
})
@Setter
public class Event {
Long group_id;
String user_id;

View File

@ -12,6 +12,7 @@ import mops.gruppen2.domain.Group;
@AllArgsConstructor
@NoArgsConstructor
public class UpdateGroupDescriptionEvent extends Event {
String newGroupDescription;
public UpdateGroupDescriptionEvent(Long group_id, String user_id, String newGroupDescription) {

View File

@ -12,6 +12,7 @@ import mops.gruppen2.domain.Group;
@AllArgsConstructor
@NoArgsConstructor
public class UpdateGroupTitleEvent extends Event {
String newGroupTitle;
public UpdateGroupTitleEvent(Long group_id, String user_id, String newGroupTitle) {

View File

@ -1,13 +1,11 @@
package mops.gruppen2.domain.event;
import lombok.*;
import mops.gruppen2.domain.Exceptions.EventException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User;
import java.util.Optional;
/**
* Aktualisiert die Gruppenrolle eines Teilnehmers.
@ -18,14 +16,14 @@ import java.util.Optional;
public class UpdateRoleEvent extends Event {
Role newRole;
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
super(group_id, user_id);
this.newRole = newRole;
}
public void apply(Group group) throws UserNotFoundException{
if (!group.getRoles().containsKey(user_id)){
public void apply(Group group) throws UserNotFoundException {
if (!group.getRoles().containsKey(user_id)) {
throw new UserNotFoundException("Der User wurde nicht gefunden");
}
group.getRoles().put(this.user_id, this.newRole);

View File

@ -10,6 +10,7 @@ import java.util.List;
@Repository
public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("select distinct group_id from event where user_id =:id")
List<Long> findGroup_idsWhereUser_id(@Param("id") String user_id);
@ -19,9 +20,9 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
//@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
//Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
@Query("select distinct group_id from event where visibility =:vis")
List<Long> findGroup_idsWhereVisibility(@Param("vis") Boolean visibility);
@Query("select distinct group_id from event where visibility =:vis")
List<Long> findGroup_idsWhereVisibility(@Param("vis") Boolean visibility);
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
public List<Long> findNewEventSinceStatus(@Param("status") Long status);

View File

@ -1,12 +1,14 @@
package mops.gruppen2.security;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Set;
@Getter
@AllArgsConstructor
public class Account {
private final String name; //user_id
private final String email;
private final String image;

View File

@ -16,39 +16,30 @@ import org.springframework.web.client.RestTemplate;
@Configuration
public class KeycloakConfig {
@Value("${keycloak.resource}")
private String clientId;
@Value("${keycloak.credentials.secret}")
private String clientSecret;
@Value("${hhu_keycloak.token-uri}")
private String tokenUri;
@Bean
public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
@Value("${keycloak.resource}")
private String clientId;
@Value("${keycloak.credentials.secret}")
private String clientSecret;
@Value("${hhu_keycloak.token-uri}")
private String tokenUri;
@Bean
public RestTemplate serviceAccountRestTemplate() {
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setGrantType(OAuth2Constants.CLIENT_CREDENTIALS);
resourceDetails.setAccessTokenUri(tokenUri);
resourceDetails.setClientId(clientId);
resourceDetails.setClientSecret(clientSecret);
return new OAuth2RestTemplate(resourceDetails);
}
}
}

View File

@ -48,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
@ -61,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();
@ -88,5 +88,6 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
jsr250Enabled = true)
public static class MethodSecurityConfig
extends GlobalMethodSecurityConfiguration {
}
}

View File

@ -8,7 +8,8 @@ import java.util.List;
@Service
public class APIFormatterService {
static public UpdatedGroupRequestMapper wrapp(Long status, List<Group> groupList){
static public UpdatedGroupRequestMapper wrapp(Long status, List<Group> groupList) {
return new UpdatedGroupRequestMapper(status, groupList);
}
}

View File

@ -1,8 +1,18 @@
package mops.gruppen2.service;
import mops.gruppen2.domain.*;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.event.*;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.DeleteGroupEvent;
import mops.gruppen2.domain.event.DeleteUserEvent;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.domain.event.UpdateRoleEvent;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service;
@ -34,7 +44,7 @@ public class ControllerService {
createInviteLink(group_id);
}
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.SIMPLE, visibility1);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.SIMPLE, visibility1);
eventService.saveEvent(createGroupEvent);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
@ -49,8 +59,8 @@ public class ControllerService {
}
public void addUser(Account account, Long group_id){
AddUserEvent addUserEvent = new AddUserEvent(group_id,account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
public void addUser(Account account, Long group_id) {
AddUserEvent addUserEvent = new AddUserEvent(group_id, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
eventService.saveEvent(addUserEvent);
}
@ -61,13 +71,13 @@ public class ControllerService {
}
}
public void updateTitle(Account account, Long group_id, String title){
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
public void updateTitle(Account account, Long group_id, String title) {
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id, account.getName(), title);
eventService.saveEvent(updateGroupTitleEvent);
}
public void updateDescription(Account account, Long group_id, String description){
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(group_id,account.getName(),description);
public void updateDescription(Account account, Long group_id, String description) {
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(group_id, account.getName(), description);
eventService.saveEvent(updateGroupDescriptionEvent);
}
@ -76,7 +86,9 @@ public class ControllerService {
Group group = userService.getGroupById(group_id);
User user = null;
for (User member : group.getMembers()) {
if(member.getUser_id().equals(user_id)) user = member;
if (member.getUser_id().equals(user_id)) {
user = member;
}
}
assert user != null;
if (group.getRoles().get(user.getUser_id()) == Role.ADMIN) {
@ -91,7 +103,9 @@ public class ControllerService {
Group group = userService.getGroupById(group_id);
User user = null;
for (User member : group.getMembers()) {
if(member.getUser_id().equals(user_id)) user = member;
if (member.getUser_id().equals(user_id)) {
user = member;
}
}
assert user != null;
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id, user.getUser_id());

View File

@ -13,6 +13,7 @@ import java.util.List;
@Service
public class EventService {
private final SerializationService serializationService;
private final EventRepository eventStore;

View File

@ -1,9 +1,8 @@
package mops.gruppen2.service;
import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.security.Account;
@ -25,7 +24,8 @@ public class GroupService {
this.eventRepository = eventRepository;
}
/** Sucht in der DB alle Zeilen raus welche eine der Gruppen_ids hat.
/**
* Sucht in der DB alle Zeilen raus welche eine der Gruppen_ids hat.
* Wandelt die Zeilen in Events um und gibt davon eine Liste zurück.
*
* @param group_ids
@ -33,14 +33,15 @@ public class GroupService {
*/
public List<Event> getGroupEvents(List<Long> group_ids) {
List<EventDTO> eventDTOS = new ArrayList<>();
for (Long group_id: group_ids) {
for (Long group_id : group_ids) {
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id));
}
return eventService.translateEventDTOs(eventDTOS);
}
/** Erzeugt eine neue Map wo Gruppen aus den Events erzeugt und den Gruppen_ids zugeordnet werden.
* Die Gruppen werden als Liste zurückgegeben
/**
* 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
* @return
@ -57,8 +58,9 @@ public class GroupService {
return new ArrayList<>(groupMap.values());
}
/** guckt in der Map anhand der Id nach ob die Gruppe schon in der Map vorhanden ist, wenn nicht wird eine neue
* Gruppe erzeugt
/**
* guckt in der Map anhand der Id nach ob die Gruppe schon in der Map vorhanden ist, wenn nicht wird eine neue
* Gruppe erzeugt
*
* @param groups
* @param group_id
@ -73,7 +75,7 @@ public class GroupService {
}
private List<Long> removeUserGroups(List<Long> group_ids, List<Long> user_groups) {
for (Long group_id: user_groups) {
for (Long group_id : user_groups) {
group_ids.remove(group_id);
}
return group_ids;
@ -82,6 +84,7 @@ public class GroupService {
/**
* sucht alle Zeilen in der DB wo die Visibility true ist und entfernt alle Gruppen des Users.
* Erstellt eine Liste aus Gruppen.
*
* @return
* @throws EventException
*/
@ -97,14 +100,15 @@ public class GroupService {
/**
* Filtert alle öffentliche Gruppen nach dem suchbegriff und gibt diese als Liste von Gruppen zurück.
* Groß und kleinschreibung wird beachtet.
*
* @param search
* @return
* @throws EventException
*/
public List<Group> findGroupWith(String search, Account account) throws EventException {
List<Group> groups = new ArrayList<>();
for (Group group: getAllGroupWithVisibilityPublic(account.getName())) {
if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())){
for (Group group : getAllGroupWithVisibilityPublic(account.getName())) {
if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())) {
groups.add(group);
}
}

View File

@ -28,7 +28,7 @@ public class SerializationService {
* @return JSON-Event-Payload als String
* @throws JsonProcessingException
*/
public String serializeEvent(Event event) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(event);

View File

@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
//Hallo
@Service
public class UserService {
@ -25,11 +26,11 @@ public class UserService {
public List<Group> getUserGroups(User user) throws EventException {
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user.getUser_id());
List<Event> events = groupService.getGroupEvents(group_ids);
List<Event> events = groupService.getGroupEvents(group_ids);
List<Group> groups = groupService.projectEventList(events);
List<Group> newGroups = new ArrayList<>();
for (Group group: groups) {
if(group.getMembers().contains(user)){
for (Group group : groups) {
if (group.getMembers().contains(user)) {
newGroups.add(group);
}
}