Skip to content
Merged
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 @@ -2,6 +2,7 @@

import edu.suffolk.litlab.efsp.db.model.Transaction;
import edu.suffolk.litlab.efsp.ecfcodes.tyler.CodeTableConstants;
import edu.suffolk.litlab.efsp.model.EmailTemplates;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -84,12 +85,7 @@ public void addToTable(
String caseType,
String courtId,
Timestamp submitted,
String acceptedTmpl,
String acceptedSubject,
String rejectedTmpl,
String rejectedSubject,
String neutralTmpl,
String neutralSubject,
EmailTemplates emailTemplates,
String caseTitle,
String envelopeId)
throws SQLException {
Expand All @@ -105,12 +101,7 @@ public void addToTable(
caseType,
courtId,
submitted,
acceptedTmpl,
acceptedSubject,
rejectedTmpl,
rejectedSubject,
neutralTmpl,
neutralSubject,
emailTemplates,
caseTitle,
envelopeId);
}
Expand All @@ -128,12 +119,7 @@ public void addToTable(
String caseType,
String courtId,
Timestamp submitted,
String acceptedTmpl,
String acceptedSubject,
String rejectedTmpl,
String rejectedSubject,
String neutralTmpl,
String neutralSubject,
EmailTemplates tmpls,
String caseTitle,
String envelopeId)
throws SQLException {
Expand Down Expand Up @@ -173,12 +159,12 @@ INSERT INTO submitted_filings (
insertSt.setString(8, caseType);
insertSt.setString(9, courtId);
insertSt.setTimestamp(10, submitted);
insertSt.setString(11, acceptedTmpl);
insertSt.setString(12, acceptedSubject);
insertSt.setString(13, rejectedTmpl);
insertSt.setString(14, rejectedSubject);
insertSt.setString(15, neutralTmpl);
insertSt.setString(16, neutralSubject);
insertSt.setString(11, tmpls.acceptedTemplate());
insertSt.setString(12, tmpls.acceptedSubject());
insertSt.setString(13, tmpls.rejectedTemplate());
insertSt.setString(14, tmpls.rejectedSubject());
insertSt.setString(15, tmpls.neutralTemplate());
insertSt.setString(16, tmpls.neutralSubject());
insertSt.setString(17, caseTitle);
insertSt.setString(18, envelopeId);
insertSt.executeUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import edu.suffolk.litlab.efsp.model.Address;
import edu.suffolk.litlab.efsp.server.ecf4.CodesParser;
import edu.suffolk.litlab.efsp.utils.FilingError;
import edu.suffolk.litlab.efsp.utils.InfoCollector;
import edu.suffolk.litlab.efsp.utils.InterviewVariable;
Expand All @@ -21,8 +22,8 @@ protected AddressDocassembleJacksonDeserializer() {}
*
* @throws FilingError if @param node isn't a JSON object describing an address
*/
public static Optional<Address> fromNode(JsonNode node, InfoCollector collector)
throws FilingError {
public static Optional<Address> fromNode(
JsonNode node, CodesParser parser, InfoCollector collector) throws FilingError {
if (!node.isObject()) {
FilingError err =
FilingError.malformedInterview(
Expand Down Expand Up @@ -65,6 +66,7 @@ public static Optional<Address> fromNode(JsonNode node, InfoCollector collector)
String zip = (node.has("zip")) ? node.get("zip").asText("") : "";
String country = (node.has("country")) ? node.get("country").asText("US").toUpperCase() : "US";
if (country.length() > 2) {
// TODO: consider handling ISO-3166-alpha 3 codes?
log.error("Country {} isn't a valid country (should be 2 letters", country);
InterviewVariable countryOptions =
collector.requestVar(
Expand All @@ -73,6 +75,13 @@ public static Optional<Address> fromNode(JsonNode node, InfoCollector collector)
collector.error(err);
throw err;
}
var stateRes = parser.vetStateCode(state, country);
if (stateRes.isErr()) {
var stateBuilder = collector.varBuilder().name("state");
collector.addCodeError(stateRes.expectErr(""), stateBuilder);
} else {
state = stateRes.expect("");
}
Address addr = new Address(address, unit, city, state, zip, country);
return Optional.of(addr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import edu.suffolk.litlab.efsp.server.ecf4.CodesParser.TextVarError;
import edu.suffolk.litlab.efsp.utils.FilingError;
import edu.suffolk.litlab.efsp.utils.InfoCollector;
import edu.suffolk.litlab.efsp.utils.InterviewVariable;
import edu.suffolk.litlab.efsp.utils.JsonHelpers;
import fj.data.NonEmptyList;
import fj.data.Option;
Expand Down Expand Up @@ -57,6 +58,7 @@ public static Optional<FilingDoc> fromNode(
int sequenceNum,
List<FilingCode> filingOptions,
boolean isInitialFiling,
boolean hasServiceContacts,
CodesParser parser,
InfoCollector collector)
throws FilingError {
Expand Down Expand Up @@ -161,7 +163,7 @@ public static Optional<FilingDoc> fromNode(
yield Optional.empty();
}
};
var actionRes = parser.vetFilingAction(maybeAction, isInitialFiling);
var actionRes = parser.vetFilingAction(maybeAction, isInitialFiling, hasServiceContacts);
if (actionRes.isErr()) {
collector.addWrong(
collector
Expand All @@ -187,6 +189,16 @@ public static Optional<FilingDoc> fromNode(
return PartyId.Already(fp);
})
.collect(Collectors.toList());
var partiesRes = parser.vetFilingParties(fullParties);
if (partiesRes.isErr()) {
InterviewVariable partyVar =
collector.requestVar(
"filing_parties", "The Parties that are filing this document", "text");
collector.addRequired(partyVar);
} else {
fullParties = partiesRes.expect("");
}

var components = new ArrayList<FilingComponent>(parser.retrieveFilingComponents(filingType));
fj.data.List<FilingAttachment> attachments = fj.data.List.nil();
if (node.has("tyler_merge_attachments")
Expand Down Expand Up @@ -234,7 +246,7 @@ public static Optional<FilingDoc> fromNode(

var descriptionFromSpec =
parser.getDocumentDescription(
userDescription, goodAttachments.some().head().getFileName(), filingType);
userDescription, goodAttachments.some().head().fileName(), filingType);
return Optional.of(
new FilingDoc(
filingType,
Expand Down Expand Up @@ -333,6 +345,15 @@ private static Optional<FilingAttachment> getAttachment(
+ dataUrl
+ ")"));
}

// TODO(brycew): depends on some DA code, should read in the PDF if possible here. Might be
// risky though.
// https://stackoverflow.com/questions/6026971/page-count-of-pdf-with-java
Optional<Integer> pageCount = Optional.empty();
if (node.has("page_count")) {
int count = node.get("page_count").asInt(1);
pageCount = Optional.of(count);
}
// Difficult to hardcode more SSRF solutions, since deployment can be varied. Can't block local
// network /
// localhost, since things could be on the same server / network. TODO: inject an allow-list
Expand All @@ -351,11 +372,12 @@ private static Optional<FilingAttachment> getAttachment(

return Optional.of(
new FilingAttachment(
filingComponent,
documentDescription,
fileName,
(inStream != null) ? inStream.readAllBytes() : new byte[0],
documentType,
filingComponent,
documentDescription));
pageCount));
} catch (MalformedURLException ex) {
FilingError err =
serverError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.suffolk.litlab.efsp.docassemble;

import static edu.suffolk.litlab.efsp.utils.JsonHelpers.getNumberMember;
import static edu.suffolk.litlab.efsp.utils.JsonHelpers.getStringDefault;
import static edu.suffolk.litlab.efsp.utils.JsonHelpers.getStringMember;

import com.fasterxml.jackson.core.JsonParser;
Expand All @@ -11,6 +13,7 @@
import com.hubspot.algebra.Result;
import edu.suffolk.litlab.efsp.ecfcodes.tyler.FilingCode;
import edu.suffolk.litlab.efsp.model.CaseServiceContact;
import edu.suffolk.litlab.efsp.model.EmailTemplates;
import edu.suffolk.litlab.efsp.model.FilingDoc;
import edu.suffolk.litlab.efsp.model.FilingInformation;
import edu.suffolk.litlab.efsp.model.LowerCourtInfo;
Expand Down Expand Up @@ -319,6 +322,7 @@ public FilingInformation fromNode(JsonNode node, InfoCollector collector) throws
varToPartyId,
filingOptions,
isInitialFiling,
entities.getServiceContacts().size() > 0,
parser,
collector));
if (entities.getFilings().isEmpty()) {
Expand Down Expand Up @@ -400,7 +404,53 @@ public FilingInformation fromNode(JsonNode node, InfoCollector collector) throws
}

entities.setReturnDate(extractReturnDate(node.get("return_date"), collector));
entities.setMiscInfo(node);

var filerTypeRes = parser.vetFilerType(getStringMember(node, "filer_type"));
if (filerTypeRes.isErr()) {
var filerTypeBuilder = collector.varBuilder().name("filer_type");
collector.addCodeError(filerTypeRes.expectErr(""), filerTypeBuilder);
} else {
entities.setFilerType(filerTypeRes.expect(""));
}

var maybeAmt = getNumberMember(node, "amount_in_controversy");
var filingCodes = entities.getFilings().stream().map(d -> d.getFilingCode()).toList();
var amtRes = parser.vetAmountInControversy(maybeAmt, filingCodes);
if (amtRes.isErr()) {
collector.error(
FilingError.malformedInterview("ad danum amount, Amount in controversy required"));
} else {
entities.setAmountInControversy(amtRes.expect(""));
}

var maybeMax = getNumberMember(node, "max_fee_amount");
entities.setMaxFeeAmount(parser.vetMaxAmount(maybeMax));

boolean contestedCase = false;
JsonNode jsonContested = node.get("is_contested_case");
if (jsonContested != null && jsonContested.isBoolean()) {
contestedCase = jsonContested.asBoolean();
}
entities.setIsContestedCase(contestedCase);

boolean outOfState = false;
if (node.has("out_of_state")) {
outOfState = node.get("out_of_state").asBoolean(false);
}
entities.setOutOfState(outOfState);

var emailTemplates =
new EmailTemplates(
getStringDefault(node, "email_confirmation_contents", ""),
getStringDefault(node, "email_confirmation_subject", ""),
getStringDefault(node, "acceptance_contents", ""),
getStringDefault(node, "acceptance_subject", ""),
getStringDefault(node, "rejected_contents", ""),
getStringDefault(node, "rejected_subject", ""),
getStringDefault(node, "neutral_contents", ""),
getStringDefault(node, "neutral_subject", ""));

entities.setEmailTemplates(emailTemplates);

return entities;
}
Expand Down Expand Up @@ -517,6 +567,7 @@ private static List<FilingDoc> extractFilingDocs(
Map<String, PartyId> varToPartyId,
List<FilingCode> filingOptions,
boolean isInitialFiling,
boolean hasServiceContacts,
CodesParser parser,
InfoCollector collector)
throws FilingError {
Expand Down Expand Up @@ -547,6 +598,7 @@ private static List<FilingDoc> extractFilingDocs(
filingDocs.size(),
filingOptions,
isInitialFiling,
hasServiceContacts,
parser,
collector);
collector.popAttributeStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public static Result<Person, FilingError> fromNode(
if (node.has("address") && node.get("address").isObject()) {
collector.pushAttributeStack("address");
try {
addr = AddressDocassembleJacksonDeserializer.fromNode(node.get("address"), collector);
addr =
AddressDocassembleJacksonDeserializer.fromNode(node.get("address"), parser, collector);
collector.popAttributeStack();
} catch (FilingError err) {
if (!err.getType().equals(FilingError.Type.MissingRequired)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package edu.suffolk.litlab.efsp.model;

public record EmailTemplates(
String confirmationTemplate,
String confirmationSubject,
String acceptedTemplate,
String acceptedSubject,
String rejectedTemplate,
String rejectedSubject,
String neutralTemplate,
String neutralSubject) {

public EmailTemplates() {
this("", "", "", "", "", "", "", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,15 @@
import java.util.Optional;

/** An individual PDF, all a part of the same "document". The equivalent of an ALDocument. */
public class FilingAttachment {
private final FilingComponent filingComponentCode;
// For the setBinaryDescriptionText
private final String documentDescription;
private final String fileName;
private final byte[] fileContents;
// This is, "determined via configuration within the EFM for each EFSP"?
// So, we can just say yes?
// Provides Document Type code / BinaryFormatStandardName
private final Optional<DocumentTypeTableRow> documentTypeFormatStandardName;

// page count?

public FilingAttachment(
String fileName,
byte[] fileStream,
Optional<DocumentTypeTableRow> documentTypeFormatStandardName,
FilingComponent filingComponentCode,
String documentDescription) {
this.filingComponentCode = filingComponentCode;
this.fileName = fileName;
this.documentTypeFormatStandardName = documentTypeFormatStandardName;
this.documentDescription = documentDescription;
this.fileContents = fileStream;
}

public byte[] getFileContents() {
return fileContents;
}

public String getFileName() {
return fileName;
}

public FilingComponent getFilingComponent() {
return filingComponentCode;
}

public Optional<DocumentTypeTableRow> getDocumentTypeFormatStandardName() {
return documentTypeFormatStandardName;
}

/** The description of this document. Goes into BinaryDescriptionText for Tyler. */
public String getDocumentDescription() {
return documentDescription;
}
}
public record FilingAttachment(
FilingComponent filingComponentCode,
/** The description of this document. Goes into BinaryDescriptionText for Tyler. */
String documentDescription,
String fileName,
byte[] fileContents,
// This is, "determined via configuration within the EFM for each EFSP"?
// So, we can just say yes?
// Provides Document Type code / BinaryFormatStandardName
Optional<DocumentTypeTableRow> documentTypeFormatStandardName,
// If present, we've pre-counted the pages, if not, will have to count them later.
Optional<Integer> pageCount) {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import java.util.UUID;
import org.apache.commons.lang3.builder.ToStringBuilder;

// TODO(brycew-later): this class is a mess. Refactor, considering the same pattern that's in
// FilingInformation: add a JsonNode / generic container for EFM specific settings
// TODO(brycew-later): this class is a mess. Refactor
public class FilingDoc {
private final Optional<NonEmptyString> userProvidedDescription;
// Tyler has crazy dumb rules regarding the title of a doc; it's set here
Expand Down Expand Up @@ -107,7 +106,7 @@ public FilingDoc(
public int allAttachmentsLength() {
int length = 0;
for (var attachment : filingAttachments) {
length += attachment.getFileContents().length;
length += attachment.fileContents().length;
}
return length;
}
Expand Down
Loading
Loading