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

pgil 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 531f2bda92 Improved:  Add alternative to performFind group option 
(OFBIZ-13184) (#860)
531f2bda92 is described below

commit 531f2bda92095f2693e6f70cb1711326b588600e
Author: Gil Portenseigne <[email protected]>
AuthorDate: Mon Dec 2 08:59:13 2024 +0100

    Improved:  Add alternative to performFind group option (OFBIZ-13184) (#860)
    
    * Test creation before refactor createConditionList method
    
    * Refactor createConditionList to avoid redundancy
    
    * Implementation and test of OR_AND alternative
---
 framework/common/servicedef/services.xml           |  16 +++
 .../java/org/apache/ofbiz/common/FindServices.java | 111 ++++++++++---------
 .../apache/ofbiz/common/test/PerformFindTests.java | 119 ++++++++++++++++++---
 3 files changed, 173 insertions(+), 73 deletions(-)

diff --git a/framework/common/servicedef/services.xml 
b/framework/common/servicedef/services.xml
index 698610395d..c085669321 100644
--- a/framework/common/servicedef/services.xml
+++ b/framework/common/servicedef/services.xml
@@ -216,6 +216,14 @@ under the License.
         <attribute name="filterByDateValue" type="Timestamp" mode="IN" 
optional="true"/>
         <attribute name="fromDateName" type="String" mode="IN" 
optional="true"/>
         <attribute name="thruDateName" type="String" mode="IN" 
optional="true"/>
+        <attribute name="groupConditionOperator" type="String" mode="IN" 
optional="true">
+            <description>
+                Defines how the group condition will be applied, default is 
AND_OR:
+                    (group1_v1 AND group1_v2) OR (group2_v1 AND group2_v2) AND 
no_group
+                Alternative is OR_AND:
+                    (group1_v1 OR group1_v2) AND (group2_v1 OR group2_v2) AND 
no_group
+            </description>
+        </attribute>
         <attribute name="queryString" type="String" mode="OUT" 
optional="true"/>
         <attribute name="queryStringMap" type="java.util.Map" mode="OUT" 
optional="true"/>
         <attribute name="orderByList" type="java.util.List" mode="OUT" 
optional="true"/>
@@ -251,6 +259,14 @@ under the License.
         <attribute name="thruDateName" type="String" mode="IN" 
optional="true"/>
         <attribute name="viewIndex" type="Integer" mode="IN" optional="true"/>
         <attribute name="viewSize" type="Integer" mode="IN" optional="true"/>
+        <attribute name="groupConditionOperator" type="String" mode="IN" 
optional="true">
+            <description>
+                Defines how the group condition will be applied, default is 
AND_OR:
+                (group1_v1 AND group1_v2) OR (group2_v1 AND group2_v2) AND 
no_group
+                Alternative is OR_AND:
+                (group1_v1 OR group1_v2) AND (group2_v1 OR group2_v2) AND 
no_group
+            </description>
+        </attribute>
         <attribute name="listIt" 
type="org.apache.ofbiz.entity.util.EntityListIterator" mode="OUT" 
optional="true"/>
         <attribute name="listSize" type="Integer" mode="OUT" optional="true"/>
         <attribute name="queryString" type="String" mode="OUT" 
optional="true"/>
diff --git 
a/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java 
b/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
index 239a013167..73522f4a4a 100644
--- a/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
+++ b/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
@@ -22,6 +22,7 @@ import static 
org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
 import static org.apache.ofbiz.base.util.UtilGenerics.checkMap;
 
 import java.sql.Timestamp;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -32,6 +33,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TimeZone;
+import java.util.stream.Collectors;
 
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.ObjectType;
@@ -50,6 +52,7 @@ import 
org.apache.ofbiz.entity.condition.EntityComparisonOperator;
 import org.apache.ofbiz.entity.condition.EntityCondition;
 import org.apache.ofbiz.entity.condition.EntityConditionList;
 import org.apache.ofbiz.entity.condition.EntityFunction;
+import org.apache.ofbiz.entity.condition.EntityJoinOperator;
 import org.apache.ofbiz.entity.condition.EntityOperator;
 import org.apache.ofbiz.entity.model.DynamicViewEntity;
 import org.apache.ofbiz.entity.model.ModelEntity;
@@ -73,6 +76,7 @@ public class FindServices {
     private static final String MODULE = FindServices.class.getName();
     private static final String RESOURCE = "CommonUiLabels";
     public static final Map<String, EntityComparisonOperator<?, ?>> 
ENTITY_OPERATORS;
+    public static final List<String> PERFORMFIND_SEARCH_SUFFIXES = 
List.of("_ic", "_op", "_grp", "_value");
 
     static {
         ENTITY_OPERATORS = new LinkedHashMap<>();
@@ -166,7 +170,8 @@ public class FindServices {
                         fieldPair = suffix;
                         fieldMode = "value";
                     } else {
-                        // if it does not start with fld, assume it is an op 
or the 'ignore case' (ic) field
+                        // if it does not start with fld,
+                        // assume it is an op or the 'ignore case' (ic) field
                         fieldPair = "fld0";
                         fieldMode = suffix;
                     }
@@ -216,61 +221,38 @@ public class FindServices {
      * @param context
      * @return returns an EntityCondition list
      */
-    public static List<EntityCondition> createConditionList(Map<String, ? 
extends Object> parameters, List<ModelField> fieldList,
-                                                            Map<String, 
Object> queryStringMap, Delegator delegator, Map<String, ?> context) {
+    public static List<EntityCondition> createConditionList(Map<String, ?> 
parameters, List<ModelField> fieldList, Map<String, Object> queryStringMap,
+                                                            Delegator 
delegator, Map<String, ?> context, String groupConditionOperator) {
         Set<String> processed = new LinkedHashSet<>();
         Set<String> keys = new LinkedHashSet<>();
         Map<String, ModelField> fieldMap = new LinkedHashMap<>();
-        /**
+        /*
          * When inputFields contains several xxxx_grp, yyyy_grp ... values,
-         * Corresponding conditions will grouped by an {@link 
EntityOperator.AND} then all added to final
+         * Corresponding conditions will group depending on {@param 
groupConditionOperator}
+         * Default behaviour is grouping by an {@link EntityOperator.AND} then 
all added to final
          * condition grouped by an {@link EntityOperator.OR}
-         * That will allow union of search criteria, instead of default 
intersection.
+         * "OR_AND" behaviour is grouping by an {@link EntityOperator.OR} then 
all added to final
+         * condition grouped by an {@link EntityOperator.AND}
          */
+        EntityJoinOperator operatorInsideGroup = 
"OR_AND".equals(groupConditionOperator) ? EntityOperator.OR : 
EntityOperator.AND;
+        EntityJoinOperator operatorBetweenGroups = 
"OR_AND".equals(groupConditionOperator) ? EntityOperator.AND : 
EntityOperator.OR;
         Map<String, List<EntityCondition>> savedGroups = new LinkedHashMap<>();
         for (ModelField modelField : fieldList) {
             fieldMap.put(modelField.getName(), modelField);
         }
         List<EntityCondition> result = new LinkedList<>();
         for (Map.Entry<String, ? extends Object> entry : 
parameters.entrySet()) {
-            String currentGroup = null;
             String parameterName = entry.getKey();
             if (processed.contains(parameterName)) {
                 continue;
             }
             keys.clear();
-            String fieldName = parameterName;
-            Object fieldValue = null;
-            String operation = null;
-            boolean ignoreCase = false;
-            if (parameterName.endsWith("_ic") || 
parameterName.endsWith("_op")) {
-                fieldName = parameterName.substring(0, parameterName.length() 
- 3);
-            } else if (parameterName.endsWith("_value")) {
-                fieldName = parameterName.substring(0, parameterName.length() 
- 6);
-            }
+            String fieldName = extractFieldNameIfSuffix(parameterName, 
PERFORMFIND_SEARCH_SUFFIXES);
+            String currentGroup = (String) 
getValueFromParametersWithSuffix(fieldName, parameters, "_grp", keys);
+            boolean ignoreCase = 
"Y".equals(getValueFromParametersWithSuffix(fieldName, parameters, "_ic", 
keys));
+            String operation = (String) 
getValueFromParametersWithSuffix(fieldName, parameters, "_op", keys);
+            Object fieldValue = getValueFromParametersWithSuffix(fieldName, 
parameters, "_value", keys);
 
-            String key = fieldName.concat("_grp");
-            if (parameters.containsKey(key)) {
-                if (parameters.containsKey(key)) {
-                    keys.add(key);
-                }
-                currentGroup = (String) parameters.get(key);
-            }
-            key = fieldName.concat("_ic");
-            if (parameters.containsKey(key)) {
-                keys.add(key);
-                ignoreCase = "Y".equals(parameters.get(key));
-            }
-            key = fieldName.concat("_op");
-            if (parameters.containsKey(key)) {
-                keys.add(key);
-                operation = (String) parameters.get(key);
-            }
-            key = fieldName.concat("_value");
-            if (parameters.containsKey(key)) {
-                keys.add(key);
-                fieldValue = parameters.get(key);
-            }
             if (fieldName.endsWith("_fld0") || fieldName.endsWith("_fld1")) {
                 if (parameters.containsKey(fieldName)) {
                     keys.add(fieldName);
@@ -291,31 +273,43 @@ public class FindServices {
             if (ObjectType.isEmpty(fieldValue) && !"empty".equals(operation)) {
                 continue;
             }
-            if (UtilValidate.isNotEmpty(currentGroup)) {
-                List<EntityCondition> groupedConditions = new LinkedList<>();
-                if (savedGroups.get(currentGroup) != null) {
-                    groupedConditions.addAll(savedGroups.get(currentGroup));
-                }
-                groupedConditions.add(createSingleCondition(modelField, 
operation, fieldValue, ignoreCase, delegator, context));
-                savedGroups.put(currentGroup, groupedConditions);
-            } else {
-                result.add(createSingleCondition(modelField, operation, 
fieldValue, ignoreCase, delegator, context));
-            }
 
-            for (String mapKey : keys) {
-                queryStringMap.put(mapKey, parameters.get(mapKey));
+            EntityCondition cond = createSingleCondition(modelField, 
operation, fieldValue, ignoreCase, delegator, context);
+            if (UtilValidate.isEmpty(currentGroup)) {
+                result.add(cond);
+            } else {
+                savedGroups.computeIfAbsent(currentGroup, k -> new 
ArrayList<>())
+                        .add(cond);
             }
+            keys.forEach(mapKey -> queryStringMap.put(mapKey, 
parameters.get(mapKey)));
         }
-        //Add OR-grouped conditions
-        List<EntityCondition> orConditions = new LinkedList<>();
-        for (String groupedConditions : savedGroups.keySet()) {
-            
orConditions.add(EntityCondition.makeCondition(savedGroups.get(groupedConditions)));
+        List<EntityCondition> orConditions = savedGroups.keySet().stream()
+                .map(groupName -> 
EntityCondition.makeCondition(savedGroups.get(groupName), operatorInsideGroup))
+                .collect(Collectors.toList());
+
+        if (UtilValidate.isNotEmpty(orConditions)) {
+            result.add(EntityCondition.makeCondition(orConditions, 
operatorBetweenGroups));
         }
-        if (!orConditions.isEmpty()) 
result.add(EntityCondition.makeCondition(orConditions, EntityOperator.OR));
 
         return result;
     }
 
+    private static Object getValueFromParametersWithSuffix(String fieldName, 
Map<String, ?> parameters, String suffix, Set<String> keys) {
+        String key = fieldName.concat(suffix);
+        if (parameters.containsKey(key)) {
+            keys.add(key);
+            return parameters.get(key);
+        }
+        return null;
+    }
+
+    private static String extractFieldNameIfSuffix(String parameterName, 
List<String> suffixes) {
+        return suffixes.stream()
+                .filter(parameterName::endsWith)
+                .map(suffix -> parameterName.substring(0, 
parameterName.length() - suffix.length()))
+                .findFirst().orElse(parameterName);
+    }
+
     /**
      * Creates a single <code>EntityCondition</code> based on a set of 
parameters.
      * @param modelField
@@ -505,6 +499,7 @@ public class FindServices {
         String entityName = (String) context.get("entityName");
         DynamicViewEntity dynamicViewEntity = (DynamicViewEntity) 
context.get("dynamicViewEntity");
         String orderBy = (String) context.get("orderBy");
+        String groupConditionOperator = (String) 
context.get("groupConditionOperator");
         Map<String, ?> inputFields = checkMap(context.get("inputFields"), 
String.class, Object.class); // Input
         String noConditionFind = (String) context.get("noConditionFind");
         String distinct = (String) context.get("distinct");
@@ -549,7 +544,7 @@ public class FindServices {
         Map<String, Object> prepareResult = null;
         try {
             prepareResult = dispatcher.runSync("prepareFind", 
UtilMisc.toMap("entityName", entityName, "orderBy", orderBy,
-                                               "dynamicViewEntity", 
dynamicViewEntity,
+                                               "dynamicViewEntity", 
dynamicViewEntity, "groupConditionOperator", groupConditionOperator,
                                                "inputFields", inputFields, 
"filterByDate", filterByDate, "noConditionFind", noConditionFind,
                                                "filterByDateValue", 
filterByDateValue, "userLogin", userLogin, "fromDateName", fromDateName,
                     "thruDateName", thruDateName,
@@ -598,6 +593,7 @@ public class FindServices {
         DynamicViewEntity dynamicViewEntity = (DynamicViewEntity) 
context.get("dynamicViewEntity");
         Delegator delegator = dctx.getDelegator();
         String orderBy = (String) context.get("orderBy");
+        String groupConditionOperator = (String) 
context.get("groupConditionOperator");
         Map<String, ?> inputFields = checkMap(context.get("inputFields"), 
String.class, Object.class); // Input
         String noConditionFind = (String) context.get("noConditionFind");
         if (UtilValidate.isEmpty(noConditionFind)) {
@@ -628,7 +624,8 @@ public class FindServices {
         } else {
             modelEntity = delegator.getModelEntity(entityName);
         }
-        List<EntityCondition> tmpList = createConditionList(inputFields, 
modelEntity.getFieldsUnmodifiable(), queryStringMap, delegator, context);
+        List<EntityCondition> tmpList = createConditionList(inputFields, 
modelEntity.getFieldsUnmodifiable(),
+                queryStringMap, delegator, context, groupConditionOperator);
 
         /* the filter by date condition should only be added when there are 
other conditions or when
          * the user has specified a noConditionFind.  Otherwise, specifying 
filterByDate will become
diff --git 
a/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java
 
b/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java
index 6732853a7d..9c97669b8a 100644
--- 
a/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java
+++ 
b/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java
@@ -60,15 +60,17 @@ public class PerformFindTests extends OFBizTestCase {
         Delegator delegator = getDelegator();
         if 
(EntityQuery.use(delegator).from("TestingType").where("testingTypeId", 
"PERFOMFINDTEST").cache().queryOne() == null) {
             delegator.create("TestingType", "testingTypeId", "PERFOMFINDTEST");
-            delegator.create("Testing", "testingId", "PERF_TEST_1", 
"testingTypeId", "PERFOMFINDTEST", "testingName", "nice name one");
-            delegator.create("Testing", "testingId", "PERF_TEST_2", 
"testingTypeId", "PERFOMFINDTEST", "testingName", "nice other name two");
-            delegator.create("Testing", "testingId", "PERF_TEST_3", 
"testingTypeId", "PERFOMFINDTEST", "testingName", "medium name three");
-            delegator.create("Testing", "testingId", "PERF_TEST_4", 
"testingTypeId", "PERFOMFINDTEST", "testingName", "bad nme four");
-            delegator.create("Testing", "testingId", "PERF_TEST_5", 
"testingTypeId", "PERFOMFINDTEST", "testingName", "nice name one");
-            delegator.create("Testing", "testingId", "PERF_TEST_6", 
"testingTypeId", "PERFOMFINDTEST");
-            delegator.create("Testing", "testingId", "PERF_TEST_7", 
"testingTypeId", "PERFOMFINDTEST");
-            delegator.create("Testing", "testingId", "PERF_TEST_8", 
"testingTypeId", "PERFOMFINDTEST");
-            delegator.create("Testing", "testingId", "PERF_TEST_9", 
"testingTypeId", "PERFOMFINDTEST");
+            delegator.create("TestingType", "testingTypeId", 
"PERFOMFINDGROUPTEST");
+            createTestingValue(delegator, "PERF_TEST_1", 1, "PERFOMFINDTEST", 
"nice name one", "nice description");
+            createTestingValue(delegator, "PERF_TEST_2", 1, "PERFOMFINDTEST", 
"nice other name two", "bad description");
+            createTestingValue(delegator, "PERF_TEST_3", 1, "PERFOMFINDTEST", 
"medium name three", "medium description");
+            createTestingValue(delegator, "PERF_TEST_4", 1, "PERFOMFINDTEST", 
"bad nme four", null);
+            createTestingValue(delegator, "PERF_TEST_5", 1, "PERFOMFINDTEST", 
"nice name one", null);
+            createTestingValue(delegator, "PERF_TEST_6", 1, "PERFOMFINDTEST", 
null, null);
+            createTestingValue(delegator, "PERF_TEST_7", 1, "PERFOMFINDTEST", 
null, null);
+            createTestingValue(delegator, "PERF_TEST_8", 1, "PERFOMFINDTEST", 
null, null);
+            createTestingValue(delegator, "PERF_TEST_9", 2, "PERFOMFINDTEST", 
"nice name bad nine", "nice description");
+            createTestingValue(delegator, "PERF_TEST_10", 1, 
"PERFOMFINDGROUPTEST", null, null);
 
             Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
             delegator.create("TestingNode", "testingNodeId", "NODE_1", 
"description", "Date Node");
@@ -100,9 +102,19 @@ public class PerformFindTests extends OFBizTestCase {
         }
     }
 
+    private static void createTestingValue(Delegator delegator, String 
testingId, int testingSize,
+                                           String testingTypeId, String 
testingName, String description) throws GenericEntityException {
+        delegator.create("Testing",
+                "testingId", testingId,
+                "testingSize", testingSize,
+                "testingTypeId", testingTypeId,
+                "testingName", testingName,
+                "description", description);
+    }
+
     /**
      * Main test function to call other test.
-     * If each function call by junit, it generate an random error with DBCP
+     * If each function call by junit, it generates a random error with DBCP
      * See the issue OFBIZ-6218 Unit tests throw exception in DBCP for more 
details
      * @throws Exception
      */
@@ -111,6 +123,9 @@ public class PerformFindTests extends OFBizTestCase {
         performFindConditionFieldLike();
         performFindConditionDistinct();
         performFindFilterByDate();
+        performFindGroup();
+        performFindGroupOrAnd();
+        performFindDateFindAndIgnoreCase();
         performFindFilterByDateWithDedicateDateField();
     }
 
@@ -132,7 +147,7 @@ public class PerformFindTests extends OFBizTestCase {
         result = dispatcher.runSync("performFind", performFindMap);
         assertTrue(ServiceUtil.isSuccess(result));
         foundElements = getCompleteList(result);
-        assertEquals("performFind search without condition with 
noConditionFind Y", 9, foundElements.size());
+        assertEquals("performFind search without condition with 
noConditionFind Y", 10, foundElements.size());
 
         //third test with equals condition on testingTypeId
         inputFields = UtilMisc.toMap("testingTypeId", "PERFOMFINDTEST");
@@ -140,7 +155,10 @@ public class PerformFindTests extends OFBizTestCase {
         result = dispatcher.runSync("performFind", performFindMap);
         assertTrue(ServiceUtil.isSuccess(result));
         foundElements = getCompleteList(result);
-        List<GenericValue> testingElements = getDelegator().findAll("Testing", 
false);
+        List<GenericValue> testingElements = EntityQuery.use(getDelegator())
+                .from("Testing")
+                .where("testingTypeId", "PERFOMFINDTEST")
+                .queryList();
         assertEquals("performFind search without condition with equals on 
testingTypeId", testingElements.size(), foundElements.size());
 
         //fourth test with equals condition on testingId
@@ -163,7 +181,7 @@ public class PerformFindTests extends OFBizTestCase {
         Map<String, Object> result = dispatcher.runSync("performFind", 
performFindMap);
         assertTrue(ServiceUtil.isSuccess(result));
         List<GenericValue> foundElements = getCompleteList(result);
-        assertEquals("performFind search with like nice% condition", 3, 
foundElements.size());
+        assertEquals("performFind search with like nice% condition", 4, 
foundElements.size());
 
         //second test contains condition
         inputFields = UtilMisc.toMap("testingName", "name", "testingName_op", 
"contains");
@@ -171,7 +189,7 @@ public class PerformFindTests extends OFBizTestCase {
         result = dispatcher.runSync("performFind", performFindMap);
         assertTrue(ServiceUtil.isSuccess(result));
         foundElements = getCompleteList(result);
-        assertEquals("performFind search with like %name% condition", 4, 
foundElements.size());
+        assertEquals("performFind search with like %name% condition", 5, 
foundElements.size());
 
         //third test not-like condition
         inputFields = UtilMisc.toMap("testingName", "bad", "testingName_op", 
"not-like");
@@ -179,7 +197,7 @@ public class PerformFindTests extends OFBizTestCase {
         result = dispatcher.runSync("performFind", performFindMap);
         assertTrue(ServiceUtil.isSuccess(result));
         foundElements = getCompleteList(result);
-        assertEquals("performFind search with not like bad% condition", 4, 
foundElements.size());
+        assertEquals("performFind search with not like bad% condition", 5, 
foundElements.size());
 
         //fourth test not-contains condition
         inputFields = UtilMisc.toMap("testingName", "name", "testingName_op", 
"not-contains");
@@ -211,7 +229,7 @@ public class PerformFindTests extends OFBizTestCase {
         result = dispatcher.runSync("performFind", performFindMap);
         assertTrue(ServiceUtil.isSuccess(result));
         foundElements = getCompleteList(result);
-        assertEquals("performFind search with distinct Y", 5, 
foundElements.size());
+        assertEquals("performFind search with distinct Y", 6, 
foundElements.size());
     }
 
     private void performFindFilterByDate() throws Exception {
@@ -237,6 +255,75 @@ public class PerformFindTests extends OFBizTestCase {
         assertEquals("performFind search with filterDate Y", 3, 
foundElements.size());
     }
 
+    /*
+     * Find all Testing value with
+     * both `nice` in name and description,
+     * or with type `PERFOMFINDGROUPTEST`,
+     * and that size is `1`.
+     */
+    private void performFindGroup() throws Exception {
+        prepareData();
+        LocalDispatcher dispatcher = getDispatcher();
+        GenericValue userLogin = getUserLogin("system");
+
+        Map<String, Object> inputFields = UtilMisc.toMap(
+                "testingName", "nice", "testingName_grp", "1", 
"testingName_op", "contains",
+                "description", "nice", "description_grp", "1", 
"description_op", "contains",
+                "testingTypeId", "PERFOMFINDGROUPTEST", "testingTypeId_grp", 
"2",
+                "testingSize", 1);
+
+        Map<String, Object> performFindMap = UtilMisc.toMap("userLogin", 
userLogin, "entityName", "Testing", "inputFields", inputFields);
+        Map<String, Object> result = dispatcher.runSync("performFind", 
performFindMap);
+        assertTrue(ServiceUtil.isSuccess(result));
+        List<GenericValue> foundElements = getCompleteList(result);
+        assertEquals("performFind search with group condition", 2, 
foundElements.size());
+        assertTrue(foundElements.stream().allMatch(genericValue ->
+                List.of("PERF_TEST_1", 
"PERF_TEST_10").contains(genericValue.getString("testingId"))));
+    }
+
+    /*
+     * Find all Testing value with `nice` in name or description
+     * and that are type `PERFOMFINDTEST`
+     * and that size is `1`.
+     */
+    private void performFindGroupOrAnd() throws Exception {
+        prepareData();
+        LocalDispatcher dispatcher = getDispatcher();
+        GenericValue userLogin = getUserLogin("system");
+        Map<String, Object> inputFields = UtilMisc.toMap(
+                "testingName", "nice", "testingName_grp", "1", 
"testingName_op", "contains",
+                "description", "nice", "description_grp", "1", 
"description_op", "contains",
+                "testingTypeId", "PERFOMFINDTEST", "testingTypeId_grp", "2",
+                "testingSize", 1);
+
+        Map<String, Object> performFindMap = UtilMisc.toMap("userLogin", 
userLogin, "entityName", "Testing",
+                "inputFields", inputFields, "groupConditionOperator", 
"OR_AND");
+        Map<String, Object> result = dispatcher.runSync("performFind", 
performFindMap);
+        assertTrue(ServiceUtil.isSuccess(result));
+        List<GenericValue> foundElements = getCompleteList(result);
+        assertEquals("performFind search with group condition", 3, 
foundElements.size());
+    }
+
+    private void performFindDateFindAndIgnoreCase() throws Exception {
+        LocalDispatcher dispatcher = getDispatcher();
+        GenericValue userLogin = getUserLogin("system");
+        Timestamp now = UtilDateTime.nowTimestamp();
+
+        Map<String, Object> inputFields = UtilMisc.toMap(
+                "testingNodeId", "node_1",
+                "testingNodeId_ic", "Y",
+                "fromDate_fld0_value", UtilDateTime.addDaysToTimestamp(now, 
-2d),
+                "fromDate_fld0_op", "greaterThanEqualTo",
+                "fromDate_fld1_value", now,
+                "fromDate_fld1_op", "upToDay");
+
+        Map<String, Object> performFindMap = UtilMisc.toMap("userLogin", 
userLogin, "entityName", "TestingNodeMember", "inputFields", inputFields);
+        Map<String, Object> result = dispatcher.runSync("performFind", 
performFindMap);
+        assertTrue(ServiceUtil.isSuccess(result));
+        List<GenericValue> foundElements = getCompleteList(result);
+        assertEquals("performFind search with date-find widget condition", 2, 
foundElements.size());
+    }
+
     private void performFindFilterByDateWithDedicateDateField() throws 
Exception {
         GenericValue userLogin = getUserLogin("system");
         prepareData();

Reply via email to