]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Assurance.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / src / org / cacert / gigi / dbObjects / Assurance.java
index b1c9ccd507c79fc4981ea7d364ff8280e67a7f79..07c3a39be3b721fc10287181aa591087e408a86b 100644 (file)
@@ -1,15 +1,37 @@
 package org.cacert.gigi.dbObjects;
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.util.Date;
 
+import org.cacert.gigi.database.DBEnum;
+import org.cacert.gigi.dbObjects.wrappers.DataContainer;
 
+@DataContainer
 public class Assurance {
+
+    public enum AssuranceType implements DBEnum {
+        FACE_TO_FACE("Face to Face Meeting"), TOPUP("TOPUP"), TTP_ASSISTED("TTP-Assisted"), NUCLEUS("Nucleus Bonus");
+
+        private final String description;
+
+        private AssuranceType(String description) {
+            this.description = description;
+        }
+
+        public String getDescription() {
+            return description;
+        }
+
+        @Override
+        public String getDBName() {
+            return description;
+        }
+    }
+
     private int id;
 
     private User from;
 
-    private User to;
+    private Name to;
 
     private String location;
 
@@ -19,15 +41,20 @@ public class Assurance {
 
     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");
+    private Country country;
+
+    private Date expireDate;
+
+    public Assurance(int id, User from, Name to, String location, String method, int points, String date, Country country, Date expireDate) {
+        this.id = id;
+        this.from = from;
+        this.to = to;
+        this.location = location;
+        this.method = method;
+        this.points = points;
+        this.date = date;
+        this.country = country;
+        this.expireDate = expireDate;
     }
 
     public User getFrom() {
@@ -46,7 +73,7 @@ public class Assurance {
         return points;
     }
 
-    public User getTo() {
+    public Name getTo() {
         return to;
     }
 
@@ -58,4 +85,22 @@ public class Assurance {
         return date;
     }
 
+    public Country getCountry() {
+        return country;
+    }
+
+    public Date getExpireDate() {
+        return expireDate;
+    }
+
+    public boolean isExpired() {
+        boolean expired = false;
+        if (expireDate == null) {
+            expired = false;
+        } else {
+            Date now = new Date();
+            expired = expireDate.before(now);
+        }
+        return expired;
+    }
 }