AdvancedSearchHome advancedSearchHome = (AdvancedSearchHome)CVUtility.getHomeObject("com.centraview.advancedsearch.AdvancedSearchHome", "AdvancedSearch");
remoteAdvancedSearch = advancedSearchHome.create();
remoteAdvancedSearch.setDataSource(dataSource);
} catch (Exception e) {
System.out.println("[Exception][SearchForm.execute] Exception Thrown getting EJB connection: " + e);
throw new ServletException(e);
}
// because we can get reposted get the current criteria from the form.
// As we may be manipulating the searchCriteria, adding rows, and such.
SearchCriteriaVO[] searchCriteria = (SearchCriteriaVO[])adhocReportForm.get("searchCriteria");
// Build dem drop downs
// if necessary.
HashMap allFields = (HashMap)adhocReportForm.get("allFields");
ArrayList tableList = (ArrayList)adhocReportForm.get("tableList");
ArrayList conditionList = (ArrayList)adhocReportForm.get("conditionList");
if (conditionList == null || conditionList.isEmpty()) {
// This will get us the possible search conditions.
HashMap conditionMap = SearchVO.getConditionOptions();
// Build an ArrayList of LabelValueBeans
conditionList = AdvancedSearchUtil.buildSelectOptionList(conditionMap);
// stick it on the form
adhocReportForm.set("conditionList", conditionList);
}
if (tableList == null || tableList.isEmpty()) {
HashMap tableMap = remoteAdvancedSearch.getSearchTablesForModule(individualId, moduleId);
// Build an ArrayList of LabelValueBeans
tableList = AdvancedSearchUtil.buildSelectOptionList(tableMap);
adhocReportForm.set("tableList", tableList);
// if we had to add get the tableList we more than likely
// have to build the allFields map, so its probably worth the zillion
// cpu cycles we will have to waste.
// Get all the appropriate field lists and stick them on the formbean
// The fieldList (ArrayList of LabelValueBean) will be stored in a
// HashMap with the key being the (Number)tableId
TreeSet keySet = new TreeSet(tableMap.keySet());
Iterator keyIterator = keySet.iterator();
allFields = new HashMap();
while (keyIterator.hasNext()) {
Number key = (Number)keyIterator.next();
// iterate the tables and get all the field lists
// stick them in a hashmap of arraylists on the form bean.
HashMap tableFields = remoteAdvancedSearch.getSearchFieldsForTable(individualId, key.intValue(), moduleId);
ArrayList tableFieldList = AdvancedSearchUtil.buildSelectOptionList(tableFields);
allFields.put(key, tableFieldList);
} // end while(keyIterator.hasNext())
adhocReportForm.set("allFields", allFields);
}
// See if we need to add or remove rows from the search criteria array.
// and do it.
String addRow = (String)adhocReportForm.get("addRow");
if (addRow.equals("true")) {
searchCriteria = AdvancedSearchUtil.addRow(searchCriteria);
adhocReportForm.set("addRow", "false");
}
String removeRow = (String)adhocReportForm.get("removeRow");
if (!removeRow.equals("false")) {
searchCriteria = AdvancedSearchUtil.removeRow(searchCriteria, removeRow);
adhocReportForm.set("removeRow", "false");
}
// now that the criteria is ready stick it on the formbean.
adhocReportForm.set("searchCriteria", searchCriteria);
ReportVO reportVO = new ReportVO();
reportVO.setSelect(selects);
// This parses the fields from the form bean and builds up an arraylist of
// ReportContentVOs which represent what is selected. This is then stuck on the
// reportVO which is stuck on the request
reportVO.setSelectedFields(getSelectedFieldsWithNames((String)adhocReportForm.get("contentFields"), (String)adhocReportForm.get("contentOrders"), (String)adhocReportForm.get("contentFieldNames")));
request.setAttribute("pagedata", reportVO);
// I think this should probably live on the adhocreportform, rather than worrying
// about something on the request. But here it is for now.
request.setAttribute("reportType", String.valueOf(ReportConstants.ADHOC_REPORT_CODE));
} catch (Exception e) {
logger.error("[execute] Exception thrown.", e);
throw new ServletException(e);
}
String forwardName = "";
switch (moduleId) {
case 14: forwardName = ".view.reports.entities.adhoc"; break;
case 15: forwardName = ".view.reports.individuals.adhoc"; break;