KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > wstore > InfoServlet


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 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-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.wstore;
15
16 import javax.servlet.*;
17 import javax.servlet.http.*;
18 import java.io.*;
19 import java.util.*;
20 import java.math.*;
21
22 import org.apache.log4j.Logger;
23
24 import org.compiere.www.*;
25 import org.compiere.model.*;
26 import org.compiere.util.*;
27
28 /**
29  * Web Store Payment Entry & Confirmation
30  *
31  * @author Jorg Janke
32  * @version $Id: InfoServlet.java,v 1.4 2003/07/24 03:36:41 jjanke Exp $
33  */

34 public class InfoServlet extends HttpServlet
35 {
36     /** Logging */
37     private Logger log = Logger.getLogger(getClass());
38
39     /**
40      * Initialize global variables
41      * @param config servlet configuration
42      * @throws ServletException
43      */

44     public void init(ServletConfig config) throws ServletException
45     {
46         super.init(config);
47         if (!WEnv.initWeb(config))
48             throw new ServletException("InfoServlet.init");
49     } // init
50

51     /**
52      * Get Servlet information
53      * @return Info
54      */

55     public String JavaDoc getServletInfo()
56     {
57         return "Compiere Interest Area Servlet";
58     } // getServletInfo
59

60     /**
61      * Clean up resources
62      */

63     public void destroy()
64     {
65         log.info("destroy");
66     } // destroy
67

68     /*************************************************************************/
69
70     /**
71      * Process the initial HTTP Get request.
72      * Reads the Parameter Amt and optional C_Invoice_ID
73      *
74      * @param request request
75      * @param response response
76      * @throws ServletException
77      * @throws IOException
78      */

79     public void doGet(HttpServletRequest request, HttpServletResponse response)
80         throws ServletException, IOException
81     {
82         log.info("doGet from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
83         HttpSession session = request.getSession(true);
84         session.removeAttribute(JSPEnv.HDR_MESSAGE);
85         WEnv.dump(session);
86         WEnv.dump(request);
87
88         boolean success = processParameter(request);
89
90         String JavaDoc url = "info.jsp";
91         log.info ("doPost - Forward to " + url);
92         RequestDispatcher dispatcher = getServletContext ().getRequestDispatcher (url);
93         dispatcher.forward (request, response);
94     } // doGet
95

96     /**
97      * Process the HTTP Post request.
98      *
99      * @param request request
100      * @param response response
101      * @throws ServletException
102      * @throws IOException
103      */

104     public void doPost(HttpServletRequest request, HttpServletResponse response)
105         throws ServletException, IOException
106     {
107         log.info("doPost from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
108         doGet (request, response);
109     } // doPost
110

111
112     /*************************************************************************/
113
114     /**
115      * Process Parameter and check them
116      * @param request request
117      * @return true if processed
118      */

119     private boolean processParameter (HttpServletRequest request)
120     {
121         HttpSession session = request.getSession(true);
122         session.removeAttribute(JSPEnv.HDR_MESSAGE);
123         Properties ctx = JSPEnv.getCtx(request);
124
125         // mode = subscribe
126
String JavaDoc mode = request.getParameter("mode");
127         if (mode == null)
128             return false;
129         boolean subscribe = !mode.startsWith("un");
130         // area = 101
131
int R_InterestArea_ID = WUtil.getParameterAsInt(request, "area");
132         // contact = -1
133
int AD_User_ID = WUtil.getParameterAsInt(request, "contact");
134         //
135
log.debug("processParameter - subscribe=" + subscribe
136             + ",R_InterestArea_ID=" + R_InterestArea_ID
137             + ",AD_User_ID=" + AD_User_ID);
138         if (R_InterestArea_ID == 0 || AD_User_ID == 0)
139             return false;
140         //
141
boolean insert = subscribe;
142         int no = 0;
143
144         if (insert) // subscribe
145
{
146             String JavaDoc sql = "INSERT INTO R_ContactInterest ("
147                 + "R_InterestArea_ID,AD_User_ID,"
148                 + " AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
149                 + " SubscribeDate,OptOutDate) VALUES (";
150             // R_InterestArea_ID,AD_User_ID,
151
sql += R_InterestArea_ID + "," + AD_User_ID + ",";
152             // AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,
153
int AD_Client_ID = Env.getContextAsInt(ctx, "#AD_Client_ID");
154             int AD_Org_ID = Env.getContextAsInt(ctx, "#AD_Org_ID");
155             sql += AD_Client_ID + "," + AD_Org_ID + ",'Y',SysDate,0,SysDate,0,";
156             // SubscribeDate,OptOutDate
157
sql += "SysDate,NULL)";
158             //
159
no = DB.executeUpdate(sql, true);
160             if (no == 0) // Insert no success - try update
161
insert = false;
162         }
163
164         if (!insert) // subscribe or unsubscribe
165
{
166             String JavaDoc sql = "UPDATE R_ContactInterest"
167                 + " SET SubscribeDate=";
168             sql += subscribe ? "SysDate," : "NULL,";
169             sql += " OptOutDate=";
170             sql += subscribe ? "NULL," : "SysDate,";
171             sql +=" Updated=SysDate, IsActive='Y' "
172                 + "WHERE AD_User_ID=" + AD_User_ID
173                 + " AND R_InterestArea_ID=" + R_InterestArea_ID;
174             //
175
no = DB.executeUpdate(sql);
176         }
177
178         // Lookup user if direct link
179
WebUser wu = (WebUser)session.getAttribute(WebUser.NAME);
180         if (wu == null && no == 1)
181         {
182             wu = WebUser.get(ctx, AD_User_ID);
183             session.setAttribute(WebUser.NAME, wu);
184         }
185
186         return no == 1;
187     } // processParameter
188

189     /**
190      * Send Payment EMail.
191      * @param request request
192      * @param ctx context
193      * @param wu web user
194      */

195     private void sendEMail (HttpServletRequest request, Properties ctx, WebUser wu)
196     {
197         String JavaDoc subject = "Compiere Web - Interest Area";
198         String JavaDoc message = "Thank you - http://"
199             + request.getServerName()
200             + request.getContextPath() + "/";
201
202         String JavaDoc SMTPHost = ctx.getProperty("SMTPHost", "localhost");
203         String JavaDoc RequestEMail = ctx.getProperty("RequestEMail");
204         String JavaDoc RequestUser = ctx.getProperty("RequestUser");
205         String JavaDoc RequestUserPw = ctx.getProperty("RequestUserPw");
206         //
207
EMail em = new EMail(SMTPHost, RequestEMail, wu.getEmail(), subject, message);
208         em.setEMailUser(RequestUser, RequestUserPw);
209         //
210
// String webOrderEMail = ctx.getProperty("webOrderEMail");
211
// em.addBcc(webOrderEMail);
212
//
213
em.send();
214
215         /**
216         Name=GardenWorld
217         webDir=compiere,
218         Description=GardenWorld
219         **/

220
221     } // sendEMail
222

223
224 } // InfoServlet
225
Popular Tags