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