001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.timesheet; 017 018 import java.text.ParseException; 019 import java.text.SimpleDateFormat; 020 import java.util.Map; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.kuali.rice.kns.document.MaintenanceDocument; 024 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; 025 026 public class TimeSheetInitiateMaintainableImpl extends KualiMaintainableImpl { 027 /** 028 * 029 */ 030 private static final long serialVersionUID = 1L; 031 032 @Override 033 public void saveBusinessObject() { 034 super.saveBusinessObject(); 035 } 036 037 038 @Override 039 public Map populateBusinessObject(Map<String, String> fieldValues, 040 MaintenanceDocument maintenanceDocument, String methodToCall) { 041 if(StringUtils.equals(getMaintenanceAction(),"New")){ 042 if (!fieldValues.containsKey("documentId") || StringUtils.isEmpty(fieldValues.get("documentId"))) { 043 TimeSheetInitiate tsi = (TimeSheetInitiate) this.getBusinessObject(); 044 fieldValues.put("documentId", tsi.getDocumentId()); 045 } 046 } 047 if (fieldValues.containsKey("endPeriodDateTime") && !StringUtils.isEmpty(fieldValues.get("endPeriodDateTime"))) { 048 try { 049 if(fieldValues.get("endPeriodDateTime").length() > 10) { 050 SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"); 051 java.util.Date aDate = dateFormat.parse(fieldValues.get("endPeriodDateTime")); 052 dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 053 fieldValues.put("endPeriodDateTime", dateFormat.format(aDate)); 054 } 055 } catch (ParseException e) { 056 // TODO Auto-generated catch block 057 e.printStackTrace(); 058 } 059 } 060 return super.populateBusinessObject(fieldValues, maintenanceDocument, methodToCall); 061 } 062 063 }