Search in sources :

Example 16 with MColumn

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

the class RecordInfoController method dynInit.

/**
	 * 	Dynamic Init
	 *	@param dse data status event
	 *	@param title title
	 *	@param mField field
	 */
private void dynInit(DataStatusEvent dse, String title, GridField mField) {
    m_Field = mField;
    //	Yamel Senih FR[ 146 ] Add support to change log in a specific column
    //	2015-12-03
    //	For Field
    int m_Record_ID = 0;
    int m_AD_Table_ID = 0;
    int m_AD_Column_ID = 0;
    if (m_Field != null) {
        //	Set Values
        m_Record_ID = m_Field.getGridTab().getRecord_ID();
        m_AD_Table_ID = m_Field.getGridTab().getAD_Table_ID();
        m_AD_Column_ID = m_Field.getAD_Column_ID();
        //	
        MColumn column = MColumn.get(Env.getCtx(), m_AD_Column_ID);
        X_AD_Reference reference = new X_AD_Reference(Env.getCtx(), m_Field.getDisplayType(), null);
        DecimalFormat format = DisplayType.getNumberFormat(reference.getAD_Reference_ID());
        MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
        //  Info
        m_info.append("(").append(table.getTableName()).append(" - ").append(m_Field.getColumnName()).append(" = ").append(m_Field.getValue()).append(")").append("\n").append(Msg.translate(Env.getCtx(), "Name")).append(": ").append(m_Field.getHeader()).append("\n").append(Msg.translate(Env.getCtx(), "Description")).append(": ").append(m_Field.getDescription()).append("\n").append(Msg.translate(Env.getCtx(), "AD_Reference_ID")).append(": ").append(reference.get_Translation("Name")).append("\n");
        //	For Reference Key
        if (m_Field.getDisplayType() == DisplayType.List || m_Field.getDisplayType() == DisplayType.Table || m_Field.getDisplayType() == DisplayType.Search) {
            //	Valid Reference Value
            if (m_Field.getAD_Reference_Value_ID() != 0) {
                X_AD_Reference referenceKey = new X_AD_Reference(Env.getCtx(), m_Field.getAD_Reference_Value_ID(), null);
                m_info.append(Msg.translate(Env.getCtx(), "AD_Reference_Value_ID")).append(": ").append(referenceKey.get_Translation("Name")).append(" (").append(m_Field.getAD_Reference_Value_ID()).append(")").append("\n");
            }
        }
        //	Valid Dynamic Validation
        if (column.getAD_Val_Rule_ID() != 0) {
            X_AD_Val_Rule validation = (X_AD_Val_Rule) column.getAD_Val_Rule();
            m_info.append(Msg.translate(Env.getCtx(), "AD_Val_Rule_ID")).append(": ").append(validation.get_Translation("Name")).append(" (").append(column.getAD_Val_Rule_ID()).append(")").append("\n");
        }
        m_info.append(Msg.translate(Env.getCtx(), "Length")).append(": ").append(format.format(column.getFieldLength())).append("\n");
        //	Add Entity Type for info
        MEntityType entity = MEntityType.get(Env.getCtx(), column.getEntityType());
        m_info.append(Msg.translate(Env.getCtx(), "EntityType")).append(": ").append(entity.get_Translation("Name"));
        //	Title
        m_Title = title + " - " + m_Field.getHeader();
    } else {
        if (dse.CreatedBy == null)
            return;
        //  Info
        MUser user = MUser.get(Env.getCtx(), dse.CreatedBy.intValue());
        m_info.append(" ").append(Msg.translate(Env.getCtx(), "CreatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Created)).append("\n");
        if (!dse.Created.equals(dse.Updated) || !dse.CreatedBy.equals(dse.UpdatedBy)) {
            if (!dse.CreatedBy.equals(dse.UpdatedBy))
                user = MUser.get(Env.getCtx(), dse.UpdatedBy.intValue());
            m_info.append(" ").append(Msg.translate(Env.getCtx(), "UpdatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Updated)).append("\n");
        }
        if (dse.Info != null && dse.Info.length() > 0)
            m_info.append("\n (").append(dse.Info).append(")");
        //	Title
        if (dse.AD_Table_ID != 0) {
            m_AD_Table_ID = dse.AD_Table_ID;
            MTable table1 = MTable.get(Env.getCtx(), dse.AD_Table_ID);
            m_Title = title + " - " + table1.getName();
        }
        //	Set Record ID
        if (dse.Record_ID instanceof Integer)
            m_Record_ID = ((Integer) dse.Record_ID).intValue();
        else
            log.info("dynInit - Invalid Record_ID=" + dse.Record_ID);
    }
    //	Valid Record Identifier
    if (m_Record_ID == 0)
        return;
    //	Only Client Preference can view Change Log
    if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()))
        return;
    //	Data
    String sql = "SELECT AD_Column_ID, Updated, UpdatedBy, OldValue, NewValue " + "FROM AD_ChangeLog " + "WHERE AD_Table_ID=? AND Record_ID=? " + (m_AD_Column_ID != 0 ? "AND AD_Column_ID=? " : "") + "ORDER BY Updated DESC";
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_AD_Table_ID);
        pstmt.setInt(2, m_Record_ID);
        //	Add support to column
        if (m_AD_Column_ID != 0)
            pstmt.setInt(3, m_AD_Column_ID);
        //	
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            addLine(rs.getInt(1), rs.getTimestamp(2), rs.getInt(3), rs.getString(4), rs.getString(5));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    //	Set Loaded to Ok
    m_IsLoaded = true;
}
Also used : MColumn(org.compiere.model.MColumn) DecimalFormat(java.text.DecimalFormat) PreparedStatement(java.sql.PreparedStatement) X_AD_Val_Rule(org.compiere.model.X_AD_Val_Rule) X_AD_Reference(org.compiere.model.X_AD_Reference) MTable(org.compiere.model.MTable) ResultSet(java.sql.ResultSet) MEntityType(org.compiere.model.MEntityType) MUser(org.compiere.model.MUser)

Example 17 with MColumn

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

the class TranslationDocSync method processTable.

//	doIt
/**
	 * 	Process Translation Table
	 *	@param table table
	 */
private void processTable(MTable table, int AD_Client_ID) {
    StringBuffer sql = new StringBuffer();
    MColumn[] columns = table.getColumns(false);
    for (int i = 0; i < columns.length; i++) {
        MColumn column = columns[i];
        if (column.getAD_Reference_ID() == DisplayType.String || column.getAD_Reference_ID() == DisplayType.Text) {
            String columnName = column.getColumnName();
            if (sql.length() != 0)
                sql.append(",");
            sql.append(columnName);
        }
    }
    String baseTable = table.getTableName();
    baseTable = baseTable.substring(0, baseTable.length() - 4);
    log.config(baseTable + ": " + sql);
    String columnNames = sql.toString();
    sql = new StringBuffer();
    sql.append("UPDATE ").append(table.getTableName()).append(" t SET (").append(columnNames).append(") = (SELECT ").append(columnNames).append(" FROM ").append(baseTable).append(" b WHERE t.").append(baseTable).append("_ID=b.").append(baseTable).append("_ID) WHERE AD_Client_ID=").append(AD_Client_ID);
    int no = DB.executeUpdate(sql.toString(), get_TrxName());
    addLog(0, null, new BigDecimal(no), baseTable);
}
Also used : MColumn(org.compiere.model.MColumn) BigDecimal(java.math.BigDecimal)

Example 18 with MColumn

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

the class TabCreateFields method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    MTab tab = new MTab(getCtx(), p_AD_Tab_ID, get_TrxName());
    if (p_AD_Tab_ID == 0 || tab == null || tab.get_ID() == 0)
        throw new AdempiereSystemError("@NotFound@: @AD_Tab_ID@ " + p_AD_Tab_ID);
    log.info(tab.toString());
    //
    int count = 0;
    String sql = "SELECT * FROM AD_Column c " + "WHERE NOT EXISTS (SELECT * FROM AD_Field f " + "WHERE c.AD_Column_ID=f.AD_Column_ID" + //	#1
    " AND c.AD_Table_ID=?" + //	#2
    " AND f.AD_Tab_ID=?)" + //	#3
    " AND AD_Table_ID=?" + " AND NOT (Name LIKE 'Created%' OR Name LIKE 'Updated%')" + " AND IsActive='Y' " + "ORDER BY Name";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        pstmt.setInt(1, tab.getAD_Table_ID());
        pstmt.setInt(2, tab.getAD_Tab_ID());
        pstmt.setInt(3, tab.getAD_Table_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MColumn column = new MColumn(getCtx(), rs, get_TrxName());
            //
            MField field = new MField(tab);
            field.setColumn(column);
            if ("D".equals(column.getEntityType()))
                field.setEntityType(tab.getEntityType());
            else
                field.setEntityType(column.getEntityType());
            if (column.isKey())
                field.setIsDisplayed(false);
            if (field.save()) {
                addLog(0, null, null, column.getName());
                count++;
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return "@Created@ #" + count;
}
Also used : MColumn(org.compiere.model.MColumn) AdempiereSystemError(org.compiere.util.AdempiereSystemError) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MTab(org.compiere.model.MTab) MField(org.compiere.model.MField)

Example 19 with MColumn

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

the class TableCreateColumns method addTableColumn.

//	addTable
/**
	 * 	Add Table Column
	 *	@param rs result set with meta data
	 *	@param table table
	 *	@throws Exception
	 */
private void addTableColumn(ResultSet rs, MTable table) throws Exception {
    String tableName = table.getTableName();
    if (DB.isOracle())
        tableName = tableName.toUpperCase();
    // globalqss 2005-10-24
    if (DB.isPostgreSQL())
        tableName = tableName.toLowerCase();
    // end globalqss 2005-10-24
    while (rs.next()) {
        String tn = rs.getString("TABLE_NAME");
        if (!tableName.equalsIgnoreCase(tn))
            continue;
        String columnName = rs.getString("COLUMN_NAME");
        MColumn column = table.getColumn(columnName);
        if (column != null)
            continue;
        int dataType = rs.getInt("DATA_TYPE");
        String typeName = rs.getString("TYPE_NAME");
        String nullable = rs.getString("IS_NULLABLE");
        int size = rs.getInt("COLUMN_SIZE");
        int digits = rs.getInt("DECIMAL_DIGITS");
        //
        log.config(columnName + " - DataType=" + dataType + " " + typeName + ", Nullable=" + nullable + ", Size=" + size + ", Digits=" + digits);
        //
        column = new MColumn(table);
        // teo_sarca: bug [ 1640908 ] 
        column.set_TrxName(get_TrxName());
        column.setEntityType(p_EntityType);
        //
        M_Element element = M_Element.get(getCtx(), columnName);
        if (element == null) {
            element = new M_Element(getCtx(), columnName, p_EntityType, get_TrxName());
            //and the name & description from table
            if (columnName.equalsIgnoreCase(table.getTableName() + "_ID")) {
                element.setColumnName(table.getTableName() + "_ID");
                element.setName(table.getName());
                element.setPrintName(table.getName());
            }
            element.saveEx();
        }
        column.setColumnName(element.getColumnName());
        column.setName(element.getName());
        column.setDescription(element.getDescription());
        column.setHelp(element.getHelp());
        column.setAD_Element_ID(element.getAD_Element_ID());
        //
        column.setIsMandatory("NO".equals(nullable));
        // Key
        if (columnName.equalsIgnoreCase(tableName + "_ID")) {
            column.setIsKey(true);
            column.setAD_Reference_ID(DisplayType.ID);
            column.setIsUpdateable(false);
        } else // bug [ 1637912 ] 
        if (columnName.toUpperCase().endsWith("_ACCT") && size == 10)
            column.setAD_Reference_ID(DisplayType.Account);
        else // Account
        if (columnName.equalsIgnoreCase("C_Location_ID"))
            column.setAD_Reference_ID(DisplayType.Location);
        else // Product Attribute
        if (columnName.equalsIgnoreCase("M_AttributeSetInstance_ID"))
            column.setAD_Reference_ID(DisplayType.PAttribute);
        else // SalesRep_ID (=User)
        if (columnName.equalsIgnoreCase("SalesRep_ID")) {
            column.setAD_Reference_ID(DisplayType.Table);
            column.setAD_Reference_Value_ID(190);
        } else // ID
        if (columnName.toUpperCase().endsWith("_ID"))
            column.setAD_Reference_ID(DisplayType.TableDir);
        else // Date
        if (dataType == Types.DATE || dataType == Types.TIME || dataType == Types.TIMESTAMP || // || columnName.toUpperCase().indexOf("DATE") != -1
        columnName.equalsIgnoreCase("Created") || columnName.equalsIgnoreCase("Updated"))
            column.setAD_Reference_ID(DisplayType.DateTime);
        else // CreatedBy/UpdatedBy (=User)
        if (columnName.equalsIgnoreCase("CreatedBy") || columnName.equalsIgnoreCase("UpdatedBy")) {
            column.setAD_Reference_ID(DisplayType.Table);
            column.setAD_Reference_Value_ID(110);
            column.setIsUpdateable(false);
        } else //	Entity Type
        if (columnName.equalsIgnoreCase("EntityType")) {
            column.setAD_Reference_ID(DisplayType.Table);
            column.setAD_Reference_Value_ID(389);
        } else // CLOB
        if (dataType == Types.CLOB)
            column.setAD_Reference_ID(DisplayType.TextLong);
        else // BLOB
        if (dataType == Types.BLOB)
            column.setAD_Reference_ID(DisplayType.Binary);
        else // Amount
        if (columnName.toUpperCase().indexOf("AMT") != -1)
            column.setAD_Reference_ID(DisplayType.Amount);
        else // Qty
        if (columnName.toUpperCase().indexOf("QTY") != -1)
            column.setAD_Reference_ID(DisplayType.Quantity);
        else // Boolean
        if (size == 1 && (columnName.toUpperCase().startsWith("IS") || dataType == Types.CHAR))
            column.setAD_Reference_ID(DisplayType.YesNo);
        else // List
        if (size < 4 && dataType == Types.CHAR)
            column.setAD_Reference_ID(DisplayType.List);
        else // Name, DocumentNo
        if (columnName.equalsIgnoreCase("Name") || columnName.equals("DocumentNo")) {
            column.setAD_Reference_ID(DisplayType.String);
            column.setIsIdentifier(true);
            column.setSeqNo(1);
        } else // String, Text
        if (dataType == Types.CHAR || dataType == Types.VARCHAR || typeName.startsWith("NVAR") || typeName.startsWith("NCHAR")) {
            if (//	MultiByte	
            typeName.startsWith("N"))
                size /= 2;
            if (size > 255)
                column.setAD_Reference_ID(DisplayType.Text);
            else
                column.setAD_Reference_ID(DisplayType.String);
        } else // Number
        if (dataType == Types.INTEGER || dataType == Types.SMALLINT || dataType == Types.DECIMAL || dataType == Types.NUMERIC) {
            if (size == 10)
                column.setAD_Reference_ID(DisplayType.Integer);
            else
                column.setAD_Reference_ID(DisplayType.Number);
        } else
            //	??
            column.setAD_Reference_ID(DisplayType.String);
        column.setFieldLength(size);
        if (column.isUpdateable() && (table.isView() || columnName.equalsIgnoreCase("AD_Client_ID") || columnName.equalsIgnoreCase("AD_Org_ID") || columnName.toUpperCase().startsWith("CREATED") || columnName.toUpperCase().equals("UPDATED")))
            column.setIsUpdateable(false);
        // Check if is a possible selection column
        if (MColumn.isSuggestSelectionColumn(column.getColumnName(), false))
            column.setIsSelectionColumn(true);
        //	Done
        if (column.save()) {
            addLog(0, null, null, table.getTableName() + "." + column.getColumnName());
            m_count++;
        }
    }
//	while columns
}
Also used : MColumn(org.compiere.model.MColumn) M_Element(org.compiere.model.M_Element)

Example 20 with MColumn

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

the class ExportFormatGenerator method createFormatLine.

private int createFormatLine(MEXPFormat format, MTable table, MColumn col, int position, boolean force) throws SQLException {
    MEXPFormatLine formatLine = null;
    String formatlinevalue = col.getColumnName();
    formatLine = MEXPFormatLine.getFormatLineByValue(getCtx(), formatlinevalue, format.getEXP_Format_ID(), get_TrxName());
    if (formatLine == null)
        formatLine = new MEXPFormatLine(getCtx(), 0, get_TrxName());
    formatLine.setAD_Org_ID(0);
    formatLine.setEXP_Format_ID(format.getEXP_Format_ID());
    formatLine.setValue(formatlinevalue);
    formatLine.setName(col.getName());
    formatLine.setDescription(col.getDescription());
    formatLine.setHelp(col.getHelp());
    formatLine.setPosition(position);
    formatLine.setIsMandatory(col.isMandatory());
    if (force || (col.isIdentifier() && !col.isKey())) {
        formatLine.setIsPartUniqueIndex(true);
        formatLine.setIsActive(true);
    } else {
        formatLine.setIsActive(false);
    }
    MTable tabledir = null;
    if (col.getColumnName().equals(parentTable + "_ID") && DisplayType.isID(col.getAD_Reference_ID())) {
        MEXPFormat referenceFormat = null;
        referenceFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), parentTable + "_Key", getAD_Client_ID(), version, get_TrxName());
        if (referenceFormat == null) {
            referenceFormat = new MEXPFormat(getCtx(), 0, get_TrxName());
        }
        referenceFormat.setAD_Org_ID(0);
        referenceFormat.setValue(parentTable + "_Key");
        referenceFormat.setName(parentTable + "_Key");
        referenceFormat.setAD_Table_ID(MTable.getTable_ID(parentTable));
        referenceFormat.setDescription(table.getDescription());
        referenceFormat.setHelp(table.getHelp());
        referenceFormat.saveEx();
        int AD_Column_ID = DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='DOCUMENTNO'", parentTable);
        if (AD_Column_ID > 0) {
            //used if the export format is a document like invoice, etc.
            createFormatLine(referenceFormat, table, new MColumn(getCtx(), AD_Column_ID, get_TrxName()), 10, true);
            AD_Column_ID = 0;
            AD_Column_ID = DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='C_DOCTYPE_ID'", parentTable);
            if (AD_Column_ID > 0)
                createFormatLine(referenceFormat, table, new MColumn(getCtx(), AD_Column_ID, get_TrxName()), 20, true);
            formatLine.setValue(parentTable + "_Key");
            formatLine.setName("Key DocumentNo_C_DocType");
            formatLine.setAD_Column_ID(col.getAD_Column_ID());
            formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat);
            formatLine.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID());
            formatLine.saveEx();
            if (parentTable != null) {
                if (col.isParent() && col.getColumnName().contains(parentTable)) {
                    int reference = ((MEXPFormat) exportFormats.get(formatValue)).getEXP_Format_ID();
                    MEXPFormatLine embededformatLine = new MEXPFormatLine(getCtx(), 0, get_TrxName());
                    embededformatLine.setAD_Org_ID(0);
                    embededformatLine.setValue(format.getValue() + "_Embedded");
                    embededformatLine.setName("Embedded " + format.getName());
                    embededformatLine.setEXP_EmbeddedFormat_ID(formatLine.getEXP_Format_ID());
                    embededformatLine.setEXP_Format_ID(reference);
                    embededformatLine.setType(MEXPFormatLine.TYPE_EmbeddedEXPFormat);
                    embededformatLine.setAD_Column_ID(col.getAD_Column_ID());
                    embededformatLine.saveEx();
                }
            }
            log.info("Export Format Line:" + formatLine.getName());
            return formatLine.getEXP_FormatLine_ID();
        } else {
            AD_Column_ID = DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='NAME'", parentTable);
            if (AD_Column_ID > 0) {
                createFormatLine(referenceFormat, table, new MColumn(getCtx(), AD_Column_ID, get_TrxName()), 10, true);
            } else {
                AD_Column_ID = DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='VALUE'", parentTable);
                if (AD_Column_ID > 0) {
                    createFormatLine(referenceFormat, table, new MColumn(getCtx(), AD_Column_ID, get_TrxName()), 10, true);
                } else {
                    throw new AdempiereException("Table without name or value column");
                }
            }
            formatLine.setValue(parentTable + "_Key");
            formatLine.setName("Key " + col.getColumnName());
            formatLine.setAD_Column_ID(col.getAD_Column_ID());
            formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat);
            formatLine.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID());
            formatLine.saveEx();
            return formatLine.getEXP_FormatLine_ID();
        }
    }
    if (DisplayType.isID(col.getAD_Reference_ID()) && col.getAD_Reference_Value_ID() > 0) {
        int AD_Table_ID = DB.getSQLValue(get_TrxName(), "SELECT rt.AD_Table_ID FROM AD_Reference r INNER JOIN AD_Ref_Table rt ON (r.AD_Reference_ID=rt.AD_Reference_ID)  WHERE r.AD_Reference_ID=?", col.getAD_Reference_Value_ID());
        if (AD_Table_ID > 0) {
            tabledir = MTable.get(getCtx(), AD_Table_ID);
            formatLine.setValue(col.getColumnName() + "_Reference");
            formatLine.setName("Referenced " + tabledir.getTableName());
            formatLine.setAD_Column_ID(col.getAD_Column_ID());
            String format_value = createFormat(tabledir);
            int embedded = ((MEXPFormat) exportFormats.get(format_value)).getEXP_Format_ID();
            formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat);
            formatLine.setEXP_EmbeddedFormat_ID(embedded);
            formatLine.saveEx();
            return formatLine.getEXP_FormatLine_ID();
        }
    }
    if (DisplayType.isID(col.getAD_Reference_ID()) && col.isKey() == false && DisplayType.ID != col.getAD_Reference_ID() && DisplayType.Image != col.getAD_Reference_ID()) {
        String tableName = col.getColumnName().substring(0, col.getColumnName().lastIndexOf("_ID"));
        log.info("Table Name:" + tableName);
        if (tableName == null) {
            log.info("Table Name: null");
            return 0;
        }
        tabledir = MTable.get(getCtx(), tableName);
        if (tabledir == null)
            return 0;
        //	throw new Exception ("Ilegal Table Name");
        formatLine.setValue(tabledir.getTableName() + "_Reference");
        formatLine.setName("Referenced " + tabledir.getTableName());
        //formatLine.setType(MEXPFormatLine.TYPE_XMLElement);
        if (tabledir != null) {
            String format_value = createFormat(tabledir);
            int embedded = ((MEXPFormat) exportFormats.get(format_value)).getEXP_Format_ID();
            formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat);
            formatLine.setEXP_EmbeddedFormat_ID(embedded);
        } else
            formatLine.setType(MEXPFormatLine.TYPE_XMLElement);
    }
    formatLine.setAD_Column_ID(col.getAD_Column_ID());
    formatLine.saveEx();
    log.info("Export Format Line:" + formatLine.getName());
    return formatLine.getEXP_FormatLine_ID();
}
Also used : MEXPFormat(org.compiere.model.MEXPFormat) MColumn(org.compiere.model.MColumn) MEXPFormatLine(org.compiere.model.MEXPFormatLine) MTable(org.compiere.model.MTable) AdempiereException(org.adempiere.exceptions.AdempiereException)

Aggregations

MColumn (org.compiere.model.MColumn)40 MTable (org.compiere.model.MTable)15 SQLException (java.sql.SQLException)11 BigDecimal (java.math.BigDecimal)9 AdempiereException (org.adempiere.exceptions.AdempiereException)7 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 Query (org.compiere.model.Query)6 MEXPFormat (org.compiere.model.MEXPFormat)5 Timestamp (java.sql.Timestamp)4 ArrayList (java.util.ArrayList)4 Vector (java.util.Vector)4 MEXPFormatLine (org.compiere.model.MEXPFormatLine)4 MLookup (org.compiere.model.MLookup)4 MUser (org.compiere.model.MUser)4 DBException (org.adempiere.exceptions.DBException)3 MField (org.compiere.model.MField)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2