Source Code Cross Referenced for UIQuery.java in  » ERP-CRM-Financial » SourceTap-CRM » com » sourcetap » sfa » ui » 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.ui 
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.ui;
018:
019:        import java.util.ArrayList;
020:        import java.util.Collection;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.LinkedList;
024:        import java.util.List;
025:        import java.util.StringTokenizer;
026:
027:        import org.ofbiz.base.util.Debug;
028:        import org.ofbiz.base.util.UtilFormatOut;
029:        import org.ofbiz.base.util.UtilMisc;
030:        import org.ofbiz.entity.GenericDelegator;
031:        import org.ofbiz.entity.GenericEntityException;
032:        import org.ofbiz.entity.GenericValue;
033:        import org.ofbiz.entity.condition.EntityComparisonOperator;
034:        import org.ofbiz.entity.condition.EntityCondition;
035:        import org.ofbiz.entity.condition.EntityConditionList;
036:        import org.ofbiz.entity.condition.EntityExpr;
037:        import org.ofbiz.entity.condition.EntityOperator;
038:        import org.ofbiz.entity.model.DynamicViewEntity;
039:        import org.ofbiz.entity.model.ModelKeyMap;
040:
041:        import com.sourcetap.sfa.event.EventUtility;
042:        import com.sourcetap.sfa.replication.GenericReplicator;
043:        import com.sourcetap.sfa.util.EntityHelper;
044:        import com.sourcetap.sfa.util.QueryInfo;
045:
046:        /**
047:         * This class is used by the UI builder to store and retrieve queries so they can be reused.
048:         *
049:         * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
050:         * @see  #UIQueryValue
051:         */
052:        public class UIQuery {
053:            public static final String module = UIQuery.class.getName();
054:
055:            /**
056:             * Constant containing the name of the last query used
057:             */
058:            public static final String LAST_QUERY_NAME = ".Last Query";
059:            public static final String LAST_QUERY_NAME_URL_ENCODED = ".Last+Query";
060:
061:            /**
062:             * Query ID - Uniquely identifies this query
063:             */
064:            protected String queryId = "";
065:
066:            /**
067:             * Section ID - Identifies the UI screen section on which this query can be used
068:             */
069:            protected String sectionId = "";
070:
071:            /**
072:             * Party ID - Identifies the user who created the query, and who can re-use it.
073:             */
074:            protected String partyId = "";
075:
076:            /**
077:             * Query Name - Name of this query to appear on the screen in the drop list of available queries
078:             */
079:            protected String queryName = "";
080:
081:            /**
082:             * Query Value List - List of objects that contain the query values for this query
083:             *
084:             * @see #UIQueryValue
085:             */
086:            protected ArrayList uiQueryValueList = new ArrayList();
087:
088:            /**
089:             * Basic constructor
090:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
091:             */
092:            public UIQuery() {
093:            }
094:
095:            /**
096:             * Constructor to create a UI Query from the data base using the specified query ID
097:             * @param queryId_ Query ID - Uniquely identifies this query
098:             * @param delegator Generic delegator object required to attach to the correct data source
099:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
100:             */
101:            public UIQuery(String queryId_, GenericDelegator delegator) {
102:
103:                HashMap uiQueryFindMap = new HashMap();
104:                uiQueryFindMap.put("queryId", queryId_);
105:
106:                try {
107:                    // Get the query from the data base.
108:                    GenericValue uiQueryGV = delegator.findByPrimaryKey(
109:                            "UiQuery", uiQueryFindMap);
110:
111:                    if (uiQueryGV == null) {
112:                        Debug.logWarning(
113:                                "[UIQuery.UIQuery(queryId)] UiQuery not found with query ID"
114:                                        + queryId_, module);
115:
116:                        return;
117:                    }
118:
119:                    setQueryId((uiQueryGV.getString("queryId") == null) ? ""
120:                            : uiQueryGV.getString("queryId"));
121:                    setSectionId((uiQueryGV.getString("sectionId") == null) ? ""
122:                            : uiQueryGV.getString("sectionId"));
123:                    setPartyId((uiQueryGV.getString("partyId") == null) ? ""
124:                            : uiQueryGV.getString("partyId"));
125:                    setQueryName((uiQueryGV.getString("queryName") == null) ? ""
126:                            : uiQueryGV.getString("queryName"));
127:
128:                    try {
129:
130:                        // Get the query values.
131:                        HashMap uiQueryValueFindMap = new HashMap();
132:                        uiQueryValueFindMap.put("queryId", queryId_);
133:
134:                        // Get the query from the data base.
135:                        List uiQueryValueGVL = delegator.findByAnd(
136:                                "UiQueryValue", uiQueryValueFindMap);
137:                        Iterator uiQueryValueGVI = uiQueryValueGVL.iterator();
138:
139:                        while (uiQueryValueGVI.hasNext()) {
140:                            GenericValue uiQueryValueGV = (GenericValue) uiQueryValueGVI
141:                                    .next();
142:                            String entityOperatorIdString = (uiQueryValueGV
143:                                    .getString("queryOperatorId") == null) ? "1"
144:                                    : uiQueryValueGV
145:                                            .getString("queryOperatorId");
146:                            int entityOperatorId = Integer.valueOf(
147:                                    entityOperatorIdString).intValue();
148:                            addUiQueryValue(
149:                                    UtilFormatOut.checkNull(uiQueryValueGV
150:                                            .getString("attributeId")),
151:                                    EntityOperator
152:                                            .lookup(EntityHelper
153:                                                    .getEntityOperator(entityOperatorId)),
154:                                    UtilFormatOut.checkNull(uiQueryValueGV
155:                                            .getString("attributeValue")),
156:                                    UtilFormatOut.checkNull(uiQueryValueGV
157:                                            .getString("displayTypeId")),
158:                                    UtilFormatOut.checkNull(uiQueryValueGV
159:                                            .getString("displayObjectId")),
160:                                    delegator);
161:                        }
162:                    } catch (GenericEntityException e2) {
163:                        Debug.logError(
164:                                "[UIQuery.UIQuery(queryId)] Error looking for UiQueryValues with query ID"
165:                                        + queryId_ + ": "
166:                                        + e2.getLocalizedMessage(), module);
167:                    }
168:                } catch (GenericEntityException e1) {
169:                    Debug.logError(
170:                            "[UIQuery.UIQuery(queryId)] Error looking for UiQuery with query ID"
171:                                    + queryId_ + ": "
172:                                    + e1.getLocalizedMessage(), module);
173:                }
174:            }
175:
176:            /**
177:             * Constructor with initial values
178:             * @param queryId_ Query ID - Uniquely identifies this query
179:             * @param sectionId_ Section ID - Identifies the UI screen section on which this query can be used
180:             * @param partyId_ Party ID - Identifies the user who created the query, and who can re-use it.
181:             * @param queryName_ Query Name - Name of this query to appear on the screen in the drop list of available queries
182:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
183:             */
184:            public UIQuery(String queryId_, String sectionId_, String partyId_,
185:                    String queryName_, ArrayList uiQueryValueList_) {
186:
187:                setQueryId(queryId_);
188:                setSectionId(sectionId_);
189:                setPartyId(partyId_);
190:                setQueryName(queryName_);
191:                setUiQueryValueList(uiQueryValueList_);
192:            }
193:
194:            /**
195:             * Gets the Query ID
196:             * @return Query ID - Uniquely identifies this query
197:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
198:             */
199:            public String getQueryId() {
200:                return (queryId == null) ? "" : queryId;
201:            }
202:
203:            /**
204:             * Sets the Query ID
205:             * @param queryId_ Query ID - Uniquely identifies this query
206:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
207:             */
208:            public void setQueryId(String queryId_) {
209:                queryId = queryId_;
210:
211:                return;
212:            }
213:
214:            /**
215:             * Gets the Section ID
216:             * @param sectionId_ Section ID - Identifies the UI screen section on which this query can be used
217:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
218:             */
219:            public String getSectionId() {
220:                return (sectionId == null) ? "" : sectionId;
221:            }
222:
223:            /**
224:             * Sets the Section ID
225:             * @return Section ID - Identifies the UI screen section on which this query can be used
226:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
227:             */
228:            public void setSectionId(String sectionId_) {
229:                sectionId = sectionId_;
230:
231:                return;
232:            }
233:
234:            /**
235:             * Gets the Party ID
236:             * @return Party ID - Identifies the user who created the query, and who can re-use it.
237:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
238:             */
239:            public String getPartyId() {
240:                return (partyId == null) ? "" : partyId;
241:            }
242:
243:            /**
244:             * Sets the Party ID
245:             * @param partyId_ Party ID - Identifies the user who created the query, and who can re-use it.
246:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
247:             */
248:            public void setPartyId(String partyId_) {
249:                partyId = partyId_;
250:
251:                return;
252:            }
253:
254:            /**
255:             * Gets the Query Name
256:             * @param queryName_ Query Name - Name of this query to appear on the screen in the drop list of available queries
257:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
258:             */
259:            public String getQueryName() {
260:                return (queryName == null) ? "" : queryName;
261:            }
262:
263:            /**
264:             * Sets the Query Name
265:             * @return_ Query Name - Name of this query to appear on the screen in the drop list of available queries
266:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
267:             */
268:            public void setQueryName(String queryName_) {
269:                queryName = queryName_;
270:
271:                return;
272:            }
273:
274:            /**
275:             * Gets a reference to the Query Value List
276:             *
277:             * @return_ Query Value List - List of objects that contain the query values for this query
278:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
279:             * @see #UIQueryValue
280:             */
281:            public ArrayList getUiQueryValueList() {
282:                return uiQueryValueList;
283:            }
284:
285:            /**
286:             * Stores an ArrayList containing values of type UIQueryValue into the Query Value List
287:             *
288:             * @param uiQueryValueList_ Query Value List - List of objects that contain the query values for this query
289:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
290:             * @see #UIQueryValue
291:             */
292:            public void setUiQueryValueList(ArrayList uiQueryValueList_) {
293:                uiQueryValueList = uiQueryValueList_;
294:
295:                return;
296:            }
297:
298:            /**
299:             * Gets a reference to the UIQueryValue stored in the query value list at the position specified by the queryValueNbr parameter
300:             *
301:             * @param queryValueNbr Position in the query value list from which to get the query value object
302:             * @return Query value object from the specified position in the query value list
303:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
304:             * @see #UIQueryValue
305:             */
306:            public UIQueryValue getUiQueryValue(int queryValueNbr) {
307:
308:                return (UIQueryValue) uiQueryValueList.get(queryValueNbr);
309:            }
310:
311:            /**
312:             * Adds an object of class UIQueryValue to the query value list
313:             *
314:             * @param attributeId_ Attribute ID - Uniquely identifies an attribute defined in the UI data
315:             * @param attributeValue_ The value to be compared to the specified attribute on entities in the data base
316:             *    when the query is executed
317:             * @param entityOperator_ The operand to be used to compare the value to the specified attribute on
318:             *    entities in the data base when the query is executed
319:             * @param delegator Generic delegator object required to attach to the correct data source
320:             * @return ID of new query value
321:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
322:             * @see #UIQueryValue
323:             */
324:            public void addUiQueryValue(String attributeId,
325:                    EntityOperator entityOperator, String attributeValue,
326:                    String displayTypeId, String displayObjectId,
327:                    GenericDelegator delegator) {
328:
329:                uiQueryValueList.add(new UIQueryValue("", getQueryId(),
330:                        attributeId, attributeValue,
331:                        (EntityComparisonOperator) entityOperator,
332:                        displayTypeId, displayObjectId));
333:
334:                //		return queryValueId;
335:                return;
336:            }
337:
338:            /**
339:             * DOCUMENT ME!
340:             *
341:             * @param delegator 
342:             * @param partyId 
343:             * @param sectionName 
344:             * @param screenName 
345:             *
346:             * @return 
347:             *
348:             * @throws GenericEntityException 
349:             */
350:            public static List getUiQueryList(GenericDelegator delegator,
351:                    String partyId, String sectionName, String screenName)
352:                    throws GenericEntityException {
353:
354:                // Add all queries not tied to any particular party ID or screen section.
355:                HashMap uiQueryFindMap = new HashMap();
356:                uiQueryFindMap.put("partyId", "-1");
357:                uiQueryFindMap.put("sectionId", "-1");
358:
359:                ArrayList uiQueryFindOrder = new ArrayList();
360:                uiQueryFindOrder.add("queryName");
361:
362:                List uiQueryGVL = delegator.findByAnd("UiQuery",
363:                        uiQueryFindMap, uiQueryFindOrder);
364:
365:                // Add all queries not tied to any particular party ID, but tied to the current screen section.
366:                // Find the last query used by this party ID for this screen section.
367:                // select X from ui_query q, ui_screen_section ss, ui_screen s where q.section_id = ss.section_id and q.party_id = -1 and ss.section_name = <section_name>
368:                //      and s.screen_name = <screenName> and s.screen_id = ss.screen_id order by query_name       
369:                DynamicViewEntity dve = EntityHelper.createDynamicViewEntity(
370:                        delegator, "UiQuery");
371:                dve.addMemberEntity("UiScreenSection", "UiScreenSection");
372:                dve.addViewLink("UiQuery", "UiScreenSection", Boolean.FALSE,
373:                        UtilMisc.toList(new ModelKeyMap("sectionId",
374:                                "sectionId")));
375:                dve.addMemberEntity("UiScreen", "UiScreen");
376:                dve
377:                        .addViewLink("UiScreenSection", "UiScreen",
378:                                Boolean.FALSE, UtilMisc.toList(new ModelKeyMap(
379:                                        "screenId", "screenId")));
380:                dve.addAlias("UiScreen", "screenName", null, null, null, null,
381:                        null);
382:                dve.addAlias("UiScreenSection", "sectionName", null, null,
383:                        null, null, null);
384:
385:                EntityCondition condition = new EntityConditionList(UtilMisc
386:                        .toList(new EntityExpr("partyId",
387:                                EntityOperator.EQUALS, "-1"),
388:                                new EntityExpr("screenName",
389:                                        EntityOperator.EQUALS, screenName),
390:                                new EntityExpr("sectionName",
391:                                        EntityOperator.EQUALS, sectionName)),
392:                        EntityOperator.AND);
393:
394:                uiQueryGVL.addAll(EntityHelper.findByCondition(delegator, dve,
395:                        condition, uiQueryFindOrder));
396:
397:                // Add all queries tied to the current party ID and screen section.
398:                // select X from ui_query q, ui_screen_section ss, ui_screen s where q.section_id = ss.section_id and q.party_id = <partyId> and ss.section_name = <section_name>
399:                //      and s.screen_name = <screenName> and s.screen_id = ss.screen_id order by query_name       
400:                condition = new EntityConditionList(UtilMisc.toList(
401:                        new EntityExpr("partyId", EntityOperator.EQUALS,
402:                                partyId), new EntityExpr("screenName",
403:                                EntityOperator.EQUALS, screenName),
404:                        new EntityExpr("sectionName", EntityOperator.EQUALS,
405:                                sectionName)), EntityOperator.AND);
406:
407:                uiQueryGVL.addAll(EntityHelper.findByCondition(delegator, dve,
408:                        condition, uiQueryFindOrder));
409:
410:                return uiQueryGVL;
411:            }
412:
413:            /**
414:             * DOCUMENT ME!
415:             *
416:             * @param delegator 
417:             * @param partyId 
418:             * @param sectionName 
419:             * @param screenName 
420:             * @param savedQueryName 
421:             *
422:             * @return 
423:             *
424:             * @throws GenericEntityException 
425:             */
426:            public static GenericValue getUiQueryByName(
427:                    GenericDelegator delegator, String partyId,
428:                    String sectionName, String screenName, String savedQueryName)
429:                    throws GenericEntityException {
430:
431:                GenericValue uiQueryGV = null;
432:
433:                // Find the last query used by this party ID for this screen section.
434:                // select X from ui_query q, ui_screen_section ss, ui_screen s where q.section_id = ss.section_id and q.party_id = <party_id> and ss.section_name = <section_name>
435:                //      and s.screen_name = <screenName> and s.screen_id = ss.screen_id and q.queryName = <queryName>        
436:                DynamicViewEntity dve = EntityHelper.createDynamicViewEntity(
437:                        delegator, "UiQuery");
438:                dve.addMemberEntity("UiScreenSection", "UiScreenSection");
439:                dve.addViewLink("UiQuery", "UiScreenSection", Boolean.FALSE,
440:                        UtilMisc.toList(new ModelKeyMap("sectionId",
441:                                "sectionId")));
442:                dve.addMemberEntity("UiScreen", "UiScreen");
443:                dve
444:                        .addViewLink("UiScreenSection", "UiScreen",
445:                                Boolean.FALSE, UtilMisc.toList(new ModelKeyMap(
446:                                        "screenId", "screenId")));
447:                dve.addAlias("UiScreen", "screenName", null, null, null, null,
448:                        null);
449:                dve.addAlias("UiScreenSection", "sectionName", null, null,
450:                        null, null, null);
451:
452:                EntityCondition condition = new EntityConditionList(UtilMisc
453:                        .toList(new EntityExpr("partyId",
454:                                EntityOperator.EQUALS, partyId),
455:                                new EntityExpr("queryName",
456:                                        EntityOperator.EQUALS, savedQueryName),
457:                                new EntityExpr("screenName",
458:                                        EntityOperator.EQUALS, screenName),
459:                                new EntityExpr("sectionName",
460:                                        EntityOperator.EQUALS, sectionName)),
461:                        EntityOperator.AND);
462:
463:                List uiQueryGVL = EntityHelper.findByCondition(delegator, dve,
464:                        condition, null);
465:
466:                if (uiQueryGVL.size() == 0) {
467:                    // There is no last query to pull up.
468:                    Debug.logWarning(
469:                            "[UIQuery.getUiQueryByName]: Named query not found for query name "
470:                                    + savedQueryName + ", partyId " + partyId
471:                                    + ", sectionName " + sectionName
472:                                    + ", and screenName " + screenName + ".",
473:                            module);
474:
475:                    return uiQueryGV;
476:                } else {
477:                    // The last query was found. Get it from the List.
478:                    Debug.logVerbose(
479:                            "[UIQuery.getUiQueryByName]: Named query found for query name "
480:                                    + savedQueryName + ", partyId " + partyId
481:                                    + ", sectionName " + sectionName
482:                                    + ", and screenName " + screenName + ".",
483:                            module);
484:
485:                    uiQueryGV = (GenericValue) uiQueryGVL.iterator().next();
486:                }
487:
488:                /*
489:                                // Add the query values to the "other" array of the query generic value object.
490:                                List uiQueryValueL = (List)delegator.getRelated("UiQueryValue", uiQueryGV);
491:                                uiQueryGV.preStoreOthers(uiQueryValueL);
492:                 */
493:                return uiQueryGV;
494:            }
495:
496:            /**
497:             * DOCUMENT ME!
498:             *
499:             * @param delegator 
500:             * @param queryId 
501:             *
502:             * @return 
503:             *
504:             * @throws GenericEntityException 
505:             */
506:            public static List getUiQueryValues(GenericDelegator delegator,
507:                    String queryId) throws GenericEntityException {
508:
509:                HashMap uiQueryFindMap = new HashMap();
510:                uiQueryFindMap.put("queryId", queryId);
511:
512:                GenericValue uiQueryGV = delegator.findByPrimaryKey("UiQuery",
513:                        uiQueryFindMap);
514:
515:                if (uiQueryGV == null) {
516:                    throw new GenericEntityException(
517:                            "No UI Query was found with ID \"" + queryId
518:                                    + "\".");
519:                }
520:
521:                // Get the query values for this query ID.
522:                List uiQueryValueL = (List) delegator.getRelated(
523:                        "UiQueryValue", uiQueryGV);
524:
525:                return uiQueryValueL;
526:            }
527:
528:            /**
529:             * Save the query to the data base
530:             * @param delegator Generic delegator object required to attach to the correct data source
531:             * @return Query ID - Uniquely identifies this query
532:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
533:             */
534:            public String save(GenericDelegator delegator) {
535:                // Find out if there is already a query saved with this name for this section ID and party ID.  If so,
536:                // just retrieve and update that one.
537:
538:                HashMap uiQueryFindMap = new HashMap();
539:                uiQueryFindMap.put("partyId", getPartyId());
540:                uiQueryFindMap.put("sectionId", getSectionId());
541:                uiQueryFindMap.put("queryName", getQueryName());
542:
543:                Debug.logVerbose(
544:                        "[UIQuery.save] About to search for UiQuery - "
545:                                + "partyId:" + getPartyId() + ", sectionId:"
546:                                + getSectionId() + ", queryName:"
547:                                + getQueryName(), module);
548:
549:                try {
550:                    List storeGVL = new LinkedList();
551:                    List uiQueryGVL = delegator.findByAnd("UiQuery",
552:                            uiQueryFindMap, null);
553:                    GenericValue uiQueryGV = null;
554:
555:                    if (uiQueryGVL.size() == 0) {
556:                        // Query not found. Create a new one.
557:
558:                        setQueryId(GenericReplicator.getNextSeqId("UiQuery",
559:                                delegator));
560:                        uiQueryGV = toGenericValue(delegator);
561:                    } else {
562:
563:                        // Query already exists. Prepare to update existing.
564:                        uiQueryGV = (GenericValue) uiQueryGVL.iterator().next();
565:
566:                        // Store the existing query ID from the data base to this query object.
567:                        setQueryId(uiQueryGV.getString("queryId"));
568:
569:                        // Remove existing query values from the data base.
570:                        List uiQueryValueL = (List) delegator.getRelated(
571:                                "UiQueryValue", uiQueryGV);
572:                        Iterator uiQueryValueI = uiQueryValueL.iterator();
573:
574:                        while (uiQueryValueI.hasNext()) {
575:                            // Remove this attribute from the database.
576:                            GenericValue uiQueryValueGV = (GenericValue) uiQueryValueI
577:                                    .next();
578:                            uiQueryValueGV.remove();
579:                        }
580:                    }
581:
582:                    // Add the query onto the List of records to be saved.
583:                    storeGVL.add(uiQueryGV);
584:
585:                    // Append all the attributes onto the query so they will be inserted into the data base.
586:
587:                    ArrayList uiQueryValueList = getUiQueryValueList();
588:
589:                    for (int uiQueryValueNbr = 0; uiQueryValueNbr < uiQueryValueList
590:                            .size(); uiQueryValueNbr++) {
591:
592:                        UIQueryValue uiQueryValue = getUiQueryValue(uiQueryValueNbr);
593:
594:                        // Copy the query ID onto the query value in case it is not already set.
595:                        uiQueryValue.setQueryId(getQueryId());
596:
597:                        // Set the query VALUE ID now so it will change each time we save the query.
598:                        String queryValueId = GenericReplicator.getNextSeqId(
599:                                "UiQueryValue", delegator);
600:
601:                        uiQueryValue.setQueryValueId(queryValueId);
602:
603:                        // Create a generic value for this query value, and attach it to the query's generic value so it will be saved.
604:                        GenericValue uiQueryValueGV = uiQueryValue
605:                                .toGenericValue(delegator);
606:
607:                        // Add the query value onto the List of records to be saved.
608:                        storeGVL.add(uiQueryValueGV);
609:                    }
610:
611:                    try {
612:                        // Insert or update the query and associated values.
613:                        delegator.storeAll(storeGVL);
614:                    } catch (GenericEntityException e2) {
615:                        Debug.logError("[UIQuery.save] Error saving query: "
616:                                + e2.getLocalizedMessage(), module);
617:                    }
618:                } catch (GenericEntityException e) {
619:                    Debug.logError(
620:                            "[UIQuery.save] Error looking for existing query: "
621:                                    + e.getLocalizedMessage(), module);
622:                }
623:
624:                return getQueryId();
625:            }
626:
627:            /**
628:             * Create entity clauses for this query that can be used by the GenericDelegator.findByCondition method
629:             * @param delegator Generic delegator object required to attach to the correct data source
630:             * @param queryInfo  criteria to be used in search
631:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
632:             */
633:            public void appendEntityClauses(GenericDelegator delegator,
634:                    QueryInfo queryInfo) {
635:
636:                // Append an entity clause for each query value.
637:                for (int uiQueryValueNbr = 0; uiQueryValueNbr < uiQueryValueList
638:                        .size(); uiQueryValueNbr++) {
639:                    UIQueryValue uiQueryValue = getUiQueryValue(uiQueryValueNbr);
640:
641:                    try {
642:                        // Find the UI attribute generic value.
643:                        HashMap uiAttributeSearchMap = new HashMap();
644:                        uiAttributeSearchMap.put("attributeId", uiQueryValue
645:                                .getAttributeId());
646:
647:                        GenericValue uiAttributeGV = delegator
648:                                .findByPrimaryKey("UiAttribute",
649:                                        uiAttributeSearchMap);
650:                        String searchAttribName = uiAttributeGV
651:                                .getString("attributeName");
652:                        String entityId = uiAttributeGV.getString("entityId");
653:
654:                        // Find the UI entity generic value.
655:                        HashMap uiEntitySearchMap = new HashMap();
656:                        uiEntitySearchMap.put("entityId", entityId);
657:
658:                        List queryEntities = queryInfo.getEntities();
659:                        HashMap joinedEntities = new HashMap();
660:                        for (int i = 0; i < queryEntities.size(); i++) {
661:                            joinedEntities.put((String) queryEntities.get(i),
662:                                    "Y");
663:                        }
664:
665:                        try {
666:                            GenericValue uiEntityGV = delegator
667:                                    .findByPrimaryKey("UiEntity",
668:                                            uiEntitySearchMap);
669:                            String searchEntityName = uiEntityGV
670:                                    .getString("entityName");
671:
672:                            String hasJoin = (String) joinedEntities
673:                                    .get(searchEntityName);
674:
675:                            if ((hasJoin == null) || (!hasJoin.equals("Y"))) {
676:                                String primaryEntityName = queryInfo
677:                                        .getPrimaryEntity();
678:                                EventUtility
679:                                        .addOneRelationClause(
680:                                                delegator,
681:                                                "",
682:                                                "",
683:                                                searchEntityName,
684:                                                primaryEntityName,
685:                                                delegator
686:                                                        .getModelEntity(primaryEntityName),
687:                                                false, queryInfo);
688:
689:                                joinedEntities.put(searchEntityName, "Y");
690:                            }
691:
692:                            String displayTypeId = uiQueryValue
693:                                    .getDisplayTypeId();
694:
695:                            EntityComparisonOperator entityOperator = uiQueryValue
696:                                    .getEntityOperator();
697:                            String searchValueStr = uiQueryValue
698:                                    .getAttributeValue();
699:                            Object searchValue = searchValueStr;
700:
701:                            // If this is a set operator, convert the String param into a comma separated List 
702:                            if ((entityOperator.equals(EntityOperator.IN))
703:                                    || (entityOperator
704:                                            .equals(EntityOperator.NOT_IN))
705:                                    || (entityOperator
706:                                            .equals(EntityOperator.BETWEEN))) {
707:                                List valueList = new ArrayList();
708:                                StringTokenizer tokComma = new StringTokenizer(
709:                                        searchValueStr, ",");
710:
711:                                while (tokComma.hasMoreTokens()) {
712:                                    String valueItem = tokComma.nextToken();
713:                                    valueList.add(valueItem);
714:                                }
715:                                searchValue = valueList;
716:                            }
717:
718:                            // Generate an entry in the WHERE clause for this attribute.  
719:                            // If this is a select field, we need to search on the lookup value, not the lookup ID
720:                            if (displayTypeId
721:                                    .equals(UIDisplayObject.DISPLAY_TYPE_SELECT)
722:                                    || displayTypeId
723:                                            .equals(UIDisplayObject.DISPLAY_TYPE_SEARCH_TEXT)) {
724:                                String aliasName = searchEntityName
725:                                        + searchAttribName + "srch";
726:                                UIUtility.addSelectSearch(queryInfo,
727:                                        uiQueryValue.getDisplayObjectId(),
728:                                        searchEntityName, searchAttribName,
729:                                        aliasName, entityOperator, searchValue);
730:                            } else {
731:                                // Generate an entry in the WHERE clause for this attribute.
732:                                if (searchValue instanceof  Collection)
733:                                    EventUtility.appendEntityClause(
734:                                            searchEntityName, searchAttribName,
735:                                            (Collection) searchValue,
736:                                            entityOperator, queryInfo);
737:                                else
738:                                    EventUtility.appendEntityClause(
739:                                            searchEntityName, searchAttribName,
740:                                            searchValueStr, entityOperator,
741:                                            queryInfo);
742:                            }
743:
744:                        } catch (GenericEntityException e2) {
745:                            Debug.logError(
746:                                    "[UIQuery.appendEntityClauses] Error looking for UiEntity: "
747:                                            + e2.getLocalizedMessage(), module);
748:                        }
749:                    } catch (GenericEntityException e1) {
750:                        Debug.logError(
751:                                "[UIQuery.appendEntityClauses] Error looking for UiAttribute: "
752:                                        + e1.getLocalizedMessage(), module);
753:                    }
754:                }
755:            }
756:
757:            /**
758:             * Creates a generic value for this query.
759:             * @param delegator Generic delegator object required to attach to the correct data source
760:             * @return Generic value representing this query
761:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
762:             */
763:            public GenericValue toGenericValue(GenericDelegator delegator) {
764:
765:                GenericValue uiQueryGV = new GenericValue(delegator
766:                        .getModelEntity("UiQuery"));
767:                uiQueryGV.setDelegator(delegator);
768:                uiQueryGV.set("queryId", getQueryId());
769:                uiQueryGV.set("sectionId", getSectionId());
770:                uiQueryGV.set("partyId", getPartyId());
771:                uiQueryGV.set("queryName", getQueryName());
772:
773:                return uiQueryGV;
774:            }
775:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.