Skip to content
Snippets Groups Projects

Resolve "[Queue-2.0] Export requests in a lab"

9 files
+ 304
27
Compare changes
  • Side-by-side
  • Inline

Files

@@ -20,6 +20,7 @@ package nl.tudelft.queue.controller;
import static nl.tudelft.queue.service.LabService.SessionType.REGULAR;
import static nl.tudelft.queue.service.LabService.SessionType.SHARED;
import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
@@ -55,16 +56,25 @@ import nl.tudelft.queue.model.enums.QueueSessionType;
import nl.tudelft.queue.model.enums.RequestType;
import nl.tudelft.queue.model.labs.*;
import nl.tudelft.queue.repository.QueueSessionRepository;
import nl.tudelft.queue.service.*;
import nl.tudelft.queue.service.LabService;
import nl.tudelft.queue.service.PermissionService;
import nl.tudelft.queue.service.RequestService;
import nl.tudelft.queue.service.RequestTableService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ContentDisposition;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.google.common.net.HttpHeaders;
@Controller
public class LabController {
@Autowired
@@ -612,6 +622,29 @@ public class LabController {
return "redirect:/lab/" + session.getId();
}
/**
* Exports the entire session request info to a single CSV file.
*
* @param session The session to export to a file.
* @return The Resource representing the file to download in a response with appropriate
* headers set.
* @throws IOException when something goes wrong when writing the file.
*/
@GetMapping("/lab/{session}/export")
@PreAuthorize("@permissionService.canManageSession(#session)")
public ResponseEntity<Resource> exportSession(@PathEntity QueueSession<?> session) throws IOException {
var resource = ls.sessionToCsv(session);
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(resource.contentLength())
.header(HttpHeaders.CONTENT_DISPOSITION,
ContentDisposition.attachment()
.filename("session-export-" + session.getId() + ".csv")
.build().toString())
.body(resource);
}
/**
* Sets the model attributes for an enqueueing or editing requests page.
*
Loading