1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.dataaccess.impl;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.ojb.broker.query.Criteria;
28 import org.apache.ojb.broker.query.Query;
29 import org.apache.ojb.broker.query.QueryByCriteria;
30 import org.apache.ojb.broker.query.QueryFactory;
31 import org.apache.ojb.broker.query.ReportQueryByCriteria;
32 import org.kuali.ole.coa.businessobject.Account;
33 import org.kuali.ole.gl.GeneralLedgerConstants;
34 import org.kuali.ole.gl.OJBUtility;
35 import org.kuali.ole.gl.businessobject.Balance;
36 import org.kuali.ole.gl.businessobject.CashBalance;
37 import org.kuali.ole.gl.businessobject.Transaction;
38 import org.kuali.ole.gl.dataaccess.BalanceDao;
39 import org.kuali.ole.gl.dataaccess.LedgerBalanceBalancingDao;
40 import org.kuali.ole.sys.OLEConstants;
41 import org.kuali.ole.sys.OLEPropertyConstants;
42 import org.kuali.ole.sys.businessobject.SystemOptions;
43 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
44 import org.kuali.rice.core.api.util.type.KualiDecimal;
45 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
46
47
48
49
50 public class BalanceDaoOjb extends PlatformAwareDaoBaseOjb implements BalanceDao, LedgerBalanceBalancingDao {
51 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BalanceDaoOjb.class);
52
53
54
55
56
57
58
59
60
61 public Iterator<Object[]> getGlSummary(int universityFiscalYear, Collection<String> balanceTypeCodes) {
62 LOG.debug("getGlSummary() started");
63
64 Criteria c = new Criteria();
65 c.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityFiscalYear);
66 c.addIn(OLEPropertyConstants.BALANCE_TYPE_CODE, balanceTypeCodes);
67
68 String[] attributes = new String[] { "account.subFundGroup.fundGroupCode", "sum(accountLineAnnualBalanceAmount)", "sum(beginningBalanceLineAmount)", "sum(contractsGrantsBeginningBalanceAmount)", "sum(month1Amount)", "sum(month2Amount)", "sum(month3Amount)", "sum(month4Amount)", "sum(month5Amount)", "sum(month6Amount)", "sum(month7Amount)", "sum(month8Amount)", "sum(month9Amount)", "sum(month10Amount)", "sum(month11Amount)", "sum(month12Amount)", "sum(month13Amount)" };
69
70 String[] groupby = new String[] { "account.subFundGroup.fundGroupCode" };
71
72 ReportQueryByCriteria query = new ReportQueryByCriteria(Balance.class, c);
73
74 query.setAttributes(attributes);
75 query.addGroupBy(groupby);
76 query.addOrderByAscending("account.subFundGroup.fundGroupCode");
77
78 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
79 }
80
81
82
83
84
85
86
87
88 public Iterator<Balance> findBalancesForFiscalYear(Integer year) {
89 LOG.debug("findBalancesForFiscalYear() started");
90
91 Criteria c = new Criteria();
92 c.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
93
94 QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
95 query.addOrderByAscending(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
96 query.addOrderByAscending(OLEPropertyConstants.ACCOUNT_NUMBER);
97 query.addOrderByAscending(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
98 query.addOrderByAscending(OLEPropertyConstants.OBJECT_CODE);
99 query.addOrderByAscending(OLEPropertyConstants.SUB_OBJECT_CODE);
100 query.addOrderByAscending(OLEPropertyConstants.BALANCE_TYPE_CODE);
101 query.addOrderByAscending(OLEPropertyConstants.OBJECT_TYPE_CODE);
102
103 return getPersistenceBrokerTemplate().getIteratorByQuery(query);
104 }
105
106
107
108
109
110
111
112
113 public Balance getBalanceByTransaction(Transaction t) {
114 LOG.debug("getBalanceByTransaction() started");
115
116 Criteria crit = new Criteria();
117 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, t.getUniversityFiscalYear());
118 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, t.getChartOfAccountsCode());
119 crit.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, t.getAccountNumber());
120 crit.addEqualTo(OLEPropertyConstants.SUB_ACCOUNT_NUMBER, t.getSubAccountNumber());
121 crit.addEqualTo(OLEPropertyConstants.OBJECT_CODE, t.getFinancialObjectCode());
122 crit.addEqualTo(OLEPropertyConstants.SUB_OBJECT_CODE, t.getFinancialSubObjectCode());
123 crit.addEqualTo(OLEPropertyConstants.BALANCE_TYPE_CODE, t.getFinancialBalanceTypeCode());
124 crit.addEqualTo(OLEPropertyConstants.OBJECT_TYPE_CODE, t.getFinancialObjectTypeCode());
125
126 QueryByCriteria qbc = QueryFactory.newQuery(Balance.class, crit);
127 return (Balance) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
128 }
129
130
131
132
133
134
135
136
137
138 protected void criteriaBuilder(Criteria criteria, String name, Collection collection) {
139 criteriaBuilderHelper(criteria, name, collection, false);
140 }
141
142
143
144
145
146
147
148
149 protected void negatedCriteriaBuilder(Criteria criteria, String name, Collection collection) {
150 criteriaBuilderHelper(criteria, name, collection, true);
151 }
152
153
154
155
156
157
158
159
160
161
162 protected void criteriaBuilderHelper(Criteria criteria, String name, Collection collection, boolean negate) {
163 if (collection != null) {
164 int size = collection.size();
165 if (size == 1) {
166 if (negate) {
167 criteria.addNotEqualTo(name, collection.iterator().next());
168 }
169 else {
170 criteria.addEqualTo(name, collection.iterator().next());
171 }
172 }
173 if (size > 1) {
174 if (negate) {
175 criteria.addNotIn(name, collection);
176 }
177 else {
178 criteria.addIn(name, collection);
179
180 }
181 }
182 }
183
184 }
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 public Iterator<Balance> findBalances(Account account, Integer fiscalYear, Collection includedObjectCodes, Collection excludedObjectCodes, Collection objectTypeCodes, Collection balanceTypeCodes) {
200 LOG.debug("findBalances() started");
201
202 Criteria criteria = new Criteria();
203
204 criteria.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, account.getAccountNumber());
205 criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, account.getChartOfAccountsCode());
206
207 criteria.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, fiscalYear);
208
209 criteriaBuilder(criteria, GeneralLedgerConstants.ColumnNames.OBJECT_TYPE_CODE, objectTypeCodes);
210 criteriaBuilder(criteria, GeneralLedgerConstants.ColumnNames.BALANCE_TYPE_CODE, balanceTypeCodes);
211 criteriaBuilder(criteria, GeneralLedgerConstants.ColumnNames.OBJECT_CODE, includedObjectCodes);
212 negatedCriteriaBuilder(criteria, GeneralLedgerConstants.ColumnNames.OBJECT_CODE, excludedObjectCodes);
213
214 ReportQueryByCriteria query = new ReportQueryByCriteria(Balance.class, criteria);
215
216
217 Iterator balances = getPersistenceBrokerTemplate().getIteratorByQuery(query);
218 return balances;
219 }
220
221
222
223
224
225
226
227
228
229
230 public Iterator<Balance> lookupCashBalance(Map fieldValues, boolean isConsolidated, Collection<String> encumbranceBalanceTypes) {
231 LOG.debug("findCashBalance() started");
232
233 Query query = this.getCashBalanceQuery(fieldValues, isConsolidated, encumbranceBalanceTypes);
234 OJBUtility.limitResultSize(query);
235 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
236 }
237
238
239
240
241
242
243
244
245
246 public Integer getDetailedCashBalanceRecordCount(Map fieldValues, Collection<String> encumbranceBalanceTypes) {
247 LOG.debug("getDetailedCashBalanceRecordCount() started");
248
249 Query query = this.getCashBalanceQuery(fieldValues, false, encumbranceBalanceTypes);
250 return getPersistenceBrokerTemplate().getCount(query);
251 }
252
253
254
255
256
257
258
259
260 public int getConsolidatedCashBalanceRecordCount(Map fieldValues, Collection<String> encumbranceBalanceTypes) {
261 LOG.debug("getCashBalanceRecordCount() started");
262
263 ReportQueryByCriteria query = this.getCashBalanceCountQuery(fieldValues, encumbranceBalanceTypes);
264 return getPersistenceBrokerTemplate().getCount(query);
265 }
266
267
268
269
270
271
272
273
274
275 public Iterator<Balance> findBalance(Map fieldValues, boolean isConsolidated, Collection<String> encumbranceBalanceTypes) {
276 LOG.debug("findBalance() started");
277
278 Query query = this.getBalanceQuery(fieldValues, isConsolidated, encumbranceBalanceTypes);
279 OJBUtility.limitResultSize(query);
280
281 if (isConsolidated) {
282 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
283 }
284 return getPersistenceBrokerTemplate().getIteratorByQuery(query);
285 }
286
287
288
289
290
291
292
293
294
295 public Iterator getConsolidatedBalanceRecordCount(Map fieldValues, Collection<String> encumbranceBalanceTypes) {
296 LOG.debug("getBalanceRecordCount() started");
297
298 ReportQueryByCriteria query = this.getBalanceCountQuery(fieldValues, encumbranceBalanceTypes);
299 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
300 }
301
302
303
304
305
306
307
308 protected ReportQueryByCriteria getCashBalanceCountQuery(Map fieldValues, Collection<String> encumbranceBalanceTypes) {
309 Criteria criteria = buildCriteriaFromMap(fieldValues, new CashBalance(), encumbranceBalanceTypes);
310 criteria.addEqualTo(OLEPropertyConstants.BALANCE_TYPE_CODE, OLEConstants.BALANCE_TYPE_ACTUAL);
311 criteria.addEqualToField("chart.financialCashObjectCode", OLEPropertyConstants.OBJECT_CODE);
312
313 ReportQueryByCriteria query = QueryFactory.newReportQuery(CashBalance.class, criteria);
314
315 List groupByList = buildGroupByList();
316 groupByList.remove(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
317 groupByList.remove(OLEPropertyConstants.SUB_OBJECT_CODE);
318 groupByList.remove(OLEPropertyConstants.OBJECT_TYPE_CODE);
319
320
321 String[] groupBy = (String[]) groupByList.toArray(new String[groupByList.size()]);
322 query.addGroupBy(groupBy);
323
324 return query;
325 }
326
327
328
329
330
331
332
333
334 protected Query getCashBalanceQuery(Map fieldValues, boolean isConsolidated, Collection<String> encumbranceBalanceTypes) {
335 Criteria criteria = buildCriteriaFromMap(fieldValues, new CashBalance(), encumbranceBalanceTypes);
336 criteria.addEqualTo(OLEPropertyConstants.BALANCE_TYPE_CODE, OLEConstants.BALANCE_TYPE_ACTUAL);
337 criteria.addEqualToField("chart.financialCashObjectCode", OLEPropertyConstants.OBJECT_CODE);
338
339 ReportQueryByCriteria query = QueryFactory.newReportQuery(CashBalance.class, criteria);
340 List attributeList = buildAttributeList(false);
341 List groupByList = buildGroupByList();
342
343
344 if (isConsolidated) {
345 attributeList.remove(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
346 groupByList.remove(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
347 attributeList.remove(OLEPropertyConstants.SUB_OBJECT_CODE);
348 groupByList.remove(OLEPropertyConstants.SUB_OBJECT_CODE);
349 attributeList.remove(OLEPropertyConstants.OBJECT_TYPE_CODE);
350 groupByList.remove(OLEPropertyConstants.OBJECT_TYPE_CODE);
351 }
352
353
354 String[] groupBy = (String[]) groupByList.toArray(new String[groupByList.size()]);
355 query.addGroupBy(groupBy);
356
357
358 String[] attributes = (String[]) attributeList.toArray(new String[attributeList.size()]);
359 query.setAttributes(attributes);
360
361 return query;
362 }
363
364
365
366
367
368
369
370
371 protected Query getBalanceQuery(Map fieldValues, boolean isConsolidated, Collection<String> encumbranceBalanceTypes) {
372 LOG.debug("getBalanceQuery(Map, boolean) started");
373
374 Criteria criteria = buildCriteriaFromMap(fieldValues, new Balance(), encumbranceBalanceTypes);
375 ReportQueryByCriteria query = QueryFactory.newReportQuery(Balance.class, criteria);
376
377
378 if (isConsolidated) {
379 List attributeList = buildAttributeList(true);
380 List groupByList = buildGroupByList();
381
382
383 attributeList.remove(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
384 groupByList.remove(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
385 attributeList.remove(OLEPropertyConstants.SUB_OBJECT_CODE);
386 groupByList.remove(OLEPropertyConstants.SUB_OBJECT_CODE);
387 attributeList.remove(OLEPropertyConstants.OBJECT_TYPE_CODE);
388 groupByList.remove(OLEPropertyConstants.OBJECT_TYPE_CODE);
389
390
391 String[] attributes = (String[]) attributeList.toArray(new String[attributeList.size()]);
392 query.setAttributes(attributes);
393
394
395 String[] groupBy = (String[]) groupByList.toArray(new String[groupByList.size()]);
396 query.addGroupBy(groupBy);
397 }
398
399 return query;
400 }
401
402
403
404
405
406
407
408 protected ReportQueryByCriteria getBalanceCountQuery(Map fieldValues, Collection<String> encumbranceBalanceTypes) {
409 Criteria criteria = buildCriteriaFromMap(fieldValues, new Balance(), encumbranceBalanceTypes);
410 ReportQueryByCriteria query = QueryFactory.newReportQuery(Balance.class, criteria);
411
412
413 query.setAttributes(new String[] { "count(*)" });
414
415 List groupByList = buildGroupByList();
416 groupByList.remove(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
417 groupByList.remove(OLEPropertyConstants.SUB_OBJECT_CODE);
418 groupByList.remove(OLEPropertyConstants.OBJECT_TYPE_CODE);
419
420
421 String[] groupBy = (String[]) groupByList.toArray(new String[groupByList.size()]);
422 query.addGroupBy(groupBy);
423 return query;
424 }
425
426
427
428
429
430
431
432
433 protected Criteria buildCriteriaFromMap(Map fieldValues, Balance balance, Collection<String> encumbranceBalanceTypes) {
434 Map localFieldValues = new HashMap();
435 localFieldValues.putAll(fieldValues);
436
437 Criteria criteria = new Criteria();
438
439
440 String propertyName = OLEPropertyConstants.BALANCE_TYPE_CODE;
441 if (localFieldValues.containsKey(propertyName)) {
442 String propertyValue = (String) localFieldValues.get(propertyName);
443 if (OLEConstants.AGGREGATE_ENCUMBRANCE_BALANCE_TYPE_CODE.equals(propertyValue)) {
444 localFieldValues.remove(OLEPropertyConstants.BALANCE_TYPE_CODE);
445
446 criteria.addIn(OLEPropertyConstants.BALANCE_TYPE_CODE, encumbranceBalanceTypes);
447 }
448 }
449
450 criteria.addAndCriteria(OJBUtility.buildCriteriaFromMap(localFieldValues, balance));
451 return criteria;
452 }
453
454
455
456
457
458
459
460 protected List<String> buildAttributeList(boolean isExtended) {
461 List attributeList = this.buildGroupByList();
462
463 attributeList.add("sum(accountLineAnnualBalanceAmount)");
464 attributeList.add("sum(beginningBalanceLineAmount)");
465 attributeList.add("sum(contractsGrantsBeginningBalanceAmount)");
466
467
468 if (isExtended) {
469 attributeList.add("sum(month1Amount)");
470 attributeList.add("sum(month2Amount)");
471 attributeList.add("sum(month3Amount)");
472 attributeList.add("sum(month4Amount)");
473 attributeList.add("sum(month5Amount)");
474 attributeList.add("sum(month6Amount)");
475 attributeList.add("sum(month7Amount)");
476 attributeList.add("sum(month8Amount)");
477 attributeList.add("sum(month9Amount)");
478 attributeList.add("sum(month10Amount)");
479 attributeList.add("sum(month11Amount)");
480 attributeList.add("sum(month12Amount)");
481 attributeList.add("sum(month13Amount)");
482 }
483 return attributeList;
484 }
485
486
487
488
489
490
491 protected List<String> buildGroupByList() {
492 List attributeList = new ArrayList();
493
494 attributeList.add(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR);
495 attributeList.add(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
496 attributeList.add(OLEPropertyConstants.ACCOUNT_NUMBER);
497 attributeList.add(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
498 attributeList.add(OLEPropertyConstants.BALANCE_TYPE_CODE);
499 attributeList.add(OLEPropertyConstants.OBJECT_CODE);
500 attributeList.add(OLEPropertyConstants.SUB_OBJECT_CODE);
501 attributeList.add(OLEPropertyConstants.OBJECT_TYPE_CODE);
502
503 return attributeList;
504 }
505
506
507
508
509
510
511
512
513
514
515
516
517
518 public Balance getCurrentBudgetForObjectCode(Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber, String objectCode) {
519 LOG.debug("getCurrentBudgetForObjectCode() started");
520
521 Criteria crit = new Criteria();
522 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityFiscalYear);
523 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
524 crit.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
525 crit.addEqualTo(OLEPropertyConstants.OBJECT_CODE, objectCode);
526 crit.addEqualTo(OLEPropertyConstants.BALANCE_TYPE_CODE, OLEConstants.BALANCE_TYPE_CURRENT_BUDGET);
527
528 QueryByCriteria qbc = QueryFactory.newQuery(Balance.class, crit);
529 return (Balance) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
530 }
531
532
533
534
535
536
537
538
539
540 public Iterator<Balance> findAccountBalances(Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber) {
541 LOG.debug("findAccountBalances() started");
542 return this.findAccountBalances(universityFiscalYear, chartOfAccountsCode, accountNumber, OLEConstants.SF_TYPE_OBJECT);
543 }
544
545
546
547
548
549
550
551
552
553
554 public Iterator<Balance> findAccountBalances(Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber, String sfCode) {
555 LOG.debug("findAccountBalances() started");
556
557 Criteria crit = new Criteria();
558 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityFiscalYear);
559 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
560 crit.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
561
562 QueryByCriteria qbc = QueryFactory.newQuery(Balance.class, crit);
563 if (OLEConstants.SF_TYPE_OBJECT.equals(sfCode)) {
564 qbc.addOrderByAscending(OLEPropertyConstants.OBJECT_CODE);
565 }
566 else if (OLEConstants.SF_TYPE_LEVEL.equals(sfCode)) {
567 qbc.addOrderByAscending(GeneralLedgerConstants.BalanceInquiryDrillDowns.OBJECT_LEVEL_CODE);
568 }
569 else if (OLEConstants.SF_TYPE_CONSOLIDATION.equals(sfCode)) {
570 qbc.addOrderByAscending(GeneralLedgerConstants.BalanceInquiryDrillDowns.CONSOLIDATION_OBJECT_CODE);
571 }
572 return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
573 }
574
575
576
577
578
579
580
581 public void purgeYearByChart(String chartOfAccountsCode, int year) {
582 LOG.debug("purgeYearByChart() started");
583
584 Criteria criteria = new Criteria();
585 criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
586 criteria.addLessThan(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, new Integer(year));
587
588 getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(Balance.class, criteria));
589
590
591
592
593 getPersistenceBrokerTemplate().clearCache();
594 }
595
596
597
598
599
600
601
602
603 public int countBalancesForFiscalYear(Integer year) {
604 LOG.debug("countBalancesForFiscalYear() started");
605
606 Criteria c = new Criteria();
607 c.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
608 QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
609
610 return getPersistenceBrokerTemplate().getCount(query);
611 }
612
613
614
615
616
617
618
619
620 public Iterator<Balance> findNominalActivityBalancesForFiscalYear(Integer year, Collection<String> nominalActivityObjectTypeCodes, SystemOptions currentYearOptions) {
621 LOG.debug("findNominalActivityBalancesForFiscalYear() started");
622
623 Criteria c = new Criteria();
624 c.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
625 c.addEqualTo(OLEPropertyConstants.BALANCE_TYPE_CODE, currentYearOptions.getActualFinancialBalanceTypeCd());
626 c.addIn(OLEPropertyConstants.OBJECT_TYPE_CODE, nominalActivityObjectTypeCodes);
627 c.addNotEqualTo("accountLineAnnualBalanceAmount", KualiDecimal.ZERO);
628
629 QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
630 query.addOrderByAscending(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
631 query.addOrderByAscending(OLEPropertyConstants.ACCOUNT_NUMBER);
632 query.addOrderByAscending(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
633 query.addOrderByAscending(OLEPropertyConstants.OBJECT_CODE);
634 query.addOrderByAscending(OLEPropertyConstants.SUB_OBJECT_CODE);
635 query.addOrderByAscending(OLEPropertyConstants.BALANCE_TYPE_CODE);
636 query.addOrderByAscending(OLEPropertyConstants.OBJECT_TYPE_CODE);
637
638 return getPersistenceBrokerTemplate().getIteratorByQuery(query);
639 }
640
641
642
643
644
645 public Iterator<Balance> findGeneralBalancesToForwardForFiscalYear(Integer year, Collection<String> generalForwardBalanceObjectTypes, Collection<String> generalBalanceForwardBalanceTypes) {
646
647 Criteria c = new Criteria();
648 c.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
649 c.addIn(OLEPropertyConstants.BALANCE_TYPE_CODE, generalBalanceForwardBalanceTypes);
650 c.addIn(OLEPropertyConstants.OBJECT_TYPE_CODE, generalForwardBalanceObjectTypes);
651
652 QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
653 query.addOrderByAscending(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
654 query.addOrderByAscending(OLEPropertyConstants.ACCOUNT_NUMBER);
655 query.addOrderByAscending(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
656 query.addOrderByAscending(OLEPropertyConstants.OBJECT_CODE);
657 query.addOrderByAscending(OLEPropertyConstants.SUB_OBJECT_CODE);
658 query.addOrderByAscending(OLEPropertyConstants.BALANCE_TYPE_CODE);
659 query.addOrderByAscending(OLEPropertyConstants.OBJECT_TYPE_CODE);
660
661 Iterator<Balance> balances = getPersistenceBrokerTemplate().getIteratorByQuery(query);
662
663 return balances;
664 }
665
666
667
668
669
670 public Iterator<Balance> findCumulativeBalancesToForwardForFiscalYear(Integer year, Collection<String> cumulativeForwardBalanceObjectTypes, Collection<String> contractsAndGrantsDenotingValues, Collection<String> subFundGroupsForCumulativeBalanceForwarding, Collection<String> cumulativeBalanceForwardBalanceTypes, boolean fundGroupDenotesCGInd) {
671 Criteria c = new Criteria();
672 c.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
673 c.addIn(OLEPropertyConstants.BALANCE_TYPE_CODE, cumulativeBalanceForwardBalanceTypes);
674 c.addIn(OLEPropertyConstants.OBJECT_TYPE_CODE, cumulativeForwardBalanceObjectTypes);
675
676 Criteria forCGCrit = new Criteria();
677 if (fundGroupDenotesCGInd) {
678 for (String value : contractsAndGrantsDenotingValues) {
679 forCGCrit.addEqualTo("priorYearAccount.subFundGroup.fundGroupCode", value);
680 }
681 }
682 else {
683 for (String value : contractsAndGrantsDenotingValues) {
684 forCGCrit.addEqualTo("priorYearAccount.subFundGroupCode", value);
685 }
686 }
687
688 Criteria subFundGroupCrit = new Criteria();
689 subFundGroupCrit.addIn("priorYearAccount.subFundGroupCode", subFundGroupsForCumulativeBalanceForwarding);
690 forCGCrit.addOrCriteria(subFundGroupCrit);
691 c.addAndCriteria(forCGCrit);
692
693 QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
694 query.addOrderByAscending(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
695 query.addOrderByAscending(OLEPropertyConstants.ACCOUNT_NUMBER);
696 query.addOrderByAscending(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
697 query.addOrderByAscending(OLEPropertyConstants.OBJECT_CODE);
698 query.addOrderByAscending(OLEPropertyConstants.SUB_OBJECT_CODE);
699 query.addOrderByAscending(OLEPropertyConstants.BALANCE_TYPE_CODE);
700 query.addOrderByAscending(OLEPropertyConstants.OBJECT_TYPE_CODE);
701
702 Iterator<Balance> balances = getPersistenceBrokerTemplate().getIteratorByQuery(query);
703
704 return balances;
705 }
706
707
708
709
710
711
712
713
714
715 public Iterator<Balance> findOrganizationReversionBalancesForFiscalYear(Integer year, boolean endOfYear, SystemOptions options, List<ParameterEvaluator> parameterEvaluators) {
716 LOG.debug("findOrganizationReversionBalancesForFiscalYear() started");
717 Criteria c = new Criteria();
718 c.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
719
720 for (ParameterEvaluator parameterEvaluator : parameterEvaluators) {
721
722 String currentRule = parameterEvaluator.getValue();
723 if (endOfYear) {
724 currentRule = currentRule.replaceAll("account\\.", "priorYearAccount.");
725 }
726 if (StringUtils.isNotBlank(currentRule)) {
727 String propertyName = StringUtils.substringBefore(currentRule, "=");
728 List<String> ruleValues = Arrays.asList(StringUtils.substringAfter(currentRule, "=").split(";"));
729 if (propertyName != null && propertyName.length() > 0 && ruleValues.size() > 0 && !StringUtils.isBlank(ruleValues.get(0))) {
730 if (parameterEvaluator.constraintIsAllow()) {
731 c.addIn(propertyName, ruleValues);
732 }
733 else {
734 c.addNotIn(propertyName, ruleValues);
735 }
736 }
737 }
738 }
739
740 List organizationReversionBalancesToSelect = new ArrayList();
741 organizationReversionBalancesToSelect.add(options.getActualFinancialBalanceTypeCd());
742 organizationReversionBalancesToSelect.add(options.getFinObjTypeExpenditureexpCd());
743 organizationReversionBalancesToSelect.add(options.getCostShareEncumbranceBalanceTypeCd());
744 organizationReversionBalancesToSelect.add(options.getIntrnlEncumFinBalanceTypCd());
745 organizationReversionBalancesToSelect.add(OLEConstants.BALANCE_TYPE_CURRENT_BUDGET);
746 c.addIn(OLEPropertyConstants.BALANCE_TYPE_CODE, organizationReversionBalancesToSelect);
747 QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
748 query.addOrderByAscending(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
749 query.addOrderByAscending(OLEPropertyConstants.ACCOUNT_NUMBER);
750 query.addOrderByAscending(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
751 query.addOrderByAscending(OLEPropertyConstants.OBJECT_CODE);
752 query.addOrderByAscending(OLEPropertyConstants.SUB_OBJECT_CODE);
753 query.addOrderByAscending(OLEPropertyConstants.BALANCE_TYPE_CODE);
754 query.addOrderByAscending(OLEPropertyConstants.OBJECT_TYPE_CODE);
755
756 return getPersistenceBrokerTemplate().getIteratorByQuery(query);
757 }
758
759
760
761
762 public Integer findCountGreaterOrEqualThan(Integer year) {
763 Criteria criteria = new Criteria();
764 criteria.addGreaterOrEqualThan(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
765
766 ReportQueryByCriteria query = QueryFactory.newReportQuery(Balance.class, criteria);
767
768 return getPersistenceBrokerTemplate().getCount(query);
769 }
770
771 }