BT 2777077 Copy Role doesn't copy document action access
https://sourceforge.net/tracker/?func=detail&aid=2777077&group_id=176962&atid=879332
This commit is contained in:
parent
2be6a1d26f
commit
ac7eedb48b
|
@ -19,18 +19,17 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.process;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.logging.Level;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
|
||||
/**
|
||||
* Convert AD to XML
|
||||
* Copy role access records
|
||||
*
|
||||
* @author Robert Klein
|
||||
* @ author Paul Bowden
|
||||
* @version $Id: CopyRole.java,v 1.0$
|
||||
*
|
||||
*/
|
||||
|
@ -41,8 +40,6 @@ public class CopyRole extends SvrProcess
|
|||
private int m_AD_Role_ID_To = 0;
|
||||
private int m_AD_Client_ID = 0;
|
||||
private int m_AD_Org_ID = 0;
|
||||
StringBuffer sqlB = null;
|
||||
private Object[] m_newValues = null;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
|
@ -53,8 +50,8 @@ public class CopyRole extends SvrProcess
|
|||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("AD_Role_ID") && i == 0)
|
||||
m_AD_Role_ID_From = para[i].getParameterAsInt();
|
||||
|
@ -66,268 +63,53 @@ public class CopyRole extends SvrProcess
|
|||
m_AD_Org_ID = para[i].getParameterAsInt();
|
||||
}
|
||||
} // prepare
|
||||
|
||||
|
||||
/**
|
||||
* Start the transformation to XML
|
||||
* Copy the role access records
|
||||
* @return info
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt() throws java.lang.Exception
|
||||
{
|
||||
//Process AD_Window_Access Values
|
||||
String sql = "SELECT * FROM AD_Window_Access WHERE AD_Role_ID= " + m_AD_Role_ID_From;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
try {
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
|
||||
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Window_Access "
|
||||
+ "WHERE AD_Role_ID=? and AD_Window_ID=?"
|
||||
+ "and AD_Client_ID = " + m_AD_Client_ID
|
||||
+ "and AD_Org_ID= " + m_AD_Org_ID);
|
||||
|
||||
int count = DB.getSQLValue(null,sqlB.toString(),m_AD_Role_ID_To,rs.getInt("AD_Window_ID"));
|
||||
|
||||
if (count>0){
|
||||
sqlB = new StringBuffer ("UPDATE AD_Window_Access "
|
||||
+ "SET isActive = '" + rs.getString("isActive")
|
||||
+ "', isReadWrite = '" + rs.getString("isReadWrite")
|
||||
+ "' WHERE AD_Client_ID = " + m_AD_Client_ID
|
||||
+ " and AD_Org_ID = " + m_AD_Org_ID
|
||||
+ " and AD_Role_ID = " + m_AD_Role_ID_To
|
||||
+ " and AD_Window_ID = " + rs.getInt("AD_Window_ID") );
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
else{
|
||||
|
||||
sqlB = new StringBuffer ("Insert INTO AD_Window_Access"
|
||||
+ "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
|
||||
+ "AD_Role_ID, AD_Window_ID, isActive, isReadWrite) "
|
||||
+ "VALUES("
|
||||
+ " "+ m_AD_Client_ID
|
||||
+ ", "+ m_AD_Org_ID
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", " + m_AD_Role_ID_To
|
||||
+ ", " + rs.getInt("AD_Window_ID")
|
||||
+ ", '" + rs.getString("isActive")
|
||||
+ "', '" + rs.getString("isReadWrite")+"')");
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.log(Level.SEVERE,"CreateRoles-Window Access", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
//Process AD_Process_Access Values
|
||||
sql = "SELECT * FROM AD_Process_Access WHERE AD_Role_ID= " + m_AD_Role_ID_From;
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
try {
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Process_Access "
|
||||
+ "WHERE AD_Role_ID=? AND AD_Process_ID=?"
|
||||
+ "AND AD_Client_ID = " + m_AD_Client_ID
|
||||
+ "and AD_Org_ID= " + m_AD_Org_ID);
|
||||
int count = DB.getSQLValue(null,sqlB.toString(),m_AD_Role_ID_To,rs.getInt("AD_Process_ID"));
|
||||
protected String doIt() throws Exception
|
||||
{
|
||||
String[] tables = new String[] {"AD_Window_Access", "AD_Process_Access", "AD_Form_Access",
|
||||
"AD_Workflow_Access", "AD_Task_Access", "AD_Document_Action_Access"};
|
||||
String[] keycolumns = new String[] {"AD_Window_ID", "AD_Process_ID", "AD_Form_ID",
|
||||
"AD_Workflow_ID", "AD_Task_ID", "C_DocType_ID, AD_Ref_List_ID"};
|
||||
|
||||
int action = 0;
|
||||
|
||||
for ( int i = 0; i < tables.length; i++ )
|
||||
{
|
||||
String table = tables[i];
|
||||
String keycolumn = keycolumns[i];
|
||||
|
||||
if (count>0){
|
||||
sqlB = new StringBuffer ("UPDATE AD_Process_Access "
|
||||
+ "SET isActive = '" + rs.getString("isActive")
|
||||
+ "', isReadWrite = '" + rs.getString("isReadWrite")
|
||||
+ "' WHERE AD_Client_ID = " + m_AD_Client_ID
|
||||
+ " and AD_Org_ID = " + m_AD_Org_ID
|
||||
+ " and AD_Role_ID = " + m_AD_Role_ID_To
|
||||
+ " and AD_Process_ID = " + rs.getInt("AD_Process_ID") );
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
else{
|
||||
sqlB = new StringBuffer ("Insert INTO AD_Process_Access"
|
||||
+ "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
|
||||
+ "AD_Role_ID, AD_Process_ID, isActive, isReadWrite) "
|
||||
+ "VALUES("
|
||||
+ " "+ m_AD_Client_ID
|
||||
+ ", "+ m_AD_Org_ID
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", " + m_AD_Role_ID_To
|
||||
+ ", " + rs.getInt("AD_Process_ID")
|
||||
+ ", '" + rs.getString("isActive")
|
||||
+ "', '" + rs.getString("isReadWrite")+"')");
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.log(Level.SEVERE,"CreateRoles-AD_Process", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
// Process AD_Form_Access Values
|
||||
sql = "SELECT * FROM AD_Form_Access WHERE AD_Role_ID= " + m_AD_Role_ID_From;
|
||||
pstmt = null;
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
try {
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Form_Access "
|
||||
+ "WHERE AD_Role_ID=? AND AD_Form_ID=?"
|
||||
+ "AND AD_Client_ID = " + m_AD_Client_ID
|
||||
+ "and AD_Org_ID= " + m_AD_Org_ID);
|
||||
int count = DB.getSQLValue(null,sqlB.toString(),m_AD_Role_ID_To,rs.getInt("AD_Form_ID"));
|
||||
if (count>0){
|
||||
sqlB = new StringBuffer ("UPDATE AD_Form_Access "
|
||||
+ "SET isActive = '" + rs.getString("isActive")
|
||||
+ "', isReadWrite = '" + rs.getString("isReadWrite")
|
||||
+ "' WHERE AD_Client_ID = " + m_AD_Client_ID
|
||||
+ " and AD_Org_ID = " + m_AD_Org_ID
|
||||
+ " and AD_Role_ID = " + m_AD_Role_ID_To
|
||||
+ " and AD_Form_ID = " + rs.getInt("AD_Form_ID") );
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
else{
|
||||
sqlB = new StringBuffer ("Insert INTO AD_Form_Access"
|
||||
+ "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
|
||||
+ "AD_Role_ID, AD_Form_ID, isActive, isReadWrite) "
|
||||
+ "VALUES("
|
||||
+ " "+ m_AD_Client_ID
|
||||
+ ", "+ m_AD_Org_ID
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", " + m_AD_Role_ID_To
|
||||
+ ", " + rs.getInt("AD_Form_ID")
|
||||
+ ", '" + rs.getString("isActive")
|
||||
+ "', '" + rs.getString("isReadWrite")+"')");
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.log(Level.SEVERE,"CreateRoles-Form Access", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
// Process AD_Workflow_Access Values
|
||||
sql = "SELECT * FROM AD_Workflow_Access WHERE AD_Role_ID= " + m_AD_Role_ID_From;
|
||||
pstmt = null;
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
try {
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Workflow_Access "
|
||||
+ "WHERE AD_Role_ID=? AND AD_Workflow_ID=?"
|
||||
+ "AND AD_Client_ID = " + m_AD_Client_ID
|
||||
+ "and AD_Org_ID= " + m_AD_Org_ID);
|
||||
int count = DB.getSQLValue(null,sqlB.toString(),m_AD_Role_ID_To,rs.getInt("AD_Workflow_ID"));
|
||||
|
||||
if (count>0){
|
||||
sqlB = new StringBuffer ("UPDATE AD_Workflow_Access "
|
||||
+ "SET isActive = '" + rs.getString("isActive")
|
||||
+ "', isReadWrite = '" + rs.getString("isReadWrite")
|
||||
+ "' WHERE AD_Client_ID = " + m_AD_Client_ID
|
||||
+ " and AD_Org_ID = " + m_AD_Org_ID
|
||||
+ " and AD_Role_ID = " + m_AD_Role_ID_To
|
||||
+ " and AD_Workflow_ID = " + rs.getInt("AD_Workflow_ID") );
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
else{
|
||||
|
||||
sqlB = new StringBuffer ("Insert INTO AD_Workflow_Access"
|
||||
+ "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
|
||||
+ "AD_Role_ID, AD_Workflow_ID, isActive, isReadWrite) "
|
||||
+ "VALUES("
|
||||
+ " "+ m_AD_Client_ID
|
||||
+ ", "+ m_AD_Org_ID
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", " + m_AD_Role_ID_To
|
||||
+ ", " + rs.getInt("AD_Workflow_ID")
|
||||
+ ", '" + rs.getString("isActive")
|
||||
+ "', '" + rs.getString("isReadWrite")+"')");
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
log.log(Level.SEVERE,"CreateRoles-Workflow", e);
|
||||
}
|
||||
String sql = "DELETE FROM " + table + " WHERE AD_Role_ID = " + m_AD_Role_ID_To;
|
||||
int no = DB.executeUpdateEx(sql, get_TrxName());
|
||||
addLog(action++, null, new BigDecimal(no), "Old records deleted from " + table );
|
||||
|
||||
// Process AD_Task_Access Values
|
||||
sql = "SELECT * FROM AD_Task_Access WHERE AD_Role_ID= " + m_AD_Role_ID_From;
|
||||
pstmt = null;
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
try {
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Task_Access "
|
||||
+ "WHERE AD_Role_ID=? AND AD_Task_ID=?"
|
||||
+ "AND AD_Client_ID = " + m_AD_Client_ID
|
||||
+ "and AD_Org_ID= " + m_AD_Org_ID);
|
||||
int count = DB.getSQLValue(null,sqlB.toString(),m_AD_Role_ID_To,rs.getInt("AD_Task_ID"));
|
||||
|
||||
if (count>0){
|
||||
sqlB = new StringBuffer ("UPDATE AD_Task_Access "
|
||||
+ "SET isActive = '" + rs.getString("isActive")
|
||||
+ "', isReadWrite = '" + rs.getString("isReadWrite")
|
||||
+ "' WHERE AD_Client_ID = " + m_AD_Client_ID
|
||||
+ " and AD_Org_ID = " + m_AD_Org_ID
|
||||
+ " and AD_Role_ID = " + m_AD_Role_ID_To
|
||||
+ " and AD_Task_ID = " + rs.getInt("AD_Task_ID") );
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
else{
|
||||
|
||||
sqlB = new StringBuffer ("Insert INTO AD_Task_Access"
|
||||
+ "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
|
||||
+ "AD_Role_ID, AD_Task_ID, isActive, isReadWrite) "
|
||||
+ "VALUES("
|
||||
+ " "+ m_AD_Client_ID
|
||||
+ ", "+ m_AD_Org_ID
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", " + m_AD_Role_ID_To
|
||||
+ ", " + rs.getInt("AD_Task_ID")
|
||||
+ ", '" + rs.getString("isActive")
|
||||
+ "', '" + rs.getString("isReadWrite")+"')");
|
||||
sql = "Insert INTO " + table
|
||||
+ " (AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
|
||||
+ "AD_Role_ID, " + keycolumn +", isActive";
|
||||
if ( ! table.equals("AD_Document_Action_Access"))
|
||||
sql += ", isReadWrite) ";
|
||||
else
|
||||
sql += ") ";
|
||||
sql += "SELECT " + m_AD_Client_ID
|
||||
+ ", "+ m_AD_Org_ID
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", "+ Env.getAD_User_ID(Env.getCtx())
|
||||
+ ", " + m_AD_Role_ID_To
|
||||
+ ", " + keycolumn
|
||||
+ ", IsActive ";
|
||||
if ( ! table.equals("AD_Document_Action_Access") )
|
||||
sql += ", isReadWrite ";
|
||||
sql += "FROM " + table + " WHERE AD_Role_ID = " + m_AD_Role_ID_From;
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
log.log(Level.SEVERE,"CreateRoles-Task", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
return "";
|
||||
no = DB.executeUpdateEx (sql, get_TrxName());
|
||||
|
||||
addLog(action++, null, new BigDecimal(no), "New records inserted into " + table );
|
||||
}
|
||||
|
||||
return "Role copied";
|
||||
} // doIt
|
||||
} // CopyRole
|
||||
|
|
Loading…
Reference in New Issue