Search in sources :

Example 21 with MColumn

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

the class CreateViewColumn method doIt.

/**
	 * Process - Generate Export Format
	 * 
	 * @return info
	 */
@SuppressWarnings("unchecked")
protected String doIt() throws Exception {
    MViewDefinition join = new MViewDefinition(getCtx(), p_Record_ID, get_TrxName());
    for (MColumn attr : join.getEntityAttributes()) {
        MViewColumn column = MViewColumn.get(join, attr);
        if (column != null)
            continue;
        column = new MViewColumn(attr);
        column.setAD_View_Definition_ID(join.getAD_View_Definition_ID());
        column.setColumnSQL(join.getTableAlias() + "." + attr.getColumnName());
        column.setColumnName(join.getTableAlias().toUpperCase() + "_" + attr.getColumnName());
        column.setEntityType(join.getAD_View().getEntityType());
        column.setAD_View_ID(join.getAD_View_ID());
        column.saveEx();
        addLog(attr.getColumnName());
    }
    return "@Ok@";
}
Also used : MColumn(org.compiere.model.MColumn) MViewDefinition(org.adempiere.model.MViewDefinition) MViewColumn(org.adempiere.model.MViewColumn)

Example 22 with MColumn

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

the class CreateAdempiere method createTable.

//	createTables
/**
	 * 	Create Table
	 *	@param mTable table model
	 *	@param md meta data
	 *	@return true if created
	 */
private boolean createTable(MTable mTable, DatabaseMetaData md) {
    String tableName = mTable.getTableName();
    log.info(tableName);
    String catalog = m_dbSource.getCatalog();
    String schema = m_dbSource.getSchema();
    String table = tableName.toUpperCase();
    //	
    MColumn[] columns = mTable.getColumns(false);
    StringBuffer sb = new StringBuffer("CREATE TABLE ");
    sb.append(tableName).append(" (");
    try {
        //	Columns
        boolean first = true;
        ResultSet sourceColumns = md.getColumns(catalog, schema, table, null);
        while (sourceColumns.next()) {
            sb.append(first ? "" : ", ");
            first = false;
            //	Case sensitive Column Name
            MColumn column = null;
            String columnName = sourceColumns.getString("COLUMN_NAME");
            for (int i = 0; i < columns.length; i++) {
                String cn = columns[i].getColumnName();
                if (cn.equalsIgnoreCase(columnName)) {
                    columnName = cn;
                    column = columns[i];
                    break;
                }
            }
            sb.append(columnName).append(" ");
            //	Data Type & Precision
            //	sql.Types
            int sqlType = sourceColumns.getInt("DATA_TYPE");
            //	DB Dependent
            String typeName = sourceColumns.getString("TYPE_NAME");
            int size = sourceColumns.getInt("COLUMN_SIZE");
            int decDigits = sourceColumns.getInt("DECIMAL_DIGITS");
            if (sourceColumns.wasNull())
                decDigits = -1;
            if (typeName.equals("NUMBER")) {
                /** Oracle Style	*
					if (decDigits == -1)
						sb.append(typeName);
					else
						sb.append(typeName).append("(")
							.append(size).append(",").append(decDigits).append(")");
					/** Other DBs		*/
                int dt = column.getAD_Reference_ID();
                if (DisplayType.isID(dt))
                    sb.append("INTEGER");
                else {
                    int scale = DisplayType.getDefaultPrecision(dt);
                    sb.append("DECIMAL(").append(18 + scale).append(",").append(scale).append(")");
                }
            } else if (typeName.equals("DATE") || typeName.equals("BLOB") || typeName.equals("CLOB"))
                sb.append(typeName);
            else if (typeName.equals("CHAR") || typeName.startsWith("VARCHAR"))
                sb.append(typeName).append("(").append(size).append(")");
            else if (typeName.startsWith("NCHAR") || typeName.startsWith("NVAR"))
                sb.append(typeName).append("(").append(size / 2).append(")");
            else if (typeName.startsWith("TIMESTAMP"))
                sb.append("DATE");
            else
                log.severe("Do not support data type " + typeName);
            //	Default
            String def = sourceColumns.getString("COLUMN_DEF");
            if (def != null) {
                //jz: replace '' to \', otherwise exception
                def.replaceAll("''", "\\'");
                sb.append(" DEFAULT ").append(def);
            }
            //	Null
            if (sourceColumns.getInt("NULLABLE") == DatabaseMetaData.columnNoNulls)
                sb.append(" NOT NULL");
            else
                sb.append(" NULL");
        //	Check Contraints
        }
        //	for all columns
        sourceColumns.close();
        //	Primary Key
        ResultSet sourcePK = md.getPrimaryKeys(catalog, schema, table);
        //	TABLE_CAT=null, TABLE_SCHEM=REFERENCE, TABLE_NAME=A_ASSET, COLUMN_NAME=A_ASSET_ID, KEY_SEQ=1, PK_NAME=A_ASSET_KEY
        first = true;
        boolean hasPK = false;
        while (sourcePK.next()) {
            hasPK = true;
            if (first)
                sb.append(", CONSTRAINT ").append(sourcePK.getString("PK_NAME")).append(" PRIMARY KEY (");
            else
                sb.append(",");
            first = false;
            String columnName = sourcePK.getString("COLUMN_NAME");
            sb.append(checkColumnName(columnName));
        }
        if (//	close constraint
        hasPK)
            // USING INDEX TABLESPACE INDX
            sb.append(")");
        sourcePK.close();
        //
        //	close create table
        sb.append(")");
    } catch (Exception ex) {
        log.log(Level.SEVERE, "createTable", ex);
        return false;
    }
    //	Execute Create Table
    if (!executeCommands(new String[] { sb.toString() }, m_conn, false, true))
        // continue
        return true;
    //	Create Inexes
    createTableIndexes(mTable, md);
    return createTableData(mTable);
}
Also used : MColumn(org.compiere.model.MColumn) ResultSet(java.sql.ResultSet) DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException)

