Search in sources :

Example 1 with X_AD_Element

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

the class ProcessParaElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        if (element.parent != null && element.parent.getElementValue().equals("process") && element.parent.defer) {
            element.defer = true;
            return;
        }
        String name = atts.getValue("Name");
        int id = 0;
        int masterId = 0;
        String processValue = "";
        if (element.parent != null && element.parent.getElementValue().equals("process") && element.parent.recordId > 0) {
            masterId = element.parent.recordId;
        } else {
            processValue = atts.getValue("ADProcessValueID");
            if (processValue != null && processValue.trim().length() > 0) {
                masterId = get_IDWithColumn(ctx, "AD_Process", "Value", processValue);
            } else {
                //for backward compatibility
                processValue = atts.getValue("ADProcessNameID");
                masterId = get_IDWithColumn(ctx, "AD_Process", "Name", processValue);
            }
        }
        if (masterId <= 0) {
            element.defer = true;
            element.unresolved = "AD_Process: " + processValue;
            return;
        }
        id = get_IDWithMasterAndColumn(ctx, "AD_Process_Para", "Name", name, "AD_Process", masterId);
        X_AD_Process_Para m_Process_para = new X_AD_Process_Para(ctx, id, getTrxName(ctx));
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id <= 0 && atts.getValue("AD_Process_Para_ID") != null && Integer.parseInt(atts.getValue("AD_Process_Para_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_Process_para.setAD_Process_Para_ID(Integer.parseInt(atts.getValue("AD_Process_Para_ID")));
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_Process_Para", m_Process_para);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_Process_para.setName(atts.getValue("Name"));
        m_Process_para.setAD_Process_ID(masterId);
        m_Process_para.setColumnName(atts.getValue("ColumnName"));
        m_Process_para.setEntityType(atts.getValue("EntityType"));
        name = atts.getValue("ADElementNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", name);
            if (id <= 0) /** Check Packout version - 005 */
            {
                id = get_IDWithColumn(ctx, "AD_Element", "Name", name);
            }
            // Setup Element
            X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
            if (adElement.getAD_Element_ID() == 0) {
                String columnName = m_Process_para.getColumnName();
                id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", columnName);
                if (id > 0) {
                    adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
                } else {
                    adElement.setColumnName(columnName);
                    adElement.setEntityType(m_Process_para.getEntityType());
                    adElement.setPrintName(name);
                    adElement.setName(m_Process_para.getName());
                    if (adElement.save(getTrxName(ctx)) == true) {
                        record_log(ctx, 1, m_Process_para.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_Process_para.getName(), "Element", adElement.getAD_Element_ID(), AD_Backup_ID, "New", "AD_Element", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
                    }
                }
            }
            m_Process_para.setAD_Element_ID(adElement.getAD_Element_ID());
        }
        name = atts.getValue("ADReferenceNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", name);
            if (id <= 0) {
                element.defer = true;
                element.unresolved = "AD_Reference: " + name;
                return;
            }
            m_Process_para.setAD_Reference_ID(id);
        }
        name = atts.getValue("ADReferenceValueNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", name);
            if (id <= 0) {
                element.defer = true;
                element.unresolved = "AD_Reference: " + name;
                return;
            }
            m_Process_para.setAD_Reference_Value_ID(id);
        }
        name = atts.getValue("ADValRuleNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", name);
            if (id <= 0) {
                element.defer = true;
                element.unresolved = "AD_Val_Rule: " + name;
                return;
            }
            m_Process_para.setAD_Val_Rule_ID(id);
        }
        m_Process_para.setDefaultValue(getStringValue(atts, "DefaultValue"));
        m_Process_para.setDefaultValue2(getStringValue(atts, "DefaultValue2"));
        m_Process_para.setDescription(getStringValue(atts, "Description"));
        m_Process_para.setHelp(getStringValue(atts, "Help"));
        m_Process_para.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_Process_para.setReadOnlyLogic(getStringValue(atts, "ReadOnlyLogic"));
        m_Process_para.setDisplayLogic(getStringValue(atts, "DisplayLogic"));
        m_Process_para.setVFormat(getStringValue(atts, "VFormat"));
        m_Process_para.setValueMax(getStringValue(atts, "ValueMax"));
        m_Process_para.setValueMin(getStringValue(atts, "ValueMin"));
        m_Process_para.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
        m_Process_para.setFieldLength(Integer.parseInt(atts.getValue("FieldLength")));
        m_Process_para.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("isCentrallyMaintained")).booleanValue());
        m_Process_para.setIsMandatory(Boolean.valueOf(atts.getValue("isMandatory")).booleanValue());
        m_Process_para.setIsRange(Boolean.valueOf(atts.getValue("isRange")).booleanValue());
        if (m_Process_para.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_Process_para.getName(), "Process_para", m_Process_para.get_ID(), AD_Backup_ID, Object_Status, "AD_Process_para", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Process_para"));
        } else {
            record_log(ctx, 0, m_Process_para.getName(), "Process_para", m_Process_para.get_ID(), AD_Backup_ID, Object_Status, "AD_Process_para", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Process_para"));
            throw new POSaveFailedException("ProcessPara");
        }
    } else {
        element.skip = true;
    }
}
Also used : X_AD_Process_Para(org.compiere.model.X_AD_Process_Para) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) X_AD_Element(org.compiere.model.X_AD_Element)

