backend-api #6
@ -27,6 +27,7 @@ dependencies {
|
|||||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
|
||||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
|
||||||
implementation 'org.postgresql:postgresql'
|
implementation 'org.postgresql:postgresql'
|
||||||
|
implementation group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13.3'
|
||||||
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
testImplementation 'com.h2database:h2'
|
testImplementation 'com.h2database:h2'
|
||||||
|
@ -81,7 +81,7 @@ public class AdminApi {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/admin/appoitements/report/{appointmentId}")
|
@PostMapping("/admin/appoitements/report/{appointmentId}")
|
||||||
public void createAppointmentReport(
|
public void createAppointmentReport(
|
||||||
@PathVariable String appointmentId,
|
@PathVariable long appointmentId,
|
||||||
@RequestBody Report report,
|
@RequestBody Report report,
|
||||||
@AuthenticationPrincipal Jwt principal) {
|
@AuthenticationPrincipal Jwt principal) {
|
||||||
adminApiService.createAppointmentReport(
|
adminApiService.createAppointmentReport(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package enseirb.myinpulse.controller;
|
package enseirb.myinpulse.controller;
|
||||||
|
|
||||||
|
import com.itextpdf.text.DocumentException;
|
||||||
import enseirb.myinpulse.model.*;
|
import enseirb.myinpulse.model.*;
|
||||||
import enseirb.myinpulse.service.SharedApiService;
|
import enseirb.myinpulse.service.SharedApiService;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|||||||
import org.springframework.security.oauth2.jwt.Jwt;
|
import org.springframework.security.oauth2.jwt.Jwt;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@RestController
|
@RestController
|
||||||
public class SharedApi {
|
public class SharedApi {
|
||||||
@ -78,7 +82,11 @@ public class SharedApi {
|
|||||||
@GetMapping("/shared/projects/appointments/report/{appointmentId}")
|
@GetMapping("/shared/projects/appointments/report/{appointmentId}")
|
||||||
public void getPDFReport(
|
public void getPDFReport(
|
||||||
@PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) {
|
@PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) {
|
||||||
|
try {
|
||||||
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email"));
|
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email"));
|
||||||
|
} catch (FileNotFoundException | DocumentException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,4 +115,8 @@ public class Appointment {
|
|||||||
public Report getAppointmentReport() {
|
public Report getAppointmentReport() {
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAppointmentReport(Report report) {
|
||||||
|
this.report = report;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,4 +37,12 @@ public class Report {
|
|||||||
public void setReportContent(String reportContent) {
|
public void setReportContent(String reportContent) {
|
||||||
this.reportContent = reportContent;
|
this.reportContent = reportContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Appointment getAppointmentReport() {
|
||||||
|
return appointmentReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppointmentReport(Appointment appointmentReport) {
|
||||||
|
this.appointmentReport = appointmentReport;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,12 @@ import enseirb.myinpulse.model.*;
|
|||||||
import enseirb.myinpulse.service.database.AdministratorService;
|
import enseirb.myinpulse.service.database.AdministratorService;
|
||||||
import enseirb.myinpulse.service.database.ProjectService;
|
import enseirb.myinpulse.service.database.ProjectService;
|
||||||
import enseirb.myinpulse.service.database.UserService;
|
import enseirb.myinpulse.service.database.UserService;
|
||||||
|
import enseirb.myinpulse.service.database.AppointmentService;
|
||||||
|
import enseirb.myinpulse.service.database.ReportService;
|
||||||
|
import enseirb.myinpulse.service.UtilsService;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -13,30 +19,41 @@ import org.springframework.web.server.ResponseStatusException;
|
|||||||
@Service
|
@Service
|
||||||
public class AdminApiService {
|
public class AdminApiService {
|
||||||
|
|
||||||
|
protected static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final AdministratorService administratorService;
|
private final AdministratorService administratorService;
|
||||||
|
private final UtilsService utilsService;
|
||||||
|
private final AppointmentService appointmentService;
|
||||||
|
private final ReportService reportService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
AdminApiService(
|
AdminApiService(
|
||||||
ProjectService projectService,
|
ProjectService projectService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
AdministratorService administratorService) {
|
AdministratorService administratorService,
|
||||||
|
UtilsService utilsService,
|
||||||
|
AppointmentService appointmentService,
|
||||||
|
ReportService reportService) {
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.administratorService = administratorService;
|
this.administratorService = administratorService;
|
||||||
|
this.utilsService = utilsService;
|
||||||
|
this.appointmentService = appointmentService;
|
||||||
|
this.reportService = reportService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test
|
// TODO: test
|
||||||
public Iterable<Project> getProjectsOfAdmin(String email) {
|
public Iterable<Project> getProjectsOfAdmin(String mail) {
|
||||||
return projectService.getProjectsByAdminId(
|
return projectService.getProjectsByAdminId(
|
||||||
administratorService.getAdministratorById(
|
administratorService.getAdministratorById(
|
||||||
this.userService.getUserByEmail(email).getIdUser()));
|
this.userService.getUserByEmail(mail).getIdUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
public Iterable<Appointment> getUpcomingAppointments(String email) {
|
public Iterable<Appointment> getUpcomingAppointments(String mail) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
logger.info("User {} check their upcoming appointments", mail);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test
|
// TODO: test
|
||||||
@ -60,9 +77,26 @@ public class AdminApiService {
|
|||||||
projectService.addNewProject(project); // TODO: how can the front know the ID ?
|
projectService.addNewProject(project); // TODO: how can the front know the ID ?
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
public void createAppointmentReport(long appointmentId, Report report, String mail) {
|
||||||
public void createAppointmentReport(String appointmentId, Report report, String email) {
|
long projectId =
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
this.appointmentService
|
||||||
|
.getAppointmentById(appointmentId)
|
||||||
|
.getAppointmentListSectionCell()
|
||||||
|
.getFirst()
|
||||||
|
.getProjectSectionCell()
|
||||||
|
.getIdProject();
|
||||||
|
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
||||||
|
logger.warn(
|
||||||
|
"User {} tried to add an report for appointment {} but is not allowed to.",
|
||||||
|
mail,
|
||||||
|
projectId);
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
|
||||||
|
}
|
||||||
|
logger.info("User {} added a report for appointment {}", mail, projectId);
|
||||||
|
Report addedReport = this.reportService.addNewReport(report);
|
||||||
|
addedReport.setAppointmentReport(this.appointmentService.getAppointmentById(appointmentId));
|
||||||
|
this.appointmentService.getAppointmentById(appointmentId).setAppointmentReport(addedReport);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test
|
// TODO: test
|
||||||
|
@ -10,6 +10,11 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import com.itextpdf.text.*;
|
||||||
|
import com.itextpdf.text.pdf.PdfWriter;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -118,8 +123,9 @@ public class SharedApiService {
|
|||||||
return appointments;
|
return appointments;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
//
|
||||||
public void getPDFReport(long appointmentId, String mail) {
|
public void getPDFReport(long appointmentId, String mail)
|
||||||
|
throws FileNotFoundException, DocumentException {
|
||||||
long projectId =
|
long projectId =
|
||||||
this.appointmentService
|
this.appointmentService
|
||||||
.getAppointmentById(appointmentId)
|
.getAppointmentById(appointmentId)
|
||||||
@ -139,15 +145,82 @@ public class SharedApiService {
|
|||||||
throw new ResponseStatusException(
|
throw new ResponseStatusException(
|
||||||
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
|
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
|
||||||
}
|
}
|
||||||
/* return this.appointmentService
|
logger.info(
|
||||||
|
"User {} generated the PDF report related to appointment {}", mail, appointmentId);
|
||||||
|
|
||||||
|
String reportContent =
|
||||||
|
this.appointmentService
|
||||||
.getAppointmentById(appointmentId)
|
.getAppointmentById(appointmentId)
|
||||||
.getAppointmentReport().getReportContent(); */
|
.getAppointmentReport()
|
||||||
// generate pdf from this string, and format it to be decent looking
|
.getReportContent();
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
|
||||||
|
// PDF generation
|
||||||
|
Document document = new Document();
|
||||||
|
PdfWriter.getInstance(document, new FileOutputStream("Report" + appointmentId + ".pdf"));
|
||||||
|
document.open();
|
||||||
|
|
||||||
|
Paragraph title =
|
||||||
|
new Paragraph(
|
||||||
|
new Phrase(
|
||||||
|
"Compte Rendu - Réunion du "
|
||||||
|
+ this.appointmentService
|
||||||
|
.getAppointmentById(appointmentId)
|
||||||
|
.getAppointmentDate()
|
||||||
|
.toString(),
|
||||||
|
FontFactory.getFont(
|
||||||
|
FontFactory.HELVETICA,
|
||||||
|
20,
|
||||||
|
Font.BOLDITALIC,
|
||||||
|
BaseColor.BLACK)));
|
||||||
|
title.setAlignment(Element.ALIGN_CENTER);
|
||||||
|
document.add(title);
|
||||||
|
|
||||||
|
Font subsection =
|
||||||
|
FontFactory.getFont(FontFactory.HELVETICA, 14, Font.UNDERLINE, BaseColor.DARK_GRAY);
|
||||||
|
Font body = FontFactory.getFont(FontFactory.COURIER, 12, BaseColor.BLACK);
|
||||||
|
|
||||||
|
String[] split = reportContent.split(" ");
|
||||||
|
|
||||||
|
String tmp = "";
|
||||||
|
int counter = 1;
|
||||||
|
for (String s : split) {
|
||||||
|
if (s.equals("//")) {
|
||||||
|
Chunk chunk = new Chunk(tmp, body);
|
||||||
|
document.add(chunk);
|
||||||
|
document.add(new Paragraph("\n"));
|
||||||
|
tmp = "";
|
||||||
|
Paragraph paragraph = new Paragraph("Point n°" + counter + " : ", subsection);
|
||||||
|
document.add(paragraph);
|
||||||
|
document.add(new Paragraph("\n"));
|
||||||
|
counter++;
|
||||||
|
} else {
|
||||||
|
tmp = tmp.concat(s + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Chunk chunk = new Chunk(tmp, body);
|
||||||
|
document.add(chunk);
|
||||||
|
document.add(new Paragraph("\n"));
|
||||||
|
|
||||||
|
document.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
public void createAppointmentRequest(Appointment appointment, String mail) {
|
public void createAppointmentRequest(Appointment appointment, String mail) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
long projectId =
|
||||||
|
appointment
|
||||||
|
.getAppointmentListSectionCell()
|
||||||
|
.getFirst()
|
||||||
|
.getProjectSectionCell()
|
||||||
|
.getIdProject();
|
||||||
|
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
||||||
|
logger.warn(
|
||||||
|
"User {} tried to create for the project {} but is not allowed to.",
|
||||||
|
mail,
|
||||||
|
projectId);
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
|
||||||
|
}
|
||||||
|
logger.info("User {} tried to create an appointment for project {}", mail, projectId);
|
||||||
|
this.appointmentService.addNewAppointment(appointment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
documentation/Doc.txt
Normal file
12
documentation/Doc.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Format des comptes rendus de réunion :
|
||||||
|
Texte organisé par bullet point, chaque bullet point est séparé par "//" pour pouvoir être correctement généré.
|
||||||
|
|
||||||
|
Exemple :
|
||||||
|
Le texte "// blablabla // oui bonjour"
|
||||||
|
donne le résultat
|
||||||
|
|
||||||
|
Point n°1 :
|
||||||
|
blablabla
|
||||||
|
|
||||||
|
Point n°2 :
|
||||||
|
oui bonjour
|
Loading…
x
Reference in New Issue
Block a user