public ActionForward search( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ReportTrackingLookupForm lookupForm = (ReportTrackingLookupForm) form; Lookupable kualiLookupable = lookupForm.getLookupable(); if (kualiLookupable == null) { LOG.error("Lookupable is null."); throw new RuntimeException("Lookupable is null."); } // validate search parameters kualiLookupable.validateSearchParameters(lookupForm.getFields()); if (lookupForm.isViewRawResults()) { return super.search(mapping, lookupForm, request, response); } else { LookupUtils.preProcessRangeFields(lookupForm.getFields()); List<ReportTracking> groupedResults = getReportTrackingDao() .getResultsGroupedBy( lookupForm.getFields(), lookupForm.getGroupedByFields(), lookupForm.getGroupedByDisplayFields()); lookupForm.setGroupedByResults(groupedResults); return mapping.findForward(Constants.MAPPING_BASIC); } }
/** * Picks out business object name from the request to get retrieve a lookupable and set * properties. * * @param request <code>{@link javax.servlet.http.HttpServletRequest}</code> instance for Struts */ @Override public void populate(HttpServletRequest request) { Lookupable localPendingEntryLookupable = null; super.populate(request); if (Entry.class.getName().equals(getBusinessObjectClassName())) { localPendingEntryLookupable = LookupableSpringContext.getLookupable( GeneralLedgerConstants.LookupableBeanKeys.PENDING_ENTRY); } if (localPendingEntryLookupable != null) { localPendingEntryLookupable.setBusinessObjectClass(GeneralLedgerPendingEntry.class); localPendingEntryLookupable.setFieldConversions(getFieldConversions()); } setPendingEntryLookupable(localPendingEntryLookupable); }
/** * This service is used to print the report. * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward print( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ContractsGrantsAwardBalancesReportLookupForm awardBalancesReportLookupForm = (ContractsGrantsAwardBalancesReportLookupForm) form; String methodToCall = findMethodToCall(form, request); if (methodToCall.equalsIgnoreCase(KRADConstants.SEARCH_METHOD)) { GlobalVariables.getUserSession().removeObjectsByPrefix(KRADConstants.SEARCH_METHOD); } Lookupable kualiLookupable = awardBalancesReportLookupForm.getLookupable(); if (kualiLookupable == null) { throw new RuntimeException("Lookupable is null."); } List<ResultRow> resultTable = new ArrayList<ResultRow>(); // validate search parameters kualiLookupable.validateSearchParameters(awardBalancesReportLookupForm.getFields()); // this is for 200 limit. turn it off for report. boolean isUnbounded = true; List<ContractsGrantsAwardBalancesReport> displayList = (List<ContractsGrantsAwardBalancesReport>) kualiLookupable.performLookup(awardBalancesReportLookupForm, resultTable, isUnbounded); Object sortIndexObject = GlobalVariables.getUserSession().retrieveObject(ArConstants.SORT_INDEX_SESSION_KEY); if (ObjectUtils.isNull(sortIndexObject) || sortIndexObject.toString() == "0") { sortIndexObject = "0"; } // get sort property String sortPropertyName = getFieldNameForSorting( Integer.parseInt(sortIndexObject.toString()), "ContractsGrantsAwardBalancesReport"); // sort list sortReport(displayList, sortPropertyName); // check field is valid for subtotal boolean isFieldSubtotalRequired = CGConstants.ReportsConstants.awardBalancesReportSubtotalFieldsList.contains( sortPropertyName); Map<String, KualiDecimal> subTotalMap = new HashMap<String, KualiDecimal>(); if (isFieldSubtotalRequired) { subTotalMap = buildSubTotalMap(displayList, sortPropertyName); } // build report ContractsGrantsReportDataHolder awardBalancesReportDataHolder = new ContractsGrantsReportDataHolder(); List<ContractsGrantsAwardBalancesReportDetailDataHolder> details = awardBalancesReportDataHolder.getDetails(); for (ContractsGrantsAwardBalancesReport awardBalancesReportEntry : displayList) { ContractsGrantsAwardBalancesReportDetailDataHolder reportDetail = new ContractsGrantsAwardBalancesReportDetailDataHolder(); // set report data setReportDate(awardBalancesReportEntry, reportDetail); if (isFieldSubtotalRequired) { // set sortedFieldValue for grouping in the report reportDetail.setSortedFieldValue( getPropertyValue(awardBalancesReportEntry, sortPropertyName)); reportDetail.setDisplaySubtotal(true); // set subTotal from subTotalMap reportDetail.setSubTotal( subTotalMap .get(getPropertyValue(awardBalancesReportEntry, sortPropertyName)) .bigDecimalValue()); } else { // set this to empty string for not displaying subtotal reportDetail.setDisplaySubtotal(false); } details.add(reportDetail); } awardBalancesReportDataHolder.setDetails(details); // build search criteria for report buildReportForSearchCriteia( awardBalancesReportDataHolder.getSearchCriteria(), awardBalancesReportLookupForm.getFieldsForLookup()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); String reportFileName = SpringContext.getBean(ContractsGrantsAwardBalancesReportService.class) .generateReport(awardBalancesReportDataHolder, baos); WebUtils.saveMimeOutputStreamAsFile( response, ReportGeneration.PDF_MIME_TYPE, baos, reportFileName + ReportGeneration.PDF_FILE_EXTENSION); return null; }