Example 2 with X_AD_Element

use of org.compiere.model.X_AD_Element 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 3 with X_AD_Element

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

the class AdElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int adElement_id = Env.getContextAsInt(ctx, X_AD_Element.COLUMNNAME_AD_Element_ID);
    if (processedElements.contains(adElement_id))
        return;
    processedElements.add(adElement_id);
    X_AD_Element m_AdElement = new X_AD_Element(ctx, adElement_id, null);
    AttributesImpl atts = new AttributesImpl();
    createAdElementBinding(atts, m_AdElement);
    document.startElement("", "", "element", atts);
    PackOut packOut = (PackOut) ctx.get("PackOutProcess");
    packOut.createTranslations(X_AD_Element.Table_Name, m_AdElement.get_ID(), document);
    document.endElement("", "", "element");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) PackOut(org.adempiere.pipo.PackOut) X_AD_Element(org.compiere.model.X_AD_Element)

Example 4 with X_AD_Element

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

the class AdElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    int AD_Backup_ID = -1;
    String Object_Status = null;
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("ColumnName"));
    String entitytype = atts.getValue("EntityType");
    String ColumnName = atts.getValue("ColumnName");
    if (isProcessElement(ctx, entitytype)) {
        int id = get_IDWithColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName);
        X_AD_Element m_AdElement = new X_AD_Element(ctx, id, getTrxName(ctx));
        if (id <= 0 && atts.getValue("AD_Element_ID") != null && Integer.parseInt(atts.getValue("AD_Element_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_AdElement.setAD_Element_ID(Integer.parseInt(atts.getValue("AD_Element_ID")));
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, AD_ELEMENT, m_AdElement);
            Object_Status = "Update";
            if (processedElements.contains(id)) {
                element.skip = true;
                return;
            }
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        PoFiller pf = new PoFiller(m_AdElement, atts);
        pf.setBoolean("IsActive");
        pf.setString(X_AD_Element.COLUMNNAME_ColumnName);
        pf.setString(X_AD_Element.COLUMNNAME_Description);
        pf.setString(X_AD_Element.COLUMNNAME_EntityType);
        pf.setString(X_AD_Element.COLUMNNAME_Help);
        pf.setString(X_AD_Element.COLUMNNAME_Name);
        pf.setString(X_AD_Element.COLUMNNAME_PrintName);
        pf.setString(X_AD_Element.COLUMNNAME_PO_Description);
        pf.setString(X_AD_Element.COLUMNNAME_PO_Name);
        pf.setString(X_AD_Element.COLUMNNAME_PO_Help);
        pf.setString(X_AD_Element.COLUMNNAME_PO_PrintName);
        String Name = atts.getValue("ADReferenceNameID");
        id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
        m_AdElement.setAD_Reference_ID(id);
        Name = atts.getValue("ADReferenceNameValueID");
        id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
        m_AdElement.setAD_Reference_Value_ID(id);
        if (m_AdElement.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_AdElement.getName(), "Element", m_AdElement.get_ID(), AD_Backup_ID, Object_Status, AD_ELEMENT, get_IDWithColumn(ctx, "AD_Table", "TableName", AD_ELEMENT));
            element.recordId = m_AdElement.getAD_Element_ID();
            processedElements.add(m_AdElement.getAD_Element_ID());
        } else {
            record_log(ctx, 0, m_AdElement.getName(), "Element", m_AdElement.get_ID(), AD_Backup_ID, Object_Status, AD_ELEMENT, get_IDWithColumn(ctx, "AD_Table", "TableName", AD_ELEMENT));
            throw new POSaveFailedException("Reference");
        }
    } else {
        element.skip = true;
    }
}
Also used : PoFiller(org.adempiere.pipo.PoFiller) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) X_AD_Element(org.compiere.model.X_AD_Element)

