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.earncode;
017
018 import java.sql.Date;
019 import java.text.ParseException;
020 import java.text.SimpleDateFormat;
021 import java.util.Map;
022
023 import org.apache.commons.lang.StringUtils;
024 import org.kuali.hr.time.service.base.TkServiceLocator;
025 import org.kuali.rice.krad.bo.BusinessObject;
026 import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
027
028 public class EarnCodeInquirableImpl extends KualiInquirableImpl {
029
030 @Override
031 public BusinessObject getBusinessObject(Map fieldValues) {
032 EarnCode ec = null;
033 if(StringUtils.isNotBlank((String)fieldValues.get("hrEarnCodeId"))) {
034 ec = TkServiceLocator.getEarnCodeService().getEarnCodeById((String)fieldValues.get("hrEarnCodeId"));
035
036 } else if(StringUtils.isNotBlank((String)fieldValues.get("earnCode"))
037 && StringUtils.isNotBlank((String)fieldValues.get("effectiveDate"))) {
038 java.util.Date uDate = null;
039 try {
040 uDate = new SimpleDateFormat("MM/dd/yyyy").parse(fieldValues.get("effectiveDate").toString());
041
042 Date effdt = new java.sql.Date(uDate.getTime());
043 ec = TkServiceLocator.getEarnCodeService().getEarnCode((String)fieldValues.get("earnCode"), effdt);
044 } catch (ParseException e) {
045 e.printStackTrace();
046 }
047
048 } else {
049 ec = (EarnCode) super.getBusinessObject(fieldValues);
050 }
051
052 return ec;
053 }
054
055 }