Search in sources :

Example 16 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class ImpFormatElementHandler 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("Name"));
    int id = get_ID(ctx, "AD_ImpFormat", atts.getValue("Name"));
    X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, id, getTrxName(ctx));
    if (id <= 0 && atts.getValue("AD_ImpFormat_ID") != null && Integer.parseInt(atts.getValue("AD_ImpFormat_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_ImpFormat.setAD_ImpFormat_ID(Integer.parseInt(atts.getValue("AD_ImpFormat_ID")));
    if (id > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_ImpFormat", m_ImpFormat);
        Object_Status = "Update";
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
    }
    m_ImpFormat.setName(atts.getValue("Name"));
    String name = atts.getValue("ADTableNameID");
    if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_ImpFormat.setAD_Table_ID(id);
    }
    m_ImpFormat.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
    m_ImpFormat.setProcessing(atts.getValue("isProcessing") != null ? Boolean.valueOf(atts.getValue("isProcessing")).booleanValue() : true);
    m_ImpFormat.setName(atts.getValue("Name"));
    m_ImpFormat.setDescription(getStringValue(atts, "Description"));
    m_ImpFormat.setFormatType(atts.getValue("FormatType"));
    if (m_ImpFormat.save(getTrxName(ctx)) == true) {
        record_log(ctx, 1, m_ImpFormat.getName(), "ImpFormat", m_ImpFormat.get_ID(), AD_Backup_ID, Object_Status, "AD_ImpFormat", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_ImpFormat"));
    } else {
        record_log(ctx, 0, m_ImpFormat.getName(), "ImpFormat", m_ImpFormat.get_ID(), AD_Backup_ID, Object_Status, "AD_ImpFormat", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_ImpFormat"));
        throw new POSaveFailedException("Failed to save Import Format.");
    }
}
Also used : X_AD_ImpFormat(org.compiere.model.X_AD_ImpFormat) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

Example 17 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class PrintPaperElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    final String elementValue = element.getElementValue();
    final Attributes atts = element.attributes;
    final String strIdentifier = atts.getValue(getIdentifierColumnName());
    final int id = get_IDWithColumn(ctx, getTableName(), getIdentifierColumnName(), strIdentifier);
    final PO po = getCreatePO(ctx, id, getTrxName(ctx));
    final String keyColumnName = getKeyColumnName();
    log.info(elementValue + " " + strIdentifier + "[" + id + "]");
    if (id <= 0 && keyColumnName != null && getIntValue(atts, keyColumnName, 0) <= PackOut.MAX_OFFICIAL_ID) {
        po.set_ValueOfColumn(keyColumnName, getIntValue(atts, keyColumnName, 0));
    }
    final int AD_Backup_ID;
    final String Object_Status;
    if (id > 0) {
        AD_Backup_ID = copyRecord(ctx, getTableName(), po);
        Object_Status = "Update";
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
    }
    for (String attributeName : getAttributeNames()) {
        loadAttribute(atts, attributeName, po);
    }
    if (po.save(getTrxName(ctx)) == true) {
        record_log(ctx, 1, strIdentifier, getTagName(), po.get_ID(), AD_Backup_ID, Object_Status, getTableName(), getTable_ID());
    } else {
        record_log(ctx, 0, strIdentifier, getTagName(), po.get_ID(), AD_Backup_ID, Object_Status, getTableName(), getTable_ID());
        throw new POSaveFailedException("Failed to save message.");
    }
}
Also used : Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) PO(org.compiere.model.PO)

Example 18 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class ProcessElementHandler 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"));
    int id = 0;
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        String value = atts.getValue("Value");
        // Get New process.
        id = get_IDWithColumn(ctx, "AD_Process", "Value", value);
        X_AD_Process m_Process = null;
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id > 0) {
            m_Process = new X_AD_Process(ctx, id, getTrxName(ctx));
            AD_Backup_ID = copyRecord(ctx, "AD_Process", m_Process);
            Object_Status = "Update";
        } else {
            m_Process = new X_AD_Process(ctx, id, getTrxName(ctx));
            if (id <= 0 && atts.getValue("AD_Process_ID") != null && Integer.parseInt(atts.getValue("AD_Process_ID")) <= PackOut.MAX_OFFICIAL_ID)
                m_Process.setAD_Process_ID(Integer.parseInt(atts.getValue("AD_Process_ID")));
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        String name = atts.getValue("Name");
        m_Process.setName(name);
        name = atts.getValue("ADWorkflowNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
            if (id <= 0) {
                if (element.pass == 1) {
                    element.defer = true;
                    element.unresolved = "AD_Workflow: " + name;
                    return;
                } else {
                    log.warning("AD_Workflow: " + name + " not found for Workflow: " + name);
                }
            }
            if (id > 0)
                m_Process.setAD_Workflow_ID(id);
        }
        name = atts.getValue("ADPrintFormatNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
            if (id <= 0) {
                if (element.pass == 1) {
                    element.defer = true;
                    element.unresolved = "AD_PrintFormat: " + name;
                    return;
                } else {
                    log.warning("AD_PrintFormat: " + name + " not found for Process: " + m_Process.getName());
                }
            }
            if (id > 0)
                m_Process.setAD_PrintFormat_ID(id);
        }
        name = atts.getValue("ADReportViewNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name);
            if (id <= 0) {
                if (element.pass == 1) {
                    element.defer = true;
                    element.unresolved = "AD_ReportView: " + name;
                    return;
                } else {
                    log.warning("AD_ReportView: " + name + " not found for Process: " + m_Process.getName());
                }
            }
            if (id > 0)
                m_Process.setAD_ReportView_ID(id);
        }
        name = atts.getValue("ADFormNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Form", "Name", name);
            if (id <= 0) {
                element.defer = true;
                element.unresolved = "AD_Form: " + name;
                return;
            }
            m_Process.setAD_Form_ID(id);
        }
        name = atts.getValue("ADBrowseNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Browse", "Name", name);
            if (id <= 0) {
                element.defer = true;
                element.unresolved = "AD_Browse: " + name;
                return;
            }
            m_Process.setAD_Browse_ID(id);
        }
        m_Process.setAccessLevel(atts.getValue("AccessLevel"));
        m_Process.setClassname(getStringValue(atts, "Classname"));
        m_Process.setDescription(getStringValue(atts, "Description"));
        m_Process.setEntityType(atts.getValue("EntityType"));
        m_Process.setHelp(getStringValue(atts, "Help"));
        m_Process.setIsBetaFunctionality(Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
        m_Process.setIsDirectPrint(Boolean.valueOf(atts.getValue("isDirectPrint")).booleanValue());
        m_Process.setIsReport(Boolean.valueOf(atts.getValue("isReport")).booleanValue());
        m_Process.setName(atts.getValue("Name"));
        m_Process.setProcedureName(getStringValue(atts, "ProcedureName"));
        m_Process.setStatistic_Count(0);
        m_Process.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_Process.setStatistic_Seconds(0);
        m_Process.setValue(atts.getValue("Value"));
        m_Process.setWorkflowValue(atts.getValue("WorkflowValue"));
        m_Process.setShowHelp((getStringValue(atts, "ShowHelp")));
        m_Process.setJasperReport(getStringValue(atts, "JasperReport"));
        if (m_Process.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_Process.getName(), "Process", m_Process.get_ID(), AD_Backup_ID, Object_Status, "AD_Process", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Process"));
            element.recordId = m_Process.getAD_Process_ID();
        } else {
            record_log(ctx, 0, m_Process.getName(), "Process", m_Process.get_ID(), AD_Backup_ID, Object_Status, "AD_Process", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Process"));
            throw new POSaveFailedException("Process");
        }
    } else {
        element.skip = true;
    }
}
Also used : Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) X_AD_Process(org.compiere.model.X_AD_Process)

