use of org.adempiere.model.MBrowseField in project adempiere by adempiere.
the class Browser method getOrderByPosition.
/**
* Get Order By Postirion for SB
* @param BrowserField
* @return
*/
private int getOrderByPosition(MBrowseField BrowserField) {
// columns start with 1
int colOffset = 1;
int col = 0;
for (MBrowseField field : browserFields) {
int sortBySqlNo = col + colOffset;
// colOffset++;
if (BrowserField.getAD_Browse_Field_ID() == field.getAD_Browse_Field_ID())
return sortBySqlNo;
col++;
}
return -1;
}
use of org.adempiere.model.MBrowseField in project adempiere by adempiere.
the class Browser method getInfoColumnForAxisField.
/**
* Get Info_Column for Axis Field
* @param field defined as Axis
* @return Info_Column with Axis Field
*/
public List<MBrowseField> getInfoColumnForAxisField(MBrowseField field) {
List<MBrowseField> list = new ArrayList<MBrowseField>();
axisParameters = new ArrayList<>();
axisParametersValues = new ArrayList<>();
try {
I_AD_View_Column xcol, pcol, ycol;
xcol = field.getAD_View_Column();
pcol = field.getAxis_Parent_Column();
ycol = field.getAxis_Column();
String columnName = xcol.getAD_Column().getColumnName();
MBrowseField fieldKey = ((MBrowse) field.getAD_Browse()).getFieldKey();
if (fieldKey == null)
throw new AdempiereException("@NotFound@ @IsKey@");
MTable xTable = (MTable) ycol.getAD_View_Definition().getAD_Table();
String xTableName = xTable.getTableName();
String keyColumn = MQuery.getZoomColumnName(columnName);
String tableName = MQuery.getZoomTableName(columnName);
String whereClause = "";
if (pcol != null && pcol.getAD_View_Column_ID() > 0) {
MTable parentTable = MTable.get(field.getCtx(), tableName);
MColumn parentColumn = getParentColumn(parentTable.getAD_Table_ID());
if (parentColumn == null)
throw new AdempiereException("@NotFound@ @IsParent@");
// BR [ 242 ]
if (field.getAD_Val_Rule_ID() > 0)
whereClause = Env.parseContext(Env.getCtx(), getWindowNo(), field.getAD_Val_Rule().getCode(), false);
}
MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, xcol.getAD_Column_ID(), field.getAD_Reference_ID(), m_language, keyColumn, field.getAD_Reference_Value_ID(), false, whereClause);
int cols = 0;
StringBuilder axisSql = new StringBuilder("(SELECT ");
axisSql.append("SUM(").append(ycol.getAD_Column().getColumnName()).append(") FROM ").append(ycol.getAD_View_Definition().getAD_Table().getTableName()).append(" WHERE ").append(xTableName).append(".").append(fieldKey.getAD_View_Column().getAD_Column().getColumnName()).append("=").append(fieldKey.getAD_View_Column().getColumnSQL());
for (int id : getAxisRecordIds(tableName, whereClause)) {
cols++;
String display = lookup.getDisplay(id).trim();
display = display.length() > 12 ? display.substring(1, 12) + "_" + cols : display;
String joinColumn = Msg.translate(m_language, ycol.getAD_Column().getColumnName());
joinColumn = joinColumn.length() > 15 ? joinColumn.substring(1, 15) : joinColumn;
String sqlColName = display + "/" + joinColumn;
String colName = lookup.getDisplay(id).trim() + "/" + Msg.translate(m_language, ycol.getAD_Column().getColumnName());
StringBuilder axisWhere = new StringBuilder(" ");
axisWhere.append(getAxisSQLWhere(ycol)).append(" AND ").append(xcol.getAD_View_Definition().getTableAlias()).append(".").append(xcol.getAD_Column().getColumnName());
StringBuffer select = new StringBuffer();
select.append(axisSql).append(axisWhere);
select.append("=").append(id).append(")");
MViewColumn viewColumn = new MViewColumn(field.getCtx(), 0, field.get_TrxName());
MViewColumn.copyValues((MViewColumn) ycol, viewColumn);
viewColumn.setAD_View_Column_ID(ycol.getAD_View_Column_ID());
viewColumn.setAD_Column_ID(ycol.getAD_Column_ID());
viewColumn.setColumnSQL(select.toString());
viewColumn.setColumnName("\"" + sqlColName + "\"");
MBrowseField browseField = new MBrowseField((MBrowse) field.getAD_Browse(), viewColumn);
browseField.setAD_Browse_ID(field.getAD_Browse_ID());
browseField.setAD_Element_ID(field.getAD_Element_ID());
browseField.setName(colName);
browseField.setDescription(viewColumn.getDescription());
browseField.setHelp(viewColumn.getHelp());
if (viewColumn.get_ID() > 0)
browseField.setAD_View_Column_ID(viewColumn.getAD_View_Column_ID());
browseField.setIsActive(true);
browseField.setIsIdentifier(viewColumn.isIdentifier());
browseField.setIsRange(false);
browseField.setIsQueryCriteria(false);
browseField.setAD_Reference_ID(ycol.getAD_Column().getAD_Reference_ID());
browseField.setAD_Reference_Value_ID(ycol.getAD_Column().getAD_Reference_Value_ID());
browseField.setIsKey(false);
browseField.setIsDisplayed(true);
browseField.setAxis_Column_ID(field.getAxis_Column_ID());
browseField.setAxis_Parent_Column_ID(field.getAxis_Parent_Column_ID());
browseField.setIsReadOnly(field.isReadOnly());
browseField.setAD_Element_ID(field.getAD_Element_ID());
list.add(browseField);
log.finest("Added Column=" + sqlColName + " SQL = " + select);
}
} catch (Exception e) {
throw new AdempiereException(e);
}
return list;
}
use of org.adempiere.model.MBrowseField in project adempiere by adempiere.
the class BrowseFieldElementHandler method create.
public void create(Properties ctx, TransformerHandler document) throws SAXException {
int AD_Browse_Field_ID = Env.getContextAsInt(ctx, X_AD_Browse_Field.COLUMNNAME_AD_Browse_Field_ID);
MBrowseField m_BrowseField = new MBrowseField(ctx, AD_Browse_Field_ID, null);
AttributesImpl atts = new AttributesImpl();
createBrowseFieldBinding(atts, m_BrowseField);
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
if (m_BrowseField.getAD_Reference_ID() > 0) {
packOut.createReference(m_BrowseField.getAD_Reference_ID(), document);
}
if (m_BrowseField.getAD_Reference_Value_ID() > 0) {
packOut.createReference(m_BrowseField.getAD_Reference_Value_ID(), document);
}
if (m_BrowseField.getAD_Val_Rule_ID() > 0) {
packOut.createDynamicRuleValidation(m_BrowseField.getAD_Val_Rule_ID(), document);
}
document.startElement("", "", "browsefield", atts);
document.endElement("", "", "browsefield");
}
use of org.adempiere.model.MBrowseField in project adempiere by adempiere.
the class DynamicDashBoard method prepareSelectQuery.
/**
*
* @return String<br>
*
* This method builds the sql query to generate Result set. It creates Columns and labels as well.
*
*
*/
public String prepareSelectQuery() {
// Getting isDisplayed fields based on the Browse ID
StringBuffer whereClause = new StringBuffer(X_AD_Browse.COLUMNNAME_AD_Browse_ID + " = " + browseId + " AND isDisplayed = 'Y'");
List<MBrowseField> fieldList = new Query(Env.getCtx(), I_AD_Browse_Field.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).setOrderBy(X_AD_Browse_Field.COLUMNNAME_SeqNo).list();
if (fieldList != null && !fieldList.isEmpty()) {
lable = new Label[fieldList.size()];
column = new Column[fieldList.size()];
sqlQuery = sqlQuery.append(" SELECT ");
if (zoomWindowId > 0 && zoomTabId > 0) {
MBrowseField zoomField = new MBrowseField(Env.getCtx(), zoomFieldId, null);
if (!fieldList.contains(zoomField)) {
StringBuffer columnWhereClause = new StringBuffer("AD_View_Column_ID = " + zoomField.getAD_View_Column_ID());
MViewColumn viewColumn = new Query(Env.getCtx(), I_AD_View_Column.Table_Name, columnWhereClause.toString(), null).setOnlyActiveRecords(true).first();
sqlQuery = sqlQuery.append(viewColumn.getColumnSQL() + ", ");
} else {
displayZoomCol = Boolean.TRUE;
}
whereClause = new StringBuffer("AD_Tab_ID= " + zoomTabId);
zoomTab = new Query(Env.getCtx(), I_AD_Tab.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
if (zoomTab != null) {
// Getting Zoom table based on the zoom tab
whereClause = new StringBuffer("AD_Table_ID= " + zoomTab.getAD_Table_ID());
zoomTable = new Query(Env.getCtx(), I_AD_Table.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
if (zoomTable != null) {
// table or view? based on suffix "_v". It assumed that
// created view is having this suffix
//@The View Name must be Actual Table Name and It must ends with one of above suffixes @
//If this view combination of multiple tables, the view name must be prefix with any one of Joining Tables
//And That table should have primary key::: Eg: AD_USer_v, here AD_User_ID is Primary key of AD_User
zoomTableName = zoomTable.getTableName();
if (zoomTable.isView()) {
if (zoomTableName.endsWith("_vt")) {
zoomTableColumnName = zoomTableName.replace("_vt", "_ID");
sqlQuery = sqlQuery.append(zoomTableColumnName + ", ");
} else // if view ends with _v only
if (zoomTableName.endsWith("_v")) {
zoomTableColumnName = zoomTableName.replace("_v", "_ID");
sqlQuery = sqlQuery.append(zoomTableColumnName + ", ");
}
} else {
zoomTableColumnName = zoomTable.getTableName() + "_ID";
}
}
}
}
int i = 0;
for (MBrowseField field : fieldList) {
if (i != 0) {
sqlQuery = sqlQuery.append(", ");
}
// creating column and preparing sql query with db column names
column[i] = new Column(field.getName(), null, null);
StringBuffer columnWhereClause = new StringBuffer("AD_View_Column_ID = " + field.getAD_View_Column_ID());
MViewColumn viewColumn = new Query(Env.getCtx(), I_AD_View_Column.Table_Name, columnWhereClause.toString(), null).setOnlyActiveRecords(true).first();
sqlQuery = sqlQuery.append(viewColumn.getColumnName().replaceFirst("_", "."));
i = i + 1;
}
}
whereClause = new StringBuffer("AD_Browse_ID= " + browseId);
MBrowse browse = new Query(Env.getCtx(), I_AD_Browse.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
if (browse != null) {
whereClause = new StringBuffer("AD_View_ID= " + browse.getAD_View_ID());
List<MViewDefinition> list = new Query(Env.getCtx(), I_AD_View_Definition.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).list();
whereClause = new StringBuffer(X_AD_View_Definition.COLUMNNAME_AD_Table_ID + " = " + list.get(0).getAD_Table_ID());
table = new Query(Env.getCtx(), I_AD_Table.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
StringBuffer joinClause = new StringBuffer();
for (MViewDefinition viewDefinition : list) {
if (viewDefinition.getJoinClause() == null)
joinClause.append(" " + viewDefinition.getTableAlias());
else
joinClause.append(" " + viewDefinition.getJoinClause());
}
// Associating sql query with table name
sqlQuery.append(" FROM " + table.getTableName()).append(joinClause.toString());
//get where clause of this Smart Browse
String where = browse.getWhereClause();
if (where != null) {
boolean success = true;
do {
int index = where.indexOf("@");
int index2 = where.indexOf("@", index + 1);
boolean integer = false;
int replacedValue = 0;
String replacedString = null;
if (index > 0 || index2 > 0) {
String subString1 = where.substring(index + 1, index2);
if (subString1.contains("#")) {
if (subString1.endsWith("_ID")) {
replacedValue = Env.getContextAsInt(ctx, subString1);
integer = true;
} else {
replacedString = Env.getContext(ctx, subString1);
}
if (integer) {
where = where.replaceAll(where.substring(index, index2 + 1), String.valueOf(replacedValue));
} else {
where = where.replaceAll(where.substring(index, index2 + 1), "'" + replacedString + "'");
}
} else {
where = where.replaceAll(where.substring(index, index2 + 1), where.substring(index + 1, index2));
}
success = true;
} else {
success = false;
}
} while (success);
sqlQuery.append(" Where " + where);
}
}
return sqlQuery.toString();
}
use of org.adempiere.model.MBrowseField in project adempiere by adempiere.
the class BrowseElementHandler method create.
public void create(Properties ctx, TransformerHandler document) throws SAXException {
int AD_Browse_ID = Env.getContextAsInt(ctx, "AD_Browse_ID");
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
MBrowse m_Browse = new MBrowse(ctx, AD_Browse_ID, null);
AttributesImpl atts = new AttributesImpl();
packOut.createView(m_Browse.getAD_View_ID(), document);
packOut.createProcess(m_Browse.getAD_Process_ID(), document);
createBrowseBinding(atts, m_Browse);
document.startElement("", "", "browse", atts);
// Tab Tag
StringBuilder whereClause = new StringBuilder(I_AD_Browse_Field.COLUMNNAME_AD_Browse_ID).append("=?");
List<MBrowseField> browseFields = new Query(ctx, I_AD_Browse_Field.Table_Name, whereClause.toString(), getTrxName(ctx)).setParameters(m_Browse.getAD_Browse_ID()).list();
for (MBrowseField bf : browseFields) {
createBrowseField(ctx, document, bf.getAD_Browse_Field_ID());
}
// Loop tags.
document.endElement("", "", "browse");
}
Aggregations