Skip to content
Snippets Groups Projects

Deploy

34 files
+ 1136
327
Compare changes
  • Side-by-side
  • Inline

Files

@@ -20,14 +20,11 @@ package nl.tudelft.tam.controller;
@@ -20,14 +20,11 @@ package nl.tudelft.tam.controller;
import java.io.IOException;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.util.*;
import java.util.*;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.PageableDefault;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Controller;
@@ -39,6 +36,7 @@ import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
@@ -39,6 +36,7 @@ import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.tam.controller.utility.PageUtil;
import nl.tudelft.tam.controller.utility.PageUtil;
import nl.tudelft.tam.dto.create.ApplicationCreateDTO;
import nl.tudelft.tam.dto.create.ApplicationCreateDTO;
 
import nl.tudelft.tam.dto.util.ApplicationFilterDTO;
import nl.tudelft.tam.dto.view.details.ApplicationDetailsJobOfferDTO;
import nl.tudelft.tam.dto.view.details.ApplicationDetailsJobOfferDTO;
import nl.tudelft.tam.enums.Status;
import nl.tudelft.tam.enums.Status;
import nl.tudelft.tam.model.Application;
import nl.tudelft.tam.model.Application;
@@ -69,44 +67,60 @@ public class ApplicationController {
@@ -69,44 +67,60 @@ public class ApplicationController {
/**
/**
* Gets the coordinator page.
* Gets the coordinator page.
*
*
* @param person The authenticated person
* @param person The authenticated person
* @param program The program to see the applications for
* @param filter The filter to apply to the applications
* @param since The applications changed since this time
* @param model The model to add data to
* @param model The model to add data to
* @return The coordinator page
* @return The coordinator page
*/
*/
@GetMapping("all")
@GetMapping("all")
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
public String getAllApplications(@AuthenticatedPerson Person person,
public String getAllApplications(@AuthenticatedPerson Person person,
@RequestParam(required = false) Long program,
ApplicationFilterDTO filter,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime since,
@PageableDefault(value = 25) Pageable pageable,
@PageableDefault(value = 25) Pageable pageable,
Model model) {
Model model) {
List<ProgramDetailsDTO> programs = programService.getCoordinatingPrograms(person.getId());
List<ProgramDetailsDTO> programs = programService.getCoordinatingPrograms(person.getId());
if (program == null) {
if (filter.getProgram() == null) {
program = programs.get(0).getId();
filter.setProgram(programs.get(0).getId());
}
}
List<Application> applications = applicationService
List<Application> applications = applicationService
.getCoordinatingApplicationsForProgram(person.getId(), program)
.getFilteredCoordinatingApplications(person.getId(), filter);
.stream()
.filter(a -> !editionService.getOrThrow(a.getJobOffer().getEditionId()).getIsArchived())
model.addAttribute("applications", PageUtil.pageFromList(applications, pageable));
.collect(Collectors.toList());
model.addAttribute("programs", programs);
if (since != null) {
applications = applicationService.filterApplicationsChangedSince(applications, since);
}
// Exclude retracted applications
return "application/all";
applications = applications.stream().filter(x -> !x.getStatus().equals(Status.REJECTED_BY_STUDENT))
}
.collect(Collectors.toList());
 
/**
 
* Gets the coordinator page, with FlexDelft filters.
 
*
 
* @param person The authenticated person
 
* @param filter The filter to apply to the applications
 
* @param model The model to add data to
 
* @return The coordinator page
 
*/
 
@GetMapping("all/flexdelft")
 
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
 
public String getAllApplicationsForFlexDelft(@AuthenticatedPerson Person person,
 
ApplicationFilterDTO filter,
 
@PageableDefault(value = 25) Pageable pageable,
 
Model model) {
 
List<ProgramDetailsDTO> programs = programService.getCoordinatingPrograms(person.getId());
 
if (filter.getProgram() == null) {
 
filter.setProgram(programs.get(0).getId());
 
}
// Pagination
filter.setStatuses(List.of(Status.ACCEPTED));
Page<Application> pageOfApplications = PageUtil.pageFromList(applications, pageable);
List<Application> applications = applicationService
 
.getFilteredCoordinatingApplications(person.getId(), filter);
model.addAttribute("applications", pageOfApplications);
model.addAttribute("applications", PageUtil.pageFromList(applications, pageable));
model.addAttribute("exports", applicationService.getExportsForPersonAndProgram(person, program));
model.addAttribute("exports",
 
applicationService.getExportsForPersonAndProgram(person, filter.getProgram()));
model.addAttribute("programs", programs);
model.addAttribute("programs", programs);
return "application/all";
 
return "application/all_flexdelft";
}
}
/**
/**
@@ -330,15 +344,12 @@ public class ApplicationController {
@@ -330,15 +344,12 @@ public class ApplicationController {
* @return The export file as a resource
* @return The export file as a resource
*/
*/
@GetMapping("export")
@GetMapping("export")
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
@PreAuthorize("@authorisationService.isCoordinatorForProgram(#filter.program)")
public ResponseEntity<Resource> exportApplications(@AuthenticatedPerson Person person)
public ResponseEntity<Resource> exportApplications(@AuthenticatedPerson Person person,
 
ApplicationFilterDTO filter)
throws IOException {
throws IOException {
return csvService.getResponse(applicationService.exportApplications("applications",
return csvService.getResponse(applicationService.exportApplications("applications",
applicationService.getCoordinatingApplications(person.getId()).stream()
applicationService.getFilteredCoordinatingApplications(person.getId(), filter)));
.filter(x -> !editionService.getOrThrow(x.getJobOffer().getEditionId())
.getIsArchived())
.filter(x -> !x.getStatus().equals(Status.REJECTED_BY_STUDENT))
.collect(Collectors.toList())));
}
}
/**
/**
@@ -348,20 +359,17 @@ public class ApplicationController {
@@ -348,20 +359,17 @@ public class ApplicationController {
* @return The export file as a resource
* @return The export file as a resource
*/
*/
@GetMapping("flex-delft-export")
@GetMapping("flex-delft-export")
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
@PreAuthorize("@authorisationService.isCoordinatorForProgram(#filter.program)")
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,
ApplicationFilterDTO filter, @RequestParam Integer batch)
@RequestParam Long program, @RequestParam Integer batch)
throws IOException {
throws IOException {
List<Application> appList = applicationService
filter.setStatuses(List.of(Status.ACCEPTED));
.getCoordinatingApplicationsForProgram(person.getId(), program).stream()
List<Application> appList = applicationService.getFilteredCoordinatingApplications(person.getId(),
.filter(x -> !editionService.getOrThrow(x.getJobOffer().getEditionId()).getIsArchived())
filter);
.filter(x -> x.getStatus().equals(Status.ACCEPTED))
.collect(Collectors.toList());
return csvService
return csvService
.getResponse(applicationService.exportApplicationsForFlexDelft(person, program, batch,
.getResponse(
"applications", appList, since));
applicationService.exportApplicationsForFlexDelft(person, filter.getProgram(), batch,
 
"applications", appList, filter.getUpdatedSince()));
}
}
}
}
Loading