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;
-public class Group {
-
- private static HashMap<String, Group> cache = new HashMap<>();
+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");
private final String dbName;
dbName = name;
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((dbName == null) ? 0 : dbName.hashCode());
- return result;
+ public static Group getByString(String name) {
+ return valueOf(name.toUpperCase().replace('-', '_'));
}
- @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;
+ public String getDatabaseName() {
+ return dbName;
}
- public static synchronized Group getByString(String name) {
- Group g = cache.get(name);
- if (g == null) {
- g = new Group(name);
- cache.put(name, g);
+ 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));
}
- return g;
- }
-
- public String getDatabaseName() {
- return dbName;
+ return users;
}
}