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