001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.kra.budget.service.impl;
017:
018: import java.util.Collection;
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.Map;
022:
023: import org.apache.commons.lang.StringUtils;
024: import org.kuali.core.service.BusinessObjectService;
025: import org.kuali.core.service.DocumentService;
026: import org.kuali.core.util.KualiDecimal;
027: import org.kuali.kfs.KFSConstants;
028: import org.kuali.kfs.KFSPropertyConstants;
029: import org.kuali.kfs.service.ParameterService;
030: import org.kuali.kfs.service.impl.ParameterConstants;
031: import org.kuali.module.kra.KraConstants;
032: import org.kuali.module.kra.budget.bo.AppointmentType;
033: import org.kuali.module.kra.budget.bo.Budget;
034: import org.kuali.module.kra.budget.bo.BudgetFringeRate;
035: import org.kuali.module.kra.budget.bo.BudgetUser;
036: import org.kuali.module.kra.budget.service.BudgetFringeRateService;
037: import org.springframework.transaction.annotation.Transactional;
038:
039: /**
040: * This class is the service implementation for the Account structure. This is the default, Kuali provided implementation.
041: */
042: @Transactional
043: public class BudgetFringeRateServiceImpl implements
044: BudgetFringeRateService {
045:
046: private ParameterService parameterService;
047: private BusinessObjectService businessObjectService;
048: private DocumentService documentService;
049:
050: public BudgetFringeRate getBudgetFringeRate(String documentNumber,
051: String institutionAppointmentTypeCode) {
052:
053: BudgetFringeRate budgetFringeRate = (BudgetFringeRate) businessObjectService
054: .retrieve(new BudgetFringeRate(documentNumber,
055: institutionAppointmentTypeCode));
056:
057: if (budgetFringeRate == null) {
058: AppointmentType appointmentType = (AppointmentType) businessObjectService
059: .retrieve(new AppointmentType(
060: institutionAppointmentTypeCode));
061: budgetFringeRate = new BudgetFringeRate(documentNumber,
062: appointmentType);
063: }
064:
065: return budgetFringeRate;
066: }
067:
068: /**
069: * @see org.kuali.module.kra.budget.service.BudgetFringeRateService#getDefaultFringeRates()
070: */
071: public Collection getDefaultFringeRates() {
072: Map fieldValues = new HashMap();
073: fieldValues.put(KFSPropertyConstants.ACTIVE,
074: KFSConstants.ACTIVE_INDICATOR);
075:
076: return businessObjectService.findMatching(
077: AppointmentType.class, fieldValues);
078: }
079:
080: public BudgetFringeRate getBudgetFringeRateForDefaultAppointmentType(
081: String documentNumber) {
082:
083: AppointmentType appointmentType = (AppointmentType) businessObjectService
084: .retrieve(new AppointmentType(
085: parameterService
086: .getParameterValue(
087: ParameterConstants.RESEARCH_ADMINISTRATION_DOCUMENT.class,
088: KraConstants.DEFAULT_APPOINTMENT_TYPE)));
089:
090: BudgetFringeRate defaultFringeRate = (BudgetFringeRate) businessObjectService
091: .retrieve(new BudgetFringeRate(documentNumber,
092: appointmentType.getAppointmentTypeCode()));
093:
094: if (defaultFringeRate != null) {
095: return defaultFringeRate;
096: } else {
097: return new BudgetFringeRate(documentNumber, appointmentType);
098: }
099: }
100:
101: public BudgetFringeRate getBudgetFringeRateForPerson(
102: BudgetUser budgetUser) {
103: if (StringUtils.isNotEmpty(budgetUser.getAppointmentTypeCode())) {
104: return this .getBudgetFringeRate(budgetUser
105: .getDocumentNumber(), budgetUser
106: .getAppointmentTypeCode());
107: } else if (budgetUser.getUserAppointmentTasks().size() > 0
108: && StringUtils.isNotEmpty(budgetUser
109: .getUserAppointmentTask(0)
110: .getInstitutionAppointmentTypeCode())) {
111: return this .getBudgetFringeRate(budgetUser
112: .getDocumentNumber(), budgetUser
113: .getUserAppointmentTask(0)
114: .getInstitutionAppointmentTypeCode());
115: } else {
116: return this
117: .getBudgetFringeRateForDefaultAppointmentType(budgetUser
118: .getDocumentNumber());
119: }
120: }
121:
122: public boolean isValidFringeRate(KualiDecimal fringeRate) {
123: if (fringeRate != null) {
124: return fringeRate
125: .isLessEqual(KFSConstants.CONTRACTS_AND_GRANTS_FRINGE_RATE_MAX);
126: } else {
127: return false;
128: }
129: }
130:
131: public boolean isValidCostShare(KualiDecimal costShare) {
132: if (costShare != null) {
133: return costShare
134: .isLessEqual(KFSConstants.CONTRACTS_AND_GRANTS_COST_SHARE_MAX);
135: } else {
136: return false;
137: }
138: }
139:
140: public void setupDefaultFringeRates(Budget budget) {
141: for (Iterator iter = getDefaultFringeRates().iterator(); iter
142: .hasNext();) {
143: AppointmentType appType = (AppointmentType) iter.next();
144: BudgetFringeRate bfr = new BudgetFringeRate(budget
145: .getDocumentNumber(), appType
146: .getAppointmentTypeCode(), appType
147: .getFringeRateAmount(), appType
148: .getCostShareFringeRateAmount(), appType);
149: budget.getFringeRates().add(bfr);
150: }
151: }
152:
153: public void setParameterService(ParameterService parameterService) {
154: this .parameterService = parameterService;
155: }
156:
157: public void setBusinessObjectService(
158: BusinessObjectService businessObjectService) {
159: this .businessObjectService = businessObjectService;
160: }
161:
162: public void setDocumentService(DocumentService documentService) {
163: this.documentService = documentService;
164: }
165: }
|