Example 23 with MColumn

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

the class ColumnElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    PackIn packIn = (PackIn) ctx.get("PackInProcess");
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("ColumnName"));
    int success = 0;
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        if (element.parent != null && element.parent.getElementValue().equals("table") && element.parent.defer) {
            element.defer = true;
            return;
        }
        String columnName = atts.getValue("ColumnName");
        String tableName = atts.getValue("ADTableNameID");
        int tableid = 0;
        if (element.parent != null && element.parent.getElementValue().equals("table") && element.parent.recordId > 0) {
            tableid = element.parent.recordId;
        } else {
            tableid = packIn.getTableId(tableName);
        }
        if (tableid <= 0) {
            tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
            if (tableid > 0)
                packIn.addTable(tableName, tableid);
        }
        int id = packIn.getColumnId(tableName, columnName);
        if (id <= 0) {
            id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid);
            if (id > 0) {
                packIn.addColumn(tableName, columnName, id);
            }
        }
        MColumn m_Column = new MColumn(ctx, id, getTrxName(ctx));
        if (id <= 0 && atts.getValue("AD_Column_ID") != null && Integer.parseInt(atts.getValue("AD_Column_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_Column.setAD_Column_ID(Integer.parseInt(atts.getValue("AD_Column_ID")));
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_Column", m_Column);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_Column.setColumnName(columnName);
        // Process
        String processName = atts.getValue("ADProcessNameID");
        int AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Value", processName);
        if (AD_Process_ID <= 0) /** TODO PackOut version check 005 */
        {
            AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Name", processName);
        }
        m_Column.setAD_Process_ID(AD_Process_ID);
        //
        String Name = atts.getValue("ADReferenceNameID");
        int referenceId = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
        m_Column.setAD_Reference_ID(referenceId);
        // log.info("Column ID ->"+id);
        Name = atts.getValue("ADTableNameID");
        id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name);
        m_Column.setAD_Table_ID(id);
        Name = atts.getValue("ADValRuleNameID");
        id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
        m_Column.setAD_Val_Rule_ID(id);
        //Validate that reference id is for Table or List
        if (DisplayType.Table == referenceId || DisplayType.List == referenceId || DisplayType.Search == referenceId) {
            Name = atts.getValue("ADReferenceNameValueID");
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
            m_Column.setAD_Reference_Value_ID(id);
        }
        m_Column.setCallout(getStringValue(atts, "Callout"));
        m_Column.setColumnSQL(getStringValue(atts, "ColumnSQL"));
        m_Column.setColumnName(atts.getValue("ColumnName"));
        m_Column.setDefaultValue(getStringValue(atts, "DefaultValue"));
        m_Column.setDescription(getStringValue(atts, "Description"));
        m_Column.setEntityType(atts.getValue("EntityType"));
        if (Integer.parseInt(atts.getValue("FieldLength")) > 0)
            m_Column.setFieldLength(Integer.parseInt(atts.getValue("FieldLength")));
        m_Column.setHelp(getStringValue(atts, "Help"));
        m_Column.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_Column.setIsAlwaysUpdateable((Boolean.valueOf(atts.getValue("isAlwaysUpdateable")).booleanValue()));
        // m_Column.setIsEncrypted(atts.getValue("isEncrypted"));
        m_Column.setIsIdentifier((Boolean.valueOf(atts.getValue("isIdentifier")).booleanValue()));
        m_Column.setIsKey((Boolean.valueOf(atts.getValue("isKey")).booleanValue()));
        m_Column.setIsMandatory((Boolean.valueOf(atts.getValue("isMandatory")).booleanValue()));
        m_Column.setIsParent((Boolean.valueOf(atts.getValue("isParent")).booleanValue()));
        m_Column.setIsSelectionColumn((Boolean.valueOf(atts.getValue("isSelectionColumn")).booleanValue()));
        m_Column.setIsSyncDatabase(atts.getValue("getIsSyncDatabase"));
        m_Column.setIsTranslated((Boolean.valueOf(atts.getValue("isTranslated")).booleanValue()));
        m_Column.setIsUpdateable((Boolean.valueOf(atts.getValue("isUpdateable")).booleanValue()));
        m_Column.setName(atts.getValue("Name"));
        m_Column.setReadOnlyLogic(getStringValue(atts, "ReadOnlyLogic"));
        if (Integer.parseInt(atts.getValue("SeqNo")) > 0)
            m_Column.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
        m_Column.setVFormat(getStringValue(atts, "VFormat"));
        if (getStringValue(atts, "ValueMax") != null)
            m_Column.setValueMax(atts.getValue("ValueMax"));
        if (getStringValue(atts, "ValueMin") != null)
            m_Column.setValueMin(atts.getValue("ValueMin"));
        if (getStringValue(atts, "Version") != null)
            m_Column.setVersion(new BigDecimal(atts.getValue("Version")));
        m_Column.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
        // Setup Element.
        id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", m_Column.getColumnName());
        X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
        String Object_Status_col = Object_Status;
        if (adElement.getAD_Element_ID() == 0) {
            // Object_Status = "New";
            adElement.setColumnName(m_Column.getColumnName());
            adElement.setEntityType(m_Column.getEntityType());
            adElement.setPrintName(m_Column.getColumnName());
            adElement.setName(m_Column.getColumnName());
            if (adElement.save(getTrxName(ctx)) == true) {
                record_log(ctx, 1, m_Column.getName(), "Element", adElement.getAD_Element_ID(), AD_Backup_ID, "New", "AD_Element", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
            } else {
                record_log(ctx, 0, m_Column.getName(), "Element", adElement.getAD_Element_ID(), AD_Backup_ID, "New", "AD_Element", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
            }
        }
        Object_Status = Object_Status_col;
        m_Column.setAD_Element_ID(adElement.getAD_Element_ID());
        boolean recreateColumn = (m_Column.is_new() || m_Column.is_ValueChanged("AD_Reference_ID") || m_Column.is_ValueChanged("FieldLength") || m_Column.is_ValueChanged("ColumnName") || m_Column.is_ValueChanged("IsMandatory"));
        //ignore fieldlength change for clob and lob
        if (!m_Column.is_ValueChanged("AD_Reference_ID") && m_Column.is_ValueChanged("FieldLength")) {
            if (DisplayType.isLOB(m_Column.getAD_Reference_ID())) {
                recreateColumn = false;
            }
        }
        // nulls
        if (!recreateColumn) {
            String oldDefault = (String) m_Column.get_ValueOld("DefaultValue");
            String newDefault = m_Column.getDefaultValue();
            if (oldDefault != null && oldDefault.length() == 0)
                oldDefault = null;
            if (newDefault != null && newDefault.length() == 0)
                newDefault = null;
            if ((oldDefault == null && newDefault != null) || (oldDefault != null && newDefault == null)) {
                recreateColumn = true;
            } else if (oldDefault != null && newDefault != null) {
                if (!oldDefault.equals(newDefault))
                    recreateColumn = true;
            }
        }
        // Don't create database column for virtual columns
        boolean syncDatabase = "Y".equalsIgnoreCase(atts.getValue("getIsSyncDatabase"));
        if (recreateColumn) {
            if (m_Column.isVirtualColumn() || !syncDatabase)
                recreateColumn = false;
        }
        if (m_Column.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_Column.getName(), "Column", m_Column.get_ID(), AD_Backup_ID, Object_Status, "AD_Column", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Column"));
            element.recordId = m_Column.getAD_Column_ID();
        } else {
            record_log(ctx, 0, m_Column.getName(), "Column", m_Column.get_ID(), AD_Backup_ID, Object_Status, "AD_Column", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Column"));
            throw new POSaveFailedException("Failed to import column.");
        }
        if (recreateColumn || syncDatabase) {
            MTable table = new MTable(ctx, m_Column.getAD_Table_ID(), getTrxName(ctx));
            if (!table.isView() && !m_Column.isVirtualColumn()) {
                success = createColumn(ctx, table, m_Column, recreateColumn);
                if (success == 1) {
                    record_log(ctx, 1, m_Column.getColumnName(), "dbColumn", m_Column.get_ID(), 0, Object_Status, atts.getValue("ADTableNameID").toUpperCase(), get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase()));
                } else {
                    record_log(ctx, 0, m_Column.getColumnName(), "dbColumn", m_Column.get_ID(), 0, Object_Status, atts.getValue("ADTableNameID").toUpperCase(), get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase()));
                    throw new DatabaseAccessException("Failed to create column or related constraint for " + m_Column.getColumnName());
                }
            }
        }
    } else {
        element.skip = true;
    }
}
Also used : MColumn(org.compiere.model.MColumn) MTable(org.compiere.model.MTable) PackIn(org.adempiere.pipo.PackIn) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) X_AD_Element(org.compiere.model.X_AD_Element) BigDecimal(java.math.BigDecimal) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException)

