Search in sources :

Example 1 with Column

use of org.kuali.kfs.kns.web.ui.Column in project cu-kfs by CU-CommunityApps.

the class BalanceInquiryLookupAction method getSelectedObjectIds.

/**
 * put all enties into select object map. This implmentation only deals with the money amount objects.
 *
 * @param multipleValueLookupForm the given struts form
 * @param resultTable             the given result table that holds all data being presented
 * @return the map containing all entries available for selection
 * <p>
 * KRAD Conversion: Performs customization of the results. Prepares
 * <p>
 * There is no use of data dictionary for fields.
 */
private Map<String, String> getSelectedObjectIds(MultipleValueLookupForm multipleValueLookupForm, List<ResultRow> resultTable) {
    String businessObjectClassName = multipleValueLookupForm.getBusinessObjectClassName();
    SegmentedBusinessObject segmentedBusinessObject;
    try {
        segmentedBusinessObject = (SegmentedBusinessObject) Class.forName(multipleValueLookupForm.getBusinessObjectClassName()).newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Fail to create an object of " + businessObjectClassName + e);
    }
    Map<String, String> selectedObjectIds = new HashMap<String, String>();
    Collection<String> segmentedPropertyNames = segmentedBusinessObject.getSegmentedPropertyNames();
    for (ResultRow row : resultTable) {
        for (Column column : row.getColumns()) {
            String propertyName = column.getPropertyName();
            if (segmentedPropertyNames.contains(propertyName)) {
                String propertyValue = StringUtils.replace(column.getPropertyValue(), ",", "");
                // If there is a negative value, we need to convert it from (##.##) to -##.##
                if (StringUtils.contains(propertyValue, "(")) {
                    propertyValue = StringUtils.replace(propertyValue, "(", "-");
                    propertyValue = StringUtils.replace(propertyValue, ")", "");
                }
                KualiDecimal amount = new KualiDecimal(propertyValue);
                if (amount.isNonZero()) {
                    String objectId = row.getObjectId() + "." + propertyName + "." + KRADUtils.convertDecimalIntoInteger(amount);
                    selectedObjectIds.put(objectId, objectId);
                }
            }
        }
    }
    return selectedObjectIds;
}
Also used : ResultRow(org.kuali.kfs.kns.web.ui.ResultRow) HashMap(java.util.HashMap) Column(org.kuali.kfs.kns.web.ui.Column) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) SegmentedBusinessObject(org.kuali.kfs.integration.ld.SegmentedBusinessObject)

Example 2 with Column

use of org.kuali.kfs.kns.web.ui.Column 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

Column (org.kuali.kfs.kns.web.ui.Column)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SegmentedBusinessObject (org.kuali.kfs.integration.ld.SegmentedBusinessObject)1 LookupResultsService (org.kuali.kfs.kns.lookup.LookupResultsService)1 Lookupable (org.kuali.kfs.kns.lookup.Lookupable)1 ResultRow (org.kuali.kfs.kns.web.ui.ResultRow)1 SequenceAccessorService (org.kuali.kfs.krad.service.SequenceAccessorService)1 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)1