01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.chart.dao.ojb;
17:
18: import java.util.ArrayList;
19: import java.util.Collection;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import org.apache.ojb.broker.query.Criteria;
24: import org.apache.ojb.broker.query.QueryByCriteria;
25: import org.apache.ojb.broker.query.QueryFactory;
26: import org.kuali.core.bo.user.UniversalUser;
27: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
28: import org.kuali.module.chart.bo.Chart;
29: import org.kuali.module.chart.dao.ChartDao;
30:
31: /**
32: * This class is the OJB implementation of the ChartDao interface.
33: */
34:
35: public class ChartDaoOjb extends PlatformAwareDaoBaseOjb implements
36: ChartDao {
37: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
38: .getLogger(ChartDaoOjb.class);
39:
40: /**
41: * @see org.kuali.module.chart.dao.ChartDao#getAll()
42: */
43: public Collection getAll() {
44: QueryByCriteria qbc = QueryFactory.newQuery(Chart.class,
45: (Criteria) null);
46: qbc.addOrderByAscending("chartOfAccountsCode");
47: Collection charts = getPersistenceBrokerTemplate()
48: .getCollectionByQuery(qbc);
49: List chartList = new ArrayList(charts);
50: return chartList;
51: }
52:
53: /**
54: * @see org.kuali.module.chart.dao.ChartDao#getUniversityChart()
55: */
56: public Chart getUniversityChart() {
57: Criteria criteria = new Criteria();
58: criteria.addEqualToField("FIN_COA_CD", "RPTS_TO_FIN_COA_CD");
59: return (Chart) getPersistenceBrokerTemplate()
60: .getCollectionByQuery(
61: QueryFactory.newQuery(Chart.class, criteria))
62: .iterator().next();
63: }
64:
65: /**
66: * @see org.kuali.module.chart.dao.ChartDao#getByPrimaryId(java.lang.String)
67: */
68: public Chart getByPrimaryId(String chartOfAccountsCode) {
69: Criteria criteria = new Criteria();
70: criteria.addEqualTo("chartOfAccountsCode", chartOfAccountsCode);
71:
72: return (Chart) getPersistenceBrokerTemplate().getObjectByQuery(
73: QueryFactory.newQuery(Chart.class, criteria));
74: }
75:
76: /**
77: * fetch the charts that the user is manager for
78: *
79: * @param kualiUser
80: * @return a list of Charts that the user has responsibility for
81: */
82: public List getChartsThatUserIsResponsibleFor(
83: UniversalUser universalUser) {
84: List chartResponsibilities = new ArrayList();
85: Criteria criteria = new Criteria();
86: criteria.addEqualTo("finCoaManagerUniversalId", universalUser
87: .getPersonUniversalIdentifier());
88: Collection charts = getPersistenceBrokerTemplate()
89: .getCollectionByQuery(
90: QueryFactory.newQuery(Chart.class, criteria));
91: for (Iterator iter = charts.iterator(); iter.hasNext();) {
92: Chart chart = (Chart) iter.next();
93: chartResponsibilities.add(chart);
94: }
95: return chartResponsibilities;
96: }
97: }
|