View Javadoc
1   /*
2    * Copyright 2018-2022 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7    *
8    * This file is part of MRECore project.
9    *
10   * MRECore is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation, either version 3 of the License.
13   *
14   * MRECore is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with MRECore. If not, see <http://www.gnu.org/licenses/>.
21   */
22  package cz.zcu.mre.controller;
23  
24  import cz.zcu.mre.data.support.IssueTicket;
25  import cz.zcu.mre.data.support.MessageHelper;
26  import jakarta.validation.Valid;
27  import org.springframework.stereotype.Controller;
28  import org.springframework.ui.Model;
29  import org.springframework.web.bind.annotation.RequestMapping;
30  import org.springframework.web.bind.annotation.RequestMethod;
31  import java.security.Principal;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  import org.springframework.validation.BindingResult;
35  
36  /**
37   * Issue Controller for reporting an issue or request.
38   * 
39   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
40   */
41  @Controller
42  public class IssueController {
43  
44      private static final Logger LOG = LoggerFactory.getLogger(IssueController.class);
45  
46      @RequestMapping(value = "/issue", method = RequestMethod.GET)
47      public String issue(Principal principal, Model model) {
48  
49          // initialize issue ticket by user name (email)
50          IssueTicket s = new IssueTicket();
51          s.setFrom(principal.getName());
52          model.addAttribute("issueTicket", s);
53  
54          return "web/issue";
55      }
56  
57      @RequestMapping(value = "/issue", method = RequestMethod.POST)
58      public String issue(Principal principal, Model model, @Valid IssueTicket issueTicket, BindingResult result) {
59  
60          LOG.info("{}", issueTicket);
61  
62          if (result.hasErrors()) {
63              LOG.warn("{}", result);
64              return "web/issue";
65          }
66  
67          // TODO send issue
68          //IssueWebhook.issueReport(issueTicket.getName(), issueTicket.getMessage());
69          MessageHelper.addSuccessAttribute(model, "issue.success");
70          LOG.info("Reported issue {}", issueTicket);
71          return "/ibdt/intro";
72      }
73  }