IDEMPIERE-294 BroadCast Message / Peer review

This commit is contained in:
Carlos Ruiz 2012-12-02 23:59:49 -05:00
parent f992cef2d7
commit 2de5900c6c
10 changed files with 238 additions and 1388 deletions

File diff suppressed because it is too large Load Diff

View File

@ -70,17 +70,17 @@ public class MBroadcastMessage extends X_AD_BroadcastMessage
{
Properties ctx = Env.getCtx();
if(getBroadcastType()!=null && getBroadcastType().equals("I") && getTarget()!=null){
if (getTarget().equals("R") ) {
String SQL = "select count(*) from ad_user_roles where ad_role_id = ? and ad_User_ID=?";
int roleSubs = DB.getSQLValue(null, SQL, getAD_Role_ID(),Env.getAD_User_ID(ctx));
if(getBroadcastType()!=null && getBroadcastType().equals(BROADCASTTYPE_Immediate) && getTarget()!=null){
if (getTarget().equals(TARGET_Role) ) {
String sql = "SELECT COUNT(*) FROM AD_User_Roles WHERE AD_Role_ID = ? AND AD_User_ID=? AND IsActive='Y'";
int roleSubs = DB.getSQLValue(null, sql, getAD_Role_ID(),Env.getAD_User_ID(ctx));
if(roleSubs>0)
return true;
} else if (getTarget().equals("U") && getAD_User_ID() == Env.getAD_User_ID(ctx)) {
} else if (getTarget().equals(TARGET_User) && getAD_User_ID() == Env.getAD_User_ID(ctx)) {
return true;
} else if (getTarget().equals("C") && getAD_Client_ID() == Env.getAD_Client_ID(ctx)) {
} else if (getTarget().equals(TARGET_Client) && getAD_Client_ID() == Env.getAD_Client_ID(ctx)) {
return true;
}else if (getTarget().equals("E")){
}else if (getTarget().equals(TARGET_Everybody)){
return true;
}
}
@ -88,7 +88,7 @@ public class MBroadcastMessage extends X_AD_BroadcastMessage
int AD_User_ID = Env.getAD_User_ID(ctx);
String sql = "SELECT AD_User_ID from AD_Note WHERE AD_BroadcastMessage_ID = ? AND AD_User_ID = ? ";
int result = DB.getSQLValue(null, sql,getAD_Broadcastmessage_ID(),AD_User_ID);
int result = DB.getSQLValue(null, sql,getAD_BroadcastMessage_ID(),AD_User_ID);
if (result <= 0) {
return false;
}

View File

@ -1,6 +1,6 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *
* Product: iDempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2012 ComPiere, Inc. All Rights Reserved. *
* This program is free software, you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
@ -21,8 +21,8 @@ import java.sql.Timestamp;
import org.compiere.util.KeyNamePair;
/** Generated Interface for AD_BroadcastMessage
* @author Adempiere (generated)
* @version Release 3.6.0LTS
* @author iDempiere (generated)
* @version Release 1.0a
*/
public interface I_AD_BroadcastMessage
{
@ -30,7 +30,7 @@ public interface I_AD_BroadcastMessage
/** TableName=AD_BroadcastMessage */
public static final String Table_Name = "AD_BroadcastMessage";
/** AD_Table_ID=200024 */
/** AD_Table_ID=200038 */
public static final int Table_ID = 200038;
KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);
@ -41,18 +41,27 @@ public interface I_AD_BroadcastMessage
/** Load Meta Data */
/** Column name AD_Broadcastmessage_ID */
public static final String COLUMNNAME_AD_Broadcastmessage_ID = "AD_Broadcastmessage_ID";
/** Column name AD_BroadcastMessage_ID */
public static final String COLUMNNAME_AD_BroadcastMessage_ID = "AD_BroadcastMessage_ID";
/** Set Broadcast Message.
* Broadcast Message
*/
public void setAD_Broadcastmessage_ID (int AD_Broadcastmessage_ID);
public void setAD_BroadcastMessage_ID (int AD_BroadcastMessage_ID);
/** Get Broadcast Message.
* Broadcast Message
*/
public int getAD_Broadcastmessage_ID();
public int getAD_BroadcastMessage_ID();
/** Column name AD_BroadcastMessage_UU */
public static final String COLUMNNAME_AD_BroadcastMessage_UU = "AD_BroadcastMessage_UU";
/** Set AD_BroadcastMessage_UU */
public void setAD_BroadcastMessage_UU (String AD_BroadcastMessage_UU);
/** Get AD_BroadcastMessage_UU */
public String getAD_BroadcastMessage_UU();
/** Column name AD_Client_ID */
public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID";
@ -163,13 +172,13 @@ public interface I_AD_BroadcastMessage
/** Column name Expiration */
public static final String COLUMNNAME_Expiration = "Expiration";
/** Set Expiration.
* Expiration
/** Set Expire On.
* Expire On
*/
public void setExpiration (Timestamp Expiration);
/** Get Expiration.
* Expiration
/** Get Expire On.
* Expire On
*/
public Timestamp getExpiration();
@ -234,14 +243,18 @@ public interface I_AD_BroadcastMessage
*/
public boolean isLogAcknowledge();
/** Column name Notification_Client */
public static final String COLUMNNAME_Notification_Client = "Notification_Client";
/** Column name Notification_Client_ID */
public static final String COLUMNNAME_Notification_Client_ID = "Notification_Client_ID";
/** Set Notification_Client */
public void setNotification_Client (int Notification_Client);
/** Set Notification Client.
* Notification Client
*/
public void setNotification_Client_ID (int Notification_Client_ID);
/** Get Notification_Client */
public int getNotification_Client();
/** Get Notification Client.
* Notification Client
*/
public int getNotification_Client_ID();
/** Column name Processed */
public static final String COLUMNNAME_Processed = "Processed";

View File

@ -1,6 +1,6 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *
* Product: iDempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2012 ComPiere, Inc. All Rights Reserved. *
* This program is free software, you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
@ -22,15 +22,15 @@ import java.sql.Timestamp;
import java.util.Properties;
/** Generated Model for AD_BroadcastMessage
* @author Adempiere (generated)
* @version Release 3.6.0LTS - $Id$ */
* @author iDempiere (generated)
* @version Release 1.0a - $Id$ */
public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage, I_Persistent
{
/**
*
*/
private static final long serialVersionUID = 20121107L;
private static final long serialVersionUID = 20121202L;
/** Standard Constructor */
public X_AD_BroadcastMessage (Properties ctx, int AD_BroadcastMessage_ID, String trxName)
@ -38,6 +38,11 @@ public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage,
super (ctx, AD_BroadcastMessage_ID, trxName);
/** if (AD_BroadcastMessage_ID == 0)
{
setAD_BroadcastMessage_ID (0);
setBroadcastFrequency (null);
setBroadcastMessage (null);
setBroadcastType (null);
setTarget (null);
} */
}
@ -70,28 +75,42 @@ public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage,
}
/** Set Broadcast Message.
@param AD_Broadcastmessage_ID
@param AD_BroadcastMessage_ID
Broadcast Message
*/
public void setAD_Broadcastmessage_ID (int AD_Broadcastmessage_ID)
public void setAD_BroadcastMessage_ID (int AD_BroadcastMessage_ID)
{
if (AD_Broadcastmessage_ID < 1)
set_ValueNoCheck (COLUMNNAME_AD_Broadcastmessage_ID, null);
if (AD_BroadcastMessage_ID < 1)
set_ValueNoCheck (COLUMNNAME_AD_BroadcastMessage_ID, null);
else
set_ValueNoCheck (COLUMNNAME_AD_Broadcastmessage_ID, Integer.valueOf(AD_Broadcastmessage_ID));
set_ValueNoCheck (COLUMNNAME_AD_BroadcastMessage_ID, Integer.valueOf(AD_BroadcastMessage_ID));
}
/** Get Broadcast Message.
@return Broadcast Message
*/
public int getAD_Broadcastmessage_ID ()
public int getAD_BroadcastMessage_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_AD_Broadcastmessage_ID);
Integer ii = (Integer)get_Value(COLUMNNAME_AD_BroadcastMessage_ID);
if (ii == null)
return 0;
return ii.intValue();
}
/** Set AD_BroadcastMessage_UU.
@param AD_BroadcastMessage_UU AD_BroadcastMessage_UU */
public void setAD_BroadcastMessage_UU (String AD_BroadcastMessage_UU)
{
set_Value (COLUMNNAME_AD_BroadcastMessage_UU, AD_BroadcastMessage_UU);
}
/** Get AD_BroadcastMessage_UU.
@return AD_BroadcastMessage_UU */
public String getAD_BroadcastMessage_UU ()
{
return (String)get_Value(COLUMNNAME_AD_BroadcastMessage_UU);
}
public org.compiere.model.I_AD_Role getAD_Role() throws RuntimeException
{
return (org.compiere.model.I_AD_Role)MTable.get(getCtx(), org.compiere.model.I_AD_Role.Table_Name)
@ -148,8 +167,8 @@ public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage,
return ii.intValue();
}
/** BroadcastFrequency AD_Reference_ID=200010 */
public static final int BROADCASTFREQUENCY_AD_Reference_ID=200010;
/** BroadcastFrequency AD_Reference_ID=200020 */
public static final int BROADCASTFREQUENCY_AD_Reference_ID=200020;
/** Just Once = J */
public static final String BROADCASTFREQUENCY_JustOnce = "J";
/** Until Expiration = U */
@ -189,14 +208,14 @@ public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage,
return (String)get_Value(COLUMNNAME_BroadcastMessage);
}
/** BroadcastType AD_Reference_ID=200009 */
public static final int BROADCASTTYPE_AD_Reference_ID=200009;
/** Login = L */
public static final String BROADCASTTYPE_Login = "L";
/** BroadcastType AD_Reference_ID=200021 */
public static final int BROADCASTTYPE_AD_Reference_ID=200021;
/** Immediate = I */
public static final String BROADCASTTYPE_Immediate = "I";
/** Immediate + Login = IL */
public static final String BROADCASTTYPE_ImmediatePlusLogin = "IL";
/** Login = L */
public static final String BROADCASTTYPE_Login = "L";
/** Set Broadcast Type.
@param BroadcastType
Type of Broadcast
@ -215,17 +234,17 @@ public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage,
return (String)get_Value(COLUMNNAME_BroadcastType);
}
/** Set Expiration.
/** Set Expire On.
@param Expiration
Expiration
Expire On
*/
public void setExpiration (Timestamp Expiration)
{
set_Value (COLUMNNAME_Expiration, Expiration);
}
/** Get Expiration.
@return Expiration
/** Get Expire On.
@return Expire On
*/
public Timestamp getExpiration ()
{
@ -318,18 +337,24 @@ public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage,
return false;
}
/** Set Notification_Client.
@param Notification_Client Notification_Client */
public void setNotification_Client (int Notification_Client)
/** Set Notification Client.
@param Notification_Client_ID
Notification Client
*/
public void setNotification_Client_ID (int Notification_Client_ID)
{
set_Value (COLUMNNAME_Notification_Client, Integer.valueOf(Notification_Client));
if (Notification_Client_ID < 1)
set_Value (COLUMNNAME_Notification_Client_ID, null);
else
set_Value (COLUMNNAME_Notification_Client_ID, Integer.valueOf(Notification_Client_ID));
}
/** Get Notification_Client.
@return Notification_Client */
public int getNotification_Client ()
/** Get Notification Client.
@return Notification Client
*/
public int getNotification_Client_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_Notification_Client);
Integer ii = (Integer)get_Value(COLUMNNAME_Notification_Client_ID);
if (ii == null)
return 0;
return ii.intValue();
@ -376,16 +401,16 @@ public class X_AD_BroadcastMessage extends PO implements I_AD_BroadcastMessage,
return (String)get_Value(COLUMNNAME_Publish);
}
/** Target AD_Reference_ID=200011 */
public static final int TARGET_AD_Reference_ID=200011;
/** Everybody = E */
public static final String TARGET_Everybody = "E";
/** Target AD_Reference_ID=200022 */
public static final int TARGET_AD_Reference_ID=200022;
/** Client = C */
public static final String TARGET_Client = "C";
/** User = U */
public static final String TARGET_User = "U";
/** Everybody = E */
public static final String TARGET_Everybody = "E";
/** Role = R */
public static final String TARGET_Role = "R";
/** User = U */
public static final String TARGET_User = "U";
/** Set Target.
@param Target
Target client

View File

@ -16,13 +16,12 @@ package org.idempiere.broadcast;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import org.adempiere.base.event.EventManager;
import org.adempiere.base.event.IEventTopics;
import org.adempiere.exceptions.DBException;
import org.adempiere.model.MBroadcastMessage;
import org.compiere.model.MNote;
import org.compiere.util.CLogger;
@ -55,53 +54,35 @@ public class BroadcastMsgUtil
if (MBroadcastMessage.BROADCASTTYPE_Login.equals(broadcastType)
|| MBroadcastMessage.BROADCASTTYPE_ImmediatePlusLogin.equals(broadcastType)) {
// get list of users based on rule
ArrayList<Integer> userIDs = new ArrayList<Integer>();
String SQL = "";
if (mbMessage.getTarget() != null) {
String sql = "SELECT DISTINCT(AD_User_ID) FROM AD_User_Roles WHERE IsActive='Y'";
// Role
if (mbMessage.getTarget().equals("R")) {
SQL = "select DISTINCT(ad_user_id) from ad_user_roles where ad_role_id = "
+ mbMessage.getAD_Role_ID();
} else if (mbMessage.getTarget().equals("U")) {
SQL = "select DISTINCT(ad_user_id) from ad_user_roles where ad_user_id = "
+ mbMessage.getAD_User_ID();
} else if (mbMessage.getTarget().equals("C")) {
SQL = "select DISTINCT(ad_user_id) from ad_user_roles where ad_client_id = "
+ mbMessage.getNotification_Client();
} else if (mbMessage.getTarget().equals("E")) {
SQL = "select DISTINCT(ad_user_id) from ad_user_roles";
if (mbMessage.getTarget().equals(MBroadcastMessage.TARGET_Role)) {
sql += " AND AD_Role_ID=" + mbMessage.getAD_Role_ID();
} else if (mbMessage.getTarget().equals(MBroadcastMessage.TARGET_User)) {
sql += " AND AD_User_ID=" + mbMessage.getAD_User_ID();
} else if (mbMessage.getTarget().equals(MBroadcastMessage.TARGET_Client)) {
sql += " AND ad_client_id = " + mbMessage.getNotification_Client_ID();
}
Statement stmt = DB.createStatement();
ResultSet rs =null;
try {
rs = stmt.executeQuery(SQL);
while (rs.next()) {
int AD_User_ID = rs.getInt("ad_user_id");
userIDs.add(AD_User_ID);
}
} catch (SQLException e) {
logger.log(Level.SEVERE, "Exception while retrieving user list",e);
}finally{
DB.close(rs, stmt);
}
int[] userIDs = DB.getIDsEx(null, sql);
for (Integer userID : userIDs) {
for (int userID : userIDs) {
MNote note = new MNote(Env.getCtx(), 0, trxName);
note.setAD_Broadcastmessage_ID(messageID);
note.setAD_User_ID(userID);
note.setAD_Message_ID(0);
note.save();
note.saveEx();
}
mbMessage.setIsPublished(true);
mbMessage.setProcessed(true);
mbMessage.save(trxName);
mbMessage.saveEx(trxName);
} // create entry for users in AD_Note
}else if(MBroadcastMessage.BROADCASTTYPE_Immediate.equals(broadcastType)){
mbMessage.setProcessed(true);
mbMessage.setIsPublished(true);
mbMessage.save(trxName);
mbMessage.saveEx(trxName);
}
if (!MBroadcastMessage.BROADCASTTYPE_Login.equals(broadcastType)) {
@ -150,20 +131,19 @@ public class BroadcastMsgUtil
* @param AD_User_ID
* @param messageWindow
*/
public static void showPendingMeassage(int AD_User_ID, IBroadcastMsgPopup messageWindow) {
StringBuilder sql = new StringBuilder("SELECT bm.AD_BroadcastMessage_ID ")
.append(" FROM AD_Note n INNER JOIN AD_BroadcastMessage bm ON bm.AD_BroadcastMessage_ID=n.AD_BroadcastMessage_ID ")
.append(" WHERE n.AD_User_ID = ?")
.append(" AND (bm.BroadcastType='IL' OR bm.BroadcastType='L') ")
.append(" AND bm.isPublished='Y' AND n.processed = 'N'")
.append(" AND ((bm.BroadcastFrequency='U' AND bm.Expired='N' AND bm.expiration > current_timestamp) OR bm.BroadcastFrequency='J') ");
public static void showPendingMessage(int AD_User_ID, IBroadcastMsgPopup messageWindow) {
String sql = "SELECT bm.AD_BroadcastMessage_ID "
+ " FROM AD_Note n INNER JOIN AD_BroadcastMessage bm ON (bm.AD_BroadcastMessage_ID=n.AD_BroadcastMessage_ID) "
+ " WHERE n.AD_User_ID=?"
+ " AND (bm.BroadcastType='IL' OR bm.BroadcastType='L') "
+ " AND bm.isPublished='Y' AND n.processed = 'N'"
+ " AND ((bm.BroadcastFrequency='U' AND bm.Expired='N' AND bm.expiration > SYSDATE) OR bm.BroadcastFrequency='J')";
ArrayList<MBroadcastMessage> mbMessages = new ArrayList<MBroadcastMessage>();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql.toString(),null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_User_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
@ -171,11 +151,12 @@ public class BroadcastMsgUtil
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Broadcast messages could not be retrieved",e);
throw new DBException(e);
}
finally{
DB.close(rs, pstmt);
}
if(mbMessages.size()>0){
if (mbMessages.size()>0) {
messageWindow.prepareMessage(mbMessages);
}
}

View File

@ -14,8 +14,6 @@
package org.idempiere.broadcast.process;
import java.sql.PreparedStatement;
import org.adempiere.model.MBroadcastMessage;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
@ -36,21 +34,13 @@ public class ExpireBrodcastMessage extends SvrProcess{
@Override
protected String doIt() throws Exception {
MBroadcastMessage mbMessage = MBroadcastMessage.get(Env.getCtx(), getRecord_ID());
if(mbMessage.getBroadcastFrequency().equals("U") && !mbMessage.isExpired() && mbMessage.isPublished()){
String sql = "UPDATE AD_Note SET processed='Y' WHERE AD_BroadcastMessage_ID = ?";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql,null);
pstmt.setInt(1, getRecord_ID());
pstmt.executeUpdate();
if (MBroadcastMessage.BROADCASTFREQUENCY_UntilExpiration.equals(mbMessage.getBroadcastFrequency())
&& !mbMessage.isExpired() && mbMessage.isPublished()){
String sql = "UPDATE AD_Note SET Processed='Y' WHERE AD_BroadcastMessage_ID = ?";
DB.executeUpdateEx(sql, new Object[] {getRecord_ID()}, null);
mbMessage.setProcessed(true);
mbMessage.setExpired(true);
} catch (Exception e) {
return "Message is not Expired";
}finally{
DB.close(pstmt);
}
mbMessage.save();
mbMessage.saveEx();
}
return "Expired";
}

File diff suppressed because one or more lines are too long

View File

@ -176,7 +176,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
homeTab.appendChild(busyDialog);
messageWindow = new BroadcastMessageWindow(pnlHead);
BroadcastMsgUtil.showPendingMeassage(Env.getAD_User_ID(Env.getCtx()), messageWindow);
BroadcastMsgUtil.showPendingMessage(Env.getAD_User_ID(Env.getCtx()), messageWindow);
if (!layout.getDesktop().isServerPushEnabled())
{

View File

@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.adempiere.model.MBroadcastMessage;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Checkbox;
@ -296,7 +297,7 @@ public class BroadcastMessageWindow extends Window implements IBroadcastMsgPopup
boolean ack = hashMessages.get(mbMessage.get_ID());
acknowledged.setChecked(ack);
acknowledged.setVisible(true);
}else if((broadcastFrequency.equals("J"))
}else if((broadcastFrequency.equals(MBroadcastMessage.BROADCASTFREQUENCY_JustOnce))
|| (mbMessage.getBroadcastType().equals(MBroadcastMessage.BROADCASTTYPE_Immediate))){
acknowledged.setVisible(false);
hashMessages.put(mbMessages.get(currMsg).get_ID(), true);
@ -312,9 +313,9 @@ public class BroadcastMessageWindow extends Window implements IBroadcastMsgPopup
* @return
*/
public MNote getMNote(MBroadcastMessage mbMessage) {
String sql = "SELECT * FROM AD_Note WHERE AD_BroadcastMessage_ID = ? AND AD_User_ID = ?";
MNote note =null;
if(!mbMessage.getBroadcastType().equals(MBroadcastMessage.BROADCASTTYPE_Immediate)){
String sql = "SELECT * FROM AD_Note WHERE AD_BroadcastMessage_ID = ? AND AD_User_ID = ?";
PreparedStatement pstmt = null;
ResultSet rs=null;
try {
@ -326,6 +327,7 @@ public class BroadcastMessageWindow extends Window implements IBroadcastMsgPopup
note = new MNote(Env.getCtx(), rs, null);
} catch (Exception e) {
log.log(Level.SEVERE, "Note for the Mesaage Could not be retrieved ",e);
throw new DBException(e);
}finally{
DB.close(rs, pstmt);
}
@ -351,7 +353,7 @@ public class BroadcastMessageWindow extends Window implements IBroadcastMsgPopup
if(hashMessages.get(mbMessage.get_ID())){
acknowedgedMsgs.add(mbMessage);
}
note.save();
note.saveEx();
}else{
acknowedgedMsgs.add(mbMessage);
}