KickJava   Java API By Example, From Geeks To Geeks.

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


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.wstore;
15
16 import java.util.*;
17 import java.sql.*;
18
19 import org.apache.log4j.Logger;
20
21 import org.compiere.model.*;
22 import org.compiere.util.DB;
23 import org.compiere.util.Env;
24 import org.compiere.www.*;
25
26 /**
27  * Web User Info.
28  * Assumes that Email is a direct match.
29  * UPDATE AD_User SET EMail=TRIM(EMail) WHERE Email<>TRIM(EMail)
30  * @author Jorg Janke
31  * @version $Id: WebUser.java,v 1.25 2003/08/18 15:54:49 jjanke Exp $
32  */

33 public class WebUser
34 {
35     /**
36      * Get user unconditional from cache
37      * @param ctx context
38      * @param email email
39      * @return web user
40      */

41     public static WebUser get (Properties ctx, String JavaDoc email)
42     {
43         return get (ctx, email, null, true);
44     } // get
45

46     /**
47      * Get user
48      * @param ctx context
49      * @param email email
50      * @param password optional password
51      * @param useCache use cache
52      * @return web user
53      */

54     public static WebUser get (Properties ctx, String JavaDoc email, String JavaDoc password, boolean useCache)
55     {
56         if (!useCache)
57             s_cache = null;
58         if (s_cache != null && email != null && email.equals(s_cache.getEmail()))
59         {
60             // if password is null, don't check it
61
if (password == null || password.equals(s_cache.getPassword()))
62                 return s_cache;
63             s_cache.setPasswordOK(false, null);
64             return s_cache;
65         }
66         s_cache = new WebUser (ctx, email, password);
67         return s_cache;
68     } // get
69

70     /**
71      * Get user unconditional (from cache)
72      * @param ctx context
73      * @param AD_User_ID BP Contact
74      * @return web user
75      */

76     public static WebUser get (Properties ctx, int AD_User_ID)
77     {
78         if (s_cache != null && s_cache.getAD_User_ID() == AD_User_ID)
79             return s_cache;
80         s_cache = new WebUser (ctx, AD_User_ID);
81         return s_cache;
82     } // get
83

84     /** Short term Cache for immediate re-query/post (hit rate 20%) */
85     private static WebUser s_cache = null;
86
87     /*************************************************************************/
88
89     /** Attribute Name - also in JSPs */
90     public static final String JavaDoc NAME = "webUser";
91     /** Logging */
92     private Logger log = Logger.getLogger(getClass());
93
94     /**
95      * Load User with password
96      * @param ctx context
97      * @param email email
98      * @param password password
99      */

100     private WebUser (Properties ctx, String JavaDoc email, String JavaDoc password)
101     {
102         m_ctx = ctx;
103         m_AD_Client_ID = Env.getContextAsInt(ctx, "#AD_Client_ID");
104         load (email, password);
105     } // WebUser
106

107     /**
108      * Load User with password
109      * @param ctx context
110      * @param AD_User_ID BP Contact
111      */

112     private WebUser (Properties ctx, int AD_User_ID)
113     {
114         m_ctx = ctx;
115         m_AD_Client_ID = Env.getContextAsInt(ctx, "#AD_Client_ID");
116         load (AD_User_ID);
117     } // WebUser
118

119     private Properties m_ctx;
120     //
121
private MBPartner m_bp;
122     private MUser m_bpc;
123     private MBPartner_Location m_bpl;
124     private MLocation m_loc;
125     //
126
private boolean m_passwordOK = false;
127     private String JavaDoc m_passwordMessage;
128     private String JavaDoc m_saveErrorMessage;
129     //
130
private int m_AD_Client_ID = 0;
131     private boolean m_loggedIn = false;
132
133
134     /**
135      * Load Contact
136      * @param email email
137      * @param password optional password
138      */

139     private void load (String JavaDoc email, String JavaDoc password)
140     {
141         log.info("load -" + email + "- AD_Client_ID=" + m_AD_Client_ID);
142         String JavaDoc sql = "SELECT * "
143             + "FROM AD_User "
144             + "WHERE AD_Client_ID=?"
145             + " AND TRIM(EMail)=?";
146         if (email == null)
147             email = "";
148
149         PreparedStatement pstmt = null;
150         try
151         {
152             pstmt = DB.prepareStatement(sql);
153             pstmt.setInt(1, m_AD_Client_ID);
154             pstmt.setString(2, email.trim());
155             ResultSet rs = pstmt.executeQuery();
156             if (rs.next())
157             {
158                 m_bpc = new MUser (m_ctx, rs);
159                 log.debug("load - found BPC=" + m_bpc);
160             }
161             rs.close();
162             pstmt.close();
163             pstmt = null;
164         }
165         catch (Exception JavaDoc e)
166         {
167             log.error("load", e);
168         }
169         finally
170         {
171             try
172             {
173                 if (pstmt != null)
174                     pstmt.close ();
175             }
176             catch (Exception JavaDoc e)
177             {}
178             pstmt = null;
179         }
180
181         // Check Password
182
m_passwordOK = false;
183         if (m_bpc != null && password != null && password.equals(m_bpc.getPassword()))
184             m_passwordOK = true;
185         if (m_passwordOK || m_bpc == null)
186             m_passwordMessage = null;
187         else
188             setPasswordOK (false, password);
189
190         // Load BPartner
191
if (m_bpc != null)
192         {
193             m_bp = new MBPartner (m_ctx, m_bpc.getC_BPartner_ID ());
194             log.debug("load - found BP=" + m_bp);
195         }
196         else
197             m_bp = null;
198         // Load Loacation
199
if (m_bpc != null)
200         {
201             if (m_bpc.getC_BPartner_Location_ID() != 0)
202             {
203                 m_bpl = new MBPartner_Location (m_ctx, m_bpc.getC_BPartner_Location_ID ());
204                 log.debug("load - found BPL=" + m_bpl);
205             }
206             else
207             {
208                 MBPartner_Location[] bpls = m_bp.getLocations();
209                 if (bpls != null && bpls.length > 0)
210                 {
211                     m_bpl = bpls[0];
212                     log.debug ("load - found BPL=" + m_bpl);
213                 }
214             }
215             if (m_bpl != null)
216             {
217                 m_loc = new MLocation (m_ctx, 0);
218                 m_loc.load(m_bpl.getC_Location_ID());
219                 log.debug ("load - found LOC=" + m_loc);
220             }
221             else
222                 m_loc = null;
223         }
224         else
225         {
226             m_bpl = null;
227             m_loc = null;
228         }
229
230         // Make sure that all entities exist
231
if (m_bpc == null)
232         {
233             m_bpc = new MUser (m_ctx, 0, 0);
234             m_bpc.setEmail(email);
235             m_bpc.setPassword(password);
236         }
237         if (m_bp == null)
238         {
239             m_bp = new MBPartner (m_ctx); // template
240
m_bp.setIsCustomer(true);
241         }
242         if (m_bpl == null)
243             m_bpl = new MBPartner_Location (m_ctx, 0, 0);
244         if (m_loc == null)
245         {
246             m_loc = new MLocation (m_ctx, 0);
247             m_loc.load(0);
248         }
249         //
250
log.info("load complete - " + m_bp + " - " + m_bpc);
251     } // load
252

253     /**
254      * Load Contact
255      * @param AD_User_ID BP Contact
256      */

257     private void load (int AD_User_ID)
258     {
259         log.info("load ID=" + AD_User_ID + ", AD_Client_ID=" + m_AD_Client_ID);
260         String JavaDoc sql = "SELECT * "
261             + "FROM AD_User "
262             + "WHERE AD_Client_ID=?"
263             + " AND AD_User_ID=?";
264
265         PreparedStatement pstmt = null;
266         try
267         {
268             pstmt = DB.prepareStatement(sql);
269             pstmt.setInt(1, m_AD_Client_ID);
270             pstmt.setInt(2, AD_User_ID);
271             ResultSet rs = pstmt.executeQuery();
272             if (rs.next())
273             {
274                 m_bpc = new MUser (m_ctx, rs);
275                 log.debug("load = found BPC=" + m_bpc);
276             }
277             rs.close();
278             pstmt.close();
279             pstmt = null;
280         }
281         catch (Exception JavaDoc e)
282         {
283             log.error("load", e);
284         }
285         finally
286         {
287             try
288             {
289                 if (pstmt != null)
290                     pstmt.close ();
291             }
292             catch (Exception JavaDoc e)
293             {}
294             pstmt = null;
295         }
296
297         // Password not entered
298
m_passwordOK = false;
299         m_loggedIn = false;
300
301         // Load BPartner
302
if (m_bpc != null)
303         {
304             m_bp = new MBPartner (m_ctx, m_bpc.getC_BPartner_ID ());
305             log.debug("load = found BP=" + m_bp);
306         }
307         else
308             m_bp = null;
309         // Load Loacation
310
if (m_bpc != null)
311         {
312             if (m_bpc.getC_BPartner_Location_ID() != 0)
313             {
314                 m_bpl = new MBPartner_Location (m_ctx, m_bpc.getC_BPartner_Location_ID ());
315                 log.debug("load = found BPL=" + m_bpl);
316             }
317             else
318             {
319                 MBPartner_Location[] bpls = m_bp.getLocations();
320                 if (bpls != null && bpls.length > 0)
321                 {
322                     m_bpl = bpls[0];
323                     log.debug ("load = found BPL=" + m_bpl);
324                 }
325             }
326             if (m_bpl != null)
327             {
328                 m_loc = new MLocation (m_ctx, 0);
329                 m_loc.load(m_bpl.getC_Location_ID());
330                 log.debug ("load = found LOC=" + m_loc);
331             }
332             else
333                 m_loc = null;
334         }
335         else
336         {
337             m_bpl = null;
338             m_loc = null;
339         }
340
341         // Make sure that all entities exist
342
if (m_bpc == null)
343         {
344             m_bpc = new MUser (m_ctx, 0, 0);
345             m_bpc.setEmail("?");
346             m_bpc.setPassword("?");
347         }
348         if (m_bp == null)
349         {
350             m_bp = new MBPartner (m_ctx); // template
351
m_bp.setIsCustomer(true);
352         }
353         if (m_bpl == null)
354             m_bpl = new MBPartner_Location (m_ctx, 0, 0);
355         if (m_loc == null)
356         {
357             m_loc = new MLocation (m_ctx, 0);
358             m_loc.load(0);
359         }
360         //
361
log.info("load = " + m_bp + " - " + m_bpc);
362     } // load
363

364     /**
365      * Return Valid.
366      * @return return true if found
367      */

368     public boolean isValid()
369     {
370         if (m_bpc == null)
371             return false;
372         boolean ok = m_bpc.getAD_User_ID() != 0;
373         return ok;
374     } // isValid
375

376     /**
377      * Return Email Validation.
378      * @return return true if email is valid
379      */

380     public boolean isEMailValid()
381     {
382         if (m_bpc == null || !WUtil.exists(getEmail()))
383         {
384             log.debug("isEMailValid - " + getEmail() + "bpc=" + m_bpc);
385             return false;
386         }
387         //
388
boolean ok = m_bpc.getAD_User_ID() != 0
389             && m_bpc.isOnline()
390             && m_bpc.isEMailValid();
391         if (!ok)
392             log.debug("isEMailValid - " + getEmail()
393                 + ", ID=" + m_bpc.getAD_User_ID()
394                 + ", Online=" + m_bpc.isOnline()
395                 + ", EMailValid=" + m_bpc.isEMailValid());
396         return ok;
397     } // isEMailValid
398

399     /**
400      * Return Email Validation and set error message
401      * @return return true if email is valid
402      */

403     public boolean setEMailValid()
404     {
405         if (isEMailValid())
406             return true;
407         m_passwordMessage = "EMail invalid";
408         return false;
409     } // setEMailValid
410

411     /**
412      * Info
413      * @return info
414      */

415     public String JavaDoc toString ()
416     {
417         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("WebUser[");
418         sb.append(getEmail())
419             .append(",LoggedIn=").append(m_loggedIn)
420             .append(",").append(m_bpc)
421             .append(",PasswordOK=").append(m_passwordOK)
422             .append(",Valid=").append(isValid())
423             .append(" - ").append(m_bp).append("Customer=").append(isCustomer())
424             .append("]");
425         return sb.toString();
426     } // toString
427

428     /*************************************************************************/
429
430     /**
431      * Save BPartner Objects
432      * @return true if saved
433      */

434     public boolean save()
435     {
436         m_saveErrorMessage = null;
437         log.info("save - BP.Value=" + m_bp.getValue() + ", Name=" + m_bp.getName());
438         try
439         {
440             // check if BPartner exists ***********************************
441
if (m_bp.getC_BPartner_ID() == 0)
442             {
443                 String JavaDoc sql = "SELECT * FROM C_BPartner WHERE AD_Client_ID=? AND Value=?";
444                 PreparedStatement pstmt = null;
445                 try
446                 {
447                     pstmt = DB.prepareStatement(sql);
448                     pstmt.setInt (1, m_AD_Client_ID);
449                     pstmt.setString (2, m_bp.getValue());
450                     ResultSet rs = pstmt.executeQuery();
451                     if (rs.next())
452                     {
453                         m_bp = new MBPartner (m_ctx, m_bpc.getC_BPartner_ID ());
454                         log.debug ("save - BP loaded =" + m_bp);
455                     }
456                     rs.close();
457                     pstmt.close();
458                     pstmt = null;
459                 }
460                 catch (Exception JavaDoc e)
461                 {
462                     log.error("save-check", e);
463                 }
464                 finally
465                 {
466                     try
467                     {
468                         if (pstmt != null)
469                             pstmt.close ();
470                     }
471                     catch (Exception JavaDoc e)
472                     {}
473                     pstmt = null;
474                 }
475             }
476
477             // save BPartner ***************************************
478
if (m_bp.getName () == null || m_bp.getName().length() == 0)
479                 m_bp.setName (m_bpc.getName());
480             if (m_bp.getValue() == null || m_bp.getValue().length() == 0)
481                 m_bp.setValue(m_bpc.getEmail());
482             log.debug ("save - BP=" + m_bp);
483             if (!m_bp.save ())
484             {
485                 m_saveErrorMessage = "Could not save Business Partner";
486                 return false;
487             }
488
489             // save Location ***************************************
490
log.debug ("save - LOC=" + m_loc);
491             m_loc.save ();
492
493             // save BP Location ***************************************
494
if (m_bpl.getC_BPartner_ID () != m_bp.getC_BPartner_ID())
495                 m_bpl.setC_BPartner_ID (m_bp.getC_BPartner_ID());
496             if (m_bpl.getC_Location_ID () != m_loc.getC_Location_ID())
497                 m_bpl.setC_Location_ID (m_loc.getC_Location_ID());
498             log.debug ("save - BPL=" + m_bpl);
499             if (!m_bpl.save ())
500             {
501                 m_saveErrorMessage = "Could not save Location";
502                 return false;
503             }
504
505             // save Contact ***************************************
506
if (m_bpc.getC_BPartner_ID () != m_bp.getC_BPartner_ID())
507                 m_bpc.setC_BPartner_ID (m_bp.getC_BPartner_ID());
508             if (m_bpc.getC_BPartner_Location_ID () != m_bpl.getC_BPartner_Location_ID ())
509                 m_bpc.setC_BPartner_Location_ID (m_bpl.getC_BPartner_Location_ID ());
510             log.debug ("save - BPC=" + m_bpc);
511             if (!m_bpc.save ())
512             {
513                 m_saveErrorMessage = "Could not save Contact";
514                 return false;
515             }
516         }
517         catch (Exception JavaDoc ex)
518         {
519             log.error("save", ex);
520             m_saveErrorMessage = ex.toString();
521             return false;
522         }
523         //
524
return true;
525     } // save
526

527     public void setSaveErrorMessage(String JavaDoc msg)
528     {
529         m_saveErrorMessage = msg;
530     }
531     public String JavaDoc getSaveErrorMessage()
532     {
533         return m_saveErrorMessage;
534     }
535
536     /*************************************************************************/
537
538     /**
539      * Get EMail address
540      * @return email address of contact
541      */

542     public String JavaDoc getEmail ()
543     {
544         return m_bpc.getEmail();
545     }
546
547     public void setEmail (String JavaDoc email)
548     {
549         m_bpc.setEmail(email);
550     }
551
552     public String JavaDoc getName ()
553     {
554         return m_bpc.getName();
555     }
556
557     public void setName (String JavaDoc name)
558     {
559         m_bpc.setName(name);
560     }
561
562     public String JavaDoc getTitle ()
563     {
564         return m_bpc.getTitle();
565     }
566
567     public void setTitle (String JavaDoc title)
568     {
569         m_bpc.setTitle(title);
570     }
571
572     /**
573      * Get Password
574      * @return password
575      */

576     public String JavaDoc getPassword ()
577     {
578         String JavaDoc pwd = m_bpc.getPassword();
579         if (pwd == null || pwd.length() == 0) // if no password use time
580
pwd = String.valueOf(System.currentTimeMillis());
581         return pwd;
582     } // getPassword
583

584     /**
585      * Check & Save Password
586      */

587     public void setPassword ()
588     {
589         String JavaDoc pwd = m_bpc.getPassword();
590         if ((pwd == null || pwd.length() == 0) // no password set
591
&& m_bpc.getC_BPartner_ID() != 0 && m_bpc.getAD_User_ID() != 0 ) // existing BPartner
592
{
593             pwd = String.valueOf (System.currentTimeMillis ());
594             m_bpc.setPassword (pwd);
595             m_bpc.save();
596         }
597     } // setPassword
598

599     /**
600      * Set Password
601      * @param password new password
602      */

603     public void setPassword (String JavaDoc password)
604     {
605         if (password == null || password.length() == 0)
606             m_passwordMessage = "Enter Password";
607         m_bpc.setPassword (password);
608     } // setPassword
609

610     /**
611      * Set Password OK
612      * @param ok password valid
613      * @param password password
614      */

615     private void setPasswordOK (boolean ok, String JavaDoc password)
616     {
617         m_passwordOK = ok;
618         if (ok)
619             m_passwordMessage = null;
620         else if (password == null || password.length() == 0)
621             m_passwordMessage = "Enter Password";
622         else
623             m_passwordMessage = "Invalid Password";
624     } // setPasswordOK
625

626     /**
627      * Is Password OK
628      * @return true if OK
629      */

630     public boolean isPasswordOK()
631     {
632         if (m_bpc == null || !WUtil.exists(m_bpc.getPassword()))
633             return false;
634         return m_passwordOK;
635     } // isPasswordOK
636

637     /**
638      * Set Password Message
639      * @return error message or null
640      */

641     public String JavaDoc getPasswordMessage ()
642     {
643         return m_passwordMessage;
644     } // getPasswordMessage
645

646     /**
647      * Set Password Message
648      * @param passwordMessage message
649      */

650     protected void setPasswordMessage (String JavaDoc passwordMessage)
651     {
652         m_passwordMessage = passwordMessage;
653     } // setPasswordMessage
654

655     /**
656      * Log in with password
657      * @param password password
658      * @return true if the user is logged in
659      */

660     public boolean login (String JavaDoc password)
661     {
662         m_loggedIn = isValid () // we have a contact
663
&& WUtil.exists (password) // we have a password
664
&& password.equals (getPassword ());
665         setPasswordOK (m_loggedIn, password);
666         log.debug("login - success=" + m_loggedIn);
667         return m_loggedIn;
668     } // isLoggedIn
669

670     /**
671      * Log in with oassword
672      */

673     public void logout ()
674     {
675         m_loggedIn = false;
676     } // isLoggedIn
677

678     /**
679      * Is User Logged in
680      * @return is the user logged in
681      */

682     public boolean isLoggedIn ()
683     {
684         return m_loggedIn;
685     } // isLoggedIn
686

687     public String JavaDoc getPhone ()
688     {
689         return m_bpc.getPhone();
690     }
691
692     public void setPhone (String JavaDoc phone)
693     {
694         m_bpc.setPhone(phone);
695     }
696
697     public String JavaDoc getPhone2 ()
698     {
699         return m_bpc.getPhone2();
700     }
701
702     public void setPhone2 (String JavaDoc phone2)
703     {
704         m_bpc.setPhone2(phone2);
705     }
706
707     public String JavaDoc getFax ()
708     {
709         return m_bpc.getFax();
710     }
711
712     public void setFax (String JavaDoc fax)
713     {
714         m_bpc.setFax(fax);
715     }
716
717     public Timestamp getBirthday ()
718     {
719         return m_bpc.getBirthday();
720     }
721
722     public void setBirthday (Timestamp birthday)
723     {
724         m_bpc.setBirthday(birthday);
725     }
726
727     public String JavaDoc getTaxID ()
728     {
729         return m_bp.getTaxID();
730     }
731
732     public void setTaxID (String JavaDoc taxID)
733     {
734         m_bp.setTaxID(taxID);
735     }
736
737
738     public int getAD_User_ID ()
739     {
740         return m_bpc.getAD_User_ID();
741     }
742
743     public int getContactID ()
744     {
745         return getAD_User_ID();
746     }
747
748     /*************************************************************************/
749
750     /**
751      * Get Company Name
752      * @return company name
753      */

754     public String JavaDoc getCompany()
755     {
756         return m_bp.getName();
757     }
758
759     public void setCompany(String JavaDoc company)
760     {
761         m_bp.setName(company);
762     }
763
764     public int getC_BPartner_ID ()
765     {
766         return m_bp.getC_BPartner_ID();
767     }
768
769     public int getM_PriceList_ID ()
770     {
771         return m_bp.getM_PriceList_ID();
772     }
773
774
775     /*************************************************************************/
776
777     /**
778      * Get BP Location ID
779      * @return BP Loaction
780      */

781     public int getC_BPartner_Location_ID ()
782     {
783         return m_bpl.getC_BPartner_Location_ID();
784     }
785
786     /*************************************************************************/
787
788     /**
789      * Get Location
790      * @return location address
791      */

792     public String JavaDoc getAddress ()
793     {
794         return m_loc.getAddress1();
795     }
796
797     public void setAddress (String JavaDoc address)
798     {
799         m_loc.setAddress1(address);
800     }
801
802     public String JavaDoc getAddress2 ()
803     {
804         return m_loc.getAddress2();
805     }
806
807     public void setAddress2 (String JavaDoc address2)
808     {
809         m_loc.setAddress2(address2);
810     }
811
812     public String JavaDoc getCity ()
813     {
814         return m_loc.getCity();
815     }
816
817     public void setCity (String JavaDoc city)
818     {
819         m_loc.setCity(city);
820     }
821
822     public String JavaDoc getPostal ()
823     {
824         return m_loc.getPostal();
825     }
826
827     public void setPostal (String JavaDoc postal)
828     {
829         m_loc.setPostal(postal);
830     }
831
832     /*************************************************************************/
833
834     /**
835      * Get Region name
836      * @return location region name
837      */

838     public String JavaDoc getRegionName ()
839     {
840         return m_loc.getRegionName();
841     }
842
843     public void setRegionName (String JavaDoc region)
844     {
845         m_loc.setRegionName(region);
846     }
847
848     public int getC_Region_ID ()
849     {
850         return m_loc.getC_Region_ID();
851     }
852
853     public String JavaDoc getRegionID ()
854     {
855         return String.valueOf(getC_Region_ID());
856     }
857
858     public void setC_Region_ID (int C_Region_ID)
859     {
860         m_loc.setC_Region_ID(C_Region_ID);
861     }
862
863     public void setC_Region_ID (String JavaDoc C_Region_ID)
864     {
865         try
866         {
867             if (C_Region_ID == null || C_Region_ID.length() == 0)
868                 setC_Region_ID(0);
869             else
870                 setC_Region_ID(Integer.parseInt(C_Region_ID));
871         }
872         catch (Exception JavaDoc e)
873         {
874             setC_Region_ID(0);
875             log.warn("setC_Region_ID", e);
876         }
877     }
878
879     public String JavaDoc getCountryName ()
880     {
881         return m_loc.getCountryName();
882     }
883
884     public void setCountryName (String JavaDoc country)
885     {
886         log.warn("setCountryName=" + country + " Ignored - C_Country_ID=" + m_loc.getC_Country_ID());
887         // m_loc.setCountryName(country);
888
}
889
890     public int getC_Country_ID ()
891     {
892         return m_loc.getC_Country_ID();
893     }
894
895     public String JavaDoc getCountryID ()
896     {
897         return String.valueOf(getC_Country_ID());
898     }
899
900     public void setC_Country_ID (int C_Country_ID)
901     {
902         m_loc.setC_Country_ID(C_Country_ID);
903     }
904
905     public void setC_Country_ID (String JavaDoc C_Country_ID)
906     {
907         try
908         {
909             if (C_Country_ID == null || C_Country_ID.length() == 0)
910                 setC_Country_ID(0);
911             else
912                 setC_Country_ID(Integer.parseInt(C_Country_ID));
913         }
914         catch (Exception JavaDoc e)
915         {
916             setC_Country_ID(0);
917             log.warn("setC_Country_ID", e);
918         }
919     }
920
921     public boolean isEmployee()
922     {
923         return m_bp.isEmployee();
924     }
925
926     public boolean isSalesRep()
927     {
928         return m_bp.isSalesRep();
929     }
930
931     public boolean isCustomer()
932     {
933         return m_bp.isCustomer();
934     }
935
936     public void setIsCustomer(boolean isCustomer)
937     {
938         m_bp.setIsCustomer(isCustomer);
939     }
940
941     public boolean isVendor()
942     {
943         return m_bp.isVendor();
944     }
945
946     public int getSalesRep_ID()
947     {
948         return m_bp.getSalesRep_ID();
949     }
950
951
952     /*************************************************************************/
953
954     /**
955      * Get BP Bank Account (or create it)
956      * @return Bank Account
957      */

958     public MBP_BankAccount getBankAccount()
959     {
960         MBP_BankAccount retValue = null;
961         MBP_BankAccount[] bas = m_bp.getBankAccounts();
962         // create new
963
if (bas == null || bas.length == 0)
964         {
965             retValue = new MBP_BankAccount (m_ctx, m_bp, m_bpc, m_loc);
966             retValue.save();
967         }
968         else
969             retValue = bas[0]; // first
970
return retValue;
971     } // getBankAccount
972

973 } // WebUser
974
Popular Tags