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.wrappers.DataContainer;
public class Organisation extends CertificateOwner {
private String name;
- private String state;
+ private CountryCode state;
private String province;
if ( !creator.isInGroup(Group.ORGASSURER)) {
throw new GigiApiException("Only Organisation RA Agents may create organisations.");
}
+ if (state == null || state.getCountryCodeType() != CountryCodeType.CODE_2_CHARS) {
+ throw new GigiApiException("Got country code of illegal type.");
+ }
this.name = name;
- this.state = state.getCountryCode();
+ this.state = state;
this.province = province;
this.city = city;
this.email = email;
}
}
- protected Organisation(GigiResultSet rs) {
+ protected Organisation(GigiResultSet rs) throws GigiApiException {
super(rs.getInt("id"));
name = rs.getString("name");
- state = rs.getString("state");
+ state = CountryCode.getCountryCode(rs.getString("state"), CountryCodeType.CODE_2_CHARS);
province = rs.getString("province");
city = rs.getString("city");
email = rs.getString("contactEmail");
return name;
}
- public String getState() {
+ public CountryCode getState() {
return state;
}
}
}
- public void updateCertData(String o, CountryCode c, String st, String l) {
+ public void updateCertData(String o, CountryCode c, String st, String l) throws GigiApiException {
+ if (c == null || c.getCountryCodeType() != CountryCodeType.CODE_2_CHARS) {
+ throw new GigiApiException("Got country code of illegal type.");
+ }
for (Certificate cert : getCertificates(false)) {
if (cert.getStatus() == CertificateStatus.ISSUED) {
cert.revoke();
ps.executeUpdate();
}
name = o;
- state = c.getCountryCode();
+ state = c;
province = st;
city = l;
}
Organisation o1 = createUniqueOrg();
o1.updateCertData("name", CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS), DIFFICULT_CHARS, "Köln");
assertEquals("name", o1.getName());
- assertEquals("DE", o1.getState());
+ assertEquals("DE", o1.getState().getCountryCode());
assertEquals(DIFFICULT_CHARS, o1.getProvince());
assertEquals("Köln", o1.getCity());
o1.delete();
String s128 = str128;
String s129 = str128 + "a";
- assertNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), o1.getCity()));
+ assertNull(upCertData(o1, o1.getName(), null, o1.getProvince(), o1.getCity()));
// test organisation name
- assertNotNull(upCertData(o1, "", o1.getState(), o1.getProvince(), o1.getCity()));
- assertNull(upCertData(o1, "A", o1.getState(), o1.getProvince(), o1.getCity()));
- assertNull(upCertData(o1, s64, o1.getState(), o1.getProvince(), o1.getCity()));
- assertNotNull(upCertData(o1, s65, o1.getState(), o1.getProvince(), o1.getCity()));
+ assertNotNull(upCertData(o1, "", null, o1.getProvince(), o1.getCity()));
+ assertNull(upCertData(o1, "A", null, o1.getProvince(), o1.getCity()));
+ assertNull(upCertData(o1, s64, null, o1.getProvince(), o1.getCity()));
+ assertNotNull(upCertData(o1, s65, null, o1.getProvince(), o1.getCity()));
// test state
- assertNotNull(upCertData(o1, o1.getName(), o1.getState(), se, o1.getCity()));
- assertNull(upCertData(o1, o1.getName(), o1.getState(), "A", o1.getCity()));
- assertNull(upCertData(o1, o1.getName(), o1.getState(), s128, o1.getCity()));
- assertNotNull(upCertData(o1, o1.getName(), o1.getState(), s129, o1.getCity()));
+ assertNotNull(upCertData(o1, o1.getName(), null, se, o1.getCity()));
+ assertNull(upCertData(o1, o1.getName(), null, "A", o1.getCity()));
+ assertNull(upCertData(o1, o1.getName(), null, s128, o1.getCity()));
+ assertNotNull(upCertData(o1, o1.getName(), null, s129, o1.getCity()));
// test town
- assertNotNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), se));
- assertNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), "A"));
- assertNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), s128));
- assertNotNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), s129));
+ assertNotNull(upCertData(o1, o1.getName(), null, o1.getProvince(), se));
+ assertNull(upCertData(o1, o1.getName(), null, o1.getProvince(), "A"));
+ assertNull(upCertData(o1, o1.getName(), null, o1.getProvince(), s128));
+ assertNotNull(upCertData(o1, o1.getName(), null, o1.getProvince(), s129));
// test country
assertNotNull(upCertData(o1, o1.getName(), "", o1.getProvince(), o1.getCity()));
* @param o
* the new name
* @param c
- * the new country
+ * the new country or <code>null</code> to keep the current
+ * country.
* @param province
* the new "province/state"
* @param ct
* @return an error message or <code>null</code>
*/
private String upCertData(Organisation o1, String o, String c, String province, String ct) throws IOException, MalformedURLException, UnsupportedEncodingException {
+ if (c == null) {
+ c = o1.getState().getCountryCode();
+ }
return executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "action=updateCertificateData&O=" + o + "&C=" + c + "&ST=" + province + "&L=" + ct, 0);
}