Search in sources :

Example 1 with LookupResultsService

use of org.kuali.kfs.kns.lookup.LookupResultsService 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
 */
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 occurred trying to persist multiple lookup results", e);
        throw new RuntimeException("error occurred trying to persist multiple lookup results");
    }
    // since new search, nothing's checked
    multipleValueLookupForm.setCompositeObjectIdMap(new HashMap<>());
    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)

Example 2 with LookupResultsService

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

the class BalanceInquiryLookupAction method selectAll.

@Override
protected List<ResultRow> selectAll(MultipleValueLookupForm multipleValueLookupForm, int maxRowsPerPage) {
    List<ResultRow> resultTable;
    try {
        LookupResultsService lookupResultsService = SpringContext.getBean(LookupResultsService.class);
        String lookupResultsSequenceNumber = multipleValueLookupForm.getLookupResultsSequenceNumber();
        resultTable = lookupResultsService.retrieveResultsTable(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId());
    } catch (Exception e) {
        LOG.error("error occurred trying to export multiple lookup results", e);
        throw new RuntimeException("error occurred trying to export multiple lookup results");
    }
    Map<String, String> selectedObjectIds = this.getSelectedObjectIds(multipleValueLookupForm, resultTable);
    multipleValueLookupForm.jumpToPage(multipleValueLookupForm.getViewedPageNumber(), resultTable.size(), maxRowsPerPage);
    multipleValueLookupForm.setColumnToSortIndex(Integer.parseInt(multipleValueLookupForm.getPreviouslySortedColumnIndex()));
    multipleValueLookupForm.setCompositeObjectIdMap(selectedObjectIds);
    return resultTable;
}
Also used : ResultRow(org.kuali.kfs.kns.web.ui.ResultRow) LookupResultsService(org.kuali.kfs.kns.lookup.LookupResultsService)

Aggregations

LookupResultsService (org.kuali.kfs.kns.lookup.LookupResultsService)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Lookupable (org.kuali.kfs.kns.lookup.Lookupable)1 Column (org.kuali.kfs.kns.web.ui.Column)1 ResultRow (org.kuali.kfs.kns.web.ui.ResultRow)1 SequenceAccessorService (org.kuali.kfs.krad.service.SequenceAccessorService)1