Skip to content

Commit e7d4d99

Browse files
More Ecf4 XML helpers
Fixed a quick bug with `getNonEmptyText`
1 parent e053744 commit e7d4d99

3 files changed

Lines changed: 68 additions & 46 deletions

File tree

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

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package edu.suffolk.litlab.efsp.server.ecf4;
22

3+
import com.hubspot.algebra.Result;
34
import edu.suffolk.litlab.efsp.server.utils.ServiceHelpers;
45
import edu.suffolk.litlab.efsp.tyler.TylerErrorCodes;
56
import gov.niem.niem.domains.jxdm._4.CourtType;
7+
import gov.niem.niem.fips_10_4._2.CountryCodeSimpleType;
8+
import gov.niem.niem.fips_10_4._2.CountryCodeType;
69
import gov.niem.niem.niem_core._2.DateType;
710
import gov.niem.niem.niem_core._2.EntityType;
811
import gov.niem.niem.niem_core._2.MeasureType;
912
import gov.niem.niem.niem_core._2.TextType;
13+
import gov.niem.niem.proxy.xsd._2.Decimal;
1014
import jakarta.ws.rs.core.Response;
1115
import jakarta.xml.bind.JAXBContext;
1216
import jakarta.xml.bind.JAXBElement;
1317
import jakarta.xml.bind.JAXBException;
1418
import jakarta.xml.bind.Marshaller;
1519
import java.io.File;
1620
import java.io.StringWriter;
21+
import java.math.BigDecimal;
1722
import java.time.LocalDate;
1823
import java.util.GregorianCalendar;
1924
import java.util.List;
@@ -60,8 +65,6 @@ public class Ecf4Helper {
6065
try {
6166
datatypeFac = DatatypeFactory.newInstance();
6267
} catch (DatatypeConfigurationException e) {
63-
// TODO Auto-generated catch block
64-
e.printStackTrace();
6568
throw new RuntimeException(e);
6669
}
6770
}
@@ -90,6 +93,13 @@ public static gov.niem.niem.proxy.xsd._2.Boolean convertBool(boolean bool) {
9093
return val;
9194
}
9295

