View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.time.timecollection.rule.service;
17  
18  import java.sql.Timestamp;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.hr.core.cache.CacheUtils;
23  import org.kuali.hr.time.HrBusinessObject;
24  import org.kuali.hr.time.collection.rule.TimeCollectionRule;
25  import org.kuali.hr.time.service.base.TkServiceLocator;
26  import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
27  import org.kuali.hr.time.util.TKUtils;
28  import org.kuali.rice.kns.document.MaintenanceDocument;
29  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
30  import org.kuali.rice.krad.service.KRADServiceLocator;
31  import org.kuali.rice.krad.util.GlobalVariables;
32  
33  public class TimeCollectionRuleMaintainableImpl extends HrBusinessObjectMaintainableImpl {
34      /**
35       *
36       */
37      private static final long serialVersionUID = 1L;
38  
39      @Override
40      public HrBusinessObject getObjectById(String id) {
41          return TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRule(id);
42      }
43  
44      @Override
45      public void processAfterNew(MaintenanceDocument document, Map<String, String[]> parameters) {
46          super.processAfterNew(document, parameters);
47      }
48  
49      @Override
50      public void processAfterPost(MaintenanceDocument document, Map<String, String[]> parameters) {
51          TimeCollectionRule timeCollectionRule = (TimeCollectionRule) document.getNewMaintainableObject().getBusinessObject();
52          timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
53          super.processAfterPost(document, parameters);
54      }
55  
56      @Override
57      public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> parameters) {
58          TimeCollectionRule timeCollectionRule = (TimeCollectionRule) document.getNewMaintainableObject().getBusinessObject();
59          timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
60          super.processAfterEdit(document, parameters);
61      }
62  
63      /*@Override
64      public void saveBusinessObject() {
65          TimeCollectionRule timeCollectionRule = (TimeCollectionRule) this.getBusinessObject();
66  
67  		//Inactivate the old time collection rule as of the effective date of new time collection rule
68  		if(timeCollectionRule.getTkTimeCollectionRuleId()!=null && timeCollectionRule.isActive()){
69  			TimeCollectionRule oldTimeCollectRule = TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRule(timeCollectionRule.getTkTimeCollectionRuleId());
70  			if(timeCollectionRule.getEffectiveDate().equals(oldTimeCollectRule.getEffectiveDate())){
71  				timeCollectionRule.setTimestamp(null);
72  			} else{
73  				if(oldTimeCollectRule!=null){
74  					oldTimeCollectRule.setActive(false);
75  					//NOTE this is done to prevent the timestamp of the inactive one to be greater than the 
76  					oldTimeCollectRule.setTimestamp(TKUtils.subtractOneSecondFromTimestamp(new Timestamp(System.currentTimeMillis())));
77  					oldTimeCollectRule.setEffectiveDate(timeCollectionRule.getEffectiveDate());
78  					KRADServiceLocator.getBusinessObjectService().save(oldTimeCollectRule);
79  				}
80  				timeCollectionRule.setTimestamp(new Timestamp(System.currentTimeMillis()));
81  				timeCollectionRule.setTkTimeCollectionRuleId(null);
82  			}
83  		}
84  		
85  		KRADServiceLocator.getBusinessObjectService().save(timeCollectionRule);
86          CacheUtils.flushCache(TimeCollectionRule.CACHE_NAME);
87      }*/
88  
89  
90      @Override
91      public Map populateBusinessObject(Map<String, String> fieldValues, MaintenanceDocument maintenanceDocument, String methodToCall) {
92          if (fieldValues.containsKey("workArea") && StringUtils.equals(fieldValues.get("workArea"), "%")) {
93              fieldValues.put("workArea", "-1");
94          }
95          if (fieldValues.containsKey("jobNumber") && StringUtils.equals(fieldValues.get("jobNumber"), "%")) {
96              fieldValues.put("jobNumber", "-1");
97          }
98          return super.populateBusinessObject(fieldValues, maintenanceDocument, methodToCall);
99      }
100 }