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


The following commit(s) were added to refs/heads/trunk by this push:
     new 4ffbd8a  Fixed: CategoryTree.groovy
4ffbd8a is described below

commit 4ffbd8a257f2e148d6f9dd98ddde6a6e14d540e1
Author: Nicolas Malin <nicolas.ma...@nereide.fr>
AuthorDate: Tue Sep 28 11:22:13 2021 +0200

    Fixed: CategoryTree.groovy
    
    No functional change, review the code to down less it :
     * Use groovy syntax
     * Use DSL when is not use as it should
     * Add missing variable type, for most ide analyser potential
---
 .../groovyScripts/category/CategoryTree.groovy     | 43 ++++++++++------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/applications/humanres/groovyScripts/category/CategoryTree.groovy 
b/applications/humanres/groovyScripts/category/CategoryTree.groovy
index a2cee50..27d9ef9 100644
--- a/applications/humanres/groovyScripts/category/CategoryTree.groovy
+++ b/applications/humanres/groovyScripts/category/CategoryTree.groovy
@@ -17,43 +17,40 @@
  * under the License.
  */
 
-/*
- * This script is also referenced by the ecommerce's screens and
- * should not contain order component's specific code.
- */
+import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.party.party.PartyHelper
 
-// Put the result of CategoryWorker.getRelatedCategories into the 
separateRootType function as attribute.
-// The separateRootType function will return the list of category of given 
catalog.
 // PLEASE NOTE : The structure of the list of separateRootType function is 
according to the JSON_DATA plugin of the jsTree.
 
-completedTree =  []
-completedTreeContext = []
-subtopLists = []
+List completedTree =  []
+List completedTreeContext = []
+List subTopList = []
 
 //internalOrg list
-partyRelationships = from("PartyRelationship").where("partyIdFrom", partyId, 
"partyRelationshipTypeId", "GROUP_ROLLUP").filterByDate().queryList()
+List partyRelationships = from("PartyRelationship")
+        .where(partyIdFrom: partyId,
+                partyRelationshipTypeId: "GROUP_ROLLUP")
+        .filterByDate()
+        .cache()
+        .queryList()
 if (partyRelationships) {
     //root
-    partyRoot = from("PartyGroup").where("partyId", partyId).queryOne()
-    partyRootMap = [:]
-    partyRootMap.put("partyId", partyId)
-    partyRootMap.put("groupName", partyRoot.getString("groupName"))
+    GenericValue partyRoot = from("PartyGroup").where(partyId: 
partyId).cache().queryOne()
+    Map partyRootMap = [partyId  : partyId,
+                        groupName: partyRoot.groupName]
 
     //child
-    for(partyRelationship in partyRelationships) {
-        partyGroupMap = [:]
-        partyGroupMap.put("partyId", partyRelationship.getString("partyIdTo"))
-        partyGroupMap.put("groupName", PartyHelper.getPartyName(delegator, 
partyRelationship.getString("partyIdTo"), false))
-        completedTreeContext.add(partyGroupMap)
+    partyRelationships.each {
+        completedTreeContext << [partyId  : it.partyIdTo,
+                                 groupName: 
PartyHelper.getPartyName(delegator, it.partyIdTo, false)]
 
-        subtopLists.addAll(partyRelationship.getString("partyIdTo"))
+        subTopList << it.partyIdTo
     }
 
-    partyRootMap.put("child", completedTreeContext)
-    completedTree.add(partyRootMap)
+    partyRootMap.child = completedTreeContext
+    completedTree << partyRootMap
 }
 
 // The complete tree list for the category tree
 context.completedTree = completedTree
-context.subtopLists = subtopLists
+context.subtopLists = subTopList

Reply via email to