Search in sources :

Example 1 with X_AD_Menu

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

the class MenuElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int AD_Menu_ID = Env.getContextAsInt(ctx, "AD_Menu_ID");
    X_AD_Menu m_Menu = new X_AD_Menu(ctx, AD_Menu_ID, null);
    if (m_Menu.isSummary() == false) {
        createApplication(ctx, document, AD_Menu_ID);
    } else {
        AttributesImpl atts = new AttributesImpl();
        createMenuBinding(atts, m_Menu);
        document.startElement("", "", "menu", atts);
        createModule(ctx, document, AD_Menu_ID);
        document.endElement("", "", "menu");
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) X_AD_Menu(org.compiere.model.X_AD_Menu)

Example 2 with X_AD_Menu

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

the class MenuElementHandler method createModule.

public void createModule(Properties ctx, TransformerHandler document, int menu_id) throws SAXException {
    PackOut packOut = (PackOut) ctx.get("PackOutProcess");
    String sql = null;
    sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_BROWSE_ID, B.AD_WORKBENCH_ID " + "FROM AD_TreeNoDemm A, AD_Menu B " + "WHERE A.Parent_ID = " + menu_id + " AND A.Node_ID = B.AD_Menu_ID";
    AttributesImpl atts = new AttributesImpl();
    PreparedStatement pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            // Menu tag Start.
            X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), null);
            atts = createMenuBinding(atts, m_Menu);
            document.startElement("", "", "menu", atts);
            if (rs.getInt("AD_WINDOW_ID") > 0 || rs.getInt("AD_WORKFLOW_ID") > 0 || rs.getInt("AD_TASK_ID") > 0 || rs.getInt("AD_PROCESS_ID") > 0 || rs.getInt("AD_FORM_ID") > 0 || rs.getInt("AD_BROWSE_ID") > 0 || rs.getInt("AD_WORKBENCH_ID") > 0) {
                // Call CreateWindow.
                if (rs.getInt("AD_WINDOW_ID") > 0) {
                    packOut.createWindow(rs.getInt("AD_WINDOW_ID"), document);
                } else // Call CreateProcess.
                if (rs.getInt("AD_PROCESS_ID") > 0) {
                    packOut.createProcess(rs.getInt("AD_PROCESS_ID"), document);
                } else // Call CreateTask.
                if (rs.getInt("AD_TASK_ID") > 0) {
                    packOut.createTask(rs.getInt("AD_TASK_ID"), document);
                } else // Call CreateForm.
                if (rs.getInt("AD_FORM_ID") > 0) {
                    packOut.createForm(rs.getInt("AD_FORM_ID"), document);
                } else // Call Browse.
                if (rs.getInt("AD_Browse_ID") > 0) {
                    packOut.createBrowse(rs.getInt("AD_Browse_ID"), document);
                } else // Call CreateWorkflow
                if (rs.getInt("AD_Workflow_ID") > 0) {
                    packOut.createWorkflow(rs.getInt("AD_Workflow_ID"), document);
                }
            // Call CreateModule because entry is a summary menu
            } else {
                createModule(ctx, document, rs.getInt("Node_ID"));
            }
            document.endElement("", "", "menu");
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "getWindows", e);
    } finally {
        try {
            if (pstmt != null)
                pstmt.close();
        } catch (Exception e) {
        }
        pstmt = null;
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) X_AD_Menu(org.compiere.model.X_AD_Menu) PackOut(org.adempiere.pipo.PackOut) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SAXException(org.xml.sax.SAXException)

Example 3 with X_AD_Menu

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

the class MenuElementHandler 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("ADMenuNameID"));
    // String entitytype = atts.getValue("EntityType");
    // if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0
    // && m_UpdateMode == true ) {
    String name = null;
    int idDetail = 0;
    StringBuffer sqlB = null;
    name = atts.getValue("ADMenuNameID");
    int menuid = get_IDWithColumn(ctx, "AD_Menu", "Name", name);
    X_AD_Menu m_Menu = new X_AD_Menu(ctx, menuid, getTrxName(ctx));
    if (menuid <= 0 && atts.getValue("AD_Menu_ID") != null && Integer.parseInt(atts.getValue("AD_Menu_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_Menu.setAD_Menu_ID(Integer.parseInt(atts.getValue("AD_Menu_ID")));
    if (menuid > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_Menu", m_Menu);
        Object_Status = "Update";
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
    }
    m_Menu.setName(name);
    name = atts.getValue("ADWindowNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Window", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Window_ID(id);
    }
    name = atts.getValue("ADProcessNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Process_ID(id);
    }
    name = atts.getValue("ADFormNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Form", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Form_ID(id);
    }
    name = atts.getValue("ADBrowseNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Browse", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Browse_ID(id);
    }
    name = atts.getValue("ADTaskNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Task", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Task_ID(id);
    }
    name = atts.getValue("ADWorkbenchNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Workbench", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Workbench_ID(id);
    }
    name = atts.getValue("ADWorkflowNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Workflow_ID(id);
    }
    String action = (atts.getValue("Action") != null ? atts.getValue("Action") : " ");
    if (action.compareTo(" ") > -1)
        m_Menu.setAction(action);
    m_Menu.setDescription(getStringValue(atts, "Description"));
    m_Menu.setEntityType(atts.getValue("EntityType"));
    m_Menu.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
    m_Menu.setIsSOTrx(Boolean.valueOf(atts.getValue("isSOTrx")).booleanValue());
    m_Menu.setIsSummary(Boolean.valueOf(atts.getValue("isSummary")).booleanValue());
    m_Menu.setIsActive(Boolean.valueOf(atts.getValue("isActive")).booleanValue());
    if (m_Menu.save(getTrxName(ctx)) == true) {
        try {
            idDetail = record_log(ctx, 1, m_Menu.getName(), "Menu", m_Menu.get_ID(), AD_Backup_ID, Object_Status, "AD_Menu", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Menu"));
        } catch (SAXException e) {
            log.info("setmenu:" + e);
        }
    } else {
        try {
            idDetail = record_log(ctx, 0, m_Menu.getName(), "Menu", m_Menu.get_ID(), AD_Backup_ID, Object_Status, "AD_Menu", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Menu"));
        } catch (SAXException e) {
            log.info("setmenu:" + e);
        }
    }
    name = atts.getValue("ADParentMenuNameID");
    int id = get_ID(ctx, "AD_Menu", name);
    String sql2 = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10" + " AND Node_ID = " + menuid;
    int countRecords = DB.getSQLValue(getTrxName(ctx), sql2);
    if (countRecords > 0) {
        StringBuffer sqlC = new StringBuffer("select * from AD_TREENODEMM where AD_Tree_ID = 10 and " + " Node_ID =?");
        try {
            PreparedStatement pstmt1 = DB.prepareStatement(sqlC.toString(), getTrxName(ctx));
            pstmt1.setInt(1, menuid);
            ResultSet rs1 = pstmt1.executeQuery();
            if (rs1.next()) {
                String colValue = null;
                ResultSetMetaData meta = rs1.getMetaData();
                int columns = meta.getColumnCount();
                int tableID = get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_TreeNodeMM");
                for (int q = 1; q <= columns; q++) {
                    String col_Name = meta.getColumnName(q);
                    StringBuffer sql = new StringBuffer("SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = '" + col_Name + "' AND AD_Table_ID = ?");
                    int columnID = DB.getSQLValue(getTrxName(ctx), sql.toString(), tableID);
                    sql = new StringBuffer("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = " + (columnID == -1 ? "null" : columnID));
                    int referenceID = DB.getSQLValue(getTrxName(ctx), sql.toString());
                    int idBackup = DB.getNextID(Env.getAD_Client_ID(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
                    if (referenceID == 20 || referenceID == 28)
                        if (rs1.getObject(q).equals("Y"))
                            colValue = "true";
                        else
                            colValue = "false";
                    else
                        colValue = rs1.getObject(q).toString();
                    StringBuffer sqlD = new StringBuffer("INSERT INTO AD_Package_Imp_Backup" + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," + " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" + "VALUES(" + " " + Env.getAD_Client_ID(ctx) + ", " + Env.getAD_Org_ID(ctx) + ", " + Env.getAD_User_ID(ctx) + ", " + Env.getAD_User_ID(ctx) + ", " + idBackup + ", " + idDetail + ", " + getPackageImpId(ctx) + ", " + tableID + ", " + (columnID == -1 ? "null" : columnID) + ", " + (referenceID == -1 ? "null" : referenceID) + ", '" + colValue + "')");
                    int no = DB.executeUpdate(sqlD.toString(), getTrxName(ctx));
                    if (no == -1)
                        log.info("Insert to import backup failed");
                }
            }
            rs1.close();
            pstmt1.close();
            pstmt1 = null;
        } catch (Exception e) {
            log.info("get_IDWithMasterID:" + e);
        }
        MTree tree = new MTree(ctx, 10, getTrxName(ctx));
        MTree_NodeMM treeNode = MTree_NodeMM.get(tree, m_Menu.getAD_Menu_ID());
        treeNode.setSeqNo(Integer.valueOf(atts.getValue("ADParentSeqno")));
        treeNode.set_CustomColumn("Parent_ID", id);
        treeNode.saveEx();
    } else {
        MTree tree = new MTree(ctx, 10, getTrxName(ctx));
        MTree_NodeMM treeNode = new MTree_NodeMM(tree, m_Menu.getAD_Menu_ID());
        treeNode.setSeqNo(Integer.valueOf(atts.getValue("ADParentSeqno")));
        treeNode.set_CustomColumn("Parent_ID", id);
        treeNode.setNode_ID(m_Menu.getAD_Menu_ID());
        treeNode.saveEx();
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) X_AD_Menu(org.compiere.model.X_AD_Menu) Attributes(org.xml.sax.Attributes) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) MTree(org.compiere.model.MTree) MTree_NodeMM(org.compiere.model.MTree_NodeMM)

Example 4 with X_AD_Menu

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

the class MenuElementHandler method createApplication.

private void createApplication(Properties ctx, TransformerHandler document, int AD_Menu_ID) throws SAXException {
    PackOut packOut = (PackOut) ctx.get("PackOutProcess");
    String sql = null;
    // int x = 0;
    sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " + "B.AD_PROCESS_ID, B.AD_FORM_ID , B.AD_BROWSE_ID, B.AD_WORKBENCH_ID " + "FROM AD_TreeNoDemm A, AD_Menu B " + "WHERE A.Node_ID = " + AD_Menu_ID + " AND A.Node_ID = B.AD_Menu_ID";
    AttributesImpl atts = new AttributesImpl();
    PreparedStatement pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), null);
            atts = createMenuBinding(atts, m_Menu);
            document.startElement("", "", "menu", atts);
            if (rs.getInt("AD_WINDOW_ID") > 0 || rs.getInt("AD_WORKFLOW_ID") > 0 || rs.getInt("AD_TASK_ID") > 0 || rs.getInt("AD_PROCESS_ID") > 0 || rs.getInt("AD_FORM_ID") > 0 || rs.getInt("AD_BROWSE_ID") > 0 || rs.getInt("AD_WORKBENCH_ID") > 0) {
                // Call CreateWindow.
                if (rs.getInt("AD_WINDOW_ID") > 0) {
                    packOut.createWindow(rs.getInt("AD_WINDOW_ID"), document);
                } else // Call CreateProcess.
                if (rs.getInt("AD_PROCESS_ID") > 0) {
                    packOut.createProcess(rs.getInt("AD_PROCESS_ID"), document);
                } else // Call CreateTask.
                if (rs.getInt("AD_TASK_ID") > 0) {
                    packOut.createTask(rs.getInt("AD_TASK_ID"), document);
                } else // Call CreateForm.
                if (rs.getInt("AD_FORM_ID") > 0) {
                    packOut.createForm(rs.getInt("AD_FORM_ID"), document);
                } else // Call CreateBrowse.
                if (rs.getInt("AD_BROWSE_ID") > 0) {
                    packOut.createBrowse(rs.getInt("AD_BROWSE_ID"), document);
                } else // Call CreateWorkflow
                if (rs.getInt("AD_Workflow_ID") > 0) {
                    packOut.createWorkflow(rs.getInt("AD_Workflow_ID"), document);
                }
            // Call CreateModule because entry is a summary menu
            } else {
                createModule(ctx, document, rs.getInt("Node_ID"));
            }
            document.endElement("", "", "menu");
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "getWindows", e);
    } finally {
        try {
            if (pstmt != null)
                pstmt.close();
        } catch (Exception e) {
        }
        pstmt = null;
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) X_AD_Menu(org.compiere.model.X_AD_Menu) PackOut(org.adempiere.pipo.PackOut) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SAXException(org.xml.sax.SAXException)

Aggregations

X_AD_Menu (org.compiere.model.X_AD_Menu)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SAXException (org.xml.sax.SAXException)3 AttributesImpl (org.xml.sax.helpers.AttributesImpl)3 PackOut (org.adempiere.pipo.PackOut)2 ResultSetMetaData (java.sql.ResultSetMetaData)1 MTree (org.compiere.model.MTree)1 MTree_NodeMM (org.compiere.model.MTree_NodeMM)1 Attributes (org.xml.sax.Attributes)1