- public List<User> getAllAdmins() {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT memid FROM org_admin WHERE orgid=? AND deleted is null");
- ps.setInt(1, getId());
- GigiResultSet rs = ps.executeQuery();
- rs.last();
- ArrayList<User> al = new ArrayList<>(rs.getRow());
- rs.beforeFirst();
- while (rs.next()) {
- al.add(User.getById(rs.getInt(1)));
+ public List<Affiliation> getAllAdmins() {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `memid`, `master` FROM `org_admin` WHERE `orgid`=? AND `deleted` IS NULL", true)) {
+ ps.setInt(1, getId());
+ GigiResultSet rs = ps.executeQuery();
+ rs.last();
+ ArrayList<Affiliation> al = new ArrayList<>(rs.getRow());
+ rs.beforeFirst();
+ while (rs.next()) {
+ al.add(new Affiliation(this, User.getById(rs.getInt(1)), rs.getString(2).equals("y"), null));
+ }
+ return al;
+ }
+ }
+
+ public static Organisation[] getOrganisations(int offset, int count) {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `certOwners`.`id` FROM `organisations` INNER JOIN `certOwners` ON `certOwners`.`id`=`organisations`.`id` WHERE `certOwners`.`deleted` IS NULL OFFSET ? LIMIT ?", true)) {
+ ps.setInt(1, offset);
+ ps.setInt(2, count);
+ GigiResultSet res = ps.executeQuery();
+ res.last();
+ Organisation[] resu = new Organisation[res.getRow()];
+ res.beforeFirst();
+ int i = 0;
+ while (res.next()) {
+ resu[i++] = getById(res.getInt(1));
+ }
+ return resu;
+ }
+ }
+
+ 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.getCode());
+ ps.setString(3, st);
+ ps.setString(4, l);
+ ps.setInt(5, getId());
+ ps.executeUpdate();