]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/GroupSelector.java
upd: cleanup SQL statements to make them statically verifiable.
[gigi.git] / src / org / cacert / gigi / output / GroupSelector.java
index a12a5cd49b6bf9b1e4f84f8a958882798fdc7791..9d3080ddc1aaf3646ebc08631d6edd3553affc7e 100644 (file)
@@ -17,20 +17,22 @@ public class GroupSelector implements Outputable {
 
     private Group value = null;
 
-    private final boolean supportFlag;
+    private final boolean bySupporter;
 
-    public GroupSelector(String name, boolean supportFlag) {
+    public GroupSelector(String name, boolean bySupporter) {
         this.name = HTMLEncoder.encodeHTML(name);
-        this.supportFlag = supportFlag;
+        this.bySupporter = bySupporter;
     }
 
     public void update(HttpServletRequest r) throws GigiApiException {
         String vS = r.getParameter(name);
-        value = null;
-        for (Group g : Group.values()) {
-            if (g.getDatabaseName().equals(vS) && g.isManagedBySupport() == supportFlag) {
-                value = g;
-            }
+        if (vS == null) {
+            throw new GigiApiException("No value for group.");
+        }
+        try {
+            value = Group.getByString(vS);
+        } catch (IllegalArgumentException e) {
+            throw new GigiApiException("Invalid value for group.");
         }
     }
 
@@ -38,8 +40,8 @@ public class GroupSelector implements Outputable {
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
         out.println("<select name='" + name + "'>");
         for (Group g : Group.values()) {
-            if (supportFlag == g.isManagedBySupport()) {
-                out.print("<option value='" + g.getDatabaseName());
+            if (mayManage(g)) {
+                out.print("<option value='" + g.getDBName());
                 if (g.equals(value)) {
                     out.print(" selected");
                 }
@@ -51,6 +53,10 @@ public class GroupSelector implements Outputable {
         out.println("</select>");
     }
 
+    private boolean mayManage(Group g) {
+        return (bySupporter && g.isManagedBySupport()) || ( !bySupporter && g.isManagedByUser());
+    }
+
     public Group getGroup() {
         return value;
     }