Example 5 with X_AD_Element

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

the class BrowseFieldElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        if (element.parent != null && element.parent.getElementValue().equals("browse") && element.parent.defer) {
            element.defer = true;
            return;
        }
        String browsename = atts.getValue("ADBrowseNameID");
        String colviewname = atts.getValue("ADViewColumnNameID");
        String viewName = atts.getValue("ADViewNameID");
        int viewid = get_IDWithColumn(ctx, "AD_View", "Name", viewName);
        if (viewid <= 0) {
            element.defer = true;
            return;
        }
        int viewcolumnid = get_IDWithMasterAndColumn(ctx, "AD_View_Column", "ColumnName", colviewname, "AD_View", viewid);
        if (viewcolumnid <= 0) {
            element.defer = true;
            return;
        }
        int browseid = 0;
        if (element.parent != null && element.parent.getElementValue().equals("browse") && element.parent.recordId > 0) {
            browseid = element.parent.recordId;
        } else {
            StringBuffer sqlB = new StringBuffer("SELECT AD_Browse_ID from AD_Browse WHERE AD_Browse_ID = " + browseid).append(" and Name = '" + browsename + "'").append(" and AD_View_ID = ?");
            browseid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), viewid);
            if (element.parent != null && element.parent.getElementValue().equals("browse") && browseid > 0) {
                element.parent.recordId = browseid;
            }
        }
        if (browseid > 0) {
            StringBuffer sqlB = new StringBuffer("SELECT AD_Browse_Field_ID from AD_Browse_Field where AD_View_Column_ID = ").append(viewcolumnid).append(" and AD_Browse_ID = ?");
            int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), browseid);
            final MBrowseField m_BrowseField = new MBrowseField(ctx, id, getTrxName(ctx));
            if (id <= 0 && atts.getValue("AD_Browse_Field_ID") != null && Integer.parseInt(atts.getValue("AD_Browse_Field_ID")) <= PackOut.MAX_OFFICIAL_ID)
                m_BrowseField.setAD_Browse_Field_ID(Integer.parseInt(atts.getValue("AD_Browse_Field_ID")));
            int AD_Backup_ID = -1;
            String Object_Status = null;
            if (id > 0) {
                AD_Backup_ID = copyRecord(ctx, "AD_Browse_Field", m_BrowseField);
                Object_Status = "Update";
            } else {
                Object_Status = "New";
                AD_Backup_ID = 0;
            }
            m_BrowseField.setName(atts.getValue("Name"));
            m_BrowseField.setAD_View_Column_ID(viewcolumnid);
            m_BrowseField.setAD_Browse_ID(browseid);
            m_BrowseField.setEntityType(atts.getValue("EntityType"));
            m_BrowseField.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("isCentrallyMaintained")).booleanValue());
            m_BrowseField.setIsMandatory(Boolean.valueOf(atts.getValue("isMandatory")).booleanValue());
            m_BrowseField.setIsDisplayed(Boolean.valueOf(atts.getValue("Displayed")).booleanValue());
            m_BrowseField.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
            m_BrowseField.setDefaultValue(atts.getValue("DefaultValue"));
            m_BrowseField.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
            m_BrowseField.setDefaultValue2(atts.getValue("DefaultValue2"));
            m_BrowseField.setReadOnlyLogic(atts.getValue("ReadOnlyLogic"));
            m_BrowseField.setDisplayLogic(atts.getValue("DisplayLogic"));
            m_BrowseField.setVFormat(atts.getValue("VFormat"));
            m_BrowseField.setFieldLength(Integer.parseInt(atts.getValue("FieldLength")));
            m_BrowseField.setValueMin(atts.getValue("ValueMin"));
            m_BrowseField.setValueMin(atts.getValue("ValueMax"));
            String Name = atts.getValue("ADValRuleNameID");
            id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
            m_BrowseField.setAD_Val_Rule_ID(id);
            m_BrowseField.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
            m_BrowseField.setSeqNoGrid(Integer.parseInt(atts.getValue("SeqNoGrid")));
            //	Is Information Only #556
            m_BrowseField.setIsInfoOnly(Boolean.valueOf(atts.getValue("IsInfoOnly")).booleanValue());
            m_BrowseField.setSortNo(Integer.parseInt(atts.getValue("SortNo")));
            m_BrowseField.setIsOrderBy(Boolean.valueOf(atts.getValue("IsOrderBy")).booleanValue());
            m_BrowseField.setDescription(getStringValue(atts, "Description"));
            m_BrowseField.setHelp(getStringValue(atts, "Help"));
            m_BrowseField.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
            m_BrowseField.setIsRange(atts.getValue("isRange") != null ? Boolean.valueOf(atts.getValue("isRange")).booleanValue() : true);
            m_BrowseField.setIsKey(atts.getValue("isKey") != null ? Boolean.valueOf(atts.getValue("isKey")).booleanValue() : true);
            m_BrowseField.setIsQueryCriteria(atts.getValue("isQueryCriteria") != null ? Boolean.valueOf(atts.getValue("isQueryCriteria")).booleanValue() : true);
            m_BrowseField.setIsIdentifier(atts.getValue("isIdentifier") != null ? Boolean.valueOf(atts.getValue("isIdentifier")).booleanValue() : true);
            Name = atts.getValue("ADReferenceNameID");
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
            m_BrowseField.setAD_Reference_ID(id);
            // Name = atts.getValue("ADValRuleNameID");
            // id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
            // m_BrowseField.setAD_Val_Rule_ID(id);
            Name = atts.getValue("ADReferenceNameValueID");
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
            m_BrowseField.setAD_Reference_Value_ID(id);
            Name = atts.getValue("ADAxisViewColumnNameID");
            id = get_IDWithMasterAndColumn(ctx, "AD_View_Column", "ColumnName", Name, "AD_View", viewid);
            m_BrowseField.setAxis_Column_ID(id);
            Name = atts.getValue("ADAxisParentViewColumnNameID");
            id = get_IDWithMasterAndColumn(ctx, "AD_View_Column", "ColumnName", Name, "AD_View", viewid);
            m_BrowseField.setAxis_Parent_Column_ID(id);
            // Setup Element.
            Name = atts.getValue("ADElementNameID");
            id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", Name);
            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_BrowseField.getAD_View_Column().getAD_Column().getColumnName());
                adElement.setEntityType(m_BrowseField.getEntityType());
                adElement.setPrintName(m_BrowseField.getName());
                adElement.setName(m_BrowseField.getName());
                if (adElement.save(getTrxName(ctx)) == true) {
                    record_log(ctx, 1, m_BrowseField.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_BrowseField.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_BrowseField.setAD_Element_ID(adElement.getAD_Element_ID());
            if (m_BrowseField.save(getTrxName(ctx)) == true) {
                record_log(ctx, 1, m_BrowseField.getName(), "BrowseField", m_BrowseField.get_ID(), AD_Backup_ID, Object_Status, "AD_Browse_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Browse_Field"));
                element.recordId = m_BrowseField.getAD_Browse_Field_ID();
            } else {
                record_log(ctx, 0, m_BrowseField.getName(), "BrowseField", m_BrowseField.get_ID(), AD_Backup_ID, Object_Status, "AD_Browse_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Browse_Field"));
                throw new POSaveFailedException("Failed to save field definition.");
            }
        } else {
            element.defer = true;
            return;
        }
    } else {
        element.skip = true;
    }
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) X_AD_Element(org.compiere.model.X_AD_Element)

Aggregations

X_AD_Element (org.compiere.model.X_AD_Element)5 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)4 Attributes (org.xml.sax.Attributes)4 BigDecimal (java.math.BigDecimal)1 MBrowseField (org.adempiere.model.MBrowseField)1 PackIn (org.adempiere.pipo.PackIn)1 PackOut (org.adempiere.pipo.PackOut)1 PoFiller (org.adempiere.pipo.PoFiller)1 DatabaseAccessException (org.adempiere.pipo.exception.DatabaseAccessException)1 MColumn (org.compiere.model.MColumn)1 MTable (org.compiere.model.MTable)1 X_AD_Process_Para (org.compiere.model.X_AD_Process_Para)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1