KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MInterestArea


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.util.*;
17 import java.sql.*;
18 import java.math.*;
19 import java.io.Serializable JavaDoc;
20 import org.compiere.util.*;
21
22
23 /**
24  * Interest Area.
25  * Note: if model is changed, update
26  * org.compiere.wstore.Info.getInterests()
27  * manually
28  *
29  * @author Jorg Janke
30  * @version $Id: MInterestArea.java,v 1.4 2003/08/31 06:48:59 jjanke Exp $
31  */

32 public class MInterestArea extends X_R_InterestArea
33 {
34     /**
35      * Constructor
36      * @param ctx context
37      * @param R_InterestArea_ID interest area
38      */

39     public MInterestArea (Properties ctx, int R_InterestArea_ID)
40     {
41         super (ctx, R_InterestArea_ID);
42         if (R_InterestArea_ID == 0)
43         {
44         // setName (null);
45
// setR_InterestArea_ID (0);
46
}
47     } // MInterestArea
48

49     /**
50      * Loader Constructor
51      * @param ctx context
52      * @param rs result set
53      */

54     public MInterestArea (Properties ctx, ResultSet rs)
55     {
56         super (ctx, rs);
57     } // MInterestArea
58

59
60     /*************************************************************************/
61
62     /**
63      * String representation
64      * @return info
65      */

66     public String JavaDoc toString ()
67     {
68         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("MInterestArea[")
69             .append (getID()).append(" - ").append(getName())
70             .append ("]");
71         return sb.toString ();
72     }
73
74     /*************************************************************************/
75
76     private int m_AD_User_ID = -1;
77     private int m_old_AD_User_ID = -1;
78     private Timestamp m_OptOutDate = null;
79     private Timestamp m_SubscribeDate = null;
80     private boolean m_Subscribed = false;
81
82     /**
83      * Set Subscription info "constructor"
84      * @param AD_User_ID contact
85      * @param SubscribeDate opt-in
86      * @param OptOutDate opt-out
87      */

88     public void setSubscription (int AD_User_ID, Timestamp SubscribeDate, Timestamp OptOutDate)
89     {
90         m_old_AD_User_ID = AD_User_ID;
91         m_AD_User_ID = AD_User_ID;
92         setSubscribeDate(SubscribeDate);
93         setOptOutDate(OptOutDate);
94         isSelfService();
95     } // setSubscription
96

97     public void setAD_User_ID (int AD_User_ID)
98     {
99         m_AD_User_ID = AD_User_ID;
100     }
101
102     public int getAD_User_ID ()
103     {
104         return m_AD_User_ID;
105     }
106
107     public void setSubscribeDate (Timestamp SubscribeDate)
108     {
109         m_SubscribeDate = SubscribeDate;
110     }
111
112     public Timestamp getSubscribeDate ()
113     {
114         return m_SubscribeDate;
115     }
116
117     public void setOptOutDate (Timestamp OptOutDate)
118     {
119         m_OptOutDate = OptOutDate;
120     }
121
122     public Timestamp getOptOutDate ()
123     {
124         return m_OptOutDate;
125     }
126
127     public boolean isSubscribed()
128     {
129         if (m_AD_User_ID <= 0)
130             return false;
131         // We have a BPartner Contact
132
return (m_OptOutDate == null);
133     } // isSubscribed
134

135     /**
136      * Save Subscription
137      * @return true if saved
138      */

139     public boolean saveSubscription ()
140     {
141         log.debug ("saveSubscription");
142         // No BP Contact
143
if (m_AD_User_ID <= 0)
144             return false;
145
146         int no = 0;
147
148         // new
149
if (m_AD_User_ID != m_old_AD_User_ID)
150         {
151             String JavaDoc sql = "INSERT INTO R_ContactInterest ("
152                 + "R_InterestArea_ID,AD_User_ID,"
153                 + " AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
154                 + " SubscribeDate,OptOutDate) VALUES (";
155             // R_InterestArea_ID,AD_User_ID,
156
sql += getR_InterestArea_ID() + "," + m_AD_User_ID + ",";
157             // AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,
158
sql += getAD_Client_ID() + "," + getAD_Org_ID() + ",'Y',SysDate,0,SysDate,0,";
159             // SubscribeDate,OptOutDate
160
if (m_SubscribeDate == null)
161                 sql += "NULL,";
162             else
163                 sql += DB.TO_DATE(m_SubscribeDate, false) + ",";
164             if (m_OptOutDate == null)
165                 sql += "NULL";
166             else
167                 sql += DB.TO_DATE(m_OptOutDate, false);
168             sql += ")";
169             //
170
no = DB.executeUpdate(sql);
171             if (no == 0) // Insert no success - try update
172
m_old_AD_User_ID = m_AD_User_ID;
173         }
174
175         // update
176
if (m_AD_User_ID == m_old_AD_User_ID)
177         {
178             String JavaDoc sql = "UPDATE R_ContactInterest"
179                 + " SET SubscribeDate=";
180             if (m_SubscribeDate == null)
181                  sql += "NULL,";
182             else
183                 sql += DB.TO_DATE(m_SubscribeDate, false) + ",";
184             sql += " OptOutDate=";
185             if (m_OptOutDate == null)
186                 sql += "NULL,";
187             else
188                 sql += DB.TO_DATE(m_OptOutDate, false) + ",";
189             sql +=" Updated=SysDate, IsActive='Y' "
190                 + "WHERE AD_User_ID=" + m_AD_User_ID
191                 + " AND R_InterestArea_ID=" + getR_InterestArea_ID();
192             //
193
no = DB.executeUpdate(sql);
194         }
195         return no == 1;
196     } // saveSubscription
197

198 } // MInterestArea
199
Popular Tags