IDEMPIERE-4087 Virtual search columns

This commit is contained in:
Diego Ruiz 2019-11-27 19:25:12 +01:00
parent 7487a885bb
commit 570875e74b
11 changed files with 90 additions and 22 deletions

View File

@ -83,7 +83,7 @@ public class GridField
/** /**
* *
*/ */
private static final long serialVersionUID = -5923967271000455417L; private static final long serialVersionUID = 496387784464611123L;
/** /**
* Field Constructor. * Field Constructor.
@ -1323,7 +1323,7 @@ public class GridField
if (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0) if (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0)
{ {
String query; String query;
if (m_vo.ColumnSQL.startsWith("@SQL=")) if (m_vo.ColumnSQL.startsWith("@SQL=") || m_vo.ColumnSQL.startsWith("@SQLFIND="))
query = "NULL"; query = "NULL";
else else
query = m_vo.ColumnSQL; query = m_vo.ColumnSQL;
@ -1334,6 +1334,26 @@ public class GridField
} }
return m_vo.ColumnName; return m_vo.ColumnName;
} // getColumnSQL } // getColumnSQL
/**
* Get Column Name or SQL for search queries
* @return column name
*/
public String getSearchColumnSQL()
{
if (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0)
{
String query;
if (m_vo.ColumnSQL.startsWith("@SQL="))
query = "NULL";
else if (m_vo.ColumnSQL.startsWith("@SQLFIND="))
query = m_vo.ColumnSQL.substring(9);
else
query = m_vo.ColumnSQL;
return query;
}
return m_vo.ColumnName;
} // getSearchColumnSQL
/** /**
* Is Virtual Column * Is Virtual Column
@ -1362,6 +1382,15 @@ public class GridField
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith("@SQL=")); return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith("@SQL="));
} // isVirtualUIColumn } // isVirtualUIColumn
/**
* Is Virtual search Column
* @return column is virtual search
*/
public boolean isVirtualSearchColumn()
{
return (m_vo.ColumnSQL != null && m_vo.ColumnSQL.length() > 0 && m_vo.ColumnSQL.startsWith("@SQLFIND="));
} // isVirtualDBColumn
/** /**
* Get Header * Get Header
* @return header * @return header

View File

@ -202,7 +202,7 @@ public class GridFieldVO implements Serializable
vo.ValidationCode = rs.getString(i); vo.ValidationCode = rs.getString(i);
else if (columnName.equalsIgnoreCase("ColumnSQL")) { else if (columnName.equalsIgnoreCase("ColumnSQL")) {
vo.ColumnSQL = rs.getString(i); vo.ColumnSQL = rs.getString(i);
if (vo.ColumnSQL != null && !vo.ColumnSQL.startsWith("@SQL=") && vo.ColumnSQL.contains("@")) { if (vo.ColumnSQL != null && !vo.ColumnSQL.startsWith("@SQL=") && !vo.ColumnSQL.startsWith("@SQLFIND=") && vo.ColumnSQL.contains("@")) {
// NOTE: cannot use window context because this is set globally on the query, not per record // NOTE: cannot use window context because this is set globally on the query, not per record
vo.ColumnSQL = Env.parseContext(ctx, -1, vo.ColumnSQL, false, true); vo.ColumnSQL = Env.parseContext(ctx, -1, vo.ColumnSQL, false, true);
} }

View File

@ -67,7 +67,7 @@ public class LookupDisplayColumn implements Serializable
IsTranslated = isTranslated; IsTranslated = isTranslated;
DisplayType = ad_Reference_ID; DisplayType = ad_Reference_ID;
AD_Reference_ID = ad_Reference_Value_ID; AD_Reference_ID = ad_Reference_Value_ID;
if (columnSQL != null && columnSQL.length() > 0 && columnSQL.startsWith("@SQL=")) if (columnSQL != null && columnSQL.length() > 0 && (columnSQL.startsWith("@SQL=") || columnSQL.startsWith("@SQLFIND=")))
ColumnSQL = "NULL"; ColumnSQL = "NULL";
else else
ColumnSQL = columnSQL; ColumnSQL = columnSQL;

View File

@ -52,7 +52,7 @@ public class MColumn extends X_AD_Column
/** /**
* *
*/ */
private static final long serialVersionUID = 7215660422231054443L; private static final long serialVersionUID = -6905852892037761285L;
public static MColumn get (Properties ctx, int AD_Column_ID) public static MColumn get (Properties ctx, int AD_Column_ID)
{ {
@ -228,6 +228,16 @@ public class MColumn extends X_AD_Column
String s = getColumnSQL(); String s = getColumnSQL();
return s != null && s.length() > 0 && s.startsWith("@SQL="); return s != null && s.length() > 0 && s.startsWith("@SQL=");
} // isVirtualUIColumn } // isVirtualUIColumn
/**
* Is Virtual Search Column
* @return true if virtual search column
*/
public boolean isVirtualSearchColumn()
{
String s = getColumnSQL();
return s != null && s.length() > 0 && s.startsWith("@SQLFIND=");
} // isVirtualSearchColumn
/** /**
* Is the Column Encrypted? * Is the Column Encrypted?
@ -362,7 +372,7 @@ public class MColumn extends X_AD_Column
setIsMandatory(false); setIsMandatory(false);
if (isUpdateable()) if (isUpdateable())
setIsUpdateable(false); setIsUpdateable(false);
if (isVirtualUIColumn() && isIdentifier()) if ((isVirtualUIColumn() || isVirtualSearchColumn()) && isIdentifier())
setIsIdentifier(false); setIsIdentifier(false);
} }
// Updateable // Updateable
@ -1240,10 +1250,18 @@ public class MColumn extends X_AD_Column
} }
public String getColumnSQL(boolean nullForUI) { public String getColumnSQL(boolean nullForUI) {
return getColumnSQL(nullForUI, true);
}
public String getColumnSQL(boolean nullForUI, boolean nullForSearch) {
String query = getColumnSQL(); String query = getColumnSQL();
if (query != null && query.length() > 0) { if (query != null && query.length() > 0) {
if (query.startsWith("@SQL=") && nullForUI) if (query.startsWith("@SQL=") && nullForUI)
query = "NULL"; query = "NULL";
else if (query.startsWith("@SQLFIND=") && nullForSearch)
query = "NULL";
else if (query.startsWith("@SQLFIND=") && !nullForSearch)
query = query.substring(9);
} }
return query; return query;
} }

View File

@ -149,6 +149,13 @@ public class MField extends X_AD_Field
setAD_Val_Rule_ID(0); setAD_Val_Rule_ID(0);
setIsToolbarButton(null); setIsToolbarButton(null);
} }
if (isDisplayed()) {
MColumn column = (MColumn) getAD_Column();
if (column.isVirtualSearchColumn()) {
setIsDisplayed(false);
setIsDisplayedGrid(false);
}
}
return true; return true;
} // beforeSave } // beforeSave

View File

@ -435,7 +435,7 @@ public class MLookupFactory
ZoomWindowPO = rs.getInt(9); ZoomWindowPO = rs.getInt(9);
//AD_Table_ID = rs.getInt(10); //AD_Table_ID = rs.getInt(10);
displayColumnSQL = rs.getString(11); displayColumnSQL = rs.getString(11);
if (displayColumnSQL != null && displayColumnSQL.length() > 0 && displayColumnSQL.startsWith("@SQL=")) if (displayColumnSQL != null && displayColumnSQL.length() > 0 && (displayColumnSQL.startsWith("@SQL=") || displayColumnSQL.startsWith("@SQLFIND=")))
displayColumnSQL = "NULL"; displayColumnSQL = "NULL";
if (displayColumnSQL != null && displayColumnSQL.contains("@") && displayColumnSQL.startsWith("@SQL=")) if (displayColumnSQL != null && displayColumnSQL.contains("@") && displayColumnSQL.startsWith("@SQL="))
displayColumnSQL = Env.parseContext(Env.getCtx(), -1, displayColumnSQL, false, true); displayColumnSQL = Env.parseContext(Env.getCtx(), -1, displayColumnSQL, false, true);
@ -668,7 +668,7 @@ public class MLookupFactory
embedSQL.append(TableNameAlias).append(".Value||'-'||"); embedSQL.append(TableNameAlias).append(".Value||'-'||");
MColumn columnDisplay = new MColumn(Env.getCtx(), columnDisplay_ID, null); MColumn columnDisplay = new MColumn(Env.getCtx(), columnDisplay_ID, null);
if (columnDisplay.isVirtualUIColumn()) if (columnDisplay.isVirtualUIColumn() || columnDisplay.isVirtualSearchColumn())
{ {
s_log.warning("Virtual UI Column must not be used as display"); s_log.warning("Virtual UI Column must not be used as display");
return null; return null;

View File

@ -1183,7 +1183,7 @@ class Restriction implements Serializable
MTable table = MTable.get(Env.getCtx(), tableName); MTable table = MTable.get(Env.getCtx(), tableName);
if (table != null) { if (table != null) {
for (MColumn col : table.getColumns(false)) { for (MColumn col : table.getColumns(false)) {
String colSQL = col.getColumnSQL(true); String colSQL = col.getColumnSQL(true, false);
if (colSQL != null && colSQL.contains("@")) if (colSQL != null && colSQL.contains("@"))
colSQL = Env.parseContext(Env.getCtx(), -1, colSQL, false, true); colSQL = Env.parseContext(Env.getCtx(), -1, colSQL, false, true);
if (colSQL != null && ColumnName.equals(colSQL.trim())) { if (colSQL != null && ColumnName.equals(colSQL.trim())) {

View File

@ -48,7 +48,7 @@ public class POInfo implements Serializable
/** /**
* *
*/ */
private static final long serialVersionUID = 3496403499343293597L; private static final long serialVersionUID = -6346988499971159874L;
/** Used by Remote FinReport */ /** Used by Remote FinReport */
/** /**
@ -199,7 +199,7 @@ public class POInfo implements Serializable
// //
m_AccessLevel = rs.getString(18); m_AccessLevel = rs.getString(18);
String ColumnSQL = rs.getString(19); String ColumnSQL = rs.getString(19);
if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith("@SQL=")) if (ColumnSQL != null && ColumnSQL.length() > 0 && (ColumnSQL.startsWith("@SQL=") || ColumnSQL.startsWith("@SQLFIND=")))
ColumnSQL = "NULL"; ColumnSQL = "NULL";
if (ColumnSQL != null && ColumnSQL.contains("@")) if (ColumnSQL != null && ColumnSQL.contains("@"))
ColumnSQL = Env.parseContext(Env.getCtx(), -1, ColumnSQL, false, true); ColumnSQL = Env.parseContext(Env.getCtx(), -1, ColumnSQL, false, true);
@ -378,7 +378,7 @@ public class POInfo implements Serializable
if (index < 0 || index >= m_columns.length) if (index < 0 || index >= m_columns.length)
return null; return null;
if (m_columns[index].ColumnSQL != null && m_columns[index].ColumnSQL.length() > 0) { if (m_columns[index].ColumnSQL != null && m_columns[index].ColumnSQL.length() > 0) {
if (m_columns[index].ColumnSQL.startsWith("@SQL=")) if (m_columns[index].ColumnSQL.startsWith("@SQL=") || m_columns[index].ColumnSQL.startsWith("@SQLFIND="))
return "NULL AS " + m_columns[index].ColumnName; return "NULL AS " + m_columns[index].ColumnName;
return m_columns[index].ColumnSQL + " AS " + m_columns[index].ColumnName; return m_columns[index].ColumnSQL + " AS " + m_columns[index].ColumnName;
} }
@ -425,6 +425,20 @@ public class POInfo implements Serializable
&& m_columns[index].ColumnSQL.length() > 0 && m_columns[index].ColumnSQL.length() > 0
&& m_columns[index].ColumnSQL.startsWith("@SQL="); && m_columns[index].ColumnSQL.startsWith("@SQL=");
} // isVirtualUIColumn } // isVirtualUIColumn
/**
* Is Column Virtual Search?
* @param index index
* @return true if column is virtual search
*/
public boolean isVirtualSearchColumn (int index)
{
if (index < 0 || index >= m_columns.length)
return true;
return m_columns[index].ColumnSQL != null
&& m_columns[index].ColumnSQL.length() > 0
&& m_columns[index].ColumnSQL.startsWith("@SQLFIND=");
} // isVirtualSearchColumn
/** /**
* Get Column Label * Get Column Label

View File

@ -310,7 +310,7 @@ public class DataEngine
int AD_Column_ID = rs.getInt(1); int AD_Column_ID = rs.getInt(1);
String ColumnName = rs.getString(2); String ColumnName = rs.getString(2);
String ColumnSQL = rs.getString(24); String ColumnSQL = rs.getString(24);
if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith("@SQL=")) if (ColumnSQL != null && ColumnSQL.length() > 0 && (ColumnSQL.startsWith("@SQL=") || ColumnSQL.startsWith("@SQLFIND=")))
ColumnSQL = "NULL"; ColumnSQL = "NULL";
if (ColumnSQL != null && ColumnSQL.contains("@")) if (ColumnSQL != null && ColumnSQL.contains("@"))
ColumnSQL = Env.parseContext(Env.getCtx(), -1, ColumnSQL, false, true); ColumnSQL = Env.parseContext(Env.getCtx(), -1, ColumnSQL, false, true);

View File

@ -615,7 +615,7 @@ public class MPrintFormat extends X_AD_PrintFormat
int seqNo = 1; int seqNo = 1;
for (GridField gridField : gridFields) for (GridField gridField : gridFields)
{ {
if (gridField.isVirtualUIColumn()) if (gridField.isVirtualUIColumn() || gridField.isVirtualSearchColumn())
continue; continue;
MPrintFormatItem pfi = MPrintFormatItem.createFromGridField(pf, gridField, seqNo++); MPrintFormatItem pfi = MPrintFormatItem.createFromGridField(pf, gridField, seqNo++);
if (pfi != null) if (pfi != null)
@ -878,7 +878,7 @@ public class MPrintFormat extends X_AD_PrintFormat
{ {
int columnID = rs.getInt(1); int columnID = rs.getInt(1);
MColumn column = MColumn.get(ctx, columnID); MColumn column = MColumn.get(ctx, columnID);
if (column.isVirtualUIColumn()) if (column.isVirtualUIColumn() || column.isVirtualSearchColumn())
continue; continue;
MPrintFormatItem pfi = MPrintFormatItem.createFromColumn (format, columnID, seqNo++); MPrintFormatItem pfi = MPrintFormatItem.createFromColumn (format, columnID, seqNo++);
if (pfi != null) if (pfi != null)

View File

@ -768,7 +768,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (mField.isSelectionColumn()) { if (mField.isSelectionColumn()) {
gridFieldList.add(mField); // isSelectionColumn gridFieldList.add(mField); // isSelectionColumn
} else { } else {
if (isDisplayed && mField.getDisplayType() != DisplayType.Button && !mField.getColumnName().equals("AD_Client_ID")) if ((isDisplayed || mField.isVirtualSearchColumn()) && mField.getDisplayType() != DisplayType.Button && !mField.getColumnName().equals("AD_Client_ID"))
moreFieldList.add(mField); moreFieldList.add(mField);
} }
} // for all target tab fields } // for all target tab fields
@ -1633,7 +1633,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (field == null || field.isVirtualUIColumn()) if (field == null || field.isVirtualUIColumn())
continue; continue;
boolean isProductCategoryField = isProductCategoryField(field.getColumnName()); boolean isProductCategoryField = isProductCategoryField(field.getColumnName());
String ColumnSQL = field.getColumnSQL(false); String ColumnSQL = field.getSearchColumnSQL();
// Left brackets // Left brackets
Listbox listLeftBracket = (Listbox)row.getFellow("listLeftBracket"+row.getId()); Listbox listLeftBracket = (Listbox)row.getFellow("listLeftBracket"+row.getId());
String lBrackets = listLeftBracket.getSelectedItem().getValue().toString(); String lBrackets = listLeftBracket.getSelectedItem().getValue().toString();
@ -1866,7 +1866,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
GridField field = getTargetMField(ColumnName); GridField field = getTargetMField(ColumnName);
if (field.isVirtualUIColumn()) if (field.isVirtualUIColumn())
continue; continue;
StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); StringBuilder ColumnSQL = new StringBuilder(field.getSearchColumnSQL());
m_query.addRangeRestriction(ColumnSQL.toString(), value, valueTo, m_query.addRangeRestriction(ColumnSQL.toString(), value, valueTo,
ColumnName, wed.getDisplay(), wedTo.getDisplay(), true, 0); ColumnName, wed.getDisplay(), wedTo.getDisplay(), true, 0);
appendCode(code, ColumnName, MQuery.BETWEEN, value.toString(), valueTo.toString(), "AND", "", ""); appendCode(code, ColumnName, MQuery.BETWEEN, value.toString(), valueTo.toString(), "AND", "", "");
@ -1881,7 +1881,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
GridField field = getTargetMField(ColumnName); GridField field = getTargetMField(ColumnName);
boolean isProductCategoryField = isProductCategoryField(field.getColumnName()); boolean isProductCategoryField = isProductCategoryField(field.getColumnName());
StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); StringBuilder ColumnSQL = new StringBuilder(field.getSearchColumnSQL());
// add encryption here if the field is encrypted. // add encryption here if the field is encrypted.
if (field.isEncrypted()) { if (field.isEncrypted()) {
@ -1947,7 +1947,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
} }
GridField field = getTargetMField(ColumnName); GridField field = getTargetMField(ColumnName);
StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); StringBuilder ColumnSQL = new StringBuilder(field.getSearchColumnSQL());
// //
m_query.addRestriction(ColumnSQL.toString(), MQuery.LESS_EQUAL, valueTo, ColumnName, wed.getDisplay()); m_query.addRestriction(ColumnSQL.toString(), MQuery.LESS_EQUAL, valueTo, ColumnName, wed.getDisplay());
appendCode(code, ColumnName, MQuery.LESS_EQUAL, valueTo.toString(), "", "AND", "", ""); appendCode(code, ColumnName, MQuery.LESS_EQUAL, valueTo.toString(), "", "AND", "", "");
@ -2379,7 +2379,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
private String getSubCategoryWhereClause(GridField field, int productCategoryId) { private String getSubCategoryWhereClause(GridField field, int productCategoryId) {
//if a node with this id is found later in the search we have a loop in the tree //if a node with this id is found later in the search we have a loop in the tree
int subTreeRootParentId = 0; int subTreeRootParentId = 0;
StringBuilder retString = new StringBuilder(field.getColumnSQL(false)).append(" IN ("); StringBuilder retString = new StringBuilder(field.getSearchColumnSQL()).append(" IN (");
String sql = "SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category WHERE AD_Client_ID=? AND IsActive='Y'"; String sql = "SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category WHERE AD_Client_ID=? AND IsActive='Y'";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100); final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -2709,4 +2709,4 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
} // setDtatusDB } // setDtatusDB
/** END DEVCOFFEE **/ /** END DEVCOFFEE **/
} // FindPanel } // FindPanel