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;
return date;
}
- public CountryCode getCountry() {
+ public Country getCountry() {
return country;
}
}
--- /dev/null
+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);
+ }
+}
+++ /dev/null
-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];
- }
-
-}
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 {
private String name;
- private CountryCode state;
+ private Country state;
private String province;
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;
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);
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");
return name;
}
- public CountryCode getState() {
+ public Country getState() {
return state;
}
}
}
- 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)) {
}
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());
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;
private Name preferredName;
- private CountryCode residenceCountry;
+ private Country residenceCountry;
protected User(GigiResultSet rs) {
super(rs.getInt("id"));
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);
}
}
- 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;
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);
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);
}
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();
}
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;
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;
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;
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;
}
}
}
- 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", "");
t.output(out, l, vars);
}
- public CountryCode getCountry() {
+ public Country getCountry() {
return selected;
}
--- /dev/null
+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);
+
+}
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) {
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;
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;
}
};
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;
* @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()) {
}
}
- 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());
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());
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);
}
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);
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.");
}
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;
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());
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;
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"));
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;
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);
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;
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));
}
}
}
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) {
// 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();
// 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();
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;
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());
}
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;
@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
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"));
}
@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) {
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
String data = fetchStartErrorMessage(runRegister(query));
assertNull(data);
User u = User.getByEmail(email);
- assertEquals("DE", u.getResidenceCountry().getCountryCode());
+ assertEquals("DE", u.getResidenceCountry().getCode());
}
@Test
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;
@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();
*/
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);
}
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;
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
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 {
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;
}
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;
}
}
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;
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");
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;
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 {}
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;
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;
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"), //
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;
}
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);