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
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.ole.integration.cab.CapitalAssetBuilderModuleService;
21 import org.kuali.ole.module.purap.PurapConstants;
22 import org.kuali.ole.module.purap.PurapKeyConstants;
23 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
24 import org.kuali.ole.module.purap.businessobject.PurApItem;
25 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
30 import org.kuali.rice.kns.util.KNSGlobalVariables;
31 import org.kuali.rice.kns.util.MessageList;
32 import org.kuali.rice.krad.document.Document;
33 import org.kuali.rice.krad.util.ErrorMessage;
34 import org.kuali.rice.krad.util.ObjectUtils;
35
36 import java.util.List;
37
38 public abstract class PurapDocumentPreRulesBase extends PromptBeforeValidationBase {
39
40 public PurapDocumentPreRulesBase() {
41 super();
42 }
43
44 @Override
45 public boolean doPrompts(Document document) {
46 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) document;
47
48 boolean preRulesValid = true;
49
50
51 List<PurApItem> items = purapDocument.getItems();
52
53 for (PurApItem item : items) {
54
55 for (PurApAccountingLine account : item.getSourceAccountingLines()) {
56 account.refreshNonUpdateableReferences();
57 }
58 }
59
60 if (StringUtils.isBlank(event.getQuestionContext()) || StringUtils.equals(question, PurapConstants.FIX_CAPITAL_ASSET_WARNINGS)) {
61 preRulesValid &= confirmFixCapitalAssetWarningConditions(purapDocument);
62 }
63
64 return preRulesValid;
65 }
66
67 public boolean confirmFixCapitalAssetWarningConditions(PurchasingAccountsPayableDocument purapDocument) {
68 boolean proceed = true;
69
70
71 if (!checkCAMSWarningStatus(purapDocument)) {
72 return true;
73 }
74
75 StringBuffer questionText = new StringBuffer();
76 if (StringUtils.isBlank(event.getQuestionContext())) {
77 if (!SpringContext.getBean(CapitalAssetBuilderModuleService.class).warningObjectLevelCapital(purapDocument)) {
78 proceed &= false;
79 questionText.append(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
80 PurapKeyConstants.REQ_QUESTION_FIX_CAPITAL_ASSET_WARNINGS));
81
82 MessageList warnings = KNSGlobalVariables.getMessageList();
83 if (!warnings.isEmpty()) {
84 questionText.append("[p]");
85 for (ErrorMessage warning : warnings) {
86
87
88
89
90 questionText.append(warning.getErrorKey());
91 String[] params = warning.getMessageParameters();
92 if (params != null && params.length > 0) {
93 questionText.append("(");
94 for (int i = 0; i < params.length; ++i) {
95 if (i > 0) {
96 questionText.append(", ");
97 }
98 questionText.append(params[i]);
99 }
100 questionText.append(")");
101 }
102 }
103 questionText.append("[/p]");
104 }
105 }
106 }
107
108 if (!proceed || ((ObjectUtils.isNotNull(question)) && (question.equals(PurapConstants.FIX_CAPITAL_ASSET_WARNINGS)))) {
109 proceed = askOrAnalyzeYesNoQuestion(PurapConstants.FIX_CAPITAL_ASSET_WARNINGS, questionText.toString());
110 }
111
112 event.setQuestionContext(PurapConstants.FIX_CAPITAL_ASSET_WARNINGS);
113 event.setActionForwardName(OLEConstants.MAPPING_BASIC);
114 if (proceed) {
115 KNSGlobalVariables.getMessageList().clear();
116 }
117
118 return proceed;
119 }
120
121 protected abstract boolean checkCAMSWarningStatus(PurchasingAccountsPayableDocument purapDocument);
122
123 }