You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2015/11/03 17:53:31 UTC

svn commit: r1712347 - in /ofbiz/trunk: applications/order/src/org/ofbiz/order/shoppingcart/product/ applications/product/config/ applications/product/entitydef/ applications/product/src/org/ofbiz/product/product/ applications/product/src/org/ofbiz/pro...

Author: jleroux
Date: Tue Nov  3 16:53:30 2015
New Revision: 1712347

URL: http://svn.apache.org/viewvc?rev=1712347&view=rev
Log:
An updated and modified patch from Bob Morley for "ProductStore did not allow the default timezone to be set" https://issues.apache.org/jira/browse/OFBIZ-2813

The ProductStore has the defaultLocaleString and the defaultCurrencyUomId but does not have a defaultTimeZoneString.  What happens when a store is selected (from e-commerce or the POS) is that it will look to the user for a lastTimeZone and if that is not set, it would simply revert to the TimeZone.getDefault() (so the timezone based on the server).

The trouble we had was that you may have an application server that is running in a completely different timezone than what is desired for the store.

jleroux: see comments in the Jira issue for the modifications I did

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductStoreCartAwareEvents.java
    ofbiz/trunk/applications/product/config/ProductEntityLabels.xml
    ofbiz/trunk/applications/product/config/ProductUiLabels.xml
    ofbiz/trunk/applications/product/entitydef/entitymodel.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java
    ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java
    ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/container/PosContainer.java

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductStoreCartAwareEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductStoreCartAwareEvents.java?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductStoreCartAwareEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductStoreCartAwareEvents.java Tue Nov  3 16:53:30 2015
@@ -94,10 +94,11 @@ public class ProductStoreCartAwareEvents
         // have set the new store, now need to clear out the current catalog so the default for the new store will be used
         session.removeAttribute("CURRENT_CATALOG_ID");
 
-        // if there is no locale or currencyUom in the session, set the defaults from the store, but don't do so through the CommonEvents methods setSessionLocale and setSessionCurrencyUom because we don't want these to be put on the UserLogin entity
+        // if there is no locale, timezone, or currencyUom in the session, set the defaults from the store, but don't do so through the CommonEvents methods setSessionLocale and setSessionCurrencyUom because we don't want these to be put on the UserLogin entity
         // note that this is different from the normal default setting process because these will now override the settings on the UserLogin; this is desired when changing stores and the user should be given a chance to change their personal settings after the store change
         UtilHttp.setCurrencyUomIfNone(session, productStore.getString("defaultCurrencyUomId"));
         UtilHttp.setLocaleIfNone(session, productStore.getString("defaultLocaleString"));
+        UtilHttp.setTimeZoneIfNone(session, productStore.getString("defaultTimeZoneString"));
 
         // if a shoppingCart exists in the session and the productStoreId on it is different,
         // - leave the old cart as-is (don't clear it, want to leave the auto-save list intact)

Modified: ofbiz/trunk/applications/product/config/ProductEntityLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductEntityLabels.xml?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductEntityLabels.xml (original)
+++ ofbiz/trunk/applications/product/config/ProductEntityLabels.xml Tue Nov  3 16:53:30 2015
@@ -4404,6 +4404,10 @@
         <value xml:lang="zh">如果没有指定,使用哪个国家的币种。使用Web工具查找非美国的地区代码。</value>
         <value xml:lang="zh-TW">如果沒有指定,使用哪個國家的幣種.使用Web工具尋找非美國的地區代碼.</value>
     </property>
+    <property key="FieldDescription.ProductStore.defaultTimeZoneString">
+        <value xml:lang="en">Which time zone will be used. If none is specified the machine time zone will be used.</value>
+        <value xml:lang="fr">Utilise ce fuseau horaire. Si aucun n'est spécifié le fuseau horaire de la machine sera utilisé.</value>
+    </property>
     <property key="FieldDescription.ProductStore.defaultSalesChannelEnumId">
         <value xml:lang="de">Sofern der Verkaufskanal in der Transaktion nicht spezifiziert ist, wird angenommen, dass der Verkauf über den hier ausgewählten Kanal kommt.</value>
         <value xml:lang="en">Unless the sales channel has been specified in the transaction, it will be assumed that the sale came in through the selected path.</value>

Modified: ofbiz/trunk/applications/product/config/ProductUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels.xml?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductUiLabels.xml (original)
+++ ofbiz/trunk/applications/product/config/ProductUiLabels.xml Tue Nov  3 16:53:30 2015
@@ -4612,6 +4612,10 @@
         <value xml:lang="zh">缺省序号</value>
         <value xml:lang="zh-TW">預設序號</value>
     </property>
+    <property key="FormFieldTitle_defaultTimeZoneString">
+        <value xml:lang="en">Default Time Zone</value>
+        <value xml:lang="fr">Fuseau horaire par défaut</value>
+    </property>
     <property key="FormFieldTitle_deleteCostComponent">
         <value xml:lang="de">Kostenkomponente löschen</value>
         <value xml:lang="en">Delete Cost Component</value>

Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Tue Nov  3 16:53:30 2015
@@ -3722,6 +3722,7 @@ under the License.
       <field name="orderNumberPrefix" type="id-long"></field>
       <field name="defaultLocaleString" type="very-short"></field>
       <field name="defaultCurrencyUomId" type="id"></field>
+      <field name="defaultTimeZoneString" type="id-long"></field>
       <field name="defaultSalesChannelEnumId" type="id"></field>
       <field name="allowPassword" type="indicator"></field>
       <field name="defaultPassword" type="long-varchar"></field>

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java Tue Nov  3 16:53:30 2015
@@ -909,6 +909,7 @@ public class ProductEvents {
         if (productStore != null) {
             String currencyStr = null;
             String localeStr = null;
+            String timeZoneStr = null;
 
             HttpSession session = request.getSession();
             GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
@@ -917,6 +918,8 @@ public class ProductEvents {
                 currencyStr = userLogin.getString("lastCurrencyUom");
                 // user login locale
                 localeStr = userLogin.getString("lastLocale");
+                // user login timezone
+                timeZoneStr = userLogin.getString("lastTimeZone");
             }
 
             // if currency is not set, the store's default currency is used
@@ -928,10 +931,15 @@ public class ProductEvents {
             if (localeStr == null && productStore.get("defaultLocaleString") != null) {
                 localeStr = productStore.getString("defaultLocaleString");
             }
+            
+            // if timezone is not set, the store's default timezone is used
+            if (timeZoneStr == null && productStore.get("defaultTimeZoneString") != null) {
+                timeZoneStr = productStore.getString("defaultTimeZoneString");
+            }
 
             UtilHttp.setCurrencyUom(session, currencyStr);
             UtilHttp.setLocale(request, localeStr);
-
+            UtilHttp.setTimeZone(request, timeZoneStr);
         }
         return "success";
     }

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java Tue Nov  3 16:53:30 2015
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Random;
+import java.util.TimeZone;
 
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
@@ -111,6 +112,16 @@ public class ProductStoreWorker {
             return UtilHttp.getLocale(request, request.getSession(), productStore.getString("defaultLocaleString"));
         }
     }
