Skip to content
Snippets Groups Projects

Resolve "Add batch number, program and updated from to application export"

Files

@@ -18,9 +18,11 @@
package nl.tudelft.tam.controller;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
import nl.tudelft.labracore.api.dto.ProgramDetailsDTO;
import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.tam.enums.Status;
@@ -29,6 +31,7 @@ import nl.tudelft.tam.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
@@ -50,6 +53,9 @@ public class ApplicationController {
@Autowired
EditionService editionService;
@Autowired
ProgramService programService;
// endregion
// region view pages
@@ -57,17 +63,35 @@ public class ApplicationController {
/**
* Gets the coordinator page.
*
* @param person The authenticated person
* @param model The model to add data to
* @return The coordinator page
* @param person The authenticated person
* @param program The program to see the applications for
* @param since The applcations changed since this time
* @param model The model to add data to
* @return The coordinator page
*/
@GetMapping("all")
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
public String getAllApplications(@AuthenticatedPerson Person person, Model model) {
model.addAttribute("applications", applicationService.getCoordinatingApplications(person.getId())
public String getAllApplications(@AuthenticatedPerson Person person,
@RequestParam(required = false) Long program,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime since,
Model model) {
List<ProgramDetailsDTO> programs = programService.getCoordinatingPrograms(person.getId());
if (program == null) {
program = programs.get(0).getId();
}
List<Application> applications = applicationService
.getCoordinatingApplicationsForProgram(person.getId(), program)
.stream()
.filter(x -> !editionService.getOrThrow(x.getJobOffer().getEditionId()).getIsArchived())
.collect(Collectors.toList()));
.filter(a -> !editionService.getOrThrow(a.getJobOffer().getEditionId()).getIsArchived())
.collect(Collectors.toList());
if (since != null) {
applications = applicationService.filterApplicationsChangedSince(applications, since);
}
model.addAttribute("applications", applications);
model.addAttribute("exports", applicationService.getExportsForPersonAndProgram(person, program));
model.addAttribute("programs", programs);
return "application/all";
}
@@ -219,15 +243,18 @@ public class ApplicationController {
*/
@GetMapping("flex-delft-export")
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
public ResponseEntity<Resource> exportApplicationsForFlexDelft(@AuthenticatedPerson Person person)
public ResponseEntity<Resource> exportApplicationsForFlexDelft(@AuthenticatedPerson Person person,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime since,
@RequestParam Long program, @RequestParam Integer batch)
throws IOException {
List<Application> appList = applicationService.getCoordinatingApplications(person.getId()).stream()
.filter(x -> !editionService.getOrThrow(x.getJobOffer().getEditionId())
.getIsArchived() && x.getStatus() == Status.ACCEPTED)
List<Application> appList = applicationService
.getCoordinatingApplicationsForProgram(person.getId(), program).stream()
.filter(x -> !editionService.getOrThrow(x.getJobOffer().getEditionId()).getIsArchived())
.collect(Collectors.toList());
return csvService
.getResponse(applicationService.exportApplicationsForFlexDelft("applications", appList));
.getResponse(applicationService.exportApplicationsForFlexDelft(person, program, batch,
"applications", appList, since));
}
}
Loading