]> WPIA git - gigi.git/commitdiff
upd: change CountryCode class into a Country class
authorFelix Dörre <felix@dogcraft.de>
Tue, 16 Aug 2016 18:22:56 +0000 (20:22 +0200)
committerFelix Dörre <felix@dogcraft.de>
Tue, 16 Aug 2016 18:48:36 +0000 (20:48 +0200)
Change-Id: I26dd38c53c287f0d08f364007943922e5228f356

26 files changed:
src/org/cacert/gigi/dbObjects/Assurance.java
src/org/cacert/gigi/dbObjects/Country.java [new file with mode: 0644]
src/org/cacert/gigi/dbObjects/CountryCode.java [deleted file]
src/org/cacert/gigi/dbObjects/Organisation.java
src/org/cacert/gigi/dbObjects/User.java
src/org/cacert/gigi/output/AssurancesDisplay.java
src/org/cacert/gigi/output/CountrySelector.java
src/org/cacert/gigi/output/IterableIterable.java [new file with mode: 0644]
src/org/cacert/gigi/pages/account/certs/CertificateRequest.java
src/org/cacert/gigi/pages/orga/CreateOrgForm.java
src/org/cacert/gigi/pages/orga/ViewOrgPage.java
src/org/cacert/gigi/util/Notary.java
tests/org/cacert/gigi/TestOrga.java
tests/org/cacert/gigi/TestUser.java
tests/org/cacert/gigi/api/IssueCert.java
tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java
tests/org/cacert/gigi/dbObjects/TestAssureName.java
tests/org/cacert/gigi/dbObjects/TestCountryCode.java
tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java
tests/org/cacert/gigi/pages/main/RegisterPageTest.java
tests/org/cacert/gigi/pages/orga/TestOrgManagement.java
tests/org/cacert/gigi/pages/wot/TestAssurance.java
tests/org/cacert/gigi/testUtils/OrgTest.java
tests/org/cacert/gigi/testUtils/RestrictedApiTest.java
tests/org/cacert/gigi/util/TestNotary.java
util-testing/org/cacert/gigi/pages/Manager.java

