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.Iterator;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.ojb.broker.query.Criteria;
23 import org.apache.ojb.broker.query.QueryByCriteria;
24 import org.apache.ojb.broker.query.QueryFactory;
25 import org.apache.ojb.broker.query.ReportQueryByCriteria;
26 import org.kuali.ole.gl.OJBUtility;
27 import org.kuali.ole.gl.businessobject.AccountBalance;
28 import org.kuali.ole.gl.businessobject.Transaction;
29 import org.kuali.ole.gl.dataaccess.AccountBalanceConsolidationDao;
30 import org.kuali.ole.gl.dataaccess.AccountBalanceDao;
31 import org.kuali.ole.gl.dataaccess.AccountBalanceLevelDao;
32 import org.kuali.ole.gl.dataaccess.AccountBalanceObjectDao;
33 import org.kuali.ole.sys.OLEPropertyConstants;
34 import org.kuali.ole.sys.businessobject.SystemOptions;
35 import org.kuali.ole.sys.businessobject.UniversityDate;
36 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
37
38
39
40
41 public class AccountBalanceDaoOjb extends PlatformAwareDaoBaseOjb implements AccountBalanceDao {
42 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceDaoOjb.class);
43
44 private AccountBalanceConsolidationDao accountBalanceConsolidationDao;
45 private AccountBalanceLevelDao accountBalanceLevelDao;
46 private AccountBalanceObjectDao accountBalanceObjectDao;
47
48 static final private String OBJ_TYP_CD = "financialObject.financialObjectTypeCode";
49
50
51
52
53
54
55
56
57 public AccountBalance getByTransaction(Transaction t) {
58 LOG.debug("getByTransaction() started");
59
60 Criteria crit = new Criteria();
61 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, t.getUniversityFiscalYear());
62 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, t.getChartOfAccountsCode());
63 crit.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, t.getAccountNumber());
64 crit.addEqualTo(OLEPropertyConstants.SUB_ACCOUNT_NUMBER, t.getSubAccountNumber());
65 crit.addEqualTo(OLEPropertyConstants.OBJECT_CODE, t.getFinancialObjectCode());
66 crit.addEqualTo(OLEPropertyConstants.SUB_OBJECT_CODE, t.getFinancialSubObjectCode());
67
68 QueryByCriteria qbc = QueryFactory.newQuery(AccountBalance.class, crit);
69 return (AccountBalance) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
70 }
71
72
73
74
75
76
77
78
79 public Iterator findConsolidatedAvailableAccountBalance(Map fieldValues) {
80 LOG.debug("findConsolidatedAvailableAccountBalance() started");
81
82 Criteria criteria = OJBUtility.buildCriteriaFromMap(fieldValues, new AccountBalance());
83 ReportQueryByCriteria query = QueryFactory.newReportQuery(AccountBalance.class, criteria);
84
85 String[] attributes = new String[] { OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, OLEPropertyConstants.ACCOUNT_NUMBER, OLEPropertyConstants.OBJECT_CODE, OBJ_TYP_CD, "sum(currentBudgetLineBalanceAmount)", "sum(accountLineActualsBalanceAmount)", "sum(accountLineEncumbranceBalanceAmount)" };
86
87 String[] groupBy = new String[] { OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, OLEPropertyConstants.ACCOUNT_NUMBER, OLEPropertyConstants.OBJECT_CODE, OBJ_TYP_CD };
88
89 query.setAttributes(attributes);
90 query.addGroupBy(groupBy);
91 OJBUtility.limitResultSize(query);
92
93 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
94 }
95
96
97
98
99
100
101
102
103 public Iterator findAvailableAccountBalance(Map fieldValues) {
104 LOG.debug("findAvailableAccountBalance(Map) started");
105
106 Criteria criteria = OJBUtility.buildCriteriaFromMap(fieldValues, new AccountBalance());
107 QueryByCriteria query = QueryFactory.newReportQuery(AccountBalance.class, criteria);
108 OJBUtility.limitResultSize(query);
109
110 return getPersistenceBrokerTemplate().getIteratorByQuery(query);
111 }
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 public List findAccountBalanceByConsolidationByObjectTypes(String[] objectTypes, Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber, boolean isExcludeCostShare, boolean isConsolidated, int pendingEntriesCode, SystemOptions options, UniversityDate today) {
128 LOG.debug("findAccountBalanceByConsolidationByObjectTypes() started");
129
130
131 try {
132 return accountBalanceConsolidationDao.findAccountBalanceByConsolidationObjectTypes(objectTypes, universityFiscalYear, chartOfAccountsCode, accountNumber, isExcludeCostShare, isConsolidated, pendingEntriesCode, options, today);
133 }
134 catch (Exception e) {
135 LOG.error("findAccountBalanceByConsolidation() " + e.getMessage(), e);
136 throw new RuntimeException(e.getMessage(), e);
137 }
138 }
139
140
141
142
143
144 public List findAccountBalanceByLevel(Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber, String financialConsolidationObjectCode, boolean isCostShareExcluded, boolean isConsolidated, int pendingEntriesCode, UniversityDate today, SystemOptions options) {
145 LOG.debug("findAccountBalanceByLevel() started");
146
147
148 try {
149 return accountBalanceLevelDao.findAccountBalanceByLevel(universityFiscalYear, chartOfAccountsCode, accountNumber, financialConsolidationObjectCode, isCostShareExcluded, isConsolidated, pendingEntriesCode, today, options);
150 }
151 catch (Exception ex) {
152 LOG.error("findAccountBalanceByLevel() " + ex.getMessage(), ex);
153 throw new RuntimeException("error executing findAccountBalanceByLevel()", ex);
154 }
155 }
156
157
158
159
160
161
162 public List findAccountBalanceByObject(Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber, String financialObjectLevelCode, String financialReportingSortCode, boolean isCostShareExcluded, boolean isConsolidated, int pendingEntriesCode, UniversityDate today, SystemOptions options) {
163 LOG.debug("findAccountBalanceByObject() started");
164
165
166 try {
167 return accountBalanceObjectDao.findAccountBalanceByObject(universityFiscalYear, chartOfAccountsCode, accountNumber, financialObjectLevelCode, financialReportingSortCode, isCostShareExcluded, isConsolidated, pendingEntriesCode, today, options);
168 }
169 catch (Exception ex) {
170 LOG.error("findAccountBalanceByObject() " + ex.getMessage(), ex);
171 throw new RuntimeException(ex.getMessage(), ex);
172 }
173 }
174
175
176
177
178
179
180
181
182 public void purgeYearByChart(String chartOfAccountsCode, int year) {
183 LOG.debug("purgeYearByChart() started");
184
185 Criteria criteria = new Criteria();
186 criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
187 criteria.addLessThan(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, new Integer(year));
188
189 getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(AccountBalance.class, criteria));
190
191
192
193
194 getPersistenceBrokerTemplate().clearCache();
195 }
196
197
198
199
200 public Integer findCountGreaterOrEqualThan(Integer year) {
201 Criteria criteria = new Criteria();
202 criteria.addGreaterOrEqualThan(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
203
204 ReportQueryByCriteria query = QueryFactory.newReportQuery(AccountBalance.class, criteria);
205
206 return getPersistenceBrokerTemplate().getCount(query);
207 }
208
209 public AccountBalanceConsolidationDao getAccountBalanceConsolidationDao() {
210 return accountBalanceConsolidationDao;
211 }
212
213 public void setAccountBalanceConsolidationDao(AccountBalanceConsolidationDao accountBalanceConsolidationDao) {
214 this.accountBalanceConsolidationDao = accountBalanceConsolidationDao;
215 }
216
217 public AccountBalanceLevelDao getAccountBalanceLevelDao() {
218 return accountBalanceLevelDao;
219 }
220
221 public void setAccountBalanceLevelDao(AccountBalanceLevelDao accountBalanceLevelDao) {
222 this.accountBalanceLevelDao = accountBalanceLevelDao;
223 }
224
225 public AccountBalanceObjectDao getAccountBalanceObjectDao() {
226 return accountBalanceObjectDao;
227 }
228
229 public void setAccountBalanceObjectDao(AccountBalanceObjectDao accountBalanceObjectDao) {
230 this.accountBalanceObjectDao = accountBalanceObjectDao;
231 }
232 }