View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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      	// use the hr BO service to check if a new version exists
63  		HrBusinessObjectService hrBOService = HrServiceLocator.getService(getHrBusinessObjectServiceName());
64  		return hrBOService.doesNewerVersionExist(newBo);
65      }
66  
67  
68  }