Search in sources :

Example 1 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Env method reset.

/**
	 * 	Reset Cache
	 * 	@param finalCall everything otherwise login data remains
	 */
public static void reset(boolean finalCall) {
    s_log.info("finalCall=" + finalCall);
    if (Ini.isClient()) {
        closeWindows();
        //bug [ 1574630 ]
        if (s_windows.size() > 0) {
            if (!finalCall) {
                Container c = s_windows.get(0);
                s_windows.clear();
                createWindowNo(c);
            } else {
                s_windows.clear();
            }
        }
    }
    //	Clear all Context
    if (finalCall)
        getCtx().clear();
    else //	clear window context only
    {
        Object[] keys = getCtx().keySet().toArray();
        for (int i = 0; i < keys.length; i++) {
            String tag = keys[i].toString();
            if (Character.isDigit(tag.charAt(0)))
                getCtx().remove(keys[i]);
        }
    }
    //	Cache
    CacheMgt.get().reset();
    if (Ini.isClient())
        DB.closeTarget();
    //	Reset Role Access
    if (!finalCall) {
        if (Ini.isClient())
            DB.setDBTarget(CConnection.get());
        MRole defaultRole = MRole.getDefault(getCtx(), false);
        if (defaultRole != null)
            //	Reload
            defaultRole.loadAccess(true);
    }
}
Also used : Container(java.awt.Container) MRole(org.compiere.model.MRole)

Example 2 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Archive method getTableData.

public KeyNamePair[] getTableData() {
    //	Tables
    // metas
    final MRole role = MRole.getDefault();
    //		int AD_Role_ID = Env.getAD_Role_ID(Env.getCtx());
    boolean trl = !Env.isBaseLanguage(Env.getCtx(), "AD_Table");
    String lang = Env.getAD_Language(Env.getCtx());
    String sql = "SELECT DISTINCT t.AD_Table_ID," + (trl ? "trl.Name" : "t.Name") + " FROM AD_Table t INNER JOIN AD_Tab tab ON (tab.AD_Table_ID=t.AD_Table_ID)" + " INNER JOIN AD_Window_Access wa ON (tab.AD_Window_ID=wa.AD_Window_ID) " + (trl ? "LEFT JOIN AD_Table_Trl trl on (trl.AD_Table_ID=t.AD_Table_ID and trl.AD_Language=" + DB.TO_STRING(lang) + ")" : "") + " WHERE " + // metas
    role.getIncludedRolesWhereClause("wa.AD_Role_ID", null) + " AND t.IsActive='Y' AND tab.IsActive='Y' " + "ORDER BY 2";
    return DB.getKeyNamePairs(sql, true);
}
Also used : MRole(org.compiere.model.MRole)

Example 3 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class WWindow method getSR_Form.

//  getFieldValue
/**************************************************************************
	 *	Return SingleRow Form details
	 *  @param action action
	 *  @param wsc web session context
	 *  @param ws window status
	 *  @return Form
	 */
