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.external.kc.businessobject;
018
019 import java.util.LinkedHashMap;
020
021 import org.kuali.kfs.coa.businessobject.Account;
022 import org.kuali.kfs.coa.businessobject.Chart;
023 import org.kuali.kfs.integration.cg.ContractsAndGrantsAccountAwardInformation;
024 import org.kuali.kfs.integration.cg.ContractsAndGrantsAwardAccount;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.rice.kim.bo.Person;
027 import org.kuali.rice.kim.service.PersonService;
028 import org.kuali.rice.kns.util.ObjectUtils;
029
030 /**
031 * This class represents an association between an award and an account. It's like a reference to the account from the award. This
032 * way an award can maintain a collection of these references instead of owning accounts directly.
033 */
034 public class AwardAccount implements ContractsAndGrantsAccountAwardInformation {
035
036 private Long proposalNumber;
037 private String chartOfAccountsCode;
038 private String accountNumber;
039 private String principalId;
040 private boolean active = true;
041 private boolean newCollectionRecord;
042 private boolean federalSponsor;
043
044 private Account account;
045 private Chart chartOfAccounts;
046 private Person projectDirector;
047 private Award award;
048
049 /**
050 * Default constructor.
051 */
052 public AwardAccount() {
053 // Struts needs this instance to populate the secondary key, principalName.
054 try {
055 projectDirector = (Person)SpringContext.getBean(PersonService.class).getPersonImplementationClass().newInstance();
056 } catch (Exception e) {}
057 }
058
059 public AwardAccount(ContractsAndGrantsAwardAccount awardAccountDTO, String accountNumber, String chartOfAccountsCode, String cfdaNumber){
060 // Struts needs this instance to populate the secondary key, principalName.
061 try {
062 projectDirector = (Person)SpringContext.getBean(PersonService.class).getPersonImplementationClass().newInstance();
063 } catch (Exception e) {}
064
065
066 //setup this class from DTO
067 Proposal proposal = new Proposal();
068 Award award = new Award();
069 Agency agency = new Agency();
070 Agency primeAgency = new Agency();
071
072 this.setAccountNumber(accountNumber);
073 this.setChartOfAccountsCode(chartOfAccountsCode);
074 this.setPrincipalId(awardAccountDTO.getProjectDirector());
075 this.setProposalNumber(awardAccountDTO.getAwardId());
076 this.setActive(true);
077 this.setFederalSponsor(awardAccountDTO.getFederalSponsor());
078
079 award.setAwardNumber(awardAccountDTO.getProposalNumber());
080 award.setProposalNumber(awardAccountDTO.getAwardId());
081 award.setAgencyNumber(awardAccountDTO.getSponsorCode());
082 award.setAwardTitle(awardAccountDTO.getAwardTitle());
083 award.setGrantNumber(awardAccountDTO.getGrantNumber());
084 award.setCfdaNumber(cfdaNumber);
085
086 proposal.setFederalPassThroughAgencyNumber(awardAccountDTO.getProposalFederalPassThroughAgencyNumber());
087 proposal.setProposalNumber(awardAccountDTO.getAwardId());
088
089 proposal.setAward(award);
090 this.setAward(award);
091 this.getAward().setProposal(proposal);
092
093 agency.setAgencyNumber(awardAccountDTO.getSponsorCode());
094 agency.setReportingName(awardAccountDTO.getSponsorName());
095 primeAgency.setAgencyNumber(awardAccountDTO.getPrimeSponsorCode());
096 primeAgency.setReportingName(awardAccountDTO.getPrimeSponsorName());
097 this.getAward().setAgency(agency);
098 this.getAward().setPrimeAgency(primeAgency);
099 }
100
101 /***
102 * @see org.kuali.kfs.integration.businessobject.cg.ContractsAndGrantsAccountAwardInformation#getProposalNumber()
103 */
104 public Long getProposalNumber() {
105 return proposalNumber;
106 }
107
108 /**
109 * Sets the proposalNumber attribute.
110 *
111 * @param proposalNumber The proposalNumber to set.
112 */
113 public void setProposalNumber(Long proposalNumber) {
114 this.proposalNumber = proposalNumber;
115 }
116
117
118 /***
119 * @see org.kuali.kfs.integration.businessobject.cg.ContractsAndGrantsAccountAwardInformation#getChartOfAccountsCode()
120 */
121 public String getChartOfAccountsCode() {
122 return chartOfAccountsCode;
123 }
124
125 /**
126 * Sets the chartOfAccountsCode attribute.
127 *
128 * @param chartOfAccountsCode The chartOfAccountsCode to set.
129 */
130 public void setChartOfAccountsCode(String chartOfAccountsCode) {
131 this.chartOfAccountsCode = chartOfAccountsCode;
132 }
133
134
135 /***
136 * @see org.kuali.kfs.integration.businessobject.cg.ContractsAndGrantsAccountAwardInformation#getAccountNumber()
137 */
138 public String getAccountNumber() {
139 return accountNumber;
140 }
141
142 /**
143 * Sets the accountNumber attribute.
144 *
145 * @param accountNumber The accountNumber to set.
146 */
147 public void setAccountNumber(String accountNumber) {
148 this.accountNumber = accountNumber;
149 }
150
151 /***
152 * @see org.kuali.kfs.integration.businessobject.cg.ContractsAndGrantsAccountAwardInformation#getPrincipalId()
153 */
154 public String getPrincipalId() {
155 return principalId;
156 }
157
158 /**
159 * Sets the principalId attribute.
160 *
161 * @param principalId The principalId to set.
162 */
163 public void setPrincipalId(String principalId) {
164 this.principalId = principalId;
165 }
166
167 /***
168 * @see org.kuali.kfs.integration.businessobject.cg.ContractsAndGrantsAccountAwardInformation#getAccount()
169 */
170 public Account getAccount() {
171 return account;
172 }
173
174 /**
175 * Sets the account attribute.
176 *
177 * @param account The account to set.
178 */
179 @Deprecated
180 public void setAccount(Account account) {
181 this.account = account;
182 }
183
184 /***
185 * @see org.kuali.kfs.integration.businessobject.cg.ContractsAndGrantsAccountAwardInformation#getChartOfAccounts()
186 */
187 public Chart getChartOfAccounts() {
188 return chartOfAccounts;
189 }
190
191 /**
192 * Sets the chartOfAccounts attribute.
193 *
194 * @param chartOfAccounts The chartOfAccounts to set.
195 */
196 @Deprecated
197 public void setChartOfAccounts(Chart chartOfAccounts) {
198 this.chartOfAccounts = chartOfAccounts;
199 }
200
201 /***
202 * @see org.kuali.kfs.integration.businessobject.cg.ContractsAndGrantsAccountAwardInformation#getProjectDirector()
203 */
204 public Person getProjectDirector() {
205 projectDirector = SpringContext.getBean(org.kuali.rice.kim.service.PersonService.class).updatePersonIfNecessary(principalId, projectDirector);
206 return projectDirector;
207 }
208
209 /**
210 * Sets the project director attribute
211 *
212 * @param projectDirector The projectDirector to set.
213 * @deprecated Setter is required by OJB, but should not be used to modify this attribute. This attribute is set on the initial
214 * creation of the object and should not be changed.
215 */
216 @Deprecated
217 public void setProjectDirector(Person projectDirector) {
218 this.projectDirector = projectDirector;
219 }
220
221 /**
222 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
223 */
224 @SuppressWarnings("unchecked")
225 protected LinkedHashMap toStringMapper() {
226 LinkedHashMap m = new LinkedHashMap();
227 if (this.proposalNumber != null) {
228 m.put("proposalNumber", this.proposalNumber.toString());
229 }
230 m.put("chartOfAccountsCode", this.chartOfAccountsCode);
231 m.put("accountNumber", this.accountNumber);
232 return m;
233 }
234
235 public Award getAward() {
236 return award;
237 }
238
239 public void setAward(Award award) {
240 this.award = award;
241 }
242
243 /**
244 * @see org.kuali.rice.kns.bo.Inactivateable#isActive()
245 */
246 public boolean isActive() {
247 return active;
248 }
249
250 /**
251 * @see org.kuali.rice.kns.bo.Inactivateable#setActive(boolean)
252 */
253 public void setActive(boolean active) {
254 this.active = true;
255 }
256
257 /**
258 * @see org.kuali.kfs.integration.cg.ContractsAndGrantsAccountAwardInformation#getProjectDirectorName()
259 */
260 public String getProjectDirectorName() {
261 if (!ObjectUtils.isNull(getProjectDirector())) {
262 return getProjectDirector().getName();
263 }
264 return null;
265 }
266
267 // @Override
268 public void prepareForWorkflow() {
269
270 }
271
272 // @Override
273 public void refresh() {
274 }
275
276 public boolean isNewCollectionRecord() {
277 return false;
278 }
279
280 public void setNewCollectionRecord(boolean newCollectionRecord) {
281 this.newCollectionRecord = newCollectionRecord;
282 }
283
284 public boolean isFederalSponsor() {
285 return federalSponsor;
286 }
287
288 public void setFederalSponsor(boolean federalSponsor) {
289 this.federalSponsor = federalSponsor;
290 }
291 }
292