Compare commits
No commits in common. "137bc84c21536e42218506e9d9875c283fd0b4b4" and "5ee375554899cc335e3dface6ee68453945f5b40" have entirely different histories.
137bc84c21
...
5ee3755548
@ -1,7 +1,6 @@
|
|||||||
package enseirb.myinpulse.controller;
|
package enseirb.myinpulse.controller;
|
||||||
|
|
||||||
import com.itextpdf.text.DocumentException;
|
import com.itextpdf.text.DocumentException;
|
||||||
|
|
||||||
import enseirb.myinpulse.model.*;
|
import enseirb.myinpulse.model.*;
|
||||||
import enseirb.myinpulse.service.SharedApiService;
|
import enseirb.myinpulse.service.SharedApiService;
|
||||||
|
|
||||||
@ -11,8 +10,7 @@ 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.IOException;
|
import java.io.FileNotFoundException;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@RestController
|
@RestController
|
||||||
@ -85,12 +83,10 @@ public class SharedApi {
|
|||||||
@PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) {
|
@PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) {
|
||||||
try {
|
try {
|
||||||
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email"));
|
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email"));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println(e + "File not found");
|
||||||
} catch (DocumentException e) {
|
} catch (DocumentException e) {
|
||||||
System.out.println(e + "Document exception");
|
System.out.println(e + "Document exception");
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
System.out.println(e + "Error with URI");
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println(e + "Failed to access file");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,11 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
|
|||||||
import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
|
import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
|
||||||
|
|
||||||
import enseirb.myinpulse.model.*;
|
import enseirb.myinpulse.model.*;
|
||||||
import enseirb.myinpulse.service.database.*;
|
import enseirb.myinpulse.service.database.AdministratorService;
|
||||||
|
import enseirb.myinpulse.service.database.AppointmentService;
|
||||||
|
import enseirb.myinpulse.service.database.ProjectService;
|
||||||
|
import enseirb.myinpulse.service.database.ReportService;
|
||||||
|
import enseirb.myinpulse.service.database.UserService;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -13,9 +17,6 @@ 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 java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AdminApiService {
|
public class AdminApiService {
|
||||||
|
|
||||||
@ -27,7 +28,6 @@ public class AdminApiService {
|
|||||||
private final UtilsService utilsService;
|
private final UtilsService utilsService;
|
||||||
private final AppointmentService appointmentService;
|
private final AppointmentService appointmentService;
|
||||||
private final ReportService reportService;
|
private final ReportService reportService;
|
||||||
private final SectionCellService sectionCellService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
AdminApiService(
|
AdminApiService(
|
||||||
@ -36,15 +36,13 @@ public class AdminApiService {
|
|||||||
AdministratorService administratorService,
|
AdministratorService administratorService,
|
||||||
UtilsService utilsService,
|
UtilsService utilsService,
|
||||||
AppointmentService appointmentService,
|
AppointmentService appointmentService,
|
||||||
ReportService reportService,
|
ReportService reportService) {
|
||||||
SectionCellService sectionCellService) {
|
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.administratorService = administratorService;
|
this.administratorService = administratorService;
|
||||||
this.utilsService = utilsService;
|
this.utilsService = utilsService;
|
||||||
this.appointmentService = appointmentService;
|
this.appointmentService = appointmentService;
|
||||||
this.reportService = reportService;
|
this.reportService = reportService;
|
||||||
this.sectionCellService = sectionCellService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check if tests are sufficient - peer verification required
|
// TODO: check if tests are sufficient - peer verification required
|
||||||
@ -54,36 +52,10 @@ public class AdminApiService {
|
|||||||
this.userService.getUserByEmail(mail).getIdUser()));
|
this.userService.getUserByEmail(mail).getIdUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
public Iterable<Appointment> getUpcomingAppointments(String mail) {
|
public Iterable<Appointment> getUpcomingAppointments(String mail) {
|
||||||
logger.info("User {} check their upcoming appointments", mail);
|
logger.info("User {} check their upcoming appointments", mail);
|
||||||
User user = this.userService.getUserByEmail(mail);
|
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
||||||
List<Appointment> appointments = new ArrayList<>();
|
|
||||||
if (user instanceof Administrator) {
|
|
||||||
List<Project> projects = new ArrayList<>(((Administrator) user).getListProject());
|
|
||||||
projects.forEach(
|
|
||||||
project -> {
|
|
||||||
project.getListSectionCell()
|
|
||||||
.forEach(
|
|
||||||
sectionCell -> {
|
|
||||||
appointments.addAll(
|
|
||||||
this.sectionCellService
|
|
||||||
.getAppointmentsBySectionCellId(
|
|
||||||
sectionCell
|
|
||||||
.getIdSectionCell()));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (user instanceof Entrepreneur) {
|
|
||||||
Project project = ((Entrepreneur) user).getProjectParticipation();
|
|
||||||
project.getListSectionCell()
|
|
||||||
.forEach(
|
|
||||||
sectionCell -> {
|
|
||||||
appointments.addAll(
|
|
||||||
this.sectionCellService.getAppointmentsBySectionCellId(
|
|
||||||
sectionCell.getIdSectionCell()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return appointments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check if tests are sufficient - peer verification required
|
// TODO: check if tests are sufficient - peer verification required
|
||||||
|
@ -13,14 +13,8 @@ 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 java.io.File;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
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;
|
||||||
@ -101,6 +95,7 @@ public class SharedApiService {
|
|||||||
return project.getProjectAdministrator();
|
return project.getProjectAdministrator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
public Iterable<Appointment> getAppointmentsByProjectId(long projectId, String mail) {
|
public Iterable<Appointment> getAppointmentsByProjectId(long projectId, String mail) {
|
||||||
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
@ -128,8 +123,9 @@ public class SharedApiService {
|
|||||||
return appointments;
|
return appointments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
public void getPDFReport(long appointmentId, String mail)
|
public void getPDFReport(long appointmentId, String mail)
|
||||||
throws DocumentException, URISyntaxException, IOException {
|
throws FileNotFoundException, DocumentException {
|
||||||
long projectId =
|
long projectId =
|
||||||
this.appointmentService
|
this.appointmentService
|
||||||
.getAppointmentById(appointmentId)
|
.getAppointmentById(appointmentId)
|
||||||
@ -206,24 +202,9 @@ public class SharedApiService {
|
|||||||
document.add(new Paragraph("\n"));
|
document.add(new Paragraph("\n"));
|
||||||
|
|
||||||
document.close();
|
document.close();
|
||||||
|
|
||||||
// Replace uri with website address
|
|
||||||
Files.copy(
|
|
||||||
new URI(
|
|
||||||
"http://localhost:8080/shared/projects/appointments/report/"
|
|
||||||
+ appointmentId)
|
|
||||||
.toURL()
|
|
||||||
.openStream(),
|
|
||||||
Paths.get("Report" + appointmentId + ".pdf"),
|
|
||||||
StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
|
|
||||||
// delete file, we don't want to stock all reports on the server
|
|
||||||
File file = new File("Report" + appointmentId + ".pdf");
|
|
||||||
if (!file.delete()) {
|
|
||||||
logger.warn("Failed to delete report {}", file.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
public void createAppointmentRequest(Appointment appointment, String mail) {
|
public void createAppointmentRequest(Appointment appointment, String mail) {
|
||||||
long projectId =
|
long projectId =
|
||||||
appointment
|
appointment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user