svn commit: r533964 - in /ofbiz/trunk/framework/webtools/webapp/webtools: WEB-INF/actions/entity/FindGeneric.bsh entity/FindGeneric.ftl

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r533964 - in /ofbiz/trunk/framework/webtools/webapp/webtools: WEB-INF/actions/entity/FindGeneric.bsh entity/FindGeneric.ftl

jonesde
Author: jonesde
Date: Tue May  1 01:38:53 2007
New Revision: 533964

URL: http://svn.apache.org/viewvc?view=rev&rev=533964
Log:
A few cleanups and enhanced to support wildcard (%) in string fields; would be nice in the future to add date ranges, etc but this is a helpful start

Modified:
    ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/FindGeneric.bsh
    ofbiz/trunk/framework/webtools/webapp/webtools/entity/FindGeneric.ftl

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/FindGeneric.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/FindGeneric.bsh?view=diff&rev=533964&r1=533963&r2=533964
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/FindGeneric.bsh (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/FindGeneric.bsh Tue May  1 01:38:53 2007
@@ -26,7 +26,9 @@
 import org.ofbiz.entity.model.ModelFieldType;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityFieldMap;
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.transaction.TransactionUtil;
@@ -36,9 +38,8 @@
 import java.sql.Timestamp;
 import java.sql.Date;
 import java.sql.Time;
-
-delegator = request.getAttribute("delegator");
-security = request.getAttribute("security");
+import javolution.util.FastList;
+import javolution.util.FastMap;
 
 String entityName = request.getParameter("entityName");
 
@@ -87,8 +88,7 @@
 int viewIndex = 0;
 try {
     viewIndex = Integer.valueOf(viewIndexString).intValue();
-}
-catch (NumberFormatException nfe) {
+} catch (NumberFormatException nfe) {
     viewIndex = 0;
 }
 context.put("viewIndex", viewIndex);
@@ -103,8 +103,7 @@
 int viewSize = 10;
 try {
     viewSize = Integer.valueOf(viewSizeString).intValue();
-}
-catch (NumberFormatException nfe) {
+} catch (NumberFormatException nfe) {
     viewSize = 10;
 }
 context.put("viewSize", viewSize);
@@ -117,8 +116,23 @@
 List resultPartialList = null;
 
 if ("true".equals(find)) {
-    EntityCondition condition = new EntityFieldMap(findByEntity, EntityOperator.AND);
-    arraySize = (int) delegator.findCountByCondition(findByEntity.getEntityName(), condition, null);
+    //EntityCondition condition = new EntityFieldMap(findByEntity, EntityOperator.AND);
+    
+    // small variation to support LIKE if a wildcard (%) is found in a String
+    conditionList = FastList.newInstance();
+    findByKeySet = findByEntity.keySet();
+    fbksIter = findByKeySet.iterator();
+    while (fbksIter.hasNext()) {
+        findByKey = fbksIter.next();
+        if (findByEntity.getString(findByKey).indexOf("%") >= 0) {
+            conditionList.add(new EntityExpr(findByKey, EntityOperator.LIKE, findByEntity.getString(findByKey)));
+        } else {
+            conditionList.add(new EntityExpr(findByKey, EntityOperator.EQUALS, findByEntity.get(findByKey)));
+        }
+    }
+    condition = new EntityConditionList(conditionList, EntityOperator.AND);
+    
+    arraySize = (int) delegator.findCountByCondition(entityName, condition, null);
     if (arraySize < highIndex) {
         highIndex = arraySize;
     }
@@ -131,23 +145,20 @@
             EntityFindOptions efo = new EntityFindOptions();
             efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE);
             EntityListIterator resultEli = null;
-            resultEli = delegator.findListIteratorByCondition(findByEntity.getEntityName(), condition, null, null, null, efo);
+            resultEli = delegator.findListIteratorByCondition(entityName, condition, null, null, null, efo);
             resultPartialList = resultEli.getPartialList(lowIndex, highIndex - lowIndex + 1);
             resultEli.close();
-        }
-        catch (GenericEntityException e) {
+        } catch (GenericEntityException e) {
             Debug.logError(e, "Failure in operation, rolling back transaction", "FindGeneric.bsh");
             try {
                 // only rollback the transaction if we started one...
                 TransactionUtil.rollback(beganTransaction, "Error looking up entity values in WebTools Entity Data Maintenance", e);
-            }
-            catch (GenericEntityException e2) {
+            } catch (GenericEntityException e2) {
                 Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), "FindGeneric.bsh");
             }
             // after rolling back, rethrow the exception
             throw e;
