]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Domain.java
fix: npe in domain overview as domain
[gigi.git] / src / org / cacert / gigi / dbObjects / Domain.java
index c165c4abdbcaedc7e1e457715a5a021090304a19..6093f6d85b74b82ce64083cbdadc2563f4ec3371 100644 (file)
@@ -19,7 +19,7 @@ import org.cacert.gigi.util.PublicSuffixes;
 
 public class Domain implements IdCachable, Verifyable {
 
-    private User owner;
+    private CertificateOwner owner;
 
     private String suffix;
 
@@ -46,16 +46,18 @@ public class Domain implements IdCachable, Verifyable {
             throw new IllegalArgumentException("Invalid domain id " + id);
         }
         this.id = id;
-        owner = User.getById(rs.getInt(1));
+        owner = CertificateOwner.getById(rs.getInt(1));
         suffix = rs.getString(2);
         rs.close();
     }
 
-    public Domain(User owner, String suffix) throws GigiApiException {
-        checkCertifyableDomain(suffix, owner.isInGroup(Group.CODESIGNING));
-        this.owner = owner;
-        this.suffix = suffix;
-
+    public Domain(User actor, CertificateOwner owner, String suffix) throws GigiApiException {
+        synchronized (Domain.class) {
+            checkCertifyableDomain(suffix, actor.isInGroup(Group.CODESIGNING));
+            this.owner = owner;
+            this.suffix = suffix;
+            insert();
+        }
     }
 
     public static void checkCertifyableDomain(String s, boolean hasPunycodeRight) throws GigiApiException {
@@ -126,19 +128,17 @@ public class Domain implements IdCachable, Verifyable {
         }
     }
 
-    public void insert() throws GigiApiException {
-        synchronized (Domain.class) {
-            if (id != 0) {
-                throw new GigiApiException("already inserted.");
-            }
-            checkInsert(suffix);
-            GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
-            ps.setInt(1, owner.getId());
-            ps.setString(2, suffix);
-            ps.execute();
-            id = ps.lastInsertId();
-            myCache.put(this);
+    private void insert() throws GigiApiException {
+        if (id != 0) {
+            throw new GigiApiException("already inserted.");
         }
+        checkInsert(suffix);
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
+        ps.setInt(1, owner.getId());
+        ps.setString(2, suffix);
+        ps.execute();
+        id = ps.lastInsertId();
+        myCache.put(this);
     }
 
     public void delete() throws GigiApiException {
@@ -150,7 +150,7 @@ public class Domain implements IdCachable, Verifyable {
         ps.execute();
     }
 
-    public User getOwner() {
+    public CertificateOwner getOwner() {
         return owner;
     }
 
@@ -192,7 +192,7 @@ public class Domain implements IdCachable, Verifyable {
     }
 
     public synchronized void verify(String hash) throws GigiApiException {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=?)");
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `state`='open' AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=? AND `type`='email')");
         ps.setString(1, hash);
         ps.setInt(2, id);
         ps.executeUpdate();
@@ -206,7 +206,7 @@ public class Domain implements IdCachable, Verifyable {
     }
 
     public DomainPingExecution[] getPings() throws GigiApiException {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepareScrollable("SELECT `state`, `type`, `info`, `result`, `configId` FROM `domainPinglog` INNER JOIN `pingconfig` ON `pingconfig`.`id`=`domainPinglog`.`configId` WHERE `pingconfig`.`domainid`=? ORDER BY `when` DESC;");
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepareScrollable("SELECT `state`, `type`, `info`, `result`, `configId`, `when` FROM `domainPinglog` INNER JOIN `pingconfig` ON `pingconfig`.`id`=`domainPinglog`.`configId` WHERE `pingconfig`.`domainid`=? ORDER BY `when` DESC;");
         ps.setInt(1, id);
         GigiResultSet rs = ps.executeQuery();
         rs.last();