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 017 package org.kuali.kfs.module.bc.businessobject; 018 019 import java.util.Collection; 020 import java.util.HashMap; 021 import java.util.LinkedHashMap; 022 import java.util.List; 023 import java.util.Map; 024 025 import org.kuali.kfs.coa.businessobject.ObjectCode; 026 import org.kuali.kfs.fp.service.impl.FiscalYearFunctionControlServiceImpl; 027 import org.kuali.kfs.sys.KFSPropertyConstants; 028 import org.kuali.kfs.sys.context.SpringContext; 029 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; 030 import org.kuali.rice.kns.service.BusinessObjectService; 031 032 /** 033 * Business object that represents a selected/unselected object code for a user. 034 */ 035 public class BudgetConstructionObjectPick extends PersistableBusinessObjectBase { 036 037 private String financialObjectCode; 038 private Integer selectFlag; 039 private String principalId; 040 041 /** 042 * Default constructor. 043 */ 044 public BudgetConstructionObjectPick() { 045 selectFlag = new Integer(0); 046 } 047 048 /** 049 * Gets the financialObjectCode attribute. 050 * 051 * @return Returns the financialObjectCode 052 */ 053 public String getFinancialObjectCode() { 054 return financialObjectCode; 055 } 056 057 /** 058 * Sets the financialObjectCode attribute. 059 * 060 * @param financialObjectCode The financialObjectCode to set. 061 */ 062 public void setFinancialObjectCode(String financialObjectCode) { 063 this.financialObjectCode = financialObjectCode; 064 } 065 066 067 /** 068 * Gets the selectFlag attribute. 069 * 070 * @return Returns the selectFlag 071 */ 072 public Integer getSelectFlag() { 073 return selectFlag; 074 } 075 076 /** 077 * We only care about a general description for the object code regardless of chart. Therefore we need to do a query and return 078 * first row (if multiple). 079 * 080 * @return String - Object code description 081 */ 082 public String getObjectCodeDescription() { 083 Map criteria = new HashMap(); 084 085 List activeBudgetYears = SpringContext.getBean(FiscalYearFunctionControlServiceImpl.class).getActiveBudgetYear(); 086 criteria.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, activeBudgetYears.get(0)); 087 criteria.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, this.getFinancialObjectCode()); 088 089 Collection results = SpringContext.getBean(BusinessObjectService.class).findMatching(ObjectCode.class, criteria); 090 if (results != null && results.size() > 0) { 091 ObjectCode objectCode = (ObjectCode) results.iterator().next(); 092 return objectCode.getFinancialObjectCodeName(); 093 } 094 095 return ""; 096 } 097 098 /** 099 * Dummy setter for UI. 100 */ 101 public void setObjectCodeDescription(String objectCodeDescription) { 102 } 103 104 /** 105 * Sets the selectFlag attribute. 106 * 107 * @param selectFlag The selectFlag to set. 108 */ 109 public void setSelectFlag(Integer selectFlag) { 110 this.selectFlag = selectFlag; 111 } 112 113 114 /** 115 * Gets the principalId attribute. 116 * 117 * @return Returns the principalId. 118 */ 119 public String getPrincipalId() { 120 return principalId; 121 } 122 123 /** 124 * Sets the principalId attribute value. 125 * 126 * @param principalId The principalId to set. 127 */ 128 public void setPrincipalId(String principalId) { 129 this.principalId = principalId; 130 } 131 132 /** 133 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 134 */ 135 protected LinkedHashMap toStringMapper() { 136 LinkedHashMap m = new LinkedHashMap(); 137 m.put("principalId", this.principalId); 138 m.put("financialObjectCode", this.financialObjectCode); 139 return m; 140 } 141 } 142