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 2022/04/06 09:06:36 UTC

[ofbiz-framework] branch release22.01 updated (3284ad3994 -> 174ad12179)

This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a change to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


    from 3284ad3994 Improved: Prevent Freemarker interpolation in fields (OFBIZ-12594)
     new 4a5b0f829b Fixed: testInvoicePerShipmentSetFalse work with runtime configuration data (OFBIZ-12453)
     new 174ad12179 Fixed: Prevent Freemarker interpolation in fields (OFBIZ-12594)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../data/AccountingSystemPropertyData.xml          | 16 ++++----
 .../accounting/InvoicePerShipmentTests.groovy      | 48 ++++++++++------------
 .../org/apache/ofbiz/base/util/UtilProperties.java | 26 +++++++++++-
 .../apache/ofbiz/webapp/control/ControlFilter.java |  1 +
 4 files changed, 55 insertions(+), 36 deletions(-)


[ofbiz-framework] 01/02: Fixed: testInvoicePerShipmentSetFalse work with runtime configuration data (OFBIZ-12453)

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 4a5b0f829b0e834e70631a64e5b0c53cbe3d836e
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Tue Apr 5 17:44:28 2022 +0200

    Fixed: testInvoicePerShipmentSetFalse work with runtime configuration data (OFBIZ-12453)
    
    UtilProperties::setPropertyValueInMemory was only based on files. Thinking by
    analogy, as Pierre pushed SystemProperties with OFBIZ-6189, I thought that by
    adding an UtilProperties::setPropertyValueInMemory based on
    EntityUtilProperties::getProperties it would resolve the issue. But it did not.
    
    Looking closer at the code, I wondered why UtilProperties::setPropertyValueInMemory
    was used at all.
    
    This fixes the issue by simply removing setPropertyValueInMemory and setting "Y"
    or "N" when calling testInvoicePerShipment.
    
    It though keeps the new UtilProperties::setPropertyValueInMemory variant
---
 .../data/AccountingSystemPropertyData.xml          | 16 ++++----
 .../accounting/InvoicePerShipmentTests.groovy      | 48 ++++++++++------------
 .../org/apache/ofbiz/base/util/UtilProperties.java | 26 +++++++++++-
 3 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/applications/accounting/data/AccountingSystemPropertyData.xml b/applications/accounting/data/AccountingSystemPropertyData.xml
index 09464b9912..a08269121e 100644
--- a/applications/accounting/data/AccountingSystemPropertyData.xml
+++ b/applications/accounting/data/AccountingSystemPropertyData.xml
@@ -18,7 +18,7 @@ specific language governing permissions and limitations
 under the License.
 -->
 <entity-engine-xml>
-<!-- 
+<!--
 # what should the default of the payment to invoice processing be?
 # paymentProcessing by invoice or paymentprocessing by invoiceitem?
 # there is still a box on the menu to change this option by the user.
@@ -27,27 +27,27 @@ under the License.
 #value YY: do not show the option box to the user and do only invoice processing
 #value NN: do not show the option box to the user and do only invoiceitem processing
 -->
-    <SystemProperty systemResourceId="accounting" systemPropertyId="invoiceProcessing" 
+    <SystemProperty systemResourceId="accounting" systemPropertyId="invoiceProcessing"
     systemPropertyValue="YY"
     description="Options are: Y, N, YY, NN"
     />
 
-    <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.fixedasset.autocreate" 
+    <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.fixedasset.autocreate"
     systemPropertyValue="Y"
     description="Create a fixed asset when an 'asset usage' type product is created. Options: Y, N"/>
 
-    <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.payment.application.autocreate" 
+    <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.payment.application.autocreate"
     systemPropertyValue="Y"
     description="Create a payment application when a payment is received/sent or invoice is approved (take the oldest not closed one). Options: Y, N"/>
 
-   <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.payment.purchaseorder.autocreate" 
+   <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.payment.purchaseorder.autocreate"
     systemPropertyValue="Y"
     description="Create a 'not-paid' payment record if the purchase order is approved. Options: Y, N"/>
 
-    <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.payment.salesorder.autocreate" 
+    <SystemProperty systemResourceId="accounting" systemPropertyId="accounting.payment.salesorder.autocreate"
     systemPropertyValue="Y"
     description="Create a 'not-paid' payment record if the sales order is completed and no payment exist yet. Options:: Y, N"/>
 
-    <!-- <SystemProperty systemResourceId="accounting" systemPropertyId="create.invoice.per.shipment" systemPropertyValue="Y"
-    description="create invoice per shipment. Options: = Y (Invoice per shipment), N (Invoice per order)"/> -->
+    <SystemProperty systemResourceId="accounting" systemPropertyId="create.invoice.per.shipment" systemPropertyValue="Y"
+    description="create invoice per shipment. Options: = Y (Invoice per shipment), N (Invoice per order)"/>
 </entity-engine-xml>
diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy
index fe81f7db1e..55146ff581 100644
--- a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy
+++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy
@@ -19,7 +19,7 @@
 package org.apache.ofbiz.accounting
 
 import javax.servlet.http.HttpSession
-import org.apache.ofbiz.base.util.UtilProperties
+
 import org.apache.ofbiz.base.util.UtilValidate
 import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.order.shoppingcart.CheckOutEvents
@@ -142,49 +142,43 @@ public class InvoicePerShipmentTests extends OFBizTestCase {
     }
     void testInvoicePerShipmentSetFalse() {
         /* Test Invoice Per Shipment
-            Step 1) Set create.invoice.per.shipment=N in accounting.properties file.
-            Step 2) Create order and approve order.
-            Step 3) Pack Shipment For Ship Group.
-            Step 4) Check invoice should not created.
-        */
-        UtilProperties.setPropertyValueInMemory("accounting", "create.invoice.per.shipment", "N")
-        logInfo("===== >>> Set Accounting.properties / create.invoice.per.shipment = N")
-
-        List invoices = testInvoicePerShipment("GZ-1000", null)
+         Step 1) Set create.invoice.per.shipment=N in accounting.properties file.
+         Step 2) Create order and approve order.
+         Step 3) Pack Shipment For Ship Group.
+         Step 4) Check invoice should not created.
+         */
+        List invoices = testInvoicePerShipment("GZ-1000", "N")
         assert UtilValidate.isEmpty(invoices)
     }
 
     void testInvoicePerShipmentSetTrue() {
         /* Test Invoice Per Shipment
-             Step 1) Set create.invoice.per.shipment=Y in accounting.properties file.
-             Step 2) Create order and approve order.
-             Step 3) Pack Shipment For Ship Group.
-             Step 4) Check invoice should be created.
+         Step 1) Set create.invoice.per.shipment=Y in accounting.properties file.
+         Step 2) Create order and approve order.
+         Step 3) Pack Shipment For Ship Group.
+         Step 4) Check invoice should be created.
          */
-        UtilProperties.setPropertyValueInMemory("accounting", "create.invoice.per.shipment", "Y")
-        logInfo("===== >>> Set Accounting.properties / create.invoice.per.shipment = Y")
-
-        List invoices = testInvoicePerShipment("GZ-1000", null)
+        List invoices = testInvoicePerShipment("GZ-1000", "Y")
         assert UtilValidate.isNotEmpty(invoices)
     }
 
     void testInvoicePerShipmentSetOrderFalse() {
         /* Test Invoice Per Shipment
-            Step 1) Create order and set invoicePerShipment=N.
-            Step 2) Pack Shipment For Ship Group.
-            Step 3) Check invoice should not be created.
-        */
+         Step 1) Create order and set invoicePerShipment=N.
+         Step 2) Pack Shipment For Ship Group.
+         Step 3) Check invoice should not be created.
+         */
         List invoices = testInvoicePerShipment("GZ-2644", "N")
         assert UtilValidate.isEmpty(invoices)
     }
 
     void testInvoicePerShipmentSetOrderTrue() {
         /* Test Invoice Per Shipment
-            Step 1) Create order and set invoicePerShipment=Y
-            Step 2) Pack Shipment For Ship Group.
-            Step 3) Check invoice should be created.
-        */
+         Step 1) Create order and set invoicePerShipment=Y
+         Step 2) Pack Shipment For Ship Group.
+         Step 3) Check invoice should be created.
+         */
         List invoices = testInvoicePerShipment("GZ-2644", "Y")
         assert UtilValidate.isNotEmpty(invoices)
     }
-}
\ No newline at end of file
+}
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
index 8b1f313ae7..5ac0897f26 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
@@ -46,6 +46,8 @@ import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.cache.UtilCache;
 import org.apache.ofbiz.base.util.collections.ResourceBundleMapWrapper;
 import org.apache.ofbiz.base.util.string.FlexibleStringExpander;
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.util.EntityUtilProperties;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -501,7 +503,29 @@ public final class UtilProperties implements Serializable {
             return;
         }
 
-        Properties properties = getProperties(resource);
+        Properties properties = UtilProperties.getProperties(resource);
+        if (properties == null) {
+            return;
+        }
+        properties.setProperty(name, value);
+    }
+
+    /**
+     * Sets the specified value of the specified property name to the specified resource/properties in memory, does not persist it
+     * @param delegator Default delegator, mostly used in tests
+     * @param resource The name of the resource
+     * @param name     The name of the property in the resource
+     * @param value    The value of the property to set in memory
+     */
+    public static void setPropertyValueInMemory(Delegator delegator, String resource, String name, String value) {
+        if (UtilValidate.isEmpty(resource)) {
+            return;
+        }
+        if (UtilValidate.isEmpty(name)) {
+            return;
+        }
+
+        Properties properties = EntityUtilProperties.getProperties(delegator, resource);
         if (properties == null) {
             return;
         }


[ofbiz-framework] 02/02: Fixed: Prevent Freemarker interpolation in fields (OFBIZ-12594)

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 174ad12179e45f59ff9b79fc62b566a56b54f508
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Wed Apr 6 10:59:56 2022 +0200

    Fixed: Prevent Freemarker interpolation in fields (OFBIZ-12594)
    
    I did not catch an issue put in by this feature because BuildBot is not running
    for few days (see INFRA-23076) and i don't always run tests locally (relying on
    BuildBot and GH actions don't run tests).
    
    This is the error Solr tests throw else:
    <<Unfortunately, the stream was empty / not available. This may be caused by
    another servlet filter calling ServletRequest.getParameter*() before
    SolrDispatchFilter>>
---
 .../src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java     | 1 +
 1 file changed, 1 insertion(+)

diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
index 8c76628225..31c6fc78e1 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
@@ -150,6 +150,7 @@ public class ControlFilter extends HttpFilter {
             String uri = uriWithContext.substring(context.length());
 
             if (!GenericValue.getStackTraceAsString().contains("ControlFilterTests")
+                    && !System.getProperty("java.class.path").contains("--test component=solr") // Allows Solr tests
                     && SecurityUtil.containsFreemarkerInterpolation(req, resp, uri)) {
                 return;
             }