upd: new Manager function, adding exp-points
authorFelix Dörre <felix@dogcraft.de>
Tue, 5 Apr 2016 09:40:42 +0000 (11:40 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 7 Apr 2016 11:59:27 +0000 (13:59 +0200)
util-testing/org/cacert/gigi/pages/Manager.java
util-testing/org/cacert/gigi/pages/Manager.templ

index ebfd73b9d605a15d1d72402d2840a8b52c440a54..3ac191ac030bf4d4fc886cb685237d08e4c5977f 100644 (file)
@@ -90,36 +90,38 @@ public class Manager extends Page {
         }
     }
 
-    public User[] getAssurers() {
-        if (assurers != null) {
-            return assurers;
+    public User getAssurer(int i) {
+        if (assurers[i] != null) {
+            return assurers[i];
         }
-        assurers = new User[10];
         try {
-            try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?")) {
-                for (int i = 0; i < assurers.length; i++) {
-                    String mail = "test-assurer" + i + "@example.com";
-                    User u = User.getByEmail(mail);
-                    if (u == null) {
-                        System.out.println("Creating assurer");
-                        createUser(mail);
-                        u = User.getByEmail(mail);
-                        passCATS(u);
-                        ps.setInt(1, u.getId());
-                        ps.setInt(2, u.getId());
-                        ps.setInt(3, 100);
-                        ps.setString(4, "Manager init code");
-                        ps.setString(5, "1990-01-01");
-                        ps.execute();
-                    }
-                    assurers[i] = u;
+            User u = createAssurer(i);
+            assurers[i] = u;
 
-                }
-            }
         } catch (ReflectiveOperationException | GigiApiException e) {
             e.printStackTrace();
         }
-        return assurers;
+        return assurers[i];
+    }
+
+    private User createAssurer(int i) throws GigiApiException, IllegalAccessException {
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?")) {
+            String mail = "test-assurer" + i + "@example.com";
+            User u = User.getByEmail(mail);
+            if (u == null) {
+                System.out.println("Creating assurer");
+                createUser(mail);
+                u = User.getByEmail(mail);
+                passCATS(u);
+                ps.setInt(1, u.getId());
+                ps.setInt(2, u.getId());
+                ps.setInt(3, 100);
+                ps.setString(4, "Manager init code");
+                ps.setString(5, "1990-01-01");
+                ps.execute();
+            }
+            return u;
+        }
     }
 
     private void passCATS(User u) {
@@ -219,7 +221,7 @@ public class Manager extends Page {
         ea.verify(hash);
     }
 
-    User[] assurers;
+    User[] assurers = new User[25];
 
     @Override
     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
@@ -259,13 +261,24 @@ public class Manager extends Page {
                 return;
             }
             try {
-                for (int i = 0; i < getAssurers().length; i++) {
-                    Notary.assure(getAssurers()[i], byEmail, byEmail.getName(), byEmail.getDoB(), 10, "Testmanager Assure up code", "2014-11-06", AssuranceType.FACE_TO_FACE);
+                for (int i = 0; i < 10; i++) {
+                    Notary.assure(getAssurer(i), byEmail, byEmail.getName(), byEmail.getDoB(), 10, "Testmanager Assure up code", "2014-11-06", AssuranceType.FACE_TO_FACE);
                 }
             } catch (GigiApiException e) {
                 throw new Error(e);
             }
             resp.getWriter().println("User has been assured.");
+        } else if (req.getParameter("letassure") != null) {
+            String mail = req.getParameter("letassureEmail");
+            User byEmail = User.getByEmail(mail);
+            try {
+                for (int i = 0; i < 25; i++) {
+                    User a = getAssurer(i);
+                    Notary.assure(byEmail, a, a.getName(), a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE);
+                }
+            } catch (GigiApiException e) {
+                throw new Error(e);
+            }
         } else if (req.getParameter("addEmail") != null) {
             User u = User.getByEmail(req.getParameter("addEmailEmail"));
             try {
@@ -365,7 +378,6 @@ public class Manager extends Page {
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        getAssurers();
         String pi = req.getPathInfo().substring(PATH.length());
         if (pi.length() > 1 && pi.startsWith("/fetch-")) {
             String mail = pi.substring(pi.indexOf('-', 2) + 1);
index 434ccf97c3f4cd946b99b85e209726eaa599681d..a7101ec299bfd1ae868647366cce3f8530e8252b 100644 (file)
@@ -54,6 +54,14 @@ Email: <input type="text" name="assureEmail"/>
 <input type="submit" value="Assure 100 Points" name="assure"/>
 </td></tr>
 
+<tr><td>
+Assure 25 others (get 25 experience points)    :
+</td><td>
+Email: <input type="text" name="letassureEmail"/>
+</td><td>
+<input type="submit" value="Add 25 experience Points" name="letassure"/>
+</td></tr>
+
 <tr><td>
 Add verified Email:
 </td><td>