Source Code Cross Referenced for ContactMechWorker.java in  » ERP-CRM-Financial » ofbiz » 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 » ofbiz » org.ofbiz.party.contact 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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