public WebDoc getSR_Form(String action, WebSessionCtx wsc, WWindowStatus ws) {
    log.fine("Tab=" + ws.curTab.getTabNo());
    /**********************
		 *  For all Fields
		 */
    //Modified by Rob Klein 4/29/07
    //table table = new table()
    //	.setAlign(AlignType.CENTER);
    table table = new table();
    table.setClass("centerTable");
    StringBuffer scriptSrc = new StringBuffer();
    MRole role = MRole.getDefault(wsc.ctx, false);
    //
    tr line = new tr();
    //Modified by Rob Klein 4/29/07
    m_searchField = null;
    boolean isTabRO = ws.curTab.isReadOnly();
    if (ws.curTab.isDisplayed()) {
        int noFields = ws.curTab.getFieldCount();
        for (int i = 0; i < noFields; i++) {
            GridField field = ws.curTab.getField(i);
            String columnName = field.getColumnName();
            /**
				 *  Get Data and convert to String (singleRow)
				 */
            Object oData = ws.curTab.getValue(field);
            //Modified by Rob Klein 4/29/07
            /**
				 *  Get Record ID and Table ID for Processes
				 */
            int recordID = ws.curTab.getRecord_ID();
            int tableID = ws.curTab.getAD_Table_ID();
            /**
				 *  Display field
				 */
            if (field.isDisplayed(true)) {
                if (!field.isSameLine())
                    line = new tr();
                //
                boolean hasDependents = ws.curTab.hasDependants(columnName);
                //Modified by Rob Klein 4/29/07
                addField(wsc, line, field, oData, hasDependents, recordID, tableID, isTabRO, i, ws.curTab, role);
                //addField(wsc, line, field, oData, hasDependents);
                table.addElement(line);
                //  Additional Values
                String dispLogic = field.getDisplayLogic();
                if (dispLogic != null && dispLogic.length() > 0) {
                    //  replace ' with "
                    dispLogic = dispLogic.replace('\'', '"');
                    scriptSrc.append("document.").append(FORM_NAME).append(".").append(columnName).append(".displayLogic='").append(dispLogic).append("';\n");
                }
                if (m_searchField == null)
                    if (columnName.equals("Description"))
                        m_searchField = columnName;
                    else if (columnName.equals("Name"))
                        m_searchField = columnName;
                    else if (columnName.equals("DocumentNo"))
                        m_searchField = columnName;
                    else if (columnName.equals("Value"))
                        m_searchField = columnName;
            }
        }
    //	for all fields
    }
    //	displayed
    if (scriptSrc.length() > 0)
        table.addElement(new script(scriptSrc.toString()));
    //  Status Line
    int rowNo = ws.curTab.getCurrentRow();
    String statusDB = String.valueOf(rowNo + 1) + " / " + ws.curTab.getRowCount();
    //
    return createLayout(action, table, wsc, ws, ws.curTab.getDescription(), statusDB);
}
Also used : MRole(org.compiere.model.MRole) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.script(org.apache.ecs.xhtml.script)

Example 4 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class AbstractADWindowPanel method history.

private void history(int onlyCurrentDays) {
    if (//	Day
    onlyCurrentDays == 1) {
        m_onlyCurrentRows = true;
        //	no Created restriction
        onlyCurrentDays = 0;
    } else
        m_onlyCurrentRows = false;
    //	reset previous queries
    curTab.setQuery(null);
    MRole role = MRole.getDefault();
    int maxRows = role.getMaxQueryRecords();
    logger.config("OnlyCurrent=" + m_onlyCurrentRows + ", Days=" + m_onlyCurrentDays + ", MaxRows=" + maxRows);
    curTab.query(m_onlyCurrentRows, onlyCurrentDays, maxRows);
}
Also used : MRole(org.compiere.model.MRole)

Example 5 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class TableReference method getPrintDataInfo.

//	getPrintData
/**************************************************************************
	 * 	Create Load SQL and update PrintData Info
	 *
	 * 	@param ctx context
	 * 	@param format print format
	 * 	@param query query
	 *  @param reportName report name
	 *  @param tableName table name
	 * 	@return PrintData or null
	 */
