1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.web;
17
18 import org.kuali.kpme.core.api.bo.service.HrBusinessObjectService;
19 import org.kuali.kpme.core.bo.HrBusinessObject;
20 import org.kuali.kpme.core.service.HrServiceLocator;
21 import org.kuali.rice.core.api.CoreApiServiceLocator;
22 import org.kuali.rice.kns.document.MaintenanceDocument;
23 import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
24 import org.kuali.rice.krad.document.Document;
25
26 @SuppressWarnings("deprecation")
27 public class KPMEHrObjectNewerVersionPromptBase extends PromptBeforeValidationBase {
28 private static final String FUTURE_EFFECTIVE_DATE_RECORD_EXISTS_QN_ID = "FutureEffectiveDateRecordExists";
29 private static final String WARNING_FUTURE_EFF_DATE_KEY = "warning.future.eff.date";
30 private static final String HR_BUSINESS_OBJECT_SERVICE_NAME = "hrBusinessObjectService";
31
32 @Override
33 public boolean doPrompts(Document document) {
34 boolean preRulesOK = true;
35 preRulesOK &= conditionallyAskQuestion(document);
36 return preRulesOK;
37 }
38
39 protected HrBusinessObject getNewHrBusinessObjectInstance(MaintenanceDocument document) {
40 return (HrBusinessObject) document.getNewMaintainableObject().getDataObject();
41 }
42
43 protected boolean conditionallyAskQuestion(Document document) {
44 HrBusinessObject newBo = this.getNewHrBusinessObjectInstance((MaintenanceDocument) document);
45 boolean askQuestion = this.doesNewerVersionExist(newBo);
46 if (askQuestion) {
47 String questionText = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(WARNING_FUTURE_EFF_DATE_KEY);
48 boolean confirm = super.askOrAnalyzeYesNoQuestion(FUTURE_EFFECTIVE_DATE_RECORD_EXISTS_QN_ID, questionText);
49 if (!confirm) {
50 super.abortRulesCheck();
51 }
52
53 }
54 return true;
55 }
56
57 protected String getHrBusinessObjectServiceName() {
58 return HR_BUSINESS_OBJECT_SERVICE_NAME;
59 }
60
61 protected boolean doesNewerVersionExist(HrBusinessObject newBo) {
62
63 HrBusinessObjectService hrBOService = HrServiceLocator.getService(getHrBusinessObjectServiceName());
64 return hrBOService.doesNewerVersionExist(newBo);
65 }
66
67
68 }