Author: jaz
Date: Sat Oct  6 15:25:35 2007
New Revision: 582539

URL: http://svn.apache.org/viewvc?rev=582539&view=rev
Log:
implemented feature to allow setting default values for survey questions; 
response can be generated by setting v
alues (via a map) in the wrapper before rendering

implemented GEO and ENUMERATION types for Survey Questions; now ANY Geo Group 
or Enumeration Type can be listed
as survey option lists


Modified:
    ofbiz/trunk/applications/content/data/ContentTypeData.xml
    ofbiz/trunk/applications/content/entitydef/entitymodel.xml
    
ofbiz/trunk/applications/content/script/org/ofbiz/content/survey/SurveyServices.xml
    
ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/SurveyWrapper.java
    ofbiz/trunk/applications/content/template/survey/genericsurvey.ftl
    
ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreSurveyWrapper.java

Modified: ofbiz/trunk/applications/content/data/ContentTypeData.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/data/ContentTypeData.xml?rev=582539&r1=582538&r2=582539&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/data/ContentTypeData.xml (original)
+++ ofbiz/trunk/applications/content/data/ContentTypeData.xml Sat Oct  6 
15:25:35 2007
@@ -251,9 +251,11 @@
     <SurveyQuestionType surveyQuestionTypeId="CONTENT" description="Content 
Record"/>
     <SurveyQuestionType surveyQuestionTypeId="COUNTRY" description="Country"/>
     <SurveyQuestionType surveyQuestionTypeId="CREDIT_CARD" description="Credit 
Card Number"/>
+    <SurveyQuestionType surveyQuestionTypeId="GEO" description="Geo List"/>
     <SurveyQuestionType surveyQuestionTypeId="GIFT_CARD" description="Gift 
Card Number"/>
     <SurveyQuestionType surveyQuestionTypeId="DATE" description="Date String 
(mm/dd/yyyy)"/>
     <SurveyQuestionType surveyQuestionTypeId="EMAIL" description="Email 
Address"/>
+    <SurveyQuestionType surveyQuestionTypeId="ENUMERATION" 
description="Enumeration"/>    
     <SurveyQuestionType surveyQuestionTypeId="NUMBER_CURRENCY" 
description="Numeric (Currency)"/>
     <SurveyQuestionType surveyQuestionTypeId="NUMBER_FLOAT" 
description="Numeric (Float)"/>
     <SurveyQuestionType surveyQuestionTypeId="NUMBER_LONG" 
description="Numeric (Long)"/>

Modified: ofbiz/trunk/applications/content/entitydef/entitymodel.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/entitydef/entitymodel.xml?rev=582539&r1=582538&r2=582539&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/content/entitydef/entitymodel.xml Sat Oct  6 
15:25:35 2007
@@ -1301,6 +1301,9 @@
       <field name="description" type="description"/>
       <field name="question" type="very-long"/>
       <field name="hint" type="very-long"/>
+      <field name="enumTypeId" type="id"></field>
+      <field name="geoId" type="id"></field>
+      <field name="formatString" type="value"></field>
       <prim-key field="surveyQuestionId"/>
       <relation type="one" fk-name="SRVYQST_SRVYQTP" 
rel-entity-name="SurveyQuestionType">
         <key-map field-name="surveyQuestionTypeId"/>
@@ -1308,6 +1311,13 @@
       <relation type="one" fk-name="SRVYQST_SRVYQTCT" 
rel-entity-name="SurveyQuestionCategory">
         <key-map field-name="surveyQuestionCategoryId"/>
       </relation>
+      <relation type="one" fk-name="SRVYQST_GEO" rel-entity-name="Geo">
+        <key-map field-name="geoId"/>
+      </relation>
+      <relation type="many" fk-name="SRVYQST_ENUM" 
rel-entity-name="Enumeration">
+        <key-map field-name="enumTypeId"/>
+      </relation>
+
     </entity>
     <view-entity entity-name="SurveyQuestionAndAppl"
             package-name="org.ofbiz.content.survey"
