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

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


The following commit(s) were added to refs/heads/trunk by this push:
     new e7420fe4cf Improvements for ContentWorker methods and view-entities 
(OFBIZ-12829)
e7420fe4cf is described below

commit e7420fe4cf40f21e03bba3566d9b99d63a6e79a5
Author: Cheng Hu Shan <cheng-hu.s...@ecomify.de>
AuthorDate: Thu Jun 15 13:56:26 2023 +0200

    Improvements for ContentWorker methods and view-entities (OFBIZ-12829)
---
 .../ofbiz/content/content/ContentWorker.java       | 45 +++++++++++++++-------
 .../datamodel/entitydef/product-entitymodel.xml    |  4 +-
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git 
a/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java
 
b/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java
index 4f4171d786..f8a6f8953b 100644
--- 
a/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java
+++ 
b/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java
@@ -411,7 +411,33 @@ public class ContentWorker implements 
org.apache.ofbiz.widget.content.ContentWor
         }
     }
 
+    public static List<GenericValue> findAlternateLocaleContents(Delegator 
delegator, GenericValue view) {
+        return findAlternateLocaleContents(delegator, view, true);
+    }
+
+    public static List<GenericValue> findAlternateLocaleContents(Delegator 
delegator, GenericValue view,
+            boolean useCache) {
+        List<GenericValue> alternateViews = null;
+        try {
+            alternateViews = view.getRelated("ContentAssocDataResourceViewTo", 
UtilMisc.toMap("caContentAssocTypeId",
+                    "ALTERNATE_LOCALE"), UtilMisc.toList("-caFromDate"), 
useCache);
+
+            alternateViews = EntityUtil.filterByDate(alternateViews, 
UtilDateTime.nowTimestamp(), "caFromDate",
+                    "caThruDate", true);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Error finding alternate locale content: " + e, 
MODULE);
+            alternateViews = UtilMisc.toList(view);
+        }
+
+        return alternateViews;
+    }
+
     public static GenericValue findAlternateLocaleContent(Delegator delegator, 
GenericValue view, Locale locale) {
+        return findAlternateLocaleContent(delegator, view, locale, true);
+    }
+
+    public static GenericValue findAlternateLocaleContent(Delegator delegator, 
GenericValue view, Locale locale,
+            boolean useCache) {
         GenericValue contentAssocDataResourceViewFrom = null;
         if (locale == null) {
             return view;
@@ -420,16 +446,7 @@ public class ContentWorker implements 
org.apache.ofbiz.widget.content.ContentWor
         String localeStr = locale.toString();
         boolean isTwoLetterLocale = localeStr.length() == 2;
 
-        List<GenericValue> alternateViews = null;
-        try {
-            alternateViews = view.getRelated("ContentAssocDataResourceViewTo", 
UtilMisc.toMap("caContentAssocTypeId", "ALTERNATE_LOCALE"),
-                    UtilMisc.toList("-caFromDate"), true);
-        } catch (GenericEntityException e) {
-            Debug.logError(e, "Error finding alternate locale content: " + 
e.toString(), MODULE);
-            return view;
-        }
-
-        alternateViews = EntityUtil.filterByDate(alternateViews, 
UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true);
+        List<GenericValue> alternateViews = 
findAlternateLocaleContents(delegator, view, useCache);
         // also check the given view for a matching locale
         alternateViews.add(0, view);
 
@@ -445,25 +462,25 @@ public class ContentWorker implements 
org.apache.ofbiz.widget.content.ContentWor
             if (isTwoLetterLocale) {
                 if (currentLocaleLength == 2) {
                     // if the currentLocaleString is only a two letter code 
and the current one is a two and it matches, we are done
-                    if (localeStr.equals(currentLocaleString)) {
+                    if (localeStr.equalsIgnoreCase(currentLocaleString)) {
                         contentAssocDataResourceViewFrom = thisView;
                         break;
                     }
                 } else if (currentLocaleLength == 5) {
                     // if the currentLocaleString is only a two letter code 
and the current one is a five, match up but keep going
-                    if (localeStr.equals(currentLocaleString.substring(0, 2))) 
{
+                    if 
(localeStr.equalsIgnoreCase(currentLocaleString.substring(0, 2))) {
                         contentAssocDataResourceViewFrom = thisView;
                     }
                 }
             } else {
                 if (currentLocaleLength == 2) {
                     // if the currentLocaleString is a five letter code and 
the current one is a two and it matches, keep going
-                    if (localeStr.substring(0, 2).equals(currentLocaleString)) 
{
+                    if (localeStr.substring(0, 
2).equalsIgnoreCase(currentLocaleString)) {
                         contentAssocDataResourceViewFrom = thisView;
                     }
                 } else if (currentLocaleLength == 5) {
                     // if the currentLocaleString is a five letter code and 
the current one is a five, if it matches we are done
-                    if (localeStr.equals(currentLocaleString)) {
+                    if (localeStr.equalsIgnoreCase(currentLocaleString)) {
                         contentAssocDataResourceViewFrom = thisView;
                         break;
                     }
diff --git a/applications/datamodel/entitydef/product-entitymodel.xml 
b/applications/datamodel/entitydef/product-entitymodel.xml
index 6adaa70f0d..560d1d45ad 100644
--- a/applications/datamodel/entitydef/product-entitymodel.xml
+++ b/applications/datamodel/entitydef/product-entitymodel.xml
@@ -286,7 +286,7 @@ under the License.
       <view-link entity-alias="PCC" rel-entity-alias="CO">
         <key-map field-name="contentId"/>
       </view-link>
-      <view-link entity-alias="CO" rel-entity-alias="DR">
+      <view-link entity-alias="CO" rel-entity-alias="DR" rel-optional="true">
         <key-map field-name="dataResourceId"/>
       </view-link>
       <relation type="one-nofk" rel-entity-name="ElectronicText">
@@ -3104,7 +3104,7 @@ under the License.
       <view-link entity-alias="PC" rel-entity-alias="CO">
         <key-map field-name="contentId"/>
       </view-link>
-      <view-link entity-alias="CO" rel-entity-alias="DR">
+      <view-link entity-alias="CO" rel-entity-alias="DR" rel-optional="true">
         <key-map field-name="dataResourceId"/>
       </view-link>
       <relation type="one-nofk" rel-entity-name="ElectronicText">

Reply via email to