Search in sources :

Example 1 with X_AD_Browse_Access

use of org.adempiere.model.X_AD_Browse_Access in project adempiere by adempiere.

the class RoleElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int Role_id = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID);
    if (roles.contains(Role_id))
        return;
    roles.add(Role_id);
    X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null);
    AttributesImpl atts = new AttributesImpl();
    createRoleBinding(atts, m_Role);
    document.startElement("", "", "role", atts);
    // Process org access
    String sql = "SELECT * FROM AD_Role_OrgAccess WHERE AD_Role_ID= " + Role_id;
    PreparedStatement pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createOrgAccess(ctx, document, rs.getInt("AD_Org_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Role_OrgAccess", e);
        throw new DatabaseAccessException("Failed to export organization role access.");
    }
    // Process user assignment access
    sql = "SELECT * FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createUserRole(ctx, document, rs.getInt("AD_User_ID"), rs.getInt("AD_Role_ID"), rs.getInt("AD_Org_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_User_Roles", e);
        throw new DatabaseAccessException("Failed to export user role assignment.");
    }
    // Process AD_Window_Access Values
    sql = "SELECT * FROM AD_Window_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createWindowAccess(ctx, document, rs.getInt("AD_Window_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Window_Access", e);
        throw new DatabaseAccessException("Failed to export window access.");
    }
    // Process AD_Process_Access Values
    sql = "SELECT * FROM AD_Process_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createProcessAccess(ctx, document, rs.getInt("AD_Process_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Process_Access", e);
        throw new DatabaseAccessException("Failed to export process access.");
    }
    // Process AD_Form_Access Values
    sql = "SELECT * FROM AD_Form_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createFormAccess(ctx, document, rs.getInt("AD_Form_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Form_Access", e);
        throw new DatabaseAccessException("Failed to export form access.");
    }
    // Process AD_Browse_Access
    String whereClause = I_AD_Browse_Access.COLUMNNAME_AD_Role_ID + "=?";
    List<X_AD_Browse_Access> browseaccess = new Query(ctx, I_AD_Browse_Access.Table_Name, whereClause, getTrxName(ctx)).setParameters(Role_id).list();
    for (X_AD_Browse_Access ba : browseaccess) {
        createBrowseAccess(ctx, document, ba.getAD_Browse_ID(), ba.getAD_Role_ID());
    }
    // Process AD_Workflow_Access Values
    sql = "SELECT * FROM AD_Workflow_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createWorkflowAccess(ctx, document, rs.getInt("AD_Workflow_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Workflow_Access", e);
        throw new DatabaseAccessException("Failed to export workflow access.");
    }
    // Process AD_Task_Access Values
    sql = "SELECT * FROM AD_Task_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createTaskAccess(ctx, document, rs.getInt("AD_Task_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Task_Access", e);
        throw new DatabaseAccessException("Failed to export task access.");
    } finally {
        try {
            if (pstmt != null)
                pstmt.close();
        } catch (Exception e) {
        }
        pstmt = null;
    }
    document.endElement("", "", "role");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Query(org.compiere.model.Query) X_AD_Browse_Access(org.adempiere.model.X_AD_Browse_Access) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) X_AD_Role(org.compiere.model.X_AD_Role) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) SAXException(org.xml.sax.SAXException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 X_AD_Browse_Access (org.adempiere.model.X_AD_Browse_Access)1 DatabaseAccessException (org.adempiere.pipo.exception.DatabaseAccessException)1 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)1 Query (org.compiere.model.Query)1 X_AD_Role (org.compiere.model.X_AD_Role)1 SAXException (org.xml.sax.SAXException)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1