}
- public static final int CURRENT_SCHEMA_VERSION = 24;
+ public static final int CURRENT_SCHEMA_VERSION = 25;
public static final int CONNECTION_TIMEOUT = 24 * 60 * 60;
CREATE TABLE IF NOT EXISTS "organisations" (
"id" int NOT NULL,
"name" varchar(64) NOT NULL,
- "state" varchar(2) NOT NULL,
+ "country" varchar(2) NOT NULL,
"province" varchar(128) NOT NULL,
"city" varchar(128) NOT NULL,
"contactEmail" varchar(100) NOT NULL,
"version" smallint NOT NULL,
PRIMARY KEY ("version")
);
-INSERT INTO "schemeVersion" (version) VALUES(24);
+INSERT INTO "schemeVersion" (version) VALUES(25);
DROP TABLE IF EXISTS `passwordResetTickets`;
CREATE TABLE `passwordResetTickets` (
--- /dev/null
+ALTER TABLE "organisations" RENAME COLUMN "state" TO "country";
}
public static synchronized CertificateOwner getById(int id) {
- CertificateOwner u = myCache.get(id);
- if (u == null) {
- try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT *, `users`.`id` AS uid, `organisations`.`id` AS oid FROM `certOwners` LEFT JOIN `users` ON `users`.`id`=`certOwners`.`id` LEFT JOIN `organisations` ON `organisations`.`id` = `certOwners`.`id` WHERE `certOwners`.`id`=? AND `deleted` is null")) {
- ps.setInt(1, id);
- try (GigiResultSet rs = ps.executeQuery()) {
- if ( !rs.next()) {
- return null;
- }
- if (rs.getString("uid") != null) {
- myCache.put(u = new User(rs));
- } else if (rs.getString("oid") != null) {
- myCache.put(u = new Organisation(rs));
- } else {
- System.err.println("Malformed cert owner: " + id);
- }
- } catch (GigiApiException e) {
- throw new Error(e);
- }
+ CertificateOwner cached = myCache.get(id);
+ if (cached != null) {
+ return cached;
+ }
+
+ try (GigiPreparedStatement psU = new GigiPreparedStatement("SELECT *, `users`.`id` AS uid FROM `certOwners` INNER JOIN `users` ON `users`.`id`=`certOwners`.`id` WHERE `certOwners`.`id`=? AND `deleted` is null")) {
+ psU.setInt(1, id);
+ GigiResultSet rsU = psU.executeQuery();
+ if (rsU.next()) {
+ return myCache.put(new User(rsU));
}
+ } catch (GigiApiException e) {
+ throw new Error(e);
}
- return u;
+
+ try (GigiPreparedStatement psO = new GigiPreparedStatement("SELECT *, `organisations`.`id` AS oid FROM `certOwners` INNER JOIN `organisations` ON `organisations`.`id`=`certOwners`.`id` WHERE `certOwners`.`id`=? AND `deleted` is null")) {
+ psO.setInt(1, id);
+ GigiResultSet rsO = psO.executeQuery();
+ if (rsO.next()) {
+ return myCache.put(new Organisation(rsO));
+ }
+ } catch (GigiApiException e) {
+ throw new Error(e);
+ }
+
+ System.err.println("Malformed cert owner: " + id);
+ return null;
}
public Domain[] getDomains() {
this.optionalName = optionalName;
this.postalAddress = postalAddress;
int id = getId();
- try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO organisations SET id=?, name=?, state=?, province=?, city=?, contactEmail=?, optional_name=?, postal_address=?, creator=?")) {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO organisations SET id=?, name=?, country=?, province=?, city=?, contactEmail=?, optional_name=?, postal_address=?, creator=?")) {
ps.setInt(1, id);
ps.setString(2, name);
ps.setString(3, country.getCode());
protected Organisation(GigiResultSet rs) throws GigiApiException {
super(rs.getInt("id"));
name = rs.getString("name");
- country = Country.getCountryByCode(rs.getString("state"), CountryCodeType.CODE_2_CHARS);
+ country = Country.getCountryByCode(rs.getString("country"), CountryCodeType.CODE_2_CHARS);
province = rs.getString("province");
city = rs.getString("city");
email = rs.getString("contactEmail");
return name;
}
- public Country getState() {
+ public Country getCountry() {
return country;
}
cert.revoke();
}
}
- try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `organisations` SET `name`=?, `state`=?, `province`=?, `city`=? WHERE `id`=?")) {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `organisations` SET `name`=?, `country`=?, `province`=?, `city`=? WHERE `id`=?")) {
ps.setString(1, o);
ps.setString(2, c.getCode());
ps.setString(3, st);
private Country residenceCountry;
- protected User(GigiResultSet rs) {
+ protected User(GigiResultSet rs) throws GigiApiException {
super(rs.getInt("id"));
- updateName(rs);
- }
- private void updateName(GigiResultSet rs) {
dob = new DayDate(rs.getDate("dob"));
email = rs.getString("email");
preferredName = Name.getById(rs.getInt("preferredName"));
- try {
- if (rs.getString("Country") != null) {
- residenceCountry = Country.getCountryByCode(rs.getString("Country"), Country.CountryCodeType.CODE_2_CHARS);
- }
- } catch (GigiApiException e) {
- throw new Error(e);
+ if (rs.getString("country") != null) {
+ residenceCountry = Country.getCountryByCode(rs.getString("Country"), Country.CountryCodeType.CODE_2_CHARS);
}
String localeStr = rs.getString("language");
if (ctx.getTarget() instanceof Organisation) {
Organisation org = (Organisation) ctx.getTarget();
subject.put("O", org.getName());
- subject.put("C", org.getState().getCode());
+ subject.put("C", org.getCountry().getCode());
subject.put("ST", org.getProvince());
subject.put("L", org.getCity());
if (ou != null) {
result = t;
o = t.getName();
- cs = new CountrySelector("C", false, t.getState());
+ cs = new CountrySelector("C", false, t.getCountry());
st = t.getProvince();
l = t.getCity();
Organisation org = orgas[count++];
vars.put("id", Integer.toString(org.getId()));
vars.put("name", org.getName());
- vars.put("country", org.getState().getCode());
+ vars.put("country", org.getCountry().getCode());
return true;
}
};
Organisation o1 = createUniqueOrg();
o1.updateCertData("name", Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), DIFFICULT_CHARS, "Köln");
assertEquals("name", o1.getName());
- assertEquals("DE", o1.getState().getCode());
+ assertEquals("DE", o1.getCountry().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().getCode();
+ c = o1.getCountry().getCode();
}
return executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "action=updateCertificateData&O=" + o + "&C=" + c + "&ST=" + province + "&L=" + ct, 0);
}