Source Code Cross Referenced for EventUtility.java in  » ERP-CRM-Financial » SourceTap-CRM » com » sourcetap » sfa » event » 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.event 
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.event;
018:
019:        import java.sql.Date;
020:        import java.sql.Timestamp;
021:        import java.text.DecimalFormat;
022:        import java.text.ParseException;
023:        import java.text.SimpleDateFormat;
024:        import java.util.ArrayList;
025:        import java.util.Calendar;
026:        import java.util.Collection;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.Map;
031:        import java.util.StringTokenizer;
032:
033:        import org.ofbiz.base.util.Debug;
034:        import org.ofbiz.base.util.UtilTimer;
035:        import org.ofbiz.entity.GenericDelegator;
036:        import org.ofbiz.entity.GenericEntityException;
037:        import org.ofbiz.entity.GenericPK;
038:        import org.ofbiz.entity.GenericValue;
039:        import org.ofbiz.entity.condition.EntityComparisonOperator;
040:        import org.ofbiz.entity.condition.EntityOperator;
041:        import org.ofbiz.entity.model.ModelEntity;
042:        import org.ofbiz.entity.model.ModelField;
043:        import org.ofbiz.entity.model.ModelFieldType;
044:        import org.ofbiz.entity.model.ModelFieldTypeReader;
045:        import org.ofbiz.entity.model.ModelKeyMap;
046:        import org.ofbiz.entity.model.ModelReader;
047:        import org.ofbiz.entity.model.ModelRelation;
048:
049:        import com.sourcetap.sfa.ui.UIScreenSection;
050:        import com.sourcetap.sfa.util.QueryInfo;
051:
052:        /**
053:         * DOCUMENT ME!
054:         *
055:         */
056:        public class EventUtility {
057:            public static final int STATUS_ERROR = -1;
058:            public static final int STATUS_CANCEL = 0;
059:            public static final int STATUS_CONTINUE = 1;
060:            private static final boolean TIMER = false;
061:            public static final String module = EventUtility.class.getName();
062:
063:            public EventUtility() {
064:            }
065:
066:            /**
067:             * DOCUMENT ME!
068:             *
069:             * @param gV 
070:             * @param fieldName 
071:             * @param delegator 
072:             *
073:             * @return 
074:             */
075:            public static String getDataType(GenericValue gV, String fieldName,
076:                    GenericDelegator delegator) {
077:                UtilTimer timer = new UtilTimer();
078:
079:                if (TIMER) {
080:                    timer.timerString("[EventUtility.getDataType] Start");
081:                }
082:
083:                ModelEntity modelEntity = delegator.getModelEntity(gV
084:                        .getEntityName());
085:                ModelField curField = modelEntity.getField(fieldName);
086:
087:                ModelFieldTypeReader modelFieldTypeReader = new ModelFieldTypeReader(
088:                        "mysql");
089:                ModelFieldType mft = modelFieldTypeReader
090:                        .getModelFieldType(curField.getType());
091:                String fieldType = mft.getJavaType();
092:
093:                if (TIMER) {
094:                    timer.timerString("[EventUtility.getDataType] End");
095:                }
096:
097:                return fieldType;
098:            }
099:
100:            /**
101:             * DOCUMENT ME!
102:             *
103:             * @param gV 
104:             * @param fieldName 
105:             * @param value 
106:             * @param delegator 
107:             */
108:            public static void storeValue(GenericValue gV, String fieldName,
109:                    String value, GenericDelegator delegator) {
110:                String fieldType = getDataType(gV, fieldName, delegator);
111:                storeValue(gV, fieldName, value, delegator, fieldType);
112:
113:                return;
114:            }
115:
116:            /**
117:             * DOCUMENT ME!
118:             *
119:             * @param gV 
120:             * @param fieldName 
121:             * @param value 
122:             * @param delegator 
123:             * @param fieldType 
124:             */
125:            public static void storeValue(GenericValue gV, String fieldName,
126:                    String value, GenericDelegator delegator, String fieldType) {
127:                UtilTimer timer = new UtilTimer();
128:
129:                if (TIMER) {
130:                    timer.timerString("[EventUtility.storeValue] Start");
131:                }
132:
133:                if (fieldType.equals("java.lang.String")
134:                        || fieldType.equals("String")) {
135:                    gV.set(fieldName, value);
136:                } else if (fieldType.equals("java.sql.Timestamp")
137:                        || fieldType.equals("Timestamp")) {
138:                    if ((value == null) || (value.trim().length() == 0)) {
139:                        gV.set(fieldName, null);
140:                    } else {
141:                        String[] parseMask = { "y-M-d", "M/d/y", "M-d-y",
142:                                "M d, y", "H:m:s.S", "y-M-d H:m:s.S",
143:                                "M/d/y H:m:s.S", "M-d-y H:m:s.S",
144:                                "M d, y H:m:s.S", "h:m:s a", "y-M-d h:m:s a",
145:                                "M/d/y h:m:s a", "M-d-y h:m:s a",
146:                                "M d, y h:m:s a", "H:m:s", "y-M-d H:m:s",
147:                                "M/d/y H:m:s", "M-d-y H:m:s", "M d, y H:m:s",
148:                                "h:m a", "y-M-d h:m a", "M/d/y h:m a",
149:                                "M-d-y h:m a", "M d, y h:m a", "H:m",
150:                                "y-M-d H:m", "M/d/y H:m", "M-d-y H:m",
151:                                "M d, y H:m" };
152:                        java.util.Date parsedDate = null;
153:                        boolean isParsed = false;
154:                        String currentMask = "";
155:
156:                        for (int maskNbr = 0; maskNbr < parseMask.length; maskNbr++) {
157:                            currentMask = parseMask[maskNbr];
158:
159:                            SimpleDateFormat dateFormat = new SimpleDateFormat(
160:                                    currentMask);
161:
162:                            try {
163:                                parsedDate = dateFormat.parse(value);
164:                                isParsed = true;
165:
166:                                break;
167:                            } catch (ParseException e) {
168:                                // Try the next mask.
169:                            }
170:                        }
171:
172:                        if (isParsed) {
173:
174:                            Timestamp parsedTimestamp = new Timestamp(
175:                                    parsedDate.getTime());
176:
177:                            gV.set(fieldName, parsedTimestamp);
178:                        } else {
179:                            Debug.logWarning(
180:                                    "[EventUtility.storeValue()]: Could not parse a Date or Datetime from "
181:                                            + value, module);
182:                        }
183:                    }
184:                } else if (fieldType.equals("java.sql.Time")
185:                        || fieldType.equals("Time")) {
186:                    if ((value == null) || (value.trim().length() == 0)) {
187:                        gV.set(fieldName, null);
188:                    } else {
189:                        String[] parseMask = { "H:m:s.S", "H:m:s", "H:m",
190:                                "h:m a", "h:m:s a" };
191:                        java.util.Date parsedDate = null;
192:                        boolean isParsed = false;
193:                        String currentMask = "";
194:
195:                        for (int maskNbr = 0; maskNbr < parseMask.length; maskNbr++) {
196:                            currentMask = parseMask[maskNbr];
197:
198:                            SimpleDateFormat dateFormat = new SimpleDateFormat(
199:                                    currentMask);
200:
201:                            try {
202:                                parsedDate = dateFormat.parse(value);
203:                                isParsed = true;
204:
205:                                break;
206:                            } catch (ParseException e) {
207:                                // Try the next mask.
208:                            }
209:                        }
210:
211:                        if (isParsed) {
212:
213:                            //					gV.set(fieldName, new java.sql.Time(parsedDate.getTime()));
214:                            gV.set(fieldName, new java.sql.Timestamp(parsedDate
215:                                    .getTime()));
216:                        } else {
217:                            Debug.logWarning(
218:                                    "[EventUtility.storeValue()]: Could not parse a time from "
219:                                            + value, module);
220:                        }
221:                    }
222:                } else if (fieldType.equals("java.util.Date")
223:                        || fieldType.equals("java.sql.Date")
224:                        || fieldType.equals("Date")) {
225:                    if ((value == null) || (value.trim().length() == 0)) {
226:                        gV.set(fieldName, null);
227:                    } else {
228:                        String[] parseMask = { "y-M-d", "M/d/y", "M-d-y",
229:                                "M d, y" };
230:                        java.util.Date parsedDate = null;
231:                        boolean isParsed = false;
232:                        String currentMask = "";
233:
234:                        for (int maskNbr = 0; maskNbr < parseMask.length; maskNbr++) {
235:                            currentMask = parseMask[maskNbr];
236:
237:                            SimpleDateFormat dateFormat = new SimpleDateFormat(
238:                                    currentMask);
239:
240:                            try {
241:                                parsedDate = dateFormat.parse(value);
242:                                isParsed = true;
243:
244:                                break;
245:                            } catch (ParseException e) {
246:                                // Try the next mask.
247:                            }
248:                        }
249:
250:                        if (isParsed) {
251:
252:                            gV.set(fieldName, new java.sql.Date(parsedDate
253:                                    .getTime()));
254:                        } else {
255:                            Debug.logWarning(
256:                                    "[EventUtility.storeValue()]: Could not parse a date from "
257:                                            + value, module);
258:                        }
259:                    }
260:                } else if (fieldType.equals("java.lang.Integer")
261:                        || fieldType.equals("Integer")
262:                        || fieldType.equals("java.lang.Long")
263:                        || fieldType.equals("Long")
264:                        || fieldType.equals("java.lang.Float")
265:                        || fieldType.equals("Float")
266:                        || fieldType.equals("java.lang.Double")
267:                        || fieldType.equals("Double")) {
268:                    if ((value == null) || (value.trim().length() == 0)) {
269:                        value = "0";
270:                    }
271:
272:                    //			gV.set(fieldName, String.valueOf(parseNumber(value)));
273:                    gV.set(fieldName, parseNumber(value));
274:                }
275:
276:                if (TIMER) {
277:                    timer.timerString("[EventUtility.storeValue] End.");
278:                }
279:
280:                return;
281:            }
282:
283:            //-------------------------------------------------------------------------
284:            // Put values from the screen into the Generic Value Vector List
285:            //-------------------------------------------------------------------------
286:            public static Number parseNumber(String value) {
287:                DecimalFormat decimalFormat = new DecimalFormat();
288:                StringBuffer valueBuffer = new StringBuffer(value);
289:
290:                for (int i = 0; i < valueBuffer.length(); i++) {
291:                    if (valueBuffer.toString().charAt(i) == '$') {
292:                        valueBuffer.deleteCharAt(i--);
293:                    }
294:                }
295:
296:                try {
297:                    Number n = decimalFormat.parse(valueBuffer.toString());
298:
299:                    return n;
300:                } catch (ParseException e) {
301:                    Debug.logWarning(
302:                            "[EventUtility.parseNumber()]: Could not parse a number from "
303:                                    + valueBuffer.toString(), module);
304:
305:                    return null;
306:                }
307:            }
308:
309:            /**
310:             * DOCUMENT ME!
311:             *
312:             * @param delegator 
313:             * @param uiScreenSection 
314:             * @param nameToSearchParam 
315:             *
316:             * @return 
317:             *
318:             * @throws GenericEntityException 
319:             */
320:            public static HashMap getAlphaSearchValues(
321:                    GenericDelegator delegator,
322:                    UIScreenSection uiScreenSection, String nameToSearchParam)
323:                    throws GenericEntityException {
324:                HashMap returnValues = new HashMap();
325:
326:                try {
327:                    // Alpha search.  Use the alpha search attribute specified in the screen section.
328:                    String searchAttributeId = uiScreenSection
329:                            .getSearchAttributeId();
330:                    ModelEntity uiAttributeEntity = delegator
331:                            .getModelEntity("UiAttribute");
332:                    HashMap uiAttributeFindMap = new HashMap();
333:                    uiAttributeFindMap.put("attributeId", searchAttributeId);
334:
335:                    GenericPK uiAttributePk = new GenericPK(uiAttributeEntity,
336:                            uiAttributeFindMap);
337:                    GenericValue uiAttributeGenericValue = delegator
338:                            .findByPrimaryKeyCache(uiAttributePk);
339:
340:                    if (uiAttributeGenericValue == null) {
341:                        throw new GenericEntityException(
342:                                "No Ui Attribute was found for ui_attribute.attribute_id="
343:                                        + searchAttributeId);
344:                    }
345:
346:                    String searchAttribName = uiAttributeGenericValue
347:                            .getString("attributeName");
348:                    String searchEntityId = uiAttributeGenericValue
349:                            .getString("entityId");
350:
351:                    ModelEntity uiEntityEntity = delegator
352:                            .getModelEntity("UiEntity");
353:                    HashMap uiEntityFindMap = new HashMap();
354:                    uiEntityFindMap.put("entityId", searchEntityId);
355:
356:                    GenericPK uiEntityPk = new GenericPK(uiEntityEntity,
357:                            uiEntityFindMap);
358:                    GenericValue uiEntityGenericValue = delegator
359:                            .findByPrimaryKeyCache(uiEntityPk);
360:                    String searchEntityName = uiEntityGenericValue
361:                            .getString("entityName");
362:
363:                    String searchAttribValue = nameToSearchParam.replace('*',
364:                            '%')
365:                            + "%";
366:
367:                    returnValues.put("searchEntityName", searchEntityName);
368:                    returnValues.put("searchAttribName", searchAttribName);
369:                    returnValues.put("searchAttribValue", searchAttribValue);
370:                } catch (Exception e) {
371:                    Debug.logError(e.getLocalizedMessage(), module);
372:                    e.printStackTrace();
373:                }
374:
375:                return returnValues;
376:            }
377:
378:            /**
379:             * DOCUMENT ME!
380:             *
381:             * @param queryValue 
382:             *
383:             * @return 
384:             */
385:            public static EntityComparisonOperator getEntityOperator(
386:                    StringBuffer queryValue) {
387:                EntityComparisonOperator operator = null;
388:                String queryValueString = queryValue.toString();
389:                long queryDateOffset = 0;
390:
391:                if (queryValueString.indexOf(">=") >= 0) {
392:                    operator = EntityOperator.GREATER_THAN_EQUAL_TO;
393:                } else if (queryValueString.indexOf("<=") >= 0) {
394:                    operator = EntityOperator.LESS_THAN_EQUAL_TO;
395:                    queryDateOffset = 24 * 60 * 60 * 1000; // Use tomorrow's date to say less than or equal to today.
396:                } else if ((queryValueString.indexOf("<>") >= 0)
397:                        || (queryValueString.indexOf("!=") >= 0)) {
398:                    operator = EntityOperator.NOT_EQUAL;
399:                } else if (queryValueString.indexOf(">") >= 0) {
400:                    operator = EntityOperator.GREATER_THAN;
401:                    queryDateOffset = 24 * 60 * 60 * 1000; // Use tomorrow's date to say greater than today.
402:                } else if (queryValueString.indexOf("<") >= 0) {
403:                    operator = EntityOperator.LESS_THAN;
404:                } else if (queryValueString.indexOf("=") >= 0) {
405:                    operator = EntityOperator.EQUALS;
406:                } else {
407:                    operator = EntityOperator.LIKE;
408:                }
409:
410:                // Do date logic if it is embedded in the value string.
411:                convertDateQueryValue(queryValue, queryDateOffset);
412:
413:                // Remove all the special characters
414:                for (int i = 0; i < queryValue.length(); i++) {
415:                    if ((queryValue.toString().charAt(i) == '>')
416:                            || (queryValue.toString().charAt(i) == '<')
417:                            || (queryValue.toString().charAt(i) == '=')
418:                            || (queryValue.toString().charAt(i) == '!')) {
419:                        queryValue.deleteCharAt(i--);
420:                    }
421:                }
422:
423:                return operator;
424:            }
425:
426:            /**
427:             * DOCUMENT ME!
428:             *
429:             * @param queryValue 
430:             * @param queryDateOffset 
431:             *
432:             * @return 
433:             */
434:            public static StringBuffer convertDateQueryValue(
435:                    StringBuffer queryValue, long queryDateOffset) {
436:
437:                int start = queryValue.toString().toUpperCase()
438:                        .indexOf("TODAY");
439:
440:                if (start >= 0) {
441:                    // Delete the word "today"
442:                    queryValue.delete(start, start + 5);
443:
444:                    int plusOperandPos = queryValue.toString().indexOf("+");
445:                    int minusOperandPos = queryValue.toString().indexOf("-");
446:                    long offsetMilliseconds = 0;
447:
448:                    if (plusOperandPos >= 0) {
449:                        // Need to subtract days.  Get the number of days, which should be after the operand.
450:                        String offsetDaysString = queryValue.toString()
451:                                .substring(plusOperandPos + 1);
452:
453:                        offsetMilliseconds = Integer.valueOf(offsetDaysString)
454:                                .intValue()
455:                                * 24 * 60 * 60 * 1000;
456:
457:                        queryValue.delete(plusOperandPos, plusOperandPos
458:                                + offsetDaysString.length() + 1);
459:                    }
460:
461:                    if (minusOperandPos >= 0) {
462:                        // Need to subtract days.  Get the number of days, which should be after the operand.
463:                        String offsetDaysString = queryValue.toString()
464:                                .substring(minusOperandPos + 1);
465:
466:                        offsetMilliseconds = Integer.valueOf(offsetDaysString)
467:                                .intValue()
468:                                * -24 * 60 * 60 * 1000;
469:
470:                        queryValue.delete(minusOperandPos, minusOperandPos
471:                                + offsetDaysString.length() + 1);
472:                    }
473:
474:                    Date today = new Date(Calendar.getInstance().getTime()
475:                            .getTime()
476:                            + queryDateOffset + offsetMilliseconds);
477:                    SimpleDateFormat dateFormat = new SimpleDateFormat(
478:                            "yyyy-MM-dd");
479:                    String todayString = dateFormat.format(today);
480:                    queryValue.insert(start, todayString);
481:
482:                }
483:
484:                /*
485:                                // Remove all the special characters
486:                                for (int i = 0; i < queryValue.length(); i++) {
487:                                        if (        queryValue.toString().charAt(i) == '>' ||
488:                                                        queryValue.toString().charAt(i) == '<' ||
489:                                                        queryValue.toString().charAt(i) == '=' ||
490:                                                        queryValue.toString().charAt(i) == '!') {
491:                                                queryValue.deleteCharAt(i--);
492:                                        }
493:                                }
494:                 */
495:                return queryValue;
496:            }
497:
498:            /**
499:             * DOCUMENT ME!
500:             *
501:             * @param searchEntityName 
502:             * @param searchAttribName 
503:             * @param searchAttribValue 
504:             * @param queryInfo 
505:             *
506:             * @return 
507:             */
508:            public static EntityComparisonOperator appendEntityClause(
509:                    String searchEntityName, String searchAttribName,
510:                    String searchAttribValue, QueryInfo queryInfo) {
511:                EntityComparisonOperator entityOperator = appendEntityClause(
512:                        searchEntityName, searchAttribName, searchAttribValue,
513:                        null, queryInfo);
514:
515:                return entityOperator;
516:            }
517:
518:            /**
519:             * DOCUMENT ME!
520:             *
521:             * @param searchEntityName 
522:             * @param searchAttribName 
523:             * @param searchAttribValue 
524:             * @param entityOperator 
525:             * @param queryInfo
526:             *
527:             * @return 
528:             */
529:            public static EntityComparisonOperator appendEntityClause(
530:                    String searchEntityName, String searchAttribName,
531:                    Collection searchAttribValue,
532:                    EntityComparisonOperator entityOperator, QueryInfo queryInfo) {
533:                queryInfo.addCondition(searchEntityName, searchAttribName,
534:                        entityOperator, searchAttribValue);
535:
536:                return entityOperator;
537:            }
538:
539:            /**
540:             * DOCUMENT ME!
541:             *
542:             * @param searchEntityName 
543:             * @param searchAttribName 
544:             * @param searchAttribValue 
545:             * @param entityOperator 
546:             * @param queryInfo
547:             *
548:             * @return 
549:             */
550:            public static EntityComparisonOperator appendEntityClause(
551:                    String searchEntityName, String searchAttribName,
552:                    String searchAttribValue,
553:                    EntityComparisonOperator entityOperator, QueryInfo queryInfo) {
554:                // Find out the operator to use, and strip out the special characters.
555:                StringBuffer queryValueBuffer = new StringBuffer(
556:                        searchAttribValue);
557:
558:                if (entityOperator == null) {
559:                    // No entity operator was supplied. Look for operator in the query value string, and use it if found.
560:                    // If not found, use LIKE.
561:                    entityOperator = EventUtility
562:                            .getEntityOperator(queryValueBuffer);
563:                }
564:
565:                searchAttribValue = queryValueBuffer.toString();
566:
567:                if (entityOperator.equals(EntityOperator.LIKE))
568:                    searchAttribValue = searchAttribValue + "%";
569:
570:                queryInfo.addCondition(searchEntityName, searchAttribName,
571:                        entityOperator, searchAttribValue.replace('*', '%'));
572:
573:                return entityOperator;
574:            }
575:
576:            /**
577:             * DOCUMENT ME!
578:             *
579:             * @param searchEntityName 
580:             * @param paramList 
581:             * @param queryInfo  criteria to be used in search 
582:             */
583:            public static void appendEntityClauses(String searchEntityName,
584:                    HashMap paramList, QueryInfo queryInfo) {
585:                Iterator params = paramList.entrySet().iterator();
586:
587:                while (params.hasNext()) {
588:                    Map.Entry param = (Map.Entry) params.next();
589:                    String searchAttribName = (String) param.getKey();
590:                    String searchAttribValue = (String) param.getValue();
591:
592:                    queryInfo.addCondition(searchEntityName, searchAttribName,
593:                            EntityOperator.EQUALS, searchAttribValue);
594:                }
595:
596:                return;
597:            }
598:
599:            /**
600:             * This function returns an arraylist containing HashMaps representing the primary keys of records
601:             * in a many-to-many relationship which are to be added to or removed from te data base after
602:             * being selected or unselected on a SELECT screen section.
603:             * @author  John Nutting
604:             * version  1
605:             * @param  queryParameterValueList  A hash map containing the values being used to filter the screen section.\
606:             *   Example: key=dealId, value=10010
607:             * @param  itemString  String representation of the list of keys to be added or removed.
608:             *   Example representing 3 entities, each with 2 fields in the key:
609:             *   "displayObjectId:10021,displayTypeId:22320,displayAttribId:SIZE;displayObjectId:10021,displayTypeId:22320,displayAttribId:DISABLED"
610:             * @return  An ArrayList of HashMaps, each containing the primary key of a generic value to be added to or removed from the data base.
611:             */
612:            public static ArrayList decodeSelectItem(
613:                    HashMap queryParameterValueList, String itemString) {
614:
615:                ArrayList manyToManyKeyMapList = new ArrayList();
616:
617:                if (itemString != null) {
618:                    StringTokenizer semicolonTokenizer = new StringTokenizer(
619:                            itemString, ";");
620:
621:                    while (semicolonTokenizer.hasMoreTokens()) {
622:                        // User selected or un-selected this item.  Need to add it to the many-to-many map list.
623:                        HashMap manyToManyKepMap = new HashMap();
624:
625:                        // Add the fields that are being used to filter the screen section.  These will be
626:                        // one component of the primary key of the many-to-many table.  Example: dealId:10010.
627:                        manyToManyKepMap.putAll(queryParameterValueList);
628:
629:                        // Add the key(s) of the item.  Example: "displayObjectId:10021,displayTypeId:22320"
630:                        String itemKeyDef = semicolonTokenizer.nextToken();
631:                        StringTokenizer commaTokenizer = new StringTokenizer(
632:                                itemKeyDef, ",");
633:
634:                        while (commaTokenizer.hasMoreTokens()) {
635:                            // One more field in the key of the removed item was found.
636:                            String itemKeyField = commaTokenizer.nextToken();
637:                            String itemKeyAttribName = "";
638:                            String itemKeyAttribValue = "";
639:                            StringTokenizer colonTokenizer = new StringTokenizer(
640:                                    itemKeyField, ":");
641:
642:                            if (colonTokenizer.hasMoreTokens()) {
643:                                // The name of the key attribute was found.
644:                                itemKeyAttribName = colonTokenizer.nextToken();
645:                            } else {
646:                                // Error. The name of the key attribute was not found in the string.
647:                                Debug.logWarning(
648:                                        "[EventUtility.decodeSelectItem] Key attribute name was not found in "
649:                                                + itemKeyField, module);
650:
651:                                return manyToManyKeyMapList;
652:                            }
653:
654:                            if (colonTokenizer.hasMoreTokens()) {
655:                                // The value of the key attribute was found.
656:                                itemKeyAttribValue = colonTokenizer.nextToken();
657:                            } else {
658:                                // Error. The value of the key attribute was not found in the string.
659:                                Debug.logWarning(
660:                                        "[EventUtility.decodeSelectItem] Key attribute value was not found in "
661:                                                + itemKeyField, module);
662:
663:                                return manyToManyKeyMapList;
664:                            }
665:
666:                            manyToManyKepMap.put(itemKeyAttribName,
667:                                    itemKeyAttribValue);
668:                        }
669:
670:                        manyToManyKeyMapList.add(manyToManyKepMap);
671:                    }
672:                }
673:
674:                return manyToManyKeyMapList;
675:            }
676:
677:            /**
678:             * Add entity clauses for one related entity.  This will join related tables to the query
679:             * during a retrieve so query values can be entered that are in related entities.
680:             *
681:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
682:             *
683:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
684:             * @param relationTitle Relation title
685:             * @param relatedEntityName Name of related entity
686:             * @param primaryEntityName Name of the primary entity
687:             * @param primaryME ModelEntity object for the primary entity
688:             * @param queryInfo  criteria to be used in search
689:             */
690:            public static void addOneRelationClause(GenericDelegator delegator,
691:                    String relationTitle, String relatedAndFields,
692:                    String relatedEntityName, String primaryEntityName,
693:                    ModelEntity primaryME, boolean isOuterJoin,
694:                    QueryInfo queryInfo) throws GenericEntityException {
695:
696:                String relationName = relationTitle + relatedEntityName;
697:                ModelRelation relation = primaryME.getRelation(relationName);
698:
699:                if (relation == null) {
700:                    Debug.logWarning("Could not find relation for on entity "
701:                            + primaryME.getEntityName() + " for relationName "
702:                            + relationName, module);
703:                } else {
704:                    // Relation was found. Add it to the where and from clauses.
705:                    ModelReader modelReader = delegator.getModelReader();
706:                    ModelEntity relatedME = modelReader.getModelEntity(relation
707:                            .getRelEntityName());
708:                    Iterator keyMapsIterator = relation.getKeyMapsIterator();
709:
710:                    List keyMaps = new ArrayList();
711:
712:                    while (keyMapsIterator.hasNext()) {
713:                        ModelKeyMap keyMap = (ModelKeyMap) keyMapsIterator
714:                                .next();
715:
716:                        Debug.logVerbose("Adding to entityClauses: "
717:                                + primaryEntityName + ", " + relatedEntityName
718:                                + ", " + keyMap.getFieldName() + ", "
719:                                + keyMap.getRelFieldName(), module);
720:
721:                        keyMaps.add(keyMap);
722:                    }
723:
724:                    queryInfo.addJoin(primaryEntityName, relatedEntityName,
725:                            Boolean.valueOf(isOuterJoin), keyMaps);
726:
727:                }
728:            }
729:
730:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.