96+
public static Optional<String> getNonEmptyText(TextType text) {
97+
if (text != null && text.getValue() != null && !text.getValue().isBlank()) {
98+
return Optional.of(text.getValue());
99+
}
100+
return Optional.empty();
101+
}
102+
93103
/**
94104
* Converts a Java string to NIEM "Text", a wrapper around the NIEM String.
95105
*
@@ -146,6 +156,25 @@ public static gov.niem.niem.niem_core._2.IdentificationType convertId(
146156
return id;
147157
}
148158

159+
public static Decimal convertDecimal(BigDecimal deci) {
160+
Decimal xml = new Decimal();
161+
xml.setValue(deci);
162+
return xml;
163+
}
164+
165+
/**
166+
* Convert an int to a BigDecimal to an XML Decimal
167+
*
168+
* <p>Weird conversion, but the multiplier on optional services is a Decimal for some reason? "I
169+
* need 2.3 copies of this sent to my office", lmao.
170+
*
171+
* @param val
172+
* @return
173+
*/
174+
public static Decimal convertDecimal(int val) {
175+
return convertDecimal(new BigDecimal(val));
176+
}
177+
149178
/** Converts a Java string to a URI. */
150179
public static gov.niem.niem.proxy.xsd._2.AnyURI convertUri(String uri) {
151180
gov.niem.niem.proxy.xsd._2.AnyURI anyUri = niemProxyObjFac.createAnyURI();
@@ -253,6 +282,19 @@ public static <T> void objectToXmlFile(T toXml, Class<T> toXmlClazz, File outfil
253282
mar.marshal(pp, outfile);
254283
}
255284

285+
/** Turn a given string into a country type. */
286+
public static Result<CountryCodeType, IllegalArgumentException> strToCountryCode(String country) {
287+
CountryCodeType cct = new CountryCodeType();
288+
try {
289+
// Trigger an illegal argument exception if not valid
290+
CountryCodeSimpleType.fromValue(country);
291+
cct.setValue(country);
292+
return Result.ok(cct);
293+
} catch (IllegalArgumentException ex) {
294+
return Result.err(ex);
295+
}
296+
}
297+
256298
public static <T extends QueryMessageType> T prep(T newMsg, String courtId) {
257299
EntityType typ = new EntityType();
258300
var commonObjFac =

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

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import edu.suffolk.litlab.efsp.model.PartyId;
2828
import edu.suffolk.litlab.efsp.model.Person;
2929
import edu.suffolk.litlab.efsp.stdlib.NonEmptyString;
30-
import edu.suffolk.litlab.efsp.utils.FailFastCollector;
3130
import edu.suffolk.litlab.efsp.utils.FilingError;
3231
import edu.suffolk.litlab.efsp.utils.InfoCollector;
3332
import edu.suffolk.litlab.efsp.utils.InterviewVariable;
@@ -50,7 +49,6 @@
5049
import gov.niem.niem.niem_core._2.TelephoneNumberType;
5150
import gov.niem.niem.niem_core._2.TextType;
5251
import gov.niem.niem.proxy.xsd._2.Base64Binary;
53-
import gov.niem.niem.proxy.xsd._2.Decimal;
5452
import gov.niem.niem.usps_states._2.USStateCodeSimpleType;
5553
import gov.niem.niem.usps_states._2.USStateCodeType;
5654
import jakarta.xml.bind.JAXBElement;
@@ -562,10 +560,9 @@ public static tyler.efm.latest.services.schema.common.AddressType serializeTyler
562560
addr.setAddressLine1(myAddr.getStreet());
563561
addr.setAddressLine2(myAddr.getApartment());
564562
addr.setCity(myAddr.getCity());
565-
FailFastCollector collector = new FailFastCollector();
566-
Optional<CountryCodeType> cct = strToCountryCode(myAddr.getCountry(), collector);
567-
if (cct.isEmpty()) {
568-
throw FilingError.serverError("Country Code is wrong");
563+
var cct = Ecf4Helper.strToCountryCode(myAddr.getCountry());
564+
if (cct.isErr()) {
565+
throw FilingError.serverError("Country Code is wrong: " + myAddr.getCountry());
569566
}
570567
addr.setState(myAddr.getState());
571568
addr.setZipCode(myAddr.getZip());
@@ -587,8 +584,8 @@ public JAXBElement<AddressType> serializeNiemContactMeans(
587584
ProperNameTextType pntt = niemObjFac.createProperNameTextType();
588585
pntt.setValue(address.getCity());
589586
sat.setLocationCityName(pntt);
590-
Optional<CountryCodeType> cct = strToCountryCode(address.getCountry(), collector);
591-
if (cct.isEmpty()) {
587+
var cctResult = Ecf4Helper.strToCountryCode(address.getCountry());
588+
if (cctResult.isErr()) {
592589
List<String> countries =
593590
Arrays.stream(CountryCodeSimpleType.values())
594591
.map((t) -> t.toString())
@@ -602,9 +599,10 @@ public JAXBElement<AddressType> serializeNiemContactMeans(
602599
Optional.of(address.getCountry()));
603600
collector.addWrong(var);
604601
}
605-
sat.setLocationCountry(niemObjFac.createLocationCountryFIPS104Code(cct.get()));
606-
if (!fillStateCode(address.getState(), cct.get(), sat)) {
607-
String countryString = cct.get().getValue();
602+
CountryCodeType cct = cctResult.unwrapOrElseThrow();
603+
sat.setLocationCountry(niemObjFac.createLocationCountryFIPS104Code(cct));
604+
if (!fillStateCode(address.getState(), cct, sat)) {
605+
String countryString = cct.getValue();
608606
List<String> stateCodes = cd.getStateCodes(this.court.code, countryString);
609607
InterviewVariable var =
610608
collector.requestVar(
@@ -914,9 +912,7 @@ public JAXBElement<DocumentType> filingDocToXml(
914912
if (serv.feeAmount.isEmpty()) {
915913
collector.addWrong(servVar.appendDesc(": needs fee prompt"));
916914
} else {
917-
Decimal dec = new Decimal();
918-
dec.setValue(serv.feeAmount.get());
919-
xmlServ.setFeeAmount(dec);
915+
xmlServ.setFeeAmount(Ecf4Helper.convertDecimal(serv.feeAmount.get()));
920916
}
921917
}
922918
if (!codeSettings.hasfeeprompt && serv.feeAmount.isPresent()) {
@@ -926,9 +922,7 @@ public JAXBElement<DocumentType> filingDocToXml(
926922
if (serv.multiplier.isEmpty()) {
927923
collector.addWrong(servVar.appendDesc(": needs multiplier"));
928924
} else {
929-
Decimal dec = new Decimal();
930-
dec.setValue(new BigDecimal(serv.multiplier.get()));
931-
xmlServ.setMultiplier(dec);
925+
xmlServ.setMultiplier(Ecf4Helper.convertDecimal(serv.multiplier.get()));
932926
}
933927
}
934928
docType.getDocumentOptionalService().add(xmlServ);
@@ -1170,14 +1164,6 @@ private String findDocumentDescription(
11701164
}
11711165
}
11721166

1173-
// TODO(brycew): don't need the Optional anyy more
1174-
private static Optional<CountryCodeType> strToCountryCode(
1175-
String country, InfoCollector collector) {
1176-
CountryCodeType cct = new CountryCodeType();
1177-
cct.setValue(country);
1178-
return Optional.of(cct);
1179-
}
1180-
11811167
/** True if it worked. */
11821168
private boolean fillStateCode(String state, CountryCodeType country, StructuredAddressType sat) {
11831169
String countryString = country.getValue().toString();

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,11 @@ private static String documentToStr(ReviewedDocumentType doc, CourtLocationInfo
102102
}
103103
StringBuilder docText = new StringBuilder();
104104
if (doc instanceof tyler.ecf.extensions.common.ReviewedDocumentType tylerDoc) {
105-
if (tylerDoc.getDocumentDescriptionText() != null
106-
&& tylerDoc.getDocumentDescriptionText().getValue() != null
107-
&& tylerDoc.getDocumentDescriptionText().getValue().isBlank()) {
108-
docText
109-
.append("The document (")
110-
.append(tylerDoc.getDocumentDescriptionText().getValue())
111-
.append(") ");
112-
}
105+
var description = Ecf4Helper.getNonEmptyText(tylerDoc.getDocumentDescriptionText());
106+
description.ifPresent(
107+
desc -> {
108+
docText.append("The document (").append(desc).append(") ");
109+
});
113110
if (tylerDoc.getDocumentBinary() != null
114111
&& tylerDoc.getDocumentBinary().getBinaryDescriptionText() != null) {
115112
docText
@@ -126,23 +123,20 @@ private static String documentToStr(ReviewedDocumentType doc, CourtLocationInfo
126123
}
127124
}
128125

129-
if (tylerDoc.getFilingReviewCommentsText() != null
130-
&& tylerDoc.getFilingReviewCommentsText().getValue() != null
131-
&& !tylerDoc.getFilingReviewCommentsText().getValue().isBlank()) {
132-
docText
133-
.append(" has the following review comments: ")
134-
.append(tylerDoc.getFilingReviewCommentsText().getValue());
135-
}
126+
var maybeComments = Ecf4Helper.getNonEmptyText(tylerDoc.getFilingReviewCommentsText());
127+
maybeComments.ifPresent(
128+
comments -> {
129+
docText.append(" has the following review comments: ").append(comments);
130+
});
136131

137-
if (tylerDoc.getRejectReasonText() != null
138-
&& tylerDoc.getRejectReasonText().getValue() != null
139-
&& !tylerDoc.getRejectReasonText().getValue().isBlank()) {
132+
var maybeRejectText = Ecf4Helper.getNonEmptyText(tylerDoc.getRejectReasonText());
133+
if (maybeRejectText.isPresent()) {
140134
if (courtInfo.showreturnonreject) {
141135
docText.append(", was returned for the following reason: ");
142136
} else {
143137
docText.append(", was rejected for the following reason: ");
144138
}
145-
docText.append(tylerDoc.getRejectReasonText().getValue());
139+
docText.append(maybeRejectText.get());
146140
}
147141
} else {
148142
docText.append("The review was about the document ");

0 commit comments

Comments
 (0)