]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/CertificateOwner.java
upd: history also for organisations.
[gigi.git] / src / org / cacert / gigi / dbObjects / CertificateOwner.java
index 9560224e3601283bce748b51033ba29b2365112a..f9e9fbd57f0f721e9ac2c4cfc8a590968e727339 100644 (file)
@@ -1,6 +1,7 @@
 package org.cacert.gigi.dbObjects;
 
 import java.util.LinkedList;
+import java.util.List;
 
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
@@ -12,11 +13,16 @@ public abstract class CertificateOwner implements IdCachable {
 
     private int id;
 
-    public CertificateOwner(int id) {
+    protected CertificateOwner(int id) {
         this.id = id;
     }
 
-    public CertificateOwner() {}
+    protected CertificateOwner() {
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `certOwners` DEFAULT VALUES");
+        ps.execute();
+        id = ps.lastInsertId();
+        myCache.put(this);
+    }
 
     public int getId() {
         return id;
@@ -43,20 +49,6 @@ public abstract class CertificateOwner implements IdCachable {
         return u;
     }
 
-    protected int insert() {
-        synchronized (User.class) {
-            if (id != 0) {
-                throw new Error("refusing to insert");
-            }
-            GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `certOwners` DEFAULT VALUES");
-            ps.execute();
-            id = ps.lastInsertId();
-            myCache.put(this);
-        }
-
-        return id;
-    }
-
     public Domain[] getDomains() {
         GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `id` FROM `domains` WHERE `memid`=? AND `deleted` IS NULL");
         ps.setInt(1, getId());
@@ -96,7 +88,7 @@ public abstract class CertificateOwner implements IdCachable {
         for (Domain d : getDomains()) {
             String sfx = d.getSuffix();
             if (domainname.equals(sfx) || domainname.endsWith("." + sfx)) {
-                return true;
+                return d.isVerified();
             }
         }
 
@@ -112,4 +104,17 @@ public abstract class CertificateOwner implements IdCachable {
         myCache.remove(this);
     }
 
+    public String[] getAdminLog() {
+        GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("SELECT `when`, type, information FROM `adminLog` WHERE uid=? ORDER BY `when` ASC");
+        prep.setInt(1, getId());
+        GigiResultSet res = prep.executeQuery();
+        List<String> entries = new LinkedList<String>();
+
+        while (res.next()) {
+            entries.add(res.getString(2) + " (" + res.getString(3) + ")");
+        }
+
+        return entries.toArray(new String[0]);
+    }
+
 }