Search in sources :

Example 1 with I_AD_View_Column

use of org.adempiere.model.I_AD_View_Column 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;
}
Also used : MColumn(org.compiere.model.MColumn) MBrowseField(org.adempiere.model.MBrowseField) MLookup(org.compiere.model.MLookup) ArrayList(java.util.ArrayList) I_AD_View_Column(org.adempiere.model.I_AD_View_Column) MBrowse(org.adempiere.model.MBrowse) SQLException(java.sql.SQLException) IOException(java.io.IOException) DBException(org.adempiere.exceptions.DBException) AdempiereException(org.adempiere.exceptions.AdempiereException) MViewColumn(org.adempiere.model.MViewColumn) MTable(org.compiere.model.MTable) AdempiereException(org.adempiere.exceptions.AdempiereException)

Aggregations

IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 DBException (org.adempiere.exceptions.DBException)1 I_AD_View_Column (org.adempiere.model.I_AD_View_Column)1 MBrowse (org.adempiere.model.MBrowse)1 MBrowseField (org.adempiere.model.MBrowseField)1 MViewColumn (org.adempiere.model.MViewColumn)1 MColumn (org.compiere.model.MColumn)1 MLookup (org.compiere.model.MLookup)1 MTable (org.compiere.model.MTable)1