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.module.endow.document.service.impl;
017    
018    import java.util.Collection;
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.kuali.kfs.module.endow.EndowConstants;
024    import org.kuali.kfs.module.endow.EndowPropertyConstants;
025    import org.kuali.kfs.module.endow.businessobject.AutomatedCashInvestmentModel;
026    import org.kuali.kfs.module.endow.businessobject.KEMID;
027    import org.kuali.kfs.module.endow.document.service.KEMIDService;
028    import org.kuali.kfs.sys.context.SpringContext;
029    import org.kuali.rice.kns.service.BusinessObjectService;
030    import org.kuali.rice.kns.service.DataDictionaryService;
031    
032    public class KEMIDServiceImpl implements KEMIDService {
033    
034        private BusinessObjectService businessObjectService;
035    
036        /**
037         * @see org.kuali.kfs.module.endow.document.service.KEMIDService#getByPrimaryKey(java.lang.String)
038         */
039        public KEMID getByPrimaryKey(String kemid) {
040            KEMID theKemidObj = null;
041            
042            if (StringUtils.isNotBlank(kemid)) {
043                Map criteria = new HashMap();
044                
045                if (SpringContext.getBean(DataDictionaryService.class).getAttributeForceUppercase(KEMID.class, EndowPropertyConstants.KEMID)) {
046                    kemid = kemid.toUpperCase();
047                }
048                
049                criteria.put(EndowPropertyConstants.KEMID, kemid);
050                theKemidObj = (KEMID) businessObjectService.findByPrimaryKey(KEMID.class, criteria);
051            }
052            
053            return theKemidObj;
054        }
055        
056        /**
057         * @see org.kuali.kfs.module.endow.document.service.KEMIDService#isTrueEndowment(java.lang.String)
058         */
059        public boolean isTrueEndowment(String kemid){
060            boolean isTrueEndowment = false;
061            KEMID theKemidObj = getByPrimaryKey(kemid);
062            if (theKemidObj.getTypeRestrictionCodeForPrincipalRestrictionCode().getPermanentIndicator()){
063                isTrueEndowment = true;
064            }
065            return isTrueEndowment;
066        }
067        
068        /**
069         * @see org.kuali.kfs.module.endow.document.service.KEMIDService#getByCashSweepId(java.lang.Integer)
070         */
071        public Collection<KEMID> getByCashSweepId(Integer cashSweepId) {
072            Map<String, String> fieldValues = new HashMap<String, String>();
073            fieldValues.put(EndowPropertyConstants.KEMID_CASH_SWEEP_MDL_ID, cashSweepId.toString());
074            
075            return (Collection<KEMID>)businessObjectService.findMatching(KEMID.class, fieldValues);
076        }
077    
078        /**
079         * @see org.kuali.kfs.module.endow.document.service.KEMIDService#getByPrincipleAciId(java.lang.Integer)
080         */
081        public Collection<KEMID> getByPrincipleAciId(Integer aciPrincipleId) {
082            Map<String, String> fieldValues = new HashMap<String, String>();
083            fieldValues.put(EndowPropertyConstants.TYPE_PRINCIPAL_ACI_MODEL_ID, aciPrincipleId.toString());
084            
085            return (Collection<KEMID>)businessObjectService.findMatching(KEMID.class, fieldValues);
086        }
087        
088        /**
089         * @see org.kuali.kfs.module.endow.document.service.KEMIDService#getByIncomeAciId(java.lang.Integer)
090         */
091        public Collection<KEMID> getByIncomeAciId(Integer aciIncomeId) {
092            Map<String, String> fieldValues = new HashMap<String, String>();
093            fieldValues.put(EndowPropertyConstants.TYPE_INCOME_ACI_MODEL_ID, aciIncomeId.toString());
094            
095            return (Collection<KEMID>)businessObjectService.findMatching(KEMID.class, fieldValues);
096        }
097        
098        /**
099         * @see org.kuali.kfs.module.endow.batch.service.AvailableCashUpdateService#getAllKemIdWithClosedIndicatorNo()
100         * Retrieves all kemId records where closed indicator = 'N'
101         */
102        public Collection<KEMID> getAllKemIdWithClosedIndicatorNo() {
103            Map fieldValues = new HashMap();
104            fieldValues.put(EndowPropertyConstants.KEMID_CLOSED, EndowConstants.NO);
105            
106            Collection<KEMID> kemIdRecords = businessObjectService.findMatching(KEMID.class, fieldValues);
107            
108            return kemIdRecords;
109        }
110        
111        /**
112         * This method gets the businessObjectService.
113         * 
114         * @return businessObjectService
115         */
116        public BusinessObjectService getBusinessObjectService() {
117            return businessObjectService;
118        }
119    
120        /**
121         * This method sets the businessObjectService
122         * 
123         * @param businessObjectService
124         */
125        public void setBusinessObjectService(BusinessObjectService businessObjectService) {
126            this.businessObjectService = businessObjectService;
127        }
128    
129    }