001: /*
002: * Copyright 2005-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.chart.dao.ojb;
017:
018: import java.util.ArrayList;
019: import java.util.Collections;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.apache.ojb.broker.query.Criteria;
024: import org.apache.ojb.broker.query.QueryFactory;
025: import org.apache.ojb.broker.query.ReportQueryByCriteria;
026: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
027: import org.kuali.core.util.TransactionalServiceUtils;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.KFSPropertyConstants;
030: import org.kuali.module.chart.bo.Account;
031: import org.kuali.module.chart.bo.Org;
032: import org.kuali.module.chart.dao.OrganizationDao;
033:
034: /**
035: * This class is the OJB implementation of the OrganizationDao interface.
036: */
037: public class OrganizationDaoOjb extends PlatformAwareDaoBaseOjb
038: implements OrganizationDao {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(OrganizationDaoOjb.class);
041:
042: /**
043: * @see org.kuali.module.chart.dao.OrganizationDao#getByPrimaryId(java.lang.String, java.lang.String)
044: */
045: public Org getByPrimaryId(String chartOfAccountsCode,
046: String organizationCode) {
047: Criteria criteria = new Criteria();
048: criteria.addEqualTo("chartOfAccountsCode", chartOfAccountsCode);
049: criteria.addEqualTo("organizationCode", organizationCode);
050:
051: return (Org) getPersistenceBrokerTemplate().getObjectByQuery(
052: QueryFactory.newQuery(Org.class, criteria));
053: }
054:
055: /**
056: * @see org.kuali.module.chart.dao.OrganizationDao#save(org.kuali.module.chart.bo.Org)
057: */
058: public void save(Org organization) {
059: getPersistenceBrokerTemplate().store(organization);
060: }
061:
062: /**
063: * @see org.kuali.module.chart.dao.OrganizationDao#getActiveAccountsByOrg(java.lang.String, java.lang.String)
064: */
065: public List getActiveAccountsByOrg(String chartOfAccountsCode,
066: String organizationCode) {
067:
068: List accounts = new ArrayList();
069:
070: Criteria criteria = new Criteria();
071: criteria.addEqualTo("chartOfAccountsCode", chartOfAccountsCode);
072: criteria.addEqualTo("organizationCode", organizationCode);
073: criteria.addEqualTo("accountClosedIndicator", Boolean.FALSE);
074:
075: accounts = (List) getPersistenceBrokerTemplate()
076: .getCollectionByQuery(
077: QueryFactory.newQuery(Account.class, criteria));
078:
079: if (accounts.isEmpty() || accounts.size() == 0) {
080: return Collections.EMPTY_LIST;
081: }
082: return accounts;
083: }
084:
085: /**
086: * @see org.kuali.module.chart.dao.OrganizationDao#getActiveChildOrgs(java.lang.String, java.lang.String)
087: */
088: public List getActiveChildOrgs(String chartOfAccountsCode,
089: String organizationCode) {
090:
091: List orgs = new ArrayList();
092:
093: Criteria criteria = new Criteria();
094: criteria.addEqualTo("reportsToChartOfAccountsCode",
095: chartOfAccountsCode);
096: criteria.addEqualTo("reportsToOrganizationCode",
097: organizationCode);
098: criteria
099: .addEqualTo("organizationActiveIndicator", Boolean.TRUE);
100:
101: orgs = (List) getPersistenceBrokerTemplate()
102: .getCollectionByQuery(
103: QueryFactory.newQuery(Org.class, criteria));
104:
105: if (orgs.isEmpty() || orgs.size() == 0) {
106: return Collections.EMPTY_LIST;
107: }
108: return orgs;
109: }
110:
111: /**
112: * @see org.kuali.module.chart.dao.OrganizationDao#getActiveOrgsByType(java.lang.String)
113: */
114: public List<Org> getActiveOrgsByType(String organizationTypeCode) {
115: List<Org> orgs = new ArrayList<Org>();
116:
117: Criteria criteria = new Criteria();
118: criteria.addEqualTo("organizationTypeCode",
119: organizationTypeCode);
120: criteria
121: .addEqualTo("organizationActiveIndicator", Boolean.TRUE);
122:
123: orgs = (List<Org>) getPersistenceBrokerTemplate()
124: .getCollectionByQuery(
125: QueryFactory.newQuery(Org.class, criteria));
126:
127: if (orgs.isEmpty() || orgs.size() == 0) {
128: return Collections.EMPTY_LIST;
129: }
130: return orgs;
131: }
132:
133: /**
134: * we insist that the root organization be active
135: *
136: * @see org.kuali.module.chart.dao.OrganizationDao#getRootOrganizationCode(java.lang.String, java.lang.String)
137: */
138: public String[] getRootOrganizationCode(String rootChart,
139: String selfReportsOrgTypeCode) {
140: String[] returnValues = { null, null };
141: Criteria criteria = new Criteria();
142: criteria.addEqualTo(
143: KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, rootChart);
144: criteria.addEqualTo(
145: KFSPropertyConstants.ORGANIZATION_TYPE_CODE,
146: selfReportsOrgTypeCode);
147: // the root organization must be active
148: criteria.addEqualTo(
149: KFSPropertyConstants.ORGANIZATION_ACTIVE_INDICATOR,
150: KFSConstants.ACTIVE_INDICATOR);
151: String[] attributeList = {
152: KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
153: KFSPropertyConstants.ORGANIZATION_CODE };
154: ReportQueryByCriteria rptQuery = new ReportQueryByCriteria(
155: Org.class, attributeList, criteria);
156: Iterator Results = getPersistenceBrokerTemplate()
157: .getReportQueryIteratorByQuery(rptQuery);
158: if (Results.hasNext()) {
159: Object[] returnList = (Object[]) TransactionalServiceUtils
160: .retrieveFirstAndExhaustIterator(Results);
161: returnValues[0] = (String) returnList[0];
162: returnValues[1] = (String) returnList[1];
163: }
164: return returnValues;
165: }
166:
167: }
|