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.PurapKeyConstants;
19 import org.kuali.ole.module.purap.PurapPropertyConstants;
20 import org.kuali.ole.module.purap.businessobject.PurApItem;
21 import org.kuali.ole.module.purap.businessobject.PurchasingItemBase;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.ole.sys.document.validation.GenericValidation;
24 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25 import org.kuali.rice.kns.service.DataDictionaryService;
26 import org.kuali.rice.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.util.ObjectUtils;
28
29 public class PurchasingItemQuantityValidation extends GenericValidation {
30
31 private PurApItem itemForValidation;
32 private DataDictionaryService dataDictionaryService;
33
34
35
36
37
38 public boolean validate(AttributedDocumentEvent event) {
39 boolean valid = true;
40 PurchasingItemBase purItem = (PurchasingItemBase) itemForValidation;
41 if (purItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && (ObjectUtils.isNull(purItem.getItemQuantity()))) {
42 valid = false;
43 String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(purItem.getClass().getName()).
44 getAttributeDefinition(PurapPropertyConstants.ITEM_QUANTITY).getLabel();
45 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.QUANTITY, OLEKeyConstants.ERROR_REQUIRED, attributeLabel + " in " + purItem.getItemIdentifierString());
46 } else if (purItem.getItemType().isAmountBasedGeneralLedgerIndicator() && ObjectUtils.isNotNull(purItem.getItemQuantity())) {
47 valid = false;
48 String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(purItem.getClass().getName()).
49 getAttributeDefinition(PurapPropertyConstants.ITEM_QUANTITY).getLabel();
50 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.QUANTITY, PurapKeyConstants.ERROR_ITEM_QUANTITY_NOT_ALLOWED, attributeLabel + " in " + purItem.getItemIdentifierString());
51 }
52
53 return valid;
54 }
55
56 public PurApItem getItemForValidation() {
57 return itemForValidation;
58 }
59
60 public void setItemForValidation(PurApItem itemForValidation) {
61 this.itemForValidation = itemForValidation;
62 }
63
64 public DataDictionaryService getDataDictionaryService() {
65 return dataDictionaryService;
66 }
67
68 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
69 this.dataDictionaryService = dataDictionaryService;
70 }
71
72 }