use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.
the class VendorRule method validateContracts.
private boolean validateContracts(VendorDetail vendorDetail) {
boolean success = true;
int vendorPos = 0;
List<VendorContract> vendorContracts = vendorDetail.getVendorContracts();
for (VendorContract vendorContract : vendorContracts) {
List<VendorContractOrganization> organizations = vendorContract.getVendorContractOrganizations();
List<VendorContractOrganization> organizationCopy = new ArrayList<>(organizations);
for (VendorContractOrganization organization : organizations) {
String chartCode = organization.getChartOfAccountsCode();
String organizationCode = organization.getOrganizationCode();
if (StringUtils.isNotEmpty(chartCode) && StringUtils.isNotEmpty(organizationCode)) {
int counter = 0;
int organizationPos = 0;
for (VendorContractOrganization org : organizationCopy) {
if (chartCode.equalsIgnoreCase(org.getChartOfAccountsCode()) && organizationCode.equalsIgnoreCase(org.getOrganizationCode())) {
if (counter++ != 0) {
organizationCopy.remove(organization);
putFieldError(VendorPropertyConstants.VENDOR_CONTRACT + "[" + vendorPos + "]." + VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION + "[" + organizationPos + "]." + VendorPropertyConstants.VENDOR_CUSTOMER_NUMBER_CHART_OF_ACCOUNTS_CODE, VendorKeyConstants.ERROR_DUPLICATE_ENTRY_NOT_ALLOWED, chartCode + " " + organizationCode);
success = false;
break;
}
}
organizationPos++;
}
}
vendorPos++;
}
}
return success;
}
use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.
the class VendorRule method processCustomAddCollectionLineBusinessRules.
/**
* Validates business rules for VendorDetail document collection add lines. Add lines are the initial lines on a
* collections, i.e. the ones next to the "Add" button
*/
@Override
public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
boolean success = true;
// this incoming bo needs to be refreshed because it doesn't have its subobjects setup
bo.refreshNonUpdateableReferences();
if (bo instanceof VendorAddress) {
VendorAddress address = (VendorAddress) bo;
success = checkAddressCountryEmptyStateZip(address);
}
if (bo instanceof VendorContract) {
VendorContract contract = (VendorContract) bo;
success &= validateVendorContractBeginEndDates(contract);
success &= processContractB2BValidation(contract, -1);
}
if (bo instanceof VendorContractOrganization) {
VendorContractOrganization contractOrg = (VendorContractOrganization) bo;
success &= validateVendorContractOrganization(contractOrg, 0);
}
if (bo instanceof VendorCustomerNumber) {
VendorCustomerNumber customerNumber = (VendorCustomerNumber) bo;
success &= validateVendorCustomerNumber(customerNumber);
}
if (bo instanceof VendorDefaultAddress) {
VendorDefaultAddress defaultAddress = (VendorDefaultAddress) bo;
String parentName = StringUtils.substringBeforeLast(collectionName, ".");
VendorAddress parent = (VendorAddress) ObjectUtils.getPropertyValue(this.getNewBo(), parentName);
VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
success &= checkDefaultAddressCampus(vendorDetail, defaultAddress, parent);
}
if (bo instanceof VendorCommodityCode) {
VendorCommodityCode commodityCode = (VendorCommodityCode) bo;
String purchasingCommodityCode = commodityCode.getPurchasingCommodityCode();
boolean found = ObjectUtils.isNotNull(commodityCode) && StringUtils.isNotBlank(purchasingCommodityCode) && checkVendorCommodityCode(commodityCode);
if (!found) {
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.PURCHASING_COMMODITY_CODE, KFSKeyConstants.ERROR_EXISTENCE, purchasingCommodityCode);
}
success &= found;
}
return success;
}
use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.
the class VendorRule method validateVendorContractPOLimitAndExcludeFlagCombination.
/**
* Validates that the proper combination of Exclude Indicator and APO Amount is present on a vendor contract. Do
* not perform this validation on Contract add line as the user cannot currently enter the sub-collection of
* contract-orgs so we should not force this until the document is submitted. The rules are : 1. Must enter a
* Default APO Limit or at least one organization with an APO Amount. 2. If the Exclude Indicator for an
* organization is N, an organization APO Amount is required. 3. If the Exclude Indicator for an organization is
* Y, the organization APO Amount is not allowed.
*
* @param contract VendorContract
* @return boolean true if the proper combination of Exclude Indicator and APO Amount is present, otherwise false.
*/
protected boolean validateVendorContractPOLimitAndExcludeFlagCombination(VendorContract contract) {
boolean valid = true;
boolean NoOrgHasApoLimit = true;
List<VendorContractOrganization> organizations = contract.getVendorContractOrganizations();
if (ObjectUtils.isNotNull(organizations)) {
int organizationCounter = 0;
for (VendorContractOrganization organization : organizations) {
if (ObjectUtils.isNotNull(organization.getVendorContractPurchaseOrderLimitAmount())) {
NoOrgHasApoLimit = false;
}
valid = validateVendorContractOrganization(organization, organizationCounter);
organizationCounter++;
}
}
if (NoOrgHasApoLimit && ObjectUtils.isNull(contract.getOrganizationAutomaticPurchaseOrderLimit())) {
// Rule #1 in the above java doc has been violated.
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_DEFAULT_APO_LIMIT, VendorKeyConstants.ERROR_VENDOR_CONTRACT_NO_APO_LIMIT);
valid = false;
}
return valid;
}
use of org.kuali.kfs.vnd.businessobject.VendorContractOrganization in project cu-kfs by CU-CommunityApps.
the class VendorRule method validateVendorContractOrganization.
/**
* Validates a vendor contract organization. The rules are : 1. If the Exclude Indicator for the organization is N,
* an organization APO Amount is required. 2. If the Exclude Indicator for the organization is Y, an organization
* APO Amount is not allowed. 3. The chart and org for the organization must exist in the database.
*
* @param organization VendorContractOrganization
* @return boolean true if these three rules are passed, otherwise false.
*/
protected boolean validateVendorContractOrganization(VendorContractOrganization organization, int counter) {
boolean valid = true;
List<String> previousErrorPaths = GlobalVariables.getMessageMap().getErrorPath();
String errorPath = VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION + "[" + counter + "]";
boolean shouldAddToErrorPath = true;
// path anymore.
for (String previous : previousErrorPaths) {
if (previous.startsWith(KRADConstants.ADD_PREFIX)) {
shouldAddToErrorPath = false;
break;
}
}
if (shouldAddToErrorPath) {
GlobalVariables.getMessageMap().addToErrorPath(errorPath);
}
boolean isExcluded = organization.isVendorContractExcludeIndicator();
if (isExcluded) {
if (ObjectUtils.isNotNull(organization.getVendorContractPurchaseOrderLimitAmount())) {
// Rule #2 in the above java doc has been violated.
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_APO_LIMIT, VendorKeyConstants.ERROR_VENDOR_CONTRACT_ORG_EXCLUDED_WITH_APO_LIMIT);
valid = false;
}
} else {
// isExcluded = false
if (ObjectUtils.isNull(organization.getVendorContractPurchaseOrderLimitAmount())) {
// Rule #1 in the above java doc has been violated.
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_APO_LIMIT, VendorKeyConstants.ERROR_VENDOR_CONTRACT_ORG_NOT_EXCLUDED_NO_APO_LIMIT);
valid = false;
}
}
// The chart and org must exist in the database.
String chartOfAccountsCode = organization.getChartOfAccountsCode();
String orgCode = organization.getOrganizationCode();
if (StringUtils.isNotBlank(chartOfAccountsCode) && StringUtils.isNotBlank(orgCode)) {
Map<String, String> chartOrgMap = new HashMap<>();
chartOrgMap.put("chartOfAccountsCode", chartOfAccountsCode);
if (getBusinessObjectService().countMatching(Chart.class, chartOrgMap) < 1) {
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.ERROR_EXISTENCE, chartOfAccountsCode);
valid = false;
}
chartOrgMap.put("organizationCode", orgCode);
if (getBusinessObjectService().countMatching(Organization.class, chartOrgMap) < 1) {
GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_CODE, KFSKeyConstants.ERROR_EXISTENCE, orgCode);
valid = false;
}
}
if (shouldAddToErrorPath && organization.getVendorContractPurchaseOrderLimitAmount() != null) {
BusinessObjectEntry entry = boDictionaryService.getBusinessObjectEntry(VendorContractOrganization.class.getName());
AttributeDefinition attributeDefinition = entry.getAttributeDefinition(VendorPropertyConstants.VENDOR_CONTRACT_ORGANIZATION_APO_LIMIT);
valid &= validateAPOAmount(organization.getVendorContractPurchaseOrderLimitAmount(), attributeDefinition);
}
if (shouldAddToErrorPath) {
GlobalVariables.getMessageMap().removeFromErrorPath(errorPath);
}
return valid;
}
Aggregations