Search in sources :

Example 6 with PayeeACHAccount

use of org.kuali.kfs.pdp.businessobject.PayeeACHAccount in project cu-kfs by CU-CommunityApps.

the class PayeeACHAccountExtractServiceImpl method getResolvedEmailBody.

/**
 * Helper method for replacing "[propertyName]"-style placeholders in the email body
 * with actual property values from the given Payee ACH Account, in addition to
 * replacing literal "\n" with newline characters accordingly. Potentially sensitive
 * placeholders will be replaced with empty text except for the bank name.
 * Placeholders referencing properties with value finders will print the matching key/value
 * label instead. Any placeholders that could not be resolved successfully will be replaced
 * with empty text.
 */
@SuppressWarnings("deprecation")
protected String getResolvedEmailBody(PayeeACHAccount achAccount, String emailBody) {
    Pattern placeholderPattern = Pattern.compile("\\[([^\\]]+)\\]");
    Matcher emailMatcher = placeholderPattern.matcher(emailBody.replace("\\n", "\n"));
    // Use a StringBuffer here, due to the Matcher class not supporting StringBuilder for appending operations.
    StringBuffer resolvedEmailBody = new StringBuffer(emailBody.length());
    // Replace all placeholders one by one. The pattern has a single group in it to help with retrieving just the property name and not the brackets.
    while (emailMatcher.find()) {
        String propertyName = emailMatcher.group(1);
        AttributeDefinition attDefinition = dataDictionaryService.getAttributeDefinition(PayeeACHAccount.class.getName(), propertyName);
        String replacement;
        // Make sure property exists in data dictionary and is either not potentially sensitive or is the safe-to-use bank name property.
        if (attDefinition != null) {
            AttributeSecurity attSecurity = attDefinition.getAttributeSecurity();
            if (attSecurity != null && (attSecurity.isHide() || attSecurity.isMask() || attSecurity.isPartialMask()) && !CUPdpConstants.PAYEE_ACH_ACCOUNT_EXTRACT_BANK_NAME_PROPERTY.equals(propertyName)) {
                // Replace potentially-sensitive placeholders with an empty string.
                replacement = KFSConstants.EMPTY_STRING;
            } else {
                // Replace the placeholder with the property value, or with an empty string if null or invalid.
                try {
                    Object propertyValue = ObjectPropertyUtils.getPropertyValue(achAccount, propertyName);
                    replacement = ObjectUtils.isNotNull(propertyValue) ? propertyValue.toString() : KFSConstants.EMPTY_STRING;
                    // If a values finder is defined, use the label from the matching key/value pair instead.
                    if (attDefinition.getControl() != null && StringUtils.isNotBlank(attDefinition.getControl().getValuesFinderClass())) {
                        KeyValuesFinder valuesFinder = (KeyValuesFinder) Class.forName(attDefinition.getControl().getValuesFinderClass()).newInstance();
                        String key = replacement;
                        replacement = valuesFinder.getKeyLabel(key);
                        // If the key is in the label, then remove it from the label.
                        if (attDefinition.getControl().getIncludeKeyInLabel() != null && attDefinition.getControl().getIncludeKeyInLabel().booleanValue()) {
                            // Check for key-and-dash or key-in-parentheses, and remove them if found.
                            // (Former can come from BO values finders, latter is only for custom values finders that append the keys as such.)
                            String keyAndDashPrefix = key + " - ";
                            String keyInParenSuffix = " (" + key + ")";
                            replacement = replacement.startsWith(keyAndDashPrefix) ? StringUtils.substringAfter(replacement, keyAndDashPrefix) : (replacement.endsWith(keyInParenSuffix) ? StringUtils.substringBeforeLast(replacement, keyInParenSuffix) : replacement);
                        }
                    }
                    // Because of the way that Matcher.appendReplacement() works, escape the special replacement characters accordingly.
                    if (replacement.indexOf('\\') != -1) {
                        replacement = replacement.replace("\\", "\\\\");
                    }
                    if (replacement.indexOf('$') != -1) {
                        replacement = replacement.replace("$", "\\$");
                    }
                } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | RuntimeException e) {
                    replacement = KFSConstants.EMPTY_STRING;
                }
            }
        } else {
            // Replace non-data-dictionary-defined property placeholders with an empty string.
            replacement = KFSConstants.EMPTY_STRING;
        }
        emailMatcher.appendReplacement(resolvedEmailBody, replacement);
    }
    emailMatcher.appendTail(resolvedEmailBody);
    return resolvedEmailBody.toString();
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PayeeACHAccount(org.kuali.kfs.pdp.businessobject.PayeeACHAccount) KeyValuesFinder(org.kuali.kfs.krad.keyvalues.KeyValuesFinder) AttributeDefinition(org.kuali.kfs.krad.datadictionary.AttributeDefinition) AttributeSecurity(org.kuali.kfs.krad.datadictionary.AttributeSecurity)

Example 7 with PayeeACHAccount

use of org.kuali.kfs.pdp.businessobject.PayeeACHAccount in project cu-kfs by CU-CommunityApps.

the class PayeeACHAccountExtractServiceImpl method processACHBatchDetail.

/**
 * Processes a single ACH batch detail, and routes a Payee ACH Account maintenance document accordingly.
 */
