📄 contactmechworker.java
字号:
GenericValue postalAddress = null;
try {
if (contactMech != null) postalAddress = contactMech.getRelatedOne("PostalAddress");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
if (postalAddress != null) target.put("postalAddress", postalAddress);
} else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
GenericValue telecomNumber = null;
try {
if (contactMech != null) telecomNumber = contactMech.getRelatedOne("TelecomNumber");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
if (telecomNumber != null) target.put("telecomNumber", telecomNumber);
}
if ("true".equals(request.getParameter("useValues"))) tryEntity = true;
target.put("tryEntity", new Boolean(tryEntity));
try {
Collection contactMechTypes = delegator.findAllCache("ContactMechType", null);
if (contactMechTypes != null) {
target.put("contactMechTypes", contactMechTypes);
}
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
}
/** TO BE REMOVED (DEJ 20030221): This method was for use in a JSP and when they are removed this can be removed as well rather than being maintained, should be removed when eCommerce and party mgr and possible other places are converted to FTL */
public static void getPartyPostalAddresses(PageContext pageContext, String partyId, String curContactMechId, String postalAddressInfosAttr) {
ServletRequest request = pageContext.getRequest();
List postalAddressInfos = getPartyPostalAddresses(request, partyId, curContactMechId);
if (postalAddressInfos.size() > 0) {
pageContext.setAttribute(postalAddressInfosAttr, postalAddressInfos);
}
}
public static List getPartyPostalAddresses(ServletRequest request, String partyId, String curContactMechId) {
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
List postalAddressInfos = new LinkedList();
Iterator allPartyContactMechs = null;
try {
allPartyContactMechs = UtilMisc.toIterator(EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId)), true));
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
while (allPartyContactMechs != null && allPartyContactMechs.hasNext()) {
GenericValue partyContactMech = (GenericValue) allPartyContactMechs.next();
GenericValue contactMech = null;
try {
contactMech = partyContactMech.getRelatedOne("ContactMech");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
if (contactMech != null && "POSTAL_ADDRESS".equals(contactMech.getString("contactMechTypeId")) && !contactMech.getString("contactMechId").equals(curContactMechId)) {
Map postalAddressInfo = new HashMap();
postalAddressInfos.add(postalAddressInfo);
postalAddressInfo.put("contactMech", contactMech);
postalAddressInfo.put("partyContactMech", partyContactMech);
try {
GenericValue postalAddress = contactMech.getRelatedOne("PostalAddress");
postalAddressInfo.put("postalAddress", postalAddress);
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
try {
List partyContactMechPurposes = EntityUtil.filterByDate(partyContactMech.getRelated("PartyContactMechPurpose"), true);
postalAddressInfo.put("partyContactMechPurposes", partyContactMechPurposes);
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
}
}
return postalAddressInfos;
}
/** TO BE REMOVED (DEJ 20030221): This method was for use in a JSP and when they are removed this can be removed as well rather than being maintained, should be removed when eCommerce and party mgr and possible other places are converted to FTL */
public static void getCurrentPostalAddress(PageContext pageContext, String partyId, String curContactMechId,
String curPartyContactMechAttr, String curContactMechAttr, String curPostalAddressAttr, String curPartyContactMechPurposesAttr) {
ServletRequest request = pageContext.getRequest();
Map results = getCurrentPostalAddress(request, partyId, curContactMechId);
if (results.get("curPartyContactMech") != null) pageContext.setAttribute(curPartyContactMechAttr, results.get("curPartyContactMech"));
if (results.get("curContactMech") != null) pageContext.setAttribute(curContactMechAttr, results.get("curContactMech"));
if (results.get("curPostalAddress") != null) pageContext.setAttribute(curPostalAddressAttr, results.get("curPostalAddress"));
if (results.get("curPartyContactMechPurposes") != null) pageContext.setAttribute(curPartyContactMechPurposesAttr, results.get("curPartyContactMechPurposes"));
}
public static Map getCurrentPostalAddress(ServletRequest request, String partyId, String curContactMechId) {
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
Map results = new HashMap();
if (curContactMechId != null) {
List partyContactMechs = null;
try {
partyContactMechs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", curContactMechId)), true);
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
GenericValue curPartyContactMech = EntityUtil.getFirst(partyContactMechs);
results.put("curPartyContactMech", curPartyContactMech);
GenericValue curContactMech = null;
if (curPartyContactMech != null) {
try {
curContactMech = curPartyContactMech.getRelatedOne("ContactMech");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
Collection curPartyContactMechPurposes = null;
try {
curPartyContactMechPurposes = EntityUtil.filterByDate(curPartyContactMech.getRelated("PartyContactMechPurpose"), true);
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
results.put("curPartyContactMechPurposes", curPartyContactMechPurposes);
}
results.put("curContactMech", curContactMech);
GenericValue curPostalAddress = null;
if (curContactMech != null) {
try {
curPostalAddress = curContactMech.getRelatedOne("PostalAddress");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
}
results.put("curPostalAddress", curPostalAddress);
}
return results;
}
public static boolean isUspsAddress(GenericValue postalAddress) {
if (postalAddress == null) {
// null postal address is not a USPS address
return false;
}
if (!"PostalAddress".equals(postalAddress.getEntityName())) {
// not a postal address not a USPS address
return false;
}
// get and clean the address strings
String addr1 = postalAddress.getString("address1");
String addr2 = postalAddress.getString("address2");
if (addr1 != null) {
addr1 = addr1.replaceAll("\\W", "").toLowerCase();
}
if (addr2 != null) {
addr2 = addr2.replaceAll("\\W", "").toLowerCase();
}
// get the matching string from general.properties
String matcher = UtilProperties.getPropertyValue("general.properties", "usps.address.match");
if (matcher != null && matcher.length() > 0) {
if (addr1 != null && addr1.matches(".*(" + matcher + ").*")) {
return true;
}
if (addr2 != null && addr2.matches(".*(" + matcher + ").*")) {
return true;
}
}
return false;
}
public static boolean isCompanyAddress(GenericValue postalAddress, String companyPartyId) {
if (postalAddress == null) {
// null postal address is not an internal address
return false;
}
if (!"PostalAddress".equals(postalAddress.getEntityName())) {
// not a postal address not an internal address
return false;
}
if (companyPartyId == null) {
// no partyId not an internal address
return false;
}
String state = postalAddress.getString("stateProvinceGeoId");
String addr1 = postalAddress.getString("address1");
String addr2 = postalAddress.getString("address2");
if (state != null) {
state = state.replaceAll("\\W", "").toLowerCase();
} else {
state = "";
}
if (addr1 != null) {
addr1 = addr1.replaceAll("\\W", "").toLowerCase();
} else {
addr1 = "";
}
if (addr2 != null) {
addr2 = addr2.replaceAll("\\W", "").toLowerCase();
} else {
addr2 = "";
}
// get all company addresses
GenericDelegator delegator = postalAddress.getDelegator();
List postalAddresses = new LinkedList();
try {
List partyContactMechs = delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", companyPartyId));
partyContactMechs = EntityUtil.filterByDate(partyContactMechs);
if (partyContactMechs != null) {
Iterator pci = partyContactMechs.iterator();
while (pci.hasNext()) {
GenericValue pcm = (GenericValue) pci.next();
GenericValue addr = pcm.getRelatedOne("PostalAddress");
if (addr != null) {
postalAddresses.add(addr);
}
}
}
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get party postal addresses", module);
}
if (postalAddresses != null) {
Iterator pai = postalAddresses.iterator();
while (pai.hasNext()) {
GenericValue addr = (GenericValue) pai.next();
String thisAddr1 = addr.getString("address1");
String thisAddr2 = addr.getString("address2");
String thisState = addr.getString("stateProvinceGeoId");
if (thisState != null) {
thisState = thisState.replaceAll("\\W", "").toLowerCase();
} else {
thisState = "";
}
if (thisAddr1 != null) {
thisAddr1 = thisAddr1.replaceAll("\\W", "").toLowerCase();
} else {
thisAddr1 = "";
}
if (thisAddr2 != null) {
thisAddr2 = thisAddr2.replaceAll("\\W", "").toLowerCase();
} else {
thisAddr2 = "";
}
if (thisAddr1.equals(addr1) && thisAddr2.equals(addr2) && thisState.equals(state)) {
return true;
}
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -