Search in sources :

Example 76 with Person

use of org.kuali.kfs.kim.api.identity.Person 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.kfs.core.api.criteria.Predicate) QueryByCriteria(org.kuali.kfs.core.api.criteria.QueryByCriteria) Person(org.kuali.kfs.kim.api.identity.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Example 77 with Person

use of org.kuali.kfs.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class CuPaymentFileServiceImpl method updatePaymentFieldsForEmployeePayee.

private void updatePaymentFieldsForEmployeePayee(PaymentFileLoad paymentFile, PaymentGroup paymentGroup) {
    LOG.debug("updatePaymentFieldsForEmployeePayee, entering");
    if (cuPdpEmployeeService.shouldPayeeBeProcessedAsEmployeeForThisCustomer(paymentFile)) {
        Person employee = personService.getPersonByEmployeeId(paymentGroup.getPayeeId());
        LOG.debug("updatePaymentFieldsForEmployeePayee, processing payee as emoployee: " + employee.getName());
        updatePayeeAddressFieldsFromPerson(paymentGroup, employee);
        paymentGroup.setEmployeeIndicator(true);
    }
}
Also used : Person(org.kuali.kfs.kim.api.identity.Person)

Example 78 with Person

use of org.kuali.kfs.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class CuDisbursementPayeeLookupableHelperServiceImplTest method testLookupAlumni.

public void testLookupAlumni() {
    List alumniResults = unitTestSqlDao.sqlSelect(alumniSql);
    assertFalse("alumni query didn't return any results, which is just wrong", alumniResults.isEmpty());
    HashMap alumniResult = (HashMap) alumniResults.get(0);
    String entityId = (String) alumniResult.get("DV_PAYEE_ID_NBR");
    assertTrue("couldn't get entityId from query results", StringUtils.isNotBlank(entityId));
    List<Person> people = personService.findPeople(Collections.singletonMap(KIMPropertyConstants.Person.ENTITY_ID, entityId));
    assertFalse("couldn't find a person for entityId " + entityId, people.isEmpty());
    Person alumni = people.get(0);
    Map<String, String> fieldValues = new LinkedHashMap();
    fieldValues.put(KIMPropertyConstants.Person.PRINCIPAL_NAME, alumni.getPrincipalName());
    validateSearch("Alumni", fieldValues);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Person(org.kuali.kfs.kim.api.identity.Person) LinkedHashMap(java.util.LinkedHashMap)

Example 79 with Person

use of org.kuali.kfs.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class CuDisbursementVoucherEmployeeInformationValidation method validate.

public boolean validate(AttributedDocumentEvent event) {
    LOG.debug("validate start");
    boolean isValid = true;
    CuDisbursementVoucherDocument document = (CuDisbursementVoucherDocument) getAccountingDocumentForValidation();
    DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
    if (!payeeDetail.isEmployee() || payeeDetail.isVendor() || !(document.getDocumentHeader().getWorkflowDocument().isInitiated() || document.getDocumentHeader().getWorkflowDocument().isSaved())) {
        return true;
    }
    String employeeId = payeeDetail.getDisbVchrPayeeIdNumber();
    Person employee = personService.getPersonByEmployeeId(employeeId);
    MessageMap errors = GlobalVariables.getMessageMap();
    errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
    WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
    boolean stateIsInitiated = workflowDocument.isInitiated() || workflowDocument.isSaved();
    if (ObjectUtils.isNull(employee)) {
        employee = personService.getPerson(employeeId);
    } else {
        if (!KFSConstants.EMPLOYEE_ACTIVE_STATUS.equals(employee.getEmployeeStatusCode()) && !CUKFSConstants.EMPLOYEE_RETIRED_STATUS.equals(employee.getEmployeeStatusCode())) {
            // If employee is found, then check that employee is active or retired if the doc has not already been routed.
            if (stateIsInitiated) {
                String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
                errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_INACTIVE, label);
                isValid = false;
            }
        }
    }
    // check existence of employee
    if (employee == null) {
        // If employee is not found, report existence error
        String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
        errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_EXISTENCE, label);
        isValid = false;
    }
    errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
    return isValid;
}
Also used : CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) WorkflowDocument(org.kuali.kfs.kew.api.WorkflowDocument) DisbursementVoucherPayeeDetail(org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail) Person(org.kuali.kfs.kim.api.identity.Person) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 80 with Person

use of org.kuali.kfs.kim.api.identity.Person in project cu-kfs by CU-CommunityApps.

the class SecurityRequestDocumentServiceImpl method initiateSecurityRequestDocument.

public void initiateSecurityRequestDocument(SecurityRequestDocument document, Person user) {
    LOG.info("initiateSecurityRequestDocument() Preparing security request document: " + document.getDocumentNumber());
    String principalId = document.getPrincipalId();
    if (StringUtils.isBlank(principalId)) {
        throw new RuntimeException("Principal id not set for new Security Request Document");
    } else if (document.getSecurityGroupId() == null) {
        throw new RuntimeException("Security group id not set for new Security Request Document");
    }
    Person person = personService.getPerson(principalId);
    if (person != null) {
        document.setRequestPerson(person);
        document.setPrimaryDepartmentCode(person.getPrimaryDepartmentCode());
    } else {
        LOG.error("initiateSecurityRequestDocument() Unable to find person record for principal id: " + principalId);
        throw new RuntimeException("Error preparing document: Unable to find person record for principal id: " + principalId);
    }
    buildSecurityRequestRoles(document);
}
Also used : Person(org.kuali.kfs.kim.api.identity.Person)

Aggregations

Person (org.kuali.kfs.kim.api.identity.Person)84 ArrayList (java.util.ArrayList)11 PersonService (org.kuali.kfs.kim.api.identity.PersonService)11 HashMap (java.util.HashMap)9 Note (org.kuali.kfs.krad.bo.Note)9 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)8 WorkflowDocument (org.kuali.kfs.kew.api.WorkflowDocument)6 AdHocRoutePerson (org.kuali.kfs.krad.bo.AdHocRoutePerson)6 DateTimeService (org.kuali.kfs.core.api.datetime.DateTimeService)5 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)5 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)5 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)4 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)4 CustomerProfile (org.kuali.kfs.pdp.businessobject.CustomerProfile)4 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)3 PayeeACHAccount (org.kuali.kfs.pdp.businessobject.PayeeACHAccount)3 Bank (org.kuali.kfs.sys.businessobject.Bank)3 ChartOrgHolder (org.kuali.kfs.sys.businessobject.ChartOrgHolder)3 AccountingXmlDocumentNote (edu.cornell.kfs.fp.batch.xml.AccountingXmlDocumentNote)2 CuDisbursementPayee (edu.cornell.kfs.fp.businessobject.CuDisbursementPayee)2