You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by by...@apache.org on 2007/05/11 01:40:46 UTC
svn commit: r537042 - in /ofbiz/trunk/applications/content:
servicedef/services_survey.xml
src/org/ofbiz/content/survey/PdfSurveyServices.java
Author: byersa
Date: Thu May 10 16:40:46 2007
New Revision: 537042
URL: http://svn.apache.org/viewvc?view=rev&rev=537042
Log:
Added a utility service, buildSurveyQuestionsAndAnswers, that, given a surveyResponseId, returns a list of maps that contain
"question"->SurveyQuestion and "response"->SurveyResponseAnswer pairs.
Modified:
ofbiz/trunk/applications/content/servicedef/services_survey.xml
ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
Modified: ofbiz/trunk/applications/content/servicedef/services_survey.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/servicedef/services_survey.xml?view=diff&rev=537042&r1=537041&r2=537042
==============================================================================
--- ofbiz/trunk/applications/content/servicedef/services_survey.xml (original)
+++ ofbiz/trunk/applications/content/servicedef/services_survey.xml Thu May 10 16:40:46 2007
@@ -357,4 +357,10 @@
<attribute name="surveyResponseId" type="String" mode="IN" optional="false" />
<attribute name="outByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="false" />
</service>
+ <service name="buildSurveyQuestionsAndAnswers" engine="java"
+ location="org.ofbiz.content.survey.PdfSurveyServices" invoke="buildSurveyQuestionsAndAnswers" auth="false">
+ <description>Build list of questions and answers From Survey Response</description>
+ <attribute name="surveyResponseId" type="String" mode="IN" optional="false" />
+ <attribute name="questionsAndAnswers" type="List" mode="OUT" optional="false" />
+ </service>
</services>
Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java?view=diff&rev=537042&r1=537041&r2=537042
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java Thu May 10 16:40:46 2007
@@ -24,6 +24,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -491,6 +492,44 @@
System.err.println(e.getMessage());
ServiceUtil.returnError(e.getMessage());
} catch (DocumentException e) {
+ System.err.println(e.getMessage());
+ ServiceUtil.returnError(e.getMessage());
+ }
+
+ return results;
+ }
+
+ /**
+ * Returns list of maps with "question"->SurveyQuestion and "response"->SurveyResponseAnswer
+ */
+ public static Map buildSurveyQuestionsAndAnswers(DispatchContext dctx, Map context) {
+ GenericDelegator delegator = dctx.getDelegator();
+ //LocalDispatcher dispatcher = dctx.getDispatcher();
+ Map results = ServiceUtil.returnSuccess();
+ String surveyResponseId = (String)context.get("surveyResponseId");
+ String surveyId = null;
+ List qAndA = new ArrayList();
+
+ Document document = new Document();
+ try {
+ if (UtilValidate.isNotEmpty(surveyResponseId)) {
+ GenericValue surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
+ if (surveyResponse != null) {
+ surveyId = surveyResponse.getString("surveyId");
+ }
+ }
+
+ 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));
+ qAndA.add(UtilMisc.toMap("question", surveyQuestion, "response", surveyResponseAnswer));
+ }
+ results.put("questionsAndAnswers", qAndA);
+ } catch (GenericEntityException e) {
System.err.println(e.getMessage());
ServiceUtil.returnError(e.getMessage());
}