protected String processACHBatchDetail(PayeeACHAccountExtractDetail achDetail) {
    LOG.info("processACHBatchDetail: Starting processACHBatchDetail for: " + achDetail.getLogData());
    String processingError = null;
    Person payee = personService.getPersonByPrincipalName(achDetail.getNetID());
    processingError = validateACHBatchDetail(achDetail, payee);
    if (StringUtils.isNotBlank(processingError)) {
        return processingError;
    }
    // Check for existing ACH accounts.
    PayeeACHAccount entityAccount = achService.getAchInformation(PayeeIdTypeCodes.ENTITY, payee.getEntityId(), getDirectDepositTransactionType());
    PayeeACHAccount employeeAccount = achService.getAchInformation(PayeeIdTypeCodes.EMPLOYEE, payee.getEmployeeId(), getDirectDepositTransactionType());
    // Add or update Entity ID account.
    if (ObjectUtils.isNull(entityAccount)) {
        processingError = addACHAccount(payee, achDetail, PayeeIdTypeCodes.ENTITY);
        if (ObjectUtils.isNull(processingError)) {
            LOG.info("processACHBatchDetail: Created new ACH Account of Entity type for payee " + payee.getPrincipalName());
        } else {
            return processingError;
        }
    } else {
        processingError = updateACHAccountIfNecessary(payee, achDetail, entityAccount);
        if (ObjectUtils.isNull(processingError)) {
            LOG.info("processACHBatchDetail: Any necessary update processing performed to ACH Account of Entity type for payee " + payee.getPrincipalName());
        } else {
            return processingError;
        }
    }
    // Add or update Employee ID account.
    if (ObjectUtils.isNull(employeeAccount)) {
        processingError = addACHAccount(payee, achDetail, PayeeIdTypeCodes.EMPLOYEE);
        if (ObjectUtils.isNull(processingError)) {
            LOG.info("processACHBatchDetail: Created new ACH Account of Employee type for payee " + payee.getPrincipalName());
        } else {
            return processingError;
        }
    } else {
        processingError = updateACHAccountIfNecessary(payee, achDetail, employeeAccount);
        if (ObjectUtils.isNull(processingError)) {
            LOG.info("processACHBatchDetail: Any necessary update processing performed to ACH Account of Employee type for payee " + payee.getPrincipalName());
        } else {
            return processingError;
        }
    }
    return KFSConstants.EMPTY_STRING;
}
Also used : PayeeACHAccount(org.kuali.kfs.pdp.businessobject.PayeeACHAccount) Person(org.kuali.rice.kim.api.identity.Person)

Example 8 with PayeeACHAccount

use of org.kuali.kfs.pdp.businessobject.PayeeACHAccount 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)

Example 9 with PayeeACHAccount

use of org.kuali.kfs.pdp.businessobject.PayeeACHAccount in project cu-kfs by CU-CommunityApps.

the class PayeeACHAccountExtractServiceImplTest method createEmployeePayeeACHAccountForAlternateUser.

private PayeeACHAccount createEmployeePayeeACHAccountForAlternateUser() {
    PayeeACHAccount achAccount = new PayeeACHAccount();
    achAccount.setPayeeIdentifierTypeCode(PayeeIdTypeCodes.EMPLOYEE);
    achAccount.setPayeeIdNumber(TEST_ALT_EMPLOYEEID);
    achAccount.setAchTransactionType(KFS_DIRECT_DEPOSIT_TYPE);
    achAccount.setBankRoutingNumber(TEST_ALT_BANK_ROUTING_NUMBER);
    achAccount.setBankAccountTypeCode("32PPD");
    achAccount.setBankAccountNumber(TEST_ALT_ACCOUNT_NUMBER);
    achAccount.setBankRouting(createBank(TEST_ALT_BANK_ROUTING_NUMBER, TEST_ALT_BANK_NAME));
    return achAccount;
}
Also used : PayeeACHAccount(org.kuali.kfs.pdp.businessobject.PayeeACHAccount)

Example 10 with PayeeACHAccount

use of org.kuali.kfs.pdp.businessobject.PayeeACHAccount in project cu-kfs by CU-CommunityApps.

the class PayeeACHAccountExtractServiceImplTest method testEmailBodyPlaceholderResolution.

@Test
public void testEmailBodyPlaceholderResolution() throws Exception {
    // NOTE: We expect that all potentially-sensitive placeholders except bank name will be replaced with empty text.
    PayeeACHAccount achAccount = createEmployeePayeeACHAccountForAlternateUser();
    String expectedBody = MessageFormat.format(EMAIL_STRING_AS_FORMAT, achAccount.getPayeeIdentifierTypeCode(), achAccount.getPayeeIdNumber(), PERSONAL_SAVINGS_ACCOUNT_TYPE_LABEL, achAccount.getBankRouting().getBankName());
    String actualBody = payeeACHAccountExtractService.getResolvedEmailBody(achAccount, UNRESOLVED_EMAIL_STRING);
    assertEquals("Email body placeholders and special characters were not resolved properly", expectedBody, actualBody);
}
Also used : PayeeACHAccount(org.kuali.kfs.pdp.businessobject.PayeeACHAccount) Test(org.junit.Test)

Aggregations

PayeeACHAccount (org.kuali.kfs.pdp.businessobject.PayeeACHAccount)10 Person (org.kuali.rice.kim.api.identity.Person)3 PayeeACHAccountMaintainableImpl (org.kuali.kfs.pdp.document.PayeeACHAccountMaintainableImpl)2 PayeeACHAccountExtractStep (edu.cornell.kfs.pdp.batch.PayeeACHAccountExtractStep)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 MessagingException (javax.mail.MessagingException)1 Test (org.junit.Test)1 AttributeDefinition (org.kuali.kfs.krad.datadictionary.AttributeDefinition)1 AttributeSecurity (org.kuali.kfs.krad.datadictionary.AttributeSecurity)1 InvalidAddressException (org.kuali.kfs.krad.exception.InvalidAddressException)1 ValidationException (org.kuali.kfs.krad.exception.ValidationException)1 KeyValuesFinder (org.kuali.kfs.krad.keyvalues.KeyValuesFinder)1