IDEMPIERE-86 Workflow Activities problems

http://jira.idempiere.com/browse/IDEMPIERE-86
This commit is contained in:
Carlos Ruiz 2011-10-20 21:42:29 -05:00
parent 7d62972f28
commit 29ed9dd002
4 changed files with 67 additions and 68 deletions

View File

@ -785,6 +785,7 @@ public final class AMenu extends CFrame
{ {
if (e.getClickCount() > 1) if (e.getClickCount() > 1)
{ {
updateInfo();
System.gc(); System.gc();
//updateInfo(); //updateInfo();
} }

View File

@ -92,7 +92,7 @@ public class WFActivity extends CPanel
/** /**
* *
*/ */
private static final long serialVersionUID = 6917300855914216420L; private static final long serialVersionUID = 3900449055030897013L;
private static final int MAX_ACTIVITIES_IN_LIST = MSysConfig.getIntValue("MAX_ACTIVITIES_IN_LIST", 200, Env.getAD_Client_ID(Env.getCtx())); private static final int MAX_ACTIVITIES_IN_LIST = MSysConfig.getIntValue("MAX_ACTIVITIES_IN_LIST", 200, Env.getAD_Client_ID(Env.getCtx()));
@ -382,22 +382,10 @@ public class WFActivity extends CPanel
{ {
int count = 0; int count = 0;
String sql = "SELECT count(*) FROM AD_WF_Activity a " String sql = "SELECT COUNT(*) FROM AD_WF_Activity a "
+ "WHERE a.Processed='N' AND a.WFState='OS' AND (" + "WHERE " + getWhereActivities();
// Owner of Activity
+ " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.AD_User_ID=?)" // #3
// Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?))"; // #4
//
//+ ") ORDER BY a.Priority DESC, Created";
int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx())); MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
sql = role.addAccessSQL(sql, "a", true, false); sql = role.addAccessSQL(sql, "a", true, false);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -409,6 +397,7 @@ public class WFActivity extends CPanel
pstmt.setInt (2, AD_User_ID); pstmt.setInt (2, AD_User_ID);
pstmt.setInt (3, AD_User_ID); pstmt.setInt (3, AD_User_ID);
pstmt.setInt (4, AD_User_ID); pstmt.setInt (4, AD_User_ID);
pstmt.setInt (5, AD_Client_ID);
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) { if (rs.next ()) {
count = rs.getInt(1); count = rs.getInt(1);
@ -434,27 +423,15 @@ public class WFActivity extends CPanel
*/ */
public int loadActivities() public int loadActivities()
{ {
resetDisplay(null);
while (selTableModel.getRowCount() > 0) while (selTableModel.getRowCount() > 0)
selTableModel.removeRow(0); selTableModel.removeRow(0);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
ArrayList<MWFActivity> list = new ArrayList<MWFActivity>(); ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
String sql = "SELECT * FROM AD_WF_Activity a " String sql = "SELECT * FROM AD_WF_Activity a "
+ "WHERE a.Processed='N' AND a.WFState='OS' AND (" + "WHERE " + getWhereActivities()
// Owner of Activity + " ORDER BY a.Priority DESC, Created";
+ " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.AD_User_ID=?)" // #3
// Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" // #4
//
+ ") ORDER BY a.Priority DESC, Created";
int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx())); MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
sql = role.addAccessSQL(sql, "a", true, false); sql = role.addAccessSQL(sql, "a", true, false);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -466,6 +443,7 @@ public class WFActivity extends CPanel
pstmt.setInt (2, AD_User_ID); pstmt.setInt (2, AD_User_ID);
pstmt.setInt (3, AD_User_ID); pstmt.setInt (3, AD_User_ID);
pstmt.setInt (4, AD_User_ID); pstmt.setInt (4, AD_User_ID);
pstmt.setInt (5, AD_Client_ID);
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
@ -495,13 +473,32 @@ public class WFActivity extends CPanel
rs = null; pstmt = null; rs = null; pstmt = null;
} }
selTable.autoSize(false); selTable.autoSize(false);
display(null);
log.fine("#" + selTable.getModel().getRowCount() log.fine("#" + selTable.getModel().getRowCount()
+ "(" + (System.currentTimeMillis()-start) + "ms)"); + "(" + (System.currentTimeMillis()-start) + "ms)");
return selTable.getModel().getRowCount(); return selTable.getModel().getRowCount();
} // loadActivities } // loadActivities
private String getWhereActivities() {
final String where =
"a.Processed='N' AND a.WFState='OS' AND ("
// Owner of Activity
+ " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.ResponsibleType='H' AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.ResponsibleType='H' AND r.AD_User_ID=?)" // #3
// Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND r.ResponsibleType='R' AND ur.AD_User_ID=?)" // #4
//
+ ") AND a.AD_Client_ID=?"; // #5
return where;
}
/** /**
* Display. * Display.
* @param index index of table * @param index index of table

View File

@ -296,22 +296,10 @@ public class WWFActivity extends ADForm implements EventListener
{ {
int count = 0; int count = 0;
String sql = "SELECT count(*) FROM AD_WF_Activity a " String sql = "SELECT COUNT(*) FROM AD_WF_Activity a "
+ "WHERE a.Processed='N' AND a.WFState='OS' AND (" + "WHERE " + getWhereActivities();
// Owner of Activity
+ " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.AD_User_ID=?)" // #3
// Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?))"; // #4
//
//+ ") ORDER BY a.Priority DESC, Created";
int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx())); MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
sql = role.addAccessSQL(sql, "a", true, false); sql = role.addAccessSQL(sql, "a", true, false);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -323,6 +311,7 @@ public class WWFActivity extends ADForm implements EventListener
pstmt.setInt (2, AD_User_ID); pstmt.setInt (2, AD_User_ID);
pstmt.setInt (3, AD_User_ID); pstmt.setInt (3, AD_User_ID);
pstmt.setInt (4, AD_User_ID); pstmt.setInt (4, AD_User_ID);
pstmt.setInt (5, AD_Client_ID);
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) { if (rs.next ()) {
count = rs.getInt(1); count = rs.getInt(1);
@ -356,21 +345,10 @@ public class WWFActivity extends ADForm implements EventListener
ArrayList<MWFActivity> list = new ArrayList<MWFActivity>(); ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
String sql = "SELECT * FROM AD_WF_Activity a " String sql = "SELECT * FROM AD_WF_Activity a "
+ "WHERE a.Processed='N' AND a.WFState='OS' AND (" + "WHERE " + getWhereActivities()
// Owner of Activity + " ORDER BY a.Priority DESC, Created";
+ " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.AD_User_ID=?)" // #3
// Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" // #4
//
+ ") ORDER BY a.Priority DESC, Created";
int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx())); MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
sql = role.addAccessSQL(sql, "a", true, false); sql = role.addAccessSQL(sql, "a", true, false);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -382,6 +360,7 @@ public class WWFActivity extends ADForm implements EventListener
pstmt.setInt (2, AD_User_ID); pstmt.setInt (2, AD_User_ID);
pstmt.setInt (3, AD_User_ID); pstmt.setInt (3, AD_User_ID);
pstmt.setInt (4, AD_User_ID); pstmt.setInt (4, AD_User_ID);
pstmt.setInt (5, AD_Client_ID);
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
@ -433,6 +412,25 @@ public class WWFActivity extends ADForm implements EventListener
return m_activities.length; return m_activities.length;
} // loadActivities } // loadActivities
private String getWhereActivities() {
final String where =
"a.Processed='N' AND a.WFState='OS' AND ("
// Owner of Activity
+ " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.ResponsibleType='H' AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.ResponsibleType='H' AND r.AD_User_ID=?)" // #3
// Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND r.ResponsibleType='R' AND ur.AD_User_ID=?)" // #4
//
+ ") AND a.AD_Client_ID=?"; // #5
return where;
}
/** /**
* Reset Display * Reset Display
* @param selIndex select index * @param selIndex select index
@ -605,7 +603,7 @@ public class WWFActivity extends ADForm implements EventListener
// //
MWFNode node = m_activity.getNode(); MWFNode node = m_activity.getNode();
Object forward = null;//fForward.getValue(); Object forward = fForward.getValue();
// ensure activity is ran within a transaction - [ 1953628 ] // ensure activity is ran within a transaction - [ 1953628 ]
Trx trx = null; Trx trx = null;

View File

@ -132,21 +132,23 @@ public class DPActivities extends DashboardPanel implements EventListener {
int count = 0; int count = 0;
String sql = "SELECT count(*) FROM AD_WF_Activity a " String sql = "SELECT count(*) FROM AD_WF_Activity a "
+ "WHERE a.Processed='N' AND a.WFState='OS' AND (" + "WHERE "
+ "a.Processed='N' AND a.WFState='OS' AND ("
// Owner of Activity // Owner of Activity
+ " a.AD_User_ID=?" // #1 + " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all) // Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2 + " AND r.ResponsibleType='H' AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User // Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.AD_User_ID=?)" // #3 + " AND r.ResponsibleType='H' AND r.AD_User_ID=?)" // #3
// Responsible Role // Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)" + " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?))"; // #4 + " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND r.ResponsibleType='R' AND ur.AD_User_ID=?)" // #4
// //
//+ ") ORDER BY a.Priority DESC, Created"; + ") AND a.AD_Client_ID=?"; // #5
int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try try
@ -156,6 +158,7 @@ public class DPActivities extends DashboardPanel implements EventListener {
pstmt.setInt (2, AD_User_ID); pstmt.setInt (2, AD_User_ID);
pstmt.setInt (3, AD_User_ID); pstmt.setInt (3, AD_User_ID);
pstmt.setInt (4, AD_User_ID); pstmt.setInt (4, AD_User_ID);
pstmt.setInt (5, AD_Client_ID);
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) { if (rs.next ()) {
count = rs.getInt(1); count = rs.getInt(1);