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.ClassCode;
026 import org.kuali.kfs.module.endow.document.service.ClassCodeService;
027 import org.kuali.rice.kns.service.BusinessObjectService;
028
029 public class ClassCodeServiceImpl implements ClassCodeService {
030 protected BusinessObjectService businessObjectService;
031
032 /**
033 * @see org.kuali.kfs.module.endow.document.service.ClassCodeService#getByPrimaryKey(java.lang.String)
034 */
035 public ClassCode getByPrimaryKey(String code) {
036
037 ClassCode classCode = null;
038 if (StringUtils.isNotBlank(code)) {
039 Map criteria = new HashMap();
040 criteria.put("code", code);
041 classCode = (ClassCode) businessObjectService.findByPrimaryKey(ClassCode.class, criteria);
042 }
043
044 return classCode;
045 }
046
047
048 /**
049 * @see org.kuali.kfs.module.endow.document.service.ClassCodeService#getClassCodesForAccrualProcessing()
050 */
051 public Collection<ClassCode> getClassCodesForAccrualProcessing() {
052
053 Collection<ClassCode> classCodes = null;
054
055 String[] accrualMethodsForCriteria = new String[] { EndowConstants.AccrualMethod.AUTOMATED_CASH_MANAGEMENT, EndowConstants.AccrualMethod.TIME_DEPOSITS, EndowConstants.AccrualMethod.TREASURY_NOTES_AND_BONDS, EndowConstants.AccrualMethod.DIVIDENDS };
056 Map<String, String> criteria = new HashMap<String, String>();
057
058 for (int i = 0; i < accrualMethodsForCriteria.length; i++) {
059 criteria.put(EndowPropertyConstants.CLASS_CODE_SEC_ACCRUAL_METHOD, accrualMethodsForCriteria[i]);
060 Collection<ClassCode> tmpClassCodes = businessObjectService.findMatching(ClassCode.class, criteria);
061 if (classCodes == null) {
062 classCodes = tmpClassCodes;
063 }
064 else {
065 classCodes.addAll(tmpClassCodes);
066 }
067 criteria.clear();
068 }
069
070 return classCodes;
071 }
072
073 /**
074 * Gets the businessObjectService.
075 *
076 * @return businessObjectService
077 */
078 protected BusinessObjectService getBusinessObjectService() {
079 return businessObjectService;
080 }
081
082 /**
083 * Sets the businessObjectService.
084 *
085 * @param businessObjectService
086 */
087 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
088 this.businessObjectService = businessObjectService;
089 }
090
091 }