Search in sources :

Example 1 with AccountBalanceByConsolidationLookupableHelperServiceImpl

use of org.kuali.kfs.gl.businessobject.lookup.AccountBalanceByConsolidationLookupableHelperServiceImpl 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)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)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 Lookupable (org.kuali.kfs.kns.lookup.Lookupable)1 ResultRow (org.kuali.kfs.kns.web.ui.ResultRow)1 CollectionIncomplete (org.kuali.kfs.krad.lookup.CollectionIncomplete)1