KickJava   Java API By Example, From Geeks To Geeks.

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


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-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.sql.*;
17 import java.util.*;
18
19 import org.compiere.model.*;
20 import org.compiere.util.*;
21
22 /**
23  * Request Callouts
24  *
25  * @author Jorg Janke
26  * @version $Id: CalloutRequest.java,v 1.1 2003/10/11 05:20:33 jjanke Exp $
27  */

28 public class CalloutRequest extends CalloutEngine
29 {
30     /**
31      * Request Action <b>Callout</b>.
32      * (Action has been changed in window)
33      *
34      * @param ctx Context
35      * @param WindowNo current Window No
36      * @param mTab Model Tab
37      * @param mField Model Field
38      * @param value The new value
39      * @return Error message or ""
40      */

41     public String JavaDoc action (Properties ctx, int WindowNo, MTab mTab, MField mField, Object JavaDoc value)
42     {
43         String JavaDoc colName = mField.getColumnName();
44         log.info("action - " + colName + "=" + value);
45         if (value == null)
46             return "";
47         String JavaDoc action = (String JavaDoc)value;
48         //
49
if (action.equals(MRequest.ACTIONTYPE_EMail))
50             return actionCheckEMail(ctx, mTab);
51         return "";
52     } // action
53

54
55     /**
56      * Request - Copy Text - <b>Callout</b>
57      *
58      * @param ctx Context
59      * @param WindowNo current Window No
60      * @param mTab Model Tab
61      * @param mField Model Field
62      * @param value The new value
63      * @return Error message or ""
64      */

65     public String JavaDoc copyText (Properties ctx, int WindowNo, MTab mTab, MField mField, Object JavaDoc value)
66     {
67         String JavaDoc colName = mField.getColumnName();
68         log.info("copyText - " + colName + "=" + value);
69         if (value == null)
70             return "";
71
72         Integer JavaDoc R_MailText_ID = (Integer JavaDoc)value;
73         String JavaDoc sql = "SELECT MailHeader, MailText FROM R_MailText WHERE R_MailText_ID=?";
74         try
75         {
76             PreparedStatement pstmt = DB.prepareStatement(sql);
77             pstmt.setInt(1, R_MailText_ID.intValue());
78             ResultSet rs = pstmt.executeQuery();
79             if (rs.next())
80             {
81                 String JavaDoc hdr = rs.getString(1);
82                 String JavaDoc txt = rs.getString(2);
83                 //
84
hdr = Env.parseContext(ctx, WindowNo, hdr, false, true);
85                 txt = Env.parseContext(ctx, WindowNo, txt, false, true);
86                 //
87
mTab.setValue("MailSubject", hdr);
88                 mTab.setValue("MailText", txt);
89             }
90             rs.close();
91             pstmt.close();
92         }
93         catch (SQLException e)
94         {
95             log.error("copyText", e);
96         }
97         return "";
98     } // copyText
99

100     /**
101      * Check the ability to send email.
102      * @param ctx Context
103      * @param mTab Model Tab
104      * @return Error message or ""
105      */

106     private static String JavaDoc actionCheckEMail(Properties ctx, MTab mTab)
107     {
108         // Mail Host
109
String JavaDoc host = EMailUtil.getSmtpHost(ctx);
110         if (host == null || host.length() == 0)
111             return "RequestActionEMailNoSMTP";
112
113         // Mail To
114
Object JavaDoc toAddr = mTab.getValue("C_BPartner_ID");
115         if (toAddr == null)
116             return "RequestActionEMailNoTo";
117         int C_BPartner_ID = ((Integer JavaDoc)toAddr).intValue();
118         if (C_BPartner_ID == 0)
119             return "RequestActionEMailNoTo";
120         int AD_User_ID = 0;
121         toAddr = mTab.getValue("AD_User_ID");
122         if (toAddr != null)
123             AD_User_ID = ((Integer JavaDoc)toAddr).intValue();
124         String JavaDoc emailTo = EMailUtil.getEMail_BPartner (C_BPartner_ID, AD_User_ID);
125         if (emailTo == null || emailTo.length() == 0)
126             return "RequestActionEMailNoTo";
127
128         // Mail From
129
String JavaDoc emailFrom = EMailUtil.getEMail_User (ctx, false);
130         if (emailFrom == null || emailFrom.length() == 0)
131             return "RequestActionEMailNoFrom";
132         int user = 0; // Check that UI user is Request User
133
Object JavaDoc reqUser = mTab.getValue("SalesRep_ID");
134         if (reqUser != null)
135             user = ((Integer JavaDoc)reqUser).intValue();
136         int SalesRep_ID = Env.getContextAsInt (ctx, "#AD_User_ID");
137         if (user != AD_User_ID)
138             mTab.setValue("SalesRep_ID", new Integer JavaDoc(AD_User_ID));
139
140         // RequestActionEMailInfo - EMail from {0} to {1}
141
Object JavaDoc[] args = new Object JavaDoc[] {emailFrom, emailTo};
142         String JavaDoc msg = Msg.getMsg(ctx, "RequestActionEMailInfo", args);
143         mTab.setValue("Result", msg);
144         return "";
145     } // actionCheckEMail
146

147
148
149 } // CalloutRequest
150
Popular Tags