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);
}
}
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);
}
}
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);
}
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;
}
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);
}
Aggregations