-        }
-        finally {
+        } finally {
             // only commit the transaction if we started one... this will throw an exception if it fails
             TransactionUtil.commit(beganTransaction);
         }
@@ -157,12 +168,12 @@
 context.put("arraySize", arraySize);
 context.put("resultPartialList", resultPartialList);
 
-List fieldList = new ArrayList();
+List fieldList = FastList.newInstance();
 for (int fnum = 0; fnum < modelEntity.getFieldsSize(); fnum++) {
     ModelField field = modelEntity.getField(fnum);
     ModelFieldType type = delegator.getEntityFieldType(modelEntity, field.getType());
     
-    Map fieldMap = new HashMap();
+    Map fieldMap = FastMap.newInstance();
     fieldMap.put("name", field.getName());
     fieldMap.put("isPk", (field.getIsPk() == true) ? "Y" : "N");
     fieldMap.put("javaType", type.getJavaType());
@@ -174,11 +185,11 @@
 context.put("fieldList", fieldList);
 context.put("columnCount", (fieldList.size())+2);
 
-List records = new ArrayList();
+List records = FastList.newInstance();
 if (resultPartialList != null) {
     Iterator resultPartialIter = resultPartialList.iterator();
-      while (resultPartialIter.hasNext()) {
-         Map record = new HashMap();
+    while (resultPartialIter.hasNext()) {
+        Map record = FastMap.newInstance();
             
         GenericValue value = (GenericValue)resultPartialIter.next();
         String findString = "entityName=" + entityName;
@@ -189,36 +200,8 @@
         }
         record.put("findString", findString);
         
-        List fields = new ArrayList();
-        for (int fnum = 0; fnum < modelEntity.getFieldsSize(); fnum++) {
-            String fieldValue = "";
-            ModelField field = modelEntity.getField(fnum);
-            ModelFieldType type = delegator.getEntityFieldType(modelEntity, field.getType());
-            
-            if(type.getJavaType().equals("Timestamp") || type.getJavaType().equals("java.sql.Timestamp")) {
-                Timestamp dtVal = value.getTimestamp(field.getName());
-                fieldValue = (dtVal == null) ? "" : dtVal.toString();
-            } else if(type.getJavaType().equals("Date") || type.getJavaType().equals("java.sql.Date")) {
-                Date dateVal = value.getDate(field.getName());
-                fieldValue = (dateVal == null) ? "" : dateVal.toString();
-            } else if(type.getJavaType().equals("Time") || type.getJavaType().equals("java.sql.Time")) {
-                Time timeVal = value.getTime(field.getName());
-                fieldValue = (timeVal == null) ? "" : timeVal.toString();
-            } else if(type.getJavaType().indexOf("Integer") >= 0) {
-                fieldValue = UtilFormatOut.safeToString((Integer)value.get(field.getName()));
-            } else if(type.getJavaType().indexOf("Long") >= 0) {
-                fieldValue = UtilFormatOut.safeToString((Long)value.get(field.getName()));
-            } else if(type.getJavaType().indexOf("Double") >= 0) {
-                fieldValue = UtilFormatOut.safeToString((Double)value.get(field.getName()));
-            } else if(type.getJavaType().indexOf("Float") >= 0) {
-                fieldValue = UtilFormatOut.safeToString((Float)value.get(field.getName()));
-            } else if(type.getJavaType().indexOf("String") >= 0) {
-                fieldValue = UtilFormatOut.checkNull((String)value.get(field.getName()));
-            }
-            fields.add(fieldValue);
-       }
-       record.put("fields", fields);
-       records.add(record);
+        record.put("fields", value);
+        records.add(record);
     }
 }
 context.put("records", records);

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/entity/FindGeneric.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/entity/FindGeneric.ftl?view=diff&rev=533964&r1=533963&r2=533964
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/entity/FindGeneric.ftl (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/entity/FindGeneric.ftl Tue May  1 01:38:53 2007
@@ -103,10 +103,8 @@
                     <a href='<@ofbizUrl>UpdateGeneric?${record.findString}&amp;UPDATE_MODE=DELETE&amp;${curFindString}</@ofbizUrl>'>${uiLabelMap.CommonDelete}</a>
                 </#if>
                 </td>
-                <#list record.fields as field>
-                    <td>
-                        ${field}
-                    </td>
+                <#list fieldList as field>
+                    <td>${record.fields.get(field.name)?if_exists?string}</td>
                 </#list>
             </tr>
             <#assign alt_row = !alt_row>