[OFBiz] SVN: r6896 - in trunk/applications/content: script/org/ofbiz/content/compdoc servicedef src/org/ofbiz/content/openoffice src/org/ofbiz/content/survey webapp/content/WEB-INF widget/compdoc
byersa@svn.ofbiz.org
byersa at svn.ofbiz.org
Fri Mar 3 00:47:00 CST 2006
Author: byersa
Date: 2006-03-03 00:46:28 -0600 (Fri, 03 Mar 2006)
New Revision: 6896
Modified:
trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml
trunk/applications/content/servicedef/services.xml
trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeEvents.java
trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java
trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
trunk/applications/content/webapp/content/WEB-INF/controller.xml
trunk/applications/content/widget/compdoc/CompDocForms.xml
trunk/applications/content/widget/compdoc/CompDocMenus.xml
trunk/applications/content/widget/compdoc/CompDocScreens.xml
Log:
Complex PDF generation working.
Modified: trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml
===================================================================
--- trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml 2006-03-03 06:46:28 UTC (rev 6896)
@@ -259,7 +259,7 @@
</call-service>
</simple-method>
- <simple-method method-name="persistCompDocContent" short-description="Create ContentApproval">
+ <simple-method method-name="persistCompDocContent" short-description="Persist a CompDoc DataResource and data">
<entity-one entity-name="Content" value-name="content" use-cache="false"/>
<set from-field="content.dataResourceId" field="oldDataResourceId"/>
<log level="info" message="persistCompDocContent(0).content : ${content}"/>
@@ -290,6 +290,38 @@
</simple-method>
+ <simple-method method-name="persistCompDocPdf2Survey" short-description="Upload/save PDF, create Survey, populate Content">
+
+ <set field="pdfMap.contentTypeId" value="DOCUMENT"/>
+ <set field="pdfMap.dataResourceTypeId" value="IMAGE_OBJECT"/>
+ <set field="pdfMap.mimeTypeId" value="application/pdf"/>
+ <set field="pdfMap.drMimeTypeId" value="application/pdf"/>
+ <set field="pdfMap.imageData" from-field="parameters.imageData"/>
+ <set field="pdfMap._imageData_contentType" from-field="parameters._imageData_contentType"/>
+ <set field="pdfMap._imageData_fileName" from-field="parameters._imageData_fileName"/>
+ <set field="pdfMap.contentName" from-field="parameters.pdfName"/>
+ <log level="info" message="persistCompDocPdf2Survey(1).pdfMap : ${pdfMap}"/>
+ <call-service service-name="persistContentAndAssoc" in-map-name="pdfMap">
+ <result-to-field result-name="contentId" field-name="acroFormContentId"/>
+ </call-service>
+ <log level="info" message="persistCompDocPdf2Survey(2).acroFormContentId : ${acroFormContentId}"/>
+
+ <set field="acroMap.contentId" from-field="acroFormContentId"/>
+ <call-service service-name="buildSurveyFromPdf" in-map-name="acroMap">
+ <result-to-field result-name="surveyId" field-name="surveyId"/>
+ </call-service>
+ <log level="info" message="persistCompDocPdf2Survey(3).surveyId : ${surveyId}"/>
+
+ <set-service-fields service-name="persistCompDocContent" map-name="parameters" to-map-name="persistMap"/>
+ <set field="persistMap.relatedDetailId" from-field="surveyId"/>
+ <set field="persistMap.drMimeTypeId" value="application/vnd.ofbiz.survey"/>
+ <log level="info" message="persistCompDocPdf2Survey(4)persistMap : ${persistMap}"/>
+ <call-service service-name="persistCompDocContent" in-map-name="persistMap">
+ </call-service>
+
+
+ </simple-method>
+
<!-- Methods for ContentApproval -->
<simple-method method-name="createContentApproval" short-description="Create ContentApproval">
<log level="always" message="got into createContentApproval(4)"></log>
Modified: trunk/applications/content/servicedef/services.xml
===================================================================
--- trunk/applications/content/servicedef/services.xml 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/servicedef/services.xml 2006-03-03 06:46:28 UTC (rev 6896)
@@ -863,6 +863,14 @@
<attribute name="rootContentId" type="String" mode="IN" optional="true"/>
</service>
+ <service name="persistCompDocPdf2Survey" engine="simple"
+ transaction-timout="72000"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml" invoke="persistCompDocPdf2Survey" auth="true">
+ <description>Upload/save PDF, create Survey, populate Content</description>
+ <implements service="persistCompDocContent"/>
+ <attribute name="pdfName" type="String" mode="IN" optional="true"/>
+ </service>
+
<service name="persistContentWithRevision" engine="java"
transaction-timout="72000"
location="org.ofbiz.content.ContentManagementServices" invoke="persistContentWithRevision" auth="true">
@@ -1382,7 +1390,7 @@
<attribute name="https" type="String" mode="IN" optional="true"/>
<attribute name="rootDir" type="String" mode="IN" optional="true"/>
<attribute name="locale" type="java.util.Locale" mode="IN" optional="true"/>
- <attribute name="pdfByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="false"/>
+ <attribute name="outByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="false"/>
</service>
<service name="renderContentPdf" engine="java"
@@ -1395,6 +1403,6 @@
<attribute name="https" type="String" mode="IN" optional="true"/>
<attribute name="rootDir" type="String" mode="IN" optional="true"/>
<attribute name="locale" type="java.util.Locale" mode="IN" optional="true"/>
- <attribute name="pdfByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="false"/>
+ <attribute name="outByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="false"/>
</service>
</services>
Modified: trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeEvents.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeEvents.java 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeEvents.java 2006-03-03 06:46:28 UTC (rev 6896)
@@ -77,21 +77,21 @@
return "error";
}
- ByteWrapper pdfByteWrapper = (ByteWrapper)results.get("pdfByteWrapper");
+ ByteWrapper outByteWrapper = (ByteWrapper)results.get("outByteWrapper");
// setup content type
String contentType = "application/pdf; charset=ISO-8859-1";
- ByteArrayInputStream bais = new ByteArrayInputStream(pdfByteWrapper.getBytes());
+ ByteArrayInputStream bais = new ByteArrayInputStream(outByteWrapper.getBytes());
try {
FileOutputStream fos = new FileOutputStream("/home/byersa/pdftest.pdf");
- fos.write(pdfByteWrapper.getBytes());
+ fos.write(outByteWrapper.getBytes());
} catch(FileNotFoundException e) {
} catch(IOException e) {
}
try {
- UtilHttp.streamContentToBrowser(response, bais, pdfByteWrapper.getLength(), contentType);
+ UtilHttp.streamContentToBrowser(response, bais, outByteWrapper.getLength(), contentType);
} catch(IOException e) {
}
@@ -148,21 +148,22 @@
return "error";
}
- ByteWrapper pdfByteWrapper = (ByteWrapper)results.get("pdfByteWrapper");
+ ByteWrapper outByteWrapper = (ByteWrapper)results.get("outByteWrapper");
// setup content type
String contentType = "application/pdf; charset=ISO-8859-1";
- ByteArrayInputStream bais = new ByteArrayInputStream(pdfByteWrapper.getBytes());
+ ByteArrayInputStream bais = new ByteArrayInputStream(outByteWrapper.getBytes());
try {
FileOutputStream fos = new FileOutputStream("/home/byersa/pdftest.pdf");
- fos.write(pdfByteWrapper.getBytes());
+ fos.write(outByteWrapper.getBytes());
+ fos.close();
} catch(FileNotFoundException e) {
} catch(IOException e) {
}
try {
- UtilHttp.streamContentToBrowser(response, bais, pdfByteWrapper.getLength(), contentType);
+ UtilHttp.streamContentToBrowser(response, bais, outByteWrapper.getLength(), contentType);
} catch(IOException e) {
}
Modified: trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java 2006-03-03 06:46:28 UTC (rev 6896)
@@ -445,7 +445,7 @@
Debug.logInfo("text/html string:" + s, module);
continue;
} else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
- String surveyResponseId = dataResource.getString("objectInfo");
+ String surveyResponseId = dataResource.getString("relatedDetailId");
String surveyId = null;
String acroFormContentId = null;
GenericValue surveyResponse = null;
@@ -455,7 +455,7 @@
surveyId = surveyResponse.getString("surveyId");
}
}
- if (UtilValidate.isNotEmpty(surveyId) && UtilValidate.isEmpty(contentId)) {
+ if (UtilValidate.isNotEmpty(surveyId)) {
GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
if (survey != null) {
acroFormContentId = survey.getString("acroFormContentId");
@@ -478,7 +478,6 @@
reader = new PdfReader(inputByteArray);
}
}
- continue;
} else {
byteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
OpenOfficeByteArrayInputStream oobais = new OpenOfficeByteArrayInputStream(byteWrapper.getBytes());
@@ -498,7 +497,7 @@
}
document.close();
ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());
- results.put("pdfByteWrapper", outByteWrapper);
+ results.put("outByteWrapper", outByteWrapper);
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
} catch (IOException ioe) {
@@ -584,7 +583,7 @@
String s = new String(inputByteArray);
Debug.logInfo("text/html string:" + s, module);
} else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
- String surveyResponseId = dataResource.getString("objectInfo");
+ String surveyResponseId = dataResource.getString("relatedDetailId");
String surveyId = null;
String acroFormContentId = null;
GenericValue surveyResponse = null;
@@ -594,7 +593,7 @@
surveyId = surveyResponse.getString("surveyId");
}
}
- if (UtilValidate.isNotEmpty(surveyId) && UtilValidate.isEmpty(contentId)) {
+ if (UtilValidate.isNotEmpty(surveyId)) {
GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
if (survey != null) {
acroFormContentId = survey.getString("acroFormContentId");
@@ -609,13 +608,13 @@
Map survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
ByteWrapper outByteWrapper = (ByteWrapper)survey2PdfResults.get("outByteWrapper");
inputByteArray = outByteWrapper.getBytes();
- reader = new PdfReader(inputByteArray);
+ //reader = new PdfReader(inputByteArray);
} else {
// Fill in acroForm
Map survey2PdfResults = dispatcher.runSync("setAcroFieldsFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
ByteWrapper outByteWrapper = (ByteWrapper)survey2PdfResults.get("outByteWrapper");
inputByteArray = outByteWrapper.getBytes();
- reader = new PdfReader(inputByteArray);
+ //reader = new PdfReader(inputByteArray);
}
}
} else {
@@ -625,17 +624,11 @@
inputByteArray = oobaos.toByteArray();
oobais.close();
oobaos.close();
- reader = new PdfReader(inputByteArray);
+ //reader = new PdfReader(inputByteArray);
}
- int n = reader.getNumberOfPages();
- for (int i=0; i < n; i++) {
- PdfImportedPage pg = writer.getImportedPage(reader, i + 1);
- //cb.addTemplate(pg, left, height * pgCnt);
- writer.addPage(pg);
- }
- ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());
- results.put("pdfByteWrapper", outByteWrapper);
+ ByteWrapper outByteWrapper = new ByteWrapper(inputByteArray);
+ results.put("outByteWrapper", outByteWrapper);
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
} catch (IOException ioe) {
Modified: trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java 2006-03-03 06:46:28 UTC (rev 6896)
@@ -381,6 +381,7 @@
// 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();
@@ -401,7 +402,8 @@
if (UtilValidate.isNotEmpty(fieldValue))
fs.setField(fieldName, fieldValue);
- }
+ }
+
s.close();
baos.close();
ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());
@@ -418,6 +420,9 @@
} catch(IOException ioe) {
System.err.println(ioe.getMessage());
ServiceUtil.returnError(ioe.getMessage());
+ } catch(Exception ioe) {
+ System.err.println(ioe.getMessage());
+ ServiceUtil.returnError(ioe.getMessage());
}
return results;
@@ -503,6 +508,7 @@
Map results = ServiceUtil.returnSuccess();
Map acroFieldMap = new HashMap();
String surveyResponseId = (String)context.get("surveyResponseId");
+ String acroFormContentId = null;
try {
String surveyId = null;
@@ -513,6 +519,13 @@
}
}
+ if (UtilValidate.isNotEmpty(surveyId)) {
+ GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
+ if (survey != null) {
+ acroFormContentId = survey.getString("acroFormContentId");
+ }
+ }
+
List responses = delegator.findByAnd("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId));
Iterator iter = responses.iterator();
while (iter.hasNext()) {
@@ -552,6 +565,7 @@
ModelService modelService = dispatcher.getDispatchContext().getModelService("setAcroFields");
Map ctx = modelService.makeValid(context, "IN");
ctx.put("acroFieldMap", acroFieldMap);
+ ctx.put("contentId", acroFormContentId);
Map map = dispatcher.runSync("setAcroFields", ctx);
if (ServiceUtil.isError(map)) {
String errMsg = ServiceUtil.makeErrorMessage(map, null, null, null, null);
@@ -562,7 +576,7 @@
ByteWrapper outByteWrapper = (ByteWrapper)map.get("outByteWrapper");
results.put("outByteWrapper", outByteWrapper);
if (UtilValidate.isNotEmpty(pdfFileNameOut)) {
- FileOutputStream fos = new FileOutputStream("pdfFileNameOut");
+ FileOutputStream fos = new FileOutputStream(pdfFileNameOut);
fos.write(outByteWrapper.getBytes());
fos.close();
}
Modified: trunk/applications/content/webapp/content/WEB-INF/controller.xml
===================================================================
--- trunk/applications/content/webapp/content/WEB-INF/controller.xml 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/webapp/content/WEB-INF/controller.xml 2006-03-03 06:46:28 UTC (rev 6896)
@@ -820,6 +820,12 @@
<response name="success" type="view" value="EditChildCompDoc"/>
<response name="error" type="view" value="EditChildCompDoc"/>
</request-map>
+ <request-map uri="persistCompDocPdf2Survey">
+ <security auth="true" https="true"/>
+ <event invoke="persistCompDocPdf2Survey" path="" type="service"/>
+ <response name="success" type="view" value="EditChildCompDoc"/>
+ <response name="error" type="view" value="EditChildCompDoc"/>
+ </request-map>
<request-map uri="createCompDoc">
<security auth="true" https="true"/>
<event invoke="persistContentAndAssoc" path="" type="service"/>
Modified: trunk/applications/content/widget/compdoc/CompDocForms.xml
===================================================================
--- trunk/applications/content/widget/compdoc/CompDocForms.xml 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/widget/compdoc/CompDocForms.xml 2006-03-03 06:46:28 UTC (rev 6896)
@@ -470,6 +470,24 @@
<field name="submitButton" title="Upload" widget-style="smallSubmit"><submit/></field>
</form>
+ <form name="UploadCompDocPdf2Survey" type="upload" default-title-style="tableheadtext"
+ target="persistCompDocPdf2Survey"
+ default-tooltip-style="tabletext" default-widget-style="tabletext">
+ <field name="caContentIdTo" entry-name="contentIdTo" map-name="contentAssoc"><hidden/></field>
+ <field name="caContentAssocTypeId" ><hidden value="COMPDOC_PART"/></field>
+ <field name="caFromDate" entry-name="fromDate" map-name="contentAssoc"><hidden/></field>
+
+ <field name="contentId" map-name="contentAssoc"><hidden/></field>
+ <field name="dataResourceId" map-name="dataResource"><hidden/></field>
+ <field name="dataResourceTypeId" map-name="dataResource"><hidden/></field>
+ <field name="mimeTypeId" map-name="dataResource"><hidden/></field>
+ <field name="objectInfo" title="File Name" map-name="dataResource"><display also-hidden="false"/></field>
+ <field name="pdfName" title="PDF name"><text/></field>
+ <field name="imageData" title="Enter a PDF file path to automatically create a survey."><file/></field>
+ <field name="rootContentId" ><hidden/></field>
+ <field name="submitButton" title="Upload" widget-style="smallSubmit"><submit/></field>
+ </form>
+
<form name="EditCompDocTextContent" type="single" default-title-style="tableheadtext"
target="uploadCompDocContent"
default-tooltip-style="tabletext" default-widget-style="tabletext" >
Modified: trunk/applications/content/widget/compdoc/CompDocMenus.xml
===================================================================
--- trunk/applications/content/widget/compdoc/CompDocMenus.xml 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/widget/compdoc/CompDocMenus.xml 2006-03-03 06:46:28 UTC (rev 6896)
@@ -242,7 +242,7 @@
<condition>
<not><if-empty field-name="assocRevisionItemView"/></not>
</condition>
- <link target="GenContentPdf?contentId=${instanceContentId}&caSequenceNum=${sequenceNum}"/>
+ <link target="GenContentPdf?contentId=${assocRevisionItemView.contentId}"/>
</menu-item>
</menu>
Modified: trunk/applications/content/widget/compdoc/CompDocScreens.xml
===================================================================
--- trunk/applications/content/widget/compdoc/CompDocScreens.xml 2006-03-03 01:51:05 UTC (rev 6895)
+++ trunk/applications/content/widget/compdoc/CompDocScreens.xml 2006-03-03 06:46:28 UTC (rev 6896)
@@ -679,6 +679,7 @@
<!-- Don't put this link here. It is called in the form.
<include-form name="UploadCompDocSurveyId" location="component://content/widget/compdoc/CompDocForms.xml"/>
-->
+ <include-form name="UploadCompDocPdf2Survey" location="component://content/widget/compdoc/CompDocForms.xml"/>
</widgets>
</section>
<section>
@@ -931,7 +932,7 @@
<widgets>
<decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
<decorator-section name="body">
- <container><link target="GenCompDocPdf?contentId=${contentId}&contentRevisionSeqId=${contentRevisionSeqId}" text="Generate Composite PDF" style="buttontext"/></container>
+ <container><link target="GenCompDocPdf?contentId=${rootContentId}&contentRevisionSeqId=${rootContentRevisionSeqId}" text="Generate Composite PDF" style="buttontext"/></container>
<include-tree name="CompDocInstanceTree" location="component://content/widget/compdoc/CompDocTemplateTree.xml"/>
</decorator-section>
</decorator-screen>
More information about the Svn
mailing list