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.ItemFields;
19 import org.kuali.ole.module.purap.PurapConstants.ItemTypeCodes;
20 import org.kuali.ole.module.purap.PurapKeyConstants;
21 import org.kuali.ole.module.purap.PurapPropertyConstants;
22 import org.kuali.ole.module.purap.businessobject.PurApItem;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.document.validation.GenericValidation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.rice.kns.service.DataDictionaryService;
27 import org.kuali.rice.krad.util.GlobalVariables;
28 import org.kuali.rice.krad.util.ObjectUtils;
29
30 import java.math.BigDecimal;
31
32 public class PurchasingItemUnitPriceValidation extends GenericValidation {
33
34 private PurApItem itemForValidation;
35 private DataDictionaryService dataDictionaryService;
36
37
38
39
40
41 public boolean validate(AttributedDocumentEvent event) {
42 boolean valid = true;
43 if (itemForValidation.getItemType().isLineItemIndicator()) {
44 if (ObjectUtils.isNull(itemForValidation.getItemUnitPrice())) {
45 valid = false;
46 String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(itemForValidation.getClass().getName()).
47 getAttributeDefinition(PurapPropertyConstants.ITEM_UNIT_PRICE).getLabel();
48 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_UNIT_PRICE, OLEKeyConstants.ERROR_REQUIRED, attributeLabel + " in " + itemForValidation.getItemIdentifierString());
49 }
50 }
51
52 if (ObjectUtils.isNotNull(itemForValidation.getItemUnitPrice())) {
53 if ((BigDecimal.ZERO.compareTo(itemForValidation.getItemUnitPrice()) > 0) && ((!itemForValidation.getItemTypeCode().equals(ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)) && (!itemForValidation.getItemTypeCode().equals(ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)))) {
54
55 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_ITEM_AMOUNT_BELOW_ZERO, ItemFields.UNIT_COST, itemForValidation.getItemIdentifierString());
56 valid = false;
57 } else if ((BigDecimal.ZERO.compareTo(itemForValidation.getItemUnitPrice()) < 0) && ((itemForValidation.getItemTypeCode().equals(ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)) || (itemForValidation.getItemTypeCode().equals(ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)))) {
58
59 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_ITEM_AMOUNT_NOT_BELOW_ZERO, ItemFields.UNIT_COST, itemForValidation.getItemIdentifierString());
60 valid = false;
61 }
62 }
63
64 return valid;
65 }
66
67 public PurApItem getItemForValidation() {
68 return itemForValidation;
69 }
70
71 public void setItemForValidation(PurApItem itemForValidation) {
72 this.itemForValidation = itemForValidation;
73 }
74
75 public DataDictionaryService getDataDictionaryService() {
76 return dataDictionaryService;
77 }
78
79 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
80 this.dataDictionaryService = dataDictionaryService;
81 }
82
83 }