- if (rs.next()) {
- if ( !rs.getString("keyname").equals(parts[1])) {
- throw new Error("Config error. Certificate Profile mismatch");
- }
- if ( !rs.getString("include").equals(p.getProperty("include"))) {
- throw new Error("Config error. Certificate Profile mismatch");
- }
- if ( !rs.getString("requires").equals(p.getProperty("requires", ""))) {
- throw new Error("Config error. Certificate Profile mismatch");
+ String[] parts = f.getName().split("\\.")[0].split("-", 2);
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `keyname`, `include`, `requires`, `name` FROM `profiles` WHERE `id`=?")) {
+ ps.setInt(1, Integer.parseInt(parts[0]));
+ GigiResultSet rs = ps.executeQuery();
+
+ if (rs.next()) {
+ if ( !rs.getString("keyname").equals(parts[1])) {
+ throw new Error("Config error. Certificate Profile mismatch");
+ }
+ if ( !rs.getString("include").equals(p.getProperty("include"))) {
+ throw new Error("Config error. Certificate Profile mismatch");
+ }
+ if ( !rs.getString("requires").equals(p.getProperty("requires", ""))) {
+ throw new Error("Config error. Certificate Profile mismatch");
+ }
+ } else {
+ try (GigiPreparedStatement insert = new GigiPreparedStatement("INSERT INTO `profiles` SET `keyname`=?, `include`=?, `requires`=?, `name`=?, `id`=?")) {
+ insert.setString(1, parts[1]);
+ insert.setString(2, p.getProperty("include"));
+ insert.setString(3, p.getProperty("requires", ""));
+ insert.setString(4, p.getProperty("name"));
+ insert.setInt(5, Integer.parseInt(parts[0]));
+ insert.execute();
+ }