use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.
the class CuVendorRule method processAddCollectionLineBusinessRules.
public boolean processAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
boolean success = super.processAddCollectionLineBusinessRules(document, collectionName, bo);
if (collectionName.equals(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES)) {
VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
VendorHeader vendorHeader = vendorDetail.getVendorHeader();
List<VendorSupplierDiversity> vendorSupplierDiversities = vendorHeader.getVendorSupplierDiversities();
if (vendorSupplierDiversities.size() > 0) {
int i = 0;
for (VendorSupplierDiversity vendor : vendorSupplierDiversities) {
if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate() == null) {
success = false;
putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_BLANK);
} else if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate().before(new Date())) {
// Only check expiration date on new vendors
if (document.isNew()) {
success = false;
putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_IN_PAST);
}
}
i++;
}
}
if (!success) {
return success;
}
}
if (collectionName.equals("vendorCommodities")) {
VendorCommodityCode codeToBeValidated = (VendorCommodityCode) bo;
CommodityCode persistedCommodity = commodityCodeService.getByPrimaryId(codeToBeValidated.getPurchasingCommodityCode());
if (persistedCommodity == null) {
// a commodity code entered by a user does not exist
putFieldError("add.vendorCommodities.purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DOES_NOT_EXIST, codeToBeValidated.getPurchasingCommodityCode());
success = false;
}
if (codeToBeValidated.isCommodityDefaultIndicator()) {
VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
List<VendorCommodityCode> vendorCommodities = vendorDetail.getVendorCommodities();
Iterator<VendorCommodityCode> commodities = vendorCommodities.iterator();
int indice = 0;
while (commodities.hasNext()) {
VendorCommodityCode commodity = (VendorCommodityCode) commodities.next();
if (commodity.isCommodityDefaultIndicator()) {
// more than one "default" commodity code has been specified
putFieldError("add.vendorCommodities.commodityDefaultIndicator", CUVendorKeyConstants.ERROR_DEFAULT_VENDOR_COMMODITY_CODE_ALREADY_EXISTS, Integer.toString(indice));
success = false;
}
indice++;
}
}
VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
boolean commodityAlreadyAssignedToThisVendor = false;
Iterator<VendorCommodityCode> codes = vendorDetail.getVendorCommodities().iterator();
while (codes.hasNext()) {
VendorCommodityCode vcc = codes.next();
if (vcc.getPurchasingCommodityCode().equals(codeToBeValidated.getPurchasingCommodityCode())) {
commodityAlreadyAssignedToThisVendor = true;
break;
}
}
if (commodityAlreadyAssignedToThisVendor) {
putFieldError("add.vendorCommodities.purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_ALREADY_ASSIGNED_TO_VENDOR);
success = false;
}
return success;
}
return success;
}
use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.
the class CuVendorRule method checkSupplierDiversityExpirationDate.
protected boolean checkSupplierDiversityExpirationDate(MaintenanceDocument document) {
boolean success = true;
VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
VendorHeader vendorHeader = vendorDetail.getVendorHeader();
List<VendorSupplierDiversity> vendorSupplierDiversities = vendorHeader.getVendorSupplierDiversities();
if (vendorSupplierDiversities.size() > 0) {
int i = 0;
for (VendorSupplierDiversity vendor : vendorSupplierDiversities) {
if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate() == null) {
success = false;
putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_BLANK);
} else if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate().before(new Date())) {
// Only check expiration date on new vendors
if (document.isNew()) {
success = false;
putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_IN_PAST);
}
}
i++;
}
}
return success;
}
use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.
the class CuVendorMaintainableImpl method populateGeneratedHerderId.
private void populateGeneratedHerderId(VendorHeader vendorHeader) {
if (vendorHeader.getVendorHeaderGeneratedIdentifier() == null) {
Integer generatedHeaderId = SpringContext.getBean(SequenceAccessorService.class).getNextAvailableSequenceNumber(HEADER_ID_SEQ).intValue();
vendorHeader.setVendorHeaderGeneratedIdentifier(generatedHeaderId.intValue());
((CuVendorHeaderExtension) vendorHeader.getExtension()).setVendorHeaderGeneratedIdentifier(generatedHeaderId);
}
if (CollectionUtils.isNotEmpty(vendorHeader.getVendorSupplierDiversities())) {
for (VendorSupplierDiversity supplierDiversity : vendorHeader.getVendorSupplierDiversities()) {
supplierDiversity.setVendorHeaderGeneratedIdentifier(vendorHeader.getVendorHeaderGeneratedIdentifier());
((CuVendorSupplierDiversityExtension) supplierDiversity.getExtension()).setVendorHeaderGeneratedIdentifier(vendorHeader.getVendorHeaderGeneratedIdentifier());
((CuVendorSupplierDiversityExtension) supplierDiversity.getExtension()).setVendorSupplierDiversityCode(supplierDiversity.getVendorSupplierDiversityCode());
}
}
}
use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.
the class VendorBatchServiceImpl method getVendorSupplierDiversities.
/*
* populate list of vendor batch supplier diversities to vendor supplier diversities
*/
private List<VendorSupplierDiversity> getVendorSupplierDiversities(List<VendorBatchSupplierDiversity> supplierDiversitys) {
List<VendorSupplierDiversity> vendorSupplierDiversitys = new ArrayList<VendorSupplierDiversity>();
if (CollectionUtils.isNotEmpty(supplierDiversitys)) {
for (VendorBatchSupplierDiversity diversity : supplierDiversitys) {
LOG.info("addVendor diversity " + diversity);
VendorSupplierDiversity vDiversity = new VendorSupplierDiversity();
vDiversity.setVendorSupplierDiversityCode(diversity.getVendorSupplierDiversityCode());
if (StringUtils.isNotBlank(diversity.getVendorSupplierDiversityExpirationDate())) {
((CuVendorSupplierDiversityExtension) vDiversity.getExtension()).setVendorSupplierDiversityExpirationDate(new java.sql.Date(getFormatDate(diversity.getVendorSupplierDiversityExpirationDate()).getTime()));
}
vDiversity.setActive(StringUtils.equalsIgnoreCase(YES, diversity.getActive()));
vendorSupplierDiversitys.add(vDiversity);
}
}
return vendorSupplierDiversitys;
}
use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.
the class VendorBatchServiceImpl method updateVendorSupplierDiversitys.
/*
* update existing vendor supplier diversity or create a new one if it does not exist.
*/
private void updateVendorSupplierDiversitys(List<VendorBatchSupplierDiversity> supplierDiversitys, VendorDetail vendor, VendorDetail vDetail) {
ArrayList<VendorSupplierDiversity> vendorSupplierDiversitys = new ArrayList<VendorSupplierDiversity>();
if (CollectionUtils.isNotEmpty(supplierDiversitys)) {
for (VendorBatchSupplierDiversity diversity : supplierDiversitys) {
LOG.info("updateVendor diversity " + diversity);
VendorSupplierDiversity vDiversity = getVendorSupplierDiversity(vDetail.getVendorHeader(), diversity.getVendorSupplierDiversityCode());
boolean isExist = StringUtils.isNotBlank(vDiversity.getVendorSupplierDiversityCode());
vDiversity.setVendorSupplierDiversityCode(diversity.getVendorSupplierDiversityCode());
if (StringUtils.isNotBlank(diversity.getVendorSupplierDiversityExpirationDate())) {
((CuVendorSupplierDiversityExtension) vDiversity.getExtension()).setVendorSupplierDiversityExpirationDate(new java.sql.Date(getFormatDate(diversity.getVendorSupplierDiversityExpirationDate()).getTime()));
}
vDiversity.setActive(StringUtils.equalsIgnoreCase(YES, diversity.getActive()));
if (!isExist) {
vDetail.getVendorHeader().getVendorSupplierDiversities().add(vDiversity);
vendor.getVendorHeader().getVendorSupplierDiversities().add(new VendorSupplierDiversity());
}
}
}
}
Aggregations