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.sql.Date;
019 import java.text.DateFormat;
020 import java.text.SimpleDateFormat;
021 import java.util.ArrayList;
022 import java.util.Collection;
023 import java.util.HashMap;
024 import java.util.Map;
025
026 import org.apache.commons.lang.StringUtils;
027 import org.kuali.kfs.module.endow.EndowPropertyConstants;
028 import org.kuali.kfs.module.endow.businessobject.FeeMethod;
029 import org.kuali.kfs.module.endow.businessobject.KemidFee;
030 import org.kuali.kfs.module.endow.document.service.FeeMethodService;
031 import org.kuali.kfs.sys.businessobject.defaultvalue.CurrentDateMMDDYYYYFinder;
032 import org.kuali.rice.kns.service.BusinessObjectService;
033 import org.kuali.rice.kns.service.DateTimeService;
034 import org.kuali.rice.kns.util.ObjectUtils;
035
036 import java.text.ParseException;
037
038 /**
039 * This class is the service implementation for the Fee Method. This is the default, Kuali provided implementation.
040 */
041 public class FeeMethodServiceImpl implements FeeMethodService {
042
043 private BusinessObjectService businessObjectService;
044 private DateTimeService dateTimeService;
045
046 /**
047 * @see org.kuali.kfs.module.endow.document.service.FeeMethodService#getFeeMethodsByNextProcessingDate(Date)
048 */
049 public Collection<FeeMethod> getFeeMethodsByNextProcessingDate(java.util.Date currentDate) {
050 Collection<FeeMethod> feeMethods = new ArrayList();
051 Map criteria = new HashMap();
052
053 criteria.put(EndowPropertyConstants.FEE_METHOD_NEXT_PROCESS_DATE, currentDate);
054 feeMethods = businessObjectService.findMatching(FeeMethod.class, criteria);
055
056 return feeMethods;
057 }
058
059 /**
060 * @see org.kuali.kfs.module.endow.document.service.FeeMethodService#getFeeMethods()
061 */
062 public Collection<FeeMethod> getFeeMethods() {
063 Collection<FeeMethod> feeMethods = new ArrayList();
064
065 feeMethods = businessObjectService.findAll(FeeMethod.class);
066
067 return feeMethods;
068 }
069
070 /**
071 * @see org.kuali.kfs.module.endow.document.service.FeeMethodService#getByPrimaryKey(java.lang.String)
072 */
073 public FeeMethod getByPrimaryKey(String feeMethodCode) {
074 FeeMethod feeMethod = null;
075 if (StringUtils.isNotBlank(feeMethodCode)) {
076 Map<String, String> criteria = new HashMap<String, String>();
077 criteria.put(EndowPropertyConstants.ENDOWCODEBASE_CODE, feeMethodCode);
078
079 feeMethod = (FeeMethod) businessObjectService.findByPrimaryKey(FeeMethod.class, criteria);
080 }
081 return feeMethod;
082 }
083
084 /**
085 * @see org.kuali.kfs.module.endow.document.service.FeeMethodService#getFeeMethodNextProcessDate(java.lang.String)
086 */
087 public String getFeeMethodNextProcessDateForAjax(String feeMethodCode) {
088
089 String nextProcessDateString = null;
090 Date nextProcessDate = getFeeMethodNextProcessDate(feeMethodCode);
091
092 if (ObjectUtils.isNotNull(nextProcessDate)) {
093 nextProcessDateString = dateTimeService.toDateString(getFeeMethodNextProcessDate(feeMethodCode));
094 }
095
096 return nextProcessDateString;
097 }
098
099 /**
100 * @see org.kuali.kfs.module.endow.document.service.FeeMethodService#getFeeMethodNextProcessDate(java.lang.String)
101 */
102 public Date getFeeMethodNextProcessDate(String feeMethodCode) {
103
104 FeeMethod feeMethod = getByPrimaryKey(feeMethodCode);
105 Date nextProcessDate = null;
106
107 if (ObjectUtils.isNotNull(feeMethod)) {
108 nextProcessDate = feeMethod.getFeeNextProcessDate();
109 }
110
111 return nextProcessDate;
112 }
113
114 /**
115 * This method gets the businessObjectService.
116 *
117 * @return businessObjectService
118 */
119 public BusinessObjectService getBusinessObjectService() {
120 return businessObjectService;
121 }
122
123 /**
124 * This method sets the businessObjectService
125 *
126 * @param businessObjectService
127 */
128 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
129 this.businessObjectService = businessObjectService;
130 }
131
132 /**
133 * Gets the dateTimeService.
134 *
135 * @return dateTimeService
136 */
137 public DateTimeService getDateTimeService() {
138 return dateTimeService;
139 }
140
141 /**
142 * Sets the dateTimeService.
143 *
144 * @param dateTimeService
145 */
146 public void setDateTimeService(DateTimeService dateTimeService) {
147 this.dateTimeService = dateTimeService;
148 }
149
150
151 /**
152 * @see org.kuali.kfs.module.endow.document.service.FeeMethodService#isFeeMethodUsedOnAnyKemid(java.lang.String)
153 */
154 public boolean isFeeMethodUsedOnAnyKemid(String feeMethodCode) {
155 boolean isUsed = false;
156 int count = 0;
157 Map<String, String> fieldValues = new HashMap<String, String>();
158
159 fieldValues.put(EndowPropertyConstants.KEMID_FEE_MTHD_CD, feeMethodCode);
160 count = businessObjectService.countMatching(KemidFee.class, fieldValues);
161
162 if (count > 0) {
163 isUsed = true;
164 }
165
166 return isUsed;
167 }
168
169
170 }