]> WPIA git - gigi.git/commitdiff
ADD: Assurance fetch
authorJanis Streib <janis@dogcraft.de>
Sat, 23 Aug 2014 23:24:24 +0000 (01:24 +0200)
committerJanis Streib <janis@dogcraft.de>
Sun, 24 Aug 2014 00:36:06 +0000 (02:36 +0200)
src/org/cacert/gigi/Assurance.java [new file with mode: 0644]
src/org/cacert/gigi/User.java

diff --git a/src/org/cacert/gigi/Assurance.java b/src/org/cacert/gigi/Assurance.java
new file mode 100644 (file)
index 0000000..973f0ee
--- /dev/null
@@ -0,0 +1,61 @@
+package org.cacert.gigi;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+
+public class Assurance {
+    private int id;
+
+    private User from;
+
+    private User to;
+
+    private String location;
+
+    private String method;
+
+    private int points;
+
+    private String date;
+
+    public Assurance(ResultSet result) throws SQLException {
+        super();
+        this.id = result.getInt("id");
+        this.from = User.getById(result.getInt("from"));
+        this.to = User.getById(result.getInt("to"));
+        this.location = result.getString("location");
+        this.method = result.getString("method");
+        this.points = result.getInt("points");
+        this.date = result.getString("date");
+    }
+
+    public User getFrom() {
+        return from;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getLocation() {
+        return location;
+    }
+
+    public int getPoints() {
+        return points;
+    }
+
+    public User getTo() {
+        return to;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public String getDate() {
+        return date;
+    }
+
+}
index eebf9317e2b4839aadc894fd0f86363787e17ab2..fd1989b26aa41e168d4b38cfc54a3eb5270b54ad 100644 (file)
@@ -20,6 +20,8 @@ public class User {
 
     private String email;
 
+    private Assurance[] receivedAssurances, madeAssurances;
+
     public User(int id) {
         this.id = id;
         try {
@@ -377,4 +379,48 @@ public class User {
         }
         throw new GigiApiException("Email not one of user's email addresses.");
     }
+
+    public Assurance[] getReceivedAssurances() throws SQLException {
+        if (receivedAssurances == null) {
+            PreparedStatement query = DatabaseConnection.getInstance().prepare("SELECT * FROM notary WHERE `to`=? AND deleted=0");
+            query.setInt(1, getId());
+            ResultSet res = query.executeQuery();
+            res.last();
+            Assurance[] assurances = new Assurance[res.getRow()];
+            res.beforeFirst();
+            for (int i = 0; i < assurances.length; i++) {
+                res.next();
+                assurances[i] = new Assurance(res);
+            }
+            this.receivedAssurances = assurances;
+            return assurances;
+        }
+        return receivedAssurances;
+    }
+
+    public Assurance[] getMadeAssurances() throws SQLException {
+        if (madeAssurances == null) {
+            PreparedStatement query = DatabaseConnection.getInstance().prepare("SELECT * FROM notary WHERE `from`=? AND deleted=0");
+            query.setInt(1, getId());
+            ResultSet res = query.executeQuery();
+            res.last();
+            Assurance[] assurances = new Assurance[res.getRow()];
+            res.beforeFirst();
+            for (int i = 0; i < assurances.length; i++) {
+                res.next();
+                assurances[i] = new Assurance(res);
+            }
+            this.madeAssurances = assurances;
+            return assurances;
+        }
+        return madeAssurances;
+    }
+
+    public void invalidateMadeAssurances() {
+        madeAssurances = null;
+    }
+
+    public void invalidateReceivedAssurances() {
+        receivedAssurances = null;
+    }
 }