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.module.ld.dataaccess.impl; 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.module.ld.businessobject.LaborLedgerPendingEntry; 027 import org.kuali.kfs.module.ld.dataaccess.LaborLedgerPendingEntryDao; 028 import org.kuali.kfs.sys.businessobject.UniversityDate; 029 import org.kuali.kfs.sys.context.SpringContext; 030 import org.kuali.kfs.sys.dataaccess.impl.GeneralLedgerPendingEntryDaoOjb; 031 import org.kuali.kfs.sys.service.UniversityDateService; 032 033 /** 034 * OJB Implementation of LaborLedgerPendingEntryDao. 035 */ 036 public class LaborLedgerPendingEntryDaoOjb extends GeneralLedgerPendingEntryDaoOjb implements LaborLedgerPendingEntryDao { 037 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborLedgerPendingEntryDaoOjb.class); 038 protected final static String FINANCIAL_DOCUMENT_APPROVED_CODE = "financialDocumentApprovedCode"; 039 040 /** 041 * @see org.kuali.kfs.sys.dataaccess.impl.GeneralLedgerPendingEntryDaoOjb#getEntryClass() 042 */ 043 @Override 044 public Class getEntryClass() { 045 return LaborLedgerPendingEntry.class; 046 } 047 048 /** 049 * @see org.kuali.kfs.module.ld.dataaccess.LaborLedgerPendingEntryDao#findPendingLedgerEntriesForLedgerBalance(java.util.Map, boolean) 050 */ 051 public Iterator<LaborLedgerPendingEntry> findPendingLedgerEntriesForLedgerBalance(Map fieldValues, boolean isApproved) { 052 return this.findPendingEntries(fieldValues, isApproved).iterator(); 053 } 054 055 /** 056 * @see org.kuali.kfs.module.ld.dataaccess.LaborLedgerPendingEntryDao#hasPendingLaborLedgerEntry(java.util.Map, java.lang.Object) 057 */ 058 public Collection<LaborLedgerPendingEntry> hasPendingLaborLedgerEntry(Map fieldValues, Object businessObject) { 059 LOG.debug("hasPendingLaborLedgerEntry() started"); 060 061 Criteria criteria = new Criteria(); 062 for (Iterator iter = fieldValues.keySet().iterator(); iter.hasNext();) { 063 String element = (String) iter.next(); 064 if (element.equals("documentNumber")) { 065 criteria.addNotEqualTo(element, fieldValues.get(element)); 066 } 067 else { 068 criteria.addEqualTo(element, fieldValues.get(element)); 069 } 070 } 071 072 QueryByCriteria qbc = QueryFactory.newQuery(getEntryClass(), criteria); 073 074 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc); 075 } 076 077 /** 078 * @see org.kuali.kfs.sys.dataaccess.impl.GeneralLedgerPendingEntryDaoOjb#deleteByFinancialDocumentApprovedCode(java.lang.String) 079 */ 080 @Override 081 public void deleteByFinancialDocumentApprovedCode(String financialDocumentApprovedCode) { 082 LOG.debug("deleteByFinancialDocumentApprovedCode() started"); 083 084 Criteria criteria = new Criteria(); 085 criteria.addEqualTo(FINANCIAL_DOCUMENT_APPROVED_CODE, financialDocumentApprovedCode); 086 087 QueryByCriteria qbc = QueryFactory.newQuery(this.getEntryClass(), criteria); 088 getPersistenceBrokerTemplate().deleteByQuery(qbc); 089 getPersistenceBrokerTemplate().clearCache(); 090 } 091 092 /** 093 * @see org.kuali.kfs.sys.dataaccess.impl.GeneralLedgerPendingEntryDaoOjb#findPendingEntries(java.util.Map, boolean) 094 */ 095 @Override 096 public Collection findPendingEntries(Map fieldValues, boolean isApproved) { 097 LOG.debug("findPendingEntries(Map, boolean) started"); 098 099 Collection<LaborLedgerPendingEntry> pendingEntries = super.findPendingEntries(fieldValues, isApproved); 100 UniversityDate currentUniversityDate = SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate(); 101 String currentFiscalPeriodCode = currentUniversityDate.getUniversityFiscalAccountingPeriod(); 102 Integer currentFiscalYear = currentUniversityDate.getUniversityFiscalYear(); 103 104 for (LaborLedgerPendingEntry pendingEntry : pendingEntries) { 105 106 String periodCode = pendingEntry.getUniversityFiscalPeriodCode(); 107 if (StringUtils.isEmpty(periodCode)) { 108 pendingEntry.setUniversityFiscalPeriodCode(currentFiscalPeriodCode); 109 } 110 111 Integer fiscalYear = pendingEntry.getUniversityFiscalYear(); 112 if (fiscalYear == null || StringUtils.isEmpty(fiscalYear.toString())) { 113 pendingEntry.setUniversityFiscalYear(currentFiscalYear); 114 } 115 } 116 117 return pendingEntries; 118 } 119 }