KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > party > contact > ContactHelper


1 /*
2  * $Id: ContactHelper.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.party.contact;
26
27 import java.util.Collection JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.ofbiz.base.util.Debug;
32 import org.ofbiz.base.util.UtilMisc;
33 import org.ofbiz.entity.GenericEntityException;
34 import org.ofbiz.entity.GenericValue;
35 import org.ofbiz.entity.util.EntityUtil;
36
37 /**
38  * Accessors for Contact Mechanisms
39  *
40  * @author <a HREF="mailto:epabst@bigfoot.com">Eric Pabst</a>
41  * @version $Rev: 5462 $
42  * @since 2.0
43  */

44 public class ContactHelper {
45     
46     public static final String JavaDoc module = ContactHelper.class.getName();
47     
48     public static Collection JavaDoc getContactMech(GenericValue party, boolean includeOld) {
49         return getContactMech(party, null, null, includeOld);
50     }
51
52     public static Collection JavaDoc getContactMechByType(GenericValue party, String JavaDoc contactMechTypeId, boolean includeOld) {
53         return getContactMech(party, null, contactMechTypeId, includeOld);
54     }
55
56     public static Collection JavaDoc getContactMechByPurpose(GenericValue party, String JavaDoc contactMechPurposeTypeId, boolean includeOld) {
57         return getContactMech(party, contactMechPurposeTypeId, null, includeOld);
58     }
59
60     public static Collection JavaDoc getContactMech(GenericValue party, String JavaDoc contactMechPurposeTypeId, String JavaDoc contactMechTypeId, boolean includeOld) {
61         if (party == null) return null;
62         try {
63             List JavaDoc partyContactMechList;
64
65             if (contactMechPurposeTypeId == null) {
66                 partyContactMechList = party.getRelated("PartyContactMech");
67             } else {
68                 List JavaDoc list;
69
70                 list = party.getRelatedByAnd("PartyContactMechPurpose", UtilMisc.toMap("contactMechPurposeTypeId", contactMechPurposeTypeId));
71                 if (!includeOld) {
72                     list = EntityUtil.filterByDate(list, true);
73                 }
74                 partyContactMechList = EntityUtil.getRelated("PartyContactMech", list);
75             }
76             if (!includeOld) {
77                 partyContactMechList = EntityUtil.filterByDate(partyContactMechList, true);
78             }
79             partyContactMechList = EntityUtil.orderBy(partyContactMechList, UtilMisc.toList("fromDate DESC"));
80             if (contactMechTypeId == null) {
81                 return EntityUtil.getRelated("ContactMech", partyContactMechList);
82             } else {
83                 return EntityUtil.getRelatedByAnd("ContactMech", UtilMisc.toMap("contactMechTypeId", contactMechTypeId), partyContactMechList);
84             }
85         } catch (GenericEntityException gee) {
86             Debug.logWarning(gee, module);
87             return Collections.EMPTY_LIST;
88         }
89     }
90
91     public static String JavaDoc formatCreditCard(GenericValue creditCardInfo) {
92         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
93
94         result.append(creditCardInfo.getString("cardType"));
95         String JavaDoc cardNumber = creditCardInfo.getString("cardNumber");
96
97         if (cardNumber != null && cardNumber.length() > 4) {
98             result.append(' ').append(cardNumber.substring(cardNumber.length() - 4));
99         }
100         result.append(' ').append(creditCardInfo.getString("expireDate"));
101         return result.toString();
102     }
103
104 }
105
Popular Tags