001: /*
002: * Copyright 2006-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.Collection;
019: import java.util.Iterator;
020: import java.util.Map;
021:
022: import org.apache.commons.lang.StringUtils;
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.KFSPropertyConstants;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.kfs.dao.ojb.GeneralLedgerPendingEntryDaoOjb;
029: import org.kuali.module.financial.service.UniversityDateService;
030: import org.kuali.module.gl.bo.UniversityDate;
031: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
032: import org.kuali.module.labor.dao.LaborLedgerPendingEntryDao;
033:
034: /**
035: * OJB Implementation of LaborLedgerPendingEntryDao.
036: */
037: public class LaborLedgerPendingEntryDaoOjb extends
038: GeneralLedgerPendingEntryDaoOjb implements
039: LaborLedgerPendingEntryDao {
040: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041: .getLogger(LaborLedgerPendingEntryDaoOjb.class);
042: private final static String FINANCIAL_DOCUMENT_APPROVED_CODE = "financialDocumentApprovedCode";
043:
044: /**
045: * @see org.kuali.kfs.dao.ojb.GeneralLedgerPendingEntryDaoOjb#getEntryClass()
046: */
047: @Override
048: public Class getEntryClass() {
049: return LaborLedgerPendingEntry.class;
050: }
051:
052: /**
053: * @see org.kuali.module.labor.dao.LaborLedgerPendingEntryDao#findPendingLedgerEntriesForLedgerBalance(java.util.Map, boolean)
054: */
055: public Iterator<LaborLedgerPendingEntry> findPendingLedgerEntriesForLedgerBalance(
056: Map fieldValues, boolean isApproved) {
057: return this .findPendingEntries(fieldValues, isApproved)
058: .iterator();
059: }
060:
061: /**
062: * @see org.kuali.module.labor.dao.LaborLedgerPendingEntryDao#hasPendingLaborLedgerEntry(java.util.Map, java.lang.Object)
063: */
064: public Collection<LaborLedgerPendingEntry> hasPendingLaborLedgerEntry(
065: Map fieldValues, Object businessObject) {
066: LOG.debug("hasPendingLaborLedgerEntry() started");
067:
068: Criteria criteria = new Criteria();
069: for (Iterator iter = fieldValues.keySet().iterator(); iter
070: .hasNext();) {
071: String element = (String) iter.next();
072: if (element.equals("documentNumber")) {
073: criteria.addNotEqualTo(element, fieldValues
074: .get(element));
075: } else {
076: criteria.addEqualTo(element, fieldValues.get(element));
077: }
078: }
079:
080: QueryByCriteria qbc = QueryFactory.newQuery(getEntryClass(),
081: criteria);
082:
083: return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
084: }
085:
086: /**
087: * @see org.kuali.kfs.dao.ojb.GeneralLedgerPendingEntryDaoOjb#deleteByFinancialDocumentApprovedCode(java.lang.String)
088: */
089: @Override
090: public void deleteByFinancialDocumentApprovedCode(
091: String financialDocumentApprovedCode) {
092: LOG.debug("deleteByFinancialDocumentApprovedCode() started");
093:
094: Criteria criteria = new Criteria();
095: criteria.addEqualTo(FINANCIAL_DOCUMENT_APPROVED_CODE,
096: financialDocumentApprovedCode);
097:
098: QueryByCriteria qbc = QueryFactory.newQuery(this
099: .getEntryClass(), criteria);
100: getPersistenceBrokerTemplate().deleteByQuery(qbc);
101: getPersistenceBrokerTemplate().clearCache();
102: }
103:
104: /**
105: * @see org.kuali.kfs.dao.ojb.GeneralLedgerPendingEntryDaoOjb#findPendingEntries(java.util.Map, boolean)
106: */
107: @Override
108: public Collection findPendingEntries(Map fieldValues,
109: boolean isApproved) {
110: LOG.debug("findPendingEntries(Map, boolean) started");
111:
112: // backup fiscal year and period code since they maight be removed by GL pending entry dao
113: Object fiscalYearBackup = fieldValues
114: .get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
115: Object periodCodeBackup = fieldValues
116: .get(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE);
117:
118: Collection<LaborLedgerPendingEntry> pendingEntries = super
119: .findPendingEntries(fieldValues, isApproved);
120: UniversityDate currentUniversityDate = SpringContext.getBean(
121: UniversityDateService.class).getCurrentUniversityDate();
122: String currentFiscalPeriodCode = currentUniversityDate
123: .getUniversityFiscalAccountingPeriod();
124: Integer currentFiscalYear = currentUniversityDate
125: .getUniversityFiscalYear();
126:
127: for (LaborLedgerPendingEntry pendingEntry : pendingEntries) {
128:
129: String periodCode = pendingEntry
130: .getUniversityFiscalPeriodCode();
131: if (StringUtils.isEmpty(periodCode)) {
132: pendingEntry
133: .setUniversityFiscalPeriodCode(currentFiscalPeriodCode);
134: }
135:
136: Integer fiscalYear = pendingEntry.getUniversityFiscalYear();
137: if (fiscalYear == null
138: || StringUtils.isEmpty(fiscalYear.toString())) {
139: pendingEntry.setUniversityFiscalYear(currentFiscalYear);
140: }
141: }
142:
143: fieldValues.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
144: fiscalYearBackup);
145: fieldValues.put(
146: KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE,
147: periodCodeBackup);
148:
149: return pendingEntries;
150: }
151: }
|