Example 24 with MColumn

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

the class CreateAdempiere method createTableDataRow.

//	createTableData
/**
	 * 	Create Table Data Row
	 *	@param rs result set
	 *	@param mTable table
	 *	@return true if created
	 */
private boolean createTableDataRow(ResultSet rs, MTable mTable) {
    StringBuffer insert = new StringBuffer("INSERT INTO ").append(mTable.getTableName()).append(" (");
    StringBuffer values = new StringBuffer();
    //
    MColumn[] columns = mTable.getColumns(false);
    for (int i = 0; i < columns.length; i++) {
        if (i != 0) {
            insert.append(",");
            values.append(",");
        }
        MColumn column = columns[i];
        String columnName = column.getColumnName();
        insert.append(columnName);
        //
        int dt = column.getAD_Reference_ID();
        try {
            Object value = rs.getObject(columnName);
            if (rs.wasNull()) {
                values.append("NULL");
            } else if (// Record_ID, C_ProjectType defined as Button
            columnName.endsWith("_ID") || DisplayType.isNumeric(dt) || (DisplayType.isID(dt) && !columnName.equals("AD_Language"))) {
                BigDecimal bd = rs.getBigDecimal(columnName);
                String s = m_dbTarget.TO_NUMBER(bd, dt);
                values.append(s);
            } else if (DisplayType.isDate(dt)) {
                Timestamp ts = rs.getTimestamp(columnName);
                String tsString = m_dbTarget.TO_DATE(ts, dt == DisplayType.Date);
                values.append(tsString);
            } else if (DisplayType.isLOB(dt)) {
                // ignored
                values.append("NULL");
            } else if (DisplayType.isText(dt) || dt == DisplayType.YesNo || dt == DisplayType.List || dt == DisplayType.Button || columnName.equals("AD_Language")) {
                String s = rs.getString(columnName);
                values.append(DB.TO_STRING(s));
            } else {
                log.warning("Unknown DisplayType=" + dt + " - " + value + " [" + value.getClass().getName() + "]");
                values.append("NuLl");
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, columnName, e);
        }
    }
    //	for all columns
    //
    insert.append(") VALUES (").append(values).append(")");
    return executeCommands(new String[] { insert.toString() }, m_conn, false, //	do not convert as text is converted
    false);
}
Also used : MColumn(org.compiere.model.MColumn) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException)