@@ -1331,19 +1341,25 @@
       <relation type="many" rel-entity-name="SurveyQuestionOption">
         <key-map field-name="surveyQuestionId"/>
       </relation>
-        <relation type="one-nofk" rel-entity-name="SurveyPage">
-            <key-map field-name="surveyId"/>
-            <key-map field-name="surveyPageSeqId"/>
-        </relation>
-        <relation type="one-nofk" rel-entity-name="SurveyMultiResp">
-            <key-map field-name="surveyId"/>
-            <key-map field-name="surveyMultiRespId"/>
-        </relation>
-        <relation type="one-nofk" rel-entity-name="SurveyMultiRespColumn">
-            <key-map field-name="surveyId"/>
-            <key-map field-name="surveyMultiRespId"/>
-            <key-map field-name="surveyMultiRespColId"/>
-        </relation>
+      <relation type="many" rel-entity-name="Enumeration">
+        <key-map field-name="enumTypeId"/>
+      </relation>
+      <relation type="one-nofk" rel-entity-name="Geo">
+        <key-map field-name="geoId"/>
+      </relation>
+      <relation type="one-nofk" rel-entity-name="SurveyPage">
+        <key-map field-name="surveyId"/>
+        <key-map field-name="surveyPageSeqId"/>
+      </relation>
+      <relation type="one-nofk" rel-entity-name="SurveyMultiResp">
+        <key-map field-name="surveyId"/>
+        <key-map field-name="surveyMultiRespId"/>
+      </relation>
+      <relation type="one-nofk" rel-entity-name="SurveyMultiRespColumn">
+        <key-map field-name="surveyId"/>
+        <key-map field-name="surveyMultiRespId"/>
+        <key-map field-name="surveyMultiRespColId"/>
+      </relation>
     </view-entity>
     <entity entity-name="SurveyQuestionAppl"
             package-name="org.ofbiz.content.survey"

Modified: 
ofbiz/trunk/applications/content/script/org/ofbiz/content/survey/SurveyServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/script/org/ofbiz/content/survey/SurveyServices.xml?rev=582539&r1=582538&r2=582539&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/content/script/org/ofbiz/content/survey/SurveyServices.xml
 (original)
+++ 
ofbiz/trunk/applications/content/script/org/ofbiz/content/survey/SurveyServices.xml
 Sat Oct  6 15:25:35 2007
@@ -191,7 +191,31 @@
         <check-permission action="_CREATE" permission="CONTENTMGR">
             <fail-message message="Security Error: to run createSurveyQuestion 
you must have the CONTENTMGR_CREATE or CONTENTMGR_ADMIN permission"/>
         </check-permission>
+        <if>
+            <condition>
+
+                <and>
+                    <if-compare field-name="surveyQuestionTypeId" 
value="ENUMERATION" operator="equals"/>
+                    <if-empty field-name="enumTypeId"/>
+                </and>
+            </condition>
+            <then>
+                <add-error><fail-message message="Question type ENUMERATION 
requires enumTypeId to be set"/></add-error>
+            </then>
+        </if>
+        <if>
+            <condition>
+                <and>
+                    <if-compare field-name="surveyQuestionTypeId" value="GEO" 
operator="equals"/>
+                    <if-empty field-name="geoId"/>
+                </and>
+            </condition>
+            <then>
+                <add-error><fail-message message="Question type GEO requires 
geoId to be set"/></add-error>
+            </then>
+        </if>
         <check-errors/>
+        
         <make-value entity-name="SurveyQuestion" value-name="newEntity"/>
         <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
         <sequenced-id-to-env sequence-name="SurveyQuestion" 
env-name="newEntity.surveyQuestionId"/>
@@ -202,7 +226,30 @@
         <check-permission action="_UPDATE" permission="CONTENTMGR">
             <fail-message message="Security Error: to run updateSurveyQuestion 
you must have the CONTENTMGR_UPDATE or CONTENTMGR_ADMIN permission"/>
         </check-permission>
