/** * This method performs the lookup and returns a collection of lookup items * * @param lookupForm * @param kualiLookupable * @param resultTable * @param bounded * @return */ @Override public Collection performLookup(LookupForm lookupForm, Collection resultTable, boolean bounded) { Collection displayList; // call search method to get results if (bounded) { displayList = getSearchResults(lookupForm.getFieldsForLookup()); } else { displayList = getSearchResultsUnbounded(lookupForm.getFieldsForLookup()); } // MJM get resultTable populated here if (bounded) { HashMap<String, Class> propertyTypes = new HashMap<String, Class>(); boolean hasReturnableRow = false; Person user = GlobalVariables.getUserSession().getPerson(); try { // iterate through result list and wrap rows with return url and action urls for (Object aDisplayList : displayList) { BusinessObject element = (BusinessObject) aDisplayList; BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user); String returnUrl = "www.bigfrickenRETURNurl"; String actionUrls = "www.someACTIONurl"; if (ObjectUtils.isNotNull(getColumns())) { List<Column> columns = getColumns(); populateCutoffdateLabels(); for (Object column : columns) { Column col = (Column) column; Formatter formatter = col.getFormatter(); // pick off result column from result list, do formatting Object prop = ObjectUtils.getPropertyValue(element, col.getPropertyName()); String propValue = ObjectUtils.getFormattedPropertyValue( element, col.getPropertyName(), col.getFormatter()); Class propClass = getPropertyClass(element, col.getPropertyName()); // formatters if (ObjectUtils.isNotNull(prop)) { // for Booleans, always use BooleanFormatter if (prop instanceof Boolean) { formatter = new BooleanFormatter(); } // for Dates, always use DateFormatter if (prop instanceof Date) { formatter = new DateFormatter(); } // for collection, use the list formatter if a formatter hasn't been defined yet if (prop instanceof Collection && ObjectUtils.isNull(formatter)) { formatter = new CollectionFormatter(); } if (ObjectUtils.isNotNull(formatter)) { propValue = (String) formatter.format(prop); } else { propValue = prop.toString(); } } // comparator col.setComparator( CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass)); col.setValueComparator( CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass)); propValue = super.maskValueIfNecessary( element.getClass(), col.getPropertyName(), propValue, businessObjectRestrictions); col.setPropertyValue(propValue); // add correct label for sysparam if (StringUtils.equals("unpaidBalance91toSYSPR", col.getPropertyName())) { col.setColumnTitle(cutoffdate91toSYSPRlabel); } if (StringUtils.equals("unpaidBalanceSYSPRplus1orMore", col.getPropertyName())) { col.setColumnTitle(cutoffdateSYSPRplus1orMorelabel); } if (StringUtils.equals("reportingName", col.getPropertyName())) { col.setColumnTitle(agencyShortName); } if (StringUtils.isNotBlank(propValue)) { // do not add link to the values in column "Customer Name" if (StringUtils.equals(customerNameLabel, col.getColumnTitle())) { col.setPropertyURL(getCustomerLookupUrl(element, col.getColumnTitle())); } else if (StringUtils.equals(customerNumberLabel, col.getColumnTitle())) { col.setPropertyURL( getCustomerOpenInvoicesReportUrl( element, col.getColumnTitle(), lookupForm.getFieldsForLookup())); } else if (StringUtils.equals( ArConstants.ContractsGrantsAgingReportFields.TOTAL_CREDITS, col.getColumnTitle())) { col.setPropertyURL(getCreditMemoDocSearchUrl(element, col.getColumnTitle())); } else if (StringUtils.equals( ArConstants.ContractsGrantsAgingReportFields.TOTAL_WRITEOFF, col.getColumnTitle())) { col.setPropertyURL(getCustomerWriteoffSearchUrl(element, col.getColumnTitle())); } else if (StringUtils.equals( ArConstants.ContractsGrantsAgingReportFields.AGENCY_SHORT_NAME, col.getColumnTitle())) { col.setPropertyURL(getAgencyInquiryUrl(element, col.getColumnTitle())); } else { col.setPropertyURL( getCustomerOpenInvoicesReportUrl( element, col.getColumnTitle(), lookupForm.getFieldsForLookup())); } } } ResultRow row = new ResultRow(columns, returnUrl, actionUrls); if (element instanceof PersistableBusinessObject) { row.setObjectId(((PersistableBusinessObject) element).getObjectId()); } boolean rowReturnable = isResultReturnable(element); row.setRowReturnable(rowReturnable); if (rowReturnable) { hasReturnableRow = true; } resultTable.add(row); } lookupForm.setHasReturnableRow(hasReturnableRow); } } catch (Exception e) { // do nothing, try block needed to make CustomerAgingReportLookupableHelperServiceImpl- LOG.error( "problem during contractsGrantsAgingReportLookupableHelperService.performLookup()", e); } if (displayList.size() != 0) { ((ContractsGrantsAgingReportForm) lookupForm).setTotal0to30(total0to30.toString()); ((ContractsGrantsAgingReportForm) lookupForm).setTotal31to60(total31to60.toString()); ((ContractsGrantsAgingReportForm) lookupForm).setTotal61to90(total61to90.toString()); ((ContractsGrantsAgingReportForm) lookupForm).setTotal91toSYSPR(total91toSYSPR.toString()); ((ContractsGrantsAgingReportForm) lookupForm) .setTotalSYSPRplus1orMore(totalSYSPRplus1orMore.toString()); ((ContractsGrantsAgingReportForm) lookupForm) .setTotalOpenInvoices(totalOpenInvoices.toString()); ((ContractsGrantsAgingReportForm) lookupForm).setTotalCredits(totalCredits.toString()); ((ContractsGrantsAgingReportForm) lookupForm).setTotalWriteOffs(totalWriteOffs.toString()); } } return displayList; }
/** * @param element * @param attributeName * @return Column * <p>KRAD Conversion: Performs customization of the results columns. * <p>Uses data dictionary to get column properties. */ protected Column setupResultsColumn( BusinessObject element, String attributeName, BusinessObjectRestrictions businessObjectRestrictions) { Column col = new Column(); col.setPropertyName(attributeName); String columnTitle = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), attributeName); if (StringUtils.isBlank(columnTitle)) { columnTitle = getDataDictionaryService().getCollectionLabel(getBusinessObjectClass(), attributeName); } col.setColumnTitle(columnTitle); col.setMaxLength( getDataDictionaryService().getAttributeMaxLength(getBusinessObjectClass(), attributeName)); Class formatterClass = getDataDictionaryService().getAttributeFormatter(getBusinessObjectClass(), attributeName); Formatter formatter = null; if (formatterClass != null) { try { formatter = (Formatter) formatterClass.newInstance(); col.setFormatter(formatter); } catch (InstantiationException e) { LOG.error("Unable to get new instance of formatter class: " + formatterClass.getName()); throw new RuntimeException( "Unable to get new instance of formatter class: " + formatterClass.getName()); } catch (IllegalAccessException e) { LOG.error("Unable to get new instance of formatter class: " + formatterClass.getName()); throw new RuntimeException( "Unable to get new instance of formatter class: " + formatterClass.getName()); } } // pick off result column from result list, do formatting String propValue = KFSConstants.EMPTY_STRING; Object prop = ObjectUtils.getPropertyValue(element, attributeName); // set comparator and formatter based on property type Class propClass = null; try { PropertyDescriptor propDescriptor = PropertyUtils.getPropertyDescriptor(element, col.getPropertyName()); if (propDescriptor != null) { propClass = propDescriptor.getPropertyType(); } } catch (Exception e) { throw new RuntimeException( "Cannot access PropertyType for property " + "'" + col.getPropertyName() + "' " + " on an instance of '" + element.getClass().getName() + "'.", e); } // formatters if (prop != null) { // for Booleans, always use BooleanFormatter if (prop instanceof Boolean) { formatter = new BooleanFormatter(); } if (formatter != null) { propValue = (String) formatter.format(prop); } else { propValue = prop.toString(); } } // comparator col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass)); col.setValueComparator( CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass)); propValue = super.maskValueIfNecessary( element.getClass(), col.getPropertyName(), propValue, businessObjectRestrictions); col.setPropertyValue(propValue); if (StringUtils.isNotBlank(propValue)) { col.setColumnAnchor(getInquiryUrl(element, col.getPropertyName())); } return col; }