]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Group.java
fix: Avoid warning when PoJAM is disabled
[gigi.git] / src / org / cacert / gigi / dbObjects / Group.java
index 69f8e40bf7434422bf56a957ffaceec528a0601a..dd6767ef783cb8e0a309403983a90e6c17e22c90 100644 (file)
@@ -1,58 +1,29 @@
 package org.cacert.gigi.dbObjects;
 
-import java.util.HashMap;
-
-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 class Group {
-
-    private static HashMap<String, Group> cache = new HashMap<>();
+public enum Group {
+    SUPPORTER("supporter", "supporter"), ARBITRATOR("arbitrator", "arbitrator"), //
+    BLOCKEDASSURER("blockedassurer", "may not verify"), BLOCKEDASSUREE("blockedassuree", "may not be verified"), //
+    BLOCKEDLOGIN("blockedlogin", "may not login"), BLOCKEDCERT("blockedcert", "may not issue certificates"), //
+    TTP_ASSURER("ttp-assurer", "may verify via TTP"), TTP_APPLICANT("ttp-applicant", "requests to be verified via ttp"), //
+    CODESIGNING("codesigning", "may issue codesigning certificates"), ORGASSURER("orgassurer", "may verify 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) {
-        dbName = name;
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((dbName == null) ? 0 : dbName.hashCode());
-        return result;
-    }
+    private final TranslateCommand tc;
 
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        Group other = (Group) obj;
-        if (dbName == null) {
-            if (other.dbName != null) {
-                return false;
-            }
-        } else if ( !dbName.equals(other.dbName)) {
-            return false;
-        }
-        return true;
+    private Group(String name, String display) {
+        dbName = name;
+        tc = new TranslateCommand(display);
     }
 
-    public static synchronized Group getByString(String name) {
-        Group g = cache.get(name);
-        if (g == null) {
-            g = new Group(name);
-            cache.put(name, g);
-        }
-        return g;
+    public static Group getByString(String name) {
+        return valueOf(name.toUpperCase().replace('-', '_'));
     }
 
     public String getDatabaseName() {
@@ -60,18 +31,23 @@ public class Group {
     }
 
     public User[] getMembers(int offset, int count) {
-        GigiPreparedStatement gps = DatabaseConnection.getInstance().prepare("SELECT user FROM user_groups WHERE permission=? AND deleted is NULL 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;
     }
 }