+        <if>
+            <condition>
+                <and>
+                    <if-compare field-name="parameters.surveyQuestionTypeId" 
value="ENUMERATION" operator="equals"/>
+                    <if-empty field-name="parameters.enumTypeId"/>
+                </and>
+            </condition>
+            <then>
+                <add-error><fail-message message="Question type ENUMERATION 
requires enumTypeId to be set"/></add-error>
+            </then>
+        </if>
+        <if>
+            <condition>
+                <and>
+                    <if-compare field-name="parameters.surveyQuestionTypeId" 
value="GEO" operator="equals"/>
+                    <if-empty field-name="parameters.geoId"/>
+                </and>
+            </condition>
+            <then>
+                <add-error><fail-message message="Question type GEO requires 
geoId to be set"/></add-error>
+            </then>
+        </if>
         <check-errors/>
+
         <make-value entity-name="SurveyQuestion" value-name="lookupKeyValue"/>
         <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
         <find-by-primary-key map-name="lookupKeyValue" 
value-name="lookedUpValue"/>
@@ -695,6 +742,12 @@
             </if-compare>
             <if-compare 
field-name="surveyQuestionAndAppl.surveyQuestionTypeId" operator="equals" 
value="OPTION">
                 <set from-field="answers.${currentFieldName}" 
field="responseAnswer.surveyOptionSeqId"/>
+            </if-compare>
+            <if-compare 
field-name="surveyQuestionAndAppl.surveyQuestionTypeId" operator="equals" 
value="GEO">
+                <set field="responseAnswer.textResponse" 
from-field="answers.${currentFieldName}"/>
+            </if-compare>
+            <if-compare 
field-name="surveyQuestionAndAppl.surveyQuestionTypeId" operator="equals" 
value="ENUMERATION">
+                <set field="responseAnswer.textResponse" 
from-field="answers.${currentFieldName}"/>
             </if-compare>
             <if-compare 
field-name="surveyQuestionAndAppl.surveyQuestionTypeId" operator="equals" 
value="CONTENT">
                 <!-- <log level="always" message="Found CONTENT type 
question"/> -->

Modified: 
ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/SurveyWrapper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/SurveyWrapper.java?rev=582539&r1=582538&r2=582539&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/SurveyWrapper.java
 (original)
+++ 
ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/SurveyWrapper.java
 Sat Oct  6 15:25:35 2007
@@ -68,21 +68,25 @@
     protected String partyId = null;
     protected String surveyId = null;
     protected Map passThru = null;
+    protected Map defaultValues = null;
     protected boolean edit = false;
 
     protected SurveyWrapper() {}
 
