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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.businessobject.PurApItem;
22 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocumentBase;
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 import java.util.List;
30
31 public class RequisitionAssignToTradeInValidation extends GenericValidation {
32 private DataDictionaryService dataDictionaryService;
33
34 public boolean validate(AttributedDocumentEvent event) {
35
36
37 boolean foundTradeIn = false;
38 boolean valid = true;
39
40 PurchasingAccountsPayableDocumentBase purapDoc =
41 (PurchasingAccountsPayableDocumentBase) event.getDocument();
42
43
44
45
46
47 List<PurApItem> items = (List<PurApItem>) purapDoc.getItems();
48 for (PurApItem item : items) {
49 item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
50 if (item.getItemAssignedToTradeInIndicator()) {
51 foundTradeIn = true;
52 break;
53 }
54 }
55
56
57 if (foundTradeIn) {
58
59
60 PurApItem tradeInItem = purapDoc.getTradeInItem();
61 if (tradeInItem != null) {
62 if (StringUtils.isEmpty(tradeInItem.getItemDescription())) {
63
64 String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(tradeInItem.getClass().getName()).getAttributeDefinition(PurapPropertyConstants.ITEM_DESCRIPTION).getLabel();
65 tradeInItem.getItemLineNumber();
66 GlobalVariables.getMessageMap().putError(
67 "document.item[" + (items.size() - 1) + "]." + PurapPropertyConstants.ITEM_DESCRIPTION,
68 PurapKeyConstants.ERROR_ITEM_BELOW_THE_LINE,
69 "The item description of " + tradeInItem.getItemType().getItemTypeDescription(),
70 "empty");
71
72 valid = false;
73 } else if (ObjectUtils.isNull(tradeInItem.getItemUnitPrice())) {
74
75 String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(tradeInItem.getClass().getName()).getAttributeDefinition(PurapPropertyConstants.ITEM_UNIT_PRICE).getLabel();
76 GlobalVariables.getMessageMap().putError(
77 "document.item[" + (items.size() - 1) + "]." + PurapPropertyConstants.ITEM_UNIT_PRICE,
78 PurapKeyConstants.ERROR_ITEM_BELOW_THE_LINE,
79 tradeInItem.getItemType().getItemTypeDescription(),
80 "zero");
81
82 valid = false;
83 }
84 }
85 }
86
87 return valid;
88 }
89
90
91
92
93
94
95 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
96 this.dataDictionaryService = dataDictionaryService;
97 }
98
99 }