/** * Get active activities count * * @return int */ public int getActivitiesCount() { int count = 0; String sql = "SELECT count(*) FROM AD_WF_Activity a " + "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 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()); MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx())); sql = role.addAccessSQL(sql, "a", true, false); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_User_ID); pstmt.setInt(2, AD_User_ID); pstmt.setInt(3, AD_User_ID); pstmt.setInt(4, AD_User_ID); rs = pstmt.executeQuery(); if (rs.next()) { count = rs.getInt(1); } } catch (Exception e) { log.log(Level.SEVERE, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } return count; }
/** * Load Activities * * @return int */ public int loadActivities() { long start = System.currentTimeMillis(); int MAX_ACTIVITIES_IN_LIST = MSysConfig.getIntValue("MAX_ACTIVITIES_IN_LIST", 200, Env.getAD_Client_ID(Env.getCtx())); model = new ListModelTable(); ArrayList<MWFActivity> list = new ArrayList<MWFActivity>(); String sql = "SELECT * FROM AD_WF_Activity a " + "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 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()); MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx())); sql = role.addAccessSQL(sql, "a", true, false); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_User_ID); pstmt.setInt(2, AD_User_ID); pstmt.setInt(3, AD_User_ID); pstmt.setInt(4, AD_User_ID); rs = pstmt.executeQuery(); while (rs.next()) { MWFActivity activity = new MWFActivity(Env.getCtx(), rs, null); list.add(activity); List<Object> rowData = new ArrayList<Object>(); rowData.add(activity.getPriority()); rowData.add(activity.getNodeName()); rowData.add(activity.getSummary()); model.add(rowData); if (list.size() > MAX_ACTIVITIES_IN_LIST && MAX_ACTIVITIES_IN_LIST > 0) { log.warning("More then 200 Activities - ignored"); break; } } } catch (Exception e) { log.log(Level.SEVERE, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } m_activities = new MWFActivity[list.size()]; list.toArray(m_activities); // log.fine("#" + m_activities.length + "(" + (System.currentTimeMillis() - start) + "ms)"); m_index = 0; String[] columns = new String[] { Msg.translate(Env.getCtx(), "Priority"), Msg.translate(Env.getCtx(), "AD_WF_Node_ID"), Msg.translate(Env.getCtx(), "Summary") }; WListItemRenderer renderer = new WListItemRenderer(Arrays.asList(columns)); ListHeader header = new ListHeader(); header.setWidth("30px"); renderer.setListHeader(0, header); renderer.addTableValueChangeListener(listbox); model.setNoColumns(columns.length); listbox.setModel(model); listbox.setItemRenderer(renderer); listbox.repaint(); listbox.setFixedLayout(true); return m_activities.length; } // loadActivities