diff --git a/docs/rest_guide.md b/docs/rest_guide.md index e9a1cd9b1..ca6ee858c 100644 --- a/docs/rest_guide.md +++ b/docs/rest_guide.md @@ -192,7 +192,7 @@ These three endpoints each deal with the same large request payload: the entire "comments_to_clerk": "I worked with clerk John Brown to complete this at the law library.", "tyler_payment_id": "12345678-1234-1234-1234-12345678abcd", // retrieved from .../payments/payment-accounts "lead_contact": { - // same as users / other_parties + // same as users / other_parties. Not required if users[0].is_form_filler is true "email": "cool_dude1@example.com", // email is required }, "return_date": "YYYY-MM-DD+01:00", diff --git a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/docassemble/FilingInformationDocassembleJacksonDeserializer.java b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/docassemble/FilingInformationDocassembleJacksonDeserializer.java index 7e6a778c0..eb75185b5 100644 --- a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/docassemble/FilingInformationDocassembleJacksonDeserializer.java +++ b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/docassemble/FilingInformationDocassembleJacksonDeserializer.java @@ -336,34 +336,48 @@ public FilingInformation fromNode(JsonNode node, InfoCollector collector) throws entities.setPaymentId(extractNullableString(node.get("tyler_payment_id"))); - JsonNode leadJson = node.get("lead_contact"); - if (leadJson == null) { - InterviewVariable var = - collector.requestVar( - "lead_contact", "Someone to contact about this case", "ALIndividual"); - collector.addRequired(var); + if (users.size() >= 1 + && users.get(0).isFormFiller() + && users.get(0).getContactInfo().getEmail().isPresent()) { + log.info( + "Using users[0] as lead_contact because `is_form_filler` is true (this is what the EFM will do as well)"); + entities.setLeadContact(users.get(0)); } else { - collector.pushAttributeStack("lead_contact"); - Result per = - PersonDocassembleJacksonDeserializer.fromNode( - node.get("lead_contact"), parser, collector); - collector.popAttributeStack(); - if (per.isErr()) { - FilingError ex = per.unwrapErrOrElseThrow(); - log.warn("Person exception: ", ex); - collector.error(ex); - entities.setLeadContact(null); + if (users.size() >= 1 + && users.get(0).isFormFiller() + && users.get(0).getContactInfo().getEmail().isEmpty()) { + log.warn( + "I want to use users[0] as lead_contact, but they don't have an email! Using lead_contact instead"); + } + JsonNode leadJson = node.get("lead_contact"); + if (leadJson == null) { + InterviewVariable var = + collector.requestVar( + "lead_contact", "Someone to contact about this case", "ALIndividual"); + collector.addRequired(var); } else { - Person person = per.unwrapOrElseThrow(); - if (person.getContactInfo().getEmail().isEmpty()) { - InterviewVariable var = - collector.requestVar( - "lead_contact.email", - "We need an email to contact someone about this case.", - "text"); - collector.addRequired(var); + collector.pushAttributeStack("lead_contact"); + Result per = + PersonDocassembleJacksonDeserializer.fromNode( + node.get("lead_contact"), parser, collector); + collector.popAttributeStack(); + if (per.isErr()) { + FilingError ex = per.unwrapErrOrElseThrow(); + log.warn("Person exception: ", ex); + collector.error(ex); + entities.setLeadContact(null); + } else { + Person person = per.unwrapOrElseThrow(); + if (person.getContactInfo().getEmail().isEmpty()) { + InterviewVariable var = + collector.requestVar( + "lead_contact.email", + "We need an email to contact someone about this case.", + "text"); + collector.addRequired(var); + } + entities.setLeadContact(person); } - entities.setLeadContact(person); } } diff --git a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/TylerCodesParser.java b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/TylerCodesParser.java index e7e7d98be..419764f8c 100644 --- a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/TylerCodesParser.java +++ b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/TylerCodesParser.java @@ -726,6 +726,9 @@ public Result, TextVarError> vetEmail(Optional email) { if (!emailRow.matchRegex(email.get())) { return Result.err(new WrongVar(email.get(), emailRow.regularexpression)); } + if (email.get().isBlank()) { + return Result.ok(Optional.empty()); + } } else if (emailRow.isrequired) { return Result.err(new MissingVar(emailRow.regularexpression)); }