001/* 002 * Copyright 2005-2006 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 */ 016package org.kuali.ole.gl.dataaccess.impl; 017 018import java.math.BigDecimal; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.Iterator; 022import java.util.List; 023import java.util.Map; 024 025import org.apache.ojb.broker.query.Criteria; 026import org.apache.ojb.broker.query.QueryByCriteria; 027import org.apache.ojb.broker.query.QueryFactory; 028import org.apache.ojb.broker.query.ReportQueryByCriteria; 029import org.kuali.ole.gl.businessobject.OriginEntryFull; 030import org.kuali.ole.gl.businessobject.OriginEntryGroup; 031import org.kuali.ole.gl.businessobject.OriginEntryInformation; 032import org.kuali.ole.gl.dataaccess.OriginEntryDao; 033import org.kuali.ole.sys.OLEConstants; 034import org.kuali.ole.sys.OLEPropertyConstants; 035import org.kuali.ole.sys.util.TransactionalServiceUtils; 036import org.kuali.rice.core.api.util.type.KualiDecimal; 037import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 038 039/** 040 * An OJB implementation of the OriginEntryDao 041 */ 042public class OriginEntryDaoOjb extends PlatformAwareDaoBaseOjb implements OriginEntryDao { 043 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OriginEntryDaoOjb.class); 044 045 private static final String ENTRY_GROUP_ID = "entryGroupId"; 046 private static final String ENTRY_ID = "entryId"; 047 private static final String FINANCIAL_BALANCE_TYPE_CODE = "financialBalanceTypeCode"; 048 private static final String CHART_OF_ACCOUNTS_CODE = "chartOfAccountsCode"; 049 private static final String ACCOUNT_NUMBER = "accountNumber"; 050 private static final String SUB_ACCOUNT_NUMBER = "subAccountNumber"; 051 private static final String FINANCIAL_DOCUMENT_TYPE_CODE = "financialDocumentTypeCode"; 052 private static final String FINANCIAL_SYSTEM_ORIGINATION_CODE = "financialSystemOriginationCode"; 053 private static final String FINANCIAL_DOCUMENT_REVERSAL_DATE = "financialDocumentReversalDate"; 054 private static final String UNIVERSITY_FISCAL_PERIOD_CODE = "universityFiscalPeriodCode"; 055 private static final String UNIVERSITY_FISCAL_YEAR = "universityFiscalYear"; 056 private static final String FINANCIAL_OBJECT_CODE = "financialObjectCode"; 057 private static final String FINANCIAL_SUB_OBJECT_CODE = "financialSubObjectCode"; 058 private static final String FINANCIAL_OBJECT_TYPE_CODE = "financialObjectTypeCode"; 059 private static final String TRANSACTION_LEDGER_ENTRY_SEQUENCE_NUMBER = "transactionLedgerEntrySequenceNumber"; 060 private static final String TRANSACTION_LEDGER_ENTRY_DESCRIPTION = "transactionLedgerEntryDescription"; 061 private static final String TRANSACTION_LEDGER_ENTRY_AMOUNT = "transactionLedgerEntryAmount"; 062 private static final String TRANSACTION_DEBIT_CREDIT_CODE = "transactionDebitCreditCode"; 063 064 private Class entryClass; 065 066 /** 067 * Sets the class of the origin entries this class deals with. This makes this particular 068 * class very flexible; instances of it can deal with OriginEntryLites as well as they deal 069 * with OriginEntryFulls. 070 * 071 * @param entryClass the class of OriginEntries this instance will use for OJB operations 072 */ 073 public void setEntryClass(Class entryClass) { 074 this.entryClass = entryClass; 075 } 076 077 /** 078 * Gets the entryClass attribute. 079 * 080 * @return Returns the entryClass. 081 */ 082 public Class getEntryClass() { 083 return entryClass; 084 } 085 086 /** 087 * Constructs a OriginEntryDaoOjb instance 088 */ 089 public OriginEntryDaoOjb() { 090 super(); 091 } 092 093 /** 094 * Get the total amount of transactions in a group 095 * @param the id of the origin entry group to total 096 * @param isCredit whether the total should be of credits or not 097 * @return the sum of all queried origin entries 098 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getGroupTotal(java.lang.Integer, boolean) 099 */ 100 @Override 101 public KualiDecimal getGroupTotal(Integer groupId, boolean isCredit) { 102 LOG.debug("getGroupTotal() started"); 103 104 Criteria crit = new Criteria(); 105 crit.addEqualTo(OriginEntryDaoOjb.ENTRY_GROUP_ID, groupId); 106 if (isCredit) { 107 crit.addEqualTo(OriginEntryDaoOjb.TRANSACTION_DEBIT_CREDIT_CODE, OLEConstants.GL_CREDIT_CODE); 108 } 109 else { 110 crit.addNotEqualTo(OriginEntryDaoOjb.TRANSACTION_DEBIT_CREDIT_CODE, OLEConstants.GL_CREDIT_CODE); 111 } 112 113 ReportQueryByCriteria q = QueryFactory.newReportQuery(entryClass, crit); 114 q.setAttributes(new String[] { "SUM(" + OriginEntryDaoOjb.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" }); 115 116 Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q); 117 if (i.hasNext()) { 118 Object[] data = (Object[]) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(i); 119 return (KualiDecimal) data[0]; 120 } 121 else { 122 return null; 123 } 124 } 125 126 /** 127 * Counts the number of entries in a group 128 * @param the id of an origin entry group 129 * @return the count of the entries in that group 130 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getGroupCount(java.lang.Integer) 131 */ 132 @Override 133 public Integer getGroupCount(Integer groupId) { 134 LOG.debug("getGroupCount() started"); 135 136 Criteria crit = new Criteria(); 137 crit.addEqualTo(OriginEntryDaoOjb.ENTRY_GROUP_ID, groupId); 138 139 ReportQueryByCriteria q = QueryFactory.newReportQuery(entryClass, crit); 140 q.setAttributes(new String[] { "count(*)" }); 141 142 Iterator i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q); 143 if (i.hasNext()) { 144 Object[] data = (Object[]) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(i); 145 146 if (data[0] instanceof BigDecimal) { 147 return ((BigDecimal) data[0]).intValue(); 148 } 149 else { 150 return ((Long) data[0]).intValue(); 151 } 152 } 153 else { 154 return null; 155 } 156 } 157 158 /** 159 * Counts of rows of all the origin entry groups 160 * 161 * @return iterator of Object[] {[BigDecimal id,BigDecimal count]} 162 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getGroupCounts() 163 */ 164 @Override 165 public Iterator getGroupCounts() { 166 LOG.debug("getGroupCounts() started"); 167 168 Criteria crit = new Criteria(); 169 170 ReportQueryByCriteria q = QueryFactory.newReportQuery(entryClass, crit); 171 q.setAttributes(new String[] { ENTRY_GROUP_ID, "count(*)" }); 172 q.addGroupBy(ENTRY_GROUP_ID); 173 174 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q); 175 } 176 177 /** 178 * Delete an entry from the database 179 * @param oe the entry to delete 180 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#deleteEntry(org.kuali.ole.gl.businessobject.OriginEntryInformation) 181 */ 182 @Override 183 public void deleteEntry(OriginEntryInformation oe) { 184 LOG.debug("deleteEntry() started"); 185 186 getPersistenceBrokerTemplate().delete(oe); 187 } 188 189 /** 190 * Return an iterator of keys of all documents referenced by origin entries in a given group 191 * 192 * @param oeg Group the origin entry group to find entries in, by origin entry 193 * @return Iterator of java.lang.Object[] with report data about all of the distinct document numbers/type code/origination code combinations of origin entries in the group 194 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getDocumentsByGroup(org.kuali.ole.gl.businessobject.OriginEntryGroup) 195 */ 196 @Override 197 public Iterator getDocumentsByGroup(OriginEntryGroup oeg) { 198 LOG.debug("getDocumentsByGroup() started"); 199 200 Criteria criteria = new Criteria(); 201 criteria.addEqualTo(ENTRY_GROUP_ID, oeg.getId()); 202 203 ReportQueryByCriteria q = QueryFactory.newReportQuery(entryClass, criteria); 204 q.setAttributes(new String[] { OLEPropertyConstants.DOCUMENT_NUMBER, "financialDocumentTypeCode", "financialSystemOriginationCode" }); 205 206 q.setDistinct(true); 207 208 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q); 209 } 210 211 /** 212 * Iterator of entries that match criteria 213 * 214 * @param searchCriteria Map of field, value pairs 215 * @return collection of entries 216 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getMatchingEntries(java.util.Map) 217 */ 218 @Override 219 public Iterator<OriginEntryFull> getMatchingEntries(Map searchCriteria) { 220 LOG.debug("getMatchingEntries() started"); 221 222 Criteria criteria = new Criteria(); 223 for (Iterator iter = searchCriteria.keySet().iterator(); iter.hasNext();) { 224 String element = (String) iter.next(); 225 criteria.addEqualTo(element, searchCriteria.get(element)); 226 } 227 228 QueryByCriteria qbc = QueryFactory.newQuery(entryClass, criteria); 229 qbc.addOrderByAscending(ENTRY_GROUP_ID); 230 return getPersistenceBrokerTemplate().getIteratorByQuery(qbc); 231 } 232 233 /** 234 * Get bad balance entries 235 * 236 * @param groups a Collection of groups to remove bad entries in 237 * @return an Iterator of no good, won't use, bad balance entries 238 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getBadBalanceEntries(java.util.Collection) 239 */ 240 @Override 241 public Iterator<OriginEntryFull> getBadBalanceEntries(Collection groups) { 242 LOG.debug("getBadBalanceEntries() started"); 243 244 if (groups.size() <= 0) { 245 return null; 246 } 247 248 Collection ids = new ArrayList(); 249 for (Iterator iter = groups.iterator(); iter.hasNext();) { 250 OriginEntryGroup element = (OriginEntryGroup) iter.next(); 251 ids.add(element.getId()); 252 } 253 254 Criteria crit1 = new Criteria(); 255 crit1.addIn(ENTRY_GROUP_ID, ids); 256 257 Criteria crit2 = new Criteria(); 258 crit2.addIsNull(FINANCIAL_BALANCE_TYPE_CODE); 259 260 Criteria crit3 = new Criteria(); 261 crit3.addEqualTo(FINANCIAL_BALANCE_TYPE_CODE, " "); 262 263 crit2.addOrCriteria(crit3); 264 265 crit1.addAndCriteria(crit2); 266 267 QueryByCriteria qbc = QueryFactory.newQuery(entryClass, crit1); 268 qbc.addOrderByAscending(UNIVERSITY_FISCAL_YEAR); 269 qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE); 270 qbc.addOrderByAscending(ACCOUNT_NUMBER); 271 qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE); 272 qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE); 273 qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE); 274 qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE); 275 qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE); 276 qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE); 277 qbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER); 278 279 return getPersistenceBrokerTemplate().getIteratorByQuery(qbc); 280 } 281 282 /** 283 * This method is special because of the order by. It is used in the scrubber. The getMatchingEntries wouldn't work because of 284 * the required order by. 285 * 286 * @param OriginEntryGroup the originEntryGroup that holds the origin entries to find 287 * @param sort the sort order to sort entries by, defined in OriginEntryDao 288 * 289 * @return an Iterator of whichever flavor of OriginEntries this instance uses 290 */ 291 @Override 292 public <T> Iterator<T> getEntriesByGroup(OriginEntryGroup oeg, int sort) { 293 LOG.debug("getEntriesByGroup() started"); 294 295 // clear cache because the GLCP document class saves to the origin entry table and 296 // reads from it (via this method) in the same transaction. If the clearCache line is 297 // deleted, then the references to OriginEntries returned by this method will be null. 298 getPersistenceBrokerTemplate().clearCache(); 299 300 Criteria criteria = new Criteria(); 301 criteria.addEqualTo(ENTRY_GROUP_ID, oeg.getId()); 302 303 QueryByCriteria qbc = QueryFactory.newQuery(entryClass, criteria); 304 305 if (sort == OriginEntryDao.SORT_DOCUMENT) { 306 qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE); 307 qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE); 308 qbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER); 309 qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE); 310 qbc.addOrderByAscending(ACCOUNT_NUMBER); 311 qbc.addOrderByAscending(SUB_ACCOUNT_NUMBER); 312 qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE); 313 qbc.addOrderByAscending(FINANCIAL_DOCUMENT_REVERSAL_DATE); 314 qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE); 315 qbc.addOrderByAscending(UNIVERSITY_FISCAL_YEAR); 316 // The above order by fields are required by the scrubber process. Adding these 317 // fields makes the data in the exact same order as the COBOL scrubber. 318 qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE); 319 qbc.addOrderByAscending(FINANCIAL_SUB_OBJECT_CODE); 320 qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE); 321 qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE); 322 qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE); 323 qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE); 324 qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE); 325 qbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER); 326 qbc.addOrderByAscending(TRANSACTION_LEDGER_ENTRY_SEQUENCE_NUMBER); 327 qbc.addOrderByAscending(TRANSACTION_LEDGER_ENTRY_DESCRIPTION); 328 qbc.addOrderByAscending(TRANSACTION_LEDGER_ENTRY_AMOUNT); 329 qbc.addOrderByAscending(TRANSACTION_DEBIT_CREDIT_CODE); 330 } 331 else if (sort == OriginEntryDao.SORT_REPORT) { 332 qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE); 333 qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE); 334 qbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER); 335 qbc.addOrderByAscending(TRANSACTION_DEBIT_CREDIT_CODE); 336 qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE); 337 qbc.addOrderByAscending(ACCOUNT_NUMBER); 338 qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE); 339 } 340 else if (sort == OriginEntryDao.SORT_LISTING_REPORT) { 341 qbc.addOrderByAscending(UNIVERSITY_FISCAL_YEAR); 342 qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE); 343 qbc.addOrderByAscending(ACCOUNT_NUMBER); 344 qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE); 345 qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE); 346 qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE); 347 qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE); 348 qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE); 349 qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE); 350 qbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER); 351 qbc.addOrderByAscending(TRANSACTION_LEDGER_ENTRY_DESCRIPTION); 352 } 353 else { 354 qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE); 355 qbc.addOrderByAscending(ACCOUNT_NUMBER); 356 qbc.addOrderByAscending(SUB_ACCOUNT_NUMBER); 357 qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE); 358 qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE); 359 qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE); 360 qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE); 361 qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE); 362 qbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER); 363 qbc.addOrderByAscending(TRANSACTION_LEDGER_ENTRY_DESCRIPTION); 364 } 365 366 return getPersistenceBrokerTemplate().getIteratorByQuery(qbc); 367 } 368 369 /** 370 * This method should only be used in unit tests. It loads all the gl_origin_entry_t rows in memory into a collection. This 371 * won't work for production because there would be too many rows to load into memory. 372 * 373 * @return a collection of OriginEntryFulls 374 */ 375 @Override 376 public Collection<OriginEntryFull> testingGetAllEntries() { 377 LOG.debug("testingGetAllEntries() started"); 378 379 Criteria criteria = new Criteria(); 380 QueryByCriteria qbc = QueryFactory.newQuery(entryClass, criteria); 381 qbc.addOrderByAscending(ENTRY_GROUP_ID); 382 qbc.addOrderByAscending(ENTRY_ID); 383 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc); 384 } 385 386 /** 387 * Delete entries matching searchCriteria search criteria. 388 * 389 * @param searchCriteria a map of criteria to use as keys for building a query 390 */ 391 @Override 392 public void deleteMatchingEntries(Map searchCriteria) { 393 LOG.debug("deleteMatchingEntries() started"); 394 395 Criteria criteria = new Criteria(); 396 for (Iterator iter = searchCriteria.keySet().iterator(); iter.hasNext();) { 397 String element = (String) iter.next(); 398 criteria.addEqualTo(element, searchCriteria.get(element)); 399 } 400 401 QueryByCriteria qbc = QueryFactory.newQuery(entryClass, criteria); 402 getPersistenceBrokerTemplate().deleteByQuery(qbc); 403 404 // This is required because deleteByQuery leaves the cache alone so future queries 405 // could return origin entries that don't exist. Clearing the cache makes OJB 406 // go back to the database for everything to make sure valid data is returned. 407 getPersistenceBrokerTemplate().clearCache(); 408 } 409 410 /** 411 * Delete all the groups in the list. This will delete the entries. The OriginEntryGroupDao has a method to delete the groups, 412 * and one has to use both to really delete the whole group 413 * 414 * @param groups a Collection of Origin Entry Groups to delete entries in 415 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#deleteGroups(java.util.Collection) 416 */ 417 @Override 418 public void deleteGroups(Collection<OriginEntryGroup> groups) { 419 LOG.debug("deleteGroups() started"); 420 421 if (groups == null || groups.size() <= 0) { 422 return; 423 } 424 425 List ids = new ArrayList(); 426 for (Iterator iter = groups.iterator(); iter.hasNext();) { 427 OriginEntryGroup element = (OriginEntryGroup) iter.next(); 428 ids.add(element.getId()); 429 } 430 431 Criteria criteria = new Criteria(); 432 criteria.addIn(ENTRY_GROUP_ID, ids); 433 434 QueryByCriteria qbc = QueryFactory.newQuery(entryClass, criteria); 435 getPersistenceBrokerTemplate().deleteByQuery(qbc); 436 437 // This is required because deleteByQuery leaves the cache alone so future queries 438 // could return origin entries that don't exist. Clearing the cache makes OJB 439 // go back to the database for everything to make sure valid data is returned. 440 getPersistenceBrokerTemplate().clearCache(); 441 } 442 443 /** 444 * Collection of entries that match criteria 445 * 446 * @param searchCriteria Map of field, value pairs 447 * @return collection of entries 448 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getMatchingEntriesByCollection(java.util.Map) 449 */ 450 @Override 451 public Collection<OriginEntryFull> getMatchingEntriesByCollection(Map searchCriteria) { 452 LOG.debug("getMatchingEntries() started"); 453 454 Criteria criteria = new Criteria(); 455 for (Iterator iter = searchCriteria.keySet().iterator(); iter.hasNext();) { 456 String element = (String) iter.next(); 457 criteria.addEqualTo(element, searchCriteria.get(element)); 458 } 459 460 QueryByCriteria qbc = QueryFactory.newQuery(entryClass, criteria); 461 qbc.addOrderByAscending(ENTRY_GROUP_ID); 462 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc); 463 } 464 465 /** 466 * get the summarized information of the entries that belong to the entry groups with the given group ids 467 * 468 * @param groupIdList the ids of origin entry groups 469 * @return a set of summarized information of the entries within the specified groups 470 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getSummaryByGroupId(java.util.List) 471 */ 472 @Override 473 public Iterator getSummaryByGroupId(Collection groupIdList) { 474 LOG.debug("getSummaryByGroupId() started"); 475 476 if (groupIdList == null || groupIdList.size() <= 0) { 477 return null; 478 } 479 480 Collection ids = new ArrayList(); 481 for (Iterator iter = groupIdList.iterator(); iter.hasNext();) { 482 OriginEntryGroup element = (OriginEntryGroup) iter.next(); 483 ids.add(element.getId()); 484 } 485 486 Criteria criteria = new Criteria(); 487 criteria.addIn(OLEPropertyConstants.ENTRY_GROUP_ID, ids); 488 489 ReportQueryByCriteria query = QueryFactory.newReportQuery(entryClass, criteria); 490 491 String attributeList[] = { OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE, OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE, OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE, "sum(" + OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")", "count(*)" }; 492 493 String groupList[] = { OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE, OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE, OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE }; 494 495 query.setAttributes(attributeList); 496 query.addGroupBy(groupList); 497 498 // add the sorting criteria 499 for (int i = 0; i < groupList.length; i++) { 500 query.addOrderByAscending(groupList[i]); 501 } 502 503 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query); 504 } 505 506 /** 507 * Fetches an entry for the given entryId, or returns a newly created on 508 * 509 * @param entryId an entry id to find an entry for 510 * @return the entry for the given entry id, or a newly created entry 511 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getExactMatchingEntry(java.lang.Integer) 512 */ 513 @Override 514 public OriginEntryFull getExactMatchingEntry(Integer entryId) { 515 LOG.debug("getMatchingEntries() started"); 516 OriginEntryFull oe = new OriginEntryFull(); 517 // in case of no matching entry 518 try { 519 oe = (OriginEntryFull) getPersistenceBrokerTemplate().getObjectById(entryClass, entryId); 520 521 } 522 catch (Exception e) { 523 } 524 525 return oe; 526 } 527 528 /** 529 * get the summarized information of poster input entries that belong to the entry groups with the given group id list 530 * 531 * @param groups the origin entry groups 532 * @return a set of summarized information of poster input entries within the specified groups 533 * @see org.kuali.ole.gl.dataaccess.OriginEntryDao#getPosterOutputSummaryByGroupId(java.util.Collection) 534 */ 535 @Override 536 public Iterator getPosterOutputSummaryByGroupId(Collection groups) { 537 LOG.debug("getPosterInputSummaryByGroupId() started"); 538 539 if (groups == null || groups.size() <= 0) { 540 return null; 541 } 542 543 Collection ids = new ArrayList(); 544 for (Iterator iter = groups.iterator(); iter.hasNext();) { 545 OriginEntryGroup element = (OriginEntryGroup) iter.next(); 546 ids.add(element.getId()); 547 } 548 549 Criteria criteria = new Criteria(); 550 criteria.addIn(OLEPropertyConstants.ENTRY_GROUP_ID, ids); 551 String fundGroupCode = OLEPropertyConstants.ACCOUNT + "." + OLEPropertyConstants.SUB_FUND_GROUP + "." + OLEPropertyConstants.FUND_GROUP_CODE; 552 553 ReportQueryByCriteria query = QueryFactory.newReportQuery(entryClass, criteria); 554 555 String attributeList[] = { OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE, fundGroupCode, OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE, OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE, "sum(" + OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" }; 556 557 String groupList[] = { OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE, fundGroupCode, OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE, OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE }; 558 559 query.setAttributes(attributeList); 560 query.addGroupBy(groupList); 561 562 // add the sorting criteria 563 for (int i = 0; i < groupList.length; i++) { 564 query.addOrderByAscending(groupList[i]); 565 } 566 567 return getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query); 568 } 569}