Example 25 with MColumn

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

the class Export method generateExportFormat.

/*
	 * Trifon Generate Export Format process; RESULT = 
	 * <C_Invoice>
	 *   <DocumentNo>101</DocumentNo>
	 * </C_Invoice>
	 */
private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, ResultSet rs, PO masterPO, int masterID, HashMap<String, Integer> variableMap) throws SQLException, Exception {
    Collection<MEXPFormatLine> formatLines = exportFormat.getFormatLines();
    @SuppressWarnings("unused") boolean elementHasValue = false;
    for (MEXPFormatLine formatLine : formatLines) {
        if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLElement)) {
            // process single XML Attribute
            // Create new element
            Element newElement = outDocument.createElement(formatLine.getValue());
            if (formatLine.getAD_Column_ID() == 0) {
                throw new Exception(Msg.getMsg(getCtx(), "EXPColumnMandatory"));
            }
            MColumn column = MColumn.get(getCtx(), formatLine.getAD_Column_ID());
            if (column == null) {
                throw new Exception(Msg.getMsg(getCtx(), "EXPColumnMandatory"));
            }
            if (column.isVirtualColumn()) {
                log.info("This is Virtual Column!");
            } else {
            }
            //log.info("["+column.getColumnName()+"]");
            Object value = rs.getObject(column.getColumnName());
            String valueString = null;
            if (value != null) {
                valueString = value.toString();
            } else {
                if (formatLine.isMandatory()) {
                    throw new Exception(Msg.getMsg(getCtx(), "EXPFieldMandatory"));
                }
            }
            /*				if (column.getAD_Reference_ID() == DisplayType.Date) {
					if (valueString != null) {
						if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
							m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
							//Date date = m_customDateFormat.parse ( valueString );
							valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
						} else {
							valueString = m_dateFormat.format (Timestamp.valueOf (valueString));
						}
								
					}
				} else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
					if (valueString != null) {
						if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
							m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
							//Date date = m_customDateFormat.parse ( valueString );
							valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
						} else {
							valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString));
						}
					}
				}*/
            log.info("EXP Field - column=[" + column.getColumnName() + "]; value=" + value);
            if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
                Text newText = outDocument.createTextNode(valueString);
                newElement.appendChild(newText);
                rootElement.appendChild(newElement);
                elementHasValue = true;
            //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable 
            //increaseVariable(variableMap, TOTAL_SEGMENTS);
            } else {
            // Empty field.
            }
        } else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute)) {
            /*				// Create new element
				Element newElement = outDocument.createElement(formatLines[i].getValue());
				if (hasContent) {
					rootElement.appendChild(newElement);
				}*/
            if (formatLine.getAD_Column_ID() == 0) {
                throw new Exception(Msg.getMsg(getCtx(), "EXPColumnMandatory"));
            }
            MColumn column = MColumn.get(getCtx(), formatLine.getAD_Column_ID());
            if (column == null) {
                throw new Exception(Msg.getMsg(getCtx(), "EXPColumnMandatory"));
            }
            if (column.isVirtualColumn()) {
                log.info("This is Virtual Column!");
            } else {
            }
            //log.info("["+column.getColumnName()+"]");
            Object value = rs.getObject(column.getColumnName());
            String valueString = null;
            if (value != null) {
                valueString = value.toString();
            } else {
                if (formatLine.isMandatory()) {
                    throw new Exception(Msg.getMsg(getCtx(), "EXPFieldMandatory"));
                }
            }
            /*				if (column.getAD_Reference_ID() == DisplayType.Date) {
					if (valueString != null) {
						if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
							m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
							//Date date = m_customDateFormat.parse ( valueString );
							valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
						} else {
							valueString = m_dateFormat.format (Timestamp.valueOf (valueString));
						}
								
					}
				} else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
					if (valueString != null) {
						if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
							m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
							//Date date = m_customDateFormat.parse ( valueString );
							valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
						} else {
							valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString));
						}
					}
				}*/
            log.info("EXP Field - column=[" + column.getColumnName() + "]; value=" + value);
            if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
                rootElement.setAttribute(formatLine.getValue(), valueString);
                elementHasValue = true;
            //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable 
            //increaseVariable(variableMap, TOTAL_SEGMENTS);
            } else {
            // Empty field.
            }
        } else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat)) {
            // process Embedded Export Format
            int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID();
            MEXPFormat embeddedFormat = new MEXPFormat(getCtx(), embeddedFormat_ID, get_TrxName());
            MTable tableEmbedded = MTable.get(getCtx(), embeddedFormat.getAD_Table_ID());
            log.info("Table Embedded = " + tableEmbedded);
            StringBuffer sql = new StringBuffer("SELECT * ").append("FROM ").append(tableEmbedded.getTableName()).append(" ").append("WHERE ").append(masterPO.get_KeyColumns()[0]).append("=?");
            if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) {
                sql.append(" AND ").append(embeddedFormat.getWhereClause());
            }
            ResultSet rsEmbedded = null;
            PreparedStatement pstmt = null;
            try {
                pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
                pstmt.setInt(1, masterID);
                rsEmbedded = pstmt.executeQuery();
                while (rsEmbedded.next()) {
                    //System.out.println("Trifon - tableEmbedded.getTableName()_ID = "+ tableEmbedded.getTableName() + "_ID");
                    int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID");
                    PO poEmbedded = tableEmbedded.getPO(embeddedID, get_TrxName());
                    Element embeddedElement = outDocument.createElement(formatLine.getValue());
                    embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
                    generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap);
                    rootElement.appendChild(embeddedElement);
                }
            } finally {
                try {
                    if (rsEmbedded != null)
                        rsEmbedded.close();
                    if (pstmt != null)
                        pstmt.close();
                } catch (SQLException ex) {
                }
                rsEmbedded = null;
                pstmt = null;
            }
        } else {
            throw new Exception(Msg.getMsg(getCtx(), "EXPUnknownLineType"));
        }
    }
}
Also used : MColumn(org.compiere.model.MColumn) MEXPFormat(org.compiere.model.MEXPFormat) SQLException(java.sql.SQLException) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MEXPFormatLine(org.compiere.model.MEXPFormatLine) MTable(org.compiere.model.MTable) ResultSet(java.sql.ResultSet) PO(org.compiere.model.PO)

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