Example 19 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class PreferenceElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    log.info(elementValue);
    // TODO Add User_ID
    Attributes atts = element.attributes;
    int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID"));
    if (windowid <= 0) {
        element.defer = true;
        return;
    }
    StringBuffer sqlB = new StringBuffer("select AD_Preference_ID from AD_Preference where ").append(" Attribute = '" + atts.getValue("Attribute") + "'").append(" and AD_Window_ID = ?");
    int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), windowid);
    MPreference m_Preference = new MPreference(ctx, id, getTrxName(ctx));
    int AD_Backup_ID = -1;
    String Object_Status = null;
    if (id <= 0 && atts.getValue("AD_Preference_ID") != null && Integer.parseInt(atts.getValue("AD_Preference_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_Preference.setAD_Preference_ID(Integer.parseInt(atts.getValue("AD_Preference_ID")));
    if (id > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_Preference", m_Preference);
        Object_Status = "Update";
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
    }
    sqlB = null;
    m_Preference.setAD_Window_ID(windowid);
    m_Preference.setAttribute(atts.getValue("Attribute"));
    m_Preference.setValue(atts.getValue("Value"));
    if (m_Preference.save(getTrxName(ctx)) == true) {
        record_log(ctx, 1, m_Preference.getAttribute(), "Preference", m_Preference.get_ID(), AD_Backup_ID, Object_Status, "AD_Preference", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Preference"));
    } else {
        record_log(ctx, 0, m_Preference.getAttribute(), "Preference", m_Preference.get_ID(), AD_Backup_ID, Object_Status, "AD_Preference", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Preference"));
        throw new POSaveFailedException("Failed to save Preference");
    }
}
Also used : MPreference(org.compiere.model.MPreference) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

Example 20 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class RoleElementHandler 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 name = atts.getValue("Name");
    int id = get_ID(ctx, "AD_Role", name);
    MRole m_Role = new MRole(ctx, id, getTrxName(ctx));
    int AD_Backup_ID = -1;
    String Object_Status = null;
    if (id <= 0 && atts.getValue("AD_Role_ID") != null && Integer.parseInt(atts.getValue("AD_Role_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_Role.setAD_Role_ID(Integer.parseInt(atts.getValue("AD_Role_ID")));
    if (id > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_Role", m_Role);
        Object_Status = "Update";
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
    }
    m_Role.setName(name);
    name = atts.getValue("treemenuname");
    if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_Tree", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Role.setAD_Tree_Menu_ID(id);
    }
    name = atts.getValue("treeorgname");
    if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_Tree", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Role.setAD_Tree_Org_ID(id);
    }
    name = atts.getValue("currencycode");
    if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "C_Currency", "ISO_Code", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Role.setC_Currency_ID(id);
    }
    name = atts.getValue("supervisorid");
    if (name != null && name.trim().length() > 0) {
        id = get_IDWithColumn(ctx, "AD_User", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Role.setC_Currency_ID(id);
    }
    m_Role.setDescription(getStringValue(atts, "Description"));
    String amtApproval = getStringValue(atts, "AmtApproval");
    if (amtApproval != null)
        m_Role.setAmtApproval(new BigDecimal(amtApproval));
    m_Role.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
    m_Role.setIsAccessAllOrgs(atts.getValue("isAccessAllOrgs") != null ? Boolean.valueOf(atts.getValue("isAccessAllOrgs")).booleanValue() : true);
    m_Role.setIsCanApproveOwnDoc(atts.getValue("isCanApproveOwnDoc") != null ? Boolean.valueOf(atts.getValue("isCanApproveOwnDoc")).booleanValue() : true);
    m_Role.setIsCanExport(atts.getValue("isCanExport") != null ? Boolean.valueOf(atts.getValue("isCanExport")).booleanValue() : true);
    m_Role.setIsCanReport(atts.getValue("isCanReport") != null ? Boolean.valueOf(atts.getValue("isCanReport")).booleanValue() : true);
    m_Role.setIsChangeLog(atts.getValue("isChangeLog") != null ? Boolean.valueOf(atts.getValue("isChangeLog")).booleanValue() : true);
    m_Role.setIsManual(atts.getValue("isManual") != null ? Boolean.valueOf(atts.getValue("isManual")).booleanValue() : true);
    m_Role.setIsPersonalAccess(atts.getValue("isPersonalAccess") != null ? Boolean.valueOf(atts.getValue("isPersonalAccess")).booleanValue() : true);
    m_Role.setIsPersonalLock(atts.getValue("isPersonalLock") != null ? Boolean.valueOf(atts.getValue("isPersonalLock")).booleanValue() : true);
    m_Role.setIsShowAcct(atts.getValue("isShowAcct") != null ? Boolean.valueOf(atts.getValue("isShowAcct")).booleanValue() : true);
    m_Role.setIsUseUserOrgAccess(atts.getValue("isUseUserOrgAccess") != null ? Boolean.valueOf(atts.getValue("isUseUserOrgAccess")).booleanValue() : true);
    m_Role.setOverwritePriceLimit(atts.getValue("isOverwritePriceLimit") != null ? Boolean.valueOf(atts.getValue("isOverwritePriceLimit")).booleanValue() : true);
    m_Role.setPreferenceType(atts.getValue("PreferenceType"));
    m_Role.setUserLevel(atts.getValue("UserLevel"));
    m_Role.setAllow_Info_Account(Boolean.valueOf(atts.getValue("AllowInfoAccount")));
    m_Role.setAllow_Info_Asset(Boolean.valueOf(atts.getValue("AllowInfoAsset")));
    m_Role.setAllow_Info_BPartner(Boolean.valueOf(atts.getValue("AllowInfoBPartner")));
    m_Role.setAllow_Info_CashJournal(Boolean.valueOf(atts.getValue("AllowInfoCashJournal")));
    m_Role.setAllow_Info_InOut(Boolean.valueOf(atts.getValue("AllowInfoInOut")));
    m_Role.setAllow_Info_Invoice(Boolean.valueOf(atts.getValue("AllowInfoInvoice")));
    m_Role.setAllow_Info_Order(Boolean.valueOf(atts.getValue("AllowInfoOrder")));
    m_Role.setAllow_Info_Payment(Boolean.valueOf(atts.getValue("AllowInfoPayment")));
    m_Role.setAllow_Info_Product(Boolean.valueOf(atts.getValue("AllowInfoProduct")));
    m_Role.setAllow_Info_Resource(Boolean.valueOf(atts.getValue("AllowInfoResource")));
    m_Role.setAllow_Info_Schedule(Boolean.valueOf(atts.getValue("AllowInfoSchedule")));
    m_Role.setAllow_Info_Schedule(Boolean.valueOf(atts.getValue("AllowInfoCRP")));
    m_Role.setAllow_Info_Schedule(Boolean.valueOf(atts.getValue("AllowInfoMRP")));
    if (m_Role.save(getTrxName(ctx)) == true) {
        record_log(ctx, 1, m_Role.getName(), "Role", m_Role.get_ID(), AD_Backup_ID, Object_Status, "AD_Role", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Role"));
    } else {
        record_log(ctx, 0, m_Role.getName(), "Role", m_Role.get_ID(), AD_Backup_ID, Object_Status, "AD_Role", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Role"));
        throw new POSaveFailedException("Role");
    }
}
Also used : MRole(org.compiere.model.MRole) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) BigDecimal(java.math.BigDecimal)

Aggregations

Attributes (org.xml.sax.Attributes)274 DefaultHandler (org.xml.sax.helpers.DefaultHandler)70 SAXException (org.xml.sax.SAXException)66 Test (org.junit.Test)59 AttributesImpl (org.xml.sax.helpers.AttributesImpl)50 SAXParser (javax.xml.parsers.SAXParser)48 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)37 InputSource (org.xml.sax.InputSource)31 SAXParserFactory (javax.xml.parsers.SAXParserFactory)30 IOException (java.io.IOException)29 File (java.io.File)22 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ArrayList (java.util.ArrayList)17 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 InputStream (java.io.InputStream)16 ContentHandler (org.xml.sax.ContentHandler)15 XMLReader (org.xml.sax.XMLReader)15 StringReader (java.io.StringReader)10 Transformer (org.apache.sling.rewriter.Transformer)10 MockBundle (org.apache.sling.commons.testing.osgi.MockBundle)9