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.ArrayList; 019 import java.util.Collection; 020 import java.util.HashMap; 021 import java.util.Map; 022 023 import org.apache.commons.lang.StringUtils; 024 import org.kuali.kfs.module.endow.EndowPropertyConstants; 025 import org.kuali.kfs.module.endow.businessobject.HoldingHistory; 026 import org.kuali.kfs.module.endow.businessobject.Security; 027 028 import org.kuali.kfs.module.endow.document.service.HoldingHistoryService; 029 import org.kuali.kfs.sys.context.SpringContext; 030 import org.kuali.rice.kns.service.BusinessObjectService; 031 import org.kuali.rice.kns.service.DataDictionaryService; 032 import org.kuali.rice.kns.util.KualiInteger; 033 034 /** 035 * This class provides service for Security maintenance 036 */ 037 public class HoldingHistoryServiceImpl implements HoldingHistoryService { 038 039 protected BusinessObjectService businessObjectService; 040 041 /** 042 * @see org.kuali.kfs.module.endow.document.service.PooledFundControlService#getHoldingHistoryBySecuritIdAndMonthEndId(java.lang.String, KualiInteger) 043 */ 044 public Collection<HoldingHistory> getHoldingHistoryBySecuritIdAndMonthEndId(String securityId, KualiInteger monthEndId) { 045 046 Collection<HoldingHistory> holdingHistory = new ArrayList(); 047 048 if (StringUtils.isNotBlank(securityId)) { 049 Map criteria = new HashMap(); 050 051 if (SpringContext.getBean(DataDictionaryService.class).getAttributeForceUppercase(HoldingHistory.class, EndowPropertyConstants.HISTORY_VALUE_ADJUSTMENT_SECURITY_ID)) { 052 securityId = securityId.toUpperCase(); 053 } 054 055 criteria.put(EndowPropertyConstants.HISTORY_VALUE_ADJUSTMENT_SECURITY_ID, securityId); 056 criteria.put(EndowPropertyConstants.MONTH_END_DATE_ID, monthEndId); 057 holdingHistory = businessObjectService.findMatching(HoldingHistory.class, criteria); 058 } 059 060 return holdingHistory; 061 062 } 063 064 /** 065 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#saveHoldingHistory(HoldingHistory) 066 */ 067 public boolean saveHoldingHistory(HoldingHistory holdingHistoryRecord) { 068 boolean success = true; 069 070 try { 071 businessObjectService.save(holdingHistoryRecord); 072 } 073 catch (Exception ex) { 074 success = false; 075 } 076 077 return success; 078 } 079 080 /** 081 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getKemIdFromHoldingHistory(String) 082 */ 083 public String getKemIdFromHoldingHistory(String securityId) { 084 String kemId = ""; 085 086 Collection<HoldingHistory> holdingHistory = new ArrayList(); 087 088 if (StringUtils.isNotBlank(securityId)) { 089 Map criteria = new HashMap(); 090 091 if (SpringContext.getBean(DataDictionaryService.class).getAttributeForceUppercase(HoldingHistory.class, EndowPropertyConstants.HISTORY_VALUE_ADJUSTMENT_SECURITY_ID)) { 092 securityId = securityId.toUpperCase(); 093 } 094 095 criteria.put(EndowPropertyConstants.HISTORY_VALUE_ADJUSTMENT_SECURITY_ID, securityId); 096 097 holdingHistory = businessObjectService.findMatching(HoldingHistory.class, criteria); 098 } 099 100 for (HoldingHistory holdingHistoryRecord : holdingHistory) { 101 kemId = holdingHistoryRecord.getKemid(); 102 } 103 104 return kemId; 105 } 106 107 /** 108 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getHoldingHistoryForMatchingSecurityClassCode(String) 109 * Get all securityIds for the given securityClassCode from END_SEC_T table. 110 */ 111 public Collection<HoldingHistory> getHoldingHistoryForMatchingSecurityClassCode(String securityClassCode) { 112 Collection<HoldingHistory> holdingHistory = new ArrayList(); 113 114 Collection<Security> securities = new ArrayList(); 115 116 if (StringUtils.isNotBlank(securityClassCode)) { 117 Map criteria = new HashMap(); 118 119 if (SpringContext.getBean(DataDictionaryService.class).getAttributeForceUppercase(Security.class, EndowPropertyConstants.SECURITY_CLASS_CODE)) { 120 securityClassCode = securityClassCode.toUpperCase(); 121 } 122 criteria.put(EndowPropertyConstants.SECURITY_CLASS_CODE, securityClassCode); 123 124 securities = businessObjectService.findMatching(Security.class, criteria); 125 126 for (Security security : securities) { 127 criteria.clear(); 128 criteria.put(EndowPropertyConstants.HOLDING_HISTORY_SECURITY_ID, security.getId()); 129 130 holdingHistory.addAll(businessObjectService.findMatching(HoldingHistory.class, criteria)); 131 } 132 } 133 134 return holdingHistory; 135 136 } 137 138 /** 139 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getHoldingHistoryBySecurityId(String) 140 */ 141 public Collection<HoldingHistory> getHoldingHistoryBySecurityId(String securityId) { 142 Collection<HoldingHistory> holdingHistory = new ArrayList(); 143 144 if (StringUtils.isNotBlank(securityId)) { 145 Map criteria = new HashMap(); 146 147 if (SpringContext.getBean(DataDictionaryService.class).getAttributeForceUppercase(HoldingHistory.class, EndowPropertyConstants.HOLDING_HISTORY_SECURITY_ID)) { 148 securityId = securityId.toUpperCase(); 149 } 150 151 criteria.put(EndowPropertyConstants.HOLDING_HISTORY_SECURITY_ID, securityId); 152 153 holdingHistory = businessObjectService.findMatching(HoldingHistory.class, criteria); 154 } 155 156 return holdingHistory; 157 } 158 159 /** 160 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getHoldingHistoryForMatchingSecurityClassCodeAndSecurityId(String, String) 161 */ 162 public Collection<HoldingHistory> getHoldingHistoryForMatchingSecurityClassCodeAndSecurityId(String securityClassCode, String securityId) { 163 Collection<HoldingHistory> holdingHistory = new ArrayList(); 164 165 holdingHistory = getHoldingHistoryForMatchingSecurityClassCode(securityClassCode); 166 167 holdingHistory.addAll(getHoldingHistoryBySecurityId(securityId)); 168 169 return holdingHistory; 170 } 171 172 /** 173 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getHoldingHistoryByIncomePrincipalIndicator(String) 174 */ 175 public Collection<HoldingHistory> getHoldingHistoryByIncomePrincipalIndicator(String incomePrincipalIndicator) { 176 Collection<HoldingHistory> holdingHistory = new ArrayList(); 177 178 if (StringUtils.isNotBlank(incomePrincipalIndicator)) { 179 Map criteria = new HashMap(); 180 181 if (SpringContext.getBean(DataDictionaryService.class).getAttributeForceUppercase(HoldingHistory.class, EndowPropertyConstants.HOLDING_HISTORY_INCOME_PRINCIPAL_INDICATOR)) { 182 incomePrincipalIndicator = incomePrincipalIndicator.toUpperCase(); 183 } 184 185 criteria.put(EndowPropertyConstants.HOLDING_HISTORY_INCOME_PRINCIPAL_INDICATOR, incomePrincipalIndicator); 186 187 holdingHistory = businessObjectService.findMatching(HoldingHistory.class, criteria); 188 } 189 190 return holdingHistory; 191 } 192 193 /** 194 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getAllHoldingHistory() 195 */ 196 public Collection<HoldingHistory> getAllHoldingHistory() { 197 198 Collection<HoldingHistory> holdingHistory = new ArrayList(); 199 200 holdingHistory = businessObjectService.findAll(HoldingHistory.class); 201 202 return holdingHistory; 203 } 204 205 206 /** 207 * This method gets the businessObjectService. 208 * 209 * @return businessObjectService 210 */ 211 protected BusinessObjectService getBusinessObjectService() { 212 return businessObjectService; 213 } 214 215 /** 216 * This method sets the businessObjectService 217 * 218 * @param businessObjectService 219 */ 220 public void setBusinessObjectService(BusinessObjectService businessObjectService) { 221 this.businessObjectService = businessObjectService; 222 } 223 }