--- /dev/null
+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;
+ }
+
+}
private String email;
+ private Assurance[] receivedAssurances, madeAssurances;
+
public User(int id) {
this.id = id;
try {
}
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;
+ }
}