Search in sources :

Example 1 with BeanPropertyComparator

use of org.kuali.kfs.krad.util.BeanPropertyComparator in project cu-kfs by CU-CommunityApps.

the class TransactionRowBuilder method getWorkflowDocumentForTaxRow.

/**
 * Helper method for retrieving the workflow document of the current tax source row,
 * and for updating statistics accordingly if the document could not be found.
 *
 * <p>NOTE: In order for this method to work as intended, the list of doc IDs for
 * retrieval *MUST* be sorted in ascending order, and the invocations of this method
 * for a given builder *MUST* pass in the individual document IDs in ascending order
 * (preferably with null/blank values coming first).</p>
 *
 * @param documentId The document's ID; may be blank.
 * @param summary The object encapsulating the tax-type-specific summary info.
 * @return The workflow document for the current tax row, or null if no such document exists.
 */
@SuppressWarnings("unchecked")
Document getWorkflowDocumentForTaxRow(String documentId, T summary) {
    if (StringUtils.isNotBlank(documentId)) {
        int idCompareResult = documentId.compareTo(currentDocument.getDocumentId());
        if (idCompareResult > 0) {
            // If no match and doc ID is greater than cached one, then get next document from bulk-retrieved ones.
            do {
                while (documentsForProcessing.hasNext() && idCompareResult > 0) {
                    currentDocument = documentsForProcessing.next();
                    idCompareResult = documentId.compareTo(currentDocument.getDocumentId());
                }
                // If still greater than cached ID and more unfetched docs exist, perform next bulk retrieval.
                if (idCompareResult > 0 && documentIdsForBulkQuery.hasNext()) {
                    StringBuilder docIdCriteria = new StringBuilder(DOC_ID_CRITERIA_SIZE);
                    for (int i = 0; documentIdsForBulkQuery.hasNext() && i < getMaxSearchSize(); i++) {
                        // Build a docId criteria string with "|" (Kuali lookup OR) as the separator.
                        docIdCriteria.append(documentIdsForBulkQuery.next()).append('|');
                    }
                    // Remove last unneeded "|" separator.
                    docIdCriteria.deleteCharAt(docIdCriteria.length() - 1);
                    // Get and sort the documents.
                    DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
                    criteria.setDocumentId(docIdCriteria.toString());
                    DocumentSearchResults results = workflowDocumentService.documentSearch(null, criteria.build());
                    documentsForBatch = new ArrayList<Document>(results.getSearchResults().size());
                    for (DocumentSearchResult result : results.getSearchResults()) {
                        documentsForBatch.add(result.getDocument());
                    }
                    Collections.sort(documentsForBatch, new BeanPropertyComparator(Collections.singletonList(KEWPropertyConstants.DOCUMENT_ID)));
                    documentsForProcessing = documentsForBatch.iterator();
                    // Select and compare first document from new batch, if non-empty.
                    if (documentsForProcessing.hasNext()) {
                        currentDocument = documentsForProcessing.next();
                        idCompareResult = documentId.compareTo(currentDocument.getDocumentId());
                    }
                }
            // Keep looping until doc ID is less than or equal to cached one, or until cached values are exhausted.
            } while (idCompareResult > 0 && (documentsForProcessing.hasNext() || documentIdsForBulkQuery.hasNext()));
        }
        if (idCompareResult == 0) {
            // Return document if found.
            return currentDocument;
        }
        // No document was found, so update statistics and return null.
        numNoDocumentHeaders++;
    } else {
        numNullDocumentHeaders++;
    }
    return null;
}
Also used : DocumentSearchResult(org.kuali.rice.kew.api.document.search.DocumentSearchResult) DocumentSearchCriteria(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria) DocumentSearchResults(org.kuali.rice.kew.api.document.search.DocumentSearchResults) BeanPropertyComparator(org.kuali.kfs.krad.util.BeanPropertyComparator) Document(org.kuali.rice.kew.api.document.Document)

Example 2 with BeanPropertyComparator

use of org.kuali.kfs.krad.util.BeanPropertyComparator in project cu-kfs by CU-CommunityApps.

the class CurrentFundsLookupableHelperServiceImpl method getSearchResults.

/**
 * Gets a list with the fields that will be displayed on page
 *
 * @param fieldValues list of fields that are used as a key to filter out data
 * @see org.kuali.kfs.kns.lookup.Lookupable#getSearchResults(java.util.Map)
 */
@Override
public List getSearchResults(Map fieldValues) {
    LOG.info("getSearchResults() - Entry");
    boolean unbounded = false;
    Long actualCountIfTruncated = new Long(0);
    setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION));
    setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY));
    // get the pending entry option. This method must be prior to the get search results
    String pendingEntryOption = laborInquiryOptionsService.getSelectedPendingEntryOption(fieldValues);
    // get the consolidation option
    boolean isConsolidated = laborInquiryOptionsService.isConsolidationSelected(fieldValues, (Collection<Row>) getRows());
    String searchObjectCodeVal = (String) fieldValues.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
    // Check for a valid labor object code for this inquiry
    if (StringUtils.isNotBlank(searchObjectCodeVal)) {
        Map objectCodeFieldValues = new HashMap();
        objectCodeFieldValues.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, fieldValues.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR));
        objectCodeFieldValues.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, fieldValues.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE));
        objectCodeFieldValues.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, searchObjectCodeVal);
        LaborLedgerObject foundObjectCode = (LaborLedgerObject) businessObjectService.findByPrimaryKey(LaborObject.class, objectCodeFieldValues);
        if (foundObjectCode == null) {
            GlobalVariables.getMessageMap().putError(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, LaborKeyConstants.ERROR_INVALID_LABOR_OBJECT_CODE, "2");
            return new CollectionIncomplete(new ArrayList(), actualCountIfTruncated);
        }
    }
    // Parse the map and call the DAO to process the inquiry
    Collection<AccountStatusCurrentFunds> searchResultsCollection = buildCurrentFundsCollection(toList(laborDao.getCurrentFunds(fieldValues, isConsolidated)), isConsolidated, pendingEntryOption);
    // update search results according to the selected pending entry option
    laborInquiryOptionsService.updateCurrentFundsByPendingLedgerEntry(searchResultsCollection, fieldValues, pendingEntryOption, isConsolidated);
    // gets the July1st budget amount column.
    Collection<July1PositionFunding> july1PositionFundings = laborDao.getJuly1(fieldValues);
    this.updateJuly1BalanceAmount(searchResultsCollection, july1PositionFundings, isConsolidated);
    // sort list if default sort column given
    List searchResults = (List) searchResultsCollection;
    List defaultSortColumns = getDefaultSortColumns();
    if (defaultSortColumns.size() > 0) {
        Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true));
    }
    return new CollectionIncomplete(searchResults, actualCountIfTruncated);
}
Also used : CollectionIncomplete(org.kuali.kfs.krad.lookup.CollectionIncomplete) AccountStatusCurrentFunds(org.kuali.kfs.module.ld.businessobject.AccountStatusCurrentFunds) HashMap(java.util.HashMap) BeanPropertyComparator(org.kuali.kfs.krad.util.BeanPropertyComparator) ArrayList(java.util.ArrayList) LaborLedgerObject(org.kuali.kfs.integration.ld.LaborLedgerObject) LaborObject(org.kuali.kfs.module.ld.businessobject.LaborObject) July1PositionFunding(org.kuali.kfs.module.ld.businessobject.July1PositionFunding) ArrayList(java.util.ArrayList) IteratorUtils.toList(org.apache.commons.collections.IteratorUtils.toList) List(java.util.List) Row(org.kuali.kfs.kns.web.ui.Row) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with BeanPropertyComparator

use of org.kuali.kfs.krad.util.BeanPropertyComparator in project cu-kfs by CU-CommunityApps.

the class AccountGlobalSearchLookupableHelperServiceImpl method getSearchResults.

/**
 * @see org.kuali.kfs.coa.businessobject.lookup.KualiAccountLookupableHelperServiceImpl#getSearchResults(java.util.Map)
 */
