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.labor.dao.ojb;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.ojb.broker.query.Criteria;
025: import org.apache.ojb.broker.query.Query;
026: import org.apache.ojb.broker.query.QueryFactory;
027: import org.apache.ojb.broker.query.ReportQueryByCriteria;
028: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
029: import org.kuali.kfs.KFSPropertyConstants;
030: import org.kuali.module.gl.util.OJBUtility;
031: import org.kuali.module.gl.web.Constant;
032: import org.kuali.module.labor.LaborConstants;
033: import org.kuali.module.labor.bo.AccountStatusBaseFunds;
034: import org.kuali.module.labor.bo.EmployeeFunding;
035: import org.kuali.module.labor.bo.LaborCalculatedSalaryFoundationTracker;
036: import org.kuali.module.labor.dao.LaborCalculatedSalaryFoundationTrackerDao;
037: import org.kuali.module.labor.util.ConsolidationUtil;
038: import org.kuali.module.labor.util.ObjectUtil;
039:
040: /**
041: * This is the data access object for calculated salary foundation tracker
042: *
043: * @see org.kuali.module.labor.bo.CalculatedSalaryFoundationTracker
044: */
045: public class LaborCalculatedSalaryFoundationTrackerDaoOjb extends
046: PlatformAwareDaoBaseOjb implements
047: LaborCalculatedSalaryFoundationTrackerDao {
048: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
049: .getLogger(LaborCalculatedSalaryFoundationTrackerDaoOjb.class);
050:
051: /**
052: * @see org.kuali.module.labor.dao.LaborBaseFundsDao#findCSFTrackers(java.util.Map, boolean)
053: */
054: public List<LaborCalculatedSalaryFoundationTracker> findCSFTrackers(
055: Map fieldValues, boolean isConsolidated) {
056: LOG.info("Start findCSFTrackers()");
057:
058: List<LaborCalculatedSalaryFoundationTracker> csfTrackerCollection = new ArrayList<LaborCalculatedSalaryFoundationTracker>();
059: if (isConsolidated) {
060: List<String> groupByList = getGroupByList(isConsolidated);
061: List<String> attributeList = getAttributeListForCSFTracker(
062: isConsolidated, false);
063:
064: Iterator<Object[]> queryResults = this
065: .findConsolidatedCSFTrackerRawData(fieldValues,
066: groupByList, attributeList);
067:
068: while (queryResults != null && queryResults.hasNext()) {
069: csfTrackerCollection.add(this
070: .marshalCSFTracker(queryResults.next()));
071: }
072: } else {
073: csfTrackerCollection
074: .addAll(findDetailedCSFTrackerRawData(fieldValues));
075: }
076: return csfTrackerCollection;
077: }
078:
079: /**
080: * @see org.kuali.module.labor.dao.LaborBaseFundsDao#findCSFTrackersAsAccountStatusBaseFunds(java.util.Map, boolean)
081: */
082: public List<AccountStatusBaseFunds> findCSFTrackersAsAccountStatusBaseFunds(
083: Map fieldValues, boolean isConsolidated) {
084: LOG.info("Start findCSFTrackersAsAccountStatusBaseFunds()");
085:
086: List<String> groupByList = getGroupByList(isConsolidated);
087: List<String> attributeList = getAttributeListForCSFTracker(
088: isConsolidated, false);
089:
090: Iterator<Object[]> queryResults = this
091: .findConsolidatedCSFTrackerRawData(fieldValues,
092: groupByList, attributeList);
093: List<AccountStatusBaseFunds> baseFundsCollection = new ArrayList<AccountStatusBaseFunds>();
094: while (queryResults != null && queryResults.hasNext()) {
095: baseFundsCollection
096: .add(this
097: .marshalCSFTrackerAsAccountStatusBaseFunds(queryResults
098: .next()));
099: }
100: return baseFundsCollection;
101: }
102:
103: /**
104: * @see org.kuali.module.labor.dao.LaborCalculatedSalaryFoundationTrackerDao#findCSFTrackersAsEmployeeFunding(java.util.Map,
105: * boolean)
106: */
107: public List<EmployeeFunding> findCSFTrackersAsEmployeeFunding(
108: Map fieldValues, boolean isConsolidated) {
109: LOG.info("Start findCSFTrackersAsEmployeeFunding()");
110:
111: List<LaborCalculatedSalaryFoundationTracker> csfTrackerCollection = findCSFTrackers(
112: fieldValues, isConsolidated);
113: List<EmployeeFunding> employeeFundingCollection = new ArrayList<EmployeeFunding>();
114: for (LaborCalculatedSalaryFoundationTracker csfTracker : csfTrackerCollection) {
115: EmployeeFunding employeeFunding = new EmployeeFunding();
116: ObjectUtil.buildObject(employeeFunding, csfTracker);
117: employeeFundingCollection.add(employeeFunding);
118: }
119: return employeeFundingCollection;
120: }
121:
122: // get the Consolidated CSF trackers according to the given criteria
123: private Iterator<Object[]> findConsolidatedCSFTrackerRawData(
124: Map fieldValues, List<String> groupByList,
125: List<String> attributeList) {
126:
127: Criteria tempCriteria1 = new Criteria();
128: tempCriteria1.addEqualTo(KFSPropertyConstants.CSF_DELETE_CODE,
129: LaborConstants.DASHES_DELETE_CODE);
130:
131: Criteria tempCriteria2 = new Criteria();
132: tempCriteria2.addIsNull(KFSPropertyConstants.CSF_DELETE_CODE);
133:
134: /* KFSPropertyConstants.CSF_DELETE_CODE = "-" OR is null */
135: tempCriteria2.addOrCriteria(tempCriteria1);
136:
137: Criteria criteria = OJBUtility.buildCriteriaFromMap(
138: fieldValues,
139: new LaborCalculatedSalaryFoundationTracker());
140: criteria.addAndCriteria(tempCriteria2);
141:
142: ReportQueryByCriteria query = QueryFactory.newReportQuery(
143: LaborCalculatedSalaryFoundationTracker.class, criteria);
144:
145: String[] groupBy = (String[]) groupByList
146: .toArray(new String[groupByList.size()]);
147: query.addGroupBy(groupBy);
148:
149: String[] attributes = (String[]) attributeList
150: .toArray(new String[attributeList.size()]);
151: query.setAttributes(attributes);
152:
153: return getPersistenceBrokerTemplate()
154: .getReportQueryIteratorByQuery(query);
155: }
156:
157: // get the detailed CSF trackers according to the given criteria
158: private Collection<LaborCalculatedSalaryFoundationTracker> findDetailedCSFTrackerRawData(
159: Map fieldValues) {
160:
161: Criteria tempCriteria1 = new Criteria();
162: tempCriteria1.addEqualTo(KFSPropertyConstants.CSF_DELETE_CODE,
163: LaborConstants.DASHES_DELETE_CODE);
164:
165: Criteria tempCriteria2 = new Criteria();
166: tempCriteria2.addIsNull(KFSPropertyConstants.CSF_DELETE_CODE);
167:
168: /* KFSPropertyConstants.CSF_DELETE_CODE = "-" OR is null */
169: tempCriteria2.addOrCriteria(tempCriteria1);
170:
171: Criteria criteria = OJBUtility.buildCriteriaFromMap(
172: fieldValues,
173: new LaborCalculatedSalaryFoundationTracker());
174: criteria.addAndCriteria(tempCriteria2);
175:
176: Query query = QueryFactory.newQuery(
177: LaborCalculatedSalaryFoundationTracker.class, criteria);
178: return getPersistenceBrokerTemplate().getCollectionByQuery(
179: query);
180: }
181:
182: // marshal into CalculatedSalaryFoundationTracker from the query result
183: private LaborCalculatedSalaryFoundationTracker marshalCSFTracker(
184: Object[] queryResult) {
185: LaborCalculatedSalaryFoundationTracker CSFTracker = new LaborCalculatedSalaryFoundationTracker();
186: List<String> keyFields = this .getAttributeListForCSFTracker(
187: false, true);
188:
189: ObjectUtil.buildObject(CSFTracker, queryResult, keyFields);
190: return CSFTracker;
191: }
192:
193: // marshal into AccountStatusBaseFunds from the query results
194: private AccountStatusBaseFunds marshalCSFTrackerAsAccountStatusBaseFunds(
195: Object[] queryResult) {
196: AccountStatusBaseFunds baseFunds = new AccountStatusBaseFunds();
197: List<String> keyFields = this .getAttributeListForCSFTracker(
198: false, true);
199:
200: ObjectUtil.buildObject(baseFunds, queryResult, keyFields);
201: return baseFunds;
202: }
203:
204: // marshal into EmployeeFunding from the query results
205: private EmployeeFunding marshalCSFTrackerAsEmployeeFunding(
206: Object[] queryResult) {
207: EmployeeFunding employeeFunding = new EmployeeFunding();
208: List<String> keyFields = this .getAttributeListForCSFTracker(
209: false, true);
210:
211: ObjectUtil.buildObject(employeeFunding, queryResult, keyFields);
212: return employeeFunding;
213: }
214:
215: // define a list of attributes that are used as the grouping criteria
216: private List<String> getGroupByList(boolean isConsolidated) {
217: List<String> groupByList = new ArrayList<String>();
218: groupByList.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
219: groupByList.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
220: groupByList.add(KFSPropertyConstants.ACCOUNT_NUMBER);
221: groupByList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
222:
223: if (!isConsolidated) {
224: groupByList.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
225: groupByList
226: .add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
227: }
228: return groupByList;
229: }
230:
231: // define the return attribute list
232: private List<String> getAttributeList(boolean isConsolidated) {
233: List<String> attributeList = getGroupByList(isConsolidated);
234:
235: if (isConsolidated) {
236: attributeList.add("'"
237: + Constant.CONSOLIDATED_SUB_ACCOUNT_NUMBER + "'");
238: attributeList.add("'"
239: + Constant.CONSOLIDATED_SUB_OBJECT_CODE + "'");
240: }
241: return attributeList;
242: }
243:
244: // define the return attribute list for CSF traker query
245: private List<String> getAttributeListForCSFTracker(
246: boolean isConsolidated, boolean isAttributeNameNeeded) {
247: List<String> attributeList = getAttributeList(isConsolidated);
248:
249: if (!isAttributeNameNeeded) {
250: attributeList
251: .add(ConsolidationUtil
252: .sum(KFSPropertyConstants.CSF_FULL_TIME_EMPLOYMENT_QUANTITY));
253: attributeList.add(ConsolidationUtil
254: .sum(KFSPropertyConstants.CSF_AMOUNT));
255: } else {
256: attributeList
257: .add(KFSPropertyConstants.CSF_FULL_TIME_EMPLOYMENT_QUANTITY);
258: attributeList.add(KFSPropertyConstants.CSF_AMOUNT);
259: }
260: return attributeList;
261: }
262: }
|