details: https://code.openbravo.com/erp/devel/pi/rev/ed6df2f35307 changeset: 21977:ed6df2f35307 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Feb 07 12:46:29 2014 +0100 summary: related to bug 25684: solves case a don't compute unneeded combos on CHANGE mode when visibleProperties is null
details: https://code.openbravo.com/erp/devel/pi/rev/6198177e1c61 changeset: 21978:6198177e1c61 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Feb 07 13:00:18 2014 +0100 summary: related to issue 25684: solves case b do not compute inactive combos if they are not required details: https://code.openbravo.com/erp/devel/pi/rev/82bb222117bc changeset: 21979:82bb222117bc user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Feb 07 13:01:43 2014 +0100 summary: related to issue 25684: solves case 3 don't generate complete JSON for combos when only one value is required details: https://code.openbravo.com/erp/devel/pi/rev/001ce480684b changeset: 21980:001ce480684b user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Tue Feb 11 10:55:13 2014 +0100 summary: related to issue 25684: solves case 3 diffstat: modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java | 60 +++++- modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java | 11 + modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java | 12 + src/org/openbravo/erpCommon/utility/ComboTableData.java | 85 +++++++++- 4 files changed, 151 insertions(+), 17 deletions(-) diffs (truncated from 322 to 300 lines): diff -r 4988331796f2 -r 001ce480684b modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java Wed Feb 12 16:37:31 2014 +0100 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java Tue Feb 11 10:55:13 2014 +0100 @@ -545,6 +545,18 @@ } + private boolean isNotActiveOrVisible(Field field, List<String> visibleProperties) { + return ((visibleProperties == null || !visibleProperties.contains("inp" + + Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName()))) + && !field.isDisplayed() && !field.isShowInGridView() && !field.isShownInStatusBar()) + || !field.isActive(); + } + + private boolean isNotActiveOrVisibleAndNotNeeded(Field field, List<String> visibleProperties) { + return isNotActiveOrVisible(field, visibleProperties) + && field.getColumn().getDefaultValue() == null && !field.getColumn().isMandatory(); + } + private void computeColumnValues(String mode, Tab tab, List<String> allColumns, Map<String, JSONObject> columnValues, BaseOBObject parentRecord, String parentId, String changedColumn, JSONObject jsContent, List<String> changeEventCols, @@ -554,6 +566,7 @@ if (mode.equals("CHANGE") && changedColumn != null) { RequestContext.get().setRequestParameter("donotaddcurrentelement", "true"); } + log.debug("computeColumnValues - forceComboReload: " + forceComboReload); HashMap<String, Field> columnsOfFields = new HashMap<String, Field>(); for (Field field : getADFieldList(tab.getId())) { if (field.getColumn() == null) { @@ -595,17 +608,20 @@ value = uiDef.getFieldProperties(field, true); } else { // Else, the default is used - if (visibleProperties != null - && !visibleProperties.contains("inp" + Sqlc.TransformaNombreColumna(col)) - && !field.isDisplayed() && !field.isShowInGridView() && !field.isShownInStatusBar() - && field.getColumn().getDefaultValue() == null && !field.getColumn().isMandatory()) { + if (isNotActiveOrVisibleAndNotNeeded(field, visibleProperties)) { // If the column is not currently visible, and its not mandatory, we don't need to // compute the combo. // If a column is mandatory then the combo needs to be computed, because the selected // value can depend on the computation if there is no default value + log.debug("Not calculating combo in " + mode + " mode for column " + col); value = uiDef.getFieldPropertiesWithoutCombo(field, false); } else { - value = uiDef.getFieldProperties(field, false); + if (isNotActiveOrVisible(field, visibleProperties)) { + log.debug("Only first combo record in " + mode + " mode for column " + col); + value = uiDef.getFieldPropertiesFirstRecord(field, false); + } else { + value = uiDef.getFieldProperties(field, false); + } } } } else if (mode.equals("EDIT") @@ -614,17 +630,41 @@ // On EDIT mode, the values are computed through the UIDefinition (the values have been // previously set in the RequestContext) // This is also done this way on CHANGE mode where a combo reload is needed - if (visibleProperties != null - && !visibleProperties.contains("inp" + Sqlc.TransformaNombreColumna(col)) - && !field.isDisplayed() && !field.isShowInGridView() && !field.isShownInStatusBar() - && field.getColumn().getDefaultValue() == null && !field.getColumn().isMandatory()) { + if (isNotActiveOrVisibleAndNotNeeded(field, visibleProperties)) { // If the column is not currently visible, and its not mandatory, we don't need to // compute the combo. // If a column is mandatory then the combo needs to be computed, because the selected // value can depend on the computation if there is no default value + log.debug("field: " + + field + + " - getFieldPropertiesWithoutCombo: hasVisibleProperties: " + + (visibleProperties != null) + + ", &contains: " + + (visibleProperties != null && visibleProperties.contains("inp" + + Sqlc.TransformaNombreColumna(col))) + ", isDisplayed=" + field.isDisplayed() + + ", isShowInGridView=" + field.isShowInGridView() + ", isShownInStatusBar=" + + field.isShowInGridView() + ", hasDefaultValue=" + + (field.getColumn().getDefaultValue() != null) + ", isMandatory=" + + field.getColumn().isMandatory()); uiDef.getFieldPropertiesWithoutCombo(field, true); } else { - value = uiDef.getFieldProperties(field, true); + log.debug("field: " + + field + + " - getFieldProperties: hasVisibleProperties: " + + (visibleProperties != null) + + ", &contains: " + + (visibleProperties != null && visibleProperties.contains("inp" + + Sqlc.TransformaNombreColumna(col))) + ", isDisplayed=" + field.isDisplayed() + + ", isShowInGridView=" + field.isShowInGridView() + ", isShownInStatusBar=" + + field.isShowInGridView() + ", hasDefaultValue=" + + (field.getColumn().getDefaultValue() != null) + ", isMandatory=" + + field.getColumn().isMandatory()); + if (isNotActiveOrVisible(field, visibleProperties)) { + log.debug("Only first combo record in " + mode + " mode for column " + col); + value = uiDef.getFieldPropertiesFirstRecord(field, true); + } else { + value = uiDef.getFieldProperties(field, true); + } } } else if (mode.equals("CHANGE") || mode.equals("SETSESSION")) { // On CHANGE and SETSESSION mode, the values are read from the request diff -r 4988331796f2 -r 001ce480684b modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java --- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java Wed Feb 12 16:37:31 2014 +0100 +++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java Tue Feb 11 10:55:13 2014 +0100 @@ -104,6 +104,17 @@ } } + public String getFieldPropertiesFirstRecord(Field field, boolean getValueFromSession) { + JSONObject value; + try { + value = new JSONObject(super.getFieldProperties(field, getValueFromSession)); + return getValueInComboReference(field, getValueFromSession, value.getString("classicValue"), + true); + } catch (JSONException e) { + throw new OBException("Error while computing combo data", e); + } + } + @Override public String getFieldPropertiesWithoutCombo(Field field, boolean getValueFromSession) { return super.getFieldProperties(field, getValueFromSession); diff -r 4988331796f2 -r 001ce480684b modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java --- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java Wed Feb 12 16:37:31 2014 +0100 +++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java Tue Feb 11 10:55:13 2014 +0100 @@ -256,6 +256,10 @@ return getFieldProperties(field, getValueFromSession); } + public String getFieldPropertiesFirstRecord(Field field, boolean getValueFromSession) { + return getFieldProperties(field, getValueFromSession); + } + /** * Returns alignment in grid view. In case it returns null, default alignment for actual data type * is used. @@ -500,6 +504,11 @@ protected String getValueInComboReference(Field field, boolean getValueFromSession, String columnValue) { + return getValueInComboReference(field, getValueFromSession, columnValue, false); + } + + protected String getValueInComboReference(Field field, boolean getValueFromSession, + String columnValue, boolean onlyFirstRecord) { try { RequestContext rq = RequestContext.get(); VariablesSecureApp vars = rq.getVariablesSecureApp(); @@ -537,6 +546,9 @@ Map<String, String> parameters = comboTableData.fillSQLParametersIntoMap( new DalConnectionProvider(false), vars, tabData, field.getTab().getWindow().getId(), (getValueFromSession && !comboreload) ? columnValue : ""); + if (onlyFirstRecord) { + parameters.put("@ONLY_ONE_RECORD@", columnValue); + } FieldProvider[] fps = comboTableData.select(new DalConnectionProvider(false), parameters, getValueFromSession && !comboreload); ArrayList<FieldProvider> values = new ArrayList<FieldProvider>(); diff -r 4988331796f2 -r 001ce480684b src/org/openbravo/erpCommon/utility/ComboTableData.java --- a/src/org/openbravo/erpCommon/utility/ComboTableData.java Wed Feb 12 16:37:31 2014 +0100 +++ b/src/org/openbravo/erpCommon/utility/ComboTableData.java Tue Feb 11 10:55:13 2014 +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) 2001-2013 Openbravo SLU + * All portions are Copyright (C) 2001-2014 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -824,6 +824,10 @@ canBeCached = uiref.canBeCached(); } + private String getQuery(boolean onlyId, String[] discard) { + return getQuery(onlyId, discard, null); + } + /** * Returns the generated query. * @@ -833,7 +837,7 @@ * Array of field groups to remove from the query. * @return String with the query. */ - private String getQuery(boolean onlyId, String[] discard) { + private String getQuery(boolean onlyId, String[] discard, String recordId) { StringBuffer text = new StringBuffer(); Vector<QueryFieldStructure> aux = getSelectFields(); String idName = ""; @@ -906,8 +910,12 @@ txtAux.append(auxStructure.toString()).append(" \n"); } } - if (hasWhere) + if (hasWhere) { + if (recordId != null) { + txtAux.append(" AND " + idName + "=(?) "); + } text.append("WHERE ").append(txtAux.toString()); + } } if (!onlyId) { @@ -954,6 +962,11 @@ return false; } + private int setSQLParameters(PreparedStatement st, Map<String, String> lparameters, + int iParameter, String[] discard) { + return setSQLParameters(st, lparameters, iParameter, discard, null); + } + /** * Fills the query parameter's values. * @@ -966,7 +979,7 @@ * @return Integer with the next parameter's index. */ private int setSQLParameters(PreparedStatement st, Map<String, String> lparameters, - int iParameter, String[] discard) { + int iParameter, String[] discard, String recordId) { Vector<QueryParameterStructure> vAux = getSelectParameters(); if (vAux != null) { for (int i = 0; i < vAux.size(); i++) { @@ -1006,6 +1019,9 @@ } } } + if (recordId != null) { + UtilSql.setValue(st, ++iParameter, 12, null, recordId); + } vAux = getOrderByParameters(); if (vAux != null) { for (int i = 0; i < vAux.size(); i++) { @@ -1037,6 +1053,57 @@ public FieldProvider[] select(ConnectionProvider conn, Map<String, String> lparameters, boolean includeActual) throws Exception { + String actual = lparameters != null ? lparameters.get("@ACTUAL_VALUE@") + : getParameter("@ACTUAL_VALUE@"); + if (lparameters != null && lparameters.containsKey("@ONLY_ONE_RECORD@") + && !lparameters.get("@ONLY_ONE_RECORD@").isEmpty()) { + String strSqlSingleRecord = getQuery(false, null, lparameters.get("@ONLY_ONE_RECORD@")); + PreparedStatement stSingleRecord = conn.getPreparedStatement(strSqlSingleRecord); + try { + ResultSet result; + int iParameter = 0; + iParameter = setSQLParameters(stSingleRecord, lparameters, iParameter, null, + lparameters.get("@ONLY_ONE_RECORD@")); + result = stSingleRecord.executeQuery(); + if (result.next()) { + SQLReturnObject sqlReturnObject = new SQLReturnObject(); + sqlReturnObject.setData("ID", UtilSql.getValue(result, "ID")); + sqlReturnObject.setData("NAME", UtilSql.getValue(result, "NAME")); + sqlReturnObject.setData("DESCRIPTION", UtilSql.getValue(result, "DESCRIPTION")); + Vector<Object> vector = new Vector<Object>(0); + vector.add(sqlReturnObject); + FieldProvider objectListData[] = new FieldProvider[vector.size()]; + vector.copyInto(objectListData); + return (objectListData); + } + + if (includeActual && actual != null && !actual.equals("")) { + String[] discard = { "filter", "orderBy", "CLIENT_LIST", "ORG_LIST" }; + String strSqlDisc = getQuery(true, discard); + PreparedStatement stInactive = conn.getPreparedStatement(strSqlDisc); + iParameter = setSQLParameters(stInactive, lparameters, 0, discard); + UtilSql.setValue(stInactive, ++iParameter, 12, null, actual); + ResultSet resultIn = stInactive.executeQuery(); + while (resultIn.next()) { + SQLReturnObject sqlReturnObject = new SQLReturnObject(); + sqlReturnObject.setData("ID", UtilSql.getValue(resultIn, "ID")); + String strName = UtilSql.getValue(resultIn, "NAME"); + if (!strName.startsWith(INACTIVE_DATA)) + strName = INACTIVE_DATA + strName; + sqlReturnObject.setData("NAME", strName); + Vector<Object> vector = new Vector<Object>(0); + vector.add(sqlReturnObject); + FieldProvider objectListData[] = new FieldProvider[vector.size()]; + vector.copyInto(objectListData); + return (objectListData); + } + + } + } finally { + conn.releasePreparedStatement(stSingleRecord); + } + + } String strSql = getQuery(false, null); if (log4j.isDebugEnabled()) log4j.debug("SQL: " + strSql); @@ -1048,8 +1115,6 @@ int iParameter = 0; iParameter = setSQLParameters(st, lparameters, iParameter, null); boolean idFound = false; - String actual = lparameters != null ? lparameters.get("@ACTUAL_VALUE@") ------------------------------------------------------------------------------ Android apps run on BlackBerry 10 Introducing the new BlackBerry 10.2.1 Runtime for Android apps. Now with support for Jelly Bean, Bluetooth, Mapview and more. Get your Android app in front of a whole new audience. Start now. http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits