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.PurapConstants;
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.module.purap.document.PurchasingAccountsPayableDocument;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.ole.sys.document.validation.GenericValidation;
26 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
28 import org.kuali.rice.core.api.util.type.KualiDecimal;
29 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
30 import org.kuali.rice.kns.service.DataDictionaryService;
31 import org.kuali.rice.krad.util.GlobalVariables;
32 import org.kuali.rice.krad.util.ObjectUtils;
33
34 public class PurchasingAccountsPayableBelowTheLineValuesValidation extends GenericValidation {
35
36 private DataDictionaryService dataDictionaryService;
37 private ParameterService parameterService;
38 private PurApItem itemForValidation;
39
40
41
42
43
44
45
46
47
48 public boolean validate(AttributedDocumentEvent event) {
49 boolean valid = true;
50 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
51 String documentType = dataDictionaryService.getDocumentTypeNameByClass(purapDocument.getClass());
52
53 try {
54 if (ObjectUtils.isNotNull(itemForValidation.getItemUnitPrice()) && (new KualiDecimal(itemForValidation.getItemUnitPrice())).isZero()) {
55 if (parameterService.parameterExists(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_ALLOWS_ZERO) && !SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_ALLOWS_ZERO, itemForValidation.getItemTypeCode()).evaluationSucceeds()) {
56 valid = false;
57 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_ITEM_BELOW_THE_LINE, itemForValidation.getItemType().getItemTypeDescription(), "zero");
58 }
59 } else if (ObjectUtils.isNotNull(itemForValidation.getItemUnitPrice()) && (new KualiDecimal(itemForValidation.getItemUnitPrice())).isPositive()) {
60 if (parameterService.parameterExists(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_ALLOWS_POSITIVE) && !SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_ALLOWS_POSITIVE, itemForValidation.getItemTypeCode()).evaluationSucceeds()) {
61 valid = false;
62 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_UNIT_PRICE, PurapKeyConstants.ERROR_ITEM_BELOW_THE_LINE, itemForValidation.getItemType().getItemTypeDescription(), "positive");
63 }
64 }
65
66
67
68
69
70
71
72 if (ObjectUtils.isNotNull(itemForValidation.getItemUnitPrice()) && (new KualiDecimal(itemForValidation.getItemUnitPrice())).isNonZero() && StringUtils.isEmpty(itemForValidation.getItemDescription())) {
73 if (parameterService.parameterExists(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_REQUIRES_USER_ENTERED_DESCRIPTION) && SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_REQUIRES_USER_ENTERED_DESCRIPTION, itemForValidation.getItemTypeCode()).evaluationSucceeds()) {
74 valid = false;
75 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_DESCRIPTION, PurapKeyConstants.ERROR_ITEM_BELOW_THE_LINE, "The item description of " + itemForValidation.getItemType().getItemTypeDescription(), "empty");
76 }
77 }
78
79
80 if (ObjectUtils.isNotNull(itemForValidation.getTotalAmount()) && itemForValidation.getTotalAmount().isPositive()) {
81 if (parameterService.parameterExists(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_ALLOWS_POSITIVE) && !SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Class.forName(PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType)), PurapConstants.ITEM_ALLOWS_POSITIVE, itemForValidation.getItemTypeCode()).evaluationSucceeds()) {
82 valid = false;
83 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.TOTAL_AMOUNT, PurapKeyConstants.ERROR_ITEM_BELOW_THE_LINE, itemForValidation.getItemType().getItemTypeDescription() + " Total Amount", "positive");
84 }
85 }
86 } catch (ClassNotFoundException e) {
87 throw new RuntimeException("The valideBelowTheLineValues of PurchasingAccountsPayableDocumentRuleBase was unable to resolve a document type class: " + PurapConstants.PURAP_DETAIL_TYPE_CODE_MAP.get(documentType), e);
88 }
89
90 return valid;
91 }
92
93 public DataDictionaryService getDataDictionaryService() {
94 return dataDictionaryService;
95 }
96
97 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
98 this.dataDictionaryService = dataDictionaryService;
99 }
100
101 public ParameterService getParameterService() {
102 return parameterService;
103 }
104
105 public void setParameterService(ParameterService parameterService) {
106 this.parameterService = parameterService;
107 }
108
109 public PurApItem getItemForValidation() {
110 return itemForValidation;
111 }
112
113 public void setItemForValidation(PurApItem itemForValidation) {
114 this.itemForValidation = itemForValidation;
115 }
116
117 }