View Javadoc

1   /**
2    * Copyright 2004-2012 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.timesheet;
17  
18  import java.text.ParseException;
19  import java.text.SimpleDateFormat;
20  import java.util.Map;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.rice.kns.document.MaintenanceDocument;
24  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
25  
26  public class TimeSheetInitiateMaintainableImpl extends KualiMaintainableImpl {
27  	/**
28  	 * 
29  	 */
30  	private static final long serialVersionUID = 1L;
31  	
32  	@Override
33  	public void saveBusinessObject() {
34  		super.saveBusinessObject();
35  	}
36  	
37  	
38  	@Override
39  	public Map populateBusinessObject(Map<String, String> fieldValues,
40  			MaintenanceDocument maintenanceDocument, String methodToCall) {
41  		if(StringUtils.equals(getMaintenanceAction(),"New")){
42  			if (!fieldValues.containsKey("documentId") || StringUtils.isEmpty(fieldValues.get("documentId"))) {
43  				TimeSheetInitiate tsi = (TimeSheetInitiate) this.getBusinessObject();
44  				fieldValues.put("documentId", tsi.getDocumentId());
45  			}
46  		}
47  		if (fieldValues.containsKey("endPeriodDateTime") && !StringUtils.isEmpty(fieldValues.get("endPeriodDateTime"))) {
48  			try {
49  				if(fieldValues.get("endPeriodDateTime").length() > 10) {
50  					SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
51  					java.util.Date aDate = dateFormat.parse(fieldValues.get("endPeriodDateTime"));
52  					dateFormat = new SimpleDateFormat("MM/dd/yyyy");
53  					fieldValues.put("endPeriodDateTime", dateFormat.format(aDate));
54  				}
55  			} catch (ParseException e) {
56  				// TODO Auto-generated catch block
57  				e.printStackTrace();
58  			}
59  		}
60  		return super.populateBusinessObject(fieldValues, maintenanceDocument, methodToCall);
61  	}
62  		
63  }