]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Group.java
add: implement + test api for find-an-agent-system
[gigi.git] / src / org / cacert / gigi / dbObjects / Group.java
index 8a2c1de479755ed0bce9d529dfffd014e93f1295..d5d38efde66a175172b88f2c0448d860d2cb8b2f 100644 (file)
@@ -1,16 +1,25 @@
 package org.cacert.gigi.dbObjects;
 
-import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.TranslateCommand;
 
 public enum Group {
-    SUPPORTER("supporter"), ARBITRATOR("arbitrator"), BLOCKEDASSURER("blockedassurer"), BLOCKEDASSUREE("blockedassuree"), BLOCKEDLOGIN("blockedlogin"), TTP_ASSURER("ttp-assurer"), TTP_APPLICANT("ttp-applicant"), CODESIGNING("codesigning"), ORGASSURER("orgassurer");
+    SUPPORTER("supporter", "supporter"), ARBITRATOR("arbitrator", "arbitrator"), //
+    BLOCKEDASSURER("blockedassurer", "may not assure"), BLOCKEDASSUREE("blockedassuree", "may not be assured"), //
+    BLOCKEDLOGIN("blockedlogin", "may not login"), BLOCKEDCERT("blockedcert", "may not issue certificates"), //
+    TTP_ASSURER("ttp-assurer", "may assure via TTP"), TTP_APPLICANT("ttp-applicant", "requests to be assured via ttp"), //
+    CODESIGNING("codesigning", "may issue codesigning certificates"), ORGASSURER("orgassurer", "may assure organisations"), //
+    NUCLEUS_ASSURER("nucleus-assurer", "may issue nucleus assurances"), LOCATE_AGENT("locate-agent", "wants access to the locate agent system");
 
     private final String dbName;
 
-    private Group(String name) {
+    private final TranslateCommand tc;
+
+    private Group(String name, String display) {
         dbName = name;
+        tc = new TranslateCommand(display);
     }
 
     public static Group getByString(String name) {
@@ -22,18 +31,23 @@ public enum Group {
     }
 
     public User[] getMembers(int offset, int count) {
-        GigiPreparedStatement gps = DatabaseConnection.getInstance().prepareScrollable("SELECT `user` FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL OFFSET ? LIMIT ?");
-        gps.setString(1, dbName);
-        gps.setInt(2, offset);
-        gps.setInt(3, count);
-        GigiResultSet grs = gps.executeQuery();
-        grs.last();
-        User[] users = new User[grs.getRow()];
-        int i = 0;
-        grs.beforeFirst();
-        while (grs.next()) {
-            users[i++] = User.getById(grs.getInt(1));
+        try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT `user` FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL OFFSET ? LIMIT ?", true)) {
+            gps.setString(1, dbName);
+            gps.setInt(2, offset);
+            gps.setInt(3, count);
+            GigiResultSet grs = gps.executeQuery();
+            grs.last();
+            User[] users = new User[grs.getRow()];
+            int i = 0;
+            grs.beforeFirst();
+            while (grs.next()) {
+                users[i++] = User.getById(grs.getInt(1));
+            }
+            return users;
         }
-        return users;
+    }
+
+    public Outputable getName() {
+        return tc;
     }
 }