details: https://code.openbravo.com/erp/devel/pi/rev/ac4b02fa805d changeset: 33046:ac4b02fa805d user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Mon Nov 27 11:47:35 2017 +0100 summary: related to issue 37387: initial code improvements
- Add constants that were defined as local variables - getTree and createTree private methods were defining an unused parameter - Avoid String concatenation in log messages - Use diamond operator diffstat: modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java | 36 ++++----- 1 files changed, 17 insertions(+), 19 deletions(-) diffs (119 lines): diff -r a2e1574d92e2 -r ac4b02fa805d modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java --- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java Mon Nov 27 11:22:37 2017 +0100 +++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java Mon Nov 27 11:47:35 2017 +0100 @@ -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) 2013-2016 Openbravo SLU + * All portions are Copyright (C) 2013-2017 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -68,6 +68,10 @@ private static final Logger logger = LoggerFactory.getLogger(ADTreeDatasourceService.class); private static final String AD_MENU_TABLE_ID = "116"; private static final String AD_ORG_TABLE_ID = "155"; + private static final int PARENT_ID = 1; + private static final int SEQNO = 2; + private static final int NODE_ID = 3; + private static final int ENTITY = 4; @Override /** @@ -86,10 +90,10 @@ if (tableTree.isHandleNodesManually()) { return; } - Tree adTree = getTree(table, bobProperties); + Tree adTree = getTree(table); if (adTree == null) { // The adTree does not exists, create it - adTree = createTree(table, bobProperties); + adTree = createTree(table); } // Adds the node to the adTree TreeNode adTreeNode = OBProvider.getInstance().get(TreeNode.class); @@ -120,7 +124,7 @@ if (tableTree.isHandleNodesManually()) { return; } - Tree tree = getTree(table, bobProperties); + Tree tree = getTree(table); OBCriteria<TreeNode> adTreeNodeCriteria = OBDal.getInstance().createCriteria(TreeNode.class); adTreeNodeCriteria.setFilterOnActive(false); adTreeNodeCriteria.add(Restrictions.eq(TreeNode.PROPERTY_TREE, tree)); @@ -128,7 +132,7 @@ TreeNode treeNode = (TreeNode) adTreeNodeCriteria.uniqueResult(); int nChildrenMoved = reparentChildrenOfDeletedNode(tree, treeNode.getReportSet(), treeNode.getNode()); - logger.info(nChildrenMoved + " children have been moved to another parent"); + logger.info("{} children have been moved to another parent", nChildrenMoved); OBDal.getInstance().remove(treeNode); } catch (Exception e) { logger.error("Error while deleting tree node: ", e); @@ -257,8 +261,8 @@ // Selects the relevant properties from ADTreeNode and all the properties from the referenced // table String selectClause = " tn.id as treeNodeId, tn.reportSet as parentId, tn.sequenceNumber as seqNo, tn.node as nodeId, e as entity"; - OBQuery<BaseOBObject> obq = OBDal.getInstance() - .createQuery("ADTreeNode", joinClause.toString()); + OBQuery<BaseOBObject> obq = OBDal.getInstance().createQuery(TreeNode.ENTITY_NAME, + joinClause.toString()); obq.setFilterOnActive(false); obq.setSelectClause(selectClause); obq.setFilterOnReadableOrganization(false); @@ -278,11 +282,6 @@ } boolean fetchRoot = ROOT_NODE_CLIENT.equals(parentId); - - int PARENT_ID = 1; - int SEQNO = 2; - int NODE_ID = 3; - int ENTITY = 4; int cont = 0; ScrollableResults scrollNodes = obq.createQuery().scroll(ScrollMode.FORWARD_ONLY); try { @@ -344,7 +343,7 @@ .createQuery("ADTreeNode", joinClause.toString()); obq.setFilterOnActive(false); obq.setFilterOnReadableOrganization(entity.getMappingClass() != Organization.class); - final List<Object> parameters = new ArrayList<Object>(); + final List<Object> parameters = new ArrayList<>(); parameters.add(nodeId); obq.setParameters(parameters); return obq.count() > 0; @@ -435,7 +434,7 @@ st.setLong(nParam++, seqNoOfFirstModNotInDev); } int nUpdated = st.executeUpdate(); - logger.debug("Recomputing sequence numbers: " + nUpdated + " nodes updated"); + logger.debug("Recomputing sequence numbers: {} nodes updated", nUpdated); } catch (Exception e) { logger.error("Exception while recomputing sequence numbers: ", e); } finally { @@ -515,11 +514,10 @@ } /** - * Returns a Tree given the referencedTableId and a jsonobject that contains the node properties - * This is called from the EventHandler, because the parentRecordId is not avaiable in the - * parameters + * Returns a Tree given the referenced table. This is called from the EventHandler, because the + * parentRecordId is not available in the parameters. */ - private Tree getTree(Table table, JSONObject bobProperties) { + private Tree getTree(Table table) { Tree tree = null; OBCriteria<Tree> adTreeCriteria = OBDal.getInstance().createCriteria(Tree.class); adTreeCriteria.setFilterOnActive(false); @@ -532,7 +530,7 @@ * Creates a new tree (record in ADTree) * */ - private Tree createTree(Table table, JSONObject bobProperties) { + private Tree createTree(Table table) { Client client = OBContext.getOBContext().getCurrentClient(); Organization org = OBContext.getOBContext().getCurrentOrganization(); ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits