Search in sources :

Example 26 with Attributes

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

the class WorkflowNodeElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    Attributes atts = element.attributes;
    String elementValue = element.getElementValue();
    log.info(elementValue + " " + atts.getValue("Name"));
    String entitytype = atts.getValue("EntityType");
    log.info("entitytype " + atts.getValue("EntityType"));
    if (isProcessElement(ctx, entitytype)) {
        if (element.parent != null && element.parent.skip) {
            element.skip = true;
            return;
        }
        if (element.parent != null && element.parent.getElementValue().equals("workflow") && element.parent.defer) {
            element.unresolved = "Parent element mark as defer: " + atts.getValue("ADWorkflowNameID");
            element.defer = true;
            return;
        }
        int workflowId = 0;
        String workflowName = atts.getValue("ADWorkflowNameID");
        if (element.parent != null && element.parent.getElementValue().equals("workflow") && element.parent.recordId > 0)
            workflowId = element.parent.recordId;
        else {
            workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName);
            if (workflowId <= 0) {
                element.defer = true;
                element.unresolved = "AD_Workflow: " + workflowName;
                return;
            } else if (element.parent != null && element.parent.getElementValue().equals("workflow"))
                element.parent.recordId = workflowId;
        }
        String workflowNodeName = atts.getValue("Name").trim();
        StringBuffer sqlB = new StringBuffer("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?");
        int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeName);
        X_AD_WF_Node m_WFNode = new X_AD_WF_Node(ctx, id, getTrxName(ctx));
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id <= 0 && atts.getValue("AD_WF_Node_ID") != null && Integer.parseInt(atts.getValue("AD_WF_Node_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_WFNode.setAD_WF_Node_ID(Integer.parseInt(atts.getValue("AD_WF_Node_ID")));
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_WF_Node", m_WFNode);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_WFNode.setValue(atts.getValue("Value"));
        m_WFNode.setName(workflowNodeName);
        m_WFNode.setAD_Workflow_ID(workflowId);
        String name = atts.getValue("ADProcessNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
            if (id <= 0) {
                element.defer = true;
                element.unresolved = "AD_Process: " + name;
                return;
            }
            m_WFNode.setAD_Process_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_WFNode.setAD_Form_ID(id);
        }
        name = atts.getValue("ADWorkflowResponsibleNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name);
            /*
				if (id <= 0) {
					element.defer = true;
					return;
				}*/
            if (id > 0)
                m_WFNode.setAD_WF_Responsible_ID(id);
        }
        name = atts.getValue("ADWindowNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Window", "Name", name);
            if (id <= 0) {
                element.defer = true;
                element.unresolved = "AD_Window: " + name;
                return;
            }
            m_WFNode.setAD_Window_ID(id);
        }
        name = atts.getValue("ADImageNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_Image", "Name", name);
            /*
				if (id <= 0) {
					element.defer = true;
					return;
				}*/
            if (id > 0)
                m_WFNode.setAD_Image_ID(id);
        }
        name = atts.getValue("ADWorkflowBlockNameID");
        if (name != null && name.trim().length() > 0) {
            id = get_IDWithColumn(ctx, "AD_WF_Block", "Name", name);
            /*
				if (id <= 0) {
					element.defer = true;
					return;
				}*/
            if (id > 0)
                m_WFNode.setAD_WF_Block_ID(id);
        }
        String columnName = atts.getValue("ADColumnNameID");
        int tableId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Table_ID FROM AD_Workflow WHERE AD_Workflow_ID=?", workflowId);
        get_IDWithColumn(ctx, "AD_Workflow", "AD_Table_ID", workflowId);
        int columnId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableId);
        if (columnId <= 0 && tableId > 0 && columnName != null && columnName.length() > 0) {
            element.unresolved = "AD_Column=" + columnName;
            element.defer = true;
            return;
        } else if (columnId > 0)
            m_WFNode.setAD_Column_ID(columnId);
        //[Bugs-1789058 ]
        /*
			name = atts.getValue("WorkflowNameID");
			if (name != null && name.trim().length() > 0) {
				id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
				//TODO: export and import of ad_workflow
				
				if (id <= 0) {
					element.defer = true;
					element.unresolved = "Sub Workflow: " + name;
					return;
				}
				if (id > 0)
					m_WFNode.setWorkflow_ID(id);
			}*/
        /*
			 * FIXME: Do we need TaskName ? if
			 * (atts.getValue("ADTaskNameID")!=null){ String name =
			 * atts.getValue("ADTaskNameID"); sqlB = new StringBuffer ("SELECT
			 * AD_Task_ID FROM AD_Task WHERE Name= ?"); taskid =
			 * DB.getSQLValue(m_trxName,sqlB.toString(),name); }
			 */
        m_WFNode.setValue(atts.getValue("Value"));
        m_WFNode.setEntityType(atts.getValue("EntityType"));
        m_WFNode.setAction(getStringValue(atts, "Action"));
        m_WFNode.setDocAction(getStringValue(atts, "DocAction"));
        m_WFNode.setDescription(getStringValue(atts, "Description"));
        m_WFNode.setJoinElement(atts.getValue("JoinElement"));
        m_WFNode.setSplitElement(atts.getValue("SplitElement"));
        if (getStringValue(atts, "XPosition") != null)
            m_WFNode.setXPosition(Integer.valueOf(atts.getValue("XPosition")));
        if (getStringValue(atts, "YPosition") != null)
            m_WFNode.setYPosition(Integer.valueOf(atts.getValue("YPosition")));
        m_WFNode.setWaitingTime(Integer.valueOf(atts.getValue("WaitingTime")));
        if (getStringValue(atts, "WaitTime") != null)
            m_WFNode.setWaitTime(Integer.valueOf(atts.getValue("WaitTime")));
        m_WFNode.setWorkingTime(Integer.valueOf(atts.getValue("WorkingTime")));
        if (getStringValue(atts, "Cost") != null)
            m_WFNode.setCost(new BigDecimal(atts.getValue("Cost")));
        if (getStringValue(atts, "Duration") != null)
            m_WFNode.setDuration(Integer.valueOf(atts.getValue("Duration")));
        if (getStringValue(atts, "Priority") != null)
            m_WFNode.setPriority(Integer.valueOf(atts.getValue("Priority")));
        m_WFNode.setStartMode(getStringValue(atts, "StartMode"));
        m_WFNode.setSubflowExecution(getStringValue(atts, "SubflowExecution"));
        m_WFNode.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("IsCentrallyMaintained")).booleanValue());
        if (getStringValue(atts, "DynPriorityChange") != null)
            m_WFNode.setDynPriorityChange(new BigDecimal(atts.getValue("DynPriorityChange")));
        // m_WFNode.setAccessLevel (atts.getValue("AccessLevel"));
        m_WFNode.setDynPriorityUnit(getStringValue(atts, "DynPriorityUnit"));
        m_WFNode.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_WFNode.setValue(atts.getValue("Value"));
        log.info("about to execute m_WFNode.save");
        if (m_WFNode.save(getTrxName(ctx)) == true) {
            log.info("m_WFNode save success");
            record_log(ctx, 1, m_WFNode.getName(), "WFNode", m_WFNode.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_Node", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_Node"));
        } else {
            log.info("m_WFNode save failure");
            record_log(ctx, 0, m_WFNode.getName(), "WFNode", m_WFNode.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_Node", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_Node"));
            throw new POSaveFailedException("WorkflowNode");
        }
    } else {
        element.skip = true;
    }
}
Also used : Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) X_AD_WF_Node(org.compiere.model.X_AD_WF_Node) BigDecimal(java.math.BigDecimal)

Example 27 with Attributes

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

the class ViewElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    // Check namespace.
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        String name = atts.getValue("Name");
        int id = get_ID(ctx, "AD_View", name);
        if (id > 0 && views.contains(id)) {
            return;
        }
        MView m_View = new MView(ctx, id, getTrxName(ctx));
        if (id <= 0 && atts.getValue("AD_View_ID") != null && Integer.parseInt(atts.getValue("AD_View_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_View.setAD_View_ID(Integer.parseInt(atts.getValue("AD_View_ID")));
        String Object_Status = null;
        int AD_Backup_ID = -1;
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_View", m_View);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_View.setValue(atts.getValue("Value"));
        m_View.setName(atts.getValue("Name"));
        m_View.setDescription(getStringValue(atts, "Description"));
        m_View.setHelp(getStringValue(atts, "Help"));
        m_View.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_View.setEntityType(atts.getValue("EntityType"));
        if (m_View.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_View.getName(), "View", m_View.get_ID(), AD_Backup_ID, Object_Status, "AD_View", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_View"));
            element.recordId = m_View.getAD_View_ID();
            views.add(m_View.getAD_View_ID());
        } else {
            record_log(ctx, 0, m_View.getName(), "View", m_View.get_ID(), AD_Backup_ID, Object_Status, "AD_View", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_View"));
            throw new POSaveFailedException("View");
        }
    } else {
        element.skip = true;
    }
}
Also used : MView(org.adempiere.model.MView) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

Example 28 with Attributes

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

the class WindowAccessElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    log.info(elementValue);
    int roleid = 0;
    int windowid = 0;
    StringBuffer sqlB = null;
    Attributes atts = element.attributes;
    if (atts.getValue("rolename") != null) {
        String name = atts.getValue("rolename");
        sqlB = new StringBuffer("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
        roleid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
        if (roleid <= 0) {
            element.defer = true;
            return;
        }
    }
    if (atts.getValue("windowname") != null) {
        String name = atts.getValue("windowname");
        sqlB = new StringBuffer("SELECT AD_Window_ID FROM AD_Window WHERE Name= ?");
        windowid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
        if (windowid <= 0) {
            element.defer = true;
            return;
        }
    }
    sqlB = new StringBuffer("SELECT count(*) FROM AD_Window_Access WHERE AD_Role_ID=? and AD_Window_ID=?");
    int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), roleid, windowid);
    int AD_Backup_ID = -1;
    String Object_Status = null;
    if (count > 0) {
        Object_Status = "Update";
        sqlB = new StringBuffer("UPDATE AD_Window_Access ").append("SET isActive = '" + atts.getValue("isActive")).append("', isReadWrite = '" + atts.getValue("isReadWrite")).append("' WHERE AD_Role_ID = " + roleid).append(" and AD_Window_ID = " + windowid);
        int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
        if (no == -1)
            log.info("Update to window access failed");
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
        sqlB = new StringBuffer("INSERT INTO AD_Window_Access").append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append("AD_Role_ID, AD_Window_ID, isActive, isReadWrite) ").append("VALUES(").append(" " + Env.getAD_Client_ID(ctx)).append(", " + Env.getAD_Org_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + roleid).append(", " + windowid).append(", '" + atts.getValue("isActive")).append("', '" + atts.getValue("isReadWrite") + "')");
        int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
        if (no == -1)
            log.info("Insert to window access failed");
    }
}
Also used : Attributes(org.xml.sax.Attributes)

Example 29 with Attributes

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

the class UserRoleElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    log.info(elementValue);
    int roleid = 0;
    int userid = 0;
    int orgid = 0;
    StringBuffer sqlB = null;
    Attributes atts = element.attributes;
    if (atts.getValue("username") != null) {
        String name = atts.getValue("username");
        sqlB = new StringBuffer("SELECT AD_User_ID FROM AD_User WHERE Name= ?");
        userid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
    }
    if (atts.getValue("rolename") != null) {
        String name = atts.getValue("rolename");
        sqlB = new StringBuffer("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
        roleid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
    }
    if (atts.getValue("orgname") != null) {
        String name = atts.getValue("orgname");
        sqlB = new StringBuffer("SELECT AD_Org_ID FROM AD_Org WHERE Name= ?");
        orgid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
    }
    sqlB = new StringBuffer("SELECT count(*) FROM AD_User_Roles WHERE AD_User_ID = ? and AD_Role_ID = ?");
    int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), userid, roleid);
    int AD_Backup_ID = -1;
    String Object_Status = null;
    if (count > 0) {
        //AD_Backup_ID = copyRecord("AD_Role",m_Role);
        Object_Status = "Update";
        sqlB = new StringBuffer("UPDATE AD_User_Roles ").append("SET isActive = '" + atts.getValue("isActive") + "'").append(" WHERE AD_User_ID = " + userid).append(" and AD_Role_ID = " + roleid).append(" and AD_Org_ID = " + orgid);
        int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
        if (no == -1)
            log.info("Update to user roles failed");
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
        sqlB = new StringBuffer("INSERT INTO AD_User_Roles").append("(AD_Client_ID,  CreatedBy, UpdatedBy, ").append("AD_User_ID, AD_Role_ID, AD_Org_ID, isActive) ").append("VALUES(").append(" " + Env.getAD_Client_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + userid).append(", " + roleid).append(", " + orgid).append(", '" + atts.getValue("isActive") + "')");
        int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
        if (no == -1)
            log.info("Insert to user roles failed");
    }
}
Also used : Attributes(org.xml.sax.Attributes)

Example 30 with Attributes

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

the class TaskElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("ADTaskNameID"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        String name = atts.getValue("ADTaskNameID");
        int id = get_ID(ctx, "AD_Task", name);
        MTask m_Task = new MTask(ctx, id, getTrxName(ctx));
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id <= 0 && atts.getValue("AD_Task_ID") != null && Integer.parseInt(atts.getValue("AD_Task_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_Task.setAD_Task_ID(Integer.parseInt(atts.getValue("AD_Task_ID")));
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_Task", m_Task);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_Task.setAccessLevel(atts.getValue("AccessLevel"));
        m_Task.setDescription(getStringValue(atts, "Description"));
        m_Task.setEntityType(atts.getValue("EntityType"));
        m_Task.setHelp(getStringValue(atts, "Help"));
        m_Task.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_Task.setName(name);
        m_Task.setOS_Command(getStringValue(atts, "OS_Command"));
        if (m_Task.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, m_Task.getName(), "Task", m_Task.get_ID(), AD_Backup_ID, Object_Status, "AD_Task", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Task"));
        } else {
            record_log(ctx, 0, m_Task.getName(), "Task", m_Task.get_ID(), AD_Backup_ID, Object_Status, "AD_Task", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Task"));
            throw new POSaveFailedException("Task");
        }
    } else {
        element.skip = true;
    }
}
Also used : MTask(org.compiere.model.MTask) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

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