1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.sys.document.validation.GenericValidation;
22 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
23 import org.kuali.ole.vnd.businessobject.CommodityCode;
24 import org.kuali.rice.krad.service.BusinessObjectService;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 public class PurchasingCommodityCodesForDistributionValidation extends GenericValidation {
32
33 private String purchasingCommodityCode;
34 private BusinessObjectService businessObjectService;
35
36 public boolean validate(AttributedDocumentEvent event) {
37 boolean valid = true;
38
39 Map<String, String> fieldValues = new HashMap<String, String>();
40 fieldValues.put(PurapPropertyConstants.ITEM_COMMODITY_CODE, purchasingCommodityCode);
41
42 Collection<CommodityCode> result = (Collection<CommodityCode>) businessObjectService.findMatching(CommodityCode.class, fieldValues);
43 if (result != null && result.size() > 0) {
44 CommodityCode commodityCode = (CommodityCode) (result.iterator().next());
45 if (!commodityCode.isActive()) {
46
47 valid = false;
48 GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PUR_COMMODITY_CODE_INACTIVE, " in distribute commodity code");
49 }
50 } else {
51
52 valid = false;
53 GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PUR_COMMODITY_CODE_INVALID, " in distribute commodity code");
54 }
55 return valid;
56 }
57
58 public String getPurchasingCommodityCode() {
59 return purchasingCommodityCode;
60 }
61
62 public void setPurchasingCommodityCode(String purchasingCommodityCode) {
63 this.purchasingCommodityCode = purchasingCommodityCode;
64 }
65
66 public BusinessObjectService getBusinessObjectService() {
67 return businessObjectService;
68 }
69
70 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
71 this.businessObjectService = businessObjectService;
72 }
73
74 }