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.sql.Date;
020 import java.sql.Timestamp;
021 import java.util.Comparator;
022 import java.util.LinkedHashMap;
023 import java.util.List;
024 import java.util.SortedSet;
025 import java.util.TreeSet;
026
027 import org.kuali.kfs.coa.businessobject.Account;
028 import org.kuali.kfs.coa.businessobject.Chart;
029 import org.kuali.kfs.coa.businessobject.Organization;
030 import org.kuali.kfs.coa.businessobject.SubAccount;
031 import org.kuali.kfs.sys.KFSPropertyConstants;
032 import org.kuali.kfs.sys.context.SpringContext;
033 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
034 import org.kuali.rice.kew.actiontaken.service.ActionTakenService;
035 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
036
037 /**
038 *
039 */
040 public class BudgetConstructionAccountSelect extends PersistableBusinessObjectBase {
041
042 private String principalId;
043 private Integer universityFiscalYear;
044 private String chartOfAccountsCode;
045 private String accountNumber;
046 private String subAccountNumber;
047 private String documentNumber;
048 private Integer organizationLevelCode;
049 private String organizationChartOfAccountsCode;
050 private String organizationCode;
051 private String financialDocumentStatusCode;
052 private String financialDocumentInitiatorIdentifier;
053 private Date financialDocumentCreateDate;
054
055 private BudgetConstructionHeader budgetConstructionHeader;
056 private Account account;
057 private Chart chartOfAccounts;
058 private Chart organizationChartOfAccounts;
059 private SubAccount subAccount;
060 private Organization organization;
061
062 /**
063 * Default constructor.
064 */
065 public BudgetConstructionAccountSelect() {
066 super();
067 }
068
069 /**
070 * Gets the principalId attribute.
071 *
072 * @return Returns the principalId
073 */
074 public String getPrincipalId() {
075 return principalId;
076 }
077
078 /**
079 * Sets the principalId attribute.
080 *
081 * @param principalId The principalId to set.
082 */
083 public void setPrincipalId(String principalId) {
084 this.principalId = principalId;
085 }
086
087
088 /**
089 * Gets the universityFiscalYear attribute.
090 *
091 * @return Returns the universityFiscalYear
092 */
093 public Integer getUniversityFiscalYear() {
094 return universityFiscalYear;
095 }
096
097 /**
098 * Sets the universityFiscalYear attribute.
099 *
100 * @param universityFiscalYear The universityFiscalYear to set.
101 */
102 public void setUniversityFiscalYear(Integer universityFiscalYear) {
103 this.universityFiscalYear = universityFiscalYear;
104 }
105
106
107 /**
108 * Gets the chartOfAccountsCode attribute.
109 *
110 * @return Returns the chartOfAccountsCode
111 */
112 public String getChartOfAccountsCode() {
113 return chartOfAccountsCode;
114 }
115
116 /**
117 * Sets the chartOfAccountsCode attribute.
118 *
119 * @param chartOfAccountsCode The chartOfAccountsCode to set.
120 */
121 public void setChartOfAccountsCode(String chartOfAccountsCode) {
122 this.chartOfAccountsCode = chartOfAccountsCode;
123 }
124
125
126 /**
127 * Gets the accountNumber attribute.
128 *
129 * @return Returns the accountNumber
130 */
131 public String getAccountNumber() {
132 return accountNumber;
133 }
134
135 /**
136 * Sets the accountNumber attribute.
137 *
138 * @param accountNumber The accountNumber to set.
139 */
140 public void setAccountNumber(String accountNumber) {
141 this.accountNumber = accountNumber;
142 }
143
144
145 /**
146 * Gets the subAccountNumber attribute.
147 *
148 * @return Returns the subAccountNumber
149 */
150 public String getSubAccountNumber() {
151 return subAccountNumber;
152 }
153
154 /**
155 * Sets the subAccountNumber attribute.
156 *
157 * @param subAccountNumber The subAccountNumber to set.
158 */
159 public void setSubAccountNumber(String subAccountNumber) {
160 this.subAccountNumber = subAccountNumber;
161 }
162
163
164 /**
165 * Gets the documentNumber attribute.
166 *
167 * @return Returns the documentNumber
168 */
169 public String getDocumentNumber() {
170 return documentNumber;
171 }
172
173 /**
174 * Sets the documentNumber attribute.
175 *
176 * @param documentNumber The documentNumber to set.
177 */
178 public void setDocumentNumber(String documentNumber) {
179 this.documentNumber = documentNumber;
180 }
181
182
183 /**
184 * Gets the organizationLevelCode attribute.
185 *
186 * @return Returns the organizationLevelCode
187 */
188 public Integer getOrganizationLevelCode() {
189 return organizationLevelCode;
190 }
191
192 /**
193 * Sets the organizationLevelCode attribute.
194 *
195 * @param organizationLevelCode The organizationLevelCode to set.
196 */
197 public void setOrganizationLevelCode(Integer organizationLevelCode) {
198 this.organizationLevelCode = organizationLevelCode;
199 }
200
201
202 /**
203 * Gets the organizationChartOfAccountsCode attribute.
204 *
205 * @return Returns the organizationChartOfAccountsCode
206 */
207 public String getOrganizationChartOfAccountsCode() {
208 return organizationChartOfAccountsCode;
209 }
210
211 /**
212 * Sets the organizationChartOfAccountsCode attribute.
213 *
214 * @param organizationChartOfAccountsCode The organizationChartOfAccountsCode to set.
215 */
216 public void setOrganizationChartOfAccountsCode(String organizationChartOfAccountsCode) {
217 this.organizationChartOfAccountsCode = organizationChartOfAccountsCode;
218 }
219
220
221 /**
222 * Gets the organizationCode attribute.
223 *
224 * @return Returns the organizationCode
225 */
226 public String getOrganizationCode() {
227 return organizationCode;
228 }
229
230 /**
231 * Sets the organizationCode attribute.
232 *
233 * @param organizationCode The organizationCode to set.
234 */
235 public void setOrganizationCode(String organizationCode) {
236 this.organizationCode = organizationCode;
237 }
238
239
240 /**
241 * Gets the financialDocumentStatusCode attribute.
242 *
243 * @return Returns the financialDocumentStatusCode
244 */
245 public String getFinancialDocumentStatusCode() {
246 return financialDocumentStatusCode;
247 }
248
249 /**
250 * Sets the financialDocumentStatusCode attribute.
251 *
252 * @param financialDocumentStatusCode The financialDocumentStatusCode to set.
253 */
254 public void setFinancialDocumentStatusCode(String financialDocumentStatusCode) {
255 this.financialDocumentStatusCode = financialDocumentStatusCode;
256 }
257
258
259 /**
260 * Gets the financialDocumentInitiatorIdentifier attribute.
261 *
262 * @return Returns the financialDocumentInitiatorIdentifier
263 */
264 public String getFinancialDocumentInitiatorIdentifier() {
265
266 if (this.financialDocumentInitiatorIdentifier == null) {
267 try {
268 Long docNum = Long.valueOf(this.getDocumentNumber());
269
270 ActionTakenService actionTakenService = SpringContext.getBean(ActionTakenService.class);
271 List<ActionTakenValue> actionsTaken = (List<ActionTakenValue>) actionTakenService.findByRouteHeaderIdIgnoreCurrentInd(docNum);
272 SortedSet<ActionTakenValue> sortedActionsTaken = this.getSortedActionsTaken(actionsTaken);
273 if (sortedActionsTaken.size() > 0) {
274 this.financialDocumentInitiatorIdentifier = SpringContext.getBean(org.kuali.rice.kim.service.PersonService.class).getPerson(sortedActionsTaken.last().getPrincipalId()).getPrincipalName();
275 this.financialDocumentCreateDate = new Date(sortedActionsTaken.last().getActionDate().getTime());
276 }
277 else {
278 this.financialDocumentInitiatorIdentifier = "NotFound";
279 }
280
281
282 }
283 catch (Exception e) {
284 this.financialDocumentInitiatorIdentifier = "LookupError";
285 }
286 }
287 return financialDocumentInitiatorIdentifier;
288 }
289
290 /**
291 * Sets the financialDocumentInitiatorIdentifier attribute.
292 *
293 * @param financialDocumentInitiatorIdentifier The financialDocumentInitiatorIdentifier to set.
294 */
295 public void setFinancialDocumentInitiatorIdentifier(String financialDocumentInitiatorIdentifier) {
296 this.financialDocumentInitiatorIdentifier = financialDocumentInitiatorIdentifier;
297 }
298
299
300 /**
301 * Gets the financialDocumentCreateDate attribute.
302 *
303 * @return Returns the financialDocumentCreateDate
304 */
305 public Date getFinancialDocumentCreateDate() {
306
307 if (this.financialDocumentCreateDate == null) {
308 try {
309 Long docNum = Long.valueOf(this.getDocumentNumber());
310
311 ActionTakenService actionTakenService = SpringContext.getBean(ActionTakenService.class);
312 List<ActionTakenValue> actionsTaken = (List<ActionTakenValue>) actionTakenService.findByRouteHeaderIdIgnoreCurrentInd(docNum);
313 SortedSet<ActionTakenValue> sortedActionsTaken = this.getSortedActionsTaken(actionsTaken);
314 if (sortedActionsTaken.size() > 0) {
315 this.financialDocumentInitiatorIdentifier = SpringContext.getBean(org.kuali.rice.kim.service.PersonService.class).getPerson(sortedActionsTaken.last().getPrincipalId()).getPrincipalName();
316 this.financialDocumentCreateDate = new Date(sortedActionsTaken.last().getActionDate().getTime());
317 }
318
319 }
320 catch (Exception e) {
321 // nothing
322 }
323 }
324 return financialDocumentCreateDate;
325 }
326
327 /**
328 * Sets the financialDocumentCreateDate attribute.
329 *
330 * @param financialDocumentCreateDate The financialDocumentCreateDate to set.
331 */
332 public void setFinancialDocumentCreateDate(Date financialDocumentCreateDate) {
333 this.financialDocumentCreateDate = financialDocumentCreateDate;
334 }
335
336
337 /**
338 * Gets the budgetConstructionHeader attribute.
339 *
340 * @return Returns the budgetConstructionHeader
341 */
342 public BudgetConstructionHeader getBudgetConstructionHeader() {
343 return budgetConstructionHeader;
344 }
345
346 /**
347 * Sets the budgetConstructionHeader attribute.
348 *
349 * @param budgetConstructionHeader The budgetConstructionHeader to set.
350 * @deprecated
351 */
352 public void setBudgetConstructionHeader(BudgetConstructionHeader budgetConstructionHeader) {
353 this.budgetConstructionHeader = budgetConstructionHeader;
354 }
355
356 /**
357 * Gets the organization attribute.
358 *
359 * @return Returns the organization
360 */
361 public Organization getOrganization() {
362 return organization;
363 }
364
365 /**
366 * Sets the organization attribute.
367 *
368 * @param organization The organization to set.
369 * @deprecated
370 */
371 public void setOrganization(Organization organization) {
372 this.organization = organization;
373 }
374
375 /**
376 * Gets the account attribute.
377 *
378 * @return Returns the account
379 */
380 public Account getAccount() {
381 return account;
382 }
383
384 /**
385 * Sets the account attribute.
386 *
387 * @param account The account to set.
388 * @deprecated
389 */
390 public void setAccount(Account account) {
391 this.account = account;
392 }
393
394 /**
395 * Gets the chartOfAccounts attribute.
396 *
397 * @return Returns the chartOfAccounts
398 */
399 public Chart getChartOfAccounts() {
400 return chartOfAccounts;
401 }
402
403 /**
404 * Sets the chartOfAccounts attribute.
405 *
406 * @param chartOfAccounts The chartOfAccounts to set.
407 * @deprecated
408 */
409 public void setChartOfAccounts(Chart chartOfAccounts) {
410 this.chartOfAccounts = chartOfAccounts;
411 }
412
413 /**
414 * Gets the organizationChartOfAccounts attribute.
415 *
416 * @return Returns the organizationChartOfAccounts
417 */
418 public Chart getOrganizationChartOfAccounts() {
419 return organizationChartOfAccounts;
420 }
421
422 /**
423 * Sets the organizationChartOfAccounts attribute.
424 *
425 * @param organizationChartOfAccounts The organizationChartOfAccounts to set.
426 * @deprecated
427 */
428 public void setOrganizationChartOfAccounts(Chart organizationChartOfAccounts) {
429 this.organizationChartOfAccounts = organizationChartOfAccounts;
430 }
431
432 /**
433 * Gets the subAccount attribute.
434 *
435 * @return Returns the subAccount.
436 */
437 public SubAccount getSubAccount() {
438 return subAccount;
439 }
440
441 /**
442 * Sets the subAccount attribute value.
443 *
444 * @param subAccount The subAccount to set.
445 * @deprecated
446 */
447 public void setSubAccount(SubAccount subAccount) {
448 this.subAccount = subAccount;
449 }
450
451 /**
452 * Takes a list of ActionTakenValue and returns a sorted set ordered by action date
453 *
454 * @param actionsTaken
455 * @return
456 */
457 protected SortedSet<ActionTakenValue> getSortedActionsTaken(List<ActionTakenValue> actionsTaken){
458
459 // we need a sorted set of actions taken by action date
460 SortedSet<ActionTakenValue> sortedActionsTaken = new TreeSet<ActionTakenValue>(new Comparator<ActionTakenValue>(){
461 public int compare(ActionTakenValue aTaken, ActionTakenValue bTaken){
462 Timestamp aActionDate = aTaken.getActionDate();
463 Timestamp bActionDate = bTaken.getActionDate();
464 return aActionDate.compareTo(bActionDate);
465 }
466 });
467 sortedActionsTaken.addAll(actionsTaken);
468 return sortedActionsTaken;
469
470 }
471
472 /**
473 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
474 */
475 protected LinkedHashMap toStringMapper() {
476 LinkedHashMap m = new LinkedHashMap();
477 m.put("principalId", this.principalId);
478 if (this.universityFiscalYear != null) {
479 m.put("universityFiscalYear", this.universityFiscalYear.toString());
480 }
481 m.put("chartOfAccountsCode", this.chartOfAccountsCode);
482 m.put("accountNumber", this.accountNumber);
483 m.put("subAccountNumber", this.subAccountNumber);
484 m.put(KFSPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
485 return m;
486 }
487
488
489 }
490