Search in sources :

Example 1 with Predicate

use of org.kuali.kfs.core.api.criteria.Predicate in project cu-kfs by CU-CommunityApps.

the class CuVendorRuleBase method validateParentVendorTaxNumber.

/**
 * Overridden so that when an existing vendor tax number is found when trying to add a new parent vendor,
 * the error message will include the existing vendor detail's ID (in payee ID format).
 *
 * @see org.kuali.kfs.vnd.document.validation.impl.VendorRule#validateParentVendorTaxNumber(org.kuali.kfs.vnd.businessobject.VendorDetail)
 */
@SuppressWarnings("deprecation")
@Override
protected boolean validateParentVendorTaxNumber(VendorDetail vendorDetail) {
    boolean isParent = vendorDetail.isVendorParentIndicator();
    // ==== CU Customization: Use criteria API instead, due to limited BO service methods with negative criteria. ====
    List<Predicate> criteria = new ArrayList<Predicate>();
    if (ObjectUtils.isNotNull(vendorDetail.getVendorHeader().getVendorTaxTypeCode()) && ObjectUtils.isNotNull(vendorDetail.getVendorHeader().getVendorTaxNumber())) {
        criteria.add(PredicateFactory.equal(VendorPropertyConstants.VENDOR_TAX_TYPE_CODE, vendorDetail.getVendorHeader().getVendorTaxTypeCode()));
        criteria.add(PredicateFactory.equal(VendorPropertyConstants.VENDOR_TAX_NUMBER, vendorDetail.getVendorHeader().getVendorTaxNumber()));
    } else {
        return true;
    }
    // ==== CU Customization: Use the actual vendor details, not just the count. ====
    List<VendorDetail> existingVendors;
    // negative criteria so that the current vendor is excluded from the search
    if (ObjectUtils.isNotNull(vendorDetail.getVendorHeaderGeneratedIdentifier())) {
        // ==== CU Customization: Use CriteriaLookupService instead, since BO service doesn't allow negative criteria in non-count methods. ====
        criteria.add(PredicateFactory.notEqual(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorDetail.getVendorHeaderGeneratedIdentifier()));
        existingVendors = SpringContext.getBean(CriteriaLookupService.class).lookup(VendorDetail.class, QueryByCriteria.Builder.fromPredicates(criteria.toArray(new Predicate[criteria.size()]))).getResults();
    } else {
        // If this is creating a new vendor, we can't include the header generated id
        // in the negative criteria because it's null, so we'll only look for existing
        // vendors with the same tax # and tax type regardless of the vendor header generated id.
        // ==== CU Customization: Use CriteriaLookupService instead, since BO service doesn't allow negative criteria in non-count methods. ====
        existingVendors = SpringContext.getBean(CriteriaLookupService.class).lookup(VendorDetail.class, QueryByCriteria.Builder.fromPredicates(criteria.toArray(new Predicate[criteria.size()]))).getResults();
    }
    if (!existingVendors.isEmpty()) {
        if (isParent) {
            // ==== CU Customization: Print a different error message that also includes the existing vendor's ID. ====
            if (KFSConstants.SYSTEM_USER.equals(GlobalVariables.getUserSession().getActualPerson().getPrincipalName())) {
                // Only print new message when the actual KFS system user is in place (and not someone backdoored), to keep it specific to batch runs.
                VendorDetail existingVendor = existingVendors.get(0);
                // Parent vendor takes precedence when printing the error message.
                for (int i = 1; !existingVendor.isVendorParentIndicator() && i < existingVendors.size(); i++) {
                    existingVendor = existingVendors.get(i);
                }
                putFieldError(VendorPropertyConstants.VENDOR_TAX_NUMBER, CUVendorKeyConstants.ERROR_VENDOR_TAX_TYPE_AND_NUMBER_COMBO_EXISTS_AND_PRINT_EXISTING, new String[] { existingVendor.getVendorHeaderGeneratedIdentifier().toString(), existingVendor.getVendorDetailAssignedIdentifier().toString() });
            } else {
                // Just use standard KFS-delivered message for general users who are trying to submit a regular vendor maintenance document.
                putFieldError(VendorPropertyConstants.VENDOR_TAX_NUMBER, VendorKeyConstants.ERROR_VENDOR_TAX_TYPE_AND_NUMBER_COMBO_EXISTS);
            }
        } else {
            putFieldError(VendorPropertyConstants.VENDOR_TAX_NUMBER, VendorKeyConstants.ERROR_VENDOR_PARENT_NEEDS_CHANGED);
        }
        return false;
    }
    return true;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) ArrayList(java.util.ArrayList) CriteriaLookupService(org.kuali.kfs.core.api.criteria.CriteriaLookupService) Predicate(org.kuali.kfs.core.api.criteria.Predicate)

Example 2 with Predicate

use of org.kuali.kfs.core.api.criteria.Predicate 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 3 with Predicate

use of org.kuali.kfs.core.api.criteria.Predicate in project cu-kfs by CU-CommunityApps.

the class ResponsibilityServiceImpl method getResponsibilityAction.

private RoleResponsibilityAction getResponsibilityAction(String roleId, String responsibilityId, String roleMemberId) {
    RoleResponsibilityAction result = null;
    // KULRICE-7459: Requisition, PO and its subtype documents are going to final status where they should not.
    // 
    // need to do in 2 steps due to "*" wildcard convention in column data for role member id and role
    // responsibility id.  Well, we could do in 1 step w/ straight SQL, but not w/ Criteria API due to the
    // INNER JOIN automatically created between RoleResponsibility and RoleResponsibilityAction tables.
    final Predicate roleResponsibilityPredicate = PredicateFactory.and(PredicateFactory.equal("responsibilityId", responsibilityId), PredicateFactory.equal("roleId", roleId), PredicateFactory.equal("active", "Y"));
    // First get RoleResponsibilities
    final QueryByCriteria.Builder roleResponsibilityQueryBuilder = QueryByCriteria.Builder.create();
    roleResponsibilityQueryBuilder.setPredicates(roleResponsibilityPredicate);
    final GenericQueryResults<RoleResponsibility> roleResponsibilityResults = criteriaLookupService.lookup(RoleResponsibility.class, roleResponsibilityQueryBuilder.build());
    final List<RoleResponsibility> roleResponsibilities = roleResponsibilityResults.getResults();
    if (!CollectionUtils.isEmpty(roleResponsibilities)) {
        // if there are any...
        // Then query RoleResponsibilityActions based on them
        List<String> roleResponsibilityIds = new ArrayList<>(roleResponsibilities.size());
        for (RoleResponsibility roleResponsibility : roleResponsibilities) {
            roleResponsibilityIds.add(roleResponsibility.getRoleResponsibilityId());
        }
        final Predicate roleResponsibilityActionPredicate = PredicateFactory.or(PredicateFactory.and(PredicateFactory.in("roleResponsibilityId", roleResponsibilityIds.toArray()), PredicateFactory.or(PredicateFactory.equal(org.kuali.kfs.kim.impl.KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId), PredicateFactory.equal(org.kuali.kfs.kim.impl.KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, "*"))), PredicateFactory.and(PredicateFactory.equal("roleResponsibilityId", "*"), PredicateFactory.equal(KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId)));
        final QueryByCriteria.Builder roleResponsibilityActionQueryBuilder = QueryByCriteria.Builder.create();
        roleResponsibilityActionQueryBuilder.setPredicates(roleResponsibilityActionPredicate);
        final GenericQueryResults<RoleResponsibilityAction> roleResponsibilityActionResults = criteriaLookupService.lookup(RoleResponsibilityAction.class, roleResponsibilityActionQueryBuilder.build());
        final List<RoleResponsibilityAction> roleResponsibilityActions = roleResponsibilityActionResults.getResults();
        // seems a little dubious that we are just returning the first result...
        if (!roleResponsibilityActions.isEmpty()) {
            result = roleResponsibilityActions.get(0);
        }
    }
    return result;
}
Also used : RoleResponsibilityAction(org.kuali.kfs.kim.impl.role.RoleResponsibilityAction) QueryByCriteria(org.kuali.kfs.core.api.criteria.QueryByCriteria) ArrayList(java.util.ArrayList) RoleResponsibility(org.kuali.kfs.kim.impl.role.RoleResponsibility) Predicate(org.kuali.kfs.core.api.criteria.Predicate)

Example 4 with Predicate

use of org.kuali.kfs.core.api.criteria.Predicate in project cu-kfs by CU-CommunityApps.

the class ResponsibilityServiceImpl method buildWorkflowResponsibilitiesQueryByCriteria.

private QueryByCriteria buildWorkflowResponsibilitiesQueryByCriteria(String documentTypeName, String exceptionRoutingResponsibilityTemplateName) {
    QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
    Predicate p = PredicateFactory.and(PredicateFactory.equal("template.namespaceCode", KFSConstants.CoreModuleNamespaces.WORKFLOW), PredicateFactory.equal("template.name", exceptionRoutingResponsibilityTemplateName), PredicateFactory.equal("active", "Y"), PredicateFactory.equal("attributes[documentTypeName]", documentTypeName));
    builder.setPredicates(p);
    return builder.build();
}
Also used : QueryByCriteria(org.kuali.kfs.core.api.criteria.QueryByCriteria) Predicate(org.kuali.kfs.core.api.criteria.Predicate)

Aggregations

Predicate (org.kuali.kfs.core.api.criteria.Predicate)4 ArrayList (java.util.ArrayList)3 QueryByCriteria (org.kuali.kfs.core.api.criteria.QueryByCriteria)3 GeneralSecurityException (java.security.GeneralSecurityException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CriteriaLookupService (org.kuali.kfs.core.api.criteria.CriteriaLookupService)1 Person (org.kuali.kfs.kim.api.identity.Person)1 RoleResponsibility (org.kuali.kfs.kim.impl.role.RoleResponsibility)1 RoleResponsibilityAction (org.kuali.kfs.kim.impl.role.RoleResponsibilityAction)1 BeanPropertyComparator (org.kuali.kfs.krad.util.BeanPropertyComparator)1 PayeeACHAccount (org.kuali.kfs.pdp.businessobject.PayeeACHAccount)1 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)1