private PrintData getPrintDataInfo(Properties ctx, MPrintFormat format, MQuery query, String reportName, String tableName) {
    m_startTime = System.currentTimeMillis();
    log.info(reportName + " - " + m_language.getAD_Language());
    log.fine("TableName=" + tableName + ", Query=" + query);
    log.fine("Format=" + format);
    ArrayList<PrintDataColumn> columns = new ArrayList<PrintDataColumn>();
    m_group = new PrintDataGroup();
    //	Order Columns (identified by non zero/null SortNo)
    int[] orderAD_Column_IDs = format.getOrderAD_Column_IDs();
    ArrayList<String> orderColumns = new ArrayList<String>(orderAD_Column_IDs.length);
    for (int i = 0; i < orderAD_Column_IDs.length; i++) {
        log.finest("Order AD_Column_ID=" + orderAD_Column_IDs[i]);
        //	initial value overwritten with fully qualified name
        orderColumns.add("");
    }
    //	Direct SQL w/o Reference Info
    StringBuffer sqlSELECT = new StringBuffer("SELECT ");
    StringBuffer sqlFROM = new StringBuffer(" FROM ").append(tableName);
    ArrayList<String> groupByColumns = new ArrayList<String>();
    //
    boolean IsGroupedBy = false;
    //
    String sql = //	1..2
    "SELECT c.AD_Column_ID,c.ColumnName," + //	3..4
    "c.AD_Reference_ID,c.AD_Reference_Value_ID," + //	5..8
    "c.FieldLength,c.IsMandatory,c.IsKey,c.IsParent," + //	9..10
    "COALESCE(rvc.IsGroupFunction,'N'),rvc.FunctionColumn," + //	11..14
    "pfi.IsGroupBy,pfi.IsSummarized,pfi.IsAveraged,pfi.IsCounted, " + //	15..17
    "pfi.IsPrinted,pfi.SortNo,pfi.IsPageBreak, " + //	18..19
    "pfi.IsMinCalc,pfi.IsMaxCalc, " + //	20..21
    "pfi.isRunningTotal,pfi.RunningTotalLines, " + //	22..23
    "pfi.IsVarianceCalc, pfi.IsDeviationCalc, " + //	24, 25
    "c.ColumnSQL, COALESCE(pfi.FormatPattern, c.FormatPattern) " + "FROM AD_PrintFormat pf" + " INNER JOIN AD_PrintFormatItem pfi ON (pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID)" + " INNER JOIN AD_Column c ON (pfi.AD_Column_ID=c.AD_Column_ID)" + " LEFT OUTER JOIN AD_ReportView_Col rvc ON (pf.AD_ReportView_ID=rvc.AD_ReportView_ID AND c.AD_Column_ID=rvc.AD_Column_ID) " + //	#1
    "WHERE pf.AD_PrintFormat_ID=?" + " AND pfi.IsActive='Y' AND (pfi.IsPrinted='Y' OR c.IsKey='Y' OR pfi.SortNo > 0) " + " AND pfi.PrintFormatType IN ('" + MPrintFormatItem.PRINTFORMATTYPE_Field + "','" + MPrintFormatItem.PRINTFORMATTYPE_Image + "','" + MPrintFormatItem.PRINTFORMATTYPE_PrintFormat + "') " + //	Functions are put in first column
    "ORDER BY pfi.IsPrinted DESC, pfi.SeqNo";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, m_trxName);
        pstmt.setInt(1, format.get_ID());
        rs = pstmt.executeQuery();
        //	synonym
        m_synonym = "A";
        while (rs.next()) {
            //	get Values from record
            int AD_Column_ID = rs.getInt(1);
            String ColumnName = rs.getString(2);
            String ColumnSQL = rs.getString(24);
            if (ColumnSQL == null)
                ColumnSQL = "";
            int AD_Reference_ID = rs.getInt(3);
            int AD_Reference_Value_ID = rs.getInt(4);
            //  ColumnInfo
            int FieldLength = rs.getInt(5);
            boolean IsMandatory = "Y".equals(rs.getString(6));
            boolean IsKey = "Y".equals(rs.getString(7));
            boolean IsParent = "Y".equals(rs.getString(8));
            //  SQL GroupBy
            boolean IsGroupFunction = "Y".equals(rs.getString(9));
            if (IsGroupFunction)
                IsGroupedBy = true;
            String FunctionColumn = rs.getString(10);
            if (FunctionColumn == null)
                FunctionColumn = "";
            //	Breaks/Column Functions
            if ("Y".equals(rs.getString(11)))
                m_group.addGroupColumn(ColumnName);
            if ("Y".equals(rs.getString(12)))
                m_group.addFunction(ColumnName, PrintDataFunction.F_SUM);
            if ("Y".equals(rs.getString(13)))
                m_group.addFunction(ColumnName, PrintDataFunction.F_MEAN);
            if ("Y".equals(rs.getString(14)))
                m_group.addFunction(ColumnName, PrintDataFunction.F_COUNT);
            if (//	IsMinCalc
            "Y".equals(rs.getString(18)))
                m_group.addFunction(ColumnName, PrintDataFunction.F_MIN);
            if (//	IsMaxCalc
            "Y".equals(rs.getString(19)))
                m_group.addFunction(ColumnName, PrintDataFunction.F_MAX);
            if (//	IsVarianceCalc
            "Y".equals(rs.getString(22)))
                m_group.addFunction(ColumnName, PrintDataFunction.F_VARIANCE);
            if (//	IsDeviationCalc
            "Y".equals(rs.getString(23)))
                m_group.addFunction(ColumnName, PrintDataFunction.F_DEVIATION);
            if (//	isRunningTotal
            "Y".equals(rs.getString(20)))
                //	RunningTotalLines only once - use max
                m_runningTotalLines = Math.max(m_runningTotalLines, rs.getInt(21));
            //	General Info
            boolean IsPrinted = "Y".equals(rs.getString(15));
            int SortNo = rs.getInt(16);
            boolean isPageBreak = "Y".equals(rs.getString(17));
            String formatPattern = rs.getString(25);
            //	Fully qualified Table.Column for ordering
            String orderName = tableName + "." + ColumnName;
            String lookupSQL = orderName;
            PrintDataColumn pdc = null;
            //  -- Key --
            if (IsKey) {
                //	=>	Table.Column,
                sqlSELECT.append(tableName).append(".").append(ColumnName).append(",");
                groupByColumns.add(tableName + "." + ColumnName);
                //	KeyColumn
                pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, KEY, isPageBreak);
            } else // not printed Sort Columns
            if (!IsPrinted) {
                ;
            } else //	-- Parent, TableDir (and unqualified Search) --
            if ((IsParent && DisplayType.isLookup(AD_Reference_ID)) || AD_Reference_ID == DisplayType.TableDir || (AD_Reference_ID == DisplayType.Search && AD_Reference_Value_ID == 0)) {
                //  Creates Embedded SQL in the form
                //  SELECT ColumnTable.Name FROM ColumnTable WHERE TableName.ColumnName=ColumnTable.ColumnName
                String eSql;
                if (ColumnSQL.length() > 0) {
                    eSql = MLookupFactory.getLookup_TableDirEmbed(m_language, ColumnName, tableName, "(" + ColumnSQL + ")");
                    lookupSQL = ColumnSQL;
                } else {
                    eSql = MLookupFactory.getLookup_TableDirEmbed(m_language, ColumnName, tableName);
                }
                //	TableName
                String table = ColumnName;
                if (table.endsWith("_ID"))
                    table = table.substring(0, table.length() - 3);
                //  DisplayColumn
                String display = ColumnName;
                //	=> (..) AS AName, Table.ID,
                sqlSELECT.append("(").append(eSql).append(") AS ").append(m_synonym).append(display).append(",").append(lookupSQL).append(" AS ").append(ColumnName).append(",");
                groupByColumns.add(lookupSQL);
                orderName = m_synonym + display;
                //
                pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, orderName, isPageBreak);
                synonymNext();
            } else //	-- Table --
            if (AD_Reference_ID == DisplayType.Table || (AD_Reference_ID == DisplayType.Search && AD_Reference_Value_ID != 0)) {
                if (ColumnSQL.length() > 0) {
                    lookupSQL = ColumnSQL;
                }
                if (AD_Reference_Value_ID <= 0) {
                    log.warning(ColumnName + " - AD_Reference_Value_ID not set");
                    continue;
                }
                TableReference tr = getTableReference(AD_Reference_Value_ID);
                String display = tr.DisplayColumn;
                //	=> A.Name AS AName, Table.ID,
                if (tr.IsValueDisplayed)
                    sqlSELECT.append(m_synonym).append(".Value||'-'||");
                sqlSELECT.append(m_synonym).append(".").append(display);
                sqlSELECT.append(" AS ").append(m_synonym).append(display).append(",").append(lookupSQL).append(" AS ").append(ColumnName).append(",");
                groupByColumns.add(m_synonym + display);
                groupByColumns.add(lookupSQL);
                orderName = m_synonym + display;
                //	=> x JOIN table A ON (x.KeyColumn=A.Key)
                if (IsMandatory)
                    sqlFROM.append(" INNER JOIN ");
                else
                    sqlFROM.append(" LEFT OUTER JOIN ");
                sqlFROM.append(tr.TableName).append(" ").append(m_synonym).append(" ON (").append(lookupSQL).append("=").append(m_synonym).append(".").append(tr.KeyColumn).append(")");
                //
                pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, orderName, isPageBreak);
                synonymNext();
            } else //	-- List or Button with ReferenceValue --
            if (AD_Reference_ID == DisplayType.List || (AD_Reference_ID == DisplayType.Button && AD_Reference_Value_ID != 0)) {
                if (ColumnSQL.length() > 0) {
                    lookupSQL = ColumnSQL;
                }
                if (Env.isBaseLanguage(m_language, "AD_Ref_List")) {
                    //	=> A.Name AS AName,
                    sqlSELECT.append(m_synonym).append(".Name AS ").append(m_synonym).append("Name,");
                    groupByColumns.add(m_synonym + ".Name");
                    orderName = m_synonym + "Name";
                    //	=> x JOIN AD_Ref_List A ON (x.KeyColumn=A.Value AND A.AD_Reference_ID=123)
                    if (IsMandatory)
                        sqlFROM.append(" INNER JOIN ");
                    else
                        sqlFROM.append(" LEFT OUTER JOIN ");
                    sqlFROM.append("AD_Ref_List ").append(m_synonym).append(" ON (").append(lookupSQL).append("=").append(m_synonym).append(".Value").append(" AND ").append(m_synonym).append(".AD_Reference_ID=").append(AD_Reference_Value_ID).append(")");
                } else {
                    //	=> A.Name AS AName,
                    sqlSELECT.append(m_synonym).append(".Name AS ").append(m_synonym).append("Name,");
                    groupByColumns.add(m_synonym + ".Name");
                    orderName = m_synonym + "Name";
                    //	LEFT OUTER JOIN AD_Ref_List_Trl A ON (XA.AD_Ref_List_ID=A.AD_Ref_List_ID AND A.AD_Language='de_DE')
                    if (IsMandatory)
                        sqlFROM.append(" INNER JOIN ");
                    else
                        sqlFROM.append(" LEFT OUTER JOIN ");
                    sqlFROM.append(" AD_Ref_List X").append(m_synonym).append(" ON (").append(lookupSQL).append("=X").append(m_synonym).append(".Value AND X").append(m_synonym).append(".AD_Reference_ID=").append(AD_Reference_Value_ID).append(")");
                    if (IsMandatory)
                        sqlFROM.append(" INNER JOIN ");
                    else
                        sqlFROM.append(" LEFT OUTER JOIN ");
                    sqlFROM.append(" AD_Ref_List_Trl ").append(m_synonym).append(" ON (X").append(m_synonym).append(".AD_Ref_List_ID=").append(m_synonym).append(".AD_Ref_List_ID").append(" AND ").append(m_synonym).append(".AD_Language='").append(m_language.getAD_Language()).append("')");
                }
                // 	TableName.ColumnName,
                sqlSELECT.append(lookupSQL).append(" AS ").append(ColumnName).append(",");
                pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, orderName, isPageBreak);
                synonymNext();
            } else //  -- Special Lookups --
            if (AD_Reference_ID == DisplayType.Location || AD_Reference_ID == DisplayType.Account || AD_Reference_ID == DisplayType.Locator || AD_Reference_ID == DisplayType.PAttribute) {
                if (ColumnSQL.length() > 0) {
                    lookupSQL = ColumnSQL;
                }
                //	TableName, DisplayColumn
                String table = "";
                String key = "";
                String display = "";
                String synonym = null;
                //
                if (AD_Reference_ID == DisplayType.Location) {
                    table = "C_Location";
                    key = "C_Location_ID";
                    //	in case City is empty
                    display = "City||'.'";
                    synonym = "Address";
                } else if (AD_Reference_ID == DisplayType.Account) {
                    table = "C_ValidCombination";
                    key = "C_ValidCombination_ID";
                    display = "Combination";
                } else if (AD_Reference_ID == DisplayType.Locator) {
                    table = "M_Locator";
                    key = "M_Locator_ID";
                    display = "Value";
                } else if (AD_Reference_ID == DisplayType.PAttribute) {
                    table = "M_AttributeSetInstance";
                    key = "M_AttributeSetInstance_ID";
                    display = "Description";
                    if (CLogMgt.isLevelFine())
                        display += "||'{'||" + m_synonym + ".M_AttributeSetInstance_ID||'}'";
                    synonym = "Description";
                }
                if (synonym == null)
                    synonym = display;
                //	=> A.Name AS AName, table.ID,
                sqlSELECT.append(m_synonym).append(".").append(display).append(" AS ").append(m_synonym).append(synonym).append(",").append(lookupSQL).append(" AS ").append(ColumnName).append(",");
                groupByColumns.add(m_synonym + "." + synonym);
                groupByColumns.add(lookupSQL);
                orderName = m_synonym + synonym;
                //	=> x JOIN table A ON (table.ID=A.Key)
                if (IsMandatory)
                    sqlFROM.append(" INNER JOIN ");
                else
                    sqlFROM.append(" LEFT OUTER JOIN ");
                sqlFROM.append(table).append(" ").append(m_synonym).append(" ON (").append(lookupSQL).append("=").append(m_synonym).append(".").append(key).append(")");
                //
                pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, orderName, isPageBreak);
                synonymNext();
            } else //	-- Standard Column --
            {
                int index = FunctionColumn.indexOf('@');
                if (ColumnSQL != null && ColumnSQL.length() > 0) {
                    //	=> ColumnSQL AS ColumnName
                    sqlSELECT.append(ColumnSQL).append(" AS ").append(ColumnName).append(",");
                    if (!IsGroupFunction)
                        groupByColumns.add(ColumnSQL);
                    //	no prefix for synonym
                    orderName = ColumnName;
                } else if (index == -1) {
                    //	=> Table.Column,
                    StringBuffer sb = new StringBuffer();
                    sb.append(tableName).append(".").append(ColumnName);
                    sqlSELECT.append(sb).append(",");
                    if (!IsGroupFunction)
                        groupByColumns.add(sb.toString());
                } else {
                    //  => Function(Table.Column) AS Column   -- function has @ where column name goes
                    StringBuffer sb = new StringBuffer();
                    sb.append(FunctionColumn.substring(0, index)).append(tableName).append(".").append(ColumnName).append(FunctionColumn.substring(index + 1));
                    sqlSELECT.append(sb).append(" AS ").append(ColumnName).append(",");
                    if (!IsGroupFunction)
                        groupByColumns.add(sb.toString());
                    //	no prefix for synonym
                    orderName = ColumnName;
                }
                pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, ColumnName, isPageBreak);
            }
            //	Order Sequence - Overwrite order column name
            for (int i = 0; i < orderAD_Column_IDs.length; i++) {
                if (AD_Column_ID == orderAD_Column_IDs[i]) {
                    orderColumns.set(i, orderName);
                    // We need to GROUP BY even is not printed, because is used in ORDER clause
                    if (!IsPrinted && !IsGroupFunction) {
                        groupByColumns.add(tableName + "." + ColumnName);
                    }
                    break;
                }
            }
            //
            if (pdc == null || (!IsPrinted && !IsKey))
                continue;
            pdc.setFormatPattern(formatPattern);
            columns.add(pdc);
        }
    //	for all Fields in Tab
    } catch (SQLException e) {
        log.log(Level.SEVERE, "SQL=" + sql + " - ID=" + format.get_ID(), e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    if (columns.size() == 0) {
        log.log(Level.SEVERE, "No Colums - Delete Report Format " + reportName + " and start again");
        log.finest("No Colums - SQL=" + sql + " - ID=" + format.get_ID());
        return null;
    }
    boolean hasLevelNo = false;
    if (tableName.startsWith("T_Report")) {
        hasLevelNo = true;
        if (sqlSELECT.indexOf("LevelNo") == -1)
            sqlSELECT.append("LevelNo,");
    }
    /**
		 *	Assemble final SQL - delete last SELECT ','
		 */
    StringBuffer finalSQL = new StringBuffer();
    finalSQL.append(sqlSELECT.substring(0, sqlSELECT.length() - 1)).append(sqlFROM);
    //	WHERE clause
    if (tableName.startsWith("T_Report")) {
        finalSQL.append(" WHERE ");
        for (int i = 0; i < query.getRestrictionCount(); i++) {
            String q = query.getWhereClause(i);
            if (//	ignore all other Parameters
            q.indexOf("AD_PInstance_ID") != -1)
                finalSQL.append(q);
        }
    //	for all restrictions
    } else {
        //	User supplied Where Clause
        if (query != null && query.isActive()) {
            finalSQL.append(" WHERE ");
            if (!query.getTableName().equals(tableName))
                query.setTableName(tableName);
            finalSQL.append(query.getWhereClause(true));
        }
        //	Access Restriction
        MRole role = MRole.getDefault(ctx, false);
        if (role.getAD_Role_ID() == 0 && !Ini.isClient())
            //	System Access
            ;
        else
            finalSQL = new StringBuffer(role.addAccessSQL(finalSQL.toString(), tableName, MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO));
    }
    //	Add GROUP BY clause
    if (IsGroupedBy) {
        for (int i = 0; i < groupByColumns.size(); i++) {
            if (i == 0)
                finalSQL.append(" GROUP BY ");
            else
                finalSQL.append(",");
            finalSQL.append(groupByColumns.get(i));
        }
    }
    //	Add ORDER BY clause
    if (orderColumns != null) {
        for (int i = 0; i < orderColumns.size(); i++) {
            if (i == 0)
                finalSQL.append(" ORDER BY ");
            else
                finalSQL.append(",");
            String by = (String) orderColumns.get(i);
            if (by == null || by.length() == 0)
                by = String.valueOf(i + 1);
            finalSQL.append(by);
        }
    }
    //	order by
    //	Print Data
    PrintData pd = new PrintData(ctx, reportName);
    PrintDataColumn[] info = new PrintDataColumn[columns.size()];
    //	column order is is m_synonymc with SELECT column position
    columns.toArray(info);
    pd.setColumnInfo(info);
    pd.setTableName(tableName);
    pd.setSQL(finalSQL.toString());
    pd.setHasLevelNo(hasLevelNo);
    log.finest(finalSQL.toString());
    log.finest("Group=" + m_group);
    return pd;
}
Also used : SQLException(java.sql.SQLException) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet)

Aggregations

MRole (org.compiere.model.MRole)42 PreparedStatement (java.sql.PreparedStatement)14 ResultSet (java.sql.ResultSet)14 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)7 Point (java.awt.Point)4 Properties (java.util.Properties)4 BigDecimal (java.math.BigDecimal)3 Statement (java.sql.Statement)3 GridField (org.compiere.model.GridField)3 GridTab (org.compiere.model.GridTab)3 QName (javax.xml.namespace.QName)2 MBrowse (org.adempiere.model.MBrowse)2 XFireFault (org.codehaus.xfire.fault.XFireFault)2 ICreateFrom (org.compiere.grid.ICreateFrom)2 MOrgInfo (org.compiere.model.MOrgInfo)2 MProcess (org.compiere.model.MProcess)2 MTable (org.compiere.model.MTable)2 MWFActivity (org.compiere.wf.MWFActivity)2 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)2