@Override
public List<? extends BusinessObject> getSearchResults(Map<String, String> parameters) {
    setBackLocation(parameters.get(KRADConstants.BACK_LOCATION));
    setDocFormKey(parameters.get(KRADConstants.DOC_FORM_KEY));
    setReferencesToRefresh(parameters.get(KRADConstants.REFERENCES_TO_REFRESH));
    if (parameters.containsKey("useOrgHierarchy")) {
        String includeOrgHierarchyStr = parameters.get("useOrgHierarchy");
        Boolean includeOrgHierarchy = (Boolean) new BooleanFormatter().convertFromPresentationFormat(includeOrgHierarchyStr);
        if (includeOrgHierarchy == null)
            // Both was selected
            includeOrgHierarchy = true;
        if (includeOrgHierarchy) {
            String chartOfAccountsCode = null;
            if (parameters.containsKey(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)) {
                chartOfAccountsCode = parameters.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
            }
            String organizationCode = null;
            if (parameters.containsKey(KFSPropertyConstants.ORGANIZATION_CODE)) {
                organizationCode = parameters.get(KFSPropertyConstants.ORGANIZATION_CODE);
            }
            if (parameters.containsKey(KFSPropertyConstants.CLOSED)) {
                final String closedValue = parameters.get(KFSPropertyConstants.CLOSED);
                if (closedValue != null && closedValue.length() != 0) {
                    if ("Y1T".indexOf(closedValue) > -1) {
                        parameters.put(KFSPropertyConstants.ACTIVE, "N");
                    } else if ("N0F".indexOf(closedValue) > -1) {
                        parameters.put(KFSPropertyConstants.ACTIVE, "Y");
                    }
                }
                parameters.remove(KFSPropertyConstants.CLOSED);
            }
            parameters.remove("useOrgHierarchy");
            List<? extends BusinessObject> searchResults;
            if (fixPrincipalNameParameters(parameters)) {
                searchResults = (List<? extends BusinessObject>) accountGlobalSearchDao.getAccountsByOrgHierarchy(chartOfAccountsCode, organizationCode, parameters);
                List defaultSortColumns = getDefaultSortColumns();
                if (defaultSortColumns.size() > 0) {
                    Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true));
                }
            } else {
                searchResults = Collections.EMPTY_LIST;
            }
            return searchResults;
        }
    }
    parameters.remove("useOrgHierarchy");
    return super.getSearchResults(parameters);
}
Also used : BeanPropertyComparator(org.kuali.kfs.krad.util.BeanPropertyComparator) BooleanFormatter(org.kuali.rice.core.web.format.BooleanFormatter) List(java.util.List)

Example 4 with BeanPropertyComparator

use of org.kuali.kfs.krad.util.BeanPropertyComparator in project cu-kfs by CU-CommunityApps.

the class CuACHPayeeLookupableHelperServiceImpl method getSearchResults.

/**
 * Overridden to only search for employee or entity payees when principal name is specified.
 *
 * @see org.kuali.kfs.pdp.businessobject.lookup.ACHPayeeLookupableHelperServiceImpl#getSearchResults(java.util.Map)
 */
@SuppressWarnings({ "deprecation", "rawtypes", "unchecked" })
@Override
public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
    /*
         * This is mostly a copy of the superclass's method, but has been tweaked to account for principal name
         * and to conform to our line formatting standards.
         */
    List<DisbursementPayee> searchResults = new ArrayList<DisbursementPayee>();
    String payeeTypeCode = fieldValues.get(KFSPropertyConstants.PAYEE_TYPE_CODE);
    if (StringUtils.isBlank(payeeTypeCode)) {
        GlobalVariables.getMessageMap().putInfo(KFSPropertyConstants.PAYEE_TYPE_CODE, PdpKeyConstants.MESSAGE_PDP_ACH_PAYEE_LOOKUP_NO_PAYEE_TYPE);
    }
    // CU Customization: Updated "else if" to restrict results to people if principal name is given.
    if (StringUtils.isNotBlank(fieldValues.get(KFSPropertyConstants.VENDOR_NUMBER)) || StringUtils.isNotBlank(fieldValues.get(KFSPropertyConstants.VENDOR_NAME)) || (StringUtils.isNotBlank(payeeTypeCode) && PdpConstants.PayeeIdTypeCodes.VENDOR_ID.equals(payeeTypeCode))) {
        searchResults.addAll(this.getVendorsAsPayees(fieldValues));
    } else if (StringUtils.isNotBlank(fieldValues.get(KIMPropertyConstants.Person.EMPLOYEE_ID)) || StringUtils.isNotBlank(fieldValues.get(KIMPropertyConstants.Person.ENTITY_ID)) || StringUtils.isNotBlank(fieldValues.get(KIMPropertyConstants.Person.PRINCIPAL_NAME)) || (StringUtils.isNotBlank(payeeTypeCode) && (PdpConstants.PayeeIdTypeCodes.EMPLOYEE.equals(payeeTypeCode) || PdpConstants.PayeeIdTypeCodes.ENTITY.equals(payeeTypeCode)))) {
        searchResults.addAll(this.getPersonAsPayees(fieldValues));
    } else {
        searchResults.addAll(this.getVendorsAsPayees(fieldValues));
        searchResults.addAll(this.getPersonAsPayees(fieldValues));
    }
    CollectionIncomplete results = new CollectionIncomplete(searchResults, Long.valueOf(searchResults.size()));
    // sort list if default sort column given
    List<String> defaultSortColumns = getDefaultSortColumns();
    if (defaultSortColumns.size() > 0) {
        Collections.sort(results, new BeanPropertyComparator(getDefaultSortColumns(), true));
    }
    return results;
}
Also used : CollectionIncomplete(org.kuali.kfs.krad.lookup.CollectionIncomplete) BeanPropertyComparator(org.kuali.kfs.krad.util.BeanPropertyComparator) ArrayList(java.util.ArrayList) DisbursementPayee(org.kuali.kfs.fp.businessobject.DisbursementPayee)

