Merge pull request #96 from hhu-propra2/feature-orga-csv
Feature orga csv
This commit is contained in:
@ -68,6 +68,7 @@ dependencies {
|
||||
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.2'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
@ -77,6 +78,8 @@ dependencies {
|
||||
|
||||
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.4.0.RELEASE'
|
||||
|
||||
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.10.3'
|
||||
|
||||
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'
|
||||
|
||||
@ -7,13 +7,13 @@ 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.APIFormatterService;
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.SerializationService;
|
||||
import mops.gruppen2.service.*;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -59,4 +59,5 @@ public class APIController {
|
||||
List<Group> groups = groupService.projectEventList(eventList);
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import mops.gruppen2.config.Gruppen2Config;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.*;
|
||||
@ -13,13 +14,18 @@ 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.client.RestTemplate;
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
public class Gruppen2Controller {
|
||||
|
||||
@ -54,14 +60,36 @@ public class Gruppen2Controller {
|
||||
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
|
||||
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_studentin", "ROLE_actuator"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@GetMapping("/createLecture")
|
||||
public String createLecture(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
return "createLecture";
|
||||
}
|
||||
|
||||
@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("file") MultipartFile file) throws IOException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
visibility = visibility == null;
|
||||
controllerService.createLecture(account, title, beschreibung, visibility, userList);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/createGroup")
|
||||
public String createGroup(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
|
||||
@ -3,10 +3,11 @@ package mops.gruppen2.domain;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Value
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
|
||||
public class User {
|
||||
String user_id;
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.*;
|
||||
import mops.gruppen2.domain.event.*;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -34,8 +31,9 @@ public class ControllerService {
|
||||
* @param description Gruppenbeschreibung
|
||||
*/
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility) {
|
||||
Long group_id = eventService.checkGroup();
|
||||
Visibility visibility1;
|
||||
Long group_id = eventService.checkGroup();
|
||||
|
||||
if(visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
@ -43,7 +41,7 @@ public class ControllerService {
|
||||
createInviteLink(group_id);
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.LECTURE, visibility1);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.SIMPLE, visibility1);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, group_id);
|
||||
@ -62,6 +60,13 @@ public class ControllerService {
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
|
||||
public void addUserList(List<User> users, Long group_id) {
|
||||
for (User user : users) {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(group_id, user.getUser_id(), user.getGivenname(), user.getFamilyname(), user.getEmail());
|
||||
eventService.saveEvent(addUserEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTitle(Account account, Long group_id, String title){
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id,account.getName(),title);
|
||||
eventService.saveEvent(updateGroupTitleEvent);
|
||||
@ -81,4 +86,24 @@ public class ControllerService {
|
||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
||||
eventService.saveEvent(deleteUserEvent);
|
||||
}
|
||||
|
||||
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) {
|
||||
Visibility visibility1;
|
||||
Long group_id = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.LECTURE, visibility1);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, group_id);
|
||||
updateTitle(account, group_id, title);
|
||||
updateDescription(account, group_id, description);
|
||||
updateRole(account, group_id);
|
||||
addUserList(users, group_id);
|
||||
}
|
||||
}
|
||||
|
||||
24
src/main/java/mops/gruppen2/service/CsvService.java
Normal file
24
src/main/java/mops/gruppen2/service/CsvService.java
Normal file
@ -0,0 +1,24 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
||||
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
||||
import mops.gruppen2.domain.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CsvService {
|
||||
|
||||
public static List<User> read(InputStream stream) throws IOException {
|
||||
CsvMapper mapper = new CsvMapper();
|
||||
|
||||
CsvSchema schema = mapper.schemaFor(User.class).withHeader().withColumnReordering(true);
|
||||
ObjectReader reader = mapper.readerFor(User.class).with(schema);
|
||||
|
||||
return reader.<User>readValues(stream).readAll();
|
||||
}
|
||||
}
|
||||
@ -22,6 +22,9 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
70
src/main/resources/templates/createLecture.html
Normal file
70
src/main/resources/templates/createLecture.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org"
|
||||
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
|
||||
xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Gruppenerstellung</title>
|
||||
<th:block th:fragment="headcontent">
|
||||
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||
</th:block>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<ul>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}" class="active">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Veranstaltung erstellen</h1>
|
||||
<div class="shadow p-2" style=" border: 10px solid aliceblue; background: aliceblue">
|
||||
<form method="post" action="/gruppen2/createLecture" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label for="titel">Titel</label>
|
||||
<input type="text" class="form-control" id="titel" th:name="title" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="beschreibung">Beschreibung</label>
|
||||
<textarea th:name="beschreibung" class="form-control" id="beschreibung" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input type="checkbox" id="visibility" class="custom-control-input" th:name="visibility">
|
||||
<label class="custom-control-label" for="visibility">Private Gruppe</label>
|
||||
</div>
|
||||
<div class="form-group pt-4">
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" id="file" th:name="file">
|
||||
<label class="custom-file-label" for="file">CSV Datei von Mitgliedern hochladen</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group pt-4">
|
||||
<button class="btn btn-primary" type="submit" style="background: #52a1eb; border-style: none">Erstellen</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@ -21,6 +21,9 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -21,6 +21,10 @@
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<!-- Fix double point -->
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
<li class="active">
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user