[ofbiz-framework] branch trunk updated (8902637 -> 91fa4a9)

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

[ofbiz-framework] branch trunk updated (8902637 -> 91fa4a9)

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

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


    from 8902637  Revert "Fixed: Potensial bug under CommunicationEventServices#updateCommEventAfterEmail for CommunicationEvent.subject field" (OFBIZ-10879)
     new fac12a4  Fixed: No functional change, correct checkstyle issues on GenericWebEvent.java
     new 11cf350  Improved: Change 'restMethod' by '_method' in request parameters (OFBIZ-11332)
     new 1ee1ec7  Fixed: Change 'restMethod' by '_method' in request parameters (OFBIZ-11007)
     new 91fa4a9  Fixed: Clean unecessary code and convert to groovy syntax

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/ofbiz/base/util/UtilHttp.java  |  11 +
 .../org/apache/ofbiz/entity/util/EntityUtil.java   |  53 +++
 .../ofbiz/webapp/control/RequestHandler.java       |   3 +-
 .../groovyScripts/entity/FindGeneric.groovy        |  14 +-
 .../groovyScripts/entity/ViewGeneric.groovy        | 409 ++++++---------------
 .../org/apache/ofbiz/webtools/GenericWebEvent.java | 133 ++++---
 framework/webtools/template/entity/ViewGeneric.ftl |   4 +-
 7 files changed, 279 insertions(+), 348 deletions(-)

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 01/04: Fixed: No functional change, correct checkstyle issues on GenericWebEvent.java

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

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

commit fac12a4e6fbcd6892dffa2a75ed83f6bed19a424
Author: Nicolas Malin <[hidden email]>
AuthorDate: Tue Jan 28 15:25:57 2020 +0100

    Fixed: No functional change, correct checkstyle issues on GenericWebEvent.java
---
 .../org/apache/ofbiz/webtools/GenericWebEvent.java | 110 ++++++++++++++-------
 1 file changed, 73 insertions(+), 37 deletions(-)

diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java
index 11e7736..07c5233 100644
--- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java
+++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java
@@ -65,9 +65,11 @@ public class GenericWebEvent {
             entityName = (String) request.getAttribute("entityName");
         }
         if (UtilValidate.isEmpty(entityName)) {
-            String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.entity_name_not_specified", locale) + ".";
+            String errMsg = UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.entity_name_not_specified", locale) + ".";
             request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            Debug.logWarning("[GenericWebEvent.updateGeneric] The entityName was not specified, but is required.", module);
+            Debug.logWarning("[GenericWebEvent.updateGeneric] The entityName was not specified,"
+                    + " but is required.", module);
             return "error";
         }
 
@@ -75,15 +77,19 @@ public class GenericWebEvent {
         Delegator delegator = (Delegator) request.getAttribute("delegator");
 
         if (security == null) {
-            String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource,"genericWebEvent.security_object_not_found", locale) + ".";
+            String errMsg = UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.security_object_not_found", locale) + ".";
             request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            Debug.logWarning("[updateGeneric] The security object was not found in the request, please check the control servlet init.", module);
+            Debug.logWarning("[updateGeneric] The security object was not found in the request,"
+                    + " please check the control servlet init.", module);
             return "error";
         }
         if (delegator == null) {
-            String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.delegator_object_not_found", locale) + ".";
+            String errMsg = UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.delegator_object_not_found", locale) + ".";
             request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            Debug.logWarning("[updateGeneric] The delegator object was not found in the request, please check the control servlet init.", module);
+            Debug.logWarning("[updateGeneric] The delegator object was not found in the request,"
+                    + " please check the control servlet init.", module);
             return "error";
         }
 
@@ -109,25 +115,33 @@ public class GenericWebEvent {
         }
 
         if (UtilValidate.isEmpty(updateMode)) {
-            String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.update_mode_not_specified", locale) + ".";
+            String errMsg = UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.update_mode_not_specified", locale) + ".";
             request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            Debug.logWarning("[updateGeneric] Update Mode was not specified, but is required; entityName: " + entityName, module);
+            Debug.logWarning("[updateGeneric] Update Mode was not specified, but is required;"
+                    + "entityName: " + entityName, module);
             return "error";
         }
 
         // check permissions before moving on...
-        if (!security.hasEntityPermission("ENTITY_DATA", "_" + updateMode, request.getSession()) &&
-            !security.hasEntityPermission(entity.getPlainTableName(), "_" + updateMode, request.getSession())) {
-                Map<String, String> messageMap = UtilMisc.toMap("updateMode", updateMode, "entityName", entity.getEntityName(), "entityPlainTableName", entity.getPlainTableName());
-                String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.not_sufficient_permissions_01", messageMap, locale);
-                errMsg += UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.not_sufficient_permissions_02", messageMap, locale) + ".";
+        String plainTableName = entity.getPlainTableName();
+        if (!security.hasEntityPermission("ENTITY_DATA", "_" + updateMode, request.getSession())
+                && !security.hasEntityPermission(plainTableName, "_" + updateMode, request.getSession())) {
+            Map<String, String> messageMap = UtilMisc.toMap(
+                    "updateMode", updateMode,
+                    "entityName", entity.getEntityName(),
+                    "entityPlainTableName", plainTableName);
+            String errMsg = UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.not_sufficient_permissions_01", messageMap, locale);
+            errMsg += UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.not_sufficient_permissions_02", messageMap, locale) + ".";
 
-                request.setAttribute("_ERROR_MESSAGE_", errMsg);
+            request.setAttribute("_ERROR_MESSAGE_", errMsg);
             // not really successful, but error return through ERROR_MESSAGE, so quietly fail
             return "error";
         }
 
-        GenericValue findByEntity = delegator.makeValue(entityName);
+        GenericValue findByEntity = delegator.makeValue(entityName, pkFields);
 
         // get the primary key parameters...
         String errMsgPk = "";
@@ -142,7 +156,8 @@ public class GenericWebEvent {
             } catch (GenericEntityException e) {
                 Debug.logWarning(e, module);
                 Map<String, String> messageMap = UtilMisc.toMap("fieldType", field.getType());
-                errMsg += UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.fatal_error_param", messageMap, locale) + ".";
+                errMsg += UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.fatal_error_param", messageMap, locale) + ".";
             }
 
             String fval = request.getParameter(field.getName());
@@ -151,7 +166,7 @@ public class GenericWebEvent {
                     findByEntity.setString(field.getName(), fval);
                 } catch (Exception e) {
                     Map<String, String> messageMap = UtilMisc.toMap("fval", fval);
-                    errMsg = errMsg + "<li>" + field.getColName() + UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.conversion_failed", messageMap, locale) + type.getJavaType() + ".";
+                    errMsg = errMsg + "<li>" + field.getColName() + UtilProperties.getMessage(err_resource, "genericWebEvent.conversion_failed", messageMap, locale) + type.getJavaType() + ".";
                     Debug.logWarning("[updateGeneric] " + field.getColName() + " conversion failed: \"" + fval + "\" is not a valid " + type.getJavaType() + "; entityName: " + entityName, module);
                 }
             }
