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.coa.dataaccess.impl; 017 018 import java.util.ArrayList; 019 import java.util.Collection; 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.QueryByCriteria; 025 import org.apache.ojb.broker.query.QueryFactory; 026 import org.kuali.kfs.coa.businessobject.Chart; 027 import org.kuali.kfs.coa.businessobject.Organization; 028 import org.kuali.kfs.coa.dataaccess.ChartDao; 029 import org.kuali.kfs.sys.KFSConstants; 030 import org.kuali.rice.kim.bo.Person; 031 import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb; 032 import org.kuali.rice.kns.service.ParameterService; 033 034 /** 035 * This class is the OJB implementation of the ChartDao interface. 036 */ 037 038 public class ChartDaoOjb extends PlatformAwareDaoBaseOjb implements ChartDao { 039 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ChartDaoOjb.class); 040 private ParameterService parameterService; 041 042 /** 043 * @see org.kuali.kfs.coa.dataaccess.ChartDao#getAll() 044 */ 045 public Collection getAll() { 046 QueryByCriteria qbc = QueryFactory.newQuery(Chart.class, (Criteria) null); 047 qbc.addOrderByAscending("chartOfAccountsCode"); 048 Collection charts = getPersistenceBrokerTemplate().getCollectionByQuery(qbc); 049 List chartList = new ArrayList(charts); 050 return chartList; 051 } 052 053 /** 054 * @see org.kuali.kfs.coa.dataaccess.ChartDao#getUniversityChart() 055 */ 056 public Chart getUniversityChart() { 057 // 1. find the organization with the type which reports to itself 058 final String organizationReportsToSelfParameterValue = getParameterService().getParameterValue(Organization.class, KFSConstants.ChartApcParms.ORG_MUST_REPORT_TO_SELF_ORG_TYPES); 059 Criteria orgCriteria = new Criteria(); 060 orgCriteria.addEqualTo("organizationTypeCode", organizationReportsToSelfParameterValue); 061 orgCriteria.addEqualTo("active", KFSConstants.ACTIVE_INDICATOR); 062 063 Iterator organizations = getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(Organization.class, orgCriteria)).iterator(); 064 Organization topDogOrg = null; 065 while (organizations.hasNext()) { 066 topDogOrg = (Organization)organizations.next(); 067 } 068 069 return getByPrimaryId(topDogOrg.getChartOfAccountsCode()); 070 } 071 072 /** 073 * @see org.kuali.kfs.coa.dataaccess.ChartDao#getByPrimaryId(java.lang.String) 074 */ 075 public Chart getByPrimaryId(String chartOfAccountsCode) { 076 Criteria criteria = new Criteria(); 077 criteria.addEqualTo("chartOfAccountsCode", chartOfAccountsCode); 078 079 return (Chart) getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(Chart.class, criteria)); 080 } 081 082 /** 083 * fetch the charts that the user is manager for 084 * 085 * @param kualiUser 086 * @return a list of Charts that the user has responsibility for 087 */ 088 public List getChartsThatUserIsResponsibleFor(Person person) { 089 List chartResponsibilities = new ArrayList(); 090 Criteria criteria = new Criteria(); 091 criteria.addEqualTo("finCoaManagerUniversalId", person.getPrincipalId()); 092 Collection charts = getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(Chart.class, criteria)); 093 for (Iterator iter = charts.iterator(); iter.hasNext();) { 094 Chart chart = (Chart) iter.next(); 095 chartResponsibilities.add(chart); 096 } 097 return chartResponsibilities; 098 } 099 100 /** 101 * Gets the parameterService attribute. 102 * @return Returns the parameterService. 103 */ 104 public ParameterService getParameterService() { 105 return parameterService; 106 } 107 108 /** 109 * Sets the parameterService attribute value. 110 * @param parameterService The parameterService to set. 111 */ 112 public void setParameterService(ParameterService parameterService) { 113 this.parameterService = parameterService; 114 } 115 } 116