Search in sources :

Example 1 with Lookupable

use of org.kuali.kfs.kns.lookup.Lookupable in project cu-kfs by CU-CommunityApps.

the class BalanceInquiryLookupAction method search.

/**
 * search - sets the values of the data entered on the form on the jsp into a map and then searches for the results.
 * <p>
 * KRAD Conversion: Lookupable performs customization of the results if
 * balance inquiry. The result rows are added to a collection
 * based on field's actual size if truncated is > 7.
 * <p>
 * Fields are in data dictionary for bo Balance.
 */
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    BalanceInquiryLookupForm lookupForm = (BalanceInquiryLookupForm) form;
    Lookupable lookupable = lookupForm.getLookupable();
    if (lookupable == null) {
        LOG.error("Lookupable is null.");
        throw new RuntimeException("Lookupable is null.");
    }
    lookupable.validateSearchParameters(lookupForm.getFields());
    if (GlobalVariables.getMessageMap().getErrorCount() > 0) {
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }
    List<ResultRow> resultTable = new ArrayList<ResultRow>();
    boolean bounded = true;
    Collection displayList = performMultipleValueLookup(lookupForm, resultTable, getMaxRowsPerPage(lookupForm), bounded);
    CollectionIncomplete incompleteDisplayList = (CollectionIncomplete) displayList;
    Long totalSize = incompleteDisplayList.getActualSizeIfTruncated();
    if (lookupable.isSearchUsingOnlyPrimaryKeyValues()) {
        lookupForm.setSearchUsingOnlyPrimaryKeyValues(true);
        lookupForm.setPrimaryKeyFieldLabels(lookupable.getPrimaryKeyFieldLabels());
    } else {
        lookupForm.setSearchUsingOnlyPrimaryKeyValues(false);
        lookupForm.setPrimaryKeyFieldLabels(KFSConstants.EMPTY_STRING);
    }
    // TODO: use inheritance instead of this if statement
    if (lookupable.getLookupableHelperService() instanceof AccountBalanceByConsolidationLookupableHelperServiceImpl) {
        Object[] resultTableAsArray = resultTable.toArray();
        Collection totalsTable = new ArrayList();
        int arrayIndex = 0;
        try {
            for (int listIndex = 0; listIndex < incompleteDisplayList.size(); listIndex++) {
                AccountBalance balance = (AccountBalance) incompleteDisplayList.get(listIndex);
                boolean ok = ObjectHelper.isOneOf(balance.getTitle(), getTotalTitles());
                if (ok) {
                    if (totalSize > 7) {
                        totalsTable.add(resultTableAsArray[arrayIndex]);
                    }
                    resultTable.remove(resultTableAsArray[arrayIndex]);
                    incompleteDisplayList.remove(balance);
                }
                arrayIndex++;
            }
            request.setAttribute(TOTALS_TABLE_KEY, totalsTable);
            GlobalVariables.getUserSession().addObject(TOTALS_TABLE_KEY, totalsTable);
        } catch (NumberFormatException e) {
            GlobalVariables.getMessageMap().putError(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, KFSKeyConstants.ERROR_CUSTOM, new String[] { "Fiscal Year must be a four-digit number" });
        } catch (Exception e) {
            GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_ERRORS, KFSKeyConstants.ERROR_CUSTOM, new String[] { "Please report the server error." });
            LOG.error("Application Errors", e);
        }
    }
    request.setAttribute(KFSConstants.REQUEST_SEARCH_RESULTS_SIZE, totalSize);
    request.setAttribute(KFSConstants.REQUEST_SEARCH_RESULTS, resultTable);
    lookupForm.setResultsActualSize((int) totalSize.longValue());
    lookupForm.setResultsLimitedSize(resultTable.size());
    if (lookupForm.isSegmented()) {
        LOG.debug("I'm segmented");
        request.setAttribute(GeneralLedgerConstants.LookupableBeanKeys.SEGMENTED_LOOKUP_FLAG_NAME, Boolean.TRUE);
    }
    if (request.getParameter(KFSConstants.SEARCH_LIST_REQUEST_KEY) != null) {
        GlobalVariables.getUserSession().removeObject(request.getParameter(KFSConstants.SEARCH_LIST_REQUEST_KEY));
        request.setAttribute(KFSConstants.SEARCH_LIST_REQUEST_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(resultTable));
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : ResultRow(org.kuali.kfs.kns.web.ui.ResultRow) Lookupable(org.kuali.kfs.kns.lookup.Lookupable) CollectionIncomplete(org.kuali.kfs.krad.lookup.CollectionIncomplete) ArrayList(java.util.ArrayList) AccountBalanceByConsolidationLookupableHelperServiceImpl(org.kuali.kfs.gl.businessobject.lookup.AccountBalanceByConsolidationLookupableHelperServiceImpl) AccountBalance(org.kuali.kfs.gl.businessobject.AccountBalance) Collection(java.util.Collection) SegmentedBusinessObject(org.kuali.kfs.integration.ld.SegmentedBusinessObject)

Example 2 with Lookupable

use of org.kuali.kfs.kns.lookup.Lookupable in project cu-kfs by CU-CommunityApps.

the class BalanceInquiryLookupAction method performMultipleValueLookup.

/**
 * This method performs the lookup and returns a collection of lookup items. Also initializes values in the form that will allow
 * the multiple value lookup page to render
 *
 * @param multipleValueLookupForm
 * @param resultTable             a list of result rows (used to generate what's shown in the UI). This list will be modified by this method
 * @param maxRowsPerPage
 * @param bounded                 whether the results will be bounded
 * @return the list of result BOs, possibly bounded by size
 * <p>
 * KRAD Conversion: Lookupable performs customization of the results if
 * balance inquiry. The multiple value results are sorted.
 * <p>
 * Fields are in data dictionary for bo Balance.
 */
protected Collection performMultipleValueLookup(MultipleValueLookupForm multipleValueLookupForm, List<ResultRow> resultTable, int maxRowsPerPage, boolean bounded) {
    Lookupable lookupable = multipleValueLookupForm.getLookupable();
    Collection displayList = lookupable.performLookup(multipleValueLookupForm, resultTable, bounded);
    List defaultSortColumns = lookupable.getDefaultSortColumns();
    if (defaultSortColumns != null && !defaultSortColumns.isEmpty() && resultTable != null && !resultTable.isEmpty()) {
        // there's a default sort order, just find the first sort column, and we can't go wrong
        String firstSortColumn = (String) defaultSortColumns.get(0);
        // go thru the first result row to find the index of the column (more efficient than calling lookupable.getColumns since
        // we don't have to recreate column list)
        int firstSortColumnIdx = -1;
        List<Column> columnsForFirstResultRow = resultTable.get(0).getColumns();
        for (int i = 0; i < columnsForFirstResultRow.size(); i++) {
            if (StringUtils.equals(firstSortColumn, columnsForFirstResultRow.get(i).getPropertyName())) {
                firstSortColumnIdx = i;
                break;
            }
        }
        multipleValueLookupForm.setColumnToSortIndex(firstSortColumnIdx);
    } else {
        // don't know how results were sorted, so we just say -1
        multipleValueLookupForm.setColumnToSortIndex(-1);
    }
    // we just performed the lookup, so we're on the first page (indexed from 0)
    multipleValueLookupForm.jumpToFirstPage(resultTable.size(), maxRowsPerPage);
    SequenceAccessorService sequenceAccessorService = SpringContext.getBean(SequenceAccessorService.class);
    String lookupResultsSequenceNumber = String.valueOf(sequenceAccessorService.getNextAvailableSequenceNumber(KRADConstants.LOOKUP_RESULTS_SEQUENCE));
    multipleValueLookupForm.setLookupResultsSequenceNumber(lookupResultsSequenceNumber);
    try {
        LookupResultsService lookupResultsService = SpringContext.getBean(LookupResultsService.class);
        lookupResultsService.persistResultsTable(lookupResultsSequenceNumber, resultTable, GlobalVariables.getUserSession().getPerson().getPrincipalId());
    } catch (Exception e) {
        LOG.error("error occured trying to persist multiple lookup results", e);
        throw new RuntimeException("error occured trying to persist multiple lookup results");
    }
    // since new search, nothing's checked
    multipleValueLookupForm.setCompositeObjectIdMap(new HashMap<String, String>());
    return displayList;
}
Also used : SequenceAccessorService(org.kuali.kfs.krad.service.SequenceAccessorService) Lookupable(org.kuali.kfs.kns.lookup.Lookupable) Column(org.kuali.kfs.kns.web.ui.Column) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) LookupResultsService(org.kuali.kfs.kns.lookup.LookupResultsService)

Aggregations

ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Lookupable (org.kuali.kfs.kns.lookup.Lookupable)2 List (java.util.List)1 AccountBalance (org.kuali.kfs.gl.businessobject.AccountBalance)1 AccountBalanceByConsolidationLookupableHelperServiceImpl (org.kuali.kfs.gl.businessobject.lookup.AccountBalanceByConsolidationLookupableHelperServiceImpl)1 SegmentedBusinessObject (org.kuali.kfs.integration.ld.SegmentedBusinessObject)1 LookupResultsService (org.kuali.kfs.kns.lookup.LookupResultsService)1 Column (org.kuali.kfs.kns.web.ui.Column)1 ResultRow (org.kuali.kfs.kns.web.ui.ResultRow)1 CollectionIncomplete (org.kuali.kfs.krad.lookup.CollectionIncomplete)1 SequenceAccessorService (org.kuali.kfs.krad.service.SequenceAccessorService)1