Skip to content

Commit ce2a8bf

Browse files
committed
🐛 Fix failures discovered discovered during integration testing
Server checks the template content type, should be XDP or PDF. Import can return nothing, we were throwing error, but should return empty document so that it can later be turned back into empty Optional.
1 parent ee2d27b commit ce2a8bf

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

rest-services/client/src/main/java/com/_4point/aem/docservices/rest_services/client/RestClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ default <T> Builder transformAndAddDocs(String fieldName, T fieldData, Function<
145145
return fieldData != null ? addDocsIfNotNull(fieldName, fn.apply(fieldData)) : this;
146146
}
147147
default Builder addStringVersion(String fieldName, List<?> fieldData) {
148-
for (Object obj : fieldData) {
149-
addStringVersion(fieldName, obj);
148+
if (fieldData != null) {
149+
for (Object obj : fieldData) {
150+
addStringVersion(fieldName, obj);
151+
}
150152
}
151153
return this;
152154
}

rest-services/client/src/main/java/com/_4point/aem/docservices/rest_services/client/forms/RestServicesFormsServiceAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com._4point.aem.fluentforms.api.forms.PDFFormRenderOptions;
1919
import com._4point.aem.fluentforms.api.forms.ValidationOptions;
2020
import com._4point.aem.fluentforms.api.forms.ValidationResult;
21+
import com._4point.aem.fluentforms.impl.SimpleDocumentFactoryImpl;
2122
import com._4point.aem.fluentforms.impl.forms.TraditionalFormsService;
2223
import com.adobe.fd.forms.api.DataFormat;
2324

@@ -67,7 +68,7 @@ public Document exportData(Document pdfOrXdp, DataFormat dataFormat) throws Form
6768

6869
return payload.postToServer(ContentType.APPLICATION_XML)
6970
.map(RestServicesServiceAdapter::responseToDoc)
70-
.orElseThrow();
71+
.orElse(SimpleDocumentFactoryImpl.emptyDocument()); // If there was no response, return an empty document.
7172
} catch (IOException e) {
7273
throw new FormsServiceException("I/O Error while exporting data. (" + exportDataRestClient.target() + ").", e);
7374
} catch (RestClientException e) {
@@ -101,7 +102,7 @@ private Document internalRenderPDFForm(String urlOrfilename, Document template,
101102
var xci = pdfFormRenderOptions.getXci();
102103
try (MultipartPayload payload = renderFormRestClient.multipartPayloadBuilder()
103104
.addIfNotNull(TEMPLATE_PARAM, urlOrfilename) // Since this is internal, we know that one of these two will be null
104-
.addIfNotNull(TEMPLATE_PARAM, template, ContentType.APPLICATION_XML)
105+
.addIfNotNull(TEMPLATE_PARAM, template, ContentType.APPLICATION_XDP)
105106
.addIfNotNull(DATA_PARAM, data, ContentType.APPLICATION_XML)
106107
.addStringVersion(ACROBAT_VERSION_PARAM, pdfFormRenderOptions.getAcrobatVersion())
107108
.addStringVersion(CACHE_STRATEGY_PARAM, pdfFormRenderOptions.getCacheStrategy())

rest-services/client/src/test/java/com/_4point/aem/docservices/rest_services/client/forms/RestServicesFormsServiceAdapterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void testRenderPDFForm_HappyPaths(RenderFormsHappyPath codePath) throws Exceptio
176176
PDFFormRenderOptions pdfFormRenderOptions = codePath.emptyOptions ? new PDFFormRenderOptionsImpl() : getNonDefaultPdfRenderOptions();
177177

178178
when(mockPayloadBuilder.addIfNotNull(eq("template"), codePath.templateString ? eq(templateFilename) : isNull())).thenReturn(mockPayloadBuilder);
179-
when(mockPayloadBuilder.addIfNotNull(eq("template"), codePath.templateString ? isNull() : same(templateDoc), eq(ContentType.APPLICATION_XML))).thenReturn(mockPayloadBuilder);
179+
when(mockPayloadBuilder.addIfNotNull(eq("template"), codePath.templateString ? isNull() : same(templateDoc), eq(ContentType.APPLICATION_XDP))).thenReturn(mockPayloadBuilder);
180180
when(mockPayloadBuilder.addIfNotNull(eq("data"), codePath.hasData ? same(data) : isNull(), eq(ContentType.APPLICATION_XML))).thenReturn(mockPayloadBuilder);
181181
when(mockPayloadBuilder.addStringVersion(eq("renderOptions.acrobatVersion"), eq(pdfFormRenderOptions.getAcrobatVersion()))).thenReturn(mockPayloadBuilder);
182182
when(mockPayloadBuilder.addStringVersion(eq("renderOptions.cacheStrategy"), eq(pdfFormRenderOptions.getCacheStrategy()))).thenReturn(mockPayloadBuilder);

0 commit comments

Comments
 (0)