Skip to content

Commit 03b19ce

Browse files
Pass CodeUpdater a Supplier, not a CodeDatabase
Some operations (specifically `downloadIndividual` [^1]) don't need the CodeDatabase. However, the SQL data source is always created, so you need valid env vars for a SQL database, even if not used. This patch changes it so that isn't the case; if the operation you're trying to run manually doesn't use a SQL database, the variables are not required. [^1]: `downloadInidivdual` gets individual XML files from courts (necessary for `repcap`, an undocumented table which breaks things), and doesn't directly interact with any of the SQL tables themselves.
1 parent f7f6cde commit 03b19ce

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

proxyserver/src/main/java/edu/suffolk/litlab/efsp/ecfcodes/CodeUpdater.java

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.InputStream;
2424
import java.net.HttpURLConnection;
2525
import java.net.URL;
26-
import java.sql.Connection;
2726
import java.sql.SQLException;
2827
import java.sql.Savepoint;
2928
import java.time.Clock;
@@ -37,6 +36,7 @@
3736
import java.util.Set;
3837
import java.util.concurrent.ConcurrentHashMap;
3938
import java.util.function.Function;
39+
import java.util.function.Supplier;
4040
import java.util.stream.Collectors;
4141
import java.util.stream.Stream;
4242
import java.util.zip.ZipInputStream;
@@ -413,6 +413,7 @@ private boolean downloadCourtTables(
413413
/** Returns true if successful, false if not successful */
414414
public boolean updateAll(String baseUrl, FilingReviewMDEPort filingPort, CodeDatabase cd)
415415
throws SQLException, IOException, JAXBException {
416+
cd.setAutoCommit(false);
416417
HeaderSigner signer = new HeaderSigner(this.pathToKeystore, this.x509Password);
417418
if (!downloadSystemTables(baseUrl, cd, signer)) {
418419
log.warn(
@@ -496,6 +497,7 @@ public boolean replaceAll(String baseUrl, FilingReviewMDEPort filingPort, CodeDa
496497
public boolean replaceSome(
497498
String baseUrl, FilingReviewMDEPort filingPort, CodeDatabase cd, List<String> locs)
498499
throws SQLException, IOException, JAXBException {
500+
cd.setAutoCommit(false);
499501
HeaderSigner signer = new HeaderSigner(this.pathToKeystore, this.x509Password);
500502
log.info("Downloading system tables for {}", cd.getDomain());
501503
boolean success = downloadSystemTables(baseUrl, cd, signer);
@@ -598,11 +600,14 @@ public boolean downloadIndiv(List<String> args, String jurisdiction, TylerEnv en
598600
}
599601

600602
public static boolean executeCommand(
601-
CodeDatabase cd, String jurisdiction, TylerEnv env, List<String> args, String x509Password) {
603+
Supplier<CodeDatabase> cdSupplier,
604+
String jurisdiction,
605+
TylerEnv env,
606+
List<String> args,
607+
String x509Password) {
602608
SoapX509CallbackHandler.setX509Password(x509Password);
603609
String command = args.get(0);
604610
try {
605-
cd.setAutoCommit(false);
606611
String codesSite = TylerClients.getTylerServerRootUrl(jurisdiction, env);
607612
FilingReviewMDEPort filingPort =
608613
loginWithTyler(
@@ -612,11 +617,12 @@ public static boolean executeCommand(
612617
System.getenv("TYLER_USER_PASSWORD"));
613618
CodeUpdater cu = new CodeUpdater(System.getenv("PATH_TO_KEYSTORE"), x509Password);
614619
if (command.equalsIgnoreCase("replaceall")) {
615-
return cu.replaceAll(codesSite, filingPort, cd);
620+
return cu.replaceAll(codesSite, filingPort, cdSupplier.get());
616621
} else if (command.equalsIgnoreCase("replacesome")) {
617-
return cu.replaceSome(codesSite, filingPort, cd, args.subList(1, args.size()));
622+
return cu.replaceSome(
623+
codesSite, filingPort, cdSupplier.get(), args.subList(1, args.size()));
618624
} else if (command.equalsIgnoreCase("refresh")) {
619-
return cu.updateAll(codesSite, filingPort, cd);
625+
return cu.updateAll(codesSite, filingPort, cdSupplier.get());
620626
} else if (command.equalsIgnoreCase("downloadIndiv")) {
621627
return cu.downloadIndiv(args, jurisdiction, env);
622628
} else {
@@ -629,6 +635,25 @@ public static boolean executeCommand(
629635
}
630636
}
631637

638+
/** Should just be called from main. */
639+
private static CodeDatabase makeCodeDatabase(String jurisdiction, TylerEnv env) {
640+
try {
641+
DataSource ds =
642+
DatabaseCreator.makeDataSource(
643+
System.getenv("POSTGRES_URL"),
644+
Integer.parseInt(System.getenv("POSTGRES_PORT")),
645+
System.getenv("POSTGRES_CODES_DB"),
646+
System.getenv("POSTGRES_USER"),
647+
System.getenv("POSTGRES_PASSWORD"),
648+
5,
649+
100);
650+
651+
return CodeDatabase.fromDS(jurisdiction, env, ds);
652+
} catch (Exception ex) {
653+
throw new RuntimeException(ex);
654+
}
655+
}
656+
632657
/**
633658
* Run with:
634659
*
@@ -645,30 +670,19 @@ public static void main(String[] args) throws Exception {
645670
log.error("Need to pass in a subprogram: downloadIndiv, or refresh");
646671
System.exit(1);
647672
}
648-
DataSource ds =
649-
DatabaseCreator.makeDataSource(
650-
System.getenv("POSTGRES_URL"),
651-
Integer.parseInt(System.getenv("POSTGRES_PORT")),
652-
System.getenv("POSTGRES_CODES_DB"),
653-
System.getenv("POSTGRES_USER"),
654-
System.getenv("POSTGRES_PASSWORD"),
655-
5,
656-
100);
657673

658674
List<String> jurisdictions = List.of(System.getenv("TYLER_JURISDICTIONS").split(" "));
659675
var env = TylerEnv.parse(System.getenv("TYLER_ENV"));
660676
for (String jurisdiction : jurisdictions) {
661677
// Reusing USER for Jurisdiction, SESSION for the court / location, and REQUEST for the table
662678
// name.
663679
MDC.put(MDCWrappers.USER_ID, jurisdiction);
664-
try (Connection conn = ds.getConnection()) {
665-
executeCommand(
666-
new CodeDatabase(jurisdiction, env, conn),
667-
jurisdiction,
668-
env,
669-
List.of(args),
670-
System.getenv("X509_PASSWORD"));
671-
}
680+
executeCommand(
681+
() -> makeCodeDatabase(jurisdiction, env),
682+
jurisdiction,
683+
env,
684+
List.of(args),
685+
System.getenv("X509_PASSWORD"));
672686
}
673687
}
674688
}

proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/setup/tyler/TylerModuleSetup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ public void preSetup() {
184184
+ tylerJurisdiction
185185
+ ": please wait a bit");
186186
CodeUpdater.executeCommand(
187-
cd,
187+
() -> cd,
188188
tylerJurisdiction,
189189
tylerEnv,
190190
List.of("replacesome", testOnlyLocation),
191191
this.x509Password);
192192
} else {
193193
log.info("Downloading all codes for {}: please wait a bit", tylerJurisdiction);
194194
CodeUpdater.executeCommand(
195-
cd, tylerJurisdiction, tylerEnv, List.of("replaceall"), this.x509Password);
195+
() -> cd, tylerJurisdiction, tylerEnv, List.of("replaceall"), this.x509Password);
196196
}
197197
}
198198
} catch (SQLException e) {

proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/utils/UpdateCodeVersions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
5353
try (Connection conn =
5454
DatabaseCreator.makeSingleConnection(pgDb, pgFullUrl, pgUser, pgPassword);
5555
CodeDatabase cd = new CodeDatabase(jurisdiction, env, conn)) {
56-
success = CodeUpdater.executeCommand(cd, jurisdiction, env, List.of("refresh"), x509Password);
56+
success =
57+
CodeUpdater.executeCommand(() -> cd, jurisdiction, env, List.of("refresh"), x509Password);
5758
} catch (SQLException e) {
5859
log.error("Couldn't connect to Codes db from Job Executor: ", e);
5960
success = false;

0 commit comments

Comments
 (0)