@@ -168,10 +183,12 @@ public class GenericWebEvent {
             // Delete actual main entity last, just in case database is set up to do a cascading delete, caches won't get cleared
             try {
                 delegator.removeByPrimaryKey(findByEntity.getPrimaryKey());
-                String confirmMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.delete_succeeded", locale) ;
+                String confirmMsg = UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.delete_succeeded", locale);
                 request.setAttribute("_EVENT_MESSAGE_", confirmMsg);
             } catch (GenericEntityException e) {
-                String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.delete_failed", locale) + ": " + e.toString();
+                String errMsg = UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.delete_failed", locale) + ": " + e.toString();
                 Debug.logWarning(e, errMsg, module);
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
                 return "error";
@@ -192,7 +209,8 @@ public class GenericWebEvent {
             } catch (GenericEntityException e) {
                 Debug.logWarning(e, module);
                 Map<String, String> messageMap = UtilMisc.toMap("fieldType", field.getType());
-                errMsgNonPk += UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.fatal_error_param", messageMap, locale) + ".";
+                errMsgNonPk += UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.fatal_error_param", messageMap, locale) + ".";
             }
 
             String fval = request.getParameter(field.getName());
@@ -201,9 +219,11 @@ public class GenericWebEvent {
                     findByEntity.setString(field.getName(), fval);
                 } catch (Exception e) {
                     Map<String, String> messageMap = UtilMisc.toMap("fval", fval);
-                    errMsgNonPk += field.getColName() + UtilProperties.getMessage(GenericWebEvent.err_resource,
+                    errMsgNonPk += field.getColName() + UtilProperties.getMessage(err_resource,
                             "genericWebEvent.conversion_failed", messageMap, locale) + type.getJavaType() + ".";
-                    Debug.logWarning("[updateGeneric] " + field.getColName() + " conversion failed: \"" + fval + "\" is not a valid " + type.getJavaType() + "; entityName: " + entityName, module);
+                    Debug.logWarning("[updateGeneric] " + field.getColName()
+                            + " conversion failed: \"" + fval + "\" is not a valid "
+                            + type.getJavaType() + "; entityName: " + entityName, module);
                 }
             } else {
                 findByEntity.set(field.getName(), null);
@@ -221,9 +241,13 @@ public class GenericWebEvent {
             GenericValue tempEntity = null;
 
             try {
-                tempEntity = EntityQuery.use(delegator).from(findByEntity.getEntityName()).where(findByEntity.getPrimaryKey()).queryOne();
+                tempEntity = EntityQuery.use(delegator)
+                        .from(findByEntity.getEntityName())
+                        .where(findByEntity.getPrimaryKey())
+                        .queryOne();
             } catch (GenericEntityException e) {
-                String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.create_failed_by_check", locale) + ": " + e.toString();
+                String errMsg = UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.create_failed_by_check", locale) + ": " + e.toString();
                 Debug.logWarning(e, errMsg, module);
 
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
@@ -231,7 +255,8 @@ public class GenericWebEvent {
             }
             if (tempEntity != null) {
                 Map<String, String> messageMap = UtilMisc.toMap("primaryKey", findByEntity.getPrimaryKey().toString());
-                String errMsg = "[updateGeneric] " + entity.getEntityName() + UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.already_exists_pk", messageMap, locale)+ ".";
+                String errMsg = "[updateGeneric] " + entity.getEntityName() + UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.already_exists_pk", messageMap, locale) + ".";
                 Debug.logWarning(errMsg, module);
             }
         }
@@ -243,7 +268,7 @@ public class GenericWebEvent {
             ModelField field = fieldIter.next();
 
             for (String curValidate : field.getValidators()) {
-                Class<?>[] paramTypes = { String.class };
+                Class<?>[] paramTypes = {String.class};
                 Object[] params = new Object[] {findByEntity.get(field.getName()).toString()};
 
                 String className = "org.apache.ofbiz.base.util.UtilValidate";
@@ -259,7 +284,8 @@ public class GenericWebEvent {
                     ClassLoader loader = Thread.currentThread().getContextClassLoader();
                     valClass = loader.loadClass(className);
                 } catch (ClassNotFoundException cnfe) {
-                    Debug.logError("[updateGeneric] Could not find validation class: " + className + "; ignoring.", module);
+                    Debug.logError("[updateGeneric] Could not find validation class: " + className
+                            + "; ignoring.", module);
                     continue;
                 }
                 Method valMethod;
@@ -267,7 +293,8 @@ public class GenericWebEvent {
                 try {
                     valMethod = valClass.getMethod(methodName, paramTypes);
                 } catch (NoSuchMethodException cnfe) {
-                    Debug.logError("[updateGeneric] Could not find validation method: " + methodName + " of class " + className + "; ignoring.", module);
+                    Debug.logError("[updateGeneric] Could not find validation method: " + methodName
+                            + " of class " + className + "; ignoring.", module);
                     continue;
                 }
 
@@ -276,7 +303,8 @@ public class GenericWebEvent {
                 try {
                     resultBool = (Boolean) valMethod.invoke(null, params);
                 } catch (Exception e) {
-                    Debug.logError("[updateGeneric] Could not access validation method: " + methodName + " of class " + className + "; returning true.", module);
+                    Debug.logError("[updateGeneric] Could not access validation method: " + methodName
+                            + " of class " + className + "; returning true.", module);
                     resultBool = Boolean.TRUE;
                 }
 
@@ -288,10 +316,11 @@ public class GenericWebEvent {
                         msgField = valClass.getField(curValidate + "Msg");
                         message = (String) msgField.get(null);
                     } catch (Exception e) {
-                        Debug.logError("[updateGeneric] Could not find validation message field: " + curValidate + "Msg of class " + className + "; returning generic validation failure message.", module);
-                        message = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.validation_failed", locale) + ".";
+                        Debug.logError("[updateGeneric] Could not find validation message field: " + curValidate
+                                + "Msg of class " + className + "; returning generic validation failure message.", module);
+                        message = UtilProperties.getMessage(err_resource, "genericWebEvent.validation_failed", locale) + ".";
                     }
-                    errMsgParam += field.getColName() + " " + curValidate + " " + UtilProperties.getMessage(GenericWebEvent.err_resource,
+                    errMsgParam += field.getColName() + " " + curValidate + " " + UtilProperties.getMessage(err_resource,
                             "genericWebEvent.failed", locale) + ": " + message;
 
                     Debug.logWarning("[updateGeneric] " + field.getColName() + " " + curValidate + " failed: " + message, module);
@@ -300,7 +329,8 @@ public class GenericWebEvent {
         }
 
         if (errMsgParam.length() > 0) {
-            errMsgParam = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.following_error_occurred", locale) + errMsgParam;
+            errMsgParam = UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.following_error_occurred", locale) + errMsgParam;
             request.setAttribute("_ERROR_MESSAGE_", errMsgParam);
             return "error";
         }
@@ -310,7 +340,9 @@ public class GenericWebEvent {
                 delegator.create(findByEntity.getEntityName(), findByEntity.getAllFields());
             } catch (GenericEntityException e) {
                 Map<String, String> messageMap = UtilMisc.toMap("entityName", entity.getEntityName());
-                String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.creation_param_failed", messageMap, locale)+ ": " + findByEntity.toString() + ": " + e.toString();
+                String errMsg = UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.creation_param_failed", messageMap, locale)
+                        + ": " + findByEntity.toString() + ": " + e.toString();
                 Debug.logWarning(e, errMsg, module);
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
                 return "error";
@@ -322,17 +354,21 @@ public class GenericWebEvent {
                 value.store();
             } catch (GenericEntityException e) {
                 Map<String, String> messageMap = UtilMisc.toMap("entityName", entity.getEntityName());
-                String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.update_of_param_failed", messageMap, locale)+ ": " + value.toString() + ": " + e.toString();
+                String errMsg = UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.update_of_param_failed", messageMap, locale)
+                        + ": " + value.toString() + ": " + e.toString();
                 Debug.logWarning(e, errMsg, module);
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
                 return "error";
             }
         } else {
             Map<String, String> messageMap = UtilMisc.toMap("updateMode", updateMode);
-            String errMsg = UtilProperties.getMessage(GenericWebEvent.err_resource, "genericWebEvent.update_of_param_failed", messageMap, locale)+ ".";
+            String errMsg = UtilProperties.getMessage(err_resource,
+                    "genericWebEvent.update_of_param_failed", messageMap, locale) + ".";
 
             request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            Debug.logWarning("updateGeneric: Update Mode specified (" + updateMode + ") was not valid for entity: " + findByEntity.toString(), module);
+            Debug.logWarning("updateGeneric: Update Mode specified (" + updateMode + ") was not valid for entity: "
+                    + findByEntity.toString(), module);
             return "error";
         }
 

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 02/04: Improved: Change 'restMethod' by '_method' in request parameters (OFBIZ-11332)

nmalin
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.

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

commit 11cf350302015d1210b9f663cb9c68339701a3f8
Author: Nicolas Malin <[hidden email]>
AuthorDate: Tue Jan 28 17:52:19 2020 +0100

    Improved: Change 'restMethod' by '_method' in request parameters
    (OFBIZ-11332)
   
    When we analyse a request method, we currently check the parameter "restMethod".
    Mathieu Lirzin propose [1] to use "_method" instead to use a parameter name more generic
   
    I create a new function UtilHttp.getRequestMethod() to centralize the request method resolution.
   
    [1] https://issues.apache.org/jira/browse/OFBIZ-11007?focusedCommentId=17012712&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17012712
---
 .../src/main/java/org/apache/ofbiz/base/util/UtilHttp.java    | 11 +++++++++++
 .../java/org/apache/ofbiz/webapp/control/RequestHandler.java  |  3 +--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
index f4afecd..ed8babb 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
@@ -695,6 +695,17 @@ public final class UtilHttp {
         return requestUrl.toString();
     }
 
+    /** Resolve the method send with the request.
+     *  check first the parameter _method before return the request method
+     * @param request
+     * @return
+     */
+    public static String getRequestMethod(HttpServletRequest request) {
+        return request.getParameter("_method") != null ?
+                request.getParameter("_method") :
+                request.getMethod();
+    }
+
     public static Locale getLocale(HttpServletRequest request, HttpSession session, Object appDefaultLocale) {
         // check session first, should override all if anything set there
         Object localeObject = session != null ? session.getAttribute("locale") : null;
diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
index 9956de5..0e91bb1 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
@@ -260,8 +260,7 @@ public class RequestHandler {
         // The "overriddenView" attribute is set by resolveURI when necessary.
         String overrideViewUri = (String) request.getAttribute("overriddenView");
 
-        String restMethod = request.getParameter("restMethod");
-        String method = (restMethod != null) ? restMethod : request.getMethod();
+        String method = UtilHttp.getRequestMethod(request);
         RequestMap requestMap = resolveMethod(method, rmaps).orElseThrow(() -> {
             String msg = UtilProperties.getMessage("WebappUiLabels", "RequestMethodNotMatchConfig",
                     UtilMisc.toList(requestUri, method), UtilHttp.getLocale(request));

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 03/04: Fixed: Change 'restMethod' by '_method' in request parameters (OFBIZ-11007)

nmalin
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.

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

commit 1ee1ec76d6202f66cdff271fd4c313d5d2c132cc
Author: Nicolas Malin <[hidden email]>
AuthorDate: Tue Jan 28 18:16:13 2020 +0100

    Fixed: Change 'restMethod' by '_method' in request parameters
    (OFBIZ-11007)
   
    Some issue has been introduce on the previous commit 6e1c7b5 [1], corrected by this one :
      * the view link on ListGeneric failed
      * the paginate on ListGeneric failed
   
    I also simplify the url writing with delegate the entity path generation and translation
    to two function on EntityUtil : entityToPath and getPkValuesMapFromPath
   
    thanks to Pawan Verma to spot the pagination problem
   
    [1] https://gitbox.apache.org/repos/asf?p=ofbiz-framework.git;h=6e1c7b5
---
 .../org/apache/ofbiz/entity/util/EntityUtil.java   | 53 ++++++++++++++++++++++
 .../groovyScripts/entity/FindGeneric.groovy        | 14 ++----
 .../groovyScripts/entity/ViewGeneric.groovy        | 35 +++++---------
 .../org/apache/ofbiz/webtools/GenericWebEvent.java | 23 +++++++---
 framework/webtools/template/entity/ViewGeneric.ftl |  4 +-
 5 files changed, 87 insertions(+), 42 deletions(-)

diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
index 0c0411d..9a69955 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
@@ -22,6 +22,7 @@ package org.apache.ofbiz.entity.util;
 import java.io.Serializable;
 import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -48,6 +49,7 @@ import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.condition.EntityCondition;
 import org.apache.ofbiz.entity.condition.EntityDateFilterCondition;
 import org.apache.ofbiz.entity.condition.OrderByList;
+import org.apache.ofbiz.entity.model.ModelEntity;
 import org.apache.ofbiz.entity.model.ModelField;
 
 import static java.util.stream.Collectors.toList;
@@ -544,4 +546,55 @@ public final class EntityUtil {
         return new PagedList<>(startIndex, endIndex, size, viewIndex, viewSize, dataItems);
     }
 
+    /**
+     * For a entityName return the primary keys path that identify it
+     * like entityName/pkValue1/pkValue2/../pkValueN
+     * @param delegator
+     * @param entityName
+     * @param context
+     * @return
+     */
+    public static String entityToPath(Delegator delegator, String entityName, Map<String, Object> context) {
+        return entityToPath(delegator.makeValidValue(entityName, context));
+    }
+    /**
+     * For a entityName return the primary keys path that identify it
+     * like entityName/pkValue1/pkValue2/../pkValueN
+     * @param gv
+     * @return
+     */
+    public static String entityToPath(GenericValue gv) {
+        StringBuilder path = new StringBuilder(gv.getEntityName());
+        for (String pkName : gv.getModelEntity().getPkFieldNames()) {
+            path.append("/").append(gv.getString(pkName));
+        }
+        return path.toString();
+    }
+
+    /**
+     * Form a entityName and primary keys path
+     * convert it to a Map contains all pkValue :
+     *  entityName/pkValue1/pkValue2/../pkValueN
+     *    -> [pkName1: pkValue1,
+     *        pkName2, pkValue2,
+     *        ...,
+     *        pkNameN: pkValueN]
+     * @param modelEntity
+     * @param path
+     * @return
+     */
+    public static Map<String, Object> getPkValuesMapFromPath(ModelEntity modelEntity, String path)
+            throws GenericEntityException {
+        if (UtilValidate.isEmpty(path)) return null;
+        LinkedList<String> pkValues = new LinkedList<>(Arrays.asList(path.split("/")));
+        List<String> pkFieldNames = modelEntity.getPkFieldNames();
+        if (pkFieldNames.size() != pkValues.size()) {
+            throw new GenericEntityException ("Identification path failed ");
+        }
+        Map<String, Object> pkValuesMap = new HashMap<>();
+        for (String pkName : modelEntity.getPkFieldNames()) {
+            pkValuesMap.put(pkName, pkValues.removeFirst());
+        }
+        return pkValuesMap;
+    }
 }
diff --git a/framework/webtools/groovyScripts/entity/FindGeneric.groovy b/framework/webtools/groovyScripts/entity/FindGeneric.groovy
index 29d3eb1..cd8d06a 100644
--- a/framework/webtools/groovyScripts/entity/FindGeneric.groovy
+++ b/framework/webtools/groovyScripts/entity/FindGeneric.groovy
@@ -43,7 +43,7 @@ if (modelEntity) {
     String dynamicAutoEntityFieldSearchForm = """<?xml version="1.0" encoding="UTF-8"?><forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">
         <form name="FindGeneric" type="single" target="entity/find/${entityName}">
            <auto-fields-entity entity-name="${entityName}" default-field-type="find" include-internal="true"/>
-            <field name="restMethod"><hidden value="GET"/></field>
+            <field name="_method"><hidden value="GET"/></field>
             <field name="noConditionFind"><hidden value="Y"/></field>
             <field name="searchOptions_collapsed" ><hidden value="true"/></field>
             <field name="searchButton"><submit/></field>"""
@@ -82,16 +82,9 @@ if (modelEntity) {
     dynamicAutoEntitySearchFormRenderer.render(writer, context)
     context.dynamicAutoEntitySearchForm = writer
 
-    // In case of composite pk
-    String pk = modelEntity.pkNameString()
-    String res = ""
-    for (w in pk.split(", ")) {
-        res = "${res}/\${${w}}"
-    }
-
     //prepare the result list from performFind
     String dynamicAutoEntityFieldListForm = """<?xml version="1.0" encoding="UTF-8"?><forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">
-            <form name="ListGeneric" type="list" method="post" target="entity/find/${entityName}" list-name="listIt"
+            <form name="ListGeneric" type="list" target="entity/find/${entityName}" list-name="listIt" paginate-target="entity/find/${entityName}"
               odd-row-style="alternate-row" default-table-style="basic-table light-grid hover-bar" header-row-style="header-row-2">
             <actions>
                 <service service-name="performFind">
@@ -101,6 +94,7 @@ if (modelEntity) {
                 </service>
             </actions>
             <auto-fields-entity entity-name="${entityName}" default-field-type="display" include-internal="true"/>
+            <field name="_method"><hidden value="POST"/></field>
             <field name="entityName"><hidden value="${entityName}"/></field>"""
     modelEntity.getFieldsUnmodifiable().each {
         modelField ->
@@ -108,7 +102,7 @@ if (modelEntity) {
                     "<field name=\"${modelField.name}\" sort-field=\"true\"/>"
     }
     dynamicAutoEntityFieldListForm += """
-            <field name="viewGeneric" title=" "><hyperlink target="entity/find/${entityName}${res}" description="view"/></field>
+            <field name="viewGeneric" title=" "><hyperlink target="\${groovy: 'entity/find/' + org.apache.ofbiz.entity.util.EntityUtil.entityToPath(delegator, '${entityName}', context)}" description="view"/></field>
             <sort-order><sort-field name="viewGeneric"/></sort-order>
             </form></forms>"""
 
diff --git a/framework/webtools/groovyScripts/entity/ViewGeneric.groovy b/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
index 36c963d..79ef1fd 100644
--- a/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
+++ b/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
@@ -16,10 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import org.apache.ofbiz.entity.Delegator
 import org.apache.ofbiz.entity.GenericPK
 import org.apache.ofbiz.entity.GenericValue
-import org.apache.ofbiz.security.Security
+import org.apache.ofbiz.entity.util.EntityUtil
 import org.apache.ofbiz.entity.model.ModelReader
 import org.apache.ofbiz.entity.model.ModelEntity
 import org.apache.ofbiz.entity.model.ModelField
@@ -60,29 +59,19 @@ context.put("hasUpdatePermission", hasUpdatePermission)
 context.hasDeletePermission = hasDeletePermission
 
 boolean useValue = true
-String currentFindString = entityName
-GenericPK findByPK = delegator.makePK(entityName)
-Iterator pkIterator = entity.getPksIterator()
-String fieldValues = parameters.get("pkValues")
-HashMap<String,String> pkNamesValuesMap = new HashMap<>()
-if (fieldValues != null) {
-    Iterator pkParamIterator = Arrays.asList(fieldValues.split("/")).iterator()
-    while (pkIterator.hasNext() && pkParamIterator.hasNext()) {
-        ModelField field = pkIterator.next()
-        String fieldValue = pkParamIterator.next()
-        if (fieldValue) {
-            currentFindString += "/" + fieldValue
-            pkNamesValuesMap[field.getName()] = fieldValue
-            findByPK.setString(field.getName(), fieldValue)
-        }
-    }
+
+if (parameters.pkValues) {
+    Map<String, String> pkNamesValuesMap = EntityUtil.getPkValuesMapFromPath(
+            delegator.getModelEntity(entityName), parameters.pkValues)
+    parameters << pkNamesValuesMap
+    context.pkNamesValuesMap = pkNamesValuesMap
 }
-parameters << pkNamesValuesMap
-context.pkNamesValuesMap = pkNamesValuesMap
+GenericValue valueFromParameters = delegator.makeValue(entityName)
+valueFromParameters.setPKFields(parameters)
+GenericPK findByPK = valueFromParameters.getPrimaryKey()
+context.currentFindString = UtilFormatOut.encodeQuery(EntityUtil.entityToPath(valueFromParameters))
 context.put("findByPk", findByPK.toString())
 
-context.currentFindString = UtilFormatOut.encodeQuery(currentFindString)
-
 GenericValue value = null
 //only try to find it if this is a valid primary key...
 if (findByPK.isPrimaryKey()) {
@@ -141,7 +130,7 @@ if (value == null && (findByPK.getAllFields().size() > 0)) {
 }
 context.put("pkNotFound", pkNotFound)
 
-String lastUpdateMode = parameters.get("restMethod")
+String lastUpdateMode = parameters.get("_method")
 if ((session.getAttribute("_ERROR_MESSAGE_") != null || request.getAttribute("_ERROR_MESSAGE_") != null) &&
     lastUpdateMode != null && !"DELETE".equals(lastUpdateMode)) {
     //if we are updating and there is an error, do not use the entity data for the fields, use parameters to get the old value
diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java
index 07c5233..59df1db 100644
--- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java
+++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/GenericWebEvent.java
@@ -40,6 +40,7 @@ import org.apache.ofbiz.entity.model.ModelField;
 import org.apache.ofbiz.entity.model.ModelFieldType;
 import org.apache.ofbiz.entity.model.ModelReader;
 import org.apache.ofbiz.entity.util.EntityQuery;
+import org.apache.ofbiz.entity.util.EntityUtil;
 import org.apache.ofbiz.security.Security;
 
 /**
@@ -102,15 +103,23 @@ public class GenericWebEvent {
             Debug.logError(e, module);
         }
 
+        //Check if the update came from rest call
         String updateMode = request.getParameter("UPDATE_MODE");
-        if (updateMode == null && request.getParameter("restMethod") == null) {
-            updateMode = "CREATE";
-        }
+        Map<String, Object> pkFields = null;
         if (updateMode == null) {
-            switch (request.getParameter("restMethod")) {
-                case "PUT": updateMode = "UPDATE"; break;
-                case "DELETE": updateMode = "DELETE"; break;
-                default: updateMode = "CREATE"; break;
+            switch (UtilHttp.getRequestMethod(request)) {
+            case "PUT": updateMode = "UPDATE"; break;
+            case "DELETE": updateMode = "DELETE"; break;
+            default: updateMode = "CREATE"; break;
+            }
+            try {
+                pkFields = EntityUtil.getPkValuesMapFromPath(delegator.getModelEntity(entityName),
+                        (String) request.getAttribute("pkValues"));
+            } catch (Exception e) {
+
+                request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(err_resource,
+                        "genericWebEvent.entity_path_not_valid", locale));
+                return "error";
             }
         }
 
diff --git a/framework/webtools/template/entity/ViewGeneric.ftl b/framework/webtools/template/entity/ViewGeneric.ftl
index 216eb63..7c163db 100644
--- a/framework/webtools/template/entity/ViewGeneric.ftl
+++ b/framework/webtools/template/entity/ViewGeneric.ftl
@@ -60,7 +60,7 @@ function ShowTab(lname) {
         <#if value?has_content>
           <#if hasDeletePermission>
             <form action='<@ofbizUrl>entity/change/${currentFindString}</@ofbizUrl>' method="delete" name="updateForm">
-              <input type="hidden" value="DELETE" name="restMethod"/>
+              <input type="hidden" value="DELETE" name="_method"/>
               <#list pkNamesValuesMap.keySet() as pkName>
                 <input type="hidden" value="${pkNamesValuesMap.get(pkName)}" name="${pkName}"/>
               </#list>
@@ -209,7 +209,7 @@ function ShowTab(lname) {
                     <#assign alt_row = !alt_row>
                   </#list>
                   <#if value?has_content>
-                    <input type="hidden" name="restMethod" value="PUT"/>
+                    <input type="hidden" name="_method" value="PUT"/>
                     <#assign button = "${uiLabelMap.CommonUpdate}">
                   <#else>
                     <#assign button = "${uiLabelMap.CommonCreate}">

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 04/04: Fixed: Clean unecessary code and convert to groovy syntax

nmalin
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.

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

commit 91fa4a958c504c8b88011ea33ba740dbd6451ca6
Author: Nicolas Malin <[hidden email]>
AuthorDate: Wed Jan 29 10:47:25 2020 +0100

    Fixed: Clean unecessary code and convert to groovy syntax
   
    No functional change
   
    The code present on ViewGeneric.groovy has been migrated from bsh script
    without deep rewrite.
   
    I removed all unecessary or redund code to lighten the reading
---
 .../groovyScripts/entity/ViewGeneric.groovy        | 378 ++++++---------------
 1 file changed, 109 insertions(+), 269 deletions(-)

diff --git a/framework/webtools/groovyScripts/entity/ViewGeneric.groovy b/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
index 79ef1fd..44de1d6 100644
--- a/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
+++ b/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
@@ -25,20 +25,18 @@ import org.apache.ofbiz.entity.model.ModelField
 import org.apache.ofbiz.entity.model.ModelFieldType
 import org.apache.ofbiz.entity.model.ModelRelation
 import org.apache.ofbiz.entity.model.ModelKeyMap
+import org.apache.ofbiz.base.util.StringUtil
 import org.apache.ofbiz.base.util.UtilFormatOut
 import org.apache.ofbiz.base.util.UtilMisc
-import java.sql.Timestamp
-import java.sql.Date
-import java.sql.Time
 
-String entityName = parameters.get("entityName")
-context.put("entityName", entityName)
+String entityName = parameters.entityName
+context.entityName = entityName
 
 ModelReader reader = delegator.getModelReader()
 ModelEntity entity = reader.getModelEntity(entityName)
 
-context.put("entity", entity)
-context.put("plainTableName", entity.getPlainTableName())
+context.entity = entity
+context.plainTableName = entity.getPlainTableName()
 
 boolean hasAllView = security.hasEntityPermission("ENTITY_DATA", "_VIEW", session)
 boolean hasAllCreate = security.hasEntityPermission("ENTITY_DATA", "_CREATE", session)
@@ -49,94 +47,65 @@ boolean hasCreatePermission = hasAllCreate || security.hasEntityPermission(entit
 boolean hasUpdatePermission = hasAllUpdate || security.hasEntityPermission(entity.getPlainTableName(), "_UPDATE", session)
 boolean hasDeletePermission = hasAllDelete || security.hasEntityPermission(entity.getPlainTableName(), "_DELETE", session)
 
-context.put("hasAllView", hasAllView)
-context.put("hasAllCreate", hasAllCreate)
-context.put("hasAllUpdate", hasAllUpdate)
-context.put("hasAllDelete", hasAllDelete)
-context.put("hasViewPermission", hasViewPermission)
-context.put("hasCreatePermission", hasCreatePermission)
-context.put("hasUpdatePermission", hasUpdatePermission)
+context.hasAllView = hasAllView
+context.hasAllCreate = hasAllCreate
+context.hasAllUpdate = hasAllUpdate
+context.hasAllDelete = hasAllDelete
+context.hasViewPermission = hasViewPermission
+context.hasCreatePermission = hasCreatePermission
+context.hasUpdatePermission = hasUpdatePermission
 context.hasDeletePermission = hasDeletePermission
 
-boolean useValue = true
 
+// Resolve and prepare pkValues from request to support rest or oldest request call
+Map<String, String> pkNamesValuesMap = null
 if (parameters.pkValues) {
-    Map<String, String> pkNamesValuesMap = EntityUtil.getPkValuesMapFromPath(
+    pkNamesValuesMap = EntityUtil.getPkValuesMapFromPath(
             delegator.getModelEntity(entityName), parameters.pkValues)
     parameters << pkNamesValuesMap
-    context.pkNamesValuesMap = pkNamesValuesMap
 }
 GenericValue valueFromParameters = delegator.makeValue(entityName)
 valueFromParameters.setPKFields(parameters)
 GenericPK findByPK = valueFromParameters.getPrimaryKey()
 context.currentFindString = UtilFormatOut.encodeQuery(EntityUtil.entityToPath(valueFromParameters))
-context.put("findByPk", findByPK.toString())
+context.findByPk = findByPK.toString()
+context.pkNamesValuesMap = pkNamesValuesMap ?: valueFromParameters.getPrimaryKey().getAllFields()
 
 GenericValue value = null
 //only try to find it if this is a valid primary key...
 if (findByPK.isPrimaryKey()) {
-    value = from(findByPK.getEntityName()).where(findByPK).queryOne();
+    value = from(findByPK.getEntityName()).where(findByPK).queryOne()
 }
-context.put("value", value)
+context.value = value
 
-if (value == null) {
-    useValue = false
-}
+boolean useValue = value != null
 
-if (value != null) {
+if (value) {
     List fieldList = []
     Iterator fieldIterator = entity.getFieldsIterator()
     while (fieldIterator.hasNext()) {
         Map mapField = [:]
 
         ModelField field = fieldIterator.next()
-        ModelFieldType type = delegator.getEntityFieldType(entity, field.getType())
-
-        String fieldValue = ""
-        if ("Timestamp".equals(type.getJavaType()) || "java.sql.Timestamp".equals(type.getJavaType())) {
-            Timestamp dtVal = value.getTimestamp(field.getName())
-            fieldValue = (dtVal == null) ? "" : dtVal.toString()
-        } else if ("Date".equals(type.getJavaType()) || "java.sql.Date".equals(type.getJavaType())) {
-            Date dateVal = value.getDate(field.getName())
-            fieldValue = (dateVal == null) ? "" : dateVal.toString()
-        } else if ("Time".equals(type.getJavaType()) || "java.sql.Time".equals(type.getJavaType())) {
-            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("BigDecimal") >= 0) {
-            fieldValue = UtilFormatOut.safeToString((BigDecimal)value.get(field.getName()))
-        } else if (type.getJavaType().indexOf("String") >= 0) {
-            fieldValue = UtilFormatOut.checkNull((String)value.get(field.getName()))
-        }
-        mapField.put("name", field.getName())
-        mapField.put("value", fieldValue)
 
-        fieldList.add(mapField)
+        String fieldValue = UtilFormatOut.safeToString(value.get(field.getName()))
+        mapField.name = field.getName()
+        mapField.value = fieldValue
+
+        fieldList << mapField
     }
-    context.put("fields", fieldList)
+    context.fields = fieldList
 }
 
-GenericValue valueSave = value
-boolean pkNotFound = false
-if (value == null && (findByPK.getAllFields().size() > 0)) {
-    pkNotFound = true
-}
-context.put("pkNotFound", pkNotFound)
+context.pkNotFound = !value && !findByPK.getAllFields().isEmpty()
 
 String lastUpdateMode = parameters.get("_method")
 if ((session.getAttribute("_ERROR_MESSAGE_") != null || request.getAttribute("_ERROR_MESSAGE_") != null) &&
-    lastUpdateMode != null && !"DELETE".equals(lastUpdateMode)) {
+    lastUpdateMode != null && "DELETE" != lastUpdateMode) {
     //if we are updating and there is an error, do not use the entity data for the fields, use parameters to get the old value
     useValue = false
 }
-context.put("useValue", useValue)
+context.useValue = useValue
 
 List newFieldPkList = []
 pkIterator = entity.getPksIterator()
@@ -146,74 +115,32 @@ while (pkIterator.hasNext()) {
     ModelField field = pkIterator.next()
     ModelFieldType type = delegator.getEntityFieldType(entity, field.getType())
 
-    String fieldValue = ""
-    String fieldType = ""
     String stringLength = ""
-    if ("Timestamp".equals(type.getJavaType()) || "java.sql.Timestamp".equals(type.getJavaType())) {
-        String dateTimeString = null
-        if (findByPK != null && useValue) {
-            Timestamp dtVal = findByPK.getTimestamp(field.getName())
-            if (dtVal != null) {
-              dateTimeString = dtVal.toString()
-            }
-        } else if (!useValue) {
-            dateTimeString = parameters.get(field.getName())
-        }
-        fieldValue = UtilFormatOut.checkNull(dateTimeString)
+    String fieldName = field.getName()
+    String fieldValue = findByPK && useValue ?
+            UtilFormatOut.safeToString(findByPK.get(fieldName)) :
+            (useValue ? "" : UtilFormatOut.checkNull(parameters.get(fieldName)))
+    String javaType = StringUtil.split(type.getJavaType(), ".").last()
+    String fieldType = javaType
+    if ("Timestamp" == javaType) {
         fieldType = "DateTime"
-    } else if ("Date".equals(type.getJavaType()) || "java.sql.Date".equals(type.getJavaType())) {
-        String dateString = null
-        if (findByPK != null && useValue) {
-            Date dateVal = findByPK.getDate(field.getName())
-            dateString = (dateVal == null) ? "" : dateVal.toString()
-        } else if (!useValue) {
-            dateString = parameters.get(field.getName())
-        }
-        fieldValue = UtilFormatOut.checkNull(dateString)
-        fieldType = "Date"
-    } else if ("Time".equals(type.getJavaType()) || "java.sql.Time".equals(type.getJavaType())) {
-        String timeString = null
-        if (findByPK != null && useValue) {
-            Time timeVal = findByPK.getTime(field.getName())
-            timeString = (timeVal == null) ? "" : timeVal.toString()
-        } else if (!useValue) {
-            timeString = parameters.get(field.getName())
-        }
-        fieldValue = UtilFormatOut.checkNull(timeString)
-        fieldType = "Time"
-    } else if (type.getJavaType().indexOf("Integer") >= 0) {
-        fieldValue = (findByPK != null && useValue) ? UtilFormatOut.safeToString((Integer)findByPK.get(field.getName())) : (useValue ? "" : UtilFormatOut.checkNull(parameters.get(field.getName())))
-        fieldType = "Integer"
-    } else if (type.getJavaType().indexOf("Long") >= 0) {
-        fieldValue = (findByPK != null && useValue) ? UtilFormatOut.safeToString((Long)findByPK.get(field.getName())) : (useValue ? "" : UtilFormatOut.checkNull(parameters.get(field.getName())))
-        fieldType = "Long"
-    } else if (type.getJavaType().indexOf("Double") >= 0) {
-        fieldValue = (findByPK != null && useValue) ? UtilFormatOut.safeToString((Double)findByPK.get(field.getName())) : (useValue ? "" : UtilFormatOut.checkNull(parameters.get(field.getName())))
-        fieldType = "Double"
-    } else if (type.getJavaType().indexOf("Float") >= 0) {
-        fieldValue = (findByPK != null && useValue) ? UtilFormatOut.safeToString((Float)findByPK.get(field.getName())) : (useValue ? "" : UtilFormatOut.checkNull(parameters.get(field.getName())))
-        fieldType = "Float"
-    } else if (type.getJavaType().indexOf("String") >= 0) {
-        if (type.stringLength() <= 80) {
-            fieldValue = (findByPK != null && useValue) ? UtilFormatOut.checkNull((String)findByPK.get(field.getName())) : (useValue ? "" : UtilFormatOut.checkNull(parameters.get(field.getName())))
-            fieldType = "StringOneRow"
-        } else if (type.stringLength() <= 255) {
-            fieldValue = (findByPK != null && useValue) ? UtilFormatOut.checkNull((String)findByPK.get(field.getName())) : (useValue ? "" : UtilFormatOut.checkNull(parameters.get(field.getName())))
-            fieldType = "String"
-        } else {
-            fieldValue = (findByPK != null && useValue) ? UtilFormatOut.checkNull((String)findByPK.get(field.getName())):(useValue?"":UtilFormatOut.checkNull(parameters.get(field.getName())))
-            fieldType = "Textarea"
+    } else {
+        if ("String" == javaType) {
+            if (type.stringLength() <= 80) {
+                fieldType = "StringOneRow"
+            } else if (type.stringLength() > 255) {
+                fieldType = "Textarea"
+            }
+            stringLength = type.stringLength().toString()
         }
-        stringLength = type.stringLength().toString()
     }
-    mapField.put("name", field.getName())
-    mapField.put("value", fieldValue)
-    mapField.put("fieldType", fieldType)
-    mapField.put("stringLength", stringLength)
-
-    newFieldPkList.add(mapField)
+    mapField.name = fieldName
+    mapField.value = fieldValue
+    mapField.fieldType = fieldType
+    mapField.stringLength = stringLength
+    newFieldPkList << mapField
 }
-context.put("newFieldPkList", newFieldPkList)
+context.newFieldPkList = newFieldPkList
 
 List newFieldNoPkList = []
 Iterator noPkIterator = entity.getNopksIterator()
@@ -222,78 +149,34 @@ while (noPkIterator.hasNext()) {
 
     ModelField field = noPkIterator.next()
     ModelFieldType type = delegator.getEntityFieldType(entity, field.getType())
+    String fieldName = field.getName()
+    String fieldValue =  useValue ?
+            UtilFormatOut.safeToString(value.get(fieldName)) :
+            UtilFormatOut.checkNull(parameters.get(fieldName))
 
-    String fieldValue = ""
-    String fieldType = ""
+    String javaType = StringUtil.split(type.getJavaType(), ".").last()
     String stringLength = ""
-    if ("Timestamp".equals(type.getJavaType()) || "java.sql.Timestamp".equals(type.getJavaType())) {
-        String dateTimeString = null
-        if (value != null && useValue) {
-            Timestamp dtVal = value.getTimestamp(field.getName())
-            if (dtVal != null) {
-              dateTimeString = dtVal.toString()
-            }
-        } else if (!useValue) {
-            dateTimeString = parameters.get(field.getName())
-        }
-        fieldValue = UtilFormatOut.checkNull(dateTimeString)
+    String fieldType = javaType
+    if ("Timestamp" == javaType) {
         fieldType = "DateTime"
-    } else if ("Date".equals(type.getJavaType()) || "java.sql.Date".equals(type.getJavaType())) {
-        String dateString = null
-        if (value != null && useValue) {
-            Date dateVal = value.getDate(field.getName())
-            dateString = (dateVal == null) ? "" : dateVal.toString()
-        } else if (!useValue) {
-            dateString = parameters.get(field.getName())
-        }
-        fieldValue = UtilFormatOut.checkNull(dateString)
-        fieldType = "Date"
-    } else if ("Time".equals(type.getJavaType()) || "java.sql.Time".equals(type.getJavaType())) {
-        String timeString = null
-        if (value != null && useValue) {
-            Time timeVal = value.getTime(field.getName())
-            timeString = (timeVal == null) ? "" : timeVal.toString()
-        } else if (!useValue) {
-            timeString = parameters.get(field.getName())
-        }
-        fieldValue = UtilFormatOut.checkNull(timeString)
-        fieldType = "Time"
-    } else if (type.getJavaType().indexOf("Integer") >= 0) {
-        fieldValue = (value != null && useValue) ? UtilFormatOut.safeToString((Integer)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-        fieldType = "Integer"
-    } else if (type.getJavaType().indexOf("Long") >= 0) {
-        fieldValue = (value != null && useValue) ? UtilFormatOut.safeToString((Long)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-        fieldType = "Long"
-    } else if (type.getJavaType().indexOf("Double") >= 0) {
-        fieldValue = (value != null && useValue) ? UtilFormatOut.safeToString((Double)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-        fieldType = "Double"
-    } else if (type.getJavaType().indexOf("Float") >= 0) {
-        fieldValue = (value != null && useValue) ? UtilFormatOut.safeToString((Float)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-        fieldType = "Float"
-    } else if (type.getJavaType().indexOf("BigDecimal") >= 0) {
-        fieldValue = (value != null && useValue) ? UtilFormatOut.safeToString((BigDecimal)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-        fieldType = "BigDecimal"
-    } else if (type.getJavaType().indexOf("String") >= 0) {
-        if (type.stringLength() <= 80) {
-            fieldValue = (value != null && useValue) ? UtilFormatOut.checkNull((String)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-            fieldType = "StringOneRow"
-        } else if (type.stringLength() <= 255) {
-            fieldValue = (value != null && useValue) ? UtilFormatOut.checkNull((String)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-            fieldType = "String"
-        } else {
-            fieldValue = (value != null && useValue) ? UtilFormatOut.checkNull((String)value.get(field.getName())):UtilFormatOut.checkNull(parameters.get(field.getName()))
-            fieldType = "Textarea"
+    } else {
+        if ("String" == javaType) {
+            if (type.stringLength() <= 80) {
+                fieldType = "StringOneRow"
+            } else if (type.stringLength() > 255) {
+                fieldType = "Textarea"
+            }
+            stringLength = type.stringLength().toString()
         }
-        stringLength = type.stringLength().toString()
     }
-    mapField.put("name", field.getName())
-    mapField.put("value", fieldValue)
-    mapField.put("fieldType", fieldType)
-    mapField.put("stringLength", stringLength)
+    mapField.name = fieldName
+    mapField.value = fieldValue
+    mapField.fieldType = fieldType
+    mapField.stringLength = stringLength
 
-    newFieldNoPkList.add(mapField)
+    newFieldNoPkList << mapField
 }
-context.put("newFieldNoPkList", newFieldNoPkList)
+context.newFieldNoPkList = newFieldNoPkList
 
 List relationFieldList = []
 for (int relIndex = 0; relIndex < entity.getRelationsSize(); relIndex++) {
@@ -302,24 +185,21 @@ for (int relIndex = 0; relIndex < entity.getRelationsSize(); relIndex++) {
     ModelRelation relation = entity.getRelation(relIndex)
     ModelEntity relatedEntity = reader.getModelEntity(relation.getRelEntityName())
 
-    boolean relCreate = false
-    if (security.hasEntityPermission(relatedEntity.getPlainTableName(), "_CREATE", session)) {
-        relCreate = true
-    }
+    boolean relCreate = security.hasEntityPermission(relatedEntity.getPlainTableName(), "_CREATE", session)
 
-    mapRelation.put("type", relation.getType())
-    mapRelation.put("title", relation.getTitle())
-    mapRelation.put("relEntityName", relation.getRelEntityName())
-    mapRelation.put("sortName", relation.getTitle() + relation.getRelEntityName())
-    mapRelation.put("relatedTable", relatedEntity.getEntityName())
-    mapRelation.put("relCreate", relCreate)
+    mapRelation.type = relation.getType()
+    mapRelation.title = relation.getTitle()
+    mapRelation.relEntityName = relation.getRelEntityName()
+    mapRelation.sortName = relation.getTitle() + relation.getRelEntityName()
+    mapRelation.relatedTable = relatedEntity.getEntityName()
+    mapRelation.relCreate = relCreate
 
-    if ("one".equals(relation.getType()) || "one-nofk".equals(relation.getType())) {
-        if (value != null) {
+    if ("one" == relation.getType() || "one-nofk" == relation.getType()) {
+        if (value) {
             if (hasAllView || security.hasEntityPermission(relatedEntity.getPlainTableName(), "_VIEW", session)) {
                 Iterator tempIter = UtilMisc.toIterator(value.getRelated(relation.getTitle() + relatedEntity.getEntityName(), null, null, false))
                 GenericValue valueRelated = null
-                if (tempIter != null && tempIter.hasNext()) {
+                if (tempIter && tempIter.hasNext()) {
                     valueRelated = (GenericValue) tempIter.next()
                 }
 
@@ -329,100 +209,60 @@ for (int relIndex = 0; relIndex < entity.getRelationsSize(); relIndex++) {
                     Map mapRelatedFields = [:]
                     ModelField field = relFieldIterator.next()
                     ModelFieldType type = delegator.getEntityFieldType(entity, field.getType())
+                    String fieldName = field.getName()
+
+                    String fieldValue =  valueRelated ?
+                            UtilFormatOut.safeToString(valueRelated.get(fieldName)) : ""
 
-                    String fieldValue = ""
-                    String fieldType = ""
-                    if ("Timestamp".equals(type.getJavaType()) || "java.sql.Timestamp".equals(type.getJavaType())) {
-                        Timestamp dtVal = null
-                        if (valueRelated != null) {
-                            dtVal = valueRelated.getTimestamp(field.getName())
-                        }
-                        fieldValue = (dtVal == null) ? "" : dtVal.toString()
+                    String javaType = StringUtil.split(type.getJavaType(), ".").last()
+                    String fieldType = javaType
+                    if ("Timestamp" == javaType) {
                         fieldType = "DateTime"
-                    } else if ("Date".equals(type.getJavaType()) || "java.sql.Date".equals(type.getJavaType())) {
-                        Date dateVal = null
-                        if (valueRelated != null) {
-                            dateVal = valueRelated.getDate(field.getName())
-                        }
-                        fieldValue = (dateVal == null) ? "" : dateVal.toString()
-                        fieldType = "Date"
-                    } else if ("Time".equals(type.getJavaType()) || "java.sql.Time".equals(type.getJavaType())) {
-                        Time timeVal = null
-                        if (valueRelated != null) {
-                            timeVal = valueRelated.getTime(field.getName())
-                        }
-                        fieldValue = (timeVal == null) ? "" : timeVal.toString()
-                        fieldType = "Time"
-                    } else if (type.getJavaType().indexOf("Integer") >= 0) {
-                        if (valueRelated != null) {
-                            fieldValue = UtilFormatOut.safeToString((Integer)valueRelated.get(field.getName()))
-                        }
-                        fieldType = "Integer"
-                    } else if (type.getJavaType().indexOf("Long") >= 0) {
-                        if (valueRelated != null) {
-                            fieldValue = UtilFormatOut.safeToString((Long)valueRelated.get(field.getName()))
-                        }
-                        fieldType = "Long"
-                    } else if (type.getJavaType().indexOf("Double") >= 0) {
-                        if (valueRelated != null) {
-                            fieldValue = UtilFormatOut.safeToString((Double)valueRelated.get(field.getName()))
-                        }
-                        fieldType = "Double"
-                    } else if (type.getJavaType().indexOf("Float") >= 0) {
-                        if (valueRelated != null) {
-                            fieldValue = UtilFormatOut.safeToString((Float)valueRelated.get(field.getName()))
-                        }
-                        fieldType = "Float"
-                    } else if (type.getJavaType().indexOf("String") >= 0) {
-                        if (valueRelated != null) {
-                            fieldValue = UtilFormatOut.checkNull((String)valueRelated.get(field.getName()))
-                        }
-                        fieldType = "String"
                     }
 
-                    mapRelatedFields.put("name", field.getName())
-                    mapRelatedFields.put("type", fieldType)
-                    mapRelatedFields.put("value", fieldValue)
-                    relatedFieldsList.add(mapRelatedFields)
+                    mapRelatedFields.name = fieldName
+                    mapRelatedFields.type = fieldType
+                    mapRelatedFields.value = fieldValue
+                    relatedFieldsList << mapRelatedFields
                 }
 
-                mapRelation.put("valueRelated", valueRelated)
-                if (valueRelated != null) {
-                    mapRelation.put("valueRelatedPk", valueRelated.getPrimaryKey().toString())
+                mapRelation.valueRelated = valueRelated
+                if (valueRelated) {
+                    mapRelation.valueRelatedPk = valueRelated.getPrimaryKey().toString()
                 }
-                mapRelation.put("relatedFieldsList", relatedFieldsList)
-                mapRelation.put("relType", "one")
+                mapRelation.relatedFieldsList = relatedFieldsList
+                mapRelation.relType = "one"
 
                 String findString = "entityName=" + relatedEntity.getEntityName()
                 for (ModelKeyMap keyMap : relation.getKeyMaps()) {
-                    if (value.get(keyMap.getFieldName()) != null) {
+                    if (value.get(keyMap.getFieldName())) {
                         findString += "&" + keyMap.getRelFieldName() + "=" + value.get(keyMap.getFieldName())
                     }
                 }
                 String encodeFindString = UtilFormatOut.encodeQuery(findString)
-                mapRelation.put("encodeRelatedEntityFindString", encodeFindString)
+                mapRelation.encodeRelatedEntityFindString = encodeFindString
 
-                relationFieldList.add(mapRelation)
+                relationFieldList << mapRelation
             }
         }
-    } else if (relation.getType().equalsIgnoreCase("many")) {
-        if (value != null) {
+    } else if (relation.getType() == "many") {
+        if (value) {
             if (hasAllView || security.hasEntityPermission(relatedEntity.getPlainTableName(), "_VIEW", session)) {
-                mapRelation.put("relType", "many")
+                mapRelation.relType = "many"
 
                 String findString = "entityName=" + relatedEntity.getEntityName()
                 for (ModelKeyMap keyMap : relation.getKeyMaps()) {
-                    if (value.get(keyMap.getFieldName()) != null) {
+                    if (value.get(keyMap.getFieldName())) {
                         findString += "&" + keyMap.getRelFieldName() + "=" + value.get(keyMap.getFieldName())
                     }
                 }
                 String encodeFindString = UtilFormatOut.encodeQuery(findString)
-                mapRelation.put("encodeRelatedEntityFindString", encodeFindString)
+                mapRelation.encodeRelatedEntityFindString = encodeFindString
 
-                relationFieldList.add(mapRelation)
+                relationFieldList << mapRelation
             }
         }
     }
 }
-context.put("relationFieldList", UtilMisc.sortMaps(relationFieldList, UtilMisc.toList("sortName")))
-context.put("relSize", relationFieldList.size() + 2)
+context.relationFieldList = UtilMisc.sortMaps(relationFieldList, ["sortName"])
+context.relSize = (relationFieldList.size() + 2)