Source Code Cross Referenced for ContactMechWorker.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » party » contact » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » SourceTap CRM » org.ofbiz.party.contact 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $Id: ContactMechWorker.java,v 1.4 2003/11/21 20:01:49 ajzeneski Exp $
0003:         *
0004:         *  Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
0005:         *
0006:         *  Permission is hereby granted, free of charge, to any person obtaining a
0007:         *  copy of this software and associated documentation files (the "Software"),
0008:         *  to deal in the Software without restriction, including without limitation
0009:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
0010:         *  and/or sell copies of the Software, and to permit persons to whom the
0011:         *  Software is furnished to do so, subject to the following conditions:
0012:         *
0013:         *  The above copyright notice and this permission notice shall be included
0014:         *  in all copies or substantial portions of the Software.
0015:         *
0016:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0017:         *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0018:         *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0019:         *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0020:         *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
0021:         *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
0022:         *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0023:         */
0024:        package org.ofbiz.party.contact;
0025:
0026:        import java.util.Collection;
0027:        import java.util.HashMap;
0028:        import java.util.Iterator;
0029:        import java.util.LinkedList;
0030:        import java.util.List;
0031:        import java.util.Map;
0032:
0033:        import javax.servlet.ServletRequest;
0034:        import javax.servlet.jsp.PageContext;
0035:
0036:        import org.ofbiz.base.util.Debug;
0037:        import org.ofbiz.base.util.UtilMisc;
0038:        import org.ofbiz.base.util.UtilProperties;
0039:        import org.ofbiz.entity.GenericDelegator;
0040:        import org.ofbiz.entity.GenericEntityException;
0041:        import org.ofbiz.entity.GenericValue;
0042:        import org.ofbiz.entity.util.EntityUtil;
0043:
0044:        /**
0045:         * Worker methods for Contact Mechanisms
0046:         *
0047:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
0048:         * @version    $Revision: 1.4 $
0049:         * @since      2.0
0050:         */
0051:        public class ContactMechWorker {
0052:
0053:            public static final String module = ContactMechWorker.class
0054:                    .getName();
0055:
0056:            public static void getPartyContactMechValueMaps(
0057:                    PageContext pageContext, String partyId, boolean showOld,
0058:                    String partyContactMechValueMapsAttr) {
0059:                GenericDelegator delegator = (GenericDelegator) pageContext
0060:                        .getRequest().getAttribute("delegator");
0061:                List partyContactMechValueMaps = getPartyContactMechValueMaps(
0062:                        delegator, partyId, showOld);
0063:                if (partyContactMechValueMaps.size() > 0) {
0064:                    pageContext.setAttribute(partyContactMechValueMapsAttr,
0065:                            partyContactMechValueMaps);
0066:                }
0067:            }
0068:
0069:            public static List getPartyContactMechValueMaps(
0070:                    GenericDelegator delegator, String partyId, boolean showOld) {
0071:                return getPartyContactMechValueMaps(delegator, partyId,
0072:                        showOld, null);
0073:            }
0074:
0075:            public static List getPartyContactMechValueMaps(
0076:                    GenericDelegator delegator, String partyId,
0077:                    boolean showOld, String contactMechTypeId) {
0078:                List partyContactMechValueMaps = new LinkedList();
0079:
0080:                Iterator allPartyContactMechs = null;
0081:
0082:                try {
0083:                    List tempCol = delegator.findByAnd("PartyContactMech",
0084:                            UtilMisc.toMap("partyId", partyId));
0085:                    if (contactMechTypeId != null) {
0086:                        List tempColTemp = new LinkedList();
0087:                        for (Iterator iterator = tempCol.iterator(); iterator
0088:                                .hasNext();) {
0089:                            GenericValue partyContactMech = (GenericValue) iterator
0090:                                    .next();
0091:                            GenericValue contactMech = delegator.getRelatedOne(
0092:                                    "ContactMech", partyContactMech);
0093:                            if (contactMech != null
0094:                                    && contactMechTypeId.equals(contactMech
0095:                                            .getString("contactMechTypeId"))) {
0096:                                tempColTemp.add(partyContactMech);
0097:                            }
0098:
0099:                        }
0100:                        tempCol = tempColTemp;
0101:                    }
0102:                    if (!showOld)
0103:                        tempCol = EntityUtil.filterByDate(tempCol, true);
0104:                    allPartyContactMechs = UtilMisc.toIterator(tempCol);
0105:                } catch (GenericEntityException e) {
0106:                    Debug.logWarning(e, module);
0107:                }
0108:
0109:                while (allPartyContactMechs != null
0110:                        && allPartyContactMechs.hasNext()) {
0111:                    GenericValue partyContactMech = (GenericValue) allPartyContactMechs
0112:                            .next();
0113:                    GenericValue contactMech = null;
0114:
0115:                    try {
0116:                        contactMech = partyContactMech
0117:                                .getRelatedOne("ContactMech");
0118:                    } catch (GenericEntityException e) {
0119:                        Debug.logWarning(e, module);
0120:                    }
0121:                    if (contactMech != null) {
0122:                        Map partyContactMechValueMap = new HashMap();
0123:
0124:                        partyContactMechValueMaps.add(partyContactMechValueMap);
0125:                        partyContactMechValueMap
0126:                                .put("contactMech", contactMech);
0127:                        partyContactMechValueMap.put("partyContactMech",
0128:                                partyContactMech);
0129:
0130:                        try {
0131:                            partyContactMechValueMap
0132:                                    .put(
0133:                                            "contactMechType",
0134:                                            contactMech
0135:                                                    .getRelatedOneCache("ContactMechType"));
0136:                        } catch (GenericEntityException e) {
0137:                            Debug.logWarning(e, module);
0138:                        }
0139:
0140:                        try {
0141:                            List partyContactMechPurposes = partyContactMech
0142:                                    .getRelated("PartyContactMechPurpose");
0143:
0144:                            if (!showOld)
0145:                                partyContactMechPurposes = EntityUtil
0146:                                        .filterByDate(partyContactMechPurposes,
0147:                                                true);
0148:                            partyContactMechValueMap.put(
0149:                                    "partyContactMechPurposes",
0150:                                    partyContactMechPurposes);
0151:                        } catch (GenericEntityException e) {
0152:                            Debug.logWarning(e, module);
0153:                        }
0154:
0155:                        try {
0156:                            if ("POSTAL_ADDRESS".equals(contactMech
0157:                                    .getString("contactMechTypeId"))) {
0158:                                partyContactMechValueMap
0159:                                        .put("postalAddress", contactMech
0160:                                                .getRelatedOne("PostalAddress"));
0161:                            } else if ("TELECOM_NUMBER".equals(contactMech
0162:                                    .getString("contactMechTypeId"))) {
0163:                                partyContactMechValueMap
0164:                                        .put("telecomNumber", contactMech
0165:                                                .getRelatedOne("TelecomNumber"));
0166:                            }
0167:                        } catch (GenericEntityException e) {
0168:                            Debug.logWarning(e, module);
0169:                        }
0170:                    }
0171:                }
0172:
0173:                return partyContactMechValueMaps;
0174:            }
0175:
0176:            public static List getFacilityContactMechValueMaps(
0177:                    GenericDelegator delegator, String facilityId,
0178:                    boolean showOld, String contactMechTypeId) {
0179:                List facilityContactMechValueMaps = new LinkedList();
0180:
0181:                Iterator allFacilityContactMechs = null;
0182:
0183:                try {
0184:                    List tempCol = delegator.findByAnd("FacilityContactMech",
0185:                            UtilMisc.toMap("facilityId", facilityId));
0186:                    if (contactMechTypeId != null) {
0187:                        List tempColTemp = new LinkedList();
0188:                        for (Iterator iterator = tempCol.iterator(); iterator
0189:                                .hasNext();) {
0190:                            GenericValue partyContactMech = (GenericValue) iterator
0191:                                    .next();
0192:                            GenericValue contactMech = delegator.getRelatedOne(
0193:                                    "ContactMech", partyContactMech);
0194:                            if (contactMech != null
0195:                                    && contactMechTypeId.equals(contactMech
0196:                                            .getString("contactMechTypeId"))) {
0197:                                tempColTemp.add(partyContactMech);
0198:                            }
0199:
0200:                        }
0201:                        tempCol = tempColTemp;
0202:                    }
0203:                    if (!showOld)
0204:                        tempCol = EntityUtil.filterByDate(tempCol, true);
0205:                    allFacilityContactMechs = UtilMisc.toIterator(tempCol);
0206:                } catch (GenericEntityException e) {
0207:                    Debug.logWarning(e, module);
0208:                }
0209:
0210:                while (allFacilityContactMechs != null
0211:                        && allFacilityContactMechs.hasNext()) {
0212:                    GenericValue facilityContactMech = (GenericValue) allFacilityContactMechs
0213:                            .next();
0214:                    GenericValue contactMech = null;
0215:
0216:                    try {
0217:                        contactMech = facilityContactMech
0218:                                .getRelatedOne("ContactMech");
0219:                    } catch (GenericEntityException e) {
0220:                        Debug.logWarning(e, module);
0221:                    }
0222:                    if (contactMech != null) {
0223:                        Map facilityContactMechValueMap = new HashMap();
0224:
0225:                        facilityContactMechValueMaps
0226:                                .add(facilityContactMechValueMap);
0227:                        facilityContactMechValueMap.put("contactMech",
0228:                                contactMech);
0229:                        facilityContactMechValueMap.put("facilityContactMech",
0230:                                facilityContactMech);
0231:
0232:                        try {
0233:                            facilityContactMechValueMap
0234:                                    .put(
0235:                                            "contactMechType",
0236:                                            contactMech
0237:                                                    .getRelatedOneCache("ContactMechType"));
0238:                        } catch (GenericEntityException e) {
0239:                            Debug.logWarning(e, module);
0240:                        }
0241:
0242:                        try {
0243:                            List facilityContactMechPurposes = facilityContactMech
0244:                                    .getRelated("FacilityContactMechPurpose");
0245:
0246:                            if (!showOld)
0247:                                facilityContactMechPurposes = EntityUtil
0248:                                        .filterByDate(
0249:                                                facilityContactMechPurposes,
0250:                                                true);
0251:                            facilityContactMechValueMap.put(
0252:                                    "facilityContactMechPurposes",
0253:                                    facilityContactMechPurposes);
0254:                        } catch (GenericEntityException e) {
0255:                            Debug.logWarning(e, module);
0256:                        }
0257:
0258:                        try {
0259:                            if ("POSTAL_ADDRESS".equals(contactMech
0260:                                    .getString("contactMechTypeId"))) {
0261:                                facilityContactMechValueMap
0262:                                        .put("postalAddress", contactMech
0263:                                                .getRelatedOne("PostalAddress"));
0264:                            } else if ("TELECOM_NUMBER".equals(contactMech
0265:                                    .getString("contactMechTypeId"))) {
0266:                                facilityContactMechValueMap
0267:                                        .put("telecomNumber", contactMech
0268:                                                .getRelatedOne("TelecomNumber"));
0269:                            }
0270:                        } catch (GenericEntityException e) {
0271:                            Debug.logWarning(e, module);
0272:                        }
0273:                    }
0274:                }
0275:
0276:                return facilityContactMechValueMaps;
0277:            }
0278:
0279:            public static void getOrderContactMechValueMaps(
0280:                    PageContext pageContext, String orderId,
0281:                    String orderContactMechValueMapsAttr) {
0282:                GenericDelegator delegator = (GenericDelegator) pageContext
0283:                        .getRequest().getAttribute("delegator");
0284:                List maps = getOrderContactMechValueMaps(delegator, orderId);
0285:                if (maps != null && maps.size() > 0) {
0286:                    pageContext.setAttribute(orderContactMechValueMapsAttr,
0287:                            maps);
0288:                }
0289:            }
0290:
0291:            public static List getOrderContactMechValueMaps(
0292:                    GenericDelegator delegator, String orderId) {
0293:                List orderContactMechValueMaps = new LinkedList();
0294:
0295:                Iterator allOrderContactMechs = null;
0296:
0297:                try {
0298:                    Collection tempCol = delegator.findByAnd(
0299:                            "OrderContactMech", UtilMisc.toMap("orderId",
0300:                                    orderId), UtilMisc
0301:                                    .toList("contactMechPurposeTypeId"));
0302:
0303:                    allOrderContactMechs = UtilMisc.toIterator(tempCol);
0304:                } catch (GenericEntityException e) {
0305:                    Debug.logWarning(e, module);
0306:                }
0307:
0308:                while (allOrderContactMechs != null
0309:                        && allOrderContactMechs.hasNext()) {
0310:                    GenericValue orderContactMech = (GenericValue) allOrderContactMechs
0311:                            .next();
0312:                    GenericValue contactMech = null;
0313:
0314:                    try {
0315:                        contactMech = orderContactMech
0316:                                .getRelatedOne("ContactMech");
0317:                    } catch (GenericEntityException e) {
0318:                        Debug.logWarning(e, module);
0319:                    }
0320:                    if (contactMech != null) {
0321:                        Map orderContactMechValueMap = new HashMap();
0322:
0323:                        orderContactMechValueMaps.add(orderContactMechValueMap);
0324:                        orderContactMechValueMap
0325:                                .put("contactMech", contactMech);
0326:                        orderContactMechValueMap.put("orderContactMech",
0327:                                orderContactMech);
0328:
0329:                        try {
0330:                            orderContactMechValueMap
0331:                                    .put(
0332:                                            "contactMechType",
0333:                                            contactMech
0334:                                                    .getRelatedOneCache("ContactMechType"));
0335:                        } catch (GenericEntityException e) {
0336:                            Debug.logWarning(e, module);
0337:                        }
0338:
0339:                        try {
0340:                            GenericValue contactMechPurposeType = orderContactMech
0341:                                    .getRelatedOne("ContactMechPurposeType");
0342:
0343:                            orderContactMechValueMap.put(
0344:                                    "contactMechPurposeType",
0345:                                    contactMechPurposeType);
0346:                        } catch (GenericEntityException e) {
0347:                            Debug.logWarning(e, module);
0348:                        }
0349:
0350:                        try {
0351:                            if ("POSTAL_ADDRESS".equals(contactMech
0352:                                    .getString("contactMechTypeId"))) {
0353:                                orderContactMechValueMap
0354:                                        .put("postalAddress", contactMech
0355:                                                .getRelatedOne("PostalAddress"));
0356:                            } else if ("TELECOM_NUMBER".equals(contactMech
0357:                                    .getString("contactMechTypeId"))) {
0358:                                orderContactMechValueMap
0359:                                        .put("telecomNumber", contactMech
0360:                                                .getRelatedOne("TelecomNumber"));
0361:                            }
0362:                        } catch (GenericEntityException e) {
0363:                            Debug.logWarning(e, module);
0364:                        }
0365:                    }
0366:                }
0367:
0368:                return orderContactMechValueMaps;
0369:            }
0370:
0371:            public static Collection getWorkEffortContactMechValueMaps(
0372:                    GenericDelegator delegator, String workEffortId) {
0373:                Collection workEffortContactMechValueMaps = new LinkedList();
0374:
0375:                Iterator allWorkEffortContactMechs = null;
0376:
0377:                try {
0378:                    Collection tempCol = delegator.findByAnd(
0379:                            "WorkEffortContactMech", UtilMisc.toMap(
0380:                                    "workEffortId", workEffortId));
0381:                    allWorkEffortContactMechs = UtilMisc.toIterator(tempCol);
0382:                } catch (GenericEntityException e) {
0383:                    Debug.logWarning(e, module);
0384:                }
0385:
0386:                while (allWorkEffortContactMechs != null
0387:                        && allWorkEffortContactMechs.hasNext()) {
0388:                    GenericValue workEffortContactMech = (GenericValue) allWorkEffortContactMechs
0389:                            .next();
0390:                    GenericValue contactMech = null;
0391:
0392:                    try {
0393:                        contactMech = workEffortContactMech
0394:                                .getRelatedOne("ContactMech");
0395:                    } catch (GenericEntityException e) {
0396:                        Debug.logWarning(e, module);
0397:                    }
0398:                    if (contactMech != null) {
0399:                        Map workEffortContactMechValueMap = new HashMap();
0400:
0401:                        workEffortContactMechValueMaps
0402:                                .add(workEffortContactMechValueMap);
0403:                        workEffortContactMechValueMap.put("contactMech",
0404:                                contactMech);
0405:                        workEffortContactMechValueMap.put(
0406:                                "workEffortContactMech", workEffortContactMech);
0407:
0408:                        try {
0409:                            workEffortContactMechValueMap
0410:                                    .put(
0411:                                            "contactMechType",
0412:                                            contactMech
0413:                                                    .getRelatedOneCache("ContactMechType"));
0414:                        } catch (GenericEntityException e) {
0415:                            Debug.logWarning(e, module);
0416:                        }
0417:
0418:                        try {
0419:                            if ("POSTAL_ADDRESS".equals(contactMech
0420:                                    .getString("contactMechTypeId"))) {
0421:                                workEffortContactMechValueMap
0422:                                        .put("postalAddress", contactMech
0423:                                                .getRelatedOne("PostalAddress"));
0424:                            } else if ("TELECOM_NUMBER".equals(contactMech
0425:                                    .getString("contactMechTypeId"))) {
0426:                                workEffortContactMechValueMap
0427:                                        .put("telecomNumber", contactMech
0428:                                                .getRelatedOne("TelecomNumber"));
0429:                            }
0430:                        } catch (GenericEntityException e) {
0431:                            Debug.logWarning(e, module);
0432:                        }
0433:                    }
0434:                }
0435:
0436:                return workEffortContactMechValueMaps.size() > 0 ? workEffortContactMechValueMaps
0437:                        : null;
0438:            }
0439:
0440:            /** 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 */
0441:            public static void getContactMechAndRelated(
0442:                    PageContext pageContext, String partyId,
0443:                    String contactMechAttr, String contactMechIdAttr,
0444:                    String partyContactMechAttr,
0445:                    String partyContactMechPurposesAttr,
0446:                    String contactMechTypeIdAttr, String contactMechTypeAttr,
0447:                    String purposeTypesAttr, String postalAddressAttr,
0448:                    String telecomNumberAttr, String requestNameAttr,
0449:                    String donePageAttr, String tryEntityAttr,
0450:                    String contactMechTypesAttr) {
0451:
0452:                ServletRequest request = pageContext.getRequest();
0453:                GenericDelegator delegator = (GenericDelegator) pageContext
0454:                        .getRequest().getAttribute("delegator");
0455:
0456:                boolean tryEntity = true;
0457:
0458:                if (request.getAttribute("_ERROR_MESSAGE_") != null)
0459:                    tryEntity = false;
0460:                if ("true".equals(request.getParameter("tryEntity")))
0461:                    tryEntity = true;
0462:
0463:                String donePage = request.getParameter("DONE_PAGE");
0464:
0465:                if (donePage == null)
0466:                    donePage = (String) request.getAttribute("DONE_PAGE");
0467:                if (donePage == null || donePage.length() <= 0)
0468:                    donePage = "viewprofile";
0469:                pageContext.setAttribute(donePageAttr, donePage);
0470:
0471:                String contactMechTypeId = request
0472:                        .getParameter("preContactMechTypeId");
0473:
0474:                if (contactMechTypeId == null)
0475:                    contactMechTypeId = (String) request
0476:                            .getAttribute("preContactMechTypeId");
0477:                if (contactMechTypeId != null)
0478:                    tryEntity = false;
0479:
0480:                String contactMechId = request.getParameter("contactMechId");
0481:
0482:                if (request.getAttribute("contactMechId") != null)
0483:                    contactMechId = (String) request
0484:                            .getAttribute("contactMechId");
0485:
0486:                GenericValue contactMech = null;
0487:
0488:                if (contactMechId != null) {
0489:                    pageContext.setAttribute(contactMechIdAttr, contactMechId);
0490:
0491:                    // try to find a PartyContactMech with a valid date range
0492:                    List partyContactMechs = null;
0493:
0494:                    try {
0495:                        partyContactMechs = EntityUtil.filterByDate(delegator
0496:                                .findByAnd("PartyContactMech", UtilMisc.toMap(
0497:                                        "partyId", partyId, "contactMechId",
0498:                                        contactMechId)), true);
0499:                    } catch (GenericEntityException e) {
0500:                        Debug.logWarning(e, module);
0501:                    }
0502:
0503:                    GenericValue partyContactMech = EntityUtil
0504:                            .getFirst(partyContactMechs);
0505:
0506:                    if (partyContactMech != null) {
0507:                        pageContext.setAttribute(partyContactMechAttr,
0508:                                partyContactMech);
0509:
0510:                        Collection partyContactMechPurposes = null;
0511:
0512:                        try {
0513:                            partyContactMechPurposes = EntityUtil
0514:                                    .filterByDate(
0515:                                            partyContactMech
0516:                                                    .getRelated("PartyContactMechPurpose"),
0517:                                            true);
0518:                        } catch (GenericEntityException e) {
0519:                            Debug.logWarning(e, module);
0520:                        }
0521:                        if (partyContactMechPurposes != null
0522:                                && partyContactMechPurposes.size() > 0)
0523:                            pageContext.setAttribute(
0524:                                    partyContactMechPurposesAttr,
0525:                                    partyContactMechPurposes);
0526:                    }
0527:
0528:                    try {
0529:                        contactMech = delegator.findByPrimaryKey("ContactMech",
0530:                                UtilMisc.toMap("contactMechId", contactMechId));
0531:                    } catch (GenericEntityException e) {
0532:                        Debug.logWarning(e, module);
0533:                    }
0534:
0535:                    if (contactMech != null) {
0536:                        pageContext.setAttribute(contactMechAttr, contactMech);
0537:                        contactMechTypeId = contactMech
0538:                                .getString("contactMechTypeId");
0539:                    }
0540:                }
0541:
0542:                if (contactMechTypeId != null) {
0543:                    pageContext.setAttribute(contactMechTypeIdAttr,
0544:                            contactMechTypeId);
0545:
0546:                    try {
0547:                        GenericValue contactMechType = delegator
0548:                                .findByPrimaryKey("ContactMechType", UtilMisc
0549:                                        .toMap("contactMechTypeId",
0550:                                                contactMechTypeId));
0551:
0552:                        if (contactMechType != null)
0553:                            pageContext.setAttribute(contactMechTypeAttr,
0554:                                    contactMechType);
0555:                    } catch (GenericEntityException e) {
0556:                        Debug.logWarning(e, module);
0557:                    }
0558:
0559:                    Collection purposeTypes = new LinkedList();
0560:                    Iterator typePurposes = null;
0561:
0562:                    try {
0563:                        typePurposes = UtilMisc.toIterator(delegator
0564:                                .findByAnd("ContactMechTypePurpose", UtilMisc
0565:                                        .toMap("contactMechTypeId",
0566:                                                contactMechTypeId)));
0567:                    } catch (GenericEntityException e) {
0568:                        Debug.logWarning(e, module);
0569:                    }
0570:                    while (typePurposes != null && typePurposes.hasNext()) {
0571:                        GenericValue contactMechTypePurpose = (GenericValue) typePurposes
0572:                                .next();
0573:                        GenericValue contactMechPurposeType = null;
0574:
0575:                        try {
0576:                            contactMechPurposeType = contactMechTypePurpose
0577:                                    .getRelatedOne("ContactMechPurposeType");
0578:                        } catch (GenericEntityException e) {
0579:                            Debug.logWarning(e, module);
0580:                        }
0581:                        if (contactMechPurposeType != null) {
0582:                            purposeTypes.add(contactMechPurposeType);
0583:                        }
0584:                    }
0585:                    if (purposeTypes.size() > 0)
0586:                        pageContext
0587:                                .setAttribute(purposeTypesAttr, purposeTypes);
0588:                }
0589:
0590:                String requestName;
0591:
0592:                if (contactMech == null) {
0593:                    // create
0594:                    if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
0595:                        if (request.getParameter("contactMechPurposeTypeId") != null
0596:                                || request
0597:                                        .getAttribute("contactMechPurposeTypeId") != null) {
0598:                            requestName = "createPostalAddressAndPurpose";
0599:                        } else {
0600:                            requestName = "createPostalAddress";
0601:                        }
0602:                    } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
0603:                        requestName = "createTelecomNumber";
0604:                    } else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
0605:                        requestName = "createEmailAddress";
0606:                    } else {
0607:                        requestName = "createContactMech";
0608:                    }
0609:                } else {
0610:                    // update
0611:                    if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
0612:                        requestName = "updatePostalAddress";
0613:                    } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
0614:                        requestName = "updateTelecomNumber";
0615:                    } else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
0616:                        requestName = "updateEmailAddress";
0617:                    } else {
0618:                        requestName = "updateContactMech";
0619:                    }
0620:                }
0621:                pageContext.setAttribute(requestNameAttr, requestName);
0622:
0623:                if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
0624:                    GenericValue postalAddress = null;
0625:
0626:                    try {
0627:                        if (contactMech != null)
0628:                            postalAddress = contactMech
0629:                                    .getRelatedOne("PostalAddress");
0630:                    } catch (GenericEntityException e) {
0631:                        Debug.logWarning(e, module);
0632:                    }
0633:                    if (postalAddress != null)
0634:                        pageContext.setAttribute(postalAddressAttr,
0635:                                postalAddress);
0636:                } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
0637:                    GenericValue telecomNumber = null;
0638:
0639:                    try {
0640:                        if (contactMech != null)
0641:                            telecomNumber = contactMech
0642:                                    .getRelatedOne("TelecomNumber");
0643:                    } catch (GenericEntityException e) {
0644:                        Debug.logWarning(e, module);
0645:                    }
0646:                    if (telecomNumber != null)
0647:                        pageContext.setAttribute(telecomNumberAttr,
0648:                                telecomNumber);
0649:                }
0650:
0651:                if ("true".equals(request.getParameter("useValues")))
0652:                    tryEntity = true;
0653:                pageContext.setAttribute(tryEntityAttr, new Boolean(tryEntity));
0654:
0655:                try {
0656:                    Collection contactMechTypes = delegator.findAllCache(
0657:                            "ContactMechType", null);
0658:
0659:                    if (contactMechTypes != null) {
0660:                        pageContext.setAttribute(contactMechTypesAttr,
0661:                                contactMechTypes);
0662:                    }
0663:                } catch (GenericEntityException e) {
0664:                    Debug.logWarning(e, module);
0665:                }
0666:            }
0667:
0668:            public static void getContactMechAndRelated(ServletRequest request,
0669:                    String partyId, Map target) {
0670:                GenericDelegator delegator = (GenericDelegator) request
0671:                        .getAttribute("delegator");
0672:
0673:                boolean tryEntity = true;
0674:                if (request.getAttribute("_ERROR_MESSAGE_") != null)
0675:                    tryEntity = false;
0676:                if ("true".equals(request.getParameter("tryEntity")))
0677:                    tryEntity = true;
0678:
0679:                String donePage = request.getParameter("DONE_PAGE");
0680:                if (donePage == null)
0681:                    donePage = (String) request.getAttribute("DONE_PAGE");
0682:                if (donePage == null || donePage.length() <= 0)
0683:                    donePage = "viewprofile";
0684:                target.put("donePage", donePage);
0685:
0686:                String contactMechTypeId = request
0687:                        .getParameter("preContactMechTypeId");
0688:
0689:                if (contactMechTypeId == null)
0690:                    contactMechTypeId = (String) request
0691:                            .getAttribute("preContactMechTypeId");
0692:                if (contactMechTypeId != null)
0693:                    tryEntity = false;
0694:
0695:                String contactMechId = request.getParameter("contactMechId");
0696:
0697:                if (request.getAttribute("contactMechId") != null)
0698:                    contactMechId = (String) request
0699:                            .getAttribute("contactMechId");
0700:
0701:                GenericValue contactMech = null;
0702:
0703:                if (contactMechId != null) {
0704:                    target.put("contactMechId", contactMechId);
0705:
0706:                    // try to find a PartyContactMech with a valid date range
0707:                    List partyContactMechs = null;
0708:
0709:                    try {
0710:                        partyContactMechs = EntityUtil.filterByDate(delegator
0711:                                .findByAnd("PartyContactMech", UtilMisc.toMap(
0712:                                        "partyId", partyId, "contactMechId",
0713:                                        contactMechId)), true);
0714:                    } catch (GenericEntityException e) {
0715:                        Debug.logWarning(e, module);
0716:                    }
0717:
0718:                    GenericValue partyContactMech = EntityUtil
0719:                            .getFirst(partyContactMechs);
0720:
0721:                    if (partyContactMech != null) {
0722:                        target.put("partyContactMech", partyContactMech);
0723:
0724:                        Collection partyContactMechPurposes = null;
0725:
0726:                        try {
0727:                            partyContactMechPurposes = EntityUtil
0728:                                    .filterByDate(
0729:                                            partyContactMech
0730:                                                    .getRelated("PartyContactMechPurpose"),
0731:                                            true);
0732:                        } catch (GenericEntityException e) {
0733:                            Debug.logWarning(e, module);
0734:                        }
0735:                        if (partyContactMechPurposes != null
0736:                                && partyContactMechPurposes.size() > 0)
0737:                            target.put("partyContactMechPurposes",
0738:                                    partyContactMechPurposes);
0739:                    }
0740:
0741:                    try {
0742:                        contactMech = delegator.findByPrimaryKey("ContactMech",
0743:                                UtilMisc.toMap("contactMechId", contactMechId));
0744:                    } catch (GenericEntityException e) {
0745:                        Debug.logWarning(e, module);
0746:                    }
0747:
0748:                    if (contactMech != null) {
0749:                        target.put("contactMech", contactMech);
0750:                        contactMechTypeId = contactMech
0751:                                .getString("contactMechTypeId");
0752:                    }
0753:                }
0754:
0755:                if (contactMechTypeId != null) {
0756:                    target.put("contactMechTypeId", contactMechTypeId);
0757:
0758:                    try {
0759:                        GenericValue contactMechType = delegator
0760:                                .findByPrimaryKey("ContactMechType", UtilMisc
0761:                                        .toMap("contactMechTypeId",
0762:                                                contactMechTypeId));
0763:
0764:                        if (contactMechType != null)
0765:                            target.put("contactMechType", contactMechType);
0766:                    } catch (GenericEntityException e) {
0767:                        Debug.logWarning(e, module);
0768:                    }
0769:
0770:                    Collection purposeTypes = new LinkedList();
0771:                    Iterator typePurposes = null;
0772:
0773:                    try {
0774:                        typePurposes = UtilMisc.toIterator(delegator
0775:                                .findByAnd("ContactMechTypePurpose", UtilMisc
0776:                                        .toMap("contactMechTypeId",
0777:                                                contactMechTypeId)));
0778:                    } catch (GenericEntityException e) {
0779:                        Debug.logWarning(e, module);
0780:                    }
0781:                    while (typePurposes != null && typePurposes.hasNext()) {
0782:                        GenericValue contactMechTypePurpose = (GenericValue) typePurposes
0783:                                .next();
0784:                        GenericValue contactMechPurposeType = null;
0785:
0786:                        try {
0787:                            contactMechPurposeType = contactMechTypePurpose
0788:                                    .getRelatedOne("ContactMechPurposeType");
0789:                        } catch (GenericEntityException e) {
0790:                            Debug.logWarning(e, module);
0791:                        }
0792:                        if (contactMechPurposeType != null) {
0793:                            purposeTypes.add(contactMechPurposeType);
0794:                        }
0795:                    }
0796:                    if (purposeTypes.size() > 0)
0797:                        target.put("purposeTypes", purposeTypes);
0798:                }
0799:
0800:                String requestName;
0801:
0802:                if (contactMech == null) {
0803:                    // create
0804:                    if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
0805:                        if (request.getParameter("contactMechPurposeTypeId") != null
0806:                                || request
0807:                                        .getAttribute("contactMechPurposeTypeId") != null) {
0808:                            requestName = "createPostalAddressAndPurpose";
0809:                        } else {
0810:                            requestName = "createPostalAddress";
0811:                        }
0812:                    } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
0813:                        requestName = "createTelecomNumber";
0814:                    } else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
0815:                        requestName = "createEmailAddress";
0816:                    } else {
0817:                        requestName = "createContactMech";
0818:                    }
0819:                } else {
0820:                    // update
0821:                    if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
0822:                        requestName = "updatePostalAddress";
0823:                    } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
0824:                        requestName = "updateTelecomNumber";
0825:                    } else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
0826:                        requestName = "updateEmailAddress";
0827:                    } else {
0828:                        requestName = "updateContactMech";
0829:                    }
0830:                }
0831:                target.put("requestName", requestName);
0832:
0833:                if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
0834:                    GenericValue postalAddress = null;
0835:
0836:                    try {
0837:                        if (contactMech != null)
0838:                            postalAddress = contactMech
0839:                                    .getRelatedOne("PostalAddress");
0840:                    } catch (GenericEntityException e) {
0841:                        Debug.logWarning(e, module);
0842:                    }
0843:                    if (postalAddress != null)
0844:                        target.put("postalAddress", postalAddress);
0845:                } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
0846:                    GenericValue telecomNumber = null;
0847:
0848:                    try {
0849:                        if (contactMech != null)
0850:                            telecomNumber = contactMech
0851:                                    .getRelatedOne("TelecomNumber");
0852:                    } catch (GenericEntityException e) {
0853:                        Debug.logWarning(e, module);
0854:                    }
0855:                    if (telecomNumber != null)
0856:                        target.put("telecomNumber", telecomNumber);
0857:                }
0858:
0859:                if ("true".equals(request.getParameter("useValues")))
0860:                    tryEntity = true;
0861:                target.put("tryEntity", new Boolean(tryEntity));
0862:
0863:                try {
0864:                    Collection contactMechTypes = delegator.findAllCache(
0865:                            "ContactMechType", null);
0866:
0867:                    if (contactMechTypes != null) {
0868:                        target.put("contactMechTypes", contactMechTypes);
0869:                    }
0870:                } catch (GenericEntityException e) {
0871:                    Debug.logWarning(e, module);
0872:                }
0873:            }
0874:
0875:            public static void getFacilityContactMechAndRelated(
0876:                    ServletRequest request, String facilityId, Map target) {
0877:                GenericDelegator delegator = (GenericDelegator) request
0878:                        .getAttribute("delegator");
0879:
0880:                boolean tryEntity = true;
0881:                if (request.getAttribute("_ERROR_MESSAGE") != null)
0882:                    tryEntity = false;
0883:                if ("true".equals(request.getParameter("tryEntity")))
0884:                    tryEntity = true;
0885:
0886:                String donePage = request.getParameter("DONE_PAGE");
0887:                if (donePage == null)
0888:                    donePage = (String) request.getAttribute("DONE_PAGE");
0889:                if (donePage == null || donePage.length() <= 0)
0890:                    donePage = "viewprofile";
0891:                target.put("donePage", donePage);
0892:
0893:                String contactMechTypeId = request
0894:                        .getParameter("preContactMechTypeId");
0895:
0896:                if (contactMechTypeId == null)
0897:                    contactMechTypeId = (String) request
0898:                            .getAttribute("preContactMechTypeId");
0899:                if (contactMechTypeId != null)
0900:                    tryEntity = false;
0901:
0902:                String contactMechId = request.getParameter("contactMechId");
0903:
0904:                if (request.getAttribute("contactMechId") != null)
0905:                    contactMechId = (String) request
0906:                            .getAttribute("contactMechId");
0907:
0908:                GenericValue contactMech = null;
0909:
0910:                if (contactMechId != null) {
0911:                    target.put("contactMechId", contactMechId);
0912:
0913:                    // try to find a PartyContactMech with a valid date range
0914:                    List facilityContactMechs = null;
0915:
0916:                    try {
0917:                        facilityContactMechs = EntityUtil.filterByDate(
0918:                                delegator.findByAnd("FacilityContactMech",
0919:                                        UtilMisc.toMap("facilityId",
0920:                                                facilityId, "contactMechId",
0921:                                                contactMechId)), true);
0922:                    } catch (GenericEntityException e) {
0923:                        Debug.logWarning(e, module);
0924:                    }
0925:
0926:                    GenericValue facilityContactMech = EntityUtil
0927:                            .getFirst(facilityContactMechs);
0928:
0929:                    if (facilityContactMech != null) {
0930:                        target.put("facilityContactMech", facilityContactMech);
0931:
0932:                        Collection facilityContactMechPurposes = null;
0933:
0934:                        try {
0935:                            facilityContactMechPurposes = EntityUtil
0936:                                    .filterByDate(
0937:                                            facilityContactMech
0938:                                                    .getRelated("FacilityContactMechPurpose"),
0939:                                            true);
0940:                        } catch (GenericEntityException e) {
0941:                            Debug.logWarning(e, module);
0942:                        }
0943:                        if (facilityContactMechPurposes != null
0944:                                && facilityContactMechPurposes.size() > 0)
0945:                            target.put("facilityContactMechPurposes",
0946:                                    facilityContactMechPurposes);
0947:                    }
0948:
0949:                    try {
0950:                        contactMech = delegator.findByPrimaryKey("ContactMech",
0951:                                UtilMisc.toMap("contactMechId", contactMechId));
0952:                    } catch (GenericEntityException e) {
0953:                        Debug.logWarning(e, module);
0954:                    }
0955:
0956:                    if (contactMech != null) {
0957:                        target.put("contactMech", contactMech);
0958:                        contactMechTypeId = contactMech
0959:                                .getString("contactMechTypeId");
0960:                    }
0961:                }
0962:
0963:                if (contactMechTypeId != null) {
0964:                    target.put("contactMechTypeId", contactMechTypeId);
0965:
0966:                    try {
0967:                        GenericValue contactMechType = delegator
0968:                                .findByPrimaryKey("ContactMechType", UtilMisc
0969:                                        .toMap("contactMechTypeId",
0970:                                                contactMechTypeId));
0971:
0972:                        if (contactMechType != null)
0973:                            target.put("contactMechType", contactMechType);
0974:                    } catch (GenericEntityException e) {
0975:                        Debug.logWarning(e, module);
0976:                    }
0977:
0978:                    Collection purposeTypes = new LinkedList();
0979:                    Iterator typePurposes = null;
0980:
0981:                    try {
0982:                        typePurposes = UtilMisc.toIterator(delegator
0983:                                .findByAnd("ContactMechTypePurpose", UtilMisc
0984:                                        .toMap("contactMechTypeId",
0985:                                                contactMechTypeId)));
0986:                    } catch (GenericEntityException e) {
0987:                        Debug.logWarning(e, module);
0988:                    }
0989:                    while (typePurposes != null && typePurposes.hasNext()) {
0990:                        GenericValue contactMechTypePurpose = (GenericValue) typePurposes
0991:                                .next();
0992:                        GenericValue contactMechPurposeType = null;
0993:
0994:                        try {
0995:                            contactMechPurposeType = contactMechTypePurpose
0996:                                    .getRelatedOne("ContactMechPurposeType");
0997:                        } catch (GenericEntityException e) {
0998:                            Debug.logWarning(e, module);
0999:                        }
1000:                        if (contactMechPurposeType != null) {
1001:                            purposeTypes.add(contactMechPurposeType);
1002:                        }
1003:                    }
1004:                    if (purposeTypes.size() > 0)
1005:                        target.put("purposeTypes", purposeTypes);
1006:                }
1007:
1008:                String requestName;
1009:
1010:                if (contactMech == null) {
1011:                    // create
1012:                    if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
1013:                        if (request.getParameter("contactMechPurposeTypeId") != null
1014:                                || request
1015:                                        .getAttribute("contactMechPurposeTypeId") != null) {
1016:                            requestName = "createPostalAddressAndPurpose";
1017:                        } else {
1018:                            requestName = "createPostalAddress";
1019:                        }
1020:                    } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
1021:                        requestName = "createTelecomNumber";
1022:                    } else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
1023:                        requestName = "createEmailAddress";
1024:                    } else {
1025:                        requestName = "createContactMech";
1026:                    }
1027:                } else {
1028:                    // update
1029:                    if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
1030:                        requestName = "updatePostalAddress";
1031:                    } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
1032:                        requestName = "updateTelecomNumber";
1033:                    } else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
1034:                        requestName = "updateEmailAddress";
1035:                    } else {
1036:                        requestName = "updateContactMech";
1037:                    }
1038:                }
1039:                target.put("requestName", requestName);
1040:
1041:                if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
1042:                    GenericValue postalAddress = null;
1043:
1044:                    try {
1045:                        if (contactMech != null)
1046:                            postalAddress = contactMech
1047:                                    .getRelatedOne("PostalAddress");
1048:                    } catch (GenericEntityException e) {
1049:                        Debug.logWarning(e, module);
1050:                    }
1051:                    if (postalAddress != null)
1052:                        target.put("postalAddress", postalAddress);
1053:                } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
1054:                    GenericValue telecomNumber = null;
1055:
1056:                    try {
1057:                        if (contactMech != null)
1058:                            telecomNumber = contactMech
1059:                                    .getRelatedOne("TelecomNumber");
1060:                    } catch (GenericEntityException e) {
1061:                        Debug.logWarning(e, module);
1062:                    }
1063:                    if (telecomNumber != null)
1064:                        target.put("telecomNumber", telecomNumber);
1065:                }
1066:
1067:                if ("true".equals(request.getParameter("useValues")))
1068:                    tryEntity = true;
1069:                target.put("tryEntity", new Boolean(tryEntity));
1070:
1071:                try {
1072:                    Collection contactMechTypes = delegator.findAllCache(
1073:                            "ContactMechType", null);
1074:
1075:                    if (contactMechTypes != null) {
1076:                        target.put("contactMechTypes", contactMechTypes);
1077:                    }
1078:                } catch (GenericEntityException e) {
1079:                    Debug.logWarning(e, module);
1080:                }
1081:            }
1082:
1083:            /** 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 */
1084:            public static void getPartyPostalAddresses(PageContext pageContext,
1085:                    String partyId, String curContactMechId,
1086:                    String postalAddressInfosAttr) {
1087:                ServletRequest request = pageContext.getRequest();
1088:                List postalAddressInfos = getPartyPostalAddresses(request,
1089:                        partyId, curContactMechId);
1090:                if (postalAddressInfos.size() > 0) {
1091:                    pageContext.setAttribute(postalAddressInfosAttr,
1092:                            postalAddressInfos);
1093:                }
1094:            }
1095:
1096:            public static List getPartyPostalAddresses(ServletRequest request,
1097:                    String partyId, String curContactMechId) {
1098:                GenericDelegator delegator = (GenericDelegator) request
1099:                        .getAttribute("delegator");
1100:                List postalAddressInfos = new LinkedList();
1101:
1102:                Iterator allPartyContactMechs = null;
1103:
1104:                try {
1105:                    allPartyContactMechs = UtilMisc.toIterator(EntityUtil
1106:                            .filterByDate(delegator.findByAnd(
1107:                                    "PartyContactMech", UtilMisc.toMap(
1108:                                            "partyId", partyId)), true));
1109:                } catch (GenericEntityException e) {
1110:                    Debug.logWarning(e, module);
1111:                }
1112:                while (allPartyContactMechs != null
1113:                        && allPartyContactMechs.hasNext()) {
1114:                    GenericValue partyContactMech = (GenericValue) allPartyContactMechs
1115:                            .next();
1116:                    GenericValue contactMech = null;
1117:
1118:                    try {
1119:                        contactMech = partyContactMech
1120:                                .getRelatedOne("ContactMech");
1121:                    } catch (GenericEntityException e) {
1122:                        Debug.logWarning(e, module);
1123:                    }
1124:                    if (contactMech != null
1125:                            && "POSTAL_ADDRESS".equals(contactMech
1126:                                    .getString("contactMechTypeId"))
1127:                            && !contactMech.getString("contactMechId").equals(
1128:                                    curContactMechId)) {
1129:                        Map postalAddressInfo = new HashMap();
1130:
1131:                        postalAddressInfos.add(postalAddressInfo);
1132:                        postalAddressInfo.put("contactMech", contactMech);
1133:                        postalAddressInfo.put("partyContactMech",
1134:                                partyContactMech);
1135:
1136:                        try {
1137:                            GenericValue postalAddress = contactMech
1138:                                    .getRelatedOne("PostalAddress");
1139:                            postalAddressInfo.put("postalAddress",
1140:                                    postalAddress);
1141:                        } catch (GenericEntityException e) {
1142:                            Debug.logWarning(e, module);
1143:                        }
1144:
1145:                        try {
1146:                            List partyContactMechPurposes = EntityUtil
1147:                                    .filterByDate(
1148:                                            partyContactMech
1149:                                                    .getRelated("PartyContactMechPurpose"),
1150:                                            true);
1151:                            postalAddressInfo.put("partyContactMechPurposes",
1152:                                    partyContactMechPurposes);
1153:                        } catch (GenericEntityException e) {
1154:                            Debug.logWarning(e, module);
1155:                        }
1156:                    }
1157:                }
1158:
1159:                return postalAddressInfos;
1160:            }
1161:
1162:            /** 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 */
1163:            public static void getCurrentPostalAddress(PageContext pageContext,
1164:                    String partyId, String curContactMechId,
1165:                    String curPartyContactMechAttr, String curContactMechAttr,
1166:                    String curPostalAddressAttr,
1167:                    String curPartyContactMechPurposesAttr) {
1168:                ServletRequest request = pageContext.getRequest();
1169:                Map results = getCurrentPostalAddress(request, partyId,
1170:                        curContactMechId);
1171:                if (results.get("curPartyContactMech") != null)
1172:                    pageContext.setAttribute(curPartyContactMechAttr, results
1173:                            .get("curPartyContactMech"));
1174:                if (results.get("curContactMech") != null)
1175:                    pageContext.setAttribute(curContactMechAttr, results
1176:                            .get("curContactMech"));
1177:                if (results.get("curPostalAddress") != null)
1178:                    pageContext.setAttribute(curPostalAddressAttr, results
1179:                            .get("curPostalAddress"));
1180:                if (results.get("curPartyContactMechPurposes") != null)
1181:                    pageContext.setAttribute(curPartyContactMechPurposesAttr,
1182:                            results.get("curPartyContactMechPurposes"));
1183:            }
1184:
1185:            public static Map getCurrentPostalAddress(ServletRequest request,
1186:                    String partyId, String curContactMechId) {
1187:                GenericDelegator delegator = (GenericDelegator) request
1188:                        .getAttribute("delegator");
1189:                Map results = new HashMap();
1190:
1191:                if (curContactMechId != null) {
1192:                    List partyContactMechs = null;
1193:
1194:                    try {
1195:                        partyContactMechs = EntityUtil.filterByDate(delegator
1196:                                .findByAnd("PartyContactMech", UtilMisc.toMap(
1197:                                        "partyId", partyId, "contactMechId",
1198:                                        curContactMechId)), true);
1199:                    } catch (GenericEntityException e) {
1200:                        Debug.logWarning(e, module);
1201:                    }
1202:                    GenericValue curPartyContactMech = EntityUtil
1203:                            .getFirst(partyContactMechs);
1204:                    results.put("curPartyContactMech", curPartyContactMech);
1205:
1206:                    GenericValue curContactMech = null;
1207:                    if (curPartyContactMech != null) {
1208:                        try {
1209:                            curContactMech = curPartyContactMech
1210:                                    .getRelatedOne("ContactMech");
1211:                        } catch (GenericEntityException e) {
1212:                            Debug.logWarning(e, module);
1213:                        }
1214:
1215:                        Collection curPartyContactMechPurposes = null;
1216:                        try {
1217:                            curPartyContactMechPurposes = EntityUtil
1218:                                    .filterByDate(
1219:                                            curPartyContactMech
1220:                                                    .getRelated("PartyContactMechPurpose"),
1221:                                            true);
1222:                        } catch (GenericEntityException e) {
1223:                            Debug.logWarning(e, module);
1224:                        }
1225:                        results.put("curPartyContactMechPurposes",
1226:                                curPartyContactMechPurposes);
1227:                    }
1228:                    results.put("curContactMech", curContactMech);
1229:
1230:                    GenericValue curPostalAddress = null;
1231:                    if (curContactMech != null) {
1232:                        try {
1233:                            curPostalAddress = curContactMech
1234:                                    .getRelatedOne("PostalAddress");
1235:                        } catch (GenericEntityException e) {
1236:                            Debug.logWarning(e, module);
1237:                        }
1238:                    }
1239:
1240:                    results.put("curPostalAddress", curPostalAddress);
1241:                }
1242:                return results;
1243:            }
1244:
1245:            public static boolean isUspsAddress(GenericValue postalAddress) {
1246:                if (postalAddress == null) {
1247:                    // null postal address is not a USPS address
1248:                    return false;
1249:                }
1250:                if (!"PostalAddress".equals(postalAddress.getEntityName())) {
1251:                    // not a postal address not a USPS address
1252:                    return false;
1253:                }
1254:
1255:                // get and clean the address strings
1256:                String addr1 = postalAddress.getString("address1");
1257:                String addr2 = postalAddress.getString("address2");
1258:                if (addr1 != null) {
1259:                    addr1 = addr1.replaceAll("\\W", "").toLowerCase();
1260:                }
1261:                if (addr2 != null) {
1262:                    addr2 = addr2.replaceAll("\\W", "").toLowerCase();
1263:                }
1264:
1265:                // get the matching string from general.properties
1266:                String matcher = UtilProperties.getPropertyValue(
1267:                        "general.properties", "usps.address.match");
1268:                if (matcher != null && matcher.length() > 0) {
1269:                    if (addr1 != null && addr1.matches(".*(" + matcher + ").*")) {
1270:                        return true;
1271:                    }
1272:                    if (addr2 != null && addr2.matches(".*(" + matcher + ").*")) {
1273:                        return true;
1274:                    }
1275:                }
1276:
1277:                return false;
1278:            }
1279:
1280:            public static boolean isCompanyAddress(GenericValue postalAddress,
1281:                    String companyPartyId) {
1282:                if (postalAddress == null) {
1283:                    // null postal address is not an internal address
1284:                    return false;
1285:                }
1286:                if (!"PostalAddress".equals(postalAddress.getEntityName())) {
1287:                    // not a postal address not an internal address
1288:                    return false;
1289:                }
1290:                if (companyPartyId == null) {
1291:                    // no partyId not an internal address
1292:                    return false;
1293:                }
1294:
1295:                String state = postalAddress.getString("stateProvinceGeoId");
1296:                String addr1 = postalAddress.getString("address1");
1297:                String addr2 = postalAddress.getString("address2");
1298:                if (state != null) {
1299:                    state = state.replaceAll("\\W", "").toLowerCase();
1300:                } else {
1301:                    state = "";
1302:                }
1303:                if (addr1 != null) {
1304:                    addr1 = addr1.replaceAll("\\W", "").toLowerCase();
1305:                } else {
1306:                    addr1 = "";
1307:                }
1308:                if (addr2 != null) {
1309:                    addr2 = addr2.replaceAll("\\W", "").toLowerCase();
1310:                } else {
1311:                    addr2 = "";
1312:                }
1313:
1314:                // get all company addresses
1315:                GenericDelegator delegator = postalAddress.getDelegator();
1316:                List postalAddresses = new LinkedList();
1317:                try {
1318:                    List partyContactMechs = delegator.findByAnd(
1319:                            "PartyContactMech", UtilMisc.toMap("partyId",
1320:                                    companyPartyId));
1321:                    partyContactMechs = EntityUtil
1322:                            .filterByDate(partyContactMechs);
1323:                    if (partyContactMechs != null) {
1324:                        Iterator pci = partyContactMechs.iterator();
1325:                        while (pci.hasNext()) {
1326:                            GenericValue pcm = (GenericValue) pci.next();
1327:                            GenericValue addr = pcm
1328:                                    .getRelatedOne("PostalAddress");
1329:                            if (addr != null) {
1330:                                postalAddresses.add(addr);
1331:                            }
1332:                        }
1333:                    }
1334:                } catch (GenericEntityException e) {
1335:                    Debug.logError(e, "Unable to get party postal addresses",
1336:                            module);
1337:                }
1338:
1339:                if (postalAddresses != null) {
1340:                    Iterator pai = postalAddresses.iterator();
1341:                    while (pai.hasNext()) {
1342:                        GenericValue addr = (GenericValue) pai.next();
1343:                        String this Addr1 = addr.getString("address1");
1344:                        String this Addr2 = addr.getString("address2");
1345:                        String this State = addr.getString("stateProvinceGeoId");
1346:                        if (this State != null) {
1347:                            this State = this State.replaceAll("\\W", "")
1348:                                    .toLowerCase();
1349:                        } else {
1350:                            this State = "";
1351:                        }
1352:                        if (this Addr1 != null) {
1353:                            this Addr1 = this Addr1.replaceAll("\\W", "")
1354:                                    .toLowerCase();
1355:                        } else {
1356:                            this Addr1 = "";
1357:                        }
1358:                        if (this Addr2 != null) {
1359:                            this Addr2 = this Addr2.replaceAll("\\W", "")
1360:                                    .toLowerCase();
1361:                        } else {
1362:                            this Addr2 = "";
1363:                        }
1364:                        if (this Addr1.equals(addr1) && this Addr2.equals(addr2)
1365:                                && this State.equals(state)) {
1366:                            return true;
1367:                        }
1368:                    }
1369:                }
1370:
1371:                return false;
1372:            }
1373:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.