details: https://code.openbravo.com/erp/devel/pi/rev/17c442ff5b2b changeset: 28544:17c442ff5b2b user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Tue Jan 26 10:30:45 2016 +0100 summary: fixes issue 31856: allow multiple 'Tree and node image' for same client
The Account Tree window was using the ADTreeDatasourceService which asumes that a table is always represented by the same AD_Tree. In this case, two account trees (c_elementvalue table) can have different base trees to display their information. In order to support this scenario, a new datasource has been created: AccountTreeDatasourceService which allows to select the correct base tree on each case. diffstat: modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java | 8 +- modules/org.openbravo.service.datasource/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml | 14 + modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java | 13 +- modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/AccountTreeDatasourceService.java | 78 ++++++++++ modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java | 3 +- modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java | 6 +- src-db/database/sourcedata/AD_FIELD.xml | 28 +++ src-db/database/sourcedata/AD_TABLE_TREE.xml | 3 +- src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java | 13 +- 9 files changed, 155 insertions(+), 11 deletions(-) diffs (truncated from 340 to 300 lines): diff -r 69d968879453 -r 17c442ff5b2b modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java Mon Jan 25 18:46:51 2016 +0100 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java Tue Jan 26 10:30:45 2016 +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-2014 Openbravo SLU + * All portions are Copyright (C) 2013-2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -37,6 +37,7 @@ import org.openbravo.client.kernel.event.EntityDeleteEvent; import org.openbravo.client.kernel.event.EntityNewEvent; import org.openbravo.client.kernel.event.EntityPersistenceEventObserver; +import org.openbravo.dal.core.DalUtil; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBCriteria; import org.openbravo.dal.service.OBDal; @@ -62,6 +63,7 @@ private static final String TREENODE_STRUCTURE = "ADTree"; private static final String LINKTOPARENT_STRUCTURE = "LinkToParent"; + private static final String CUSTOM_STRUCTURE = "Custom"; // private static final String CUSTOM_STRUCTURE = "Custom"; private static Logger logger = LoggerFactory.getLogger(TreeTablesEventHandler.class); @@ -128,6 +130,10 @@ dataSource = dataSourceServiceProvider.getDataSource(TREENODE_DATASOURCE); } else if (LINKTOPARENT_STRUCTURE.equals(mainTableTree.getTreeStructure())) { dataSource = dataSourceServiceProvider.getDataSource(LINKTOPARENT_DATASOURCE); + } else if (CUSTOM_STRUCTURE.equals(mainTableTree.getTreeStructure()) + && mainTableTree.getDatasource() != null) { + String customDataSourceId = (String) DalUtil.getId(mainTableTree.getDatasource()); + dataSource = dataSourceServiceProvider.getDataSource(customDataSourceId); } return dataSource; } diff -r 69d968879453 -r 17c442ff5b2b modules/org.openbravo.service.datasource/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml --- a/modules/org.openbravo.service.datasource/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml Mon Jan 25 18:46:51 2016 +0100 +++ b/modules/org.openbravo.service.datasource/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml Tue Jan 26 10:30:45 2016 +0100 @@ -14,4 +14,18 @@ <!--15E4FE4F91BF4776AA326FA798CC9F53--> <IDFKFILTERING><![CDATA[Y]]></IDFKFILTERING> <!--15E4FE4F91BF4776AA326FA798CC9F53--></OBSERDS_DATASOURCE> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--><OBSERDS_DATASOURCE> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <OBSERDS_DATASOURCE_ID><![CDATA[D2F94DC86DEC48D69E4BFCE59DC670CF]]></OBSERDS_DATASOURCE_ID> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <AD_MODULE_ID><![CDATA[A44B9BA75C354D8FB2E3F7D6EB6BFDC4]]></AD_MODULE_ID> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <NAME><![CDATA[Tree Datasource for Account Tree]]></NAME> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <DESCRIPTION><![CDATA[Tree Datasource for Account Tree]]></DESCRIPTION> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <CLASSNAME><![CDATA[org.openbravo.service.datasource.AccountTreeDatasourceService]]></CLASSNAME> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <OBCLKER_TEMPLATE_ID><![CDATA[2BAD445C2A0343C58E455F9BD379C690]]></OBCLKER_TEMPLATE_ID> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <USEASTABLEDATAORIGIN><![CDATA[N]]></USEASTABLEDATAORIGIN> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--> <IDFKFILTERING><![CDATA[Y]]></IDFKFILTERING> +<!--D2F94DC86DEC48D69E4BFCE59DC670CF--></OBSERDS_DATASOURCE> + </data> diff -r 69d968879453 -r 17c442ff5b2b 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 Jan 25 18:46:51 2016 +0100 +++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java Tue Jan 26 10:30:45 2016 +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-2015 Openbravo SLU + * All portions are Copyright (C) 2013-2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -144,7 +144,7 @@ * table whose ADTree TableTree will be returned * @return the ADTree TableTree associated with the given table */ - private TableTree getTableTree(Table table) { + protected TableTree getTableTree(Table table) { TableTree tableTree = null; OBCriteria<TableTree> criteria = OBDal.getInstance().createCriteria(TableTree.class); criteria.add(Restrictions.eq(TableTree.PROPERTY_TABLE, table)); @@ -172,7 +172,9 @@ } /** - * + * @param parameters + * @param datasourceParameters + * specific datasource parameters * @param parentId * id of the node whose children are to be retrieved * @param hqlWhereClause @@ -503,7 +505,7 @@ } /** - * Returns a Tree given the referencedTableId and the parentRecordId + * Returns a Tree given the referencedTableId */ private Tree getTree(String referencedTableId) { Table referencedTable = OBDal.getInstance().get(Table.class, referencedTableId); @@ -589,7 +591,8 @@ } } - Tree tree = this.getTree(tableId); + Map<String, Object> datasourceParameters = this.getDatasourceSpecificParams(parameters); + Tree tree = (Tree) datasourceParameters.get("tree"); boolean isOrdered = this.isOrdered(tree); Long seqNo = null; if (isOrdered) { diff -r 69d968879453 -r 17c442ff5b2b modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/AccountTreeDatasourceService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/AccountTreeDatasourceService.java Tue Jan 26 10:30:45 2016 +0100 @@ -0,0 +1,78 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2016 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.service.datasource; + +import java.util.HashMap; +import java.util.Map; + +import org.hibernate.criterion.Restrictions; +import org.openbravo.dal.service.OBCriteria; +import org.openbravo.dal.service.OBDal; +import org.openbravo.model.ad.datamodel.Table; +import org.openbravo.model.ad.utility.TableTree; +import org.openbravo.model.ad.utility.Tree; +import org.openbravo.model.financialmgmt.accounting.coa.Element; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Tree Datasource for Account Tree + * + */ +public class AccountTreeDatasourceService extends ADTreeDatasourceService { + private static final Logger logger = LoggerFactory.getLogger(AccountTreeDatasourceService.class); + private static final String DATASOURCE_ID = "D2F94DC86DEC48D69E4BFCE59DC670CF"; + private static final String C_ELEMENTVALUE_TABLE_ID = "188"; + private static final String FINANCIALMGMTELEMENT_ID = "@FinancialMgmtElement.id@"; + private static final String CUSTOM_STRUCTURE = "Custom"; + + @Override + protected Map<String, Object> getDatasourceSpecificParams(Map<String, String> parameters) { + Map<String, Object> datasourceParams = new HashMap<String, Object>(); + String accountTreeId = parameters.get(FINANCIALMGMTELEMENT_ID); + if (accountTreeId == null) { + return datasourceParams; + } + Element element = OBDal.getInstance().get(Element.class, accountTreeId); + Tree tree = element.getTree(); + if (tree.getTable() == null) { + // In case the table is not defined, the C_ElementValue table is assigned to the account tree + // This prevents a NullPointerException when fetching the account tree nodes + Table cElementValueTable = OBDal.getInstance().get(Table.class, C_ELEMENTVALUE_TABLE_ID); + tree.setTable(cElementValueTable); + } + datasourceParams.put("tree", tree); + logger.debug("Retrieved tree for Account Element with id = {}", accountTreeId); + return datasourceParams; + } + + @Override + protected TableTree getTableTree(Table table) { + TableTree tableTree = null; + DataSource accountTreeDatasource = OBDal.getInstance().get(DataSource.class, DATASOURCE_ID); + OBCriteria<TableTree> criteria = OBDal.getInstance().createCriteria(TableTree.class); + criteria.add(Restrictions.eq(TableTree.PROPERTY_TABLE, table)); + criteria.add(Restrictions.eq(TableTree.PROPERTY_TREESTRUCTURE, CUSTOM_STRUCTURE)); + criteria.add(Restrictions.eq(TableTree.PROPERTY_DATASOURCE, accountTreeDatasource)); + criteria.setMaxResults(1); + tableTree = (TableTree) criteria.uniqueResult(); + return tableTree; + } +} \ No newline at end of file diff -r 69d968879453 -r 17c442ff5b2b modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java --- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java Mon Jan 25 18:46:51 2016 +0100 +++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java Tue Jan 26 10:30:45 2016 +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-2015 Openbravo SLU + * All portions are Copyright (C) 2013-2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -439,6 +439,7 @@ /** * Updates the parent of a given node a returns its definition in a JSONObject */ + @Override protected JSONObject moveNode(Map<String, String> parameters, String nodeId, String newParentId, String prevNodeId, String nextNodeId) throws Exception { diff -r 69d968879453 -r 17c442ff5b2b modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java --- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java Mon Jan 25 18:46:51 2016 +0100 +++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java Tue Jan 26 10:30:45 2016 +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-2015 Openbravo SLU + * All portions are Copyright (C) 2013-2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -760,6 +760,7 @@ /** * @param parameters + * @param datasourceParameters * @param nodeId * @return returns a json object with the definition of a node give its record id */ @@ -768,6 +769,7 @@ /** * @param parameters + * @param datasourceParameters * @param nodeId * @return returns a json object with the definition of a node give its node id */ @@ -777,6 +779,8 @@ /** * * @param parameters + * @param datasourceParameters + * specific datasource parameters * @param parentId * id of the node whose children are to be retrieved * @param hqlWhereClause diff -r 69d968879453 -r 17c442ff5b2b src-db/database/sourcedata/AD_FIELD.xml --- a/src-db/database/sourcedata/AD_FIELD.xml Mon Jan 25 18:46:51 2016 +0100 +++ b/src-db/database/sourcedata/AD_FIELD.xml Tue Jan 26 10:30:45 2016 +0100 @@ -259621,6 +259621,34 @@ <!--9C834BED1A174B57AEE41A6160110B7D--> <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY> <!--9C834BED1A174B57AEE41A6160110B7D--></AD_FIELD> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--><AD_FIELD> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <AD_FIELD_ID><![CDATA[9C9343FFB9CF4050AB1EBB65CE87BBA6]]></AD_FIELD_ID> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <NAME><![CDATA[Table]]></NAME> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <DESCRIPTION><![CDATA[A dictionary table used for this tab that points to the database table.]]></DESCRIPTION> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <HELP><![CDATA[The Table indicates the table in which a field or fields reside.]]></HELP> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <AD_TAB_ID><![CDATA[243]]></AD_TAB_ID> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <AD_COLUMN_ID><![CDATA[2D852A64DD7D4758AAA80AFB90FB5A84]]></AD_COLUMN_ID> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISREADONLY><![CDATA[N]]></ISREADONLY> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <SEQNO><![CDATA[80]]></SEQNO> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISSAMELINE><![CDATA[N]]></ISSAMELINE> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--> <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY> +<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--></AD_FIELD> + <!--9CA351D4BB3443C2A6E1B6F782DDAA63--><AD_FIELD> <!--9CA351D4BB3443C2A6E1B6F782DDAA63--> <AD_FIELD_ID><![CDATA[9CA351D4BB3443C2A6E1B6F782DDAA63]]></AD_FIELD_ID> <!--9CA351D4BB3443C2A6E1B6F782DDAA63--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r 69d968879453 -r 17c442ff5b2b src-db/database/sourcedata/AD_TABLE_TREE.xml --- a/src-db/database/sourcedata/AD_TABLE_TREE.xml Mon Jan 25 18:46:51 2016 +0100 +++ b/src-db/database/sourcedata/AD_TABLE_TREE.xml Tue Jan 26 10:30:45 2016 +0100 @@ -128,7 +128,8 @@ <!--8E70E92119184AB69AE031A72BF6BF9E--> <NAME><![CDATA[Element Value]]></NAME> <!--8E70E92119184AB69AE031A72BF6BF9E--> <ISPARENTSELECTIONALLOWED><![CDATA[Y]]></ISPARENTSELECTIONALLOWED> <!--8E70E92119184AB69AE031A72BF6BF9E--> <ISORDERED><![CDATA[Y]]></ISORDERED> -<!--8E70E92119184AB69AE031A72BF6BF9E--> <TREESTRUCTURE><![CDATA[ADTree]]></TREESTRUCTURE> +<!--8E70E92119184AB69AE031A72BF6BF9E--> <TREESTRUCTURE><![CDATA[Custom]]></TREESTRUCTURE> +<!--8E70E92119184AB69AE031A72BF6BF9E--> <OBSERDS_DATASOURCE_ID><![CDATA[D2F94DC86DEC48D69E4BFCE59DC670CF]]></OBSERDS_DATASOURCE_ID> ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits