Related to issue 40700: code review improvements
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Fri, 03 May 2019 09:54:13 +0200
changeset 35626 240b635f238d
parent 35625 4f276eb2112c
child 35627 2a604c499abc
Related to issue 40700: code review improvements
Centralize localStrLine definition in just one line, when it's used.
Change parameter names to make more difficult to have conflicts with user defined params.
Remove 'if' for corner case. This creates a very small change in this scenario:
select 'RecordId: ' || @RecordId@ || ', Line: ' || @Line@ from dual
When Line is null then:
Before: NULL
After: RecordId: 3232199ED4824EE3A07BCC1E580ABFE7, Line: NULL
src/org/openbravo/erpCommon/ad_forms/FactLine.java
--- a/src/org/openbravo/erpCommon/ad_forms/FactLine.java	Thu May 02 12:00:38 2019 -0400
+++ b/src/org/openbravo/erpCommon/ad_forms/FactLine.java	Fri May 03 09:54:13 2019 +0200
@@ -1124,29 +1124,24 @@
   public StringBuffer getDescription(ConnectionProvider connectionProvider, String strC_Bpartner_ID,
       String strC_AcctSchema_ID, String strAD_Table_ID, String strRecord_ID, String strLine)
       throws ServletException {
-    String localStrLine = strLine;
     StringBuffer description = new StringBuffer();
     String strSql = AcctServerData.selectDescription(connectionProvider, strAD_Table_ID,
         strC_AcctSchema_ID);
     try {
       if (!StringUtils.isBlank(strSql)) {
-        strSql = strSql.replaceAll("@RecordId@", ":recordId").replaceAll("@Line@", ":lineId");
+        strSql = strSql.replaceAll("@RecordId@", ":paramRecordId")
+            .replaceAll("@Line@", ":paramLineId");
 
         @SuppressWarnings("rawtypes")
         NativeQuery query = OBDal.getInstance().getSession().createSQLQuery(strSql);
-        if (strSql.contains(":recordId")) {
-          query.setParameter("recordId", strRecord_ID);
+        if (strSql.contains(":paramRecordId")) {
+          query.setParameter("paramRecordId", strRecord_ID);
         }
-        String lineValue = StringUtils.isBlank(localStrLine) ? "NULL" : localStrLine;
-        if (strSql.contains(":lineId")) {
-          query.setParameter("lineId", lineValue);
+        if (strSql.contains(":paramLineId")) {
+          query.setParameter("paramLineId", StringUtils.isBlank(strLine) ? "NULL" : strLine);
         }
         final String result = (String) query.uniqueResult();
-        if (lineValue.equalsIgnoreCase("NULL") && result != null && strSql.contains(":lineId")) {
-          description.append(lineValue);
-        } else {
-          description.append(StringUtils.defaultIfBlank(result, StringUtils.EMPTY));
-        }
+        description.append(StringUtils.defaultIfBlank(result, StringUtils.EMPTY));
       }
       if (description.length() == 0) {
         description.append((m_docVO.DocumentNo == null) ? "" : m_docVO.DocumentNo);