Author: adrianc
Date: Sun Apr 25 05:56:21 2010
New Revision: 937749
URL: http://svn.apache.org/viewvc?rev=937749&view=rev
Log:
Added a method to FindServices.java. The original code parses input parameters
into a nested Map structure, then parses the nested Map structure into an
EntityCondition. The new method takes a direct approach and parses input
parameters directly into an EntityCondition. The method isn't used yet.
Modified:
ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java
Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java?rev=937749&r1=937748&r2=937749&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java
(original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java Sun Apr
25 05:56:21 2010
@@ -29,6 +29,7 @@ import java.util.Set;
import javolution.util.FastList;
import javolution.util.FastMap;
+import javolution.util.FastSet;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.ObjectType;
@@ -46,7 +47,6 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityComparisonOperator;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
-import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityFunction;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.ModelEntity;
@@ -202,6 +202,82 @@ public class FindServices {
}
/**
+ * Parses input parameters and returns an <code>EntityCondition</code>
list.
+ *
+ * @param parameters
+ * @param fieldList
+ * @param queryStringMap
+ * @param delegator
+ * @param context
+ * @return
+ */
+ public static List<EntityCondition> createConditionList(Map<String, ?
extends Object> parameters, List<ModelField> fieldList, Map<String, Object>
queryStringMap, Delegator delegator, Map<String, ?> context) {
+ Set<String> processed = FastSet.newInstance();
+ Set<String> keys = FastSet.newInstance();
+ Map<String, ModelField> fieldMap = FastMap.newInstance();
+ for (ModelField modelField : fieldList) {
+ fieldMap.put(modelField.getName(), modelField);
+ }
+ List<EntityCondition> result = FastList.newInstance();
+ for (Map.Entry<String, ? extends Object> entry :
parameters.entrySet()) {
+ 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 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);
+ }
+ fieldName = fieldName.substring(0, fieldName.length() - 5);
+ }
+ if (parameters.containsKey(fieldName)) {
+ keys.add(fieldName);
+ }
+ processed.addAll(keys);
+ ModelField modelField = fieldMap.get(fieldName);
+ if (modelField == null) {
+ continue;
+ }
+ if (fieldValue == null) {
+ fieldValue = parameters.get(fieldName);
+ }
+ if (ObjectType.isEmpty(fieldValue)) {
+ continue;
+ }
+ result.add(createSingleCondition(modelField, operation,
fieldValue, ignoreCase, delegator, context));
+ for (String mapKey : keys) {
+ queryStringMap.put(mapKey, parameters.get(mapKey));
+ }
+ }
+ return result;
+ }
+
+ /**
* Creates a single <code>EntityCondition</code> based on a set of
parameters.
*
* @param modelField