+    
+    public static TimeZone getStoreTimeZone(HttpServletRequest request) {
+        GenericValue productStore = getProductStore(request);
+        if (UtilValidate.isEmpty(productStore)) {
+            Debug.logError("No product store found in request, cannot set timezone!", module);
+            return null;
+        } else {
+            return UtilHttp.getTimeZone(request, request.getSession(), productStore.getString("defaultTimeZoneString"));
+        }
+    }
 
     public static String determineSingleFacilityForStore(Delegator delegator, String productStoreId) {
         GenericValue productStore = null;

Modified: ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml (original)
+++ ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml Tue Nov  3 16:53:30 2015
@@ -39,8 +39,8 @@
     </form>
     <form name="EditProductStore" type="single" target="updateProductStore" title="" default-map-name="productStore"
         header-row-style="header-row" default-table-style="basic-table">
+        
         <alt-target use-when="productStore==null" target="createProductStore"/>
-
         <auto-fields-service service-name="updateProductStore" map-name=""/>
 
         <field use-when="productStore!=null" name="productStoreId" tooltip="${uiLabelMap.ProductNotModificationRecreatingProductStore}"><display/></field>
@@ -381,6 +381,7 @@
             <field-group title="${uiLabelMap.CommonLocalisation}" collapsible="true" initially-collapsed="true">
                 <sort-field name="defaultLocaleString"/>
                 <sort-field name="defaultCurrencyUomId"/>
+                <sort-field name="defaultTimeZoneString"/>
             </field-group>
             <field-group title="${uiLabelMap.ProductOrdersStatus}" collapsible="true" initially-collapsed="true">
                 <sort-field name="headerApprovedStatus"/>

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java Tue Nov  3 16:53:30 2015
@@ -70,6 +70,8 @@ public class UtilHttp {
     public static final int ROW_SUBMIT_PREFIX_LENGTH = ROW_SUBMIT_PREFIX.length();
     public static final int COMPOSITE_DELIMITER_LENGTH = COMPOSITE_DELIMITER.length();
 
+    public static final String SESSION_KEY_TIMEZONE = "timeZone";
+
     /**
      * Create a combined map from servlet context, session, attributes and parameters
      * @return The resulting Map
@@ -660,12 +662,18 @@ public class UtilHttp {
     }
 
     public static void setTimeZone(HttpSession session, TimeZone timeZone) {
-        session.setAttribute("timeZone", timeZone);
+        session.setAttribute(SESSION_KEY_TIMEZONE, timeZone);
+    }
+
+    public static void setTimeZoneIfNone(HttpSession session, String timeZoneString) {
+        if (UtilValidate.isNotEmpty(timeZoneString) && session.getAttribute(SESSION_KEY_TIMEZONE) == null) {
+            UtilHttp.setTimeZone(session, UtilDateTime.toTimeZone(timeZoneString));
+        }
     }
 
     public static TimeZone getTimeZone(HttpServletRequest request) {
         HttpSession session = request.getSession();
-        TimeZone timeZone = null;
+        TimeZone timeZone = (TimeZone) session.getAttribute(SESSION_KEY_TIMEZONE);
         Map<String, String> userLogin = UtilGenerics.cast(session.getAttribute("userLogin"));
         if (userLogin != null) {
             String tzId = userLogin.get("lastTimeZone");
@@ -676,10 +684,38 @@ public class UtilHttp {
         if (timeZone == null) {
             timeZone = TimeZone.getDefault();
         }
-        session.setAttribute("timeZone", timeZone);
+        session.setAttribute(SESSION_KEY_TIMEZONE, timeZone);
         return timeZone;
     }
 
+    public static TimeZone getTimeZone(HttpServletRequest request, HttpSession session, String appDefaultTimeZoneString) {
+        // check session first, should override all if anything set there
+        TimeZone timeZone = session != null ? (TimeZone) session.getAttribute(SESSION_KEY_TIMEZONE) : null;
+        
+        // next see if the userLogin has a value
+        if (timeZone == null) {
+            Map<String, Object> userLogin = UtilGenerics.checkMap(session.getAttribute("userLogin"), String.class, Object.class);
+            if (userLogin == null) {
+                userLogin = UtilGenerics.checkMap(session.getAttribute("autoUserLogin"), String.class, Object.class);
+            }
+
+            if ((userLogin != null) && (UtilValidate.isNotEmpty(userLogin.get("lastTimeZone")))) {
+                timeZone = UtilDateTime.toTimeZone((String) userLogin.get("lastTimeZone"));
+            }
+        }
+
+        // if there is no user TimeZone, we will got the application default time zone (if provided)
+        if ((timeZone == null) && (UtilValidate.isNotEmpty(appDefaultTimeZoneString))) {
+            timeZone = UtilDateTime.toTimeZone(appDefaultTimeZoneString);
+        }
+
+        // finally request (w/ a fall back to default)
+        if (timeZone == null) {
+            timeZone = TimeZone.getDefault();
+        }
+
+        return timeZone;
+    }
 
     /**
      * Get the currency string from the session.
@@ -717,7 +753,7 @@ public class UtilHttp {
         }
 
 
-        // if still none we will use the default for whatever locale we can get...
+        // if still none we will use the default for whatever currency we can get...
         if (iso == null) {
             Currency cur = Currency.getInstance(getLocale(session));
             iso = cur.getCurrencyCode();
@@ -933,7 +969,7 @@ public class UtilHttp {
             response.setContentType(contentType);
         }
         if (fileName != null) {
-            response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
+            setContentDisposition(response, fileName);
         }
 
         // create the streams
@@ -982,7 +1018,7 @@ public class UtilHttp {
             response.setContentType(contentType);
         }
         if (fileName != null) {
-            response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
+            setContentDisposition(response, fileName);
         }
 
         // stream the content
@@ -1397,4 +1433,10 @@ public class UtilHttp {
         request.setAttribute("UNIQUE_ID", Integer.valueOf(uniqueIdNumber.intValue() + 1));
         return "autoId_" + uniqueIdNumber;
     }
+
+    public static void setContentDisposition(final HttpServletResponse response, final String filename) {
+        String dispositionType = UtilProperties.getPropertyValue("requestHandler", "content-disposition-type", "attachment");
+        response.setHeader("Content-Disposition", String.format("%s; filename=\"%s\"", dispositionType, filename));
+    }
+
 }

Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/container/PosContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/container/PosContainer.java?rev=1712347&r1=1712346&r2=1712347&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/container/PosContainer.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/container/PosContainer.java Tue Nov  3 16:53:30 2015
@@ -19,9 +19,12 @@
 package org.ofbiz.pos.container;
 
 import java.util.Locale;
+import java.util.TimeZone;
 
 import org.ofbiz.base.container.ContainerConfig;
 import org.ofbiz.base.container.ContainerException;
+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.guiapp.xui.XuiContainer;
@@ -81,6 +84,13 @@ public class PosContainer extends XuiCon
         Locale locale = UtilMisc.parseLocale(localeStr);
         session.setAttribute("locale", locale);
 
+        // get the store timezone
+        String timeZoneStr = ContainerConfig.getPropertyValue(cc, "timeZone", null);
+        if (UtilValidate.isEmpty(timeZoneStr)) {
+            timeZoneStr = productStore.getString("defaultTimeZoneString");
+        }
+        session.setAttribute("timeZone", UtilDateTime.toTimeZone(timeZoneStr));    // this will get default is no timeZoneStr is provided
+        
         // get the store currency
         String currencyStr = ContainerConfig.getPropertyValue(cc, "currency", null);
         if (UtilValidate.isEmpty(currencyStr)) {