From: Felix Dörre Date: Tue, 16 Aug 2016 18:22:56 +0000 (+0200) Subject: upd: change CountryCode class into a Country class X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=0b0db3d1f59e3473fad2d8011f75552b7de1671e upd: change CountryCode class into a Country class Change-Id: I26dd38c53c287f0d08f364007943922e5228f356 --- diff --git a/src/org/cacert/gigi/dbObjects/Assurance.java b/src/org/cacert/gigi/dbObjects/Assurance.java index 486b5a34..f3940ebb 100644 --- a/src/org/cacert/gigi/dbObjects/Assurance.java +++ b/src/org/cacert/gigi/dbObjects/Assurance.java @@ -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 index 00000000..977b1485 --- /dev/null +++ b/src/org/cacert/gigi/dbObjects/Country.java @@ -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 countries; + + private static final Map byString; + static { + LinkedList cs = new LinkedList<>(); + HashMap 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 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 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 index 5468bcf6..00000000 --- a/src/org/cacert/gigi/dbObjects/CountryCode.java +++ /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 byString; - static { - try { - c2s = getCountryCodesFromDB(CountryCodeType.CODE_2_CHARS); - c3s = getCountryCodesFromDB(CountryCodeType.CODE_3_CHARS); - HashMap 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]; - } - -} diff --git a/src/org/cacert/gigi/dbObjects/Organisation.java b/src/org/cacert/gigi/dbObjects/Organisation.java index 526bf303..7f6df752 100644 --- a/src/org/cacert/gigi/dbObjects/Organisation.java +++ b/src/org/cacert/gigi/dbObjects/Organisation.java @@ -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()); diff --git a/src/org/cacert/gigi/dbObjects/User.java b/src/org/cacert/gigi/dbObjects/User.java index 83a89fa6..3c9b972d 100644 --- a/src/org/cacert/gigi/dbObjects/User.java +++ b/src/org/cacert/gigi/dbObjects/User.java @@ -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(); } diff --git a/src/org/cacert/gigi/output/AssurancesDisplay.java b/src/org/cacert/gigi/output/AssurancesDisplay.java index 92acc6d8..356a0349 100644 --- a/src/org/cacert/gigi/output/AssurancesDisplay.java +++ b/src/org/cacert/gigi/output/AssurancesDisplay.java @@ -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; diff --git a/src/org/cacert/gigi/output/CountrySelector.java b/src/org/cacert/gigi/output/CountrySelector.java index 5bd4b632..c58600a7 100644 --- a/src/org/cacert/gigi/output/CountrySelector.java +++ b/src/org/cacert/gigi/output/CountrySelector.java @@ -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 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 vars) { - vars.put("countryCode", new ArrayIterable(all) { + vars.put("countryCode", new IterableIterable(all) { @Override - public void apply(CountryCode t, Language l, Map 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 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 index 00000000..bf2ab07b --- /dev/null +++ b/src/org/cacert/gigi/output/IterableIterable.java @@ -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 implements IterableDataset { + + private Iterator dt; + + protected int i = 0; + + public IterableIterable(Iterable dt) { + this.dt = dt.iterator(); + } + + @Override + public boolean next(Language l, Map vars) { + if ( !dt.hasNext()) { + return false; + } + apply(dt.next(), l, vars); + i++; + return true; + } + + public abstract void apply(T t, Language l, Map vars); + +} diff --git a/src/org/cacert/gigi/pages/account/certs/CertificateRequest.java b/src/org/cacert/gigi/pages/account/certs/CertificateRequest.java index 41c7e84e..43e4fbd8 100644 --- a/src/org/cacert/gigi/pages/account/certs/CertificateRequest.java +++ b/src/org/cacert/gigi/pages/account/certs/CertificateRequest.java @@ -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) { diff --git a/src/org/cacert/gigi/pages/orga/CreateOrgForm.java b/src/org/cacert/gigi/pages/orga/CreateOrgForm.java index 8a9c52db..36bbbe8e 100644 --- a/src/org/cacert/gigi/pages/orga/CreateOrgForm.java +++ b/src/org/cacert/gigi/pages/orga/CreateOrgForm.java @@ -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; diff --git a/src/org/cacert/gigi/pages/orga/ViewOrgPage.java b/src/org/cacert/gigi/pages/orga/ViewOrgPage.java index d5839013..d1d1d519 100644 --- a/src/org/cacert/gigi/pages/orga/ViewOrgPage.java +++ b/src/org/cacert/gigi/pages/orga/ViewOrgPage.java @@ -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; } }; diff --git a/src/org/cacert/gigi/util/Notary.java b/src/org/cacert/gigi/util/Notary.java index f43e3195..2e6edd66 100644 --- a/src/org/cacert/gigi/util/Notary.java +++ b/src/org/cacert/gigi/util/Notary.java @@ -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."); } diff --git a/tests/org/cacert/gigi/TestOrga.java b/tests/org/cacert/gigi/TestOrga.java index 3ea18654..1a0a0aaf 100644 --- a/tests/org/cacert/gigi/TestOrga.java +++ b/tests/org/cacert/gigi/TestOrga.java @@ -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()); diff --git a/tests/org/cacert/gigi/TestUser.java b/tests/org/cacert/gigi/TestUser.java index ff67b4f2..4c22f813 100644 --- a/tests/org/cacert/gigi/TestUser.java +++ b/tests/org/cacert/gigi/TestUser.java @@ -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")); diff --git a/tests/org/cacert/gigi/api/IssueCert.java b/tests/org/cacert/gigi/api/IssueCert.java index 6410a6de..03ab3f3e 100644 --- a/tests/org/cacert/gigi/api/IssueCert.java +++ b/tests/org/cacert/gigi/api/IssueCert.java @@ -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); diff --git a/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java b/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java index d8661811..03645985 100644 --- a/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java +++ b/tests/org/cacert/gigi/dbObjects/TestAssuranceMail.java @@ -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(); diff --git a/tests/org/cacert/gigi/dbObjects/TestAssureName.java b/tests/org/cacert/gigi/dbObjects/TestAssureName.java index dd800cbb..c84bf483 100644 --- a/tests/org/cacert/gigi/dbObjects/TestAssureName.java +++ b/tests/org/cacert/gigi/dbObjects/TestAssureName.java @@ -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()); } diff --git a/tests/org/cacert/gigi/dbObjects/TestCountryCode.java b/tests/org/cacert/gigi/dbObjects/TestCountryCode.java index 92b169ad..7f82909c 100644 --- a/tests/org/cacert/gigi/dbObjects/TestCountryCode.java +++ b/tests/org/cacert/gigi/dbObjects/TestCountryCode.java @@ -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 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 stringLength(final int len) { diff --git a/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java b/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java index b0fb4b96..43a110ea 100644 --- a/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java +++ b/tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java @@ -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 diff --git a/tests/org/cacert/gigi/pages/main/RegisterPageTest.java b/tests/org/cacert/gigi/pages/main/RegisterPageTest.java index eba98123..9fb61830 100644 --- a/tests/org/cacert/gigi/pages/main/RegisterPageTest.java +++ b/tests/org/cacert/gigi/pages/main/RegisterPageTest.java @@ -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 diff --git a/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java b/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java index dc922907..760ca198 100644 --- a/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java +++ b/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java @@ -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); } diff --git a/tests/org/cacert/gigi/pages/wot/TestAssurance.java b/tests/org/cacert/gigi/pages/wot/TestAssurance.java index b950389b..3ae4ccd4 100644 --- a/tests/org/cacert/gigi/pages/wot/TestAssurance.java +++ b/tests/org/cacert/gigi/pages/wot/TestAssurance.java @@ -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(""))[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(""))[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 { diff --git a/tests/org/cacert/gigi/testUtils/OrgTest.java b/tests/org/cacert/gigi/testUtils/OrgTest.java index 4e2ea8bd..2a9f5da7 100644 --- a/tests/org/cacert/gigi/testUtils/OrgTest.java +++ b/tests/org/cacert/gigi/testUtils/OrgTest.java @@ -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; } } diff --git a/tests/org/cacert/gigi/testUtils/RestrictedApiTest.java b/tests/org/cacert/gigi/testUtils/RestrictedApiTest.java index 9e8586d5..2301b0ae 100644 --- a/tests/org/cacert/gigi/testUtils/RestrictedApiTest.java +++ b/tests/org/cacert/gigi/testUtils/RestrictedApiTest.java @@ -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"); diff --git a/tests/org/cacert/gigi/util/TestNotary.java b/tests/org/cacert/gigi/util/TestNotary.java index c0426b9b..fd3e62ef 100644 --- a/tests/org/cacert/gigi/util/TestNotary.java +++ b/tests/org/cacert/gigi/util/TestNotary.java @@ -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 {} diff --git a/util-testing/org/cacert/gigi/pages/Manager.java b/util-testing/org/cacert/gigi/pages/Manager.java index 93f42276..e4e3dbd4 100644 --- a/util-testing/org/cacert/gigi/pages/Manager.java +++ b/util-testing/org/cacert/gigi/pages/Manager.java @@ -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);