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