Skip to content

Commit 0e9d54d

Browse files
Fix prod bug with spaces on the end of phone numbers (#336)
A regex for the MA Appeals court was failing on a phone number because one of the two possible numbers from a user had a space at the end that wasn't stripped. Fixed in a few regards: * adds the regex to the end of the error description (would have saved me a bit of time when triaging) * strips spaces off the end of the phone number if it doesn't pass the regex the first time * if at least one number that the user gives is valid, use it, and just discard the others. Related to the recent production alerts.
1 parent a1e8c4e commit 0e9d54d

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/ecf4/EcfCourtSpecificSerializer.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,18 +514,23 @@ public ContactInformationType serializeEcfContactInformation(
514514
List<String> numbers = contactInfo.getPhoneNumbers();
515515
InterviewVariable var =
516516
collector.requestVar(
517-
"phone_number", "Phone number", "text", List.of(), Optional.of(numbers.toString()));
517+
"phone_number",
518+
"Phone number with regex: " + phoneRow.regularexpression,
519+
"text",
520+
List.of(),
521+
Optional.of(numbers.toString()));
518522
if (phoneRow.isrequired && numbers.isEmpty()) {
519523
collector.addRequired(var);
520524
}
521-
for (String phoneNumber : contactInfo.getPhoneNumbers()) {
525+
boolean atLeastOnePhoneAdded = false;
526+
for (String phoneNumber : numbers) {
522527
if (!phoneRow.matchRegex(phoneNumber)) {
523528
if (phoneNumber.contains("-")) {
524529
// HACK(brycew): Massachusetts doesn't like dashes in the number, just numbers
525-
phoneNumber = phoneNumber.replace("-", "").replace("(", "").replace(")", "");
530+
phoneNumber = phoneNumber.replace("-", "").replace("(", "").replace(")", "").strip();
526531
}
527532
if (!phoneRow.matchRegex(phoneNumber)) {
528-
collector.addWrong(var);
533+
continue;
529534
}
530535
}
531536

@@ -534,6 +539,10 @@ public ContactInformationType serializeEcfContactInformation(
534539
ftnt.setTelephoneNumberFullID(Ecf4Helper.convertString(phoneNumber));
535540
tnt.setTelephoneNumberRepresentation(niemObjFac.createFullTelephoneNumber(ftnt));
536541
cit.getContactMeans().add(niemObjFac.createContactTelephoneNumber(tnt));
542+
atLeastOnePhoneAdded = true;
543+
}
544+
if (!numbers.isEmpty() && !atLeastOnePhoneAdded) {
545+
collector.addWrong(var);
537546
}
538547
}
539548

proxyserver/src/test/java/edu/suffolk/litlab/efsp/server/ecf4/EcfCourtSpecificSerializerTest.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package edu.suffolk.litlab.efsp.server.ecf4;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
34
import static org.junit.jupiter.api.Assertions.assertEquals;
45
import static org.junit.jupiter.api.Assertions.assertTrue;
56
import static org.junit.jupiter.api.Assertions.fail;
6-
import static org.mockito.Mockito.eq;
7+
import static org.mockito.ArgumentMatchers.eq;
78
import static org.mockito.Mockito.mock;
89
import static org.mockito.Mockito.when;
910

@@ -25,6 +26,7 @@
2526
import edu.suffolk.litlab.efsp.model.ContactInformation;
2627
import edu.suffolk.litlab.efsp.model.Name;
2728
import edu.suffolk.litlab.efsp.model.Person;
29+
import edu.suffolk.litlab.efsp.utils.AllWrongCollector;
2830
import edu.suffolk.litlab.efsp.utils.FailFastCollector;
2931
import edu.suffolk.litlab.efsp.utils.FilingError;
3032
import edu.suffolk.litlab.efsp.utils.InfoCollector;
@@ -81,6 +83,20 @@ public void setUp() {
8183
"",
8284
"",
8385
false,
86+
""),
87+
"PartyPhone",
88+
new DataFieldRow(
89+
"PartyPhone",
90+
"Party Phone",
91+
true,
92+
false,
93+
"",
94+
"",
95+
"",
96+
"Do not use hyphens or other characters--just numbers",
97+
"^(\\+0?1\\s)?\\(?\\d{3}\\)?\\d{3}\\d{4}$",
98+
"",
99+
false,
84100
"")))));
85101
collector = new FailFastCollector();
86102
}
@@ -163,6 +179,22 @@ public void shouldBeEmptyPersonIfIsUser() throws FilingError, JAXBException {
163179
Ecf4Helper.objectToXmlStr(cptPer, CaseParticipantType.class);
164180
}
165181

182+
@Test
183+
public void shouldAllowAtLeastOnePhone() throws FilingError {
184+
collector = new AllWrongCollector();
185+
ContactInformation info =
186+
new ContactInformation(
187+
List.of("1234567890", "123-456-7890 ", "123-abc"),
188+
Optional.empty(),
189+
Optional.of("bob@example.com"));
190+
CourtLocationInfo loc = new CourtLocationInfo();
191+
loc.code = "not_real";
192+
EcfCourtSpecificSerializer courtSer = new EcfCourtSpecificSerializer(cd, loc);
193+
var contactInfoType = courtSer.serializeEcfContactInformation(info, collector);
194+
assertThat(contactInfoType.getContactMeans()).hasSize(2);
195+
assertThat(collector.getWrong()).hasSize(0);
196+
}
197+
166198
@Test
167199
public void shouldThrowIfRequiredButNotPresent() {
168200
CourtLocationInfo loc = new CourtLocationInfo();

0 commit comments

Comments
 (0)