KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > process > RequestAction


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

14 package org.compiere.process;
15
16 import java.sql.*;
17 import java.math.*;
18 import java.util.*;
19
20 import org.compiere.process.*;
21 import org.compiere.model.*;
22 import org.compiere.util.*;
23
24 /**
25  * Request Action.
26  * <br>
27  * The static methods <code>cation</code> and <code>copyText</code> are Callouts
28  * when a choice was changed.
29  * <p>
30  * The Object with the method <code>startProcess</code> is
31  * called then pressing the Processing Button in R_Request.
32  * If startProcess returns true, the procedure R_Request_Process.sql is
33  * executed (Copy history, etc.).
34  * <pre>
35  * ActionType action startProcess
36  * ---------- ---------- ----------
37  * Remainder - -
38  * Call - -
39  * EMail verify address send mail
40  * Transfer - send mail
41  * Close - -
42  *
43  * </pre>
44  * @author Jorg Janke
45  * @version $Id: RequestAction.java,v 1.14 2003/10/11 05:20:32 jjanke Exp $
46  */

47 public class RequestAction implements ProcessCall
48 {
49     /**
50      * Constructor for Request
51      */

52     public RequestAction()
53     {
54     } // RequestAction
55

56     /** Logger */
57     private Logger log = Logger.getCLogger (getClass());
58
59     /**
60      * Start the process.
61      * Called then pressing the Process button in R_Request.
62      * It should only return false, if the function could not be performed
63      * as this causes the process to abort.
64      *
65      * @param ctx Context
66      * @param pi Process Info
67      * @return true if success
68      */

69     public boolean startProcess (Properties ctx, ProcessInfo pi)
70     {
71         log.info("startProcess - " + pi);
72         //
73
int AD_Client_ID = 0;
74         String JavaDoc DocumentNo = null;
75         String JavaDoc ActionType = null;
76         String JavaDoc Summary = null;
77         String JavaDoc MailSubject = null;
78         String JavaDoc MailText = null;
79         int C_BPartner_ID = 0;
80         int AD_User_ID = 0;
81         int SalesRep_ID = 0;
82         int UpdatedBy = 0;
83         //
84
String JavaDoc sql = "SELECT AD_Client_ID, DocumentNo, ActionType, Summary, " // 1..4
85
+ "MailSubject,MailText, C_BPartner_ID,AD_User_ID, " // 5..8
86
+ "SalesRep_ID, UpdatedBy " // 9..10
87
+ "FROM R_Request WHERE R_Request_ID=?";
88         try
89         {
90             PreparedStatement pstmt = DB.prepareStatement(sql);
91             pstmt.setInt(1, pi.getRecord_ID());
92             ResultSet rs = pstmt.executeQuery();
93             if (rs.next())
94             {
95                 AD_Client_ID = rs.getInt(1);
96                 DocumentNo = rs.getString(2);
97                 ActionType = rs.getString(3);
98                 Summary = rs.getString(4);
99                 MailSubject = rs.getString(5);
100                 MailText = rs.getString(6);
101                 C_BPartner_ID = rs.getInt(7);
102                 AD_User_ID = rs.getInt(8);
103                 SalesRep_ID = rs.getInt(9);
104                 UpdatedBy = rs.getInt(10);
105             }
106             rs.close();
107             pstmt.close();
108         }
109         catch (SQLException e)
110         {
111             log.error("startProcess", e);
112             return false;
113         }
114
115         if (ActionType == null)
116             return true;
117
118         // Send EMail
119
if (ActionType.equals(MRequest.ACTIONTYPE_EMail))
120         {
121             String JavaDoc smtpHost = EMailUtil.getSmtpHost(AD_Client_ID);
122             String JavaDoc from = EMailUtil.getEMail_User(SalesRep_ID);
123             String JavaDoc to = EMailUtil.getEMail_BPartner(C_BPartner_ID, AD_User_ID);
124             //
125
EMail email = new EMail(smtpHost, from, to, MailSubject, MailText);
126             String JavaDoc msg = email.send();
127             if (EMail.SENT_OK.equals(msg))
128                 updateRequest (pi.getRecord_ID(), Msg.getMsg(ctx, "RequestActionEMailOK"));
129             else
130             {
131                 updateRequest (pi.getRecord_ID(), Msg.getMsg(ctx, "RequestActionEMailError") + " - " + msg);
132                 return false;
133             }
134         }
135
136         // Send Transfer EMail
137
else if (ActionType.equals(MRequest.ACTIONTYPE_Transfer))
138         {
139             // RequestActionTransfer - Request {0} was transfered by {1} to {2}
140
Object JavaDoc[] args = new Object JavaDoc[] {DocumentNo, EMailUtil.getNameOfUser(UpdatedBy), EMailUtil.getNameOfUser(AD_User_ID)};
141             String JavaDoc subject = Msg.getMsg(Env.getAD_Language(ctx), "RequestActionTransfer", args);
142             updateRequest (pi.getRecord_ID(), subject);
143             // Optional Info mail
144
String JavaDoc smtpHost = EMailUtil.getSmtpHost(AD_Client_ID);
145             String JavaDoc to = EMailUtil.getEMail_User(AD_User_ID);
146             String JavaDoc from = EMailUtil.getEMail_User(UpdatedBy);
147             String JavaDoc message = subject + "\n" + Summary;
148             //
149
EMail email = new EMail(smtpHost, from, to, subject, message);
150             String JavaDoc msg = email.send();
151         }
152
153         return true;
154     } // startProcess
155

156     /**
157      * Update result of Request
158      *
159      * @param R_Request_ID Request to be updated
160      * @param result new result
161      * @return true if request was updated
162      */

163     private boolean updateRequest (int R_Request_ID, String JavaDoc result)
164     {
165         StringBuffer JavaDoc sql = new StringBuffer JavaDoc ("UPDATE R_Request SET Result=");
166         String JavaDoc msg = DB.TO_STRING(result); // in ''
167
if (msg.length() < 258) // max length 255
168
sql.append(msg);
169         else
170             sql.append(msg.substring(0,256)).append("'");
171         sql.append(" WHERE R_Request_ID=").append(R_Request_ID);
172         int no = DB.executeUpdate(sql.toString());
173         if (no != 1)
174         {
175             log.error("updateRequest - not updated - R_Request_ID=" + R_Request_ID);
176             return false;
177         }
178         return true;
179     } // updateRequest
180

181 } // RequestAction
182
Popular Tags