Example 5 with BeanPropertyComparator

use of org.kuali.kfs.krad.util.BeanPropertyComparator in project cu-kfs by CU-CommunityApps.

the class CuPayeeACHAccountLookupableHelperServiceImpl method getSearchResultsHelper.

/**
 * Overridden to perform custom searching when a principal name is specified on the search screen.
 *
 * @see org.kuali.kfs.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean)
 */
@SuppressWarnings("unchecked")
@Override
protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
    if (StringUtils.isNotBlank(fieldValues.get(CUPdpPropertyConstants.PAYEE_PRINCIPAL_NAME))) {
        List<PayeeACHAccount> results = null;
        // Search for people with the given principal name(s), in a manner that respects lookup criteria Strings.
        List<Person> people = personService.findPeople(Collections.singletonMap(KIMPropertyConstants.Principal.PRINCIPAL_NAME, fieldValues.get(CUPdpPropertyConstants.PAYEE_PRINCIPAL_NAME)));
        if (!people.isEmpty()) {
            // Get the users' entity IDs and employee IDs for searching.
            List<String> entityIds = new ArrayList<String>();
            List<String> employeeIds = new ArrayList<String>();
            for (Person person : people) {
                entityIds.add(person.getEntityId());
                if (StringUtils.isNotBlank(person.getEmployeeId())) {
                    employeeIds.add(person.getEmployeeId());
                }
            }
            // Create a map without blank values and with all encrypted values decrypted, similar to the ancestor class's logic.
            Map<String, String> finalFieldValues = new HashMap<String, String>();
            for (Map.Entry<String, String> entry : fieldValues.entrySet()) {
                // Only add non-blank values.
                if (StringUtils.isBlank(entry.getValue())) {
                // Do nothing.
                } else if (entry.getValue().endsWith(EncryptionService.ENCRYPTION_POST_PREFIX)) {
                    // Decrypt encrypted values accordingly, as in the ancestor class.
                    String newValue = StringUtils.removeEnd(entry.getValue(), EncryptionService.ENCRYPTION_POST_PREFIX);
                    if (getEncryptionService().isEnabled()) {
                        try {
                            newValue = getEncryptionService().decrypt(newValue);
                        } catch (GeneralSecurityException e) {
                            throw new RuntimeException("Error decrypting Payee ACH Account attribute value", e);
                        }
                    }
                    finalFieldValues.put(entry.getKey(), newValue);
                } else {
                    finalFieldValues.put(entry.getKey(), entry.getValue());
                }
            }
            // Remove "payeePrincipalName" from the map, along with any hidden or non-BO-property-related entries (like back location).
            LookupUtils.removeHiddenCriteriaFields(getBusinessObjectClass(), finalFieldValues);
            finalFieldValues.remove(CUPdpPropertyConstants.PAYEE_PRINCIPAL_NAME);
            finalFieldValues.remove(KRADConstants.BACK_LOCATION);
            finalFieldValues.remove(KRADConstants.DOC_FORM_KEY);
            finalFieldValues.remove(KRADConstants.REFERENCES_TO_REFRESH);
            // Build the sub-predicate to limit by the entity or employee IDs for the given principal names.
            Predicate principalNameEquivalentPredicate;
            if (employeeIds.isEmpty()) {
                principalNameEquivalentPredicate = PredicateFactory.and(PredicateFactory.equal(PdpPropertyConstants.PAYEE_IDENTIFIER_TYPE_CODE, PayeeIdTypeCodes.ENTITY), PredicateFactory.in(PdpPropertyConstants.PAYEE_ID_NUMBER, entityIds.toArray(new String[entityIds.size()])));
            } else {
                principalNameEquivalentPredicate = PredicateFactory.or(PredicateFactory.and(PredicateFactory.equal(PdpPropertyConstants.PAYEE_IDENTIFIER_TYPE_CODE, PayeeIdTypeCodes.ENTITY), PredicateFactory.in(PdpPropertyConstants.PAYEE_ID_NUMBER, entityIds.toArray(new String[entityIds.size()]))), PredicateFactory.and(PredicateFactory.equal(PdpPropertyConstants.PAYEE_IDENTIFIER_TYPE_CODE, PayeeIdTypeCodes.EMPLOYEE), PredicateFactory.in(PdpPropertyConstants.PAYEE_ID_NUMBER, employeeIds.toArray(new String[employeeIds.size()]))));
            }
            // Build the criteria and run the search.
            QueryByCriteria.Builder crit = QueryByCriteria.Builder.create();
            if (!unbounded) {
                crit.setMaxResults(LookupUtils.getSearchResultsLimit(getBusinessObjectClass()));
            }
            if (!finalFieldValues.isEmpty()) {
                crit.setPredicates(PredicateUtils.convertMapToPredicate(finalFieldValues), principalNameEquivalentPredicate);
            } else {
                crit.setPredicates(principalNameEquivalentPredicate);
            }
            results = criteriaLookupService.lookup(getBusinessObjectClass(), crit.build()).getResults();
            // Move results to a mutable list, since the result list from CriteriaLookupService is immutable.
            results = new ArrayList<PayeeACHAccount>(results);
            // Sort results accordingly using code from the ancestor class's version of the method.
            List<String> defaultSortColumns = getDefaultSortColumns();
            if (defaultSortColumns.size() > 0) {
                Collections.sort(results, new BeanPropertyComparator(defaultSortColumns, true));
            }
        }
        // If no people were found with the given principal names, then return an empty list accordingly; otherwise, return the results.
        return (results != null) ? results : new ArrayList<PayeeACHAccount>();
    } else {
        // If principal name is not specified, then do the normal superclass processing.
        return super.getSearchResultsHelper(fieldValues, unbounded);
    }
}
Also used : HashMap(java.util.HashMap) BeanPropertyComparator(org.kuali.kfs.krad.util.BeanPropertyComparator) PayeeACHAccount(org.kuali.kfs.pdp.businessobject.PayeeACHAccount) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) Predicate(org.kuali.rice.core.api.criteria.Predicate) QueryByCriteria(org.kuali.rice.core.api.criteria.QueryByCriteria) Person(org.kuali.rice.kim.api.identity.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BeanPropertyComparator (org.kuali.kfs.krad.util.BeanPropertyComparator)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 CollectionIncomplete (org.kuali.kfs.krad.lookup.CollectionIncomplete)2 GeneralSecurityException (java.security.GeneralSecurityException)1 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)1 DisbursementPayee (org.kuali.kfs.fp.businessobject.DisbursementPayee)1 LaborLedgerObject (org.kuali.kfs.integration.ld.LaborLedgerObject)1 Row (org.kuali.kfs.kns.web.ui.Row)1 AccountStatusCurrentFunds (org.kuali.kfs.module.ld.businessobject.AccountStatusCurrentFunds)1 July1PositionFunding (org.kuali.kfs.module.ld.businessobject.July1PositionFunding)1 LaborObject (org.kuali.kfs.module.ld.businessobject.LaborObject)1 PayeeACHAccount (org.kuali.kfs.pdp.businessobject.PayeeACHAccount)1 Predicate (org.kuali.rice.core.api.criteria.Predicate)1 QueryByCriteria (org.kuali.rice.core.api.criteria.QueryByCriteria)1 BooleanFormatter (org.kuali.rice.core.web.format.BooleanFormatter)1 Document (org.kuali.rice.kew.api.document.Document)1 DocumentSearchCriteria (org.kuali.rice.kew.api.document.search.DocumentSearchCriteria)1