package at.ac.tuwien.inso.controller.grade;

import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;

import at.ac.tuwien.inso.service.GradeService;
import at.ac.tuwien.inso.view.pdf.GradePDFView;


@Controller
@RequestMapping("/public/grade")
public class PublicGradeController{

    @Autowired
    public GradeService gradeService;

    @GetMapping
    public ModelAndView generateGradePDF(@RequestParam("identifier") String identifier,
                                         ModelMap modelMap,
                                         HttpServletRequest request,
                                         HttpServletResponse response) throws Exception {

        View view = new GradePDFView();
        modelMap.addAttribute("grade", gradeService.getForValidation(identifier));
        modelMap.addAttribute("validationLink",
                request.getRequestURL().toString() + "?identifier=" + identifier);
        ModelAndView modelAndView = new ModelAndView(view);
        return modelAndView;
    }



}

@@ -42,123 +42,8 @@
 e;%0A%0A
-import javax.servlet.http.HttpServletResponse;%0A%0Aimport org.apache.catalina.servlet4preview.http.HttpServletRequest;
 %0Aimp
@@ -102,16 +102,74 @@
 owired;%0A
+import org.springframework.http.server.ServerHttpRequest;%0A
 import o
@@ -531,16 +531,113 @@
 t.View;%0A
+import org.springframework.web.util.UriComponentsBuilder;%0A%0Aimport at.ac.tuwien.inso.entity.Grade;
 %0Aimport 
@@ -1071,105 +1071,49 @@
     
-HttpServletRequest request,%0A                                         HttpServletResponse response
+UriComponentsBuilder uriComponentsBuilder
 ) th
@@ -1182,38 +1182,21 @@
     
-modelMap.addAttribute(%22
+Grade 
 grade
-%22,
+ =
  gra
@@ -1233,19 +1233,107 @@
 ntifier)
+;%0A        if (grade == null) %7B%0A            return new ModelAndView(%22error/404%22
 );%0A
+        %7D%0A
         
@@ -1359,80 +1359,210 @@
 te(%22
-validationLink%22,%0A                request.getRequestURL().toString() + %22?
+grade%22, grade);%0A        modelMap.addAttribute(%0A                %22validationLink%22,%0A                uriComponentsBuilder%0A                        .path(%22/public/grade%22)%0A                        .queryParam(%22
 iden
@@ -1571,12 +1571,10 @@
 fier
-=%22 +
+%22,
  ide
@@ -1573,32 +1573,111 @@
 er%22, identifier)
+%0A                        .build()%0A                        .toString()%0A        )
 ;%0A        ModelA

Fix PublicGradeController validation link generator