This is an automated email from the ASF dual-hosted git repository.
mridulpathak pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release24.09 by this push:
new b0ef62cda2 Fixed: PDF survey services fail to store answers and throw
a NullPointerException when no PDF is given (OFBIZ-13688)
b0ef62cda2 is described below
commit b0ef62cda2bb2f3aa7bbee91de8bb1b2537ae35e
Author: Mridul Pathak <[email protected]>
AuthorDate: Fri Oct 16 13:25:45 2026 +0530
Fixed: PDF survey services fail to store answers and throw a
NullPointerException when no PDF is given (OFBIZ-13688)
- buildSurveyResponseFromPdf created SurveyResponseAnswer without
surveyMultiRespColId, which is part of the primary key, so building a survey
response from a PDF failed on the first answer and rolled back. It now sets it
to _NA_ like the regular survey service, and updates the existing answers when
it runs again for the same survey response.
- When no PDF was given, buildSurveyFromPdf, buildSurveyResponseFromPdf,
getAcroFieldsFromPdf and setAcroFields threw a NullPointerException. They now
return an error with the new ContentPDFInputMissing label.
---
applications/content/config/ContentUiLabels.xml | 3 +++
.../ofbiz/content/survey/PdfSurveyServices.java | 19 +++++++++++++++++--
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/applications/content/config/ContentUiLabels.xml
b/applications/content/config/ContentUiLabels.xml
index c3e02181e6..3aceaf1e91 100644
--- a/applications/content/config/ContentUiLabels.xml
+++ b/applications/content/config/ContentUiLabels.xml
@@ -1889,6 +1889,9 @@
<value xml:lang="zh">生成PDF时出错:${errorString}</value>
<value xml:lang="zh-TW">產生PDF時出錯:${errorString}</value>
</property>
+ <property key="ContentPDFInputMissing">
+ <value xml:lang="en">No PDF was given.</value>
+ </property>
<property key="ContentPDFSurveyName">
<value xml:lang="da">Rundspørge navn</value>
<value xml:lang="en">PDF/Survey Name</value>
diff --git
a/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java
b/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java
index ab6872cfa4..b67c7c3843 100644
---
a/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java
+++
b/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java
@@ -85,6 +85,9 @@ public class PdfSurveyServices {
String surveyName = (String) context.get("surveyName");
ByteArrayOutputStream os = new ByteArrayOutputStream();
ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
+ if (byteBuffer == null) {
+ return
ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE,
"ContentPDFInputMissing", locale));
+ }
PdfReader pdfReader = new PdfReader(byteBuffer.array());
PdfStamper pdfStamper = new PdfStamper(pdfReader, os);
AcroFields acroFields = pdfStamper.getAcroFields();
@@ -251,6 +254,9 @@ public class PdfSurveyServices {
ByteArrayOutputStream os = new ByteArrayOutputStream();
ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
+ if (byteBuffer == null) {
+ return
ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE,
"ContentPDFInputMissing", locale));
+ }
PdfReader r = new PdfReader(byteBuffer.array());
PdfStamper s = new PdfStamper(r, os);
AcroFields fs = s.getAcroFields();
@@ -270,12 +276,13 @@ public class PdfSurveyServices {
String surveyQuestionId = (String)
surveyQuestionAndAppl.get("surveyQuestionId");
String surveyQuestionTypeId = (String)
surveyQuestionAndAppl.get("surveyQuestionTypeId");
GenericValue surveyResponseAnswer =
delegator.makeValue("SurveyResponseAnswer",
- UtilMisc.toMap("surveyResponseId", surveyResponseId,
"surveyQuestionId", surveyQuestionId));
+ UtilMisc.toMap("surveyResponseId", surveyResponseId,
"surveyQuestionId", surveyQuestionId,
+ "surveyMultiRespColId", "_NA_"));
if (surveyQuestionTypeId == null ||
"TEXT_SHORT".equals(surveyQuestionTypeId)) {
surveyResponseAnswer.set("textResponse", value);
}
- delegator.create(surveyResponseAnswer);
+ delegator.createOrStore(surveyResponseAnswer);
}
s.close();
} catch (GeneralException | DocumentException | IOException e) {
@@ -296,7 +303,11 @@ public class PdfSurveyServices {
Map<String, Object> acroFieldMap = new HashMap<>();
ByteArrayOutputStream os = new ByteArrayOutputStream();
Delegator delegator = dctx.getDelegator();
+ Locale locale = (Locale) context.get("locale");
ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
+ if (byteBuffer == null) {
+ return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE,
"ContentPDFInputMissing", locale));
+ }
try (PdfReader r = new PdfReader(byteBuffer.array());
PdfStamper s = new PdfStamper(r, os)) {
AcroFields fs = s.getAcroFields();
@@ -323,9 +334,13 @@ public class PdfSurveyServices {
public static Map<String, Object> setAcroFields(DispatchContext dctx,
Map<String, ? extends Object> context) {
Map<String, Object> results = ServiceUtil.returnSuccess();
Delegator delegator = dctx.getDelegator();
+ Locale locale = (Locale) context.get("locale");
try {
Map<String, Object> acroFieldMap =
UtilGenerics.cast(context.get("acroFieldMap"));
ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
+ if (byteBuffer == null) {
+ return
ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE,
"ContentPDFInputMissing", locale));
+ }
PdfReader r = new PdfReader(byteBuffer.array());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper s = new PdfStamper(r, baos);