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.gl.web.lookupable;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.kuali.core.bo.BusinessObject;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.kfs.bo.GeneralLedgerPendingEntry;
027: import org.kuali.module.gl.batch.poster.EncumbranceCalculator;
028: import org.kuali.module.gl.bo.Encumbrance;
029: import org.kuali.module.gl.service.EncumbranceService;
030: import org.kuali.module.gl.util.BusinessObjectFieldConverter;
031: import org.kuali.module.gl.util.OJBUtility;
032: import org.kuali.module.gl.web.inquirable.EncumbranceInquirableImpl;
033: import org.springframework.transaction.annotation.Transactional;
034:
035: /**
036: * An extension of KualiLookupableImpl to support encumbrance lookups
037: */
038: @Transactional
039: public class EncumbranceLookupableHelperServiceImpl extends
040: AbstractGLLookupableHelperServiceImpl {
041:
042: private EncumbranceCalculator postEncumbrance;
043: private EncumbranceService encumbranceService;
044:
045: /**
046: * Returns the url for any drill down links within the lookup
047: * @param bo the business object with a property being drilled down on
048: * @param propertyName the name of the property being drilled down on
049: * @return a String with the URL of the property
050: * @see org.kuali.core.lookup.Lookupable#getInquiryUrl(org.kuali.core.bo.BusinessObject, java.lang.String)
051: */
052: @Override
053: public String getInquiryUrl(BusinessObject businessObject,
054: String propertyName) {
055: return (new EncumbranceInquirableImpl()).getInquiryUrl(
056: businessObject, propertyName);
057: }
058:
059: /**
060: * Generates the list of search results for this inquiry
061: * @param fieldValues the field values of the query to carry out
062: * @return List the search results returned by the lookup
063: * @see org.kuali.core.lookup.Lookupable#getSearchResults(java.util.Map)
064: */
065: @Override
066: public List getSearchResults(Map fieldValues) {
067: setBackLocation((String) fieldValues
068: .get(KFSConstants.BACK_LOCATION));
069: setDocFormKey((String) fieldValues
070: .get(KFSConstants.DOC_FORM_KEY));
071:
072: // get the pending entry option. This method must be prior to the get search results
073: String pendingEntryOption = this
074: .getSelectedPendingEntryOption(fieldValues);
075:
076: // get the search result collection
077: Iterator encumbranceIterator = encumbranceService
078: .findOpenEncumbrance(fieldValues);
079: Collection searchResultsCollection = this
080: .buildEncumbranceCollection(encumbranceIterator);
081:
082: // update search results according to the selected pending entry option
083: updateByPendingLedgerEntry(searchResultsCollection,
084: fieldValues, pendingEntryOption, false, false);
085:
086: // get the actual size of all qualified search results
087: Integer recordCount = encumbranceService
088: .getOpenEncumbranceRecordCount(fieldValues);
089: Long actualSize = OJBUtility.getResultActualSize(
090: searchResultsCollection, recordCount, fieldValues,
091: new Encumbrance());
092:
093: return this .buildSearchResultList(searchResultsCollection,
094: actualSize);
095: }
096:
097: /**
098: * Updates pending entries before their results are included in the lookup results
099: *
100: * @param entryCollection a collection of balance entries
101: * @param fieldValues the map containing the search fields and values
102: * @param isApproved flag whether the approved entries or all entries will be processed
103: * @param isConsolidated flag whether the results are consolidated or not
104: * @param isCostShareExcluded flag whether the user selects to see the results with cost share subaccount
105: * @see org.kuali.module.gl.web.lookupable.AbstractGLLookupableImpl#updateEntryCollection(java.util.Collection, java.util.Map,
106: * boolean, boolean, boolean)
107: */
108: @Override
109: protected void updateEntryCollection(Collection entryCollection,
110: Map fieldValues, boolean isApproved,
111: boolean isConsolidated, boolean isCostShareInclusive) {
112:
113: // convert the field names of balance object into corresponding ones of pending entry object
114: Map pendingEntryFieldValues = BusinessObjectFieldConverter
115: .convertToTransactionFieldValues(fieldValues);
116:
117: // go through the pending entries to update the encumbrance collection
118: Iterator pendingEntryIterator = getGeneralLedgerPendingEntryService()
119: .findPendingLedgerEntriesForEncumbrance(
120: pendingEntryFieldValues, isApproved);
121: while (pendingEntryIterator.hasNext()) {
122: GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) pendingEntryIterator
123: .next();
124: Encumbrance encumbrance = postEncumbrance.findEncumbrance(
125: entryCollection, pendingEntry);
126: postEncumbrance
127: .updateEncumbrance(pendingEntry, encumbrance);
128: }
129: }
130:
131: /**
132: * go through the given iterator to get encumbrances and put them into a collection
133: * @param iterator an iterator of encumbrances
134: * @return a collection of those encumbrances
135: */
136: private Collection buildEncumbranceCollection(Iterator iterator) {
137: Collection encumbranceCollection = new ArrayList();
138:
139: while (iterator.hasNext()) {
140: Encumbrance encumrbance = (Encumbrance) iterator.next();
141: encumbranceCollection.add(encumrbance);
142: }
143: return encumbranceCollection;
144: }
145:
146: /**
147: * Sets the postEncumbrance attribute value.
148: *
149: * @param postEncumbrance The postEncumbrance to set.
150: */
151: public void setPostEncumbrance(EncumbranceCalculator postEncumbrance) {
152: this .postEncumbrance = postEncumbrance;
153: }
154:
155: /**
156: * Sets the encumbranceService attribute value.
157: *
158: * @param encumbranceService The encumbranceService to set.
159: */
160: public void setEncumbranceService(
161: EncumbranceService encumbranceService) {
162: this.encumbranceService = encumbranceService;
163: }
164: }
|