index 486b5a340d2b468010a9d16d9564c3da422d7ac4..f3940ebb5d089bce86dcc697a9115981b2106be4 100644 (file)
@@ -33,9 +33,9 @@ public class Assurance {
 
     private String date;
 
-    private CountryCode country;
+    private Country country;
 
-    public Assurance(int id, User from, Name to, String location, String method, int points, String date, CountryCode country) {
+    public Assurance(int id, User from, Name to, String location, String method, int points, String date, Country country) {
         this.id = id;
         this.from = from;
         this.to = to;
@@ -75,7 +75,7 @@ public class Assurance {
         return date;
     }
 
-    public CountryCode getCountry() {
+    public Country getCountry() {
         return country;
     }
 }
diff --git a/src/org/cacert/gigi/dbObjects/Country.java b/src/org/cacert/gigi/dbObjects/Country.java
new file mode 100644 (file)
index 0000000..977b148
--- /dev/null
@@ -0,0 +1,114 @@
+package org.cacert.gigi.dbObjects;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.database.GigiPreparedStatement;
+import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.output.template.SprintfCommand;
+
+public class Country {
+
+    public enum CountryCodeType {
+        CODE_2_CHARS(2), //
+        CODE_3_CHARS(3); //
+
+        private final int len;
+
+        private CountryCodeType(int len) {
+            this.len = len;
+        }
+
+        public int getLen() {
+            return len;
+        }
+    }
+
+    private final int id;
+
+    private final String country;
+
+    private final String countryCode2;
+
+    private final String countryCode3;
+
+    private static final List<Country> countries;
+
+    private static final Map<String, Country> byString;
+    static {
+        LinkedList<Country> cs = new LinkedList<>();
+        HashMap<String, Country> ccd = new HashMap<>();
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id`, `english` as country, `code2`, `code3` FROM `countryIsoCode`", true)) {
+            GigiResultSet rs = ps.executeQuery();
+            while (rs.next()) {
+                Country e = new Country(rs);
+                ccd.put(e.countryCode2, e);
+                ccd.put(e.countryCode3, e);
+                cs.add(e);
+            }
+        }
+        countries = Collections.unmodifiableList(new ArrayList<>(cs));
+        byString = Collections.unmodifiableMap(ccd);
+    }
+
+    private Country(GigiResultSet rs) {
+        this.id = rs.getInt("id");
+        this.country = rs.getString("country");
+        this.countryCode2 = rs.getString("code2");
+        this.countryCode3 = rs.getString("code3");
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getName() {
+        return country;
+    }
+
+    public String getCode() {
+        return countryCode2;
+    }
+
+    public String getCode(CountryCodeType type) {
+        switch (type) {
+        case CODE_2_CHARS:
+            return countryCode2;
+        case CODE_3_CHARS:
+            return countryCode3;
+        default:
+            throw new IllegalArgumentException("Enum switch was non-exhaustive");
+        }
+    }
+
+    public static List<Country> getCountries() {
+        return countries;
+    }
+
+    public static void checkCountryCode(String countrycode, CountryCodeType cType) throws GigiApiException {
+        getCountryByCode(countrycode, cType);
+    }
+
+    public static Country getCountryByCode(String countrycode, CountryCodeType cType) throws GigiApiException {
+        if (countrycode.length() != cType.getLen()) {
+            throw new GigiApiException(SprintfCommand.createSimple("Country code length does not have the required length of {0} characters", Integer.toString(cType.getLen())));
+        }
+        Country i = byString.get(countrycode);
+        if (i == null) {
+            throw new GigiApiException("Country Code was wrong.");
+        }
+        return i;
+    }
+
+    public static Country getRandomCountry() {
+        List<Country> cc = Country.getCountries();
+        int rnd = new Random().nextInt(cc.size());
+        return cc.get(rnd);
+    }
+}
diff --git a/src/org/cacert/gigi/dbObjects/CountryCode.java b/src/org/cacert/gigi/dbObjects/CountryCode.java
deleted file mode 100644 (file)
index 5468bcf..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-package org.cacert.gigi.dbObjects;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
-
-import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.database.GigiPreparedStatement;
-import org.cacert.gigi.database.GigiResultSet;
-import org.cacert.gigi.output.template.SprintfCommand;
-
-public class CountryCode {
-
-    public enum CountryCodeType {
-        CODE_2_CHARS(2, //
-                "SELECT `id`, `english` as country, `code2` as countrycode FROM `countryIsoCode` ORDER BY code2"), //
-        CODE_3_CHARS(3,//
-                "SELECT `id`, `english` as country, `code3` as countrycode FROM `countryIsoCode` ORDER BY code3"); //
-
-        private final String listQuery;
-
-        private final int len;
-
-        private CountryCodeType(int len, String listQuery) {
-            this.len = len;
-            this.listQuery = listQuery;
-        }
-
-        public int getLen() {
-            return len;
-        }
-
-        protected String getListQuery() {
-            return listQuery;
-        }
-    }
-
-    private final int id;
-
-    private final String country;
-
-    private final String countryCode;
-
-    private final CountryCodeType ctype;
-
-    private static final CountryCode[] c2s;
-
-    private static final CountryCode[] c3s;
-
-    private static final Map<String, CountryCode> byString;
-    static {
-        try {
-            c2s = getCountryCodesFromDB(CountryCodeType.CODE_2_CHARS);
-            c3s = getCountryCodesFromDB(CountryCodeType.CODE_3_CHARS);
-            HashMap<String, CountryCode> ccd = new HashMap<>();
-            for (CountryCode c2 : c2s) {
-                ccd.put(c2.getCountryCode(), c2);
-            }
-            for (CountryCode c3 : c3s) {
-                ccd.put(c3.getCountryCode(), c3);
-            }
-            byString = Collections.unmodifiableMap(ccd);
-        } catch (GigiApiException e) {
-            throw new Error(e);
-        }
-    }
-
-    private CountryCode(int id, String country, String countryCode, CountryCodeType ctype) {
-        this.id = id;
-        this.country = country;
-        this.countryCode = countryCode;
-        this.ctype = ctype;
-    }
-
-    public int getId() {
-        return id;
-    }
-
-    public String getCountry() {
-        return country;
-    }
-
-    public String getCountryCode() {
-        return countryCode;
-    }
-
-    public CountryCodeType getCountryCodeType() {
-        return ctype;
-    }
-
-    public static CountryCode[] getCountryCodes(CountryCodeType clength) {
-        switch (clength) {
-        case CODE_2_CHARS:
-            return Arrays.copyOf(c2s, c2s.length);
-        case CODE_3_CHARS:
-            return Arrays.copyOf(c3s, c3s.length);
-        }
-        throw new Error("Enum switch was not exhaustive.");
-    }
-
-    private static CountryCode[] getCountryCodesFromDB(CountryCodeType clength) throws GigiApiException {
-        try (GigiPreparedStatement ps = new GigiPreparedStatement(clength.getListQuery(), true)) {
-            GigiResultSet rs = ps.executeQuery();
-
-            rs.last();
-            int totalCount = rs.getRow();
-            rs.beforeFirst();
-            int i = 0;
-
-            CountryCode[] finalResult = new CountryCode[totalCount];
-            while (rs.next()) {
-                finalResult[i] = new CountryCode(rs.getInt("id"), rs.getString("country"), rs.getString("countrycode"), clength);
-                i += 1;
-            }
-
-            return finalResult;
-        }
-    }
-
-    public static void checkCountryCode(String countrycode, CountryCodeType cType) throws GigiApiException {
-        getCountryCode(countrycode, cType);
-    }
-
-    public CountryCode convertToCountryCodeType(CountryCodeType ctype) {
-        if (this.ctype.equals(ctype)) {
-            return this;
-        }
-        CountryCode[] cclist = getCountryCodes(ctype);
-        for (CountryCode cc : cclist) {
-            if (cc.getId() == this.getId()) {
-                return cc;
-            }
-        }
-        throw new RuntimeException("Internal Error: CountryCode for country not found" + this.getCountry());
-    }
-
-    public static CountryCode getCountryCode(String countrycode, CountryCodeType cType) throws GigiApiException {
-        if (countrycode.length() != cType.getLen()) {
-            throw new GigiApiException(SprintfCommand.createSimple("Country code length does not have the required length of {0} characters", Integer.toString(cType.getLen())));
-        }
-        CountryCode i = byString.get(countrycode);
-        if (i == null || i.getCountryCodeType() != cType) {
-            throw new GigiApiException("Country Code was wrong.");
-        }
-        return i;
-    }
-
-    public static CountryCode getRandomCountry(CountryCodeType cType) {
-        CountryCode[] cc = CountryCode.getCountryCodes(cType);
-        int rnd = new Random().nextInt(cc.length);
-        return cc[rnd];
-    }
-
-}
index 526bf303c710f1785f70f044b4ae9d947ba3cefc..7f6df7520717cd80c33b48f12ab53a1916bb4309 100644 (file)
@@ -10,7 +10,7 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.wrappers.DataContainer;
 
 public class Organisation extends CertificateOwner {
@@ -54,7 +54,7 @@ public class Organisation extends CertificateOwner {
 
     private String name;
 
-    private CountryCode state;
+    private Country state;
 
     private String province;
 
@@ -66,11 +66,11 @@ public class Organisation extends CertificateOwner {
 
     private String postalAddress;
 
-    public Organisation(String name, CountryCode state, String province, String city, String email, String optionalName, String postalAddress, User creator) throws GigiApiException {
+    public Organisation(String name, Country state, String province, String city, String email, String optionalName, String postalAddress, User creator) throws GigiApiException {
         if ( !creator.isInGroup(Group.ORGASSURER)) {
             throw new GigiApiException("Only Organisation RA Agents may create organisations.");
         }
-        if (state == null || state.getCountryCodeType() != CountryCodeType.CODE_2_CHARS) {
+        if (state == null) {
             throw new GigiApiException("Got country code of illegal type.");
         }
         this.name = name;
@@ -84,7 +84,7 @@ public class Organisation extends CertificateOwner {
         try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO organisations SET id=?, name=?, state=?, province=?, city=?, contactEmail=?, optional_name=?, postal_address=?, creator=?")) {
             ps.setInt(1, id);
             ps.setString(2, name);
-            ps.setString(3, state.getCountryCode());
+            ps.setString(3, state.getCode());
             ps.setString(4, province);
             ps.setString(5, city);
             ps.setString(6, email);
@@ -100,7 +100,7 @@ public class Organisation extends CertificateOwner {
     protected Organisation(GigiResultSet rs) throws GigiApiException {
         super(rs.getInt("id"));
         name = rs.getString("name");
-        state = CountryCode.getCountryCode(rs.getString("state"), CountryCodeType.CODE_2_CHARS);
+        state = Country.getCountryByCode(rs.getString("state"), CountryCodeType.CODE_2_CHARS);
         province = rs.getString("province");
         city = rs.getString("city");
         email = rs.getString("contactEmail");
@@ -112,7 +112,7 @@ public class Organisation extends CertificateOwner {
         return name;
     }
 
-    public CountryCode getState() {
+    public Country getState() {
         return state;
     }
 
@@ -210,8 +210,8 @@ public class Organisation extends CertificateOwner {
         }
     }
 
-    public void updateCertData(String o, CountryCode c, String st, String l) throws GigiApiException {
-        if (c == null || c.getCountryCodeType() != CountryCodeType.CODE_2_CHARS) {
+    public void updateCertData(String o, Country c, String st, String l) throws GigiApiException {
+        if (c == null) {
             throw new GigiApiException("Got country code of illegal type.");
         }
         for (Certificate cert : getCertificates(false)) {
@@ -221,7 +221,7 @@ public class Organisation extends CertificateOwner {
         }
         try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `organisations` SET `name`=?, `state`=?, `province`=?, `city`=? WHERE `id`=?")) {
             ps.setString(1, o);
-            ps.setString(2, c.getCountryCode());
+            ps.setString(2, c.getCode());
             ps.setString(3, st);
             ps.setString(4, l);
             ps.setInt(5, getId());
index 83a89fa6252d9fd56872c6864af263b684eee127..3c9b972dba9930612a334d74b9d1236e77c40ce3 100644 (file)
@@ -16,7 +16,7 @@ import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
 import org.cacert.gigi.dbObjects.CATS.CATSType;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.pages.PasswordResetPage;
@@ -66,7 +66,7 @@ public class User extends CertificateOwner {
 
     private Name preferredName;
 
-    private CountryCode residenceCountry;
+    private Country residenceCountry;
 
     protected User(GigiResultSet rs) {
         super(rs.getInt("id"));
@@ -80,7 +80,7 @@ public class User extends CertificateOwner {
 
         try {
             if (rs.getString("Country") != null) {
-                residenceCountry = CountryCode.getCountryCode(rs.getString("Country"), CountryCode.CountryCodeType.CODE_2_CHARS);
+                residenceCountry = Country.getCountryByCode(rs.getString("Country"), Country.CountryCodeType.CODE_2_CHARS);
             }
         } catch (GigiApiException e) {
             throw new Error(e);
@@ -104,7 +104,7 @@ public class User extends CertificateOwner {
         }
     }
 
-    public User(String email, String password, DayDate dob, Locale locale, CountryCode residenceCountry, NamePart... preferred) throws GigiApiException {
+    public User(String email, String password, DayDate dob, Locale locale, Country residenceCountry, NamePart... preferred) throws GigiApiException {
         this.email = email;
         this.dob = dob;
         this.locale = locale;
@@ -116,7 +116,7 @@ public class User extends CertificateOwner {
             query.setString(4, locale.toString());
             query.setInt(5, getId());
             query.setInt(6, preferredName.getId());
-            query.setString(7, residenceCountry == null ? null : residenceCountry.getCountryCode());
+            query.setString(7, residenceCountry == null ? null : residenceCountry.getCode());
             query.execute();
         }
         new EmailAddress(this, email, locale);
@@ -608,7 +608,7 @@ public class User extends CertificateOwner {
 
     private Assurance assuranceByRes(GigiResultSet res) {
         try {
-            return new Assurance(res.getInt("id"), User.getById(res.getInt("from")), Name.getById(res.getInt("to")), res.getString("location"), res.getString("method"), res.getInt("points"), res.getString("date"), res.getString("country") == null ? null : CountryCode.getCountryCode(res.getString("country"), CountryCodeType.CODE_2_CHARS));
+            return new Assurance(res.getInt("id"), User.getById(res.getInt("from")), Name.getById(res.getInt("to")), res.getString("location"), res.getString("method"), res.getInt("points"), res.getString("date"), res.getString("country") == null ? null : Country.getCountryByCode(res.getString("country"), CountryCodeType.CODE_2_CHARS));
         } catch (GigiApiException e) {
             throw new Error(e);
         }
@@ -628,18 +628,18 @@ public class User extends CertificateOwner {
 
     private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {}
 
-    public CountryCode getResidenceCountry() {
+    public Country getResidenceCountry() {
         return residenceCountry;
     }
 
-    public void setResidenceCountry(CountryCode residenceCountry) {
+    public void setResidenceCountry(Country residenceCountry) {
         this.residenceCountry = residenceCountry;
         rawUpdateCountryData();
     }
 
     private void rawUpdateCountryData() {
         try (GigiPreparedStatement update = new GigiPreparedStatement("UPDATE users SET country=? WHERE id=?")) {
-            update.setString(1, residenceCountry == null ? null : residenceCountry.getCountryCode());
+            update.setString(1, residenceCountry == null ? null : residenceCountry.getCode());
             update.setInt(2, getId());
             update.executeUpdate();
         }
index 92acc6d843658c56c0f912c60179d294c0c0c218..356a0349be3b9c75f3be157a8282dd69fde01d04 100644 (file)
@@ -60,7 +60,7 @@ public class AssurancesDisplay implements Outputable {
                         vars.put("myName", to == null ? l.getTranslation("own name removed") : to);
                     }
                     vars.put("date", assurance.getDate());
-                    vars.put("location", assurance.getLocation() + " (" + (assurance.getCountry() == null ? l.getTranslation("not given") : assurance.getCountry().getCountry()) + ")");
+                    vars.put("location", assurance.getLocation() + " (" + (assurance.getCountry() == null ? l.getTranslation("not given") : assurance.getCountry().getName()) + ")");
                     vars.put("points", assurance.getPoints());
                     i++;
                     return true;
index 5bd4b63243641504d0552a4bf8b2b5d1d8615d13..c58600a74bd961a0f60310d494b717dafcc31a3c 100644 (file)
@@ -1,13 +1,14 @@
 package org.cacert.gigi.output;
 
 import java.io.PrintWriter;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Outputable;
 import org.cacert.gigi.output.template.Template;
@@ -16,11 +17,11 @@ public class CountrySelector implements Outputable {
 
     private static final Template t = new Template(CountrySelector.class.getResource("CountrySelector.templ"));
 
-    private CountryCode[] all = CountryCode.getCountryCodes(CountryCodeType.CODE_2_CHARS);
+    private List<Country> all = Country.getCountries();
 
     private String name;
 
-    private CountryCode selected;
+    private Country selected;
 
     private boolean optional;
 
@@ -29,12 +30,8 @@ public class CountrySelector implements Outputable {
         this.optional = optional;
     }
 
-    public CountrySelector(String name, boolean optional, CountryCode state) {
+    public CountrySelector(String name, boolean optional, Country state) {
         this(name, optional);
-        selected = state == null ? null : state.convertToCountryCodeType(CountryCodeType.CODE_2_CHARS);
-        if (state.getCountryCodeType() != CountryCodeType.CODE_2_CHARS) {
-            throw new IllegalArgumentException("Got country code of illegal type.");
-        }
         selected = state;
     }
 
@@ -51,18 +48,18 @@ public class CountrySelector implements Outputable {
             }
         }
 
-        selected = CountryCode.getCountryCode(vS, CountryCodeType.CODE_2_CHARS);
+        selected = Country.getCountryByCode(vS, CountryCodeType.CODE_2_CHARS);
     }
 
     @Override
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
-        vars.put("countryCode", new ArrayIterable<CountryCode>(all) {
+        vars.put("countryCode", new IterableIterable<Country>(all) {
 
             @Override
-            public void apply(CountryCode t, Language l, Map<String, Object> vars) {
-                vars.put("cc", t.getCountryCode());
-                vars.put("display", t.getCountry());
-                if (selected != null && t.getCountryCode().equals(selected.getCountryCode())) {
+            public void apply(Country t, Language l, Map<String, Object> vars) {
+                vars.put("cc", t.getCode());
+                vars.put("display", t.getName());
+                if (selected != null && t.getCode().equals(selected.getCode())) {
                     vars.put("selected", "selected");
                 } else {
                     vars.put("selected", "");
@@ -77,7 +74,7 @@ public class CountrySelector implements Outputable {
         t.output(out, l, vars);
     }
 
-    public CountryCode getCountry() {
+    public Country getCountry() {
         return selected;
     }
 
diff --git a/src/org/cacert/gigi/output/IterableIterable.java b/src/org/cacert/gigi/output/IterableIterable.java
new file mode 100644 (file)
index 0000000..bf2ab07
--- /dev/null
@@ -0,0 +1,31 @@
+package org.cacert.gigi.output;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.IterableDataset;
+
+public abstract class IterableIterable<T> implements IterableDataset {
+
+    private Iterator<T> dt;
+
+    protected int i = 0;
+
+    public IterableIterable(Iterable<T> dt) {
+        this.dt = dt.iterator();
+    }
+
+    @Override
+    public boolean next(Language l, Map<String, Object> vars) {
+        if ( !dt.hasNext()) {
+            return false;
+        }
+        apply(dt.next(), l, vars);
+        i++;
+        return true;
+    }
+
+    public abstract void apply(T t, Language l, Map<String, Object> vars);
+
+}
index 41c7e84e3b8c90546ab16edaf61e4885672e10ae..43e4fbd8205591ef31639689995cc7786f67a8e3 100644 (file)
@@ -423,7 +423,7 @@ public class CertificateRequest {
         if (ctx.getTarget() instanceof Organisation) {
             Organisation org = (Organisation) ctx.getTarget();
             subject.put("O", org.getName());
-            subject.put("C", org.getState().getCountryCode());
+            subject.put("C", org.getState().getCode());
             subject.put("ST", org.getProvince());
             subject.put("L", org.getCity());
             if (ou != null) {
index 8a9c52db2805309d0cefb60c4c407b9863f5876e..36bbbe8e511c23ac168891b886f79d6db376349f 100644 (file)
@@ -6,7 +6,7 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.CountryCode;
+import org.cacert.gigi.dbObjects.Country;
 import org.cacert.gigi.dbObjects.Organisation;
 import org.cacert.gigi.email.EmailProvider;
 import org.cacert.gigi.localisation.Language;
index d5839013222d6a70d543970bc12a77d7c414c141..d1d1d51906a1df6e5fd0ce924a628199575f97f0 100644 (file)
@@ -132,7 +132,7 @@ public class ViewOrgPage extends Page {
                 Organisation org = orgas[count++];
                 vars.put("id", Integer.toString(org.getId()));
                 vars.put("name", org.getName());
-                vars.put("country", org.getState().getCountryCode());
+                vars.put("country", org.getState().getCode());
                 return true;
             }
         };
index f43e3195038ea89b56ae2c7925efd4a857c66f48..2e6edd66524f4c16e471c163b2ea1b5cc3a7b423 100644 (file)
@@ -12,7 +12,7 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
-import org.cacert.gigi.dbObjects.CountryCode;
+import org.cacert.gigi.dbObjects.Country;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Name;
 import org.cacert.gigi.dbObjects.User;
@@ -81,7 +81,7 @@ public class Notary {
      * @throws GigiApiException
      *             if the assurance fails (for various reasons)
      */
-    public synchronized static void assure(User assurer, User assuree, Name assureeName, DayDate dob, int awarded, String location, String date, AssuranceType type, CountryCode country) throws GigiApiException {
+    public synchronized static void assure(User assurer, User assuree, Name assureeName, DayDate dob, int awarded, String location, String date, AssuranceType type, Country country) throws GigiApiException {
         may(assurer, assuree, AssuranceType.FACE_TO_FACE);
         GigiApiException gae = new GigiApiException();
         if ( !gae.isEmpty()) {
@@ -169,7 +169,7 @@ public class Notary {
         }
     }
 
-    private static void assureF2F(User assurer, User assuree, Name name, int awarded, String location, String date, CountryCode country) throws GigiApiException {
+    private static void assureF2F(User assurer, User assuree, Name name, int awarded, String location, String date, Country country) throws GigiApiException {
         may(assurer, assuree, AssuranceType.FACE_TO_FACE);
         try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `country`=?")) {
             ps.setInt(1, assurer.getId());
@@ -177,12 +177,12 @@ public class Notary {
             ps.setInt(3, awarded);
             ps.setString(4, location);
             ps.setString(5, date);
-            ps.setString(6, country.getCountryCode());
+            ps.setString(6, country.getCode());
             ps.execute();
         }
     }
 
-    private static void assureTTP(User assurer, User assuree, Name name, int awarded, String location, String date, CountryCode country) throws GigiApiException {
+    private static void assureTTP(User assurer, User assuree, Name name, int awarded, String location, String date, Country country) throws GigiApiException {
         may(assurer, assuree, AssuranceType.TTP_ASSISTED);
         try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `country`=?, `method`='TTP-Assisted'")) {
             ps.setInt(1, assurer.getId());
@@ -190,7 +190,7 @@ public class Notary {
             ps.setInt(3, awarded);
             ps.setString(4, location);
             ps.setString(5, date);
-            ps.setString(6, country.getCountryCode());
+            ps.setString(6, country.getCode());
             ps.execute();
             assuree.revokeGroup(assurer, Group.TTP_APPLICANT);
         }
@@ -223,7 +223,7 @@ public class Notary {
         throw new GigiApiException("Verification type not possible.");
     }
 
-    private static void assureNucleus(User assurer, User assuree, Name name, int awarded, String location, String date, CountryCode country) throws GigiApiException {
+    private static void assureNucleus(User assurer, User assuree, Name name, int awarded, String location, String date, Country country) throws GigiApiException {
         may(assurer, assuree, AssuranceType.NUCLEUS);
         // Do up to 35 points as f2f
         int f2fPoints = Math.min(assurer.getMaxAssurePoints(), awarded);
@@ -242,12 +242,12 @@ public class Notary {
             ps.setInt(3, awarded);
             ps.setString(4, location);
             ps.setString(5, date);
-            ps.setString(6, country.getCountryCode());
+            ps.setString(6, country.getCode());
             ps.execute();
         }
     }
 
-    public synchronized static void assureAll(User assurer, User assuree, DayDate dob, int awarded, String location, String date, AssuranceType type, Name[] toAssure, CountryCode country) throws GigiApiException {
+    public synchronized static void assureAll(User assurer, User assuree, DayDate dob, int awarded, String location, String date, AssuranceType type, Name[] toAssure, Country country) throws GigiApiException {
         if (toAssure.length == 0) {
             throw new GigiApiException("You must confirm at least one name to verify an account.");
         }
index 3ea186540f30eade03708f22407554d72c6e7fd6..1a0a0aaf189b74537cc8a95971254df689e8ee80 100644 (file)
@@ -4,8 +4,8 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Organisation;
 import org.cacert.gigi.dbObjects.User;
@@ -24,7 +24,7 @@ public class TestOrga extends BusinessTest {
         u3.grantGroup(u1, Group.ORGASSURER);
         User u4 = User.getById(createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD));
         u4.grantGroup(u1, Group.ORGASSURER);
-        Organisation o1 = new Organisation("name", CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS), "prov", "city", "email", "optional name", "postal address", u1);
+        Organisation o1 = new Organisation("name", Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "prov", "city", "email", "optional name", "postal address", u1);
         assertEquals(0, o1.getAllAdmins().size());
         o1.addAdmin(u2, u1, false);
         assertEquals(1, o1.getAllAdmins().size());
index ff67b4f290ded70f05a15fa31c6992364466af0d..4c22f8138280b8dea10a1fb2574e4a283e1b8467 100644 (file)
@@ -9,8 +9,8 @@ import java.util.Locale;
 
 import org.cacert.gigi.dbObjects.Assurance;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.EmailAddress;
 import org.cacert.gigi.dbObjects.Name;
@@ -111,7 +111,7 @@ public class TestUser extends BusinessTest {
         User[] us = new User[5];
         for (int i = 0; i < us.length; i++) {
             us[i] = User.getById(createAssuranceUser("f", "l", createUniqueName() + "@email.com", TEST_PASSWORD));
-            Notary.assure(us[i], u, u.getPreferredName(), u.getDoB(), 10, "here", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+            Notary.assure(us[i], u, u.getPreferredName(), u.getDoB(), 10, "here", validVerificationDateString(), AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
         }
 
         assertTrue(u.isValidName("aä b"));
index 6410a6dec1a5a427a34fb8faeff505ef1fe1698a..03ab3f3e53bc90767ad8d7e2f44440c43144a7a6 100644 (file)
@@ -18,9 +18,9 @@ import java.security.cert.X509Certificate;
 import org.cacert.gigi.dbObjects.Certificate;
 import org.cacert.gigi.dbObjects.Certificate.CSRType;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.CertificateProfile;
-import org.cacert.gigi.dbObjects.CountryCode;
+import org.cacert.gigi.dbObjects.Country;
 import org.cacert.gigi.dbObjects.Digest;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.Group;
@@ -89,7 +89,7 @@ public class IssueCert extends ClientTest {
         makeAssurer(id);
         u.grantGroup(u, Group.ORGASSURER);
 
-        Organisation o1 = new Organisation("name", CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "st", "test@mail", "", "", u);
+        Organisation o1 = new Organisation("name", Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "st", "test@mail", "", "", u);
         o1.addAdmin(u, u, false);
         String testdom = createUniqueName() + "-example.com";
         Domain d2 = new Domain(u, o1, testdom);
index d8661811d6f5aca1b2bf10498d41e9bdb87850b5..036459850bb7309146223ea434823efe78ec83b0 100644 (file)
@@ -8,7 +8,7 @@ import java.sql.Timestamp;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.NamePart.NamePartType;
 import org.cacert.gigi.testUtils.BusinessTest;
 import org.cacert.gigi.util.DayDate;
@@ -46,7 +46,7 @@ public class TestAssuranceMail extends BusinessTest {
             int applicantId = createVerifiedUser("John", "Doe", applicantT, TEST_PASSWORD);
             User applicantXP = User.getById(applicantId);
             applicantXP = User.getById(applicantId);
-            Notary.assure(agentXP, applicantXP, applicantXP.getNames()[0], applicantXP.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+            Notary.assure(agentXP, applicantXP, applicantXP.getNames()[0], applicantXP.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
         }
     }
 
@@ -55,7 +55,7 @@ public class TestAssuranceMail extends BusinessTest {
     }
 
     private void enterVerification(int points, Name... names) throws GigiApiException {
-        Notary.assureAll(agent, applicant, applicant.getDoB(), points, createUniqueName(), validVerificationDateString(), AssuranceType.FACE_TO_FACE, names, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assureAll(agent, applicant, applicant.getDoB(), points, createUniqueName(), validVerificationDateString(), AssuranceType.FACE_TO_FACE, names, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
     }
 
     private void enterVerificationInPast(int points, Name name) {
@@ -273,20 +273,20 @@ public class TestAssuranceMail extends BusinessTest {
 
         // verify with 35 VP
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
-        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
-        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
-        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
-        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         // add first Verification in the past result first name 45 VP
         newAgent();
@@ -302,16 +302,16 @@ public class TestAssuranceMail extends BusinessTest {
 
         // verify first name to 85 VP
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         newAgent();
-        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
 
         // add first Verification in the past result first name 95 VP
         newAgent();
index dd800cbb22a26e537585fa0a09b4b0392dcd0b88..c84bf4833e796f7b24429ff1d841ac882278f42c 100644 (file)
@@ -4,7 +4,7 @@ import static org.junit.Assert.*;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.NamePart.NamePartType;
 import org.cacert.gigi.testUtils.ClientBusinessTest;
 import org.cacert.gigi.util.Notary;
@@ -20,13 +20,13 @@ public class TestAssureName extends ClientBusinessTest {
         Name n4 = new Name(u, new NamePart(NamePartType.SINGLE_NAME, "Testiaac"));
 
         assertEquals(0, n0.getAssurancePoints());
-        Notary.assure(u0, u, n0, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(u0, u, n0, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
         assertEquals(10, n0.getAssurancePoints());
-        Notary.assure(u0, u, n2, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(u0, u, n2, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
         assertEquals(10, n2.getAssurancePoints());
-        Notary.assure(u0, u, n3, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(u0, u, n3, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
         assertEquals(10, n3.getAssurancePoints());
-        Notary.assure(u0, u, n4, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+        Notary.assure(u0, u, n4, u.getDoB(), 10, "test mgr", validVerificationDateString(), AssuranceType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
         assertEquals(10, n4.getAssurancePoints());
         assertEquals(10, u.getMaxAssurePoints());
     }
index 92b169ad3ef42441a48c402af1a25c459e4c84d3..7f82909c75cc1dc5763f8b210271c760029c2332 100644 (file)
@@ -3,9 +3,10 @@ package org.cacert.gigi.dbObjects;
 import static org.junit.Assert.*;
 
 import java.util.Arrays;
+import java.util.List;
 
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.testUtils.BusinessTest;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.CoreMatchers;
@@ -34,19 +35,18 @@ public class TestCountryCode extends BusinessTest {
 
     @Test
     public void testList() throws GigiApiException {
-        CountryCode[] ccs = CountryCode.getCountryCodes(type);
-        for (CountryCode cc : ccs) {
-            assertSame(type, cc.getCountryCodeType());
-            assertThat(cc.getCountryCode(), stringLength(type.getLen()));
+        List<Country> ccs = Country.getCountries();
+        for (Country cc : ccs) {
+            assertThat(cc.getCode(type), stringLength(type.getLen()));
         }
     }
 
     @Test
     public void testFetch() throws GigiApiException {
         String ref = type == CountryCodeType.CODE_2_CHARS ? "DE" : "DEU";
-        CountryCode cc = CountryCode.getCountryCode(ref, type);
-        assertEquals(ref, cc.getCountryCode());
-        assertEquals("Germany", cc.getCountry());
+        Country cc = Country.getCountryByCode(ref, type);
+        assertEquals(ref, cc.getCode(type));
+        assertEquals("Germany", cc.getName());
     }
 
     @Test
@@ -54,16 +54,16 @@ public class TestCountryCode extends BusinessTest {
         String ref = type == CountryCodeType.CODE_2_CHARS ? "DE" : "DEU";
         String reff = type == CountryCodeType.CODE_2_CHARS ? "DF" : "DFU";
 
-        CountryCode.checkCountryCode(ref, type);
+        Country.checkCountryCode(ref, type);
         try {
-            CountryCode.checkCountryCode(reff, type);
+            Country.checkCountryCode(reff, type);
         } catch (GigiApiException e) {
             assertThat(e.getMessage(), CoreMatchers.containsString("was wrong"));
         }
 
-        CountryCode.getCountryCode(ref, type);
+        Country.getCountryByCode(ref, type);
         try {
-            CountryCode.getCountryCode(reff, type);
+            Country.getCountryByCode(reff, type);
         } catch (GigiApiException e) {
             assertThat(e.getMessage(), CoreMatchers.containsString("was wrong"));
         }
@@ -72,7 +72,7 @@ public class TestCountryCode extends BusinessTest {
     @Test
     public void testSingleInstance() throws GigiApiException {
         String ref = type == CountryCodeType.CODE_2_CHARS ? "DE" : "DEU";
-        assertSame(CountryCode.getCountryCode(ref, type), CountryCode.getCountryCode(ref, type));
+        assertSame(Country.getCountryByCode(ref, type), Country.getCountryByCode(ref, type));
     }
 
     private Matcher<String> stringLength(final int len) {
index b0fb4b96e91b9822798976c20676e6595d099feb..43a110ea6eb9d899e2f82b8d91624b1b3c561d96 100644 (file)
@@ -99,7 +99,7 @@ public class TestMyDetailsEdit extends ManagedTest {
     public void testChangeResidenceCountry() throws IOException {
         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "residenceCountry=DE&action=updateResidenceCountry", 0));
         User user = User.getById(id);
-        assertEquals("DE", user.getResidenceCountry().getCountryCode());
+        assertEquals("DE", user.getResidenceCountry().getCode());
     }
 
     @Test
index eba981237f9fd2117a44063f1308ab93b5abb1d1..9fb618300b5e1c04761b027b61fa1cc55682f073 100644 (file)
@@ -223,7 +223,7 @@ public class RegisterPageTest extends ManagedTest {
         String data = fetchStartErrorMessage(runRegister(query));
         assertNull(data);
         User u = User.getByEmail(email);
-        assertEquals("DE", u.getResidenceCountry().getCountryCode());
+        assertEquals("DE", u.getResidenceCountry().getCode());
     }
 
     @Test
index dc922907cf956a1c334792dbeadd8bc2ab9c2975..760ca198c5ba7c199eb410df307abb4933b3bb42 100644 (file)
@@ -13,8 +13,8 @@ import java.sql.SQLException;
 import java.util.List;
 
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.Organisation;
 import org.cacert.gigi.dbObjects.Organisation.Affiliation;
 import org.cacert.gigi.dbObjects.User;
@@ -147,9 +147,9 @@ public class TestOrgManagement extends OrgTest {
     @Test
     public void testUpdateOrgCertData() throws IOException, GigiApiException {
         Organisation o1 = createUniqueOrg();
-        o1.updateCertData("name", CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS), DIFFICULT_CHARS, "Köln");
+        o1.updateCertData("name", Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), DIFFICULT_CHARS, "Köln");
         assertEquals("name", o1.getName());
-        assertEquals("DE", o1.getState().getCountryCode());
+        assertEquals("DE", o1.getState().getCode());
         assertEquals(DIFFICULT_CHARS, o1.getProvince());
         assertEquals("Köln", o1.getCity());
         o1.delete();
@@ -246,7 +246,7 @@ public class TestOrgManagement extends OrgTest {
      */
     private String upCertData(Organisation o1, String o, String c, String province, String ct) throws IOException, MalformedURLException, UnsupportedEncodingException {
         if (c == null) {
-            c = o1.getState().getCountryCode();
+            c = o1.getState().getCode();
         }
         return executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "action=updateCertificateData&O=" + o + "&C=" + c + "&ST=" + province + "&L=" + ct, 0);
     }
index b950389b07c9922c16667496fa815f2f78920ebb..3ae4ccd4afa204b61a93a514dc4cdb8f6ad4897c 100644 (file)
@@ -18,7 +18,7 @@ import java.util.regex.Pattern;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
-import org.cacert.gigi.dbObjects.CountryCode;
+import org.cacert.gigi.dbObjects.Country;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.testUtils.IOUtils;
@@ -236,7 +236,7 @@ public class TestAssurance extends ManagedTest {
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[1];
         assertThat(resp, containsString(uniqueLoc));
-        assertThat(resp, containsString(CountryCode.getCountryCode("DE", CountryCode.CountryCodeType.CODE_2_CHARS).getCountry()));
+        assertThat(resp, containsString(Country.getCountryByCode("DE", Country.CountryCodeType.CODE_2_CHARS).getName()));
     }
 
     @Test
@@ -248,7 +248,7 @@ public class TestAssurance extends ManagedTest {
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[2];
         assertThat(resp, containsString(uniqueLoc));
-        assertThat(resp, containsString(CountryCode.getCountryCode("DE", CountryCode.CountryCodeType.CODE_2_CHARS).getCountry()));
+        assertThat(resp, containsString(Country.getCountryByCode("DE", Country.CountryCodeType.CODE_2_CHARS).getName()));
     }
 
     private void executeFails(String query) throws MalformedURLException, IOException {
index 4e2ea8bd1bb74bd3c990880afa52e5a0349cab61..2a9f5da7fce27068953619bf0d903da998b44c84 100644 (file)
@@ -3,8 +3,8 @@ package org.cacert.gigi.testUtils;
 import java.io.IOException;
 
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Organisation;
 
@@ -18,7 +18,7 @@ public class OrgTest extends ClientTest {
     }
 
     public Organisation createUniqueOrg() throws GigiApiException {
-        Organisation o1 = new Organisation(createUniqueName(), CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "city", "test@example.com", "", "", u);
+        Organisation o1 = new Organisation(createUniqueName(), Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "city", "test@example.com", "", "", u);
         return o1;
     }
 }
index 9e8586d56b49ef72309129101e0eaba26ad5743b..2301b0ae45471a5a5a8c02026d4337d6a55494c6 100644 (file)
@@ -16,8 +16,8 @@ import org.cacert.gigi.dbObjects.Certificate;
 import org.cacert.gigi.dbObjects.Certificate.CSRType;
 import org.cacert.gigi.dbObjects.Certificate.SANType;
 import org.cacert.gigi.dbObjects.CertificateProfile;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.Digest;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Organisation;
@@ -42,7 +42,7 @@ public class RestrictedApiTest extends ClientTest {
             grant(u.getEmail(), Group.ORGASSURER);
             clearCaches();
             u = User.getById(u.getId());
-            Organisation o = new Organisation(Organisation.SELF_ORG_NAME, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS), "NA", "NA", "contact@cacert.org", "", "", u);
+            Organisation o = new Organisation(Organisation.SELF_ORG_NAME, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "NA", "NA", "contact@cacert.org", "", "", u);
             assertTrue(o.isSelfOrganisation());
             KeyPair kp = generateKeypair();
             String key1 = generatePEMCSR(kp, "EMAIL=cats@cacert.org");
index c0426b9b2443767cc39022a030b46fea1a4d2030..fd3e62ef6e073855fcf2353c4a18aabd93ad952c 100644 (file)
@@ -8,8 +8,8 @@ import java.util.Date;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
 import org.cacert.gigi.dbObjects.ObjectCache;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.output.DateSelector;
@@ -18,7 +18,7 @@ import org.junit.Test;
 
 public class TestNotary extends BusinessTest {
 
-    public final CountryCode DE = CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS);
+    public final Country DE = Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS);
 
     public TestNotary() throws GigiApiException {}
 
index 93f422761f5d8dca42456afe233ef19678f54abf..e4e3dbd41a05e0cb2fe534ffa2a7a6377832c3a0 100644 (file)
@@ -34,8 +34,7 @@ import org.cacert.gigi.dbObjects.CATS.CATSType;
 import org.cacert.gigi.dbObjects.Certificate;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
 import org.cacert.gigi.dbObjects.CertificateOwner;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
 import org.cacert.gigi.dbObjects.Digest;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.DomainPingType;
@@ -117,7 +116,7 @@ public class Manager extends Page {
                 ps.setInt(3, 100);
                 ps.setString(4, "Manager init code");
                 ps.setString(5, "1990-01-01");
-                ps.setString(6, CountryCode.getRandomCountry(CountryCode.CountryCodeType.CODE_2_CHARS).getCountryCode());
+                ps.setString(6, Country.getRandomCountry().getCode());
                 ps.execute();
             }
             return u;
@@ -229,7 +228,7 @@ public class Manager extends Page {
         gc.setTimeInMillis(0);
         gc.set(1990, 0, 1);
 
-        CountryCode country = CountryCode.getRandomCountry(CountryCode.CountryCodeType.CODE_2_CHARS);
+        Country country = Country.getRandomCountry();
 
         User u = new User(email, "xvXV12°§", new DayDate(gc.getTime().getTime()), Locale.ENGLISH, country, //
                 new NamePart(NamePartType.FIRST_NAME, "Först"), new NamePart(NamePartType.FIRST_NAME, "Müddle"), //
@@ -319,7 +318,7 @@ public class Manager extends Page {
                     if (vp < 10) {
                         currentVP = vp;
                     }
-                    Notary.assure(getAssurer(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getRandomCountry(CountryCodeType.CODE_2_CHARS));
+                    Notary.assure(getAssurer(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getRandomCountry());
                     agentNumber += 1;
                     vp -= currentVP;
                 }
@@ -336,7 +335,7 @@ public class Manager extends Page {
             try {
                 for (int i = 0; i < 25; i++) {
                     User a = getAssurer(i);
-                    Notary.assure(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getRandomCountry(CountryCodeType.CODE_2_CHARS));
+                    Notary.assure(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE, Country.getRandomCountry());
                 }
             } catch (GigiApiException e) {
                 throw new Error(e);