diff --git a/src/main/java/edu/suffolk/litlab/efspserver/codes/CodeDatabase.java b/src/main/java/edu/suffolk/litlab/efspserver/codes/CodeDatabase.java index 79a039d0..44635f28 100644 --- a/src/main/java/edu/suffolk/litlab/efspserver/codes/CodeDatabase.java +++ b/src/main/java/edu/suffolk/litlab/efspserver/codes/CodeDatabase.java @@ -443,30 +443,37 @@ public DataFields getDataFields(String courtLocationId) { return new DataFields(Map.of()); } - String query = DataFieldRow.getAllDataFieldConfigsForLoc(); - try (PreparedStatement st = conn.prepareStatement(query)) { - st.setString(1, tylerDomain); - st.setString(2, courtLocationId); - ResultSet rs = st.executeQuery(); - var dataFieldMap = new HashMap(); - while (rs.next()) { - DataFieldRow dfr = - new DataFieldRow( - rs.getString(1), - rs.getString(2), - rs.getBoolean(3), - rs.getBoolean(4), - rs.getString(5), - rs.getString(6), - rs.getString(7), - rs.getString(8), - rs.getString(9), - rs.getString(10), - rs.getBoolean(11), - rs.getString(12)); - dataFieldMap.put(dfr.code, dfr); + try { + List parentList = getParentList(courtLocationId); + String query = DataFieldRow.getAllDataFieldConfigsForLoc(); + List> allDataFields = new ArrayList<>(); + for (String currentCourt : parentList) { + try (PreparedStatement st = conn.prepareStatement(query)) { + st.setString(1, tylerDomain); + st.setString(2, currentCourt); + ResultSet rs = st.executeQuery(); + var dataFieldMap = new HashMap(); + while (rs.next()) { + DataFieldRow dfr = + new DataFieldRow( + rs.getString(1), + rs.getString(2), + rs.getBoolean(3), + rs.getBoolean(4), + rs.getString(5), + rs.getString(6), + rs.getString(7), + rs.getString(8), + rs.getString(9), + rs.getString(10), + rs.getBoolean(11), + rs.getString(12)); + dataFieldMap.put(dfr.code, dfr); + } + allDataFields.add(dataFieldMap); + } } - return new DataFields(dataFieldMap); + return new DataFields(allDataFields); } catch (SQLException ex) { log.error("SQLException: " + ex.toString()); return new DataFields(Map.of()); @@ -1061,6 +1068,39 @@ public Optional getFullLocationInfo(String courtId) { }); } + /** + * Gets the full line of succession for a given court, so given "cook:dv6", this would return + * ["cook:dv6", "cook:dv", "cook", "1", "0"] + */ + public List getParentList(String courtId) { + List parentList = new ArrayList(); + String currentCourt = courtId; + while (!currentCourt.isBlank()) { + parentList.add(currentCourt); + try (PreparedStatement st = conn.prepareStatement(CourtLocationInfo.parentQuery())) { + st.setString(1, tylerDomain); + st.setString(2, currentCourt); + ResultSet rs = st.executeQuery(); + if (rs.next()) { + currentCourt = rs.getString(2); + } else { + log.warn("CourtLocation " + currentCourt + ", ancestor of " + courtId + " not found!"); + return parentList; + } + } catch (SQLException ex) { + log.error( + "CourtLocation " + + currentCourt + + ", ancestor of " + + courtId + + " made a SQL error: " + + StdLib.strFromException(ex)); + return parentList; + } + } + return parentList; + } + public List getDisclaimerRequirements(String courtLocation) { return safetyWrap( () -> { diff --git a/src/main/java/edu/suffolk/litlab/efspserver/codes/CourtLocationInfo.java b/src/main/java/edu/suffolk/litlab/efspserver/codes/CourtLocationInfo.java index 4c9f65d8..e617d0e3 100644 --- a/src/main/java/edu/suffolk/litlab/efspserver/codes/CourtLocationInfo.java +++ b/src/main/java/edu/suffolk/litlab/efspserver/codes/CourtLocationInfo.java @@ -207,6 +207,14 @@ public CourtLocationInfo(ResultSet rs) throws SQLException { this.allowhearing = Boolean.parseBoolean(rs.getString(43)); } + public static String parentQuery() { + return """ + SELECT code, parentnodeid + FROM location + WHERE domain=? AND code=? + """; + } + public static String fullSingleQuery() { return """ SELECT code, name, initial, subsequent, disallowcopyingenvelopemultipletimes, diff --git a/src/main/java/edu/suffolk/litlab/efspserver/codes/DataFields.java b/src/main/java/edu/suffolk/litlab/efspserver/codes/DataFields.java index 6e5f2dba..0c9779a6 100644 --- a/src/main/java/edu/suffolk/litlab/efspserver/codes/DataFields.java +++ b/src/main/java/edu/suffolk/litlab/efspserver/codes/DataFields.java @@ -1,17 +1,28 @@ package edu.suffolk.litlab.efspserver.codes; +import java.util.List; import java.util.Map; public class DataFields { - private final Map fieldMap; + private final List> fieldMaps; public DataFields(Map fieldMap) { - this.fieldMap = fieldMap; + this.fieldMaps = List.of(fieldMap); + } + + public DataFields(Map fieldMap, Map fieldMapParent) { + this.fieldMaps = List.of(fieldMap, fieldMapParent); + } + + public DataFields(List> fieldMaps) { + this.fieldMaps = fieldMaps; } public DataFieldRow getFieldRow(String fieldName) { - if (fieldMap.containsKey(fieldName)) { - return fieldMap.get(fieldName); + for (var fieldMap : fieldMaps) { + if (fieldMap.containsKey(fieldName)) { + return fieldMap.get(fieldName); + } } return DataFieldRow.MissingDataField(fieldName); }