Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class DatabaseVersion {

static final int CURRENT_VERSION = 10;
static final int CURRENT_VERSION = 11;
private static Logger log = LoggerFactory.getLogger(DatabaseVersion.class);
private final Connection codeConn;
private final Connection userConn;
Expand Down Expand Up @@ -149,6 +149,8 @@ private boolean updateDatabase(int onDiskVersion) throws NoSuchAlgorithmExceptio
update8To9();
} else if (onDiskVersion == 9) {
update9To10();
} else if (onDiskVersion == 10) {
update10To11();
}
setSchemaVersion(onDiskVersion + 1);
userConn.commit();
Expand Down Expand Up @@ -533,4 +535,68 @@ public void update9To10() throws SQLException {
}
codeConn.commit();
}

public void update10To11() throws SQLException {
// The codes database doesn't need to know about Tyler's environment
final String stripEnvSuffix =
"UPDATE %s SET domain = regexp_replace(domain, '-(stage|prod)$', '')";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, I think it also makes sense to rename the domain column to jurisdiction after the regex as well.


final List<String> tableNames =
List.of(
"location",
"error",
"version",
"installedversion",
"country",
"state",
"filingstatus",
"datafieldconfig",
"answer",
"arrestlocation",
"bond",
"casecategory",
"casesubtype",
"casetype",
"chargephase",
"citationjurisdiction",
"crossreference",
"damageamount",
"degree",
"disclaimerrequirement",
"driverlicensetype",
"documenttype",
"ethnicity",
"eyecolor",
"filertype",
"filetype",
"filing",
"filingcomponent",
"generaloffense",
"haircolor",
"language",
"lawenforcementunit",
"motiontype",
"namesuffix",
"optionalservices",
"optionalservices_filinglist",
"partytype",
"physicalfeature",
"procedureremedy",
"question",
"race",
"refundreason",
"servicetype",
"statute",
"statutetype",
"vehiclecolor",
"vehiclemake",
"vehicletype");

try (Statement st = codeConn.createStatement()) {
for (String tableName : tableNames) {
st.executeUpdate(stripEnvSuffix.formatted(tableName));
}
}
codeConn.commit();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package edu.suffolk.litlab.efsp.ecfcodes;

import edu.suffolk.litlab.efsp.Jurisdiction;
import edu.suffolk.litlab.efsp.db.Database;
import edu.suffolk.litlab.efsp.stdlib.SQLFunction;
import edu.suffolk.litlab.efsp.stdlib.SQLGetter;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -33,11 +33,8 @@ public CodeDatabaseAPI(Connection conn) {
super(conn);
}

/**
* The domain (the juristiction + environment, e.g. illinois-stage) that this database is working
* over.
*/
public abstract TylerDomain getDomain();
/** The jurisdiction (e.g illinois) that this database is working over */
public abstract Jurisdiction getDomain();
Comment on lines +36 to +37

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rename this getJurisdiction()


/**
* Gets all court location identifiers (CLI) stored in the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import edu.suffolk.litlab.efsp.server.utils.SendMessage;
import edu.suffolk.litlab.efsp.server.utils.ServiceHelpers;
import edu.suffolk.litlab.efsp.server.utils.SoapExceptionMapper;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.TylerEnv;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CodeDatabase;
import edu.suffolk.litlab.efsp.utils.InterviewToFilingInformationConverter;
Expand Down Expand Up @@ -160,8 +159,8 @@ private static void setupDatabases(DataSource codeDs, DataSource userDs)
@SuppressWarnings("resource")
LoginDatabase ld = new LoginDatabase(userConn);
@SuppressWarnings("resource")
// Jurisdiction and env args can be null, we're just making the tables
CodeDatabase cd = new CodeDatabase(new TylerDomain(null, null), codeConn);
// Jurisdiction can be null here, we're just checking if tables exist
CodeDatabase cd = new CodeDatabase(null, codeConn);
boolean brandNew = !ld.tablesExist() || !cd.tablesExist();

// Now we can tell if everything is being set up fresh. If so, we'll make everything now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void preSetup() {
SoapX509CallbackHandler.setX509Password(x509Password);

log.info("Checking table if absent");
try (CodeDatabase cd = new CodeDatabase(tylerDomain, codeDs.getConnection())) {
try (CodeDatabase cd = new CodeDatabase(tylerDomain.jurisdiction(), codeDs.getConnection())) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be slightly more than the original issue, but it looks like TylerEnv isn't really used anymore in this class (is included in the logs and the getName(), which is just being used for scheduling stuff), so we should probably replace the TylerDomain object with a Jurisdiction object here as well.

cd.createTablesIfAbsent();
List<String> locations = cd.getAllLocations();
log.info("All locations for {}: {}", tylerDomain, locations);
Expand Down Expand Up @@ -263,7 +263,7 @@ public Jurisdiction getJurisdiction() {
}

public Set<String> getCourts() {
try (CodeDatabase cd = new CodeDatabase(tylerDomain, codeDs.getConnection())) {
try (CodeDatabase cd = new CodeDatabase(tylerDomain.jurisdiction(), codeDs.getConnection())) {
Set<String> allCourts = new HashSet<String>(cd.getAllLocations());
// 0 and 1 are special "system" courts that have defaults for all courts.
// They aren't available for filing
Expand All @@ -286,7 +286,7 @@ public JurisdictionServiceHandle getServiceHandle() {

Supplier<CodeDatabase> cdSupplier =
() -> {
return CodeDatabase.fromDS(tylerDomain, this.codeDs);
return CodeDatabase.fromDS(tylerDomain.jurisdiction(), this.codeDs);
};

PolicyCacher policyCacher = new PolicyCacher();
Expand Down Expand Up @@ -358,7 +358,7 @@ public Optional<EfmRestCallbackInterface> getCallback() {

@Override
public void setupGlobals() {
Supplier<CodeDatabase> makeCD = () -> CodeDatabase.fromDS(tylerDomain, codeDs);
Supplier<CodeDatabase> makeCD = () -> CodeDatabase.fromDS(tylerDomain.jurisdiction(), codeDs);
Supplier<UserDatabase> makeUD = () -> UserDatabase.fromDS(userDs);
OasisEcfWsCallback implementor = new OasisEcfWsCallback(makeCD, makeUD, sender);
String baseLocalUrl = ServiceHelpers.BASE_LOCAL_URL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import edu.suffolk.litlab.efsp.server.logging.MDCWrappers;
import edu.suffolk.litlab.efsp.server.logging.Monitor;
import edu.suffolk.litlab.efsp.tyler.TylerClients;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CodeDatabase;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CodeUpdater;
import java.sql.Connection;
Expand Down Expand Up @@ -42,7 +41,6 @@ public class UpdateCodeVersions implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
var jurisdiction = Jurisdiction.parse(dataMap.getString("TYLER_JURISDICTION"));
var domain = new TylerDomain(jurisdiction, TylerClients.getTylerEnv());
MDC.put(MDCWrappers.OPERATION, "UpdateCodeVersions.execute");
MDC.put(MDCWrappers.USER_ID, jurisdiction.getName());
String x509Password = dataMap.getString("X509_PASSWORD");
Expand All @@ -55,7 +53,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
boolean success = true;
try (Connection conn =
DatabaseCreator.makeSingleConnection(pgDb, pgFullUrl, pgUser, pgPassword);
CodeDatabase cd = new CodeDatabase(domain, conn)) {
CodeDatabase cd = new CodeDatabase(jurisdiction, conn)) {
success =
CodeUpdater.executeCommand(() -> cd, jurisdiction, List.of("refresh"), x509Password);
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package edu.suffolk.litlab.efsp.tyler.ecfcodes;

import edu.suffolk.litlab.efsp.Jurisdiction;
import edu.suffolk.litlab.efsp.ecfcodes.CodeAndLocation;
import edu.suffolk.litlab.efsp.ecfcodes.CodeDatabaseAPI;
import edu.suffolk.litlab.efsp.ecfcodes.CodeDatabaseUtils;
import edu.suffolk.litlab.efsp.ecfcodes.CodeDatabaseUtils.UnsupportedTableException;
import edu.suffolk.litlab.efsp.ecfcodes.CodeDocException;
import edu.suffolk.litlab.efsp.ecfcodes.CodeDocIterator;
import edu.suffolk.litlab.efsp.ecfcodes.NameAndCode;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -39,19 +39,16 @@
public class CodeDatabase extends CodeDatabaseAPI {
private static final Logger log = LoggerFactory.getLogger(CodeDatabase.class);

/** The tyler jurisdiction + tyler environment, i.e. illinois-stage. */
private final TylerDomain tylerDomain;
private final Jurisdiction jurisdiction;

// TODO(brycew): the database doesn't need the env. Should be implicit, but it's gonna be a lot to
// take out.
public CodeDatabase(TylerDomain domain, Connection conn) {
public CodeDatabase(Jurisdiction jurisdiction, Connection conn) {
super(conn);
this.tylerDomain = domain;
this.jurisdiction = jurisdiction;
}

public static CodeDatabase fromDS(TylerDomain domain, DataSource ds) {
public static CodeDatabase fromDS(Jurisdiction jurisdiction, DataSource ds) {
try {
CodeDatabase cd = new CodeDatabase(domain, ds.getConnection());
CodeDatabase cd = new CodeDatabase(jurisdiction, ds.getConnection());
return cd;
} catch (SQLException e) {
log.error("In CodeDatabase constructor, can't get connection: ", e);
Expand Down Expand Up @@ -83,12 +80,12 @@ public void createTablesIfAbsent() throws SQLException {
}

@Override
public TylerDomain getDomain() {
return tylerDomain;
public Jurisdiction getDomain() {
return jurisdiction;
}

private String domainStr() {
return tylerDomain.getName();
return jurisdiction.getName();
}
Comment on lines 87 to 89

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rename this to jurisStr().


public void createTableIfAbsent(String tableName) throws SQLException {
Expand Down Expand Up @@ -714,7 +711,7 @@ public void vacuumAll() {
vacuumSt.executeUpdate();
}
} catch (SQLException ex) {
log.error("Error when vacuuming in {}", this.tylerDomain, ex);
log.error("Error when vacuuming in {}", this.jurisdiction, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import edu.suffolk.litlab.efsp.server.utils.SoapX509CallbackHandler;
import edu.suffolk.litlab.efsp.tyler.SoapClientChooser;
import edu.suffolk.litlab.efsp.tyler.TylerClients;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.TylerUserClient;
import edu.suffolk.litlab.efsp.tyler.TylerUserFactory;
import edu.suffolk.litlab.efsp.tyler.TylerUserNamePassword;
Expand Down Expand Up @@ -308,7 +307,7 @@ private static Map<String, DownloadedCodes> streamDownload(
}

private static Map<String, CourtPolicyResponseMessageType> streamPolicies(
Stream<String> locations, TylerDomain domain, FilingReviewMDEPort filingPort) {
Stream<String> locations, Jurisdiction jurisdiction, FilingReviewMDEPort filingPort) {
var policies = new ConcurrentHashMap<String, CourtPolicyResponseMessageType>();
locations.forEach(
location -> {
Expand All @@ -317,7 +316,8 @@ private static Map<String, CourtPolicyResponseMessageType> streamPolicies(
CourtPolicyResponseMessageType p = filingPort.getPolicy(m);
policies.put(location, p);
} catch (SOAPFaultException ex) {
log.warn("Got a SOAP excption getting policy for {} in {}: ", location, domain, ex);
log.warn(
"Got a SOAP excption getting policy for {} in {}: ", location, jurisdiction, ex);
}
});
return policies;
Expand Down Expand Up @@ -649,7 +649,6 @@ public static boolean executeCommand(

/** Should just be called from main. */
private static CodeDatabaseAPI makeCodeDatabase(Jurisdiction jurisdiction) {
var domain = new TylerDomain(jurisdiction, TylerClients.getTylerEnv());
try {
DataSource ds =
DatabaseCreator.makeDataSource(
Expand All @@ -661,7 +660,7 @@ private static CodeDatabaseAPI makeCodeDatabase(Jurisdiction jurisdiction) {
10,
100);

return CodeDatabase.fromDS(domain, ds);
return CodeDatabase.fromDS(jurisdiction, ds);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import edu.suffolk.litlab.efsp.Jurisdiction;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.TylerEnv;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CodeDatabase;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.FilingComponent;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.OptionalServiceCode;
Expand Down Expand Up @@ -143,11 +141,10 @@ public void testFullUpdate() throws SQLException, NoSuchAlgorithmException {
rs = codeSt.executeQuery("SELECT DISTINCT domain from location");

while (rs.next()) {
assertEquals(rs.getString(1), "illinois-stage");
assertEquals(rs.getString(1), "illinois");
}

try (var codesDatabase =
new CodeDatabase(new TylerDomain(Jurisdiction.ILLINOIS, TylerEnv.STAGE), codeConn)) {
try (var codesDatabase = new CodeDatabase(Jurisdiction.ILLINOIS, codeConn)) {
List<OptionalServiceCode> opts = codesDatabase.getOptionalServices("adams", "27959");
assertEquals(23, opts.size());
List<PartyType> partyTypes = codesDatabase.getPartyTypeFor("adams", "27898");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import edu.suffolk.litlab.efsp.model.FilingDoc;
import edu.suffolk.litlab.efsp.model.FilingInformation;
import edu.suffolk.litlab.efsp.model.Person;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.TylerEnv;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CaseCategory;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CaseType;
Expand Down Expand Up @@ -73,7 +72,7 @@ public void setUp() throws IOException {
when(cd.getFilingComponents("01", exampleFilingType.code))
.thenReturn(List.of(new FilingComponent("332", null, null, false, false, 0, null, null)));
when(cd.getStateCodes("01", "US")).thenReturn(List.of("MA", "TX", "IL", "VT"));
when(cd.getDomain()).thenReturn(new TylerDomain(Jurisdiction.ILLINOIS, TylerEnv.STAGE));
when(cd.getDomain()).thenReturn(Jurisdiction.ILLINOIS);
when(cd.getDataFields("01"))
.thenReturn(
new DataFields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import edu.suffolk.litlab.efsp.Jurisdiction;
import edu.suffolk.litlab.efsp.ecfcodes.CodesParser;
import edu.suffolk.litlab.efsp.model.PartyId;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.TylerEnv;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CodeDatabase;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CourtLocationInfo;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.DataFieldRow;
Expand Down Expand Up @@ -41,7 +39,7 @@ public void setUp() {
var allDataFields = mock(DataFields.class);
when(cd.getStateCodes("adams", "US")).thenReturn(List.of("MA", "TX", "IL", "VT"));
when(cd.getDataFields("adams")).thenReturn(allDataFields);
when(cd.getDomain()).thenReturn(new TylerDomain(Jurisdiction.ILLINOIS, TylerEnv.STAGE));
when(cd.getDomain()).thenReturn(Jurisdiction.ILLINOIS);
when(allDataFields.getFieldRow("PartyFirstName"))
.thenReturn(new DataFieldRow("PartyFirstName", "", true, true, "adams"));
when(allDataFields.getFieldRow("PartyMiddleName"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import edu.suffolk.litlab.efsp.db.DatabaseCreator;
import edu.suffolk.litlab.efsp.db.DatabaseVersionTest;
import edu.suffolk.litlab.efsp.ecfcodes.NameAndCode;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.TylerEnv;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CaseCategory;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CaseType;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CodeDatabase;
Expand Down Expand Up @@ -53,7 +51,7 @@ public void setUp() throws SQLException {
postgres.getJdbcUrl(),
postgres.getUsername(),
postgres.getPassword());
cd = new CodeDatabase(new TylerDomain(Jurisdiction.ILLINOIS, TylerEnv.STAGE), conn);
cd = new CodeDatabase(Jurisdiction.ILLINOIS, conn);
cd.createTablesIfAbsent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import edu.suffolk.litlab.efsp.db.DatabaseVersionTest;
import edu.suffolk.litlab.efsp.server.EfspServer;
import edu.suffolk.litlab.efsp.server.utils.ServiceHelpers;
import edu.suffolk.litlab.efsp.tyler.TylerDomain;
import edu.suffolk.litlab.efsp.tyler.TylerEnv;
import edu.suffolk.litlab.efsp.tyler.ecfcodes.CodeDatabase;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
Expand Down Expand Up @@ -58,7 +56,7 @@ private void startServer() throws Exception {
100);
Supplier<CodeDatabase> cdSupplier =
() -> {
return CodeDatabase.fromDS(new TylerDomain(Jurisdiction.ILLINOIS, TylerEnv.STAGE), ds);
return CodeDatabase.fromDS(Jurisdiction.ILLINOIS, ds);
};
try (CodeDatabase cd = cdSupplier.get()) {
cd.createTablesIfAbsent();
Expand Down
Loading