[OFBiz] SVN: r6846 - in trunk/applications/content: src/org/ofbiz/content/survey widget/compdoc
byersa@svn.ofbiz.org
byersa at svn.ofbiz.org
Sat Feb 25 14:54:20 CST 2006
Author: byersa
Date: 2006-02-25 14:54:13 -0600 (Sat, 25 Feb 2006)
New Revision: 6846
Modified:
trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
trunk/applications/content/widget/compdoc/CompDocForms.xml
trunk/applications/content/widget/compdoc/CompDocMenus.xml
trunk/applications/content/widget/compdoc/CompDocScreens.xml
Log:
Fixes a cause of the mimeType being set to survey, when it should be survey.response.
Modified: trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java 2006-02-25 01:59:42 UTC (rev 6845)
+++ trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java 2006-02-25 20:54:13 UTC (rev 6846)
@@ -26,6 +26,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream;
@@ -39,11 +40,14 @@
import java.util.Map;
import java.util.HashMap;
import java.util.StringTokenizer;
+import java.util.Locale;
+
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.content.data.DataResourceWorker;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
@@ -54,7 +58,9 @@
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.service.ModelService;
import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.base.util.GeneralException;
import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.PdfStamper;
@@ -277,53 +283,54 @@
*/
public static Map setAcroFields(DispatchContext dctx, Map context) {
- Map results = ServiceUtil.returnSuccess();
- try {
- String pdfFileNameIn = (String)context.get("pdfFileNameIn");
- Map acroFieldMap = (Map)context.get("acroFieldMap");
- String pdfFileNameOut = (String)context.get("pdfFileNameOut");
- if (pdfFileNameOut == null) {
- pdfFileNameOut = pdfFileNameIn;
- }
- File fileOut = new File(pdfFileNameOut);
- FileOutputStream os = new FileOutputStream(fileOut);
- PdfReader r = new PdfReader(pdfFileNameIn);
- PdfStamper s = new PdfStamper(r,os);
- AcroFields fs = s.getAcroFields();
- Map map = fs.getFields();
-
- s.setFormFlattening(true);
-
- // Debug code to get the values for setting TDP
- // String[] sa = fs.getAppearanceStates("TDP");
- // for (int i=0;i<sa.length;i++)
- // Debug.log("Appearance="+sa[i]);
- Iterator iter = map.keySet().iterator();
- while (iter.hasNext()) {
- String fieldName=(String)iter.next();
- String fieldValue = fs.getField(fieldName);
- Object obj = acroFieldMap.get(fieldName);
- if (obj instanceof Date) {
- Date d=(Date)obj;
- fieldValue=UtilDateTime.toDateString(d);
- } else if (obj instanceof Long) {
- Long lg=(Long)obj;
- fieldValue=lg.toString();
- } else if (obj instanceof Integer) {
- Integer ii=(Integer)obj;
- fieldValue=ii.toString();
- } else {
- fieldValue=(String)obj;
- }
-
- if (UtilValidate.isNotEmpty(fieldValue))
- fs.setField(fieldName, fieldValue);
- }
+ Map results = ServiceUtil.returnSuccess();
+ GenericDelegator delegator = dctx.getDelegator();
+ try {
+ Map acroFieldMap = (Map)context.get("acroFieldMap");
+ ByteWrapper byteWrapper = getInputByteWrapper(context, delegator);
+ PdfReader r = new PdfReader(byteWrapper.getBytes());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PdfStamper s = new PdfStamper(r, baos);
+ AcroFields fs = s.getAcroFields();
+ Map map = fs.getFields();
+
+ s.setFormFlattening(true);
+
+ // Debug code to get the values for setting TDP
+ // String[] sa = fs.getAppearanceStates("TDP");
+ // for (int i=0;i<sa.length;i++)
+ // Debug.log("Appearance="+sa[i]);
+ Iterator iter = map.keySet().iterator();
+ while (iter.hasNext()) {
+ String fieldName=(String)iter.next();
+ String fieldValue = fs.getField(fieldName);
+ Object obj = acroFieldMap.get(fieldName);
+ if (obj instanceof Date) {
+ Date d=(Date)obj;
+ fieldValue=UtilDateTime.toDateString(d);
+ } else if (obj instanceof Long) {
+ Long lg=(Long)obj;
+ fieldValue=lg.toString();
+ } else if (obj instanceof Integer) {
+ Integer ii=(Integer)obj;
+ fieldValue=ii.toString();
+ } else {
+ fieldValue=(String)obj;
+ }
+
+ if (UtilValidate.isNotEmpty(fieldValue))
+ fs.setField(fieldName, fieldValue);
+ }
s.close();
- os.close();
+ baos.close();
+ ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());
+ results.put("outByteWrapper", outByteWrapper);
} catch(DocumentException e) {
System.err.println(e.getMessage());
ServiceUtil.returnError(e.getMessage());
+ } catch(GeneralException e) {
+ System.err.println(e.getMessage());
+ ServiceUtil.returnError(e.getMessage());
} catch(FileNotFoundException e) {
System.err.println(e.getMessage());
ServiceUtil.returnError(e.getMessage());
@@ -332,9 +339,10 @@
ServiceUtil.returnError(ioe.getMessage());
}
- return results;
- }
+ return results;
+ }
+
/**
*/
public static Map setAcroFieldsFromSurveyResponse(DispatchContext dctx, Map context) {
@@ -342,60 +350,109 @@
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
Map results = ServiceUtil.returnSuccess();
- String pdfFileNameIn = (String)context.get("pdfFileNameIn");
- String surveyResponseId = (String)context.get("surveyResponseId");
- Map acroFieldMap = new HashMap();
- String pdfFileNameOut = (String)context.get("pdfFileNameOut");
- if (pdfFileNameOut == null) {
- pdfFileNameOut = pdfFileNameIn;
- }
-
- try {
- List responses = delegator.findByAnd("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId));
- Iterator iter = responses.iterator();
- while (iter.hasNext()) {
- String value = null;
- GenericValue surveyResponseAnswer = (GenericValue)iter.next();
- String surveyQuestionId = (String)surveyResponseAnswer.get("surveyQuestionId");
- GenericValue surveyQuestion = delegator.findByPrimaryKey("SurveyQuestion", UtilMisc.toMap("surveyQuestionId", surveyQuestionId));
- String questionType = surveyQuestion.getString("surveyQuestionTypeId");
- String fieldName = surveyQuestion.getString("description");
- if ("OPTION".equals(questionType)) {
- value = surveyResponseAnswer.getString("surveyOptionSeqId");
- } else if ("BOOLEAN".equals(questionType)) {
- value = surveyResponseAnswer.getString("booleanResponse");
- } else if ("NUMBER_LONG".equals(questionType)
- || "NUMBER_CURRENCY".equals(questionType)
- || "NUMBER_FLOAT".equals(questionType)
- ) {
- Double num = surveyResponseAnswer.getDouble("numericResponse");
- if (num != null) {
- value = num.toString();
- }
- } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {
- // not really a question; ingore completely
- } else {
- value = surveyResponseAnswer.getString("textResponse");
- }
- acroFieldMap.put(fieldName, value);
- }
- } catch (GenericEntityException e) {
- System.err.println(e.getMessage());
- ServiceUtil.returnError(e.getMessage());
- }
+ Map acroFieldMap = new HashMap();
+ String surveyResponseId = (String)context.get("surveyResponseId");
+
+ try {
+ List responses = delegator.findByAnd("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId));
+ Iterator iter = responses.iterator();
+ while (iter.hasNext()) {
+ String value = null;
+ GenericValue surveyResponseAnswer = (GenericValue)iter.next();
+ String surveyQuestionId = (String)surveyResponseAnswer.get("surveyQuestionId");
+ GenericValue surveyQuestion = delegator.findByPrimaryKey("SurveyQuestion", UtilMisc.toMap("surveyQuestionId", surveyQuestionId));
+ String questionType = surveyQuestion.getString("surveyQuestionTypeId");
+ String fieldName = surveyQuestion.getString("description");
+ if ("OPTION".equals(questionType)) {
+ value = surveyResponseAnswer.getString("surveyOptionSeqId");
+ } else if ("BOOLEAN".equals(questionType)) {
+ value = surveyResponseAnswer.getString("booleanResponse");
+ } else if ("NUMBER_LONG".equals(questionType)
+ || "NUMBER_CURRENCY".equals(questionType)
+ || "NUMBER_FLOAT".equals(questionType)
+ ) {
+ Double num = surveyResponseAnswer.getDouble("numericResponse");
+ if (num != null) {
+ value = num.toString();
+ }
+ } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {
+ // not really a question; ingore completely
+ } else {
+ value = surveyResponseAnswer.getString("textResponse");
+ }
+ acroFieldMap.put(fieldName, value);
+ }
+ } catch (GenericEntityException e) {
+ System.err.println(e.getMessage());
+ ServiceUtil.returnError(e.getMessage());
+ }
+
+ try {
+ ModelService modelService = dispatcher.getDispatchContext().getModelService("setAcroFields");
+ Map ctx = modelService.makeValid(context, "IN");
+ ctx.put("acroFieldMap", acroFieldMap);
+ Map map = dispatcher.runSync("setAcroFields", ctx);
+ if (ServiceUtil.isError(map)) {
+ String errMsg = ServiceUtil.makeErrorMessage(map, null, null, null, null);
+ System.err.println(errMsg);
+ ServiceUtil.returnError(errMsg);
+ }
+ String pdfFileNameOut = (String)context.get("pdfFileNameOut");
+ ByteWrapper outByteWrapper = (ByteWrapper)map.get("outByteWrapper");
+ if (UtilValidate.isNotEmpty("pdfFileNameOut")) {
+ FileOutputStream fos = new FileOutputStream("pdfFileNameOut");
+ fos.write(outByteWrapper.getBytes());
+ fos.close();
+ }
+ } catch(FileNotFoundException e) {
+ System.err.println(e.getMessage());
+ ServiceUtil.returnError(e.getMessage());
+ } catch(IOException e) {
+ System.err.println(e.getMessage());
+ ServiceUtil.returnError(e.getMessage());
+ } catch (GenericServiceException e) {
+ System.err.println(e.getMessage());
+ ServiceUtil.returnError(e.getMessage());
+ }
- try {
- Map map = dispatcher.runSync("setAcroFields", UtilMisc.toMap("pdfFileNameIn", pdfFileNameIn, "pdfFileNameOut", pdfFileNameOut, "acroFieldMap", acroFieldMap));
- if (ServiceUtil.isError(map)) {
- String errMsg = ServiceUtil.makeErrorMessage(map, null, null, null, null);
- System.err.println(errMsg);
- ServiceUtil.returnError(errMsg);
- }
- } catch (GenericServiceException e) {
- System.err.println(e.getMessage());
- ServiceUtil.returnError(e.getMessage());
- }
-
return results;
}
+
+ public static ByteWrapper getInputByteWrapper(Map context, GenericDelegator delegator) throws GeneralException {
+
+ ByteWrapper inputByteWrapper = (ByteWrapper)context.get("inputByteWrapper");
+
+ if (inputByteWrapper == null) {
+ String pdfFileNameIn = (String)context.get("pdfFileNameIn");
+ String contentId = (String)context.get("contentId");
+ if (UtilValidate.isNotEmpty("pdfFileNameIn")) {
+ try {
+ FileInputStream fis = new FileInputStream(pdfFileNameIn);
+ int c;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ while ((c = fis.read()) != -1) baos.write(c);
+ inputByteWrapper = new ByteWrapper(baos.toByteArray());
+ } catch(FileNotFoundException e) {
+ throw(new GeneralException(e.getMessage()));
+ } catch(IOException e) {
+ throw(new GeneralException(e.getMessage()));
+ }
+ } else if (UtilValidate.isNotEmpty("contentId")) {
+ try {
+ Locale locale = (Locale)context.get("locale");
+ String https = (String)context.get("https");
+ String webSiteId = (String)context.get("webSiteId");
+ String rootDir = (String)context.get("rootDir");
+ GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
+ String dataResourceId = content.getString("dataResourceId");
+ inputByteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, dataResourceId, https, webSiteId, locale, rootDir);
+ } catch (GenericEntityException e) {
+ throw(new GeneralException(e.getMessage()));
+ } catch (IOException e) {
+ throw(new GeneralException(e.getMessage()));
+ }
+ }
+ }
+ return inputByteWrapper;
+ }
}
Modified: trunk/applications/content/widget/compdoc/CompDocForms.xml
===================================================================
--- trunk/applications/content/widget/compdoc/CompDocForms.xml 2006-02-25 01:59:42 UTC (rev 6845)
+++ trunk/applications/content/widget/compdoc/CompDocForms.xml 2006-02-25 20:54:13 UTC (rev 6846)
@@ -357,11 +357,11 @@
</drop-down>
</field>
<field name="mimeTypeId" map-name="dataResource" title="Document Type" widget-style="tabletext"
- use-when="contentTypeId.equals("DOCUMENT") && mimeTypeId != null && !mimeTypeId.equals("SURVEY")">
+ use-when="contentTypeId.equals("DOCUMENT") && mimeTypeId != null && !mimeTypeId.equals("application/vnd.ofbiz.survey")">
<display-entity entity-name="MimeType" key-field-name="mimeTypeId" description="${description}"/>
</field>
<field name="mimeTypeId" map-name="dataResource" title="Document Type" widget-style="tabletext"
- use-when="contentTypeId.equals("DOCUMENT") && mimeTypeId != null && mimeTypeId.equals("SURVEY")">
+ use-when="contentTypeId.equals("DOCUMENT") && mimeTypeId != null && mimeTypeId.equals("application/vnd.ofbiz.survey")">
<display description="Survey Response"/>
</field>
<field name="relatedDetailId" map-name="dataResource" title="Survey ID" use-when="dataResource!=null&&"SURVEY".equals(dataResource.getString("dataResourceTypeId"))">
Modified: trunk/applications/content/widget/compdoc/CompDocMenus.xml
===================================================================
--- trunk/applications/content/widget/compdoc/CompDocMenus.xml 2006-02-25 01:59:42 UTC (rev 6845)
+++ trunk/applications/content/widget/compdoc/CompDocMenus.xml 2006-02-25 20:54:13 UTC (rev 6846)
@@ -221,81 +221,4 @@
</menu>
- <!-- DEJ20060220 What is this doing in here? It looks like a menu for the Content maintenance screens and has nothing to do with CompDoc... -->
- <menu name="main" default-title-style="tabButton"
- default-selected-style="tabButtonSelected"
- default-menu-item-name="content"
- orientation="horizontal"
- menu-width="100%"
- default-tooltip-style="tabletext" default-widget-style="tabButton"
- default-associated-content-id="${userLogin.userLoginId}"
- selected-menuitem-context-field-name="currentMenuItemName"
- title="" type="simple">
-
-
- <menu-item name="FindContent" title="Find" >
- <link target="FindContent"/>
- </menu-item>
-
- <menu-item name="EditContent" title="Content" >
- <condition>
- <not>
- <if-empty field-name="contentId" />
- </not>
- </condition>
- <link target="EditContent?contentId=${contentId}"/>
- </menu-item>
-
- <menu-item name="AddContent" title="Content" >
- <condition>
- <if-empty field-name="contentId" />
- </condition>
- <link target="AddContent"/>
- </menu-item>
-
- <menu-item name="contentassoc" title="Association" >
- <condition disabled-style="buttontextdisabled">
- <not>
- <if-empty field-name="contentId" />
- </not>
- </condition>
- <link target="EditContentAssoc?contentId=${contentId}"/>
- </menu-item>
-
- <menu-item name="role" title="Role" >
- <condition disabled-style="buttontextdisabled">
- <not>
- <if-empty field-name="contentId" />
- </not>
- </condition>
- <link target="EditContentRole?contentId=${contentId}"/>
- </menu-item>
-
- <menu-item name="purpose" title="Purpose" >
- <condition disabled-style="buttontextdisabled">
- <not>
- <if-empty field-name="contentId" />
- </not>
- </condition>
- <link target="EditContentPurpose?contentId=${contentId}"/>
- </menu-item>
-
- <menu-item name="attribute" title="Attribute" >
- <condition disabled-style="buttontextdisabled">
- <not>
- <if-empty field-name="contentId" />
- </not>
- </condition>
- <link target="EditContentAttribute?contentId=${contentId}"/>
- </menu-item>
-
- <menu-item name="metadata" title="Metadata" >
- <condition disabled-style="buttontextdisabled">
- <not>
- <if-empty field-name="contentId" />
- </not>
- </condition>
- <link target="EditContentMetaData?contentId=${contentId}"/>
- </menu-item>
- </menu>
</menus>
Modified: trunk/applications/content/widget/compdoc/CompDocScreens.xml
===================================================================
--- trunk/applications/content/widget/compdoc/CompDocScreens.xml 2006-02-25 01:59:42 UTC (rev 6845)
+++ trunk/applications/content/widget/compdoc/CompDocScreens.xml 2006-02-25 20:54:13 UTC (rev 6846)
@@ -371,12 +371,14 @@
<include-form name="EditChildCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
<section>
<!-- For upload-able DataResourceTypes -->
+ <!--
<condition>
<and>
<not><if-empty field-name="dataResource.dataResourceTypeId"/></not>
<if-compare field-name="dataResource.dataResourceTypeId" operator="not-equals" value="SURVEY"/>
</and>
</condition>
+ -->
<actions>
<set from-field="dummy.rootTemplateContentId" field="dummy.rootContentId" />
</actions>
@@ -410,6 +412,7 @@
<order-by field-name="-maxRevisionSeqId"/>
</entity-condition>
<set from-field="rootRevList[0].maxRevisionSeqId" field="rootInstanceRevSeqId"/>
+ <!--
<entity-one entity-name="Content" value-name="templateContent" use-cache="false">
<field-map field-name="contentId" env-name="content.instanceOfContentId"/>
</entity-one>
@@ -418,18 +421,21 @@
</entity-one>
<set from-field="templateDataResource.mimeTypeId" field="dataResource.mimeTypeId"/>
<set from-field="templateDataResource.mimeTypeId" field="mimeTypeId"/>
+ -->
</actions>
<widgets>
<decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
<decorator-section name="body">
<include-form name="EditChildCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
<section>
+ <!--
<condition>
<and>
<not><if-empty field-name="dataResource.dataResourceTypeId"/></not>
<if-compare field-name="dataResource.dataResourceTypeId" operator="not-equals" value="SURVEY"/>
</and>
</condition>
+ -->
<actions>
<set from-field="dummy.rootInstanceContentId" field="dummy.rootContentId"/>
</actions>
@@ -486,8 +492,12 @@
<section>
<condition>
<or>
+ <if-compare field-name="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey.response"/>
+ <if-compare field-name="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey"/>
+ <!--
<if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
<if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
+ -->
</or>
</condition>
<actions>
@@ -519,7 +529,7 @@
<actions>
</actions>
<widgets>
- <label text="Screen not available for mime-type: ${dataResource.mimeTypeId}"/>
+ <label text="View screen not available for mime-type: ${dataResource.mimeTypeId}"/>
</widgets>
</section>
</widgets>
@@ -569,35 +579,41 @@
<section>
<condition>
<or>
+ <if-compare field-name="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey"/>
+ <!--
<if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
<if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
+ -->
</or>
</condition>
<actions>
</actions>
<widgets>
- <section>
- <condition>
- <if-compare field-name="contentTypeId" operator="equals" value="TEMPLATE"/>
- </condition>
- <widgets>
+ <!-- Don't put this link here. It is called in the form.
<include-form name="UploadCompDocSurveyId" location="component://content/widget/compdoc/CompDocForms.xml"/>
- </widgets>
- </section>
- <!--
- <section>
- <condition>
- <if-compare field-name="contentTypeId" operator="equals" value="DOCUMENT"/>
- </condition>
- <widgets>
- <link target="" text="" style="buttontext"/>
- </widgets>
- </section>
- -->
+ -->
</widgets>
</section>
<section>
<condition>
+ <or>
+ <if-compare field-name="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey.response"/>
+ <!--
+ <if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
+ <if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
+ -->
+ </or>
+ </condition>
+ <actions>
+ </actions>
+ <widgets>
+ <!-- Don't put this link here. It is called in the form.
+ <link text="Edit Survey Response"/>
+ -->
+ </widgets>
+ </section>
+ <section>
+ <condition>
<not>
<or>
<if-compare field-name="dataResource.mimeTypeId" operator="equals" value="application/msword"/>
@@ -611,6 +627,8 @@
<if-compare field-name="dataResource.mimeTypeId" operator="equals" value="text/html"/>
<if-compare field-name="dataResource.mimeTypeId" operator="equals" value="text/plain"/>
+ <if-compare field-name="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey.response"/>
+ <if-compare field-name="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey"/>
<if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
<if-compare field-name="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
</or>
@@ -619,7 +637,7 @@
<actions>
</actions>
<widgets>
- <label text="Screen not available for mime-type: ${dataResource.mimeTypeId}"/>
+ <label text="Upload screen not available for mime-type: ${dataResource.mimeTypeId}"/>
</widgets>
</section>
</widgets>
More information about the Svn
mailing list