]> WPIA git - gigi.git/commitdiff
refactor: move two dbObjects-inner classes to their own types.
authorFelix Dörre <felix@dogcraft.de>
Thu, 22 Oct 2015 11:32:47 +0000 (13:32 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 22 Oct 2015 11:32:47 +0000 (13:32 +0200)
src/org/cacert/gigi/dbObjects/Domain.java
src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java
src/org/cacert/gigi/dbObjects/DomainPingExecution.java [new file with mode: 0644]
src/org/cacert/gigi/dbObjects/DomainPingType.java [new file with mode: 0644]
src/org/cacert/gigi/pages/account/domain/DomainPinglogForm.java
src/org/cacert/gigi/pages/account/domain/PingConfigForm.java
src/org/cacert/gigi/ping/PingerDaemon.java
tests/org/cacert/gigi/ping/TestHTTP.java

index c0787b6c535e51b1d6f3f4956f8c4be947983e97..c165c4abdbcaedc7e1e457715a5a021090304a19 100644 (file)
@@ -15,53 +15,10 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
-import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
 import org.cacert.gigi.util.PublicSuffixes;
 
 public class Domain implements IdCachable, Verifyable {
 
-    public class DomainPingExecution {
-
-        private String state;
-
-        private String type;
-
-        private String info;
-
-        private String result;
-
-        private DomainPingConfiguration config;
-
-        public DomainPingExecution(GigiResultSet rs) {
-            state = rs.getString(1);
-            type = rs.getString(2);
-            info = rs.getString(3);
-            result = rs.getString(4);
-            config = DomainPingConfiguration.getById(rs.getInt(5));
-        }
-
-        public String getState() {
-            return state;
-        }
-
-        public String getType() {
-            return type;
-        }
-
-        public String getInfo() {
-            return info;
-        }
-
-        public String getResult() {
-            return result;
-        }
-
-        public DomainPingConfiguration getConfig() {
-            return config;
-        }
-
-    }
-
     private User owner;
 
     private String suffix;
@@ -225,7 +182,7 @@ public class Domain implements IdCachable, Verifyable {
         return Collections.unmodifiableList(configs);
     }
 
-    public void addPing(PingType type, String config) throws GigiApiException {
+    public void addPing(DomainPingType type, String config) throws GigiApiException {
         GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `pingconfig` SET `domainid`=?, `type`=?::`pingType`, `info`=?");
         ps.setInt(1, id);
         ps.setString(2, type.toString().toLowerCase());
index 4c4931f5a13280c814d05667279a8b8fb892b3a9..145473fdb9a871c892f8f42ad87caa89a9c4ee5d 100644 (file)
@@ -15,15 +15,11 @@ import org.cacert.gigi.output.template.SprintfCommand;
 
 public class DomainPingConfiguration implements IdCachable {
 
-    public static enum PingType {
-        EMAIL, DNS, HTTP, SSL;
-    }
-
     private int id;
 
     private Domain target;
 
-    private PingType type;
+    private DomainPingType type;
 
     private String info;
 
@@ -37,7 +33,7 @@ public class DomainPingConfiguration implements IdCachable {
         }
         this.id = rs.getInt("id");
         target = Domain.getById(rs.getInt("domainid"));
-        type = PingType.valueOf(rs.getString("type").toUpperCase());
+        type = DomainPingType.valueOf(rs.getString("type").toUpperCase());
         info = rs.getString("info");
     }
 
@@ -50,7 +46,7 @@ public class DomainPingConfiguration implements IdCachable {
         return target;
     }
 
-    public PingType getType() {
+    public DomainPingType getType() {
         return type;
     }
 
diff --git a/src/org/cacert/gigi/dbObjects/DomainPingExecution.java b/src/org/cacert/gigi/dbObjects/DomainPingExecution.java
new file mode 100644 (file)
index 0000000..9a59c10
--- /dev/null
@@ -0,0 +1,45 @@
+package org.cacert.gigi.dbObjects;
+
+import org.cacert.gigi.database.GigiResultSet;
+
+public class DomainPingExecution {
+
+    private String state;
+
+    private String type;
+
+    private String info;
+
+    private String result;
+
+    private DomainPingConfiguration config;
+
+    public DomainPingExecution(GigiResultSet rs) {
+        state = rs.getString(1);
+        type = rs.getString(2);
+        info = rs.getString(3);
+        result = rs.getString(4);
+        config = DomainPingConfiguration.getById(rs.getInt(5));
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public String getInfo() {
+        return info;
+    }
+
+    public String getResult() {
+        return result;
+    }
+
+    public DomainPingConfiguration getConfig() {
+        return config;
+    }
+
+}
diff --git a/src/org/cacert/gigi/dbObjects/DomainPingType.java b/src/org/cacert/gigi/dbObjects/DomainPingType.java
new file mode 100644 (file)
index 0000000..8c3a072
--- /dev/null
@@ -0,0 +1,5 @@
+package org.cacert.gigi.dbObjects;
+
+public enum DomainPingType {
+    EMAIL, DNS, HTTP, SSL;
+}
\ No newline at end of file
index 53f8cbd4a1093eb1c3671d15c312eac2ee4bfc2a..556051b4d96060aa11c011386c1911dc03663e13 100644 (file)
@@ -7,8 +7,8 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Domain;
-import org.cacert.gigi.dbObjects.Domain.DomainPingExecution;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
+import org.cacert.gigi.dbObjects.DomainPingExecution;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Form;
index 5b5da852ca0356709b0e17aeacd0ab99e84651e0..e18b7fb97c929cce0155f387bd27b4d5c415301b 100644 (file)
@@ -11,7 +11,7 @@ import org.cacert.gigi.Gigi;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
-import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
+import org.cacert.gigi.dbObjects.DomainPingType;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.IterableDataset;
@@ -108,13 +108,13 @@ public class PingConfigForm extends Form {
     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
         if (req.getParameter("emailType") != null) {
             String mail = AUTHORATIVE_EMAILS[Integer.parseInt(req.getParameter("email"))];
-            target.addPing(PingType.EMAIL, mail);
+            target.addPing(DomainPingType.EMAIL, mail);
         }
         if (req.getParameter("DNSType") != null) {
-            target.addPing(PingType.DNS, tokenName + ":" + tokenValue);
+            target.addPing(DomainPingType.DNS, tokenName + ":" + tokenValue);
         }
         if (req.getParameter("HTTPType") != null) {
-            target.addPing(PingType.HTTP, tokenName + ":" + tokenValue);
+            target.addPing(DomainPingType.HTTP, tokenName + ":" + tokenValue);
         }
         if (req.getParameter("SSLType") != null) {
             List<String> types = Arrays.asList(SSLPinger.TYPES);
@@ -126,9 +126,9 @@ public class PingConfigForm extends Form {
                 }
                 int portInt = Integer.parseInt(port);
                 if ("direct".equals(type)) {
-                    target.addPing(PingType.SSL, port);
+                    target.addPing(DomainPingType.SSL, port);
                 } else if (types.contains(type)) {
-                    target.addPing(PingType.SSL, portInt + ":" + type);
+                    target.addPing(DomainPingType.SSL, portInt + ":" + type);
                 }
 
             }
index bc86d80c7b09de993e945870a90786326e5887c7..b76035f2d5d217c23cd8dae81da3b43df54e75a6 100644 (file)
@@ -10,12 +10,12 @@ import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
-import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
+import org.cacert.gigi.dbObjects.DomainPingType;
 import org.cacert.gigi.util.RandomToken;
 
 public class PingerDaemon extends Thread {
 
-    HashMap<PingType, DomainPinger> pingers = new HashMap<>();
+    HashMap<DomainPingType, DomainPinger> pingers = new HashMap<>();
 
     private GigiPreparedStatement searchNeededPings;
 
@@ -30,10 +30,10 @@ public class PingerDaemon extends Thread {
     @Override
     public void run() {
         searchNeededPings = DatabaseConnection.getInstance().prepare("SELECT `pingconfig`.`id` FROM `pingconfig` LEFT JOIN `domainPinglog` ON `domainPinglog`.`configId` = `pingconfig`.`id` INNER JOIN `domains` ON `domains`.`id` = `pingconfig`.`domainid` WHERE ( `domainPinglog`.`configId` IS NULL) AND `domains`.`deleted` IS NULL GROUP BY `pingconfig`.`id`");
-        pingers.put(PingType.EMAIL, new EmailPinger());
-        pingers.put(PingType.SSL, new SSLPinger(truststore));
-        pingers.put(PingType.HTTP, new HTTPFetch());
-        pingers.put(PingType.DNS, new DNSPinger());
+        pingers.put(DomainPingType.EMAIL, new EmailPinger());
+        pingers.put(DomainPingType.SSL, new SSLPinger(truststore));
+        pingers.put(DomainPingType.HTTP, new HTTPFetch());
+        pingers.put(DomainPingType.DNS, new DNSPinger());
 
         while (true) {
             try {
@@ -66,7 +66,7 @@ public class PingerDaemon extends Thread {
     }
 
     private void handle(DomainPingConfiguration conf) {
-        PingType type = conf.getType();
+        DomainPingType type = conf.getType();
         String config = conf.getInfo();
         DomainPinger dp = pingers.get(type);
         if (dp != null) {
index 624faefff71d1e61ae5436b0343d6941424bcf00..da9892b41e854cb1735bff4a8d87331ac287e53b 100644 (file)
@@ -17,7 +17,7 @@ import javax.naming.NamingException;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
-import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
+import org.cacert.gigi.dbObjects.DomainPingType;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
@@ -88,7 +88,7 @@ public class TestHTTP extends PingTest {
             Domain d = Domain.getById(id);
             DomainPingConfiguration dpc = null;
             for (DomainPingConfiguration conf : d.getConfiguredPings()) {
-                if (conf.getType() == PingType.HTTP) {
+                if (conf.getType() == DomainPingType.HTTP) {
                     dpc = conf;
                     break;
                 }