-    public SurveyWrapper(GenericDelegator delegator, String responseId, String 
partyId, String surveyId, Map passThru) {
+    public SurveyWrapper(GenericDelegator delegator, String responseId, String 
partyId, String surveyId, Map passThru, Map defaultValues) {
         this.delegator = delegator;
         this.responseId = responseId;
         this.partyId = partyId;
         this.surveyId = surveyId;
-        if (passThru != null) {
-            this.passThru = new HashMap(passThru);
-        }
+        this.setPassThru(passThru);
+        this.setDefaultValues(defaultValues);
         this.checkParameters();
     }
 
+     public SurveyWrapper(GenericDelegator delegator, String responseId, 
String partyId, String surveyId, Map passThru) {
+         this(delegator, responseId, partyId, surveyId, passThru, null);
+     }
+
     public SurveyWrapper(GenericDelegator delegator, String surveyId) {
         this(delegator, null, null, surveyId, null);
     }
@@ -94,6 +98,28 @@
     }
 
     /**
+     * Sets the pass-thru values (hidden form fields)
+     * @param passThru
+     */
+    public void setPassThru(Map passThru) {
+        if (passThru != null) {
+            this.passThru = FastMap.newInstance();
+            this.passThru.putAll(passThru);
+        }
+    }
+
+    /**
+     * Sets the default values
+     * @param defaultValues
+     */
+    public void setDefaultValues(Map defaultValues) {
+        if (defaultValues != null) {
+            this.defaultValues = FastMap.newInstance();
+            this.defaultValues.putAll(defaultValues);
+        }
+    }
+
+    /**
      * Renders the Survey
      * @return Writer object from the parsed Freemarker Template
      * @throws SurveyWrapperException
@@ -149,6 +175,7 @@
         templateContext.put("surveyResponseId", responseId);
         templateContext.put("sequenceSort", UtilMisc.toList("sequenceNum"));
         templateContext.put("additionalFields", passThru);
+        templateContext.put("defaultValues", defaultValues);
         templateContext.put("delegator", this.delegator);
 
         Template template = this.getTemplate(templateUrl);

Modified: ofbiz/trunk/applications/content/template/survey/genericsurvey.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/template/survey/genericsurvey.ftl?rev=582539&r1=582538&r2=582539&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/template/survey/genericsurvey.ftl 
(original)
+++ ofbiz/trunk/applications/content/template/survey/genericsurvey.ftl Sat Oct  
6 15:25:35 2007
@@ -45,27 +45,27 @@
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "TEXTAREA"/>
     <textarea class="textAreaBox" cols="40" rows="5" 
name="${questionFieldName}">${(answer.textResponse)?if_exists}</textarea>
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "TEXT_SHORT"/>
-    <input type="text" size="15" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?if_exists}">
+    <input type="text" size="15" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "TEXT_LONG"/>
-    <input type="text" size="35" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?if_exists}">
+    <input type="text" size="35" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "EMAIL"/>
-    <input type="text" size="30" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?if_exists}">
+    <input type="text" size="30" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "URL"/>
-    <input type="text" size="40" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?if_exists}">
+    <input type="text" size="40" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "DATE"/>
-    <input type="text" size="12" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?if_exists}">
+    <input type="text" size="12" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "CREDIT_CARD"/>
-    <input type="text" size="20" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?if_exists}">
+    <input type="text" size="20" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "GIFT_CARD"/>
-    <input type="text" size="20" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?if_exists}">
+    <input type="text" size="20" class="inputBox" name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "NUMBER_CURRENCY"/>
-    <input type="text" size="6" class="inputBox" name="${questionFieldName}" 
value="${(answer.currencyResponse)?if_exists}">
+    <input type="text" size="6" class="inputBox" name="${questionFieldName}" 
value="${(answer.currencyResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "NUMBER_FLOAT"/>
-    <input type="text" size="6" class="inputBox" name="${questionFieldName}" 
value="${(answer.floatResponse)?if_exists}">
+    <input type="text" size="6" class="inputBox" name="${questionFieldName}" 
value="${(answer.floatResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "NUMBER_LONG"/>
-    <input type="text" size="6" class="inputBox" name="${questionFieldName}" 
value="${(answer.numericResponse?string("#"))?if_exists}">
+    <input type="text" size="6" class="inputBox" name="${questionFieldName}" 
value="${(answer.numericResponse?default(defValue)?string("#"))?if_exists}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "PASSWORD"/>
-    <input type="password" size="30" class="textBox" 
name="${questionFieldName}" value="${(answer.textResponse)?if_exists}">
+    <input type="password" size="30" class="textBox" 
name="${questionFieldName}" 
value="${(answer.textResponse)?default(defValue?if_exists)}">
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "CONTENT"/>
      <#if (answer.contentId)?has_content>
       <#assign content = answer.getRelatedOne("Content")>
@@ -87,6 +87,43 @@
         <option value="">Nothing to choose</option>
       </#if>
     </select>
+  <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "ENUMERATION"/>
+    <select class="selectBox" name="${questionFieldName}">
+    <#assign formatString = 
surveyQuestionAndAppl.get("formatString")?if_exists/>
+    <#assign enums = surveyQuestionAndAppl.getRelated("Enumeration")/>
+    <#list enums as enum>
+        <#if (((answer.textResponse)?has_content && answer.textResponse == 
enum.enumId) || (defValue == enum.enumId))>
+            <#assign selected = 'selected'/>
+        <#else>
+          <#assign selected = ''/>
+        </#if>
+        <#if (formatString?has_content)>
+            <#assign description = 
Static["org.ofbiz.base.util.string.FlexibleStringExpander"].expandString(formatString,
 enum)/>
+        <#else>
+            <#assign description = geo.getString("description")/>
+        </#if>
+        <option value='${enum.enumId}' ${selected}>${description}</option>
+    </#list>
+    </select>
+  <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "GEO"/>
+    <select class="selectBox" name="${questionFieldName}">
+    <#assign formatString = 
surveyQuestionAndAppl.get("formatString")?if_exists/>
+    <#assign parentGeoId = surveyQuestionAndAppl.get("geoId")?if_exists/>
+    <#assign geos = 
Static["org.ofbiz.common.geo.GeoWorker"].expandGeoGroup(parentGeoId, delegator)>
+    <#list geos as geo>
+        <#if (((answer.textResponse)?has_content && answer.textResponse == 
geo.geoId) || (defValue == geo.geoId))>
+          <#assign selected = 'selected'/>
+        <#else>
+          <#assign selected = ''/>
+        </#if>
+        <#if (formatString?has_content)>
+            <#assign description = 
Static["org.ofbiz.base.util.string.FlexibleStringExpander"].expandString(formatString,
 geo)/>
+        <#else>
+            <#assign description = geo.getString("geoName")/>
+        </#if>
+        <option value='${geo.geoId}' ${selected}>${description}</option>
+    </#list>
+    </select>
   <#elseif surveyQuestionAndAppl.surveyQuestionTypeId == "STATE_PROVINCE"/>
     <select class="selectBox" name="${questionFieldName}">
     <#assign states = 
Static["org.ofbiz.common.CommonWorkers"].getStateList(delegator)>
@@ -222,9 +259,15 @@
                <#assign align = "right"/>
        </#if>
     </#if>
+    
     <#-- get an answer from the answerMap -->
     <#if surveyAnswers?has_content>
       <#assign answer = 
surveyAnswers.get(surveyQuestionAndAppl.surveyQuestionId)?if_exists/>
+    </#if>
+
+    <#-- get the default value from value map -->
+    <#if defaultValues?has_content>
+      <#assign defValue = 
defaultValues.get(surveyQuestionAndAppl.surveyQuestionId)?if_exists/>
     </#if>
 
     <tr>

Modified: 
ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreSurveyWrapper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreSurveyWrapper.java?rev=582539&r1=582538&r2=582539&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreSurveyWrapper.java
 (original)
+++ 
ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreSurveyWrapper.java
 Sat Oct  6 15:25:35 2007
@@ -39,10 +39,9 @@
 
     protected ProductStoreSurveyWrapper() {}
 
-    public ProductStoreSurveyWrapper(GenericValue productStoreSurveyAppl, 
String partyId, Map passThru) {
+    public ProductStoreSurveyWrapper(GenericValue productStoreSurveyAppl, 
String partyId, Map passThru, Map defaultValues) {
         this.productStoreSurveyAppl = productStoreSurveyAppl;
 
-        this.passThru = passThru;
         if (this.productStoreSurveyAppl != null) {
             this.partyId = partyId;
             this.delegator = productStoreSurveyAppl.getDelegator();
@@ -52,7 +51,13 @@
         } else {
             throw new IllegalArgumentException("Required parameter 
productStoreSurveyAppl missing");
         }
+        this.setDefaultValues(defaultValues);
+        this.setPassThru(passThru);
         this.checkParameters();
+    }
+
+    public ProductStoreSurveyWrapper(GenericValue productStoreSurveyAppl, 
String partyId, Map passThru) {
+        this(productStoreSurveyAppl, partyId, passThru, null);
     }
 
     public void callResult(boolean b) {


Reply via email to