diff --git a/framework/common/build.xml b/framework/common/build.xml
index 489bce6b6c..f69db81674 100644
--- a/framework/common/build.xml
+++ b/framework/common/build.xml
@@ -44,4 +44,9 @@ under the License.
+
+
+
+
+
diff --git a/framework/common/ofbiz-component.xml b/framework/common/ofbiz-component.xml
index 4938878c62..511098d9d3 100644
--- a/framework/common/ofbiz-component.xml
+++ b/framework/common/ofbiz-component.xml
@@ -73,4 +73,5 @@ under the License.
+
diff --git a/framework/common/servicedef/services.xml b/framework/common/servicedef/services.xml
index 5ae75edb87..f66357c4d9 100644
--- a/framework/common/servicedef/services.xml
+++ b/framework/common/servicedef/services.xml
@@ -214,6 +214,8 @@ under the License.
+
+
@@ -243,6 +245,8 @@ under the License.
+
+
diff --git a/framework/common/src/org/ofbiz/common/FindServices.java b/framework/common/src/org/ofbiz/common/FindServices.java
index effcdd26cb..71693b8a2f 100644
--- a/framework/common/src/org/ofbiz/common/FindServices.java
+++ b/framework/common/src/org/ofbiz/common/FindServices.java
@@ -479,6 +479,16 @@ public class FindServices {
filterByDate = (String) inputFields.get("filterByDate");
}
Timestamp filterByDateValue = (Timestamp) context.get("filterByDateValue");
+ String fromDateName = (String) context.get("fromDateName");
+ if (UtilValidate.isEmpty(fromDateName)) {
+ // try finding in inputFields Map
+ fromDateName = (String) inputFields.get("fromDateName");
+ }
+ String thruDateName = (String) context.get("thruDateName");
+ if (UtilValidate.isEmpty(thruDateName)) {
+ // try finding in inputFields Map
+ thruDateName = (String) inputFields.get("thruDateName");
+ }
Integer viewSize = (Integer) context.get("viewSize");
Integer viewIndex = (Integer) context.get("viewIndex");
@@ -493,7 +503,7 @@ public class FindServices {
try {
prepareResult = dispatcher.runSync("prepareFind", UtilMisc.toMap("entityName", entityName, "orderBy", orderBy,
"inputFields", inputFields, "filterByDate", filterByDate, "noConditionFind", noConditionFind,
- "filterByDateValue", filterByDateValue, "userLogin", userLogin,
+ "filterByDateValue", filterByDateValue, "userLogin", userLogin, "fromDateName", fromDateName, "thruDateName", thruDateName,
"locale", context.get("locale"), "timeZone", context.get("timeZone")));
} catch (GenericServiceException gse) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonFindErrorPreparingConditions", UtilMisc.toMap("errorString", gse.getMessage()), locale));
@@ -550,6 +560,8 @@ public class FindServices {
filterByDate = (String) inputFields.get("filterByDate");
}
Timestamp filterByDateValue = (Timestamp) context.get("filterByDateValue");
+ String fromDateName = (String) context.get("fromDateName");
+ String thruDateName = (String) context.get("thruDateName");
Map queryStringMap = new LinkedHashMap();
ModelEntity modelEntity = delegator.getModelEntity(entityName);
@@ -562,12 +574,16 @@ public class FindServices {
if (tmpList.size() > 0 || "Y".equals(noConditionFind)) {
if ("Y".equals(filterByDate)) {
queryStringMap.put("filterByDate", filterByDate);
+ if (UtilValidate.isEmpty(fromDateName)) fromDateName = "fromDate";
+ else queryStringMap.put("fromDateName", fromDateName);
+ if (UtilValidate.isEmpty(thruDateName)) thruDateName = "thruDate";
+ else queryStringMap.put("thruDateName", thruDateName);
if (UtilValidate.isEmpty(filterByDateValue)) {
- EntityCondition filterByDateCondition = EntityUtil.getFilterByDateExpr();
+ EntityCondition filterByDateCondition = EntityUtil.getFilterByDateExpr(fromDateName, thruDateName);
tmpList.add(filterByDateCondition);
} else {
queryStringMap.put("filterByDateValue", filterByDateValue);
- EntityCondition filterByDateCondition = EntityUtil.getFilterByDateExpr(filterByDateValue);
+ EntityCondition filterByDateCondition = EntityUtil.getFilterByDateExpr(filterByDateValue, fromDateName, thruDateName);
tmpList.add(filterByDateCondition);
}
}
diff --git a/framework/common/src/org/ofbiz/common/test/PerformFindTests.java b/framework/common/src/org/ofbiz/common/test/PerformFindTests.java
new file mode 100644
index 0000000000..e348f04b8d
--- /dev/null
+++ b/framework/common/src/org/ofbiz/common/test/PerformFindTests.java
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.common.test;
+
+import java.sql.Timestamp;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.service.testtools.OFBizTestCase;
+
+public class PerformFindTests extends OFBizTestCase {
+
+ private static final String module = PerformFindTests.class.getName();
+ public PerformFindTests(String name) {
+ super(name);
+ }
+
+ private List getCompleteList(Map context) {
+ EntityListIterator listIt = (EntityListIterator) context.get("listIt");
+ List foundElements = new LinkedList();
+ if (listIt != null) {
+ try {
+ foundElements = listIt.getCompleteList();
+ } catch (GenericEntityException e) {
+ Debug.logError(" Failed to extract values from EntityListIterator after a performFind service", module);
+ } finally {
+ try {
+ listIt.close();
+ } catch (GenericEntityException e) {
+ Debug.logError(" Failed to close EntityListIterator after a performFind service", module);
+ }
+ }
+ }
+ return foundElements;
+ }
+
+ private void prepareData() throws Exception {
+ if (delegator.findOne("TestingType", false, "testingTypeId", "PERFOMFINDTEST") == 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");
+
+ Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
+ delegator.create("TestingNode", "testingNodeId", "NODE_1", "description", "Date Node");
+ delegator.create("TestingNodeMember", "testingNodeId", "NODE_1", "testingId", "PERF_TEST_5",
+ "fromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 1d),
+ "thruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 3d),
+ "extendFromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "extendThruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 3d));
+ delegator.create("TestingNodeMember", "testingNodeId", "NODE_1", "testingId", "PERF_TEST_6",
+ "fromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "thruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 1d),
+ "extendFromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "extendThruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 3d));
+ delegator.create("TestingNodeMember", "testingNodeId", "NODE_1", "testingId", "PERF_TEST_7",
+ "fromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "thruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 1d),
+ "extendFromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "extendThruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 3d));
+ delegator.create("TestingNodeMember", "testingNodeId", "NODE_1", "testingId", "PERF_TEST_8",
+ "fromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -3d),
+ "thruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 1d),
+ "extendFromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "extendThruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, 3d));
+ delegator.create("TestingNodeMember", "testingNodeId", "NODE_1", "testingId", "PERF_TEST_9",
+ "fromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -3d),
+ "thruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "extendFromDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -1d),
+ "extendThruDate", UtilDateTime.addDaysToTimestamp(nowTimestamp, -3d));
+ }
+ }
+
+ public void testPerformFindConditionFieldEquals() throws Exception {
+ GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system");
+ prepareData();
+
+ Map inputFields = new HashMap();
+ //first test without condition
+ Map performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields);
+ Map result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ List foundElements = getCompleteList(result);
+ assertTrue("performFind search without condition ", UtilValidate.isEmpty(foundElements));
+
+ //second test without condition and noConditionFind to Y
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields, "noConditionFind", "Y");
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search without condition with noConditionFind Y", 9, foundElements.size());
+
+ //third test with equals condition on testingTypeId
+ inputFields = UtilMisc.toMap("testingTypeId", "PERFOMFINDTEST");
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields);
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ List testingElements = delegator.findAll("Testing", false);
+ assertEquals("performFind search without condition with equals on testingTypeId", testingElements.size(), foundElements.size());
+
+ //fourth test with equals condition on testingId
+ inputFields = UtilMisc.toMap("testingId", "PERF_TEST_1");
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields);
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search without condition with equals on testingId", 1, foundElements.size());
+ }
+
+ public void testPerformFindConditionFieldLike() throws Exception {
+ GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system");
+ prepareData();
+
+ //first test like condition
+ Map inputFields = UtilMisc.toMap("testingName", "nice", "testingName_op", "like");
+ Map performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields);
+ Map result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ List foundElements = getCompleteList(result);
+ assertEquals("performFind search with like nice% condition", 3, foundElements.size());
+
+ //second test contains condition
+ inputFields = UtilMisc.toMap("testingName", "name", "testingName_op", "contains");
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields);
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search with like %name% condition", 4, foundElements.size());
+
+ //third test not-like condition
+ inputFields = UtilMisc.toMap("testingName", "bad", "testingName_op", "not-like");
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields);
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search with not like bad% condition", 4, foundElements.size());
+
+ //fourth test not-contains condition
+ inputFields = UtilMisc.toMap("testingName", "name", "testingName_op", "not-contains");
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields);
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search with not like %name% condition", 1, foundElements.size());
+ }
+
+ public void testPerformFindConditionDistinct() throws Exception {
+ GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system");
+ prepareData();
+
+ //first test without distinct condition
+ Map inputFields = UtilMisc.toMap("testingTypeId", "PERFOMFINDTEST");
+ List fieldList= UtilMisc.toList("testingName", "testingTypeId");
+ Map performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields, "fieldList", fieldList, "distinct", "N");
+ Map result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ List foundElements = getCompleteList(result);
+ assertEquals("performFind search with distinct N", 9, foundElements.size());
+
+ //second test with distinct condition
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "Testing", "inputFields", inputFields, "fieldList", fieldList, "distinct", "Y");
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search with distinct Y", 5, foundElements.size());
+ }
+
+ public void testPerformFindFilterByDate() throws Exception {
+ GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system");
+ prepareData();
+
+ //first test without filterDate condition
+ Map inputFields = UtilMisc.toMap("testingNodeId", "NODE_1");
+ Map performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "TestingNodeMember", "inputFields", inputFields, "filterByDate", "N", "filterByDateValue", UtilDateTime.nowTimestamp());
+ Map result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ List foundElements = getCompleteList(result);
+ assertEquals("performFind search with filterDate N", 5, foundElements.size());
+
+ //second test with filterDate condition
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "TestingNodeMember", "inputFields", inputFields, "filterByDate", "Y", "filterByDateValue", UtilDateTime.nowTimestamp());
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search with filterDate Y", 3, foundElements.size());
+ }
+
+ public void testPerformFindFilterByDateWithDedicateDateField() throws Exception {
+ GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system");
+ prepareData();
+
+ //first test without filterDate condition
+ Map inputFields = UtilMisc.toMap("testingNodeId", "NODE_1");
+ Map performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "TestingNodeMember", "inputFields", inputFields,
+ "filterByDate", "N", "filterByDateValue", UtilDateTime.nowTimestamp(),
+ "fromDateName", "extendFromDate", "thruDateName", "extendThruDate");
+ Map result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ List foundElements = getCompleteList(result);
+ assertEquals("performFind search with filterDate N and specific date field name", 5, foundElements.size());
+
+ //second test with filterDate condition
+ performFindMap = UtilMisc.toMap("userLogin", userLogin, "entityName", "TestingNodeMember", "inputFields", inputFields,
+ "filterByDate", "Y", "filterByDateValue", UtilDateTime.nowTimestamp(),
+ "fromDateName", "extendFromDate", "thruDateName", "extendThruDate");
+ result = dispatcher.runSync("performFind", performFindMap);
+ assertTrue(ServiceUtil.isSuccess(result));
+ foundElements = getCompleteList(result);
+ assertEquals("performFind search with filterDate Y and specific date field name", 4, foundElements.size());
+ }
+}
diff --git a/framework/common/testdef/PerformFindTests.xml b/framework/common/testdef/PerformFindTests.xml
new file mode 100644
index 0000000000..d2eb89011e
--- /dev/null
+++ b/framework/common/testdef/PerformFindTests.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework/entity/entitydef/entitymodel_test.xml b/framework/entity/entitydef/entitymodel_test.xml
index c7fe4a6d6c..cb54e32f70 100644
--- a/framework/entity/entitydef/entitymodel_test.xml
+++ b/framework/entity/entitydef/entitymodel_test.xml
@@ -162,10 +162,12 @@ under the License.
-
-
-
-
+
+
+
+
+
+