1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.cg.document.validation.impl;
17
18 import java.sql.Date;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.coa.document.validation.impl.MaintenancePreRulesBase;
22 import org.kuali.ole.module.cg.businessobject.Award;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.OLEPropertyConstants;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.core.api.config.property.ConfigurationService;
27 import org.kuali.rice.core.api.util.type.KualiDecimal;
28 import org.kuali.rice.kns.document.MaintenanceDocument;
29 import org.kuali.rice.kns.service.DataDictionaryService;
30 import org.kuali.rice.krad.util.ObjectUtils;
31
32
33
34
35
36 public class AwardPreRules extends MaintenancePreRulesBase {
37
38 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AwardPreRules.class);
39
40 protected ConfigurationService configService;
41 protected DataDictionaryService dataDictionaryService;
42
43 protected Award newAward;
44
45
46
47
48 public AwardPreRules() {
49 dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
50 configService = SpringContext.getBean(ConfigurationService.class);
51 }
52
53
54
55
56 @Override
57 protected boolean doCustomPreRules(MaintenanceDocument document) {
58 setupConvenienceObjects(document);
59 boolean proceed = true;
60 if (proceed) {
61 proceed = continueIfEntryDateBeforeBeginDate();
62 }
63 if (proceed) {
64 proceed = continueIfSubcontractorTotalGreaterThanAwardTotal();
65 }
66
67 if (!proceed) {
68 abortRulesCheck();
69 }
70
71 return true;
72 }
73
74
75
76
77
78
79
80 protected boolean continueIfEntryDateBeforeBeginDate() {
81 boolean proceed = true;
82 Date entryDate = newAward.getAwardEntryDate();
83 Date beginDate = newAward.getAwardBeginningDate();
84
85 if (ObjectUtils.isNotNull(entryDate) && ObjectUtils.isNotNull(beginDate) && entryDate.before(beginDate)) {
86 String entryDateLabel = dataDictionaryService.getAttributeErrorLabel(Award.class, OLEPropertyConstants.AWARD_ENTRY_DATE);
87 String beginDateLabel = dataDictionaryService.getAttributeErrorLabel(Award.class, OLEPropertyConstants.AWARD_BEGINNING_DATE);
88 proceed = askOrAnalyzeYesNoQuestion("entryDateBeforeStartDate", buildConfirmationQuestion(OLEKeyConstants.WARNING_AWARD_ENTRY_BEFORE_START_DATE, entryDateLabel, beginDateLabel));
89 }
90 return proceed;
91 }
92
93
94
95
96
97
98
99 protected boolean continueIfSubcontractorTotalGreaterThanAwardTotal() {
100 boolean proceed = true;
101
102 KualiDecimal awardTotal = newAward.getAwardTotalAmount();
103 KualiDecimal subcontractorTotal = newAward.getAwardSubcontractorsTotalAmount();
104 if ((ObjectUtils.isNotNull(awardTotal) && subcontractorTotal.isGreaterThan(awardTotal)) || (ObjectUtils.isNull(awardTotal) && subcontractorTotal.isPositive())) {
105
106 String subcontracorLabel = dataDictionaryService.getCollectionLabel(Award.class, OLEPropertyConstants.AWARD_SUBCONTRACTORS);
107 String awardLabel = dataDictionaryService.getAttributeErrorLabel(Award.class, OLEPropertyConstants.AWARD_TOTAL_AMOUNT);
108
109 proceed = askOrAnalyzeYesNoQuestion("subcontractorTotalGreaterThanAwardTotal", buildConfirmationQuestion(OLEKeyConstants.WARNING_AWARD_SUBCONTRACTOR_TOTAL_GREATER_THAN_AWARD_TOTAL, subcontracorLabel, awardLabel));
110 }
111
112 return proceed;
113 }
114
115
116
117
118
119
120
121
122 protected String buildConfirmationQuestion(String messageKey, String... parameters) {
123 String result = configService.getPropertyValueAsString(messageKey);
124 if (null != parameters) {
125 for (int i = 0; i < parameters.length; i++) {
126 result = StringUtils.replace(result, "{" + i + "}", parameters[i]);
127 }
128 }
129 return result;
130 }
131
132
133
134
135 protected void setupConvenienceObjects(MaintenanceDocument document) {
136
137 newAward = (Award) document.getNewMaintainableObject().getBusinessObject();
138 }
139
140 }