Source Code Cross Referenced for LeadEventProcessor.java in  » ERP-CRM-Financial » SourceTap-CRM » com » sourcetap » sfa » lead » 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 » com.sourcetap.sfa.lead 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * Copyright (c) 2004 SourceTap - www.sourcetap.com
004:         *
005:         *  The contents of this file are subject to the SourceTap Public License 
006:         * ("License"); You may not use this file except in compliance with the 
007:         * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008:         * Software distributed under the License is distributed on an  "AS IS"  basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010:         * the specific language governing rights and limitations under the License.
011:         *
012:         * The above copyright notice and this permission notice shall be included
013:         * in all copies or substantial portions of the Software.
014:         *
015:         */
016:
017:        package com.sourcetap.sfa.lead;
018:
019:        import java.sql.Timestamp;
020:        import java.util.Calendar;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.LinkedList;
024:        import java.util.List;
025:        import java.util.Vector;
026:
027:        import org.ofbiz.base.util.Debug;
028:        import org.ofbiz.base.util.UtilMisc;
029:        import org.ofbiz.entity.GenericDelegator;
030:        import org.ofbiz.entity.GenericEntityException;
031:        import org.ofbiz.entity.GenericValue;
032:        import org.ofbiz.entity.condition.EntityConditionList;
033:        import org.ofbiz.entity.condition.EntityExpr;
034:        import org.ofbiz.entity.condition.EntityOperator;
035:        import org.ofbiz.entity.model.ModelEntity;
036:
037:        import com.sourcetap.sfa.address.AddressHelper;
038:        import com.sourcetap.sfa.attachment.AbstractAttachmentEP;
039:        import com.sourcetap.sfa.contact.ContactEventProcessor;
040:        import com.sourcetap.sfa.event.DataMatrix;
041:        import com.sourcetap.sfa.event.GenericEventProcessor;
042:        import com.sourcetap.sfa.replication.GenericReplicator;
043:        import com.sourcetap.sfa.security.SecurityLinkInfo;
044:        import com.sourcetap.sfa.security.SecurityWrapper;
045:        import com.sourcetap.sfa.ui.UIScreenSectionEntity;
046:        import com.sourcetap.sfa.util.QueryInfo;
047:        import com.sourcetap.sfa.util.UserInfo;
048:
049:        /**
050:         * DOCUMENT ME!
051:         *
052:         */
053:        public class LeadEventProcessor extends GenericEventProcessor {
054:            public static final String module = LeadEventProcessor.class
055:                    .getName();
056:
057:            /**
058:             * DOCUMENT ME!
059:             *
060:             * @param userInfo 
061:             * @param delegator 
062:             * @param dataMatrix 
063:             *
064:             * @return 
065:             */
066:            protected int postUpdate(UserInfo userInfo,
067:                    GenericDelegator delegator, DataMatrix dataMatrix) {
068:
069:                try {
070:                    GenericValue originalLeadGV = null;
071:                    GenericValue currentLeadGV = null;
072:                    originalLeadGV = dataMatrix.getOriginalBuffer()
073:                            .getGenericValue(0, "Lead", true);
074:                    currentLeadGV = dataMatrix.getCurrentBuffer()
075:                            .getGenericValue(0, "Lead", true);
076:
077:                    String originalOwner = (originalLeadGV
078:                            .getString("leadOwnerId") == null) ? ""
079:                            : originalLeadGV.getString("leadOwnerId");
080:                    String currentOwner = (currentLeadGV
081:                            .getString("leadOwnerId") == null) ? ""
082:                            : currentLeadGV.getString("leadOwnerId");
083:                    String updatedBy = (currentLeadGV.getString("modifiedBy") == null) ? ""
084:                            : currentLeadGV.getString("modifiedBy");
085:
086:                    if ((!originalOwner.equals(currentOwner))
087:                            && (!currentOwner.equals(updatedBy))) {
088:                        sendNotification(userInfo, delegator, dataMatrix);
089:                    }
090:                } catch (GenericEntityException e) {
091:                    Debug.logWarning("postUpdate:Error getting generic value: "
092:                            + e.getLocalizedMessage(), "postUpdate");
093:
094:                    return STATUS_ERROR;
095:                }
096:
097:                return STATUS_CONTINUE;
098:            }
099:
100:            /**
101:             * DOCUMENT ME!
102:             *
103:             * @param userInfo 
104:             * @param delegator 
105:             * @param dataMatrix 
106:             *
107:             * @return 
108:             */
109:            protected int postInsert(UserInfo userInfo,
110:                    GenericDelegator delegator, DataMatrix dataMatrix) {
111:
112:                GenericValue currentLeadGV = null;
113:
114:                try {
115:                    currentLeadGV = dataMatrix.getCurrentBuffer()
116:                            .getGenericValue(0, "Lead", true);
117:
118:                    String currentOwner = (currentLeadGV
119:                            .getString("leadOwnerId") == null) ? ""
120:                            : currentLeadGV.getString("leadOwnerId");
121:                    String createdBy = (currentLeadGV.getString("modifiedBy") == null) ? ""
122:                            : currentLeadGV.getString("modifiedBy");
123:
124:                    if (!currentOwner.equals(createdBy)) {
125:                        sendNotification(userInfo, delegator, dataMatrix);
126:                    }
127:                } catch (GenericEntityException e) {
128:                    Debug.logWarning("Error getting generic value: "
129:                            + e.getLocalizedMessage(), "postUpdate");
130:
131:                    return STATUS_ERROR;
132:                }
133:
134:                return STATUS_CONTINUE;
135:            }
136:
137:            /**
138:             * DOCUMENT ME!
139:             *
140:             * @param userInfo 
141:             * @param delegator 
142:             * @param dataMatrix 
143:             *
144:             * @return 
145:             */
146:            public int sendNotification(UserInfo userInfo,
147:                    GenericDelegator delegator, DataMatrix dataMatrix) {
148:                // Find out if the owner changed.
149:                GenericValue currentLeadGV = null;
150:                String emailTo = "";
151:                String smsTo = "";
152:
153:                try {
154:                    currentLeadGV = dataMatrix.getCurrentBuffer()
155:                            .getGenericValue(0, "Lead", true);
156:
157:                    String currentOwner = (currentLeadGV
158:                            .getString("leadOwnerId") == null) ? ""
159:                            : currentLeadGV.getString("leadOwnerId");
160:
161:                    // The owner was changed. Get email address of new owner.
162:                    HashMap findMap = new HashMap();
163:                    findMap.put("contactId", currentOwner);
164:
165:                    try {
166:                        GenericValue contactGV = delegator.findByPrimaryKey(
167:                                "Contact", findMap);
168:
169:                        if (contactGV != null) {
170:                            emailTo = (contactGV.getString("email") == null) ? ""
171:                                    : contactGV.getString("email");
172:                            smsTo = (contactGV.getString("mobilePhone") == null) ? ""
173:                                    : contactGV.getString("mobilePhone");
174:
175:                            if (!smsTo.equals("")) {
176:                                smsTo += "@mobile.att.net";
177:                            }
178:                        }
179:                    } catch (Exception e) {
180:                        Debug
181:                                .logWarning(
182:                                        "Error looking for lead owner contact record: "
183:                                                + e.getLocalizedMessage(),
184:                                        "postUpdate");
185:
186:                        return STATUS_ERROR;
187:                    }
188:
189:                    if (!emailTo.equals("") || !smsTo.equals("")) {
190:                        // Send new owner an email and/or sms message.
191:                        String result = LeadHelper.sendLeadNotifyEmail(emailTo,
192:                                smsTo, currentLeadGV);
193:
194:                        if (!result.toLowerCase().equals("success")) {
195:                            Debug.logError("Error sending email: " + result,
196:                                    module);
197:
198:                            return STATUS_ERROR;
199:                        }
200:                    }
201:                } catch (GenericEntityException e) {
202:                    Debug.logError("Error getting generic value: "
203:                            + e.getLocalizedMessage(), module);
204:
205:                    return STATUS_ERROR;
206:                }
207:
208:                return STATUS_CONTINUE;
209:            }
210:
211:            /**
212:             * DOCUMENT ME!
213:             *
214:             * @param userInfo 
215:             * @param delegator 
216:             * @param dataMatrix 
217:             *
218:             * @return 
219:             */
220:            protected int preUpdate(UserInfo userInfo,
221:                    GenericDelegator delegator, DataMatrix dataMatrix) {
222:
223:                // Just process the first row for now.
224:                GenericValue leadGV = null;
225:                GenericValue originalLeadGV = null;
226:                GenericValue addressGV = null;
227:                GenericValue partyGV = null;
228:
229:                try {
230:                    leadGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
231:                            "Lead", true);
232:                    originalLeadGV = dataMatrix.getOriginalBuffer()
233:                            .getGenericValue(0, "Lead", true);
234:                    addressGV = dataMatrix.getCurrentBuffer().getGenericValue(
235:                            0, "Address", false);
236:                    partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
237:                            "Party", false);
238:                } catch (GenericEntityException e) {
239:                    Debug.logError("Error getting generic value: "
240:                            + e.toString(), module);
241:
242:                    return STATUS_ERROR;
243:                }
244:
245:                // Copy the lead ID to the address owner ID in case it is not already filled in.
246:                String leadId = leadGV.getString("leadId");
247:
248:                Timestamp now = new Timestamp(Calendar.getInstance().getTime()
249:                        .getTime());
250:
251:                // call the Name processor to split full name into first, last, etc or to combine first/last to full name
252:                ContactEventProcessor.setNameFields(leadGV);
253:
254:                // Update the address if it is new.
255:                String addressId = addressGV.getString("addressId");
256:
257:                if ((addressId == null) || addressId.equals("")) {
258:                    addressId = GenericReplicator.getNextSeqId("Address",
259:                            delegator);
260:                    addressGV.set("addressId", addressId);
261:                    addressGV.set("addressOwnerType", "Lead");
262:                    addressGV.set("isPrimary", "Y");
263:                    addressGV.set("createdDate", now);
264:                    addressGV.set("createdBy", userInfo.getPartyId());
265:
266:                    String mailingAddress = AddressHelper.getMailingAddress(
267:                            addressGV.getString("mailingAddress"), addressGV
268:                                    .getString("address1"), addressGV
269:                                    .getString("address2"), addressGV
270:                                    .getString("address3"));
271:                    addressGV.set("mailingAddress", mailingAddress);
272:                }
273:
274:                addressGV.set("addressOwnerId", leadId);
275:
276:                // Set the time stamps.
277:                leadGV.set("modifiedDate", now);
278:                addressGV.set("modifiedDate", now);
279:
280:                // Store the current user ID in the "modified by" field.
281:                leadGV.set("modifiedBy", userInfo.getPartyId());
282:                addressGV.set("modifiedBy", userInfo.getPartyId());
283:
284:                // Set the lead owner ID if it is empty.
285:                String leadOwnerId = leadGV.getString("leadOwnerId");
286:
287:                Debug.logVerbose("leadOwnerId: " + leadOwnerId, module);
288:
289:                if ((leadOwnerId == null) || leadOwnerId.equals("")) {
290:                    Debug.logVerbose("Setting leadOwnerId to "
291:                            + userInfo.getPartyId(), module);
292:
293:                    leadGV.set("leadOwnerId", userInfo.getPartyId());
294:                }
295:
296:                // Set the account ID if it is empty.
297:                String accountId = leadGV.getString("accountId");
298:
299:                Debug.logVerbose("accountId: " + accountId, module);
300:
301:                if ((accountId == null) || accountId.equals("")) {
302:                    Debug.logVerbose("Setting accountId to "
303:                            + userInfo.getAccountId(), module);
304:
305:                    leadGV.set("accountId", userInfo.getAccountId());
306:                }
307:
308:                String ownerId = leadGV.getString("leadOwnerId");
309:                String originalOwnerId = originalLeadGV
310:                        .getString("leadOwnerId");
311:
312:                if (!ownerId.equals(originalOwnerId)) {
313:                    //add the team access info
314:                    SecurityWrapper.updateRoleInformation(dataMatrix, 0,
315:                            userInfo, ownerId, "Lead", leadId, delegator);
316:
317:                    // Set the assigned date.
318:                    leadGV.set("assignedDate", now);
319:                }
320:
321:                String statusId = leadGV.getString("statusId");
322:                String originalStatusId = originalLeadGV.getString("statusId");
323:
324:                if (!statusId.equals(originalStatusId) && statusId.equals("50")) {
325:                    // Status changed to "converted". Set the converted date.
326:                    leadGV.set("convertedDate", now);
327:                }
328:
329:                return STATUS_CONTINUE;
330:            }
331:
332:            /**
333:             * DOCUMENT ME!
334:             *
335:             * @param userInfo 
336:             * @param delegator 
337:             * @param dataMatrix 
338:             *
339:             * @return 
340:             */
341:            protected int preInsert(UserInfo userInfo,
342:                    GenericDelegator delegator, DataMatrix dataMatrix) {
343:
344:                // Just process the first row for now.
345:                GenericValue leadGV = null;
346:                GenericValue addressGV = null;
347:                GenericValue partyGV = null;
348:
349:                try {
350:                    leadGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
351:                            "Lead", true);
352:                    addressGV = dataMatrix.getCurrentBuffer().getGenericValue(
353:                            0, "Address", true);
354:                    partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
355:                            "Party", true);
356:                } catch (GenericEntityException e) {
357:                    Debug.logError("Error getting generic value: "
358:                            + e.getLocalizedMessage(), module);
359:
360:                    return STATUS_ERROR;
361:                }
362:
363:                // Generate new keys for the lead and address.
364:                String leadId = GenericReplicator.getNextSeqId("Party",
365:                        delegator);
366:                String addressId = GenericReplicator.getNextSeqId("Address",
367:                        delegator);
368:                leadGV.set("leadId", leadId);
369:                addressGV.set("addressId", addressId);
370:                addressGV.set("addressOwnerId", leadId);
371:                addressGV.set("addressOwnerType", "Lead");
372:                partyGV.set("partyId", leadId);
373:
374:                // Make this address the primary one for the lead.
375:                addressGV.set("isPrimary", "Y");
376:
377:                String mailingAddress = AddressHelper.getMailingAddress(
378:                        addressGV.getString("mailingAddress"), addressGV
379:                                .getString("address1"), addressGV
380:                                .getString("address2"), addressGV
381:                                .getString("address3"));
382:                addressGV.set("mailingAddress", mailingAddress);
383:
384:                // call the Name processor to split full name into first, last, etc or to combine first/last to full name
385:                ContactEventProcessor.setNameFields(leadGV);
386:
387:                // Set the time stamps.
388:                Timestamp now = new Timestamp(Calendar.getInstance().getTime()
389:                        .getTime());
390:                leadGV.set("createdDate", now);
391:                addressGV.set("createdDate", now);
392:                leadGV.set("modifiedDate", now);
393:                addressGV.set("modifiedDate", now);
394:
395:                // Store the current user ID in the "modified by" field.
396:                leadGV.set("createdBy", userInfo.getPartyId());
397:                addressGV.set("createdBy", userInfo.getPartyId());
398:                leadGV.set("modifiedBy", userInfo.getPartyId());
399:                addressGV.set("modifiedBy", userInfo.getPartyId());
400:
401:                LeadHelper leadHelper = LeadHelper.getInstance(delegator);
402:
403:                //get the Vector of Generic Values for the new row
404:                Vector dataVector = dataMatrix.getCurrentBuffer()
405:                        .getContentsRow(0);
406:
407:                String assignId = leadHelper.getLeadAssignment(dataVector,
408:                        userInfo);
409:
410:                if ((assignId != null) && (assignId.length() > 0)) {
411:                    leadGV.set("leadOwnerId", assignId);
412:                }
413:
414:                // Set the lead owner ID if it is empty.
415:                String leadOwnerId = leadGV.getString("leadOwnerId");
416:
417:                Debug.logVerbose("leadOwnerId: " + leadOwnerId, module);
418:
419:                if ((leadOwnerId == null) || leadOwnerId.equals("")) {
420:                    Debug.logVerbose("Setting leadOwnerId to "
421:                            + userInfo.getPartyId(), module);
422:
423:                    leadGV.set("leadOwnerId", userInfo.getPartyId());
424:                }
425:
426:                // Set the assigned date.
427:                leadGV.set("assignedDate", now);
428:
429:                // Set the account ID if it is empty.
430:                String accountId = leadGV.getString("accountId");
431:
432:                if ((accountId == null) || accountId.equals("")) {
433:                    leadGV.set("accountId", userInfo.getAccountId());
434:                }
435:
436:                String ownerId = leadGV.getString("leadOwnerId");
437:
438:                //add the team access info
439:                SecurityWrapper.addRoleInformation(dataMatrix, 0, userInfo,
440:                        ownerId, "Lead", leadId, delegator);
441:
442:                String statusId = leadGV.getString("statusId");
443:
444:                if (statusId == null) {
445:                    statusId = "10";
446:                    leadGV.set("statusId", statusId);
447:                }
448:
449:                if (leadGV.get("activeFlag") == null) {
450:                    leadGV.set("activeFlag", new Boolean(true));
451:                }
452:
453:                if (leadGV.get("validatedFlag") == null) {
454:                    leadGV.set("validatedFlag", new Boolean(true));
455:                }
456:
457:                if (addressGV.get("country") == null) {
458:                    addressGV.set("country", "USA");
459:                }
460:
461:                if (statusId.equals("50")) {
462:                    // Status is "converted". Set the converted date.
463:                    leadGV.set("convertedDate", now);
464:                }
465:
466:                return STATUS_CONTINUE;
467:            }
468:
469:            /**
470:             * DOCUMENT ME!
471:             *
472:             * @param userInfo 
473:             * @param entityNameList 
474:             * @param delegator 
475:             * @param dataMatrix 
476:             *
477:             * @return 
478:             */
479:            protected int postCreate(UserInfo userInfo, List entityNameList,
480:                    GenericDelegator delegator, DataMatrix dataMatrix) {
481:
482:                // Get the empty generic values.
483:                GenericValue leadGV = null;
484:                GenericValue addressGV = null;
485:                GenericValue partyGV = null;
486:
487:                try {
488:                    leadGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
489:                            "Lead", true);
490:                    addressGV = dataMatrix.getCurrentBuffer().getGenericValue(
491:                            0, "Address", false);
492:                    partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
493:                            "Party", false);
494:                } catch (GenericEntityException e) {
495:                    Debug.logError("Error getting generic value: "
496:                            + e.toString(), module);
497:
498:                    return STATUS_ERROR;
499:                }
500:
501:                // Set default values on the new record so they will be displayed for the user to see before saving.
502:                // Lead owner ID
503:                Debug.logVerbose("Setting leadOwnerId to "
504:                        + userInfo.getPartyId(), module);
505:
506:                leadGV.set("leadOwnerId", userInfo.getPartyId());
507:
508:                leadGV.set("statusId", "10");
509:
510:                // Active Flag
511:                leadGV.set("activeFlag", new Boolean(true));
512:
513:                leadGV.set("validatedFlag", new Boolean(true));
514:
515:                // Country
516:                addressGV.set("country", "USA");
517:
518:                // Refresh the cache in the delegator so that dropdowns will show the new lead
519:                delegator.getAndCache().clear();
520:
521:                return STATUS_CONTINUE;
522:            }
523:
524:            /** event handler for quick insert screen */
525:            public boolean QuickInsert(UserInfo userInfo,
526:                    GenericDelegator delegator, String firstName,
527:                    String lastName, String title, String companyName,
528:                    String businessPhone, String mailingAddress, String city,
529:                    String state, String zip, String country, String statusId,
530:                    String leadTypeId, String activeFlag, String validatedFlag) {
531:                GenericValue leadGV = new GenericValue(delegator
532:                        .getModelEntity("Lead"));
533:                leadGV.setDelegator(delegator);
534:
535:                GenericValue addressGV = new GenericValue(delegator
536:                        .getModelEntity("Address"));
537:                addressGV.setDelegator(delegator);
538:
539:                GenericValue partyGV = new GenericValue(delegator
540:                        .getModelEntity("Party"));
541:                partyGV.setDelegator(delegator);
542:
543:                leadGV.set("firstName", firstName);
544:                leadGV.set("lastName", lastName);
545:                leadGV.set("title", title);
546:                leadGV.set("companyName", companyName);
547:                leadGV.set("businessPhone", businessPhone);
548:                addressGV.set("mailingAddress", mailingAddress);
549:                addressGV.set("isPrimary", "Y");
550:                addressGV.set("city", city);
551:                addressGV.set("state", state);
552:                addressGV.set("zip", zip);
553:                addressGV.set("country", country);
554:                leadGV.set("statusId", statusId);
555:                leadGV.set("leadTypeId", leadTypeId);
556:                leadGV
557:                        .set(
558:                                "activeFlag",
559:                                activeFlag.toUpperCase().equals("Y") ? new Boolean(
560:                                        true)
561:                                        : new Boolean(false));
562:                leadGV.set("validatedFlag", validatedFlag.toUpperCase().equals(
563:                        "Y") ? new Boolean(true) : new Boolean(false));
564:
565:                // call the Name processor to split full name into first, last, etc or to combine first/last to full name
566:                ContactEventProcessor.setNameFields(leadGV);
567:
568:                DataMatrix dataMatrix = new DataMatrix(delegator, new Vector());
569:                dataMatrix.getCurrentBuffer().addContentsRow(new Vector());
570:
571:                dataMatrix.addEntity("Lead", false, true);
572:                dataMatrix.getCurrentBuffer().getContentsRow(0).add(leadGV);
573:
574:                dataMatrix.addEntity("Address", false, true);
575:                dataMatrix.getCurrentBuffer().getContentsRow(0).add(addressGV);
576:
577:                dataMatrix.addEntity("Party", false, true);
578:                dataMatrix.getCurrentBuffer().getContentsRow(0).add(partyGV);
579:
580:                if (preInsert(userInfo, delegator, dataMatrix) != STATUS_CONTINUE) {
581:                    return false;
582:                }
583:
584:                try {
585:                    delegator.storeAll((List) dataMatrix.getCurrentBuffer()
586:                            .getContentsRow(0));
587:                } catch (GenericEntityException e2) {
588:                    Debug.logError("Error saving new lead: "
589:                            + e2.getLocalizedMessage(), module);
590:
591:                    return false;
592:                }
593:
594:                if (postInsert(userInfo, delegator, dataMatrix) != STATUS_CONTINUE) {
595:                    return false;
596:                }
597:
598:                return true;
599:            }
600:
601:            /**
602:             * DOCUMENT ME!
603:             *
604:             * @param userInfo 
605:             * @param delegator 
606:             * @param originatingEntityName 
607:             * @param entityGV 
608:             *
609:             * @return 
610:             */
611:            public int deleteAllRelated(UserInfo userInfo,
612:                    GenericDelegator delegator, String originatingEntityName,
613:                    GenericValue entityGV) {
614:
615:                int status = STATUS_CONTINUE;
616:
617:                // Delete related Addresses.
618:                status = deleteOneRelated(userInfo, delegator, entityGV, "",
619:                        "Address", originatingEntityName,
620:                        new GenericEventProcessor());
621:
622:                if (status != STATUS_CONTINUE) {
623:                    return status;
624:                }
625:
626:                // Delete related Parties.
627:                status = deleteOneRelated(userInfo, delegator, entityGV, "",
628:                        "Party", originatingEntityName,
629:                        new GenericEventProcessor());
630:
631:                if (status != STATUS_CONTINUE) {
632:                    return status;
633:                }
634:
635:                // Delete related FileAttachments.  (Note: This must happen before the LeadFiles are deleted.)
636:                status = deleteOneRelated(userInfo, delegator, entityGV, "",
637:                        "FileAttachment", originatingEntityName,
638:                        new AbstractAttachmentEP());
639:
640:                if (status != STATUS_CONTINUE) {
641:                    return status;
642:                }
643:
644:                // Delete related LeadFiles.  (Note: This must happen after the FileAttachments are deleted.)
645:                status = deleteOneRelated(userInfo, delegator, entityGV, "",
646:                        "LeadFile", originatingEntityName,
647:                        new GenericEventProcessor());
648:
649:                if (status != STATUS_CONTINUE) {
650:                    return status;
651:                }
652:
653:                return STATUS_CONTINUE;
654:            }
655:
656:            /**
657:             * DOCUMENT ME!
658:             *
659:             * @param userInfo 
660:             * @param delegator 
661:             * @param entityGV 
662:             * @param relationTitle 
663:             * @param relatedEntityName 
664:             *
665:             * @return 
666:             */
667:            public List findOneRelated(UserInfo userInfo,
668:                    GenericDelegator delegator, GenericValue entityGV,
669:                    String relationTitle, String relatedEntityName) {
670:                // Find instances of an entity related to the current entity so the instances can be deleted.
671:
672:                if (relatedEntityName.equals("FileAttachment")) {
673:                    // Finding related FileAttachment records. Need special processing because the relationship cannot be
674:                    // defined in the sfa-config.xml file.
675:                    // Get all the related LeadFile records using the generic version of findOneRelated.
676:                    List leadFileGVL = super .findOneRelated(userInfo,
677:                            delegator, entityGV, "", "LeadFile");
678:
679:                    // Make a List of FileAttachments tied to the identified LeadFiles.
680:                    List fileAttachmenGVL = new LinkedList();
681:                    Iterator leadFileGVI = leadFileGVL.iterator();
682:
683:                    while (leadFileGVI.hasNext()) {
684:                        GenericValue leadFileGV = (GenericValue) leadFileGVI
685:                                .next();
686:
687:                        try {
688:                            GenericValue fileAttachmentGV = delegator
689:                                    .getRelatedOne("FileAttachment", leadFileGV);
690:
691:                            if (fileAttachmentGV != null) {
692:                                fileAttachmenGVL.add(fileAttachmentGV);
693:                            }
694:                        } catch (GenericEntityException e) {
695:                            Debug.logError(
696:                                    "Error retrieving FileAttachment record: "
697:                                            + e.getLocalizedMessage(), module);
698:                        }
699:                    }
700:
701:                    Debug.logVerbose("End - FileAttachment", module);
702:
703:                    return fileAttachmenGVL;
704:                } else {
705:                    // Not finding EntityAccess or FileAttachment records.  Just use the standard processing using relations.
706:                    return super .findOneRelated(userInfo, delegator, entityGV,
707:                            relationTitle, relatedEntityName);
708:                }
709:            }
710:
711:            /**
712:             * DOCUMENT ME!
713:             *
714:             * @param mainGV 
715:             * @param relatedSearchClause 
716:             * @param outGVV 
717:             * @param userInfo 
718:             * @param delegator 
719:             *
720:             * @return 
721:             */
722:            protected GenericValue retrieveOneRelatedGV(GenericValue mainGV,
723:                    UIScreenSectionEntity relatedSearchClause, Vector outGVV,
724:                    UserInfo userInfo, GenericDelegator delegator) {
725:
726:                String relationRelEntityName = (String) relatedSearchClause
727:                        .getEntityName();
728:
729:                if (relationRelEntityName.equals("Address")) {
730:                    // Special processing for the Address record since it can't be retrieved with a relationship
731:                    // defined in the sfa-config.xml file.
732:
733:                    // Get lead ID from the Lead record.
734:                    String leadId = mainGV.getString("leadId");
735:
736:                    HashMap addressFindMap = new HashMap();
737:                    addressFindMap.put("addressOwnerId", leadId);
738:                    addressFindMap.put("isPrimary", "Y");
739:
740:                    GenericValue addressGV = null;
741:
742:                    try {
743:                        List addressGVL = delegator.findByAnd("Address",
744:                                addressFindMap);
745:                        Iterator addressGVI = addressGVL.iterator();
746:
747:                        if (addressGVI.hasNext()) {
748:                            // Address record was found.
749:                            addressGV = (GenericValue) addressGVI.next();
750:
751:                            Debug.logVerbose("Address was found:"
752:                                    + addressGV.toString(), module);
753:                        } else {
754:                            // Address record was not found.  Allow generic event processor to create an empty one.
755:                            Debug.logVerbose("Address was not found.", module);
756:                        }
757:
758:                        return addressGV;
759:                    } catch (GenericEntityException e) {
760:                        Debug.logError("An error occurred while searching for "
761:                                + "the address record for the Lead: "
762:                                + e.getLocalizedMessage(), module);
763:
764:                        return addressGV;
765:                    }
766:                } else {
767:                    // Retrieve all other related entities the regular way.
768:
769:                    return super .retrieveOneRelatedGV(mainGV,
770:                            relatedSearchClause, outGVV, userInfo, delegator);
771:                }
772:            }
773:
774:            /**
775:             * Add entity clauses for one related entity.  This will join related tables to the query
776:             * during a retrieve so query values can be entered that are in related entities.
777:             * <P>
778:             * This version overrides the ancestor to handle the Account entity, which
779:             * has no relation defined.
780:             *
781:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
782:             *
783:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
784:             * @param relationTitle Relation title
785:             * @param relatedEntityName Name of related entity
786:             * @param primaryEntityName Name of the primary entity
787:             * @param primaryME ModelEntity object for the primary entity
788:             * @param queryInfo  criteria to be used in search
789:             */
790:            public void addOneRelationClause(GenericDelegator delegator,
791:                    String relationTitle, String relatedAndFields,
792:                    String relatedEntityName, String primaryEntityName,
793:                    ModelEntity primaryME, boolean isOuterJoin,
794:                    QueryInfo queryInfo) throws GenericEntityException {
795:                if (relatedEntityName.equals("Address")) {
796:                    // Adding entity clauses for the Address entity.  Need to build it manually.
797:                    // Join the address owner ID field
798:                    Debug.logVerbose(
799:                            "[addOneRelationClause] Added to entityClauses: "
800:                                    + "Lead" + ", " + "Address" + ", "
801:                                    + "leadId" + ", " + "addressOwnerId",
802:                            module);
803:
804:                    queryInfo.addJoin("Lead", "Address", Boolean
805:                            .valueOf(isOuterJoin), "leadId", "addressOwnerId");
806:
807:                    if (isOuterJoin) {
808:                        queryInfo.addAlias("Address", "isPrimary", "isPrimary");
809:                        queryInfo.addAlias("Address", "addressId", "addressId");
810:                        queryInfo.addCondition(new EntityConditionList(UtilMisc
811:                                .toList(new EntityExpr("isPrimary",
812:                                        EntityOperator.EQUALS, "Y"),
813:                                        new EntityExpr("addressId",
814:                                                EntityOperator.EQUALS, null)),
815:                                EntityOperator.OR));
816:                    } else
817:                        queryInfo.addCondition("Address", "isPrimary",
818:                                EntityOperator.EQUALS, "Y");
819:                } else {
820:                    // Use the parent script for all other related entities.
821:                    super .addOneRelationClause(delegator, relationTitle,
822:                            relatedAndFields, relatedEntityName,
823:                            primaryEntityName, primaryME, isOuterJoin,
824:                            queryInfo);
825:                }
826:            }
827:
828:            /**
829:             * DOCUMENT ME!
830:             *
831:             * @param userInfo 
832:             * @param delegator 
833:             *
834:             * @return 
835:             */
836:            public SecurityLinkInfo getSecurityLinkInfo(UserInfo userInfo,
837:                    GenericDelegator delegator) {
838:                return new SecurityLinkInfo("Lead", "leadId", false);
839:            }
840:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.