Skip to content
Snippets Groups Projects

Add batches to declarations

Files

@@ -18,6 +18,7 @@
package nl.tudelft.tam.controller;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@@ -26,12 +27,14 @@ import org.springframework.core.io.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
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.controller.utility.PageUtil;
@@ -41,6 +44,7 @@ import nl.tudelft.tam.model.Declaration;
import nl.tudelft.tam.service.CSVService;
import nl.tudelft.tam.service.DeclarationService;
import nl.tudelft.tam.service.EditionService;
import nl.tudelft.tam.service.ProgramService;
@Controller
@RequestMapping("declaration")
@@ -57,6 +61,9 @@ public class DeclarationController {
@Autowired
EditionService editionService;
@Autowired
ProgramService programService;
// endregion
// region view pages
@@ -71,19 +78,32 @@ public class DeclarationController {
@GetMapping("all")
@PreAuthorize("@authorisationService.isCoordinatorOfAny()")
public String getAllDeclarations(@AuthenticatedPerson Person person,
@RequestParam(required = false) Long program,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime since,
@PageableDefault(value = 25) Pageable pageable,
Model model) {
List<Declaration> declarations = declarationService.getCoordinatingDeclarations(person.getId())
List<ProgramDetailsDTO> programs = programService.getCoordinatingPrograms(person.getId());
if (program == null) {
program = programs.get(0).getId();
}
List<Declaration> declarations = declarationService
.getCoordinatingDeclarationsForProgram(person.getId(), program)
.stream()
.filter(x -> !editionService.getOrThrow(x.getExtraWork().getEditionId())
.getIsArchived())
.filter(x -> !x.getStatus().equals(Status.REJECTED_BY_STUDENT))
.toList();
if (since != null) {
declarations = declarationService.filterDeclarationsChangedSince(declarations, since);
}
// Pagination
Page<Declaration> pageOfDeclarations = PageUtil.pageFromList(declarations, pageable);
model.addAttribute("declarations", pageOfDeclarations);
model.addAttribute("exports", declarationService.getExportsForPersonAndProgram(person, program));
model.addAttribute("programs", programs);
return "declaration/all";
}
@@ -210,15 +230,19 @@ public class DeclarationController {
*/
@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<Declaration> decList = declarationService.getCoordinatingDeclarations(person.getId()).stream()
.filter(x -> !editionService.getOrThrow(x.getExtraWork().getEditionId())
.getIsArchived() && x.getStatus() == Status.ACCEPTED)
List<Declaration> decList = declarationService
.getCoordinatingDeclarations(person.getId()).stream()
.filter(x -> !editionService.getOrThrow(x.getExtraWork().getEditionId()).getIsArchived())
.filter(x -> x.getStatus() == Status.ACCEPTED)
.collect(Collectors.toList());
return csvService
.getResponse(declarationService.exportDeclarationsForFlexDelft("declarations", decList));
.getResponse(declarationService.exportDeclarationsForFlexDelft(person, program, batch,
"declarations", decList, since));
}
}
Loading