]> WPIA git - gigi.git/blob - src/club/wpia/gigi/pages/wot/Points.java
upd: rename package name and all references to it
[gigi.git] / src / club / wpia / gigi / pages / wot / Points.java
1 package club.wpia.gigi.pages.wot;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import club.wpia.gigi.dbObjects.User;
10 import club.wpia.gigi.output.AssurancesDisplay;
11 import club.wpia.gigi.pages.Page;
12 import club.wpia.gigi.util.AuthorizationContext;
13
14 public class Points extends Page {
15
16     public static final String SUPPORT_PATH = "/support/user/*/points";
17
18     public static final String PATH = "/wot/points";
19
20     private static final int intStart = SUPPORT_PATH.indexOf('*');
21
22     private boolean support;
23
24     private AssurancesDisplay myDisplay;
25
26     private AssurancesDisplay toOtherDisplay;
27
28     public Points(boolean support) {
29         super(support ? "Support User Points" : "Points");
30         this.support = support;
31         myDisplay = new AssurancesDisplay("asArr", false, support);
32         toOtherDisplay = new AssurancesDisplay("otherAsArr", true, support);
33     }
34
35     @Override
36     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
37         User user;
38         if (support) {
39             String info = req.getPathInfo();
40             int id = Integer.parseInt(info.substring(intStart, info.length() - SUPPORT_PATH.length() + intStart + 1));
41             user = User.getById(id);
42             if (user == null) {
43                 resp.sendError(404);
44                 return;
45             }
46         } else {
47             user = getUser(req);
48         }
49
50         HashMap<String, Object> vars = new HashMap<String, Object>();
51         vars.put("support", support);
52         vars.put("username", user.getPreferredName().toString());
53         vars.put("pointlist", myDisplay);
54         vars.put("madelist", toOtherDisplay);
55         vars.put("asArr", user.getReceivedAssurances());
56         vars.put("otherAsArr", user.getMadeAssurances());
57         vars.put("assP", user.getAssurancePoints());
58         if (user.canAssure()) {
59             vars.put("expP", user.getExperiencePoints());
60             vars.put("maxP", user.getMaxAssurePoints());
61         }
62         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
63     }
64
65     @Override
66     public boolean isPermitted(AuthorizationContext ac) {
67         if (ac == null) {
68             return false;
69         }
70         if (support) {
71             return ac.canSupport();
72         } else {
73             return ac.getTarget() instanceof User;
74         }
75     }
76
77 }