package org.cacert.gigi.dbObjects;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import org.cacert.gigi.database.GigiPreparedStatement;
import org.cacert.gigi.database.GigiResultSet;
import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
+import org.cacert.gigi.dbObjects.Country.CountryCodeType;
import org.cacert.gigi.dbObjects.wrappers.DataContainer;
public class Organisation extends CertificateOwner {
+ private static final long serialVersionUID = -2386342985586320843L;
+
@DataContainer
public static class Affiliation {
private String name;
- private String state;
+ private Country country;
private String province;
private String postalAddress;
- public Organisation(String name, String state, String province, String city, String email, String optionalName, String postalAddress, User creator) throws GigiApiException {
+ public Organisation(String name, Country country, 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 (country == null) {
+ throw new GigiApiException("Got country code of illegal type.");
+ }
this.name = name;
- this.state = state;
+ this.country = country;
this.province = province;
this.city = city;
this.email = email;
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);
+ ps.setString(3, country.getCode());
ps.setString(4, province);
ps.setString(5, city);
ps.setString(6, email);
}
}
- protected Organisation(GigiResultSet rs) {
+ protected Organisation(GigiResultSet rs) throws GigiApiException {
super(rs.getInt("id"));
name = rs.getString("name");
- state = rs.getString("state");
+ country = Country.getCountryByCode(rs.getString("state"), CountryCodeType.CODE_2_CHARS);
province = rs.getString("province");
city = rs.getString("city");
email = rs.getString("contactEmail");
return name;
}
- public String getState() {
- return state;
+ public Country getState() {
+ return country;
}
public String getProvince() {
}
}
- public void updateCertData(String o, String c, String st, String l) {
+ 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)) {
if (cert.getStatus() == CertificateStatus.ISSUED) {
cert.revoke();
}
try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `organisations` SET `name`=?, `state`=?, `province`=?, `city`=? WHERE `id`=?")) {
ps.setString(1, o);
- ps.setString(2, c);
+ ps.setString(2, c.getCode());
ps.setString(3, st);
ps.setString(4, l);
ps.setInt(5, getId());
ps.executeUpdate();
}
name = o;
- state = c;
+ country = c;
province = st;
city = l;
}
public boolean isSelfOrganisation() {
return SELF_ORG_NAME.equals(getName());
}
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {}
+
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {}
+
}