1

removed unneccessary fields, decreased field visibility

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-18 21:32:05 +01:00
parent 2ba913f2c8
commit e4d8fb05cb
21 changed files with 76 additions and 127 deletions

View File

@ -10,7 +10,6 @@ import mops.gruppen2.domain.event.Event;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -26,36 +25,33 @@ import java.util.List;
@RequestMapping("/gruppen2/api")
public class APIController {
private final SerializationService serializationService;
private final EventService eventService;
private final GroupService groupService;
public APIController(SerializationService serializationService, EventService eventService, GroupService groupService) {
this.serializationService = serializationService;
public APIController(EventService eventService, GroupService groupService) {
this.eventService = eventService;
this.groupService = groupService;
}
@GetMapping("/updateGroups/{status}")
@Secured("ROLE_api_user")
@ApiOperation(value = "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 UpdatedGroupRequestMapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
List<Event> events = eventService.getNewEvents(status);
UpdatedGroupRequestMapper updatedGroupRequestMapper = APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
return updatedGroupRequestMapper;
return APIFormatterService.wrapp(eventService.getMaxEvent_id(), groupService.projectEventList(events));
}
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
@Secured("ROLE_api_user")
@ApiOperation(value = "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<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) throws EventException {
return eventService.getGroupsOfUser(teilnehmer);
}
@GetMapping("/getGroup/{groupId}")
@Secured("ROLE_api_user")
@ApiOperation(value = "Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException {
List<Event> eventList = eventService.getEventsOfGroup(groupId);

View File

@ -8,7 +8,6 @@ import mops.gruppen2.domain.User;
import mops.gruppen2.security.Account;
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;
@ -38,7 +37,6 @@ import java.util.List;
public class Gruppen2Controller {
private final KeyCloakService keyCloakService;
private final EventService eventService;
private final GroupService groupService;
private final UserService userService;
private final ControllerService controllerService;
@ -46,9 +44,8 @@ public class Gruppen2Controller {
@Autowired
Gruppen2Config gruppen2Config;
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService) {
public Gruppen2Controller(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService) {
this.keyCloakService = keyCloakService;
this.eventService = eventService;
this.groupService = groupService;
this.userService = userService;
this.controllerService = controllerService;
@ -83,8 +80,8 @@ 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("title") String title,
@RequestParam("beschreibung") String beschreibung,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
@ -101,7 +98,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("group_id") Long group_id,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
List<User> userList = new ArrayList<>();
if (!file.isEmpty()) {
@ -134,8 +131,8 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/createGroup")
public String pCreateGroup(KeycloakAuthenticationToken token,
@RequestParam(value = "title") String title,
@RequestParam(value = "beschreibung") String beschreibung,
@RequestParam("title") String title,
@RequestParam("beschreibung") String beschreibung,
@RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
@ -147,7 +144,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("id") Long id) throws EventException, ResponseStatusException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id);
@ -165,7 +162,7 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten")
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam("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());
@ -179,7 +176,7 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/detailsSearch")
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long id) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id);
if (group != null) {
@ -203,7 +200,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("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);
@ -212,7 +209,7 @@ 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("id") Long id) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(id);
if (group.getRoles().get(account.getName()) == Role.ADMIN) {
@ -228,22 +225,17 @@ 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("group_id") Long group_id,
@RequestParam("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("group_id") Long group_id,
@RequestParam("user_id") String user_id) throws EventException {
controllerService.deleteUser(user_id, group_id);
return "redirect:/gruppen2/details/members/" + group_id;
}
@GetMapping("*")
public String defaultLink() {
return "errorRenameLater";
}
}

View File

@ -18,4 +18,9 @@ public class MopsController {
request.logout();
return "redirect:/gruppen2/";
}
@GetMapping("*")
public String defaultLink() {
return "errorRenameLater";
}
}

View File

@ -1,7 +1,5 @@
package mops.gruppen2.domain;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@ -13,15 +11,13 @@ import java.util.Map;
/**
* Repräsentiert den aggregierten Zustand einer Gruppe.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@AllArgsConstructor
public class Group {
private final List<User> members;
private final Map<String, Role> roles;
private long id;
private Long id;
private String title;
private String description;
private GroupType type;

View File

@ -1,12 +0,0 @@
package mops.gruppen2.domain;
import lombok.Value;
// @ApiModelProperty
@Value
public class ProductSwaggerExample {
// @ApiModelProperty
String name;
String description;
}

View File

@ -1,18 +1,16 @@
package mops.gruppen2.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.Getter;
@Data
@Getter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
public class User {
String user_id;
String givenname;
String familyname;
String email;
private final String user_id;
private final String givenname;
private final String familyname;
private final String email;
}

View File

@ -1,17 +1,13 @@
package mops.gruppen2.domain.apiWrapper;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mops.gruppen2.domain.Group;
import java.util.List;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class UpdatedGroupRequestMapper {
private Long status;
private List<Group> groupList;
private final Long status;
private final List<Group> groupList;
}

View File

@ -1,11 +1,11 @@
package mops.gruppen2.domain.dto;
import lombok.Data;
import lombok.Value;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Table("event")
@Data
@Value
public class EventDTO {
@Id

View File

@ -1,13 +1,11 @@
package mops.gruppen2.domain.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Value;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Table("invite")
@Data
@AllArgsConstructor
@Value
public class InviteLinkDTO {
@Id

View File

@ -14,12 +14,12 @@ import mops.gruppen2.domain.User;
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor // For Jackson
public class AddUserEvent extends Event {
String givenname;
String familyname;
String email;
private String givenname;
private String familyname;
private String email;
public AddUserEvent(Long group_id, String user_id, String givenname, String familyname, String email) {
super(group_id, user_id);

View File

@ -9,7 +9,7 @@ import mops.gruppen2.domain.Visibility;
@Getter
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor // For Jackson
public class CreateGroupEvent extends Event {
private Visibility groupVisibility;

View File

@ -1,11 +1,11 @@
package mops.gruppen2.domain.event;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mops.gruppen2.domain.Group;
@EqualsAndHashCode(callSuper = true)
@Value
@Getter
@NoArgsConstructor // For Jackson
public class DeleteGroupEvent extends Event {
public DeleteGroupEvent(long group_id, String user_id) {

View File

@ -11,7 +11,7 @@ import mops.gruppen2.domain.User;
* Entfernt ein einzelnes Mitglied einer Gruppe.
*/
@Getter
@NoArgsConstructor
@NoArgsConstructor // For Jackson
public class DeleteUserEvent extends Event {
public DeleteUserEvent(Long group_id, String user_id) {

View File

@ -5,14 +5,10 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group;
@Getter
@NoArgsConstructor
@AllArgsConstructor
@JsonTypeInfo(
include = JsonTypeInfo.As.PROPERTY,
use = JsonTypeInfo.Id.NAME,
@ -26,13 +22,13 @@ import mops.gruppen2.domain.Group;
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
})
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Event {
Long group_id;
String user_id;
protected Long group_id;
protected String user_id;
public void apply(Group group) throws EventException {
}
public void apply(Group group) throws EventException {}
}

View File

@ -10,10 +10,10 @@ import mops.gruppen2.domain.Group;
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor // For Jackson
public class UpdateGroupDescriptionEvent extends Event {
String newGroupDescription;
private String newGroupDescription;
public UpdateGroupDescriptionEvent(Long group_id, String user_id, String newGroupDescription) {
super(group_id, user_id);

View File

@ -10,10 +10,10 @@ import mops.gruppen2.domain.Group;
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor // For Jackson
public class UpdateGroupTitleEvent extends Event {
String newGroupTitle;
private String newGroupTitle;
public UpdateGroupTitleEvent(Long group_id, String user_id, String newGroupTitle) {
super(group_id, user_id);

View File

@ -12,10 +12,10 @@ import mops.gruppen2.domain.Role;
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor // For Jackson
public class UpdateRoleEvent extends Event {
Role newRole;
private Role newRole;
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
super(group_id, user_id);

View File

@ -1,18 +1,16 @@
package mops.gruppen2.security;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Value;
import java.util.Set;
@Getter
@AllArgsConstructor
@Value
public class Account {
private final String name; //user_id
private final String email;
private final String image;
private final String givenname;
private final String familyname;
private final Set<String> roles;
String email;
String image;
String name; //user_id
String givenname;
String familyname;
Set<String> roles;
}

View File

@ -40,23 +40,19 @@ public class EventService {
* @return EventDTO
*/
public EventDTO getDTO(Event event) {
EventDTO eventDTO = new EventDTO();
eventDTO.setGroup_id(event.getGroup_id());
eventDTO.setUser_id(event.getUser_id());
boolean visibility = false;
if (event instanceof CreateGroupEvent) {
if (((CreateGroupEvent) event).getGroupVisibility() == Visibility.PRIVATE) {
eventDTO.setVisibility(false);
} else {
eventDTO.setVisibility(true);
}
visibility = ((CreateGroupEvent) event).getGroupVisibility() == Visibility.PRIVATE;
}
String payload = "";
try {
eventDTO.setEvent_payload(serializationService.serializeEvent(event));
payload = serializationService.serializeEvent(event);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return eventDTO;
return new EventDTO(null, event.getGroup_id(), event.getUser_id(), payload, visibility);
}
/**

View File

@ -3,9 +3,6 @@ package mops.gruppen2.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
/**
@ -14,13 +11,6 @@ import org.springframework.stereotype.Service;
@Service
public class SerializationService {
private final EventRepository eventStore;
private final Logger log = LoggerFactory.getLogger(SerializationService.class);
public SerializationService(EventRepository eventStore) {
this.eventStore = eventStore;
}
/**
* Übersetzt mithilfe der Jackson-Library eine Java-Event-Repräsentation zu einem JSON-Event-Payload.
*

View File

@ -14,8 +14,8 @@ import java.util.List;
@Service
public class UserService {
final EventRepository eventRepository;
final GroupService groupService;
private final EventRepository eventRepository;
private final GroupService groupService;
public UserService(EventRepository eventRepository, GroupService groupService) {
this.eventRepository = eventRepository;