📄 mcontactinterest.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Business Partner Contact Interest.
* Compiere compies with spamming laws.
* If the opt out date is set (by the user),
* you should not subscribe the user again.
* Internally, the isActive flag is used.
*
* @author Jorg Janke
* @version $Id: MContactInterest.java,v 1.12 2006/01/23 04:54:49 jjanke Exp $
*/
public class MContactInterest extends X_R_ContactInterest
{
/**
* Get Contact Interest
* @param ctx context
* @param R_InterestArea_ID interest ares
* @param AD_User_ID user
* @param isActive create as active
* @return Contact Interest
*/
public static MContactInterest get (Properties ctx,
int R_InterestArea_ID, int AD_User_ID, boolean isActive, String trxName)
{
MContactInterest retValue = null;
String sql = "SELECT * FROM R_ContactInterest "
+ "WHERE R_InterestArea_ID=? AND AD_User_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, R_InterestArea_ID);
pstmt.setInt(2, AD_User_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = new MContactInterest (ctx, rs, trxName);
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
if (retValue == null)
{
retValue = new MContactInterest (ctx, R_InterestArea_ID, AD_User_ID,
isActive, trxName);
s_log.fine("NOT found - " + retValue);
}
else
s_log.fine("Found - " + retValue);
return retValue;
} // get
/**************************************************************************
* Persistency Constructor
* @param ctx context
* @param ignored ignored
*/
public MContactInterest (Properties ctx, int ignored, String trxName)
{
super(ctx, 0, trxName);
if (ignored != 0)
throw new IllegalArgumentException("Multi-Key");
} // MContactInterest
/**
* Constructor
* @param ctx context
* @param R_InterestArea_ID interest area
* @param AD_User_ID partner contact
* @param isActive create as active
*/
public MContactInterest (Properties ctx, int R_InterestArea_ID, int AD_User_ID,
boolean isActive, String trxName)
{
super(ctx, 0, trxName);
setR_InterestArea_ID (R_InterestArea_ID);
setAD_User_ID (AD_User_ID);
setIsActive(isActive);
} // MContactInterest
/**
* Create & Load existing Persistent Object.
* @param ctx context
* @param rs load from current result set position (no navigation, not closed)
*/
public MContactInterest (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MContactInterest
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MContactInterest.class);
/**
* Set OptOut Date
* User action only.
* @param OptOutDate date
*/
public void setOptOutDate (Timestamp OptOutDate)
{
if (OptOutDate == null)
OptOutDate = new Timestamp(System.currentTimeMillis());
log.fine("" + OptOutDate);
super.setOptOutDate(OptOutDate);
setIsActive(false);
} // setOptOutDate
/**
* Unsubscribe.
* User action only.
*/
public void unsubscribe()
{
setOptOutDate(null);
} // unsubscribe
/**
* Is Opted Out
* @return true if opted out
*/
public boolean isOptOut()
{
return getOptOutDate() != null;
} // isOptOut
/**
* Set Subscribe Date
* User action only.
* @param SubscribeDate date
*/
public void setSubscribeDate (Timestamp SubscribeDate)
{
if (SubscribeDate == null)
SubscribeDate = new Timestamp(System.currentTimeMillis());
log.fine("" + SubscribeDate);
super.setSubscribeDate(SubscribeDate);
super.setOptOutDate(null);
setIsActive(true);
} // setSubscribeDate
/**
* Subscribe
* User action only.
*/
public void subscribe()
{
setSubscribeDate(null);
if (!isActive())
setIsActive(true);
} // subscribe
/**
* Subscribe.
* User action only.
*/
public void subscribe (boolean subscribe)
{
if (subscribe)
setSubscribeDate(null);
else
setOptOutDate(null);
} // subscribe
/**
* Is Subscribed.
* Active is set internally,
* the opt out date is set by the user via the web UI.
* @return true if subscribed
*/
public boolean isSubscribed()
{
return isActive() && getOptOutDate() == null;
} // isSubscribed
/**
* String representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("MContactInterest[")
.append("R_InterestArea_ID=").append(getR_InterestArea_ID())
.append(",AD_User_ID=").append(getAD_User_ID())
.append(",Subscribed=").append(isSubscribed())
.append ("]");
return sb.toString ();
} // toString
/**************************************************************************
*/
public static void main (String[] args)
{
org.compiere.Compiere.startup(true);
int R_InterestArea_ID = 1000002;
int AD_User_ID = 1000002;
MContactInterest ci = MContactInterest.get(Env.getCtx(), R_InterestArea_ID, AD_User_ID, false, null);
ci.subscribe();
ci.save();
//
ci = MContactInterest.get(Env.getCtx(), R_InterestArea_ID, AD_User_ID, false, null);
} // main
} // MContactInterest
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -