1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document.validation.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.document.RequisitionDocument;
20 import org.kuali.ole.module.purap.document.validation.impl.RequisitionDocumentPreRules;
21 import org.kuali.ole.select.businessobject.OleSufficientFundCheck;
22 import org.kuali.ole.select.document.OleRequisitionDocument;
23 import org.kuali.ole.select.document.service.OleRequisitionDocumentService;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.OLEPropertyConstants;
26 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.krad.document.Document;
30 import org.kuali.rice.krad.service.BusinessObjectService;
31
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 public class OleRequisitionDocumentPreRules extends RequisitionDocumentPreRules {
37
38
39
40 public OleRequisitionDocumentPreRules() {
41 super();
42 }
43
44
45
46
47
48
49 @Override
50 public boolean doPrompts(Document document) {
51 boolean preRulesOK = true;
52 OleRequisitionDocument reqDoc = null;
53 if (document instanceof RequisitionDocument) {
54 reqDoc = (OleRequisitionDocument) document;
55 }
56 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
57 .getBean("oleRequisitionDocumentService");
58 StringBuilder accountNumbers = new StringBuilder();
59 if (oleRequisitionDocumentService != null && reqDoc != null) {
60 List<SourceAccountingLine> sourceAccountingLineList = reqDoc.getSourceAccountingLines();
61 for (SourceAccountingLine accLine : sourceAccountingLineList) {
62 String notificationOption = null;
63 boolean sufficientFundCheck;
64 Map<String, Object> key = new HashMap<String, Object>();
65 String chartCode = accLine.getChartOfAccountsCode();
66 String accNo = accLine.getAccountNumber();
67 String objectCd = accLine.getFinancialObjectCode();
68 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
69 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
70 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
71 OleSufficientFundCheck.class, key);
72 if (account != null) {
73 notificationOption = account.getNotificationOption();
74 }
75 if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.WARNING_MSG)
76 && oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine)) {
77 accountNumbers.append(accLine.getAccountNumber());
78 }
79 }
80 }
81 if (accountNumbers.length() > 0) {
82 preRulesOK = askForConfirmation(OLEConstants.SufficientFundCheck.REQUISITION_SFC_CHECKING_STRING,
83 OLEConstants.SufficientFundCheck.REQUISITION_SFC_CHECKING, accountNumbers);
84 }
85 preRulesOK &= super.doPrompts(document);
86 return preRulesOK;
87 }
88
89
90
91
92
93
94
95
96 protected boolean askForConfirmation(String questionType, String messageConstant, StringBuilder accountNumbers) {
97
98 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
99 messageConstant);
100 if (questionText.contains("{")) {
101 questionText = prepareQuestionText(questionType, questionText, accountNumbers);
102 }
103
104 boolean confirmOverride = super.askOrAnalyzeYesNoQuestion(questionType, questionText);
105
106 if (!confirmOverride) {
107 event.setActionForwardName(OLEConstants.MAPPING_BASIC);
108 return false;
109 }
110 return true;
111 }
112
113
114
115
116
117
118
119
120 protected String prepareQuestionText(String questionType, String questionText, StringBuilder accountNumbers) {
121 if (StringUtils.equals(questionType, OLEConstants.SufficientFundCheck.REQUISITION_SFC_CHECKING_STRING)) {
122 questionText = StringUtils.replace(questionText, "{0}", accountNumbers.toString());
123 }
124 return questionText;
125 }
126
127 }