details:   https://code.openbravo.com/erp/devel/pi/rev/2c80088f99e5
changeset: 34842:2c80088f99e5
user:      Atul Gaware <atul.gaware <at> openbravo.com>
date:      Mon Oct 15 08:56:15 2018 +0530
summary:   Fixes Issue 0039340: Performance issue in Budget window.

** Use Deque to avoid repeatative exploring of elements
in the tree. Deprecate old methods getNaturalTree, getChildTree,
getChildNode, Define new methods getChildrenOf, getChildrenOfTreeNode

** Move fetching of trees and treenodes in separated methods
getTreeIdsFromTreeType & getTreeIdsFromTreeType respectively.

details:   https://code.openbravo.com/erp/devel/pi/rev/0ac854acbc99
changeset: 34843:0ac854acbc99
user:      Atul Gaware <atul.gaware <at> openbravo.com>
date:      Mon Oct 15 15:30:30 2018 +0530
summary:   Related To Issue 39340:Performance in budget window when exporting 
to excel.

** Add year from budget header as filter in the query.
** Use StringUtils.equals to avoid NPE.
** Use braces in if loops to make code more readable.
** Avoid printStackTrace()

details:   https://code.openbravo.com/erp/devel/pi/rev/2e0dfe691859
changeset: 34844:2e0dfe691859
user:      Sandra Huguet <sandra.huguet <at> openbravo.com>
date:      Mon Oct 15 13:42:19 2018 +0200
summary:   related to issue 39340 update Copyright year

diffstat:

 src/org/openbravo/erpCommon/ad_process/UpdateActuals.java           |  28 ++--
 src/org/openbravo/erpCommon/ad_reports/ReportBudgetExportExcel.java |  16 +-
 src/org/openbravo/erpCommon/utility/TreeUtility.java                |  65 
++++++++-
 3 files changed, 80 insertions(+), 29 deletions(-)

diffs (238 lines):

diff -r 618fcb380761 -r 2e0dfe691859 
src/org/openbravo/erpCommon/ad_process/UpdateActuals.java
--- a/src/org/openbravo/erpCommon/ad_process/UpdateActuals.java Mon Oct 15 
10:41:39 2018 +0200
+++ b/src/org/openbravo/erpCommon/ad_process/UpdateActuals.java Mon Oct 15 
13:42:19 2018 +0200
@@ -93,25 +93,25 @@
         // get the natural tree
         TreeUtility treeUtility = new TreeUtility();
         String activityTree = activity != null ? 
commaSeparated(treeUtility.getChildTree(activity,
-            "AY", true)) : activity;
+            "AY")) : activity;
         String productCategoryTree = productCategory != null ? 
commaSeparated(treeUtility
-            .getChildTree(productCategory, "PC", true)) : productCategory;
-        String assetTree = asset != null ? 
commaSeparated(treeUtility.getChildTree(asset, "AS",
-            true)) : asset;
+            .getChildTree(productCategory, "PC")) : productCategory;
+        String assetTree = asset != null ? 
commaSeparated(treeUtility.getChildTree(asset, "AS"))
+            : asset;
         String costcenterTree = costcenter != null ? 
commaSeparated(treeUtility.getChildTree(
-            costcenter, "CC", true)) : costcenter;
+            costcenter, "CC")) : costcenter;
         String accountTree = account != null ? 
commaSeparated(treeUtility.getChildTree(account,
-            "EV", true)) : account;
+            "EV")) : account;
         String projectTree = project != null ? 
commaSeparated(treeUtility.getChildTree(project,
-            "PJ", true)) : project;
+            "PJ")) : project;
         String campaignTree = salesCampaign != null ? 
commaSeparated(treeUtility.getChildTree(
-            salesCampaign, "MC", true)) : salesCampaign;
+            salesCampaign, "MC")) : salesCampaign;
         String regionTree = salesRegion != null ? 
commaSeparated(treeUtility.getChildTree(
-            salesRegion, "SR", true)) : salesRegion;
-        String user1Tree = user1 != null ? 
commaSeparated(treeUtility.getChildTree(user1, "U1",
-            true)) : user1;
-        String user2Tree = user2 != null ? 
commaSeparated(treeUtility.getChildTree(user2, "U2",
-            true)) : user2;
+            salesRegion, "SR")) : salesRegion;
+        String user1Tree = user1 != null ? 
commaSeparated(treeUtility.getChildTree(user1, "U1"))
+            : user1;
+        String user2Tree = user2 != null ? 
commaSeparated(treeUtility.getChildTree(user2, "U2"))
+            : user2;
 
         final String orgId = myBudget.getOrganization().getId();
 
@@ -124,6 +124,8 @@
         queryString.append(" from FinancialMgmtAccountingFact e where");
         queryString.append(" 
e.client.id='").append(myBudget.getClient().getId()).append("'");
         queryString.append(" and e.organization.id in 
(").append(OrgTreeList).append(")");
+        queryString.append(" and 
e.period.year.id='").append(myBudget.getYear().getId())
+            .append("'");
 
         if (!"".equals(activity)) {
           queryString.append(" and e.activity.id in 
(").append(activityTree).append(")");
diff -r 618fcb380761 -r 2e0dfe691859 
src/org/openbravo/erpCommon/ad_reports/ReportBudgetExportExcel.java
--- a/src/org/openbravo/erpCommon/ad_reports/ReportBudgetExportExcel.java       
Mon Oct 15 10:41:39 2018 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportBudgetExportExcel.java       
Mon Oct 15 13:42:19 2018 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,6 +27,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang.StringUtils;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.service.OBDal;
@@ -49,15 +50,17 @@
       String strKey = vars.getRequiredGlobalVariable("inpcBudgetId",
           "ReportBudgetGenerateExcel|inpcBudgetId");
       printPageDataExportExcel(response, vars, strKey);
-    } else
+    } else {
       pageErrorPopUp(response);
+    }
   }
 
   private void printPageDataExportExcel(HttpServletResponse response, 
VariablesSecureApp vars,
       String strBudgetId) throws IOException, ServletException {
 
-    if (log4j.isDebugEnabled())
+    if (log4j.isDebugEnabled()) {
       log4j.debug("Output: EXCEL");
+    }
 
     vars.removeSessionValue("ReportBudgetGenerateExcel|inpTabId");
 
@@ -78,16 +81,16 @@
         OBError myMessage = null;
         new UpdateActuals().execute(pb);
         myMessage = (OBError) pb.getResult();
-        if (myMessage != null && "Error".equals(myMessage.getType())) {
+        if (myMessage != null && StringUtils.equals("Error", 
myMessage.getType())) {
           log4j.error(myMessage.getMessage());
         }
       } catch (Exception e) {
-        e.printStackTrace();
+        log4j.error("Error in printPageDataExportExcel of 
ReportBudgetExportExcel", e);
       }
     }
     data = ReportBudgetGenerateExcelData.selectLines(this, vars.getLanguage(), 
strBudgetId);
 
-    if (data.length != 0 && data[0].exportactual.equals("Y")) {
+    if (data.length != 0 && StringUtils.equals(data[0].exportactual, "Y")) {
       xmlDocument = xmlEngine.readXmlTemplate(
           
"org/openbravo/erpCommon/ad_reports/ReportBudgetGenerateExcelXLS").createXmlDocument();
     } else {
@@ -101,6 +104,7 @@
 
     xmlDocument.setData("structure1", data);
     out.println(xmlDocument.print());
+    out.close();
 
   }
 
diff -r 618fcb380761 -r 2e0dfe691859 
src/org/openbravo/erpCommon/utility/TreeUtility.java
--- a/src/org/openbravo/erpCommon/utility/TreeUtility.java      Mon Oct 15 
10:41:39 2018 +0200
+++ b/src/org/openbravo/erpCommon/utility/TreeUtility.java      Mon Oct 15 
13:42:19 2018 +0200
@@ -18,7 +18,9 @@
  */
 package org.openbravo.erpCommon.utility;
 
+import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -41,6 +43,7 @@
   /**
    * Gets Natural tree for the given node
    */
+  @Deprecated
   public Set<String> getNaturalTree(String nodeId, String treeType) {
     initialize(treeType);
     Set<String> result;
@@ -57,6 +60,7 @@
   /**
    * Gets the Child tree for the given node, including optionally given node
    */
+  @Deprecated
   public Set<String> getChildTree(String nodeId, String treeType, boolean 
includeNode) {
     initialize(treeType);
     Set<String> childNode = this.getChildNode(nodeId, treeType);
@@ -75,9 +79,41 @@
     return result;
   }
 
+  public Set<String> getChildTree(String nodeId, String treeType) {
+    Set<String> result = new HashSet<>();
+
+    Deque<String> pendingNodes = new ArrayDeque<>();
+    pendingNodes.push(nodeId);
+
+    while (!pendingNodes.isEmpty()) {
+      String nextNodeId = pendingNodes.pop();
+      result.add(nextNodeId);
+      pendingNodes.addAll(getChildrenOf(nextNodeId, treeType));
+    }
+    return result;
+  }
+
+  private List<String> getChildrenOf(String nodeId, String treeType) {
+    List<Tree> treeIds = getTreeIdsFromTreeType(treeType);
+    List<String> treeNodeIds = new ArrayList<>();
+    for (Tree tree : treeIds) {
+      treeNodeIds.addAll(getChildrenOfTreeNode(tree, nodeId));
+    }
+    return treeNodeIds;
+  }
+
+  private List<String> getChildrenOfTreeNode(final Tree t, String nodeId) {
+    final String nodeQryStr = "select tn.node from " + TreeNode.class.getName()
+        + " tn where tn.tree.id='" + t.getId() + "' and tn.reportSet = '" + 
nodeId + "'";
+    final Query<String> nodeQry = SessionHandler.getInstance()
+        .createQuery(nodeQryStr, String.class);
+    return nodeQry.list();
+  }
+
   /**
    * Gets Child node in the tree
    */
+  @Deprecated
   public Set<String> getChildNode(String nodeId, String treeType) {
     initialize(treeType);
     if (childTrees.get(nodeId) == null) {
@@ -87,21 +123,14 @@
     }
   }
 
+  @Deprecated
   private void initialize(String treeType) {
 
-    final String clientId = 
OBContext.getOBContext().getCurrentClient().getId();
-    final String qryStr = "select t from " + Tree.class.getName() + " t where 
treetype='"
-        + treeType + "' and client.id='" + clientId + "'";
-    final Query<Tree> qry = SessionHandler.getInstance().createQuery(qryStr, 
Tree.class);
-    final List<Tree> ts = qry.list();
+    final List<Tree> ts = getTreeIdsFromTreeType(treeType);
 
     final List<TreeNode> treeNodes = new ArrayList<>();
     for (final Tree t : ts) {
-      final String nodeQryStr = "select tn from " + TreeNode.class.getName()
-          + " tn where tn.tree.id='" + t.getId() + "'";
-      final Query<TreeNode> nodeQry = 
SessionHandler.getInstance().createQuery(nodeQryStr,
-          TreeNode.class);
-      final List<TreeNode> tns = nodeQry.list();
+      final List<TreeNode> tns = getTreeNodesOfTree(t);
       treeNodes.addAll(tns);
     }
 
@@ -126,6 +155,22 @@
       }
     }
   }
+
+  private List<TreeNode> getTreeNodesOfTree(final Tree t) {
+    final String nodeQryStr = "select tn from " + TreeNode.class.getName()
+        + " tn where tn.tree.id='" + t.getId() + "'";
+    final Query<TreeNode> nodeQry = 
SessionHandler.getInstance().createQuery(nodeQryStr,
+        TreeNode.class);
+    return nodeQry.list();
+  }
+
+  private List<Tree> getTreeIdsFromTreeType(String treeType) {
+    final String clientId = 
OBContext.getOBContext().getCurrentClient().getId();
+    final String qryStr = "select t from " + Tree.class.getName() + " t where 
treetype='"
+        + treeType + "' and client.id='" + clientId + "'";
+    final Query<Tree> qry = SessionHandler.getInstance().createQuery(qryStr, 
Tree.class);
+    return qry.list();
+  }
 }
 
 class Node {


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to