chg: adjust ticket number handling according to current number scheme
[gigi.git] / src / club / wpia / gigi / pages / admin / support / SupportEnterTicketForm.java
1 package club.wpia.gigi.pages.admin.support;
2
3 import java.io.PrintWriter;
4 import java.util.Map;
5
6 import javax.servlet.http.HttpServletRequest;
7
8 import club.wpia.gigi.Gigi;
9 import club.wpia.gigi.GigiApiException;
10 import club.wpia.gigi.localisation.Language;
11 import club.wpia.gigi.output.template.Form;
12 import club.wpia.gigi.output.template.Template;
13 import club.wpia.gigi.pages.LoginPage;
14 import club.wpia.gigi.util.AuthorizationContext;
15 import club.wpia.gigi.util.CalendarUtil;
16
17 public class SupportEnterTicketForm extends Form {
18
19     private static final Template t = new Template(SupportEnterTicketForm.class.getResource("SupportEnterTicketForm.templ"));
20
21     public static final String TICKET_PREFIX = "acdhi";
22
23     public SupportEnterTicketForm(HttpServletRequest hsr) {
24         super(hsr);
25     }
26
27     @Override
28     public SubmissionResult submit(HttpServletRequest req) throws GigiApiException {
29         if (req.getParameter("setTicket") != null) {
30             // [acdhi]\d{8}\.\d+ according to numbering scheme
31             String ticket = req.getParameter("ticketno").toLowerCase();
32             if (ticket.matches("[" + TICKET_PREFIX + "]\\d{8}\\.\\d+") && CalendarUtil.isDateValid(ticket.substring(1, 9))) {
33                 AuthorizationContext ac = LoginPage.getAuthorizationContext(req);
34                 req.getSession().setAttribute(Gigi.AUTH_CONTEXT, new AuthorizationContext(ac.getActor(), ticket));
35                 return new RedirectResult(SupportEnterTicketPage.PATH);
36             }
37             throw new GigiApiException("Ticket format malformed");
38         } else if (req.getParameter("deleteTicket") != null) {
39             AuthorizationContext ac = LoginPage.getAuthorizationContext(req);
40             req.getSession().setAttribute(Gigi.AUTH_CONTEXT, new AuthorizationContext(ac.getActor(), ac.getActor()));
41             return new RedirectResult(SupportEnterTicketPage.PATH);
42         }
43         throw new GigiApiException("No valid action given.");
44     }
45
46     @Override
47     protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
48         t.output(out, l, vars);
49     }
50
51 }