001    /*
002     * Copyright 2011 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.kfs.fp.document.web;
017    
018    import java.util.Collection;
019    import java.util.HashMap;
020    import java.util.Map;
021    import java.util.Set;
022    
023    import org.kuali.kfs.fp.businessobject.DisbursementVoucherDocumentationLocation;
024    import org.kuali.kfs.sys.KFSConstants;
025    import org.kuali.kfs.sys.context.SpringContext;
026    import org.kuali.kfs.sys.document.web.CodeDescriptionFormatterBase;
027    import org.kuali.rice.kns.bo.PersistableBusinessObject;
028    import org.kuali.rice.kns.service.BusinessObjectService;
029    
030    /**
031     * The values are the same as the disbursementVoucherDocumentationLocationCode in the DisbursementVoucherDocumentationLocation
032     * class.
033     */
034    public class DocumentationLocationCodeDescriptionFormatter extends CodeDescriptionFormatterBase {
035        @Override
036        protected String getDescriptionOfBO(PersistableBusinessObject bo) {
037            return ((DisbursementVoucherDocumentationLocation) bo).getDisbursementVoucherDocumentationLocationName();
038        }
039    
040        @Override
041        protected Map<String, PersistableBusinessObject> getValuesToBusinessObjectsMap(Set values) {
042            Map<String, PersistableBusinessObject> map = new HashMap<String, PersistableBusinessObject>();
043            Map<String, Object> criteria = new HashMap<String, Object>();
044            criteria.put(KFSConstants.DISBURSEMENT_VOUCHER_DOCUMENTATION_LOCATION_CODE_PROPERTY_NAME, values);
045            Collection<DisbursementVoucherDocumentationLocation> coll = SpringContext.getBean(BusinessObjectService.class).findMatchingOrderBy(DisbursementVoucherDocumentationLocation.class, criteria, "versionNumber", true);
046            // by sorting on ver #, we can guarantee that the most recent value will remain in the map (assuming the iterator returns
047            // BOs in order)
048            for (DisbursementVoucherDocumentationLocation dvdl : coll) {
049                map.put(dvdl.getDisbursementVoucherDocumentationLocationCode(), dvdl);
050            }
051            return map;
052        }
053    }