1 25 package org.ofbiz.party.contact; 26 27 import java.util.Collection ; 28 import java.util.Collections ; 29 import java.util.List ; 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 44 public class ContactHelper { 45 46 public static final String module = ContactHelper.class.getName(); 47 48 public static Collection getContactMech(GenericValue party, boolean includeOld) { 49 return getContactMech(party, null, null, includeOld); 50 } 51 52 public static Collection getContactMechByType(GenericValue party, String contactMechTypeId, boolean includeOld) { 53 return getContactMech(party, null, contactMechTypeId, includeOld); 54 } 55 56 public static Collection getContactMechByPurpose(GenericValue party, String contactMechPurposeTypeId, boolean includeOld) { 57 return getContactMech(party, contactMechPurposeTypeId, null, includeOld); 58 } 59 60 public static Collection getContactMech(GenericValue party, String contactMechPurposeTypeId, String contactMechTypeId, boolean includeOld) { 61 if (party == null) return null; 62 try { 63 List partyContactMechList; 64 65 if (contactMechPurposeTypeId == null) { 66 partyContactMechList = party.getRelated("PartyContactMech"); 67 } else { 68 List 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 formatCreditCard(GenericValue creditCardInfo) { 92 StringBuffer result = new StringBuffer (16); 93 94 result.append(creditCardInfo.getString("cardType")); 95 String 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 |