Skip to content

Commit

Permalink
Allow for parent court fallback for data field codes
Browse files Browse the repository at this point in the history
Some court don't have field codes, even when they should. Specifically,
In IL-Stage, alexander doesn't have any, even though certain things
are still required, like the BinaryStandardFormatName, and won't file
without them.
  • Loading branch information
BryceStevenWilley committed Jul 5, 2023
1 parent 7b87d08 commit 593d547
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 27 deletions.
86 changes: 63 additions & 23 deletions src/main/java/edu/suffolk/litlab/efspserver/codes/CodeDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, DataFieldRow>();
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<String> parentList = getParentList(courtLocationId);
String query = DataFieldRow.getAllDataFieldConfigsForLoc();
List<Map<String, DataFieldRow>> 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<String, DataFieldRow>();
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());
Expand Down Expand Up @@ -1061,6 +1068,39 @@ public Optional<CourtLocationInfo> 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<String> getParentList(String courtId) {
List<String> parentList = new ArrayList<String>();
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<Disclaimer> getDisclaimerRequirements(String courtLocation) {
return safetyWrap(
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/edu/suffolk/litlab/efspserver/codes/DataFields.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
package edu.suffolk.litlab.efspserver.codes;

import java.util.List;
import java.util.Map;

public class DataFields {
private final Map<String, DataFieldRow> fieldMap;
private final List<Map<String, DataFieldRow>> fieldMaps;

public DataFields(Map<String, DataFieldRow> fieldMap) {
this.fieldMap = fieldMap;
this.fieldMaps = List.of(fieldMap);
}

public DataFields(Map<String, DataFieldRow> fieldMap, Map<String, DataFieldRow> fieldMapParent) {
this.fieldMaps = List.of(fieldMap, fieldMapParent);
}

public DataFields(List<Map<String, DataFieldRow>> 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);
}
Expand Down

0 comments on commit 593d547

Please sign in to comment.