Source Code Cross Referenced for UIReport.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) 


0001:        /*
0002:         * 
0003:         * Copyright (c) 2004 SourceTap - www.sourcetap.com
0004:         *
0005:         *  The contents of this file are subject to the SourceTap Public License 
0006:         * ("License"); You may not use this file except in compliance with the 
0007:         * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
0008:         * Software distributed under the License is distributed on an  "AS IS"  basis,
0009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
0010:         * the specific language governing rights and limitations under the License.
0011:         *
0012:         * The above copyright notice and this permission notice shall be included
0013:         * in all copies or substantial portions of the Software.
0014:         *
0015:         */
0016:
0017:        package com.sourcetap.sfa.ui;
0018:
0019:        import java.util.ArrayList;
0020:        import java.util.Collection;
0021:        import java.util.HashMap;
0022:        import java.util.Iterator;
0023:        import java.util.LinkedList;
0024:        import java.util.List;
0025:        import java.util.Map;
0026:        import java.util.StringTokenizer;
0027:
0028:        import javax.servlet.http.HttpServletRequest;
0029:        import javax.servlet.http.HttpServletResponse;
0030:
0031:        import org.ofbiz.base.util.Debug;
0032:        import org.ofbiz.base.util.UtilFormatOut;
0033:        import org.ofbiz.base.util.UtilMisc;
0034:        import org.ofbiz.entity.GenericDelegator;
0035:        import org.ofbiz.entity.GenericEntityException;
0036:        import org.ofbiz.entity.GenericValue;
0037:        import org.ofbiz.entity.condition.EntityComparisonOperator;
0038:        import org.ofbiz.entity.condition.EntityCondition;
0039:        import org.ofbiz.entity.condition.EntityConditionList;
0040:        import org.ofbiz.entity.condition.EntityExpr;
0041:        import org.ofbiz.entity.condition.EntityOperator;
0042:        import org.ofbiz.entity.model.ModelEntity;
0043:        import org.ofbiz.entity.util.EntityListIterator;
0044:
0045:        import com.sourcetap.sfa.event.EventUtility;
0046:        import com.sourcetap.sfa.event.GenericEventProcessor;
0047:        import com.sourcetap.sfa.replication.GenericReplicator;
0048:        import com.sourcetap.sfa.security.SecurityLinkInfo;
0049:        import com.sourcetap.sfa.security.SecurityWrapper;
0050:        import com.sourcetap.sfa.util.QueryInfo;
0051:        import com.sourcetap.sfa.util.UserInfo;
0052:
0053:        public class UIReport {
0054:            public static final String module = UIReport.class.getName();
0055:
0056:            protected boolean primaryFieldsLoaded = false;
0057:            protected boolean relatedFieldsLoaded = false;
0058:            protected List primaryFields = null;
0059:            protected List relatedFields = null;
0060:            protected String reportId = null;
0061:            protected String sectionId = null;
0062:            protected String partyId = null;
0063:            protected String reportName = null;
0064:            protected String publicFlag = null;
0065:
0066:            protected List reportFields = null;
0067:            protected List reportCriteria = null;
0068:            protected List reportOrderBy = null;
0069:
0070:            private List selectFieldLabels = null;
0071:            private List selectFieldNames = null;
0072:            protected GenericDelegator delegator = null;
0073:            protected QueryInfo queryInfo = null;
0074:            protected GenericEventProcessor eventProcessor = null;
0075:
0076:            public UIReport(GenericDelegator delegator_) {
0077:                setDelegator(delegator_);
0078:            }
0079:
0080:            public UIReport(String reportId_, GenericDelegator delegator_) {
0081:                setDelegator(delegator_);
0082:                loadReport(reportId_);
0083:            }
0084:
0085:            public void loadReport(String reportId_) {
0086:                try {
0087:                    GenericValue reportGV = delegator.findByPrimaryKey(
0088:                            "UiReport", UtilMisc.toMap("reportId", reportId_));
0089:                    if (reportGV == null)
0090:                        throw new IllegalArgumentException(
0091:                                "Unable to find report with ID " + reportId_);
0092:
0093:                    setReportId(reportId_);
0094:                    setSectionId(reportGV.getString("sectionId"));
0095:                    setPartyId(reportGV.getString("partyId"));
0096:                    setReportName(reportGV.getString("reportName"));
0097:                    setPublicFlag(reportGV.getString("publicFlag"));
0098:
0099:                    List reportFieldsGVL = delegator.findByAnd("UiReportField",
0100:                            UtilMisc.toMap("reportId", reportId_), UtilMisc
0101:                                    .toList("displayOrder"));
0102:                    setReportFields(UIReportField.loadFromGVL(reportFieldsGVL));
0103:
0104:                    List reportCriteriaGVL = delegator.findByAnd(
0105:                            "UiReportCriteria", UtilMisc.toMap("reportId",
0106:                                    reportId_), null);
0107:                    setReportCriteria(UIReportCriteria
0108:                            .loadFromGVL(reportCriteriaGVL));
0109:
0110:                    List reportOrderByGVL = delegator.findByAnd(
0111:                            "UiReportOrderBy", UtilMisc.toMap("reportId",
0112:                                    reportId_), UtilMisc.toList("sortOrder"));
0113:                    setReportOrderBy(UIReportOrderBy
0114:                            .loadFromGVL(reportOrderByGVL));
0115:
0116:                } catch (GenericEntityException e) {
0117:                    Debug.logError("Error getting report: " + e.getMessage(),
0118:                            module);
0119:                    e.printStackTrace();
0120:                }
0121:            }
0122:
0123:            public void saveReport(String partyId, String reportName) {
0124:                setPartyId(partyId);
0125:
0126:                if (!reportName.equals(getReportName())) {
0127:                    setReportName(reportName);
0128:                    setReportId(null);
0129:                }
0130:
0131:                saveReport();
0132:            }
0133:
0134:            public void saveReport() {
0135:                try {
0136:                    String reportId = getReportId();
0137:
0138:                    if (reportId == null) {
0139:                        reportId = GenericReplicator.getNextSeqId("UiReport",
0140:                                delegator);
0141:                        setReportId(reportId);
0142:                    } else {
0143:                        // TODO need to delete old report info
0144:                    }
0145:
0146:                    List valuesToStore = new ArrayList();
0147:
0148:                    GenericValue reportGV = new GenericValue(delegator
0149:                            .getModelEntity("UiReport"));
0150:                    reportGV.setDelegator(delegator);
0151:                    reportGV.set("reportId", reportId);
0152:                    reportGV.set("sectionId", getSectionId());
0153:                    reportGV.set("partyId", getPartyId());
0154:                    reportGV.set("reportName", getReportName());
0155:                    reportGV.set("publicFlag", getPublicFlag());
0156:
0157:                    valuesToStore.add(reportGV);
0158:
0159:                    Iterator iter = reportFields.iterator();
0160:                    while (iter.hasNext()) {
0161:                        UIReportField rf = (UIReportField) iter.next();
0162:
0163:                        GenericValue gv = new GenericValue(delegator
0164:                                .getModelEntity("UiReportField"));
0165:                        gv.setDelegator(delegator);
0166:                        gv.set("reportFieldId", GenericReplicator.getNextSeqId(
0167:                                "UiReportField", delegator));
0168:                        gv.set("reportId", reportId);
0169:                        gv.set("attributeId", rf.getAttributeId());
0170:                        gv.set("displayTypeId", rf.getDisplayTypeId());
0171:                        gv.set("displayObjectId", rf.getDisplayObjectId());
0172:                        gv.set("groupBy", rf.getGroupBy());
0173:                        gv.set("displayOrder",
0174:                                new Integer(rf.getDisplayOrder()));
0175:                        gv.set("sqlFunction", rf.getSqlFunction());
0176:                        gv.set("displayLabel", rf.getDisplayLabel());
0177:
0178:                        valuesToStore.add(gv);
0179:                    }
0180:
0181:                    iter = reportCriteria.iterator();
0182:                    while (iter.hasNext()) {
0183:                        UIReportCriteria rc = (UIReportCriteria) iter.next();
0184:
0185:                        GenericValue gv = new GenericValue(delegator
0186:                                .getModelEntity("UiReportCriteria"));
0187:                        gv.setDelegator(delegator);
0188:                        gv.set("reportCriteriaId", GenericReplicator
0189:                                .getNextSeqId("UiReportCriteria", delegator));
0190:                        gv.set("reportId", reportId);
0191:                        gv.set("attributeId", rc.getAttributeId());
0192:                        gv.set("displayTypeId", rc.getDisplayTypeId());
0193:                        gv.set("displayObjectId", rc.getDisplayObjectId());
0194:                        gv.set("queryOperatorId", rc.getQueryOperatorId());
0195:                        gv.set("attributeValue", rc.getAttributeValue());
0196:                        gv.set("displayLabel", rc.getDisplayLabel());
0197:
0198:                        valuesToStore.add(gv);
0199:                    }
0200:
0201:                    iter = reportOrderBy.iterator();
0202:                    while (iter.hasNext()) {
0203:                        UIReportOrderBy ro = (UIReportOrderBy) iter.next();
0204:
0205:                        GenericValue gv = new GenericValue(delegator
0206:                                .getModelEntity("UiReportOrderBy"));
0207:                        gv.setDelegator(delegator);
0208:                        gv.set("reportOrderId", GenericReplicator.getNextSeqId(
0209:                                "UiReportOrderBy", delegator));
0210:                        gv.set("reportId", reportId);
0211:                        gv.set("attributeId", ro.getAttributeId());
0212:                        gv.set("sortOrder", new Integer(ro.getSortOrder()));
0213:                        gv.set("displayLabel", ro.getDisplayLabel());
0214:
0215:                        valuesToStore.add(gv);
0216:                    }
0217:
0218:                    delegator.storeAll(valuesToStore);
0219:                } catch (GenericEntityException e) {
0220:                    e.printStackTrace();
0221:                    Debug.logError("error saving report" + e.getMessage(),
0222:                            module);
0223:                }
0224:            }
0225:
0226:            public static boolean deleteReport(String reportId,
0227:                    GenericDelegator delegator) {
0228:                try {
0229:                    List valuesToBeRemoved = new ArrayList();
0230:
0231:                    GenericValue gv = new GenericValue(delegator
0232:                            .getModelEntity("UiReportCriteria"));
0233:                    gv.set("reportId", reportId);
0234:                    valuesToBeRemoved.add(gv);
0235:
0236:                    gv = new GenericValue(delegator
0237:                            .getModelEntity("UiReportField"));
0238:                    gv.set("reportId", reportId);
0239:                    valuesToBeRemoved.add(gv);
0240:
0241:                    gv = new GenericValue(delegator
0242:                            .getModelEntity("UiReportOrderBy"));
0243:                    gv.set("reportId", reportId);
0244:                    valuesToBeRemoved.add(gv);
0245:
0246:                    gv = new GenericValue(delegator.getModelEntity("UiReport"));
0247:                    gv.set("reportId", reportId);
0248:                    valuesToBeRemoved.add(gv);
0249:
0250:                    delegator.removeAll(valuesToBeRemoved);
0251:                } catch (GenericEntityException e) {
0252:                    // TODO Auto-generated catch block
0253:                    e.printStackTrace();
0254:                    Debug.logError("unable to delete report: " + reportId
0255:                            + " error:" + e.getMessage(), module);
0256:                    return false;
0257:                }
0258:                return true;
0259:            }
0260:
0261:            public static List getReports(String companyId, String partyId,
0262:                    GenericDelegator delegator) {
0263:                return getReports(null, partyId, delegator);
0264:            }
0265:
0266:            public static List getReports(String sectionId, String companyId,
0267:                    String partyId, GenericDelegator delegator) {
0268:                try {
0269:                    Map condition = sectionId == null ? UtilMisc.toMap(
0270:                            "partyId", "-1") : UtilMisc.toMap("sectionId",
0271:                            sectionId, "partyId", "-1");
0272:                    List orderBy = UtilMisc.toList("reportName");
0273:
0274:                    List reportList = delegator.findByAnd("UiReport",
0275:                            condition, orderBy);
0276:                    if (!partyId.equals("-1")) {
0277:
0278:                        condition = sectionId == null ? UtilMisc.toMap(
0279:                                "partyId", partyId) : UtilMisc.toMap(
0280:                                "sectionId", sectionId, "partyId", partyId);
0281:
0282:                        EntityCondition c1 = new EntityConditionList(
0283:                                UtilMisc
0284:                                        .toList(
0285:                                                new EntityExpr("partyId",
0286:                                                        EntityOperator.EQUALS,
0287:                                                        partyId),
0288:                                                new EntityConditionList(
0289:                                                        UtilMisc
0290:                                                                .toList(
0291:                                                                        new EntityExpr(
0292:                                                                                "partyId",
0293:                                                                                EntityOperator.EQUALS,
0294:                                                                                companyId),
0295:                                                                        new EntityExpr(
0296:                                                                                "publicFlag",
0297:                                                                                EntityOperator.EQUALS,
0298:                                                                                "Y")),
0299:                                                        EntityOperator.AND)),
0300:                                EntityOperator.OR);
0301:                        if (sectionId != null)
0302:                            c1 = new EntityConditionList(UtilMisc.toList(c1,
0303:                                    new EntityExpr("sectionId",
0304:                                            EntityOperator.EQUALS, sectionId)),
0305:                                    EntityOperator.AND);
0306:
0307:                        if (reportList == null)
0308:                            reportList = delegator.findByCondition("UiReport",
0309:                                    c1, null, orderBy);
0310:                        else
0311:                            reportList.addAll(delegator.findByCondition(
0312:                                    "UiReport", c1, null, orderBy));
0313:                    }
0314:
0315:                    return reportList;
0316:                } catch (GenericEntityException e) {
0317:                    Debug.logError("Error getting reportList: "
0318:                            + e.getMessage(), module);
0319:                    e.printStackTrace();
0320:                }
0321:                return null;
0322:            }
0323:
0324:            public static List getAvailableReportScreens(
0325:                    GenericDelegator delegator) {
0326:                try {
0327:                    List availableScreens = delegator.findByAnd("UiScreen",
0328:                            UtilMisc.toMap("allowReporting", "Y"), UtilMisc
0329:                                    .toList("screenName"));
0330:
0331:                    return availableScreens;
0332:                } catch (GenericEntityException e) {
0333:                    Debug.logError(
0334:                            "Error getting availabel report section List: "
0335:                                    + e.getMessage(), module);
0336:                    e.printStackTrace();
0337:                }
0338:                return null;
0339:            }
0340:
0341:            public List loadPrimarySectionFields() {
0342:                try {
0343:                    List primaryFields = getDelegator().findByAnd(
0344:                            "UiScreenSectionFields",
0345:                            UtilMisc.toMap("sectionId", getSectionId()),
0346:                            UtilMisc.toList("displayOrder"));
0347:
0348:                    setPrimaryFields(primaryFields);
0349:                    return primaryFields;
0350:                } catch (GenericEntityException e) {
0351:                    Debug.logError("Unable to get Primary Screen Fields:"
0352:                            + e.getMessage(), module);
0353:                    return null;
0354:                }
0355:            }
0356:
0357:            public List loadRelatedSectionQueryFields() {
0358:                try {
0359:                    List relatedFields = getDelegator()
0360:                            .findByAnd(
0361:                                    "UiRelatedSectionQueryFields",
0362:                                    UtilMisc.toMap("sectionId", getSectionId(),
0363:                                            "useInAdvancedQueries", "Y",
0364:                                            "isSearchable", "Y"),
0365:                                    UtilMisc.toList("relatedSectionId",
0366:                                            "displayOrder"));
0367:                    setRelatedFields(relatedFields);
0368:                    return relatedFields;
0369:                } catch (GenericEntityException e) {
0370:                    Debug.logError("Unable to get Related Screen Fields:"
0371:                            + e.getMessage(), module);
0372:                    return null;
0373:                }
0374:            }
0375:
0376:            public String getOrderBySelectedOptions() {
0377:                List fieldList = getReportOrderBy();
0378:                if (fieldList == null)
0379:                    return "";
0380:
0381:                StringBuffer displayHtml = new StringBuffer(5000);
0382:                int fieldListSize = fieldList.size();
0383:
0384:                for (int fieldNbr = 0; fieldNbr < fieldListSize; fieldNbr++) {
0385:                    UIReportOrderBy fieldInfo = (UIReportOrderBy) fieldList
0386:                            .get(fieldNbr);
0387:
0388:                    String htmlName = UIWebUtility.getHtmlName("REPORT",
0389:                            fieldInfo.getEntityName(), fieldInfo
0390:                                    .getAttributeName(), 0);
0391:                    String attributeId = fieldInfo.getAttributeId();
0392:                    String displayLabel = fieldInfo.getDisplayLabel();
0393:                    String optValue = htmlName + ";" + attributeId + ";"
0394:                            + "NONE" + ";" + "NONE" + ";" + displayLabel;
0395:                    displayHtml.append("<option value='" + optValue + "'>"
0396:                            + displayLabel + "</option>");
0397:                }
0398:                return displayHtml.toString();
0399:            }
0400:
0401:            public String getSelectListSelectedOptions() {
0402:                List fieldList = getReportFields();
0403:                if (fieldList == null)
0404:                    return "";
0405:
0406:                StringBuffer displayHtml = new StringBuffer(5000);
0407:                int fieldListSize = fieldList.size();
0408:
0409:                for (int fieldNbr = 0; fieldNbr < fieldListSize; fieldNbr++) {
0410:                    UIReportField fieldInfo = (UIReportField) fieldList
0411:                            .get(fieldNbr);
0412:
0413:                    String htmlName = UIWebUtility.getHtmlName("REPORT",
0414:                            fieldInfo.getEntityName(), fieldInfo
0415:                                    .getAttributeName(), 0);
0416:                    String displayObjectId = fieldInfo.getDisplayObjectId();
0417:                    String displayTypeId = fieldInfo.getDisplayTypeId();
0418:                    String attributeId = fieldInfo.getAttributeId();
0419:                    String displayLabel = fieldInfo.getDisplayLabel();
0420:                    String optValue = htmlName + ";" + attributeId + ";"
0421:                            + displayTypeId + ";" + displayObjectId + ";"
0422:                            + displayLabel;
0423:                    displayHtml.append("<option value='" + optValue + "'>"
0424:                            + displayLabel + "</option>");
0425:                }
0426:                return displayHtml.toString();
0427:            }
0428:
0429:            public String getSelectListAvailableOptions() {
0430:                if (sectionId == null)
0431:                    throw new IllegalArgumentException(
0432:                            "section ID must be set before calling getConditionHtml");
0433:
0434:                StringBuffer displayHtml = new StringBuffer(5000);
0435:                List fieldList = getPrimaryFields();
0436:                int fieldListSize = fieldList.size();
0437:
0438:                StringBuffer fieldNameOptions = new StringBuffer(200);
0439:                //		fieldNameOptions.append("<option value=''></option>");
0440:                for (int fieldNbr = 0; fieldNbr < fieldListSize; fieldNbr++) {
0441:                    GenericValue fieldInfo = (GenericValue) fieldList
0442:                            .get(fieldNbr);
0443:                    String isVisible = UtilFormatOut.checkNull(fieldInfo
0444:                            .getString("isVisible"));
0445:                    if (isVisible.equals("Y")) {
0446:                        String htmlName = UIWebUtility.getHtmlName(fieldInfo
0447:                                .getString("sectionName"), fieldInfo
0448:                                .getString("entityName"), fieldInfo
0449:                                .getString("attributeName"), 0);
0450:                        String displayObjectId = fieldInfo
0451:                                .getString("displayObjectId");
0452:                        String displayTypeId = fieldInfo
0453:                                .getString("displayTypeId");
0454:                        String attributeId = fieldInfo.getString("attributeId");
0455:                        String displayLabel = fieldInfo
0456:                                .getString("displayLabel");
0457:                        String optValue = htmlName + ";" + attributeId + ";"
0458:                                + displayTypeId + ";" + displayObjectId + ";"
0459:                                + displayLabel;
0460:                        fieldNameOptions.append("<option value='" + optValue
0461:                                + "'>" + displayLabel + "</option>");
0462:                    }
0463:
0464:                }
0465:
0466:                List extendedFields = getRelatedFields();
0467:                if (extendedFields != null) {
0468:                    int numFields = extendedFields.size();
0469:                    for (int i = 0; i < numFields; i++) {
0470:                        GenericValue fieldInfo = (GenericValue) extendedFields
0471:                                .get(i);
0472:                        String entityName = fieldInfo.getString("entityName");
0473:                        String attributeId = fieldInfo.getString("attributeId");
0474:                        String attributeName = fieldInfo
0475:                                .getString("attributeName");
0476:                        String displayObjectId = fieldInfo
0477:                                .getString("displayObjectId");
0478:                        String displayTypeId = fieldInfo
0479:                                .getString("displayTypeId");
0480:                        String sectionName = fieldInfo.getString("sectionName");
0481:                        String sectionDescription = fieldInfo
0482:                                .getString("sectionDescription");
0483:                        String displayLabel = fieldInfo
0484:                                .getString("displayLabel");
0485:                        String htmlName = UIWebUtility.getHtmlName(sectionName,
0486:                                entityName, attributeName, 0);
0487:                        String optValue = htmlName + ";" + attributeId + ";"
0488:                                + displayTypeId + ";" + displayObjectId + ";"
0489:                                + displayLabel;
0490:                        displayLabel = sectionDescription + "." + displayLabel;
0491:                        fieldNameOptions.append("<option value='" + optValue
0492:                                + "'>" + displayLabel + "</option>");
0493:                    }
0494:                }
0495:
0496:                return fieldNameOptions.toString();
0497:            }
0498:
0499:            public String getConditionHtml() {
0500:                if (sectionId == null)
0501:                    throw new IllegalArgumentException(
0502:                            "section ID must be set before calling getConditionHtml");
0503:
0504:                StringBuffer displayHtml = new StringBuffer(5000);
0505:                List fieldList = getPrimaryFields();
0506:                int fieldListSize = fieldList.size();
0507:
0508:                StringBuffer fieldNameOptions = new StringBuffer(200);
0509:                fieldNameOptions.append("<option value=''></option>");
0510:                for (int fieldNbr = 0; fieldNbr < fieldListSize; fieldNbr++) {
0511:                    GenericValue fieldInfo = (GenericValue) fieldList
0512:                            .get(fieldNbr);
0513:                    String isSearchable = UtilFormatOut.checkNull(fieldInfo
0514:                            .getString("isSearchable"));
0515:                    if (isSearchable.equals("Y")) {
0516:                        String htmlName = UIWebUtility.getHtmlName(fieldInfo
0517:                                .getString("sectionName"), fieldInfo
0518:                                .getString("entityName"), fieldInfo
0519:                                .getString("attributeName"), 0);
0520:                        String displayObjectId = fieldInfo
0521:                                .getString("displayObjectId");
0522:                        String displayTypeId = fieldInfo
0523:                                .getString("displayTypeId");
0524:                        String attributeId = fieldInfo.getString("attributeId");
0525:                        String optValue = htmlName + ";" + attributeId + ";"
0526:                                + displayTypeId + ";" + displayObjectId + ";"
0527:                                + fieldInfo.getString("displayLabel");
0528:                        fieldNameOptions.append("<option value='" + optValue
0529:                                + "'>" + fieldInfo.getString("displayLabel")
0530:                                + "</option>");
0531:                    }
0532:
0533:                }
0534:
0535:                List extendedFields = getRelatedFields();
0536:                if (extendedFields != null) {
0537:                    int numFields = extendedFields.size();
0538:                    for (int i = 0; i < numFields; i++) {
0539:                        GenericValue fieldInfo = (GenericValue) extendedFields
0540:                                .get(i);
0541:                        String entityName = fieldInfo.getString("entityName");
0542:                        String attributeId = fieldInfo.getString("attributeId");
0543:                        String attributeName = fieldInfo
0544:                                .getString("attributeName");
0545:                        String displayObjectId = fieldInfo
0546:                                .getString("displayObjectId");
0547:                        String displayTypeId = fieldInfo
0548:                                .getString("displayTypeId");
0549:                        String sectionName = fieldInfo.getString("sectionName");
0550:                        String sectionDescription = fieldInfo
0551:                                .getString("sectionDescription");
0552:                        String displayLabel = fieldInfo
0553:                                .getString("displayLabel");
0554:                        String htmlName = UIWebUtility.getHtmlName(sectionName,
0555:                                entityName, attributeName, 0);
0556:                        String optValue = htmlName + ";" + attributeId + ";"
0557:                                + displayTypeId + ";" + displayObjectId + ";"
0558:                                + displayLabel;
0559:                        displayLabel = sectionDescription + "." + displayLabel;
0560:                        fieldNameOptions.append("<option value='" + optValue
0561:                                + "'>" + displayLabel + "</option>");
0562:                    }
0563:                }
0564:
0565:                StringBuffer conditionOptions = new StringBuffer(100);
0566:                conditionOptions.append("<option value='equals'>=</option>");
0567:                conditionOptions
0568:                        .append("<option value='like'>CONTAINS</option>");
0569:                conditionOptions
0570:                        .append("<option value='startsWith'>STARTS WITH</option>");
0571:                conditionOptions
0572:                        .append("<option value='endsWith'>ENDS WITH</option>");
0573:                conditionOptions.append("<option value='equals'>=</option>");
0574:                conditionOptions
0575:                        .append("<option value='notEqual'>NOT EQUAL</option>");
0576:                conditionOptions
0577:                        .append("<option value='lessThan'>&lt;</option>");
0578:                conditionOptions
0579:                        .append("<option value='greaterThan'>&gt;</option>");
0580:                conditionOptions
0581:                        .append("<option value='lessThanEqualTo'>&lt;=</option>");
0582:                conditionOptions
0583:                        .append("<option value='greaterThanEqualTo'>&gt;=</option>");
0584:                conditionOptions.append("<option value='in'>IN</option>");
0585:                conditionOptions
0586:                        .append("<option value='not-in'>NOT IN</option>");
0587:                conditionOptions
0588:                        .append("<option value='between'>BETWEEN</option>");
0589:
0590:                displayHtml.append("<table id='queryListTable' border=1>\n");
0591:                displayHtml
0592:                        .append("<tr><td>Field</td><td>Condition</td><td>Value</td><td>Action</td></tr>\n");
0593:
0594:                List reportConditions = getReportCriteria();
0595:                int numExistingConditions = 0;
0596:                if (reportConditions != null) {
0597:                    Iterator rcIter = reportConditions.iterator();
0598:                    while (rcIter.hasNext()) {
0599:                        UIReportCriteria rc = (UIReportCriteria) rcIter.next();
0600:                        numExistingConditions++;
0601:                        int i = numExistingConditions;
0602:                        String htmlName = UIWebUtility.getHtmlName("REPORT", rc
0603:                                .getEntityName(), rc.getAttributeName(), 0);
0604:                        String optValue = htmlName + ";" + rc.getAttributeId()
0605:                                + ";" + rc.getDisplayTypeId() + ";"
0606:                                + rc.getDisplayObjectId() + ";"
0607:                                + rc.getDisplayLabel();
0608:                        displayHtml.append("<tr id=queryListRow" + i
0609:                                + "><td><input type=hidden name=queryListField"
0610:                                + i + " value='" + optValue + "'>"
0611:                                + rc.getDisplayLabel() + "</td>\n");
0612:                        displayHtml
0613:                                .append("	<td><input type=hidden name=queryListOperator"
0614:                                        + i
0615:                                        + " value='"
0616:                                        + rc.getQueryOperatorId()
0617:                                        + "'>"
0618:                                        + rc.getQueryOperatorId() + "</td>\n");
0619:                        displayHtml
0620:                                .append("	<td><input type=hidden name=queryListValue"
0621:                                        + i
0622:                                        + " size=30 value='"
0623:                                        + rc.getAttributeValue()
0624:                                        + "'>"
0625:                                        + rc.getAttributeValue() + "</td>\n");
0626:                        displayHtml
0627:                                .append("	<td><img src=/sfaimages/remove.gif alt=Del onClick=delConditionRow("
0628:                                        + i + ")>\n");
0629:                        displayHtml
0630:                                .append("	    <img src=/sfaimages/add.gif alt=Add onClick=addConditionRow("
0631:                                        + i + ")></td>\n");
0632:                        displayHtml.append("</tr>");
0633:
0634:                    }
0635:                }
0636:
0637:                int startRow = numExistingConditions + 1;
0638:                int endRow = Math.max(startRow + 2, 5);
0639:                // default show 4 rows
0640:                for (int i = startRow; i < endRow; i++) {
0641:                    displayHtml.append("<tr id=queryListRow" + i
0642:                            + "><td><select name=queryListField" + i + ">"
0643:                            + fieldNameOptions.toString() + "</select></td>\n");
0644:                    displayHtml.append("	<td><select name=queryListOperator"
0645:                            + i + ">" + conditionOptions.toString()
0646:                            + "</select></td>\n");
0647:                    displayHtml.append("	<td><input name=queryListValue" + i
0648:                            + " size=30></td>\n");
0649:                    displayHtml
0650:                            .append("	<td><img src=/sfaimages/remove.gif alt=Del onClick=delConditionRow("
0651:                                    + i + ")>\n");
0652:                    displayHtml
0653:                            .append("	    <img src=/sfaimages/add.gif alt=Add onClick=addConditionRow("
0654:                                    + i + ")></td>\n");
0655:                    displayHtml.append("</tr>");
0656:
0657:                }
0658:
0659:                displayHtml.append("</table>\n");
0660:                displayHtml
0661:                        .append("<input type=hidden id=queryListMaxRows name=queryListMaxRows value=4>\n");
0662:
0663:                displayHtml.append("<script type='text/javascript'>\n");
0664:                displayHtml.append("function addConditionRow(i) {\n");
0665:                displayHtml
0666:                        .append("	var tab1=document.getElementById('queryListTable')\n");
0667:                displayHtml.append("	if ( tab1 ) {\n");
0668:                displayHtml.append("		var numRows = tab1.rows.length\n");
0669:                displayHtml.append("		var maxRows = 10\n");
0670:                displayHtml.append("		if ( numRows > maxRows )\n");
0671:                displayHtml
0672:                        .append("			alert(\"Can't have more than 10 conditions\");\n");
0673:                displayHtml.append("		else {\n");
0674:                displayHtml.append("			var x = tab1.insertRow(numRows)\n");
0675:                displayHtml
0676:                        .append("			var maxRows = document.getElementById('queryListMaxRows')\n");
0677:                displayHtml.append("			var newRow = maxRows.value -  -1\n");
0678:                displayHtml.append("			maxRows.value = newRow\n");
0679:                displayHtml.append("			x.id = \"queryListRow\" + newRow\n");
0680:                displayHtml.append("			var c1=x.insertCell(0)\n");
0681:                displayHtml.append("			var c2=x.insertCell(1)\n");
0682:                displayHtml.append("			var c3=x.insertCell(2)\n");
0683:                displayHtml.append("			var c4=x.insertCell(3)\n");
0684:                displayHtml
0685:                        .append("			c1.innerHTML=\"<select name=queryListField\" + newRow + \">"
0686:                                + fieldNameOptions.toString() + "</select>\"\n");
0687:                displayHtml
0688:                        .append("			c2.innerHTML=\"<select name=queryListOperator\" + newRow + \">"
0689:                                + conditionOptions.toString() + "</select>\"\n");
0690:                displayHtml
0691:                        .append("			c3.innerHTML=\"<input name=queryListValue\" + newRow + \" size=30>\"\n");
0692:                displayHtml
0693:                        .append("			c4.innerHTML=\"<img src=/sfaimages/remove.gif alt=Del onClick=delConditionRow(\" + newRow + \")>\" + \" <img src=/sfaimages/add.gif alt=Add onClick=addConditionRow(\" + newRow + \")>\"\n");
0694:
0695:                displayHtml.append("		}\n");
0696:                displayHtml.append("		fixSize()\n");
0697:                displayHtml.append("	}\n");
0698:                displayHtml.append("}\n");
0699:
0700:                displayHtml.append("function delConditionRow(i)\n");
0701:                displayHtml.append("{\n");
0702:                displayHtml
0703:                        .append("	var row1 = document.getElementById('queryListRow' + i)\n");
0704:                displayHtml
0705:                        .append("	var tab = document.getElementById('queryListTable')\n");
0706:                displayHtml.append("	var rows = tab.rows\n");
0707:                displayHtml.append("	if ( rows.length == 2 ) {\n");
0708:                displayHtml.append("		event.returnValue = false\n");
0709:                displayHtml.append("		return;\n");
0710:                displayHtml.append("	}\n");
0711:                displayHtml.append("	for ( i=0; i < rows.length; i++ ) {\n");
0712:                displayHtml.append("		row = rows[i];\n");
0713:                displayHtml.append("		if ( row.id == row1.id) {\n");
0714:                displayHtml.append("			tab.deleteRow(i);\n");
0715:                displayHtml.append("			break;\n");
0716:                displayHtml.append("		}\n");
0717:                displayHtml.append("	}\n");
0718:                displayHtml.append("	fixSize()\n");
0719:                displayHtml.append("}\n");
0720:
0721:                displayHtml.append("</script>\n");
0722:
0723:                return displayHtml.toString();
0724:            }
0725:
0726:            public boolean loadQueryInfo(HttpServletRequest request,
0727:                    HttpServletResponse response, UICache uiCache) {
0728:
0729:                try {
0730:                    List primaryFields = loadPrimarySectionFields();
0731:                    List relatedQueryFields = loadRelatedSectionQueryFields();
0732:
0733:                    List uiScreenSectionEntityGVL = delegator.findByAnd(
0734:                            "UiScreenSectionEntity", UtilMisc.toMap(
0735:                                    "sectionId", sectionId), UtilMisc
0736:                                    .toList("retrieveOrder"));
0737:
0738:                    UIScreenSectionEntity primaryEntity = new UIScreenSectionEntity(
0739:                            (GenericValue) uiScreenSectionEntityGVL.get(0),
0740:                            delegator, uiCache);
0741:                    GenericValue screenSectionGV = delegator.findByPrimaryKey(
0742:                            "UiScreenSection", UtilMisc.toMap("sectionId",
0743:                                    sectionId));
0744:                    String eventProcessorClass = screenSectionGV
0745:                            .getString("eventProcessorClass");
0746:                    eventProcessor = UIUtility
0747:                            .getEventProcessor(eventProcessorClass);
0748:
0749:                    String primaryEntityName = primaryEntity.getUiEntity()
0750:                            .getEntityName();
0751:                    String searchAttribValue = "";
0752:                    String searchEntityName = "";
0753:                    String searchAttribName = "";
0754:                    EntityComparisonOperator entityOperator = null;
0755:                    List relatedSearchClauses = new LinkedList();
0756:                    List selectFields = new ArrayList();
0757:                    List selectFieldLabels = new ArrayList();
0758:                    List sortFields = new ArrayList();
0759:
0760:                    List reportFields = new ArrayList();
0761:                    List reportCriteria = new ArrayList();
0762:                    List reportOrderBy = new ArrayList();
0763:
0764:                    ModelEntity primaryME = primaryEntity.getUiEntity()
0765:                            .getModelEntity();
0766:                    List primaryPkFieldNames = primaryEntity.getUiEntity()
0767:                            .getPrimaryKeyFieldNames();
0768:
0769:                    queryInfo = new QueryInfo(delegator, primaryEntityName);
0770:
0771:                    HashMap joinedEntities = new HashMap();
0772:
0773:                    joinedEntities.put(primaryEntityName, "Y");
0774:
0775:                    // Find the main entity(ies) by building a WHERE clause using LIKE and AND, with one or more tables in the FROM clause.
0776:                    // First join all secondary screen section entities in the WHERE and FROM clauses in case
0777:                    // we are going to use query values from them.
0778:                    Iterator uiScreenSectionEntityI = uiScreenSectionEntityGVL
0779:                            .iterator();
0780:
0781:                    uiScreenSectionEntityI.next(); // Pass up the primary entity.
0782:
0783:                    while (uiScreenSectionEntityI.hasNext()) {
0784:                        GenericValue entityGV = (GenericValue) uiScreenSectionEntityI
0785:                                .next();
0786:                        UIScreenSectionEntity uiScreenSectionEntity = new UIScreenSectionEntity(
0787:                                entityGV, delegator, uiCache);
0788:                        String relationTitle = uiScreenSectionEntity
0789:                                .getRelationTitle();
0790:                        String relatedEntityName = uiScreenSectionEntity
0791:                                .getUiEntity().getEntityName();
0792:                        String relatedAndFields = uiScreenSectionEntity
0793:                                .getRelationByAndFields();
0794:                        boolean isOuterJoin = uiScreenSectionEntity
0795:                                .getIsOuterJoined();
0796:
0797:                        eventProcessor.addOneRelationClause(delegator,
0798:                                relationTitle, relatedAndFields,
0799:                                relatedEntityName, primaryEntityName,
0800:                                primaryME, isOuterJoin, queryInfo);
0801:
0802:                        joinedEntities.put(relatedEntityName, "Y");
0803:                    }
0804:
0805:                    String queryListMaxRows = request
0806:                            .getParameter("queryListMaxRows");
0807:                    // if queryListMaxRows is set, then we are using advanced query mode
0808:                    if ((queryListMaxRows != null)
0809:                            && (queryListMaxRows.length() > 0)) {
0810:                        int maxRows = Integer.valueOf(queryListMaxRows)
0811:                                .intValue();
0812:                        for (int i = 1; i <= maxRows; i++) {
0813:                            String qlFieldInfo = request
0814:                                    .getParameter("queryListField" + i);
0815:                            if ((qlFieldInfo != null)
0816:                                    && (qlFieldInfo.length() > 0)) {
0817:                                StringTokenizer tokSemi = new StringTokenizer(
0818:                                        qlFieldInfo, ";");
0819:                                String qlFieldName = "";
0820:                                String qlAttributeId = "";
0821:                                String qlDisplayObjectId = "";
0822:                                String qlDisplayTypeId = "";
0823:                                String qlDisplayLabel = "";
0824:
0825:                                if (tokSemi.countTokens() == 5) {
0826:                                    qlFieldName = tokSemi.nextToken();
0827:                                    qlAttributeId = tokSemi.nextToken();
0828:                                    qlDisplayTypeId = tokSemi.nextToken();
0829:                                    qlDisplayObjectId = tokSemi.nextToken();
0830:                                    qlDisplayLabel = tokSemi.nextToken();
0831:                                } else {
0832:                                    qlFieldName = qlFieldInfo;
0833:                                }
0834:
0835:                                String qlOperator = request
0836:                                        .getParameter("queryListOperator" + i);
0837:                                String qlValue = request
0838:                                        .getParameter("queryListValue" + i);
0839:
0840:                                reportCriteria.add(new UIReportCriteria(
0841:                                        qlAttributeId, qlDisplayTypeId,
0842:                                        qlDisplayObjectId, qlOperator, qlValue,
0843:                                        qlDisplayLabel));
0844:
0845:                                if (qlOperator.equals("like"))
0846:                                    qlValue = "%" + qlValue.replace('*', '%')
0847:                                            + "%";
0848:                                else if (qlOperator.equals("startsWith")) {
0849:                                    qlValue = qlValue.replace('*', '%') + "%";
0850:                                    qlOperator = "like";
0851:                                } else if (qlOperator.equals("endsWith")) {
0852:                                    qlValue = "%" + qlValue.replace('*', '%');
0853:                                    qlOperator = "like";
0854:                                }
0855:
0856:                                searchEntityName = UIWebUtility
0857:                                        .getEntityFromParamName(qlFieldName);
0858:
0859:                                String hasJoin = (String) joinedEntities
0860:                                        .get(searchEntityName);
0861:
0862:                                if ((hasJoin == null) || (!hasJoin.equals("Y"))) {
0863:                                    eventProcessor.addOneRelationClause(
0864:                                            delegator, "", "",
0865:                                            searchEntityName,
0866:                                            primaryEntityName, primaryME,
0867:                                            false, queryInfo);
0868:
0869:                                    joinedEntities.put(searchEntityName, "Y");
0870:                                }
0871:
0872:                                if ((searchEntityName == null)
0873:                                        || searchEntityName.equals("")) {
0874:                                    searchEntityName = primaryEntityName;
0875:                                }
0876:
0877:                                searchAttribName = UIWebUtility
0878:                                        .getAttribFromParamName(qlFieldName);
0879:                                entityOperator = EntityOperator
0880:                                        .lookupComparison(qlOperator);
0881:                                Object searchValue = qlValue;
0882:
0883:                                // If this is a set operator, convert the String param into a comma separated List 
0884:                                if ((entityOperator.equals(EntityOperator.IN))
0885:                                        || (entityOperator
0886:                                                .equals(EntityOperator.NOT_IN))
0887:                                        || (entityOperator
0888:                                                .equals(EntityOperator.BETWEEN))) {
0889:                                    List valueList = new ArrayList();
0890:                                    StringTokenizer tokComma = new StringTokenizer(
0891:                                            qlValue, ",");
0892:
0893:                                    while (tokComma.hasMoreTokens()) {
0894:                                        String valueItem = tokComma.nextToken();
0895:                                        valueList.add(valueItem);
0896:                                    }
0897:                                    searchValue = valueList;
0898:                                }
0899:
0900:                                // Figure out the attribute ID for the UiAttribute this parameter corresponds to so we can
0901:                                // save the query.
0902:                                String attributeId = qlAttributeId;
0903:
0904:                                // Generate an entry in the WHERE clause for this attribute.  The entityOperator
0905:                                // is returned in case appendEntityClause changes it.
0906:                                // NOTE:  changes here must also be applied to UIQuery.appendEntityClauses() to work with saved queries
0907:                                //
0908:                                if (qlDisplayTypeId
0909:                                        .equals(UIDisplayObject.DISPLAY_TYPE_SELECT)
0910:                                        || qlDisplayTypeId
0911:                                                .equals(UIDisplayObject.DISPLAY_TYPE_SEARCH_TEXT)) {
0912:                                    String aliasName = searchEntityName
0913:                                            + searchAttribName + "srch";
0914:                                    UIUtility.addSelectSearch(queryInfo,
0915:                                            qlDisplayObjectId,
0916:                                            searchEntityName, searchAttribName,
0917:                                            aliasName, entityOperator,
0918:                                            searchValue);
0919:                                } else {
0920:                                    if (searchValue instanceof  String) {
0921:                                        entityOperator = EventUtility
0922:                                                .appendEntityClause(
0923:                                                        searchEntityName,
0924:                                                        searchAttribName,
0925:                                                        (String) searchValue,
0926:                                                        entityOperator,
0927:                                                        queryInfo);
0928:                                    } else if (searchValue instanceof  Collection) {
0929:                                        entityOperator = EventUtility
0930:                                                .appendEntityClause(
0931:                                                        searchEntityName,
0932:                                                        searchAttribName,
0933:                                                        (Collection) searchValue,
0934:                                                        entityOperator,
0935:                                                        queryInfo);
0936:                                    } else
0937:                                        throw new IllegalArgumentException(
0938:                                                "Query Param must be String or Collection");
0939:                                }
0940:
0941:                            }
0942:                        }
0943:                    }
0944:
0945:                    // get select List fields
0946:                    String[] selectFieldsParam = request
0947:                            .getParameterValues("selectFields");
0948:                    if (selectFieldsParam == null)
0949:                        return false;
0950:                    for (int i = 0; i < selectFieldsParam.length; i++) {
0951:                        // Do what you need for each string:  foo[i]
0952:                        String selectField = selectFieldsParam[i];
0953:                        StringTokenizer tokSemi = new StringTokenizer(
0954:                                selectField, ";");
0955:                        String qlFieldName = "";
0956:                        String qlAttributeId = "";
0957:                        String qlDisplayObjectId = "";
0958:                        String qlDisplayTypeId = "";
0959:                        String qlDisplayLabel = "";
0960:
0961:                        if (tokSemi.countTokens() == 5) {
0962:                            qlFieldName = tokSemi.nextToken();
0963:                            qlAttributeId = tokSemi.nextToken();
0964:                            qlDisplayTypeId = tokSemi.nextToken();
0965:                            qlDisplayObjectId = tokSemi.nextToken();
0966:                            qlDisplayLabel = tokSemi.nextToken();
0967:                        } else {
0968:                            qlFieldName = selectField;
0969:                        }
0970:
0971:                        reportFields.add(new UIReportField(qlAttributeId,
0972:                                qlDisplayTypeId, qlDisplayObjectId,
0973:                                qlDisplayLabel, String.valueOf(i)));
0974:
0975:                        String entityName = UIWebUtility
0976:                                .getEntityFromParamName(qlFieldName);
0977:                        String attributeName = UIWebUtility
0978:                                .getAttribFromParamName(qlFieldName);
0979:                        String aliasName = attributeName;
0980:                        if (!entityName.equals(primaryEntityName))
0981:                            aliasName = entityName + "_" + attributeName;
0982:
0983:                        String hasJoin = (String) joinedEntities
0984:                                .get(entityName);
0985:
0986:                        if ((hasJoin == null) || (!hasJoin.equals("Y"))) {
0987:                            eventProcessor.addOneRelationClause(delegator, "",
0988:                                    "", entityName, primaryEntityName,
0989:                                    primaryME, false, queryInfo);
0990:
0991:                            joinedEntities.put(entityName, "Y");
0992:                        }
0993:
0994:                        queryInfo.checkAttribute(entityName, attributeName,
0995:                                aliasName);
0996:
0997:                        selectFields.add(aliasName);
0998:                        selectFieldLabels.add(qlDisplayLabel);
0999:                    }
1000:
1001:                    setSelectFieldNames(selectFields);
1002:                    setSelectFieldLabels(selectFieldLabels);
1003:
1004:                    queryInfo.setSelectFields(selectFields);
1005:
1006:                    //get orderBy Fields
1007:                    String[] sortFieldsParam = request
1008:                            .getParameterValues("sortFields");
1009:                    if (sortFieldsParam != null) {
1010:                        for (int i = 0; i < sortFieldsParam.length; i++) {
1011:                            // Do what you need for each string:  foo[i]
1012:                            String sortField = sortFieldsParam[i];
1013:                            StringTokenizer tokSemi = new StringTokenizer(
1014:                                    sortField, ";");
1015:                            String qlFieldName = "";
1016:                            String qlAttributeId = "";
1017:                            String qlDisplayObjectId = "";
1018:                            String qlDisplayTypeId = "";
1019:                            String qlDisplayLabel = "";
1020:
1021:                            if (tokSemi.countTokens() == 5) {
1022:                                qlFieldName = tokSemi.nextToken();
1023:                                qlAttributeId = tokSemi.nextToken();
1024:                                qlDisplayTypeId = tokSemi.nextToken();
1025:                                qlDisplayObjectId = tokSemi.nextToken();
1026:                                qlDisplayLabel = tokSemi.nextToken();
1027:                            } else {
1028:                                qlFieldName = sortField;
1029:                            }
1030:                            reportOrderBy.add(new UIReportOrderBy(
1031:                                    qlAttributeId, i, qlDisplayLabel));
1032:
1033:                            String entityName = UIWebUtility
1034:                                    .getEntityFromParamName(qlFieldName);
1035:                            String attributeName = UIWebUtility
1036:                                    .getAttribFromParamName(qlFieldName);
1037:                            String aliasName = attributeName;
1038:                            if (!entityName.equals(primaryEntityName))
1039:                                aliasName = entityName + "_" + attributeName;
1040:
1041:                            String hasJoin = (String) joinedEntities
1042:                                    .get(entityName);
1043:
1044:                            if ((hasJoin == null) || (!hasJoin.equals("Y"))) {
1045:                                eventProcessor.addOneRelationClause(delegator,
1046:                                        "", "", entityName, primaryEntityName,
1047:                                        primaryME, false, queryInfo);
1048:
1049:                                joinedEntities.put(entityName, "Y");
1050:                            }
1051:
1052:                            queryInfo.checkAttribute(entityName, attributeName,
1053:                                    aliasName);
1054:
1055:                            sortFields.add(aliasName);
1056:                        }
1057:                        queryInfo.setOrderBy(sortFields);
1058:                    }
1059:                    setReportFields(reportFields);
1060:                    setReportCriteria(reportCriteria);
1061:                    setReportOrderBy(reportOrderBy);
1062:
1063:                } catch (NumberFormatException e) {
1064:                    Debug.logError(
1065:                            "Error formatting Number: " + e.getMessage(),
1066:                            module);
1067:                    return false;
1068:                } catch (GenericEntityException e) {
1069:                    Debug.logError(
1070:                            "Error loading QueryInfo: " + e.getMessage(),
1071:                            module);
1072:                    return false;
1073:                }
1074:                return true;
1075:            }
1076:
1077:            public List runReport(UserInfo userInfo, int maxRows) {
1078:                EntityListIterator eli = null;
1079:
1080:                if (eventProcessor == null)
1081:                    eventProcessor = new GenericEventProcessor();
1082:
1083:                if (queryInfo == null)
1084:                    throw new RuntimeException(
1085:                            "You must call loadQueryInfo prior to runReport");
1086:
1087:                SecurityLinkInfo securityInfo = eventProcessor
1088:                        .getSecurityLinkInfo(userInfo, delegator);
1089:                if (securityInfo == null) {
1090:                    try {
1091:                        eli = queryInfo.getQueryIterator();
1092:                    } catch (GenericEntityException e) {
1093:                        Debug.logError("An error occurred in the "
1094:                                + "GenericDelegator.findByCondition method: "
1095:                                + e.getLocalizedMessage(), module);
1096:                    }
1097:                } else {
1098:                    try {
1099:
1100:                        eli = SecurityWrapper.findListIteratorByCondition(
1101:                                queryInfo.getPrimaryEntity(), queryInfo,
1102:                                queryInfo.getOrderBy(), userInfo, securityInfo,
1103:                                delegator);
1104:                    } catch (GenericEntityException e) {
1105:                        Debug.logError("An error occurred in the "
1106:                                + "SecurityWrapper.findByCondition method: "
1107:                                + e.getLocalizedMessage(), module);
1108:                    }
1109:                }
1110:
1111:                if (eli != null) {
1112:                    try {
1113:                        List resultGVL = eli.getPartialList(1, maxRows);
1114:
1115:                        boolean hasMoreRows = false;
1116:
1117:                        // check next value since we close the cursor anyway.  
1118:                        if ((resultGVL.size() == maxRows)
1119:                                && (eli.next() != null))
1120:                            hasMoreRows = true;
1121:
1122:                        eli.close();
1123:
1124:                        return resultGVL;
1125:
1126:                    } catch (GenericEntityException e) {
1127:                        Debug.logError(
1128:                                "An error occurred in the  getPartialList method: "
1129:                                        + e.getLocalizedMessage(), module);
1130:                    }
1131:                }
1132:
1133:                return null;
1134:
1135:            }
1136:
1137:            public GenericDelegator getDelegator() {
1138:                return delegator;
1139:            }
1140:
1141:            public void setDelegator(GenericDelegator delegator_) {
1142:                delegator = delegator_;
1143:            }
1144:
1145:            /**
1146:             * @return
1147:             */
1148:            public String getPartyId() {
1149:                return partyId;
1150:            }
1151:
1152:            /**
1153:             * @return
1154:             */
1155:            public List getPrimaryFields() {
1156:                if (!primaryFieldsLoaded)
1157:                    loadPrimarySectionFields();
1158:                return primaryFields;
1159:            }
1160:
1161:            /**
1162:             * @return
1163:             */
1164:            public List getRelatedFields() {
1165:                if (!relatedFieldsLoaded)
1166:                    loadRelatedSectionQueryFields();
1167:                return relatedFields;
1168:            }
1169:
1170:            /**
1171:             * @return
1172:             */
1173:            public String getReportId() {
1174:                return reportId;
1175:            }
1176:
1177:            /**
1178:             * @return
1179:             */
1180:            public String getReportName() {
1181:                return reportName;
1182:            }
1183:
1184:            /**
1185:             * @return
1186:             */
1187:            public String getSectionId() {
1188:                return sectionId;
1189:            }
1190:
1191:            /**
1192:             * @param string
1193:             */
1194:            public void setPartyId(String string) {
1195:                partyId = string;
1196:            }
1197:
1198:            /**
1199:             * @param list
1200:             */
1201:            public void setPrimaryFields(List list) {
1202:                primaryFields = list;
1203:                primaryFieldsLoaded = true;
1204:            }
1205:
1206:            /**
1207:             * @param list
1208:             */
1209:            public void setRelatedFields(List list) {
1210:                relatedFields = list;
1211:                relatedFieldsLoaded = true;
1212:            }
1213:
1214:            /**
1215:             * @param string
1216:             */
1217:            public void setReportId(String string) {
1218:                reportId = string;
1219:            }
1220:
1221:            /**
1222:             * @param string
1223:             */
1224:            public void setReportName(String string) {
1225:                reportName = string;
1226:            }
1227:
1228:            /**
1229:             * @param string
1230:             */
1231:            public void setSectionId(String string) {
1232:                sectionId = string;
1233:            }
1234:
1235:            /**
1236:             * @return
1237:             */
1238:            public List getReportCriteria() {
1239:                return reportCriteria;
1240:            }
1241:
1242:            /**
1243:             * @return
1244:             */
1245:            public List getReportFields() {
1246:                return reportFields;
1247:            }
1248:
1249:            /**
1250:             * @return
1251:             */
1252:            public List getReportOrderBy() {
1253:                return reportOrderBy;
1254:            }
1255:
1256:            /**
1257:             * @param list
1258:             */
1259:            public void setReportCriteria(List list) {
1260:                reportCriteria = list;
1261:            }
1262:
1263:            /**
1264:             * @param list
1265:             */
1266:            public void setReportFields(List list) {
1267:                reportFields = list;
1268:            }
1269:
1270:            /**
1271:             * @param list
1272:             */
1273:            public void setReportOrderBy(List list) {
1274:                reportOrderBy = list;
1275:            }
1276:
1277:            protected List getStringListfromGVL(List gvl, String fieldName) {
1278:                List sList = new ArrayList();
1279:
1280:                Iterator iter = gvl.iterator();
1281:                while (iter.hasNext()) {
1282:                    GenericValue gv = (GenericValue) iter.next();
1283:                    sList.add(gv.getString(fieldName));
1284:                }
1285:                return sList;
1286:            }
1287:
1288:            /**
1289:             * @return
1290:             */
1291:            public String getPublicFlag() {
1292:                return publicFlag;
1293:            }
1294:
1295:            /**
1296:             * @param string
1297:             */
1298:            public void setPublicFlag(String string) {
1299:                publicFlag = string;
1300:            }
1301:
1302:            /**
1303:             * @return
1304:             */
1305:            public List getSelectFieldLabels() {
1306:                return selectFieldLabels;
1307:            }
1308:
1309:            /**
1310:             * @return
1311:             */
1312:            public List getSelectFieldNames() {
1313:                return selectFieldNames;
1314:            }
1315:
1316:            /**
1317:             * @param list
1318:             */
1319:            public void setSelectFieldLabels(List list) {
1320:                selectFieldLabels = list;
1321:            }
1322:
1323:            /**
1324:             * @param list
1325:             */
1326:            public void setSelectFieldNames(List list) {
1327:                selectFieldNames = list;
1328:            }
1329:
1330:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.