001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.gl.dao.ojb;
017:
018: import java.util.ArrayList;
019: import java.util.Calendar;
020: import java.util.GregorianCalendar;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.apache.ojb.broker.query.Criteria;
025: import org.apache.ojb.broker.query.QueryByCriteria;
026: import org.apache.ojb.broker.query.QueryFactory;
027: import org.kuali.core.util.KualiDecimal;
028: import org.kuali.kfs.KFSPropertyConstants;
029: import org.kuali.module.gl.bo.Balance;
030:
031: /**
032: * A mock implementation of BalanceDao, attempting to reduce the number of balances read from the database,
033: * and thus make certain processes, such as the year end processes, run faster in test conditions
034: */
035: public class BalanceTestDaoOjb extends BalanceDaoOjb {
036: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
037: .getLogger(BalanceTestDaoOjb.class);
038:
039: /**
040: * Finds the balances for the fiscal year which have been updated or created within the past 90 days
041: * @param year the fiscal year to find balances for
042: * @return an Iterator of balances
043: * @see org.kuali.module.gl.dao.ojb.BalanceDaoOjb#findBalancesForFiscalYear(java.lang.Integer)
044: */
045: @Override
046: public Iterator<Balance> findBalancesForFiscalYear(Integer year) {
047: LOG.debug("findBalancesForFiscalYear() test version started");
048:
049: Criteria c = new Criteria();
050: c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
051:
052: Calendar ninetyDaysAgo = new GregorianCalendar();
053: ninetyDaysAgo.add(Calendar.DAY_OF_YEAR, -90);
054: LOG.info("thirty days ago = " + ninetyDaysAgo);
055: c.addGreaterThan(KFSPropertyConstants.TIMESTAMP,
056: new java.sql.Date(ninetyDaysAgo.getTimeInMillis()));
057:
058: QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
059: query
060: .addOrderByAscending(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
061: query.addOrderByAscending(KFSPropertyConstants.ACCOUNT_NUMBER);
062: query
063: .addOrderByAscending(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
064: query.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
065: query.addOrderByAscending(KFSPropertyConstants.SUB_OBJECT_CODE);
066: query
067: .addOrderByAscending(KFSPropertyConstants.BALANCE_TYPE_CODE);
068: query
069: .addOrderByAscending(KFSPropertyConstants.OBJECT_TYPE_CODE);
070:
071: return getPersistenceBrokerTemplate().getIteratorByQuery(query);
072: }
073:
074: /**
075: * Returns a specific set of balances to be processed by the nominal activity closing process
076: *
077: * @param year the fiscal year of balances to pull
078: * @return an Iterator of qualifying balances
079: */
080: public Iterator<Balance> findNominalActivityForFiscalYear(
081: Integer year) {
082: LOG.debug("findNominalActivityForFiscalYear started");
083:
084: Criteria c = new Criteria();
085: c.addEqualTo("universityFiscalYear", year);
086: c.addEqualTo("balanceTypeCode", "AC");
087: c.addNotEqualTo("accountLineAnnualBalanceAmount",
088: KualiDecimal.ZERO);
089: c.addColumnIn("objectTypeCode",
090: nominalActivityObjectTypeCodes());
091:
092: QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
093: query
094: .addOrderByAscending(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
095: query.addOrderByAscending(KFSPropertyConstants.ACCOUNT_NUMBER);
096: query
097: .addOrderByAscending(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
098: query.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
099: query.addOrderByAscending(KFSPropertyConstants.SUB_OBJECT_CODE);
100: query
101: .addOrderByAscending(KFSPropertyConstants.BALANCE_TYPE_CODE);
102: query
103: .addOrderByAscending(KFSPropertyConstants.OBJECT_TYPE_CODE);
104:
105: return getPersistenceBrokerTemplate().getIteratorByQuery(query);
106: }
107:
108: /**
109: * A hard coded set of object type codes
110: *
111: * @return a List of object type codes nominal balance should process
112: */
113: private List<String> nominalActivityObjectTypeCodes() {
114: List<String> codes = new ArrayList<String>();
115: codes.add("ES");
116: codes.add("EX");
117: codes.add("TE");
118: codes.add("TI");
119: codes.add("EE");
120: codes.add("CH");
121: codes.add("IC");
122: codes.add("IN");
123: return codes;
124: }
125:
126: }
|