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.Collection;
019: import java.util.Collections;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.bo.BusinessObject;
026: import org.kuali.core.lookup.AbstractLookupableHelperServiceImpl;
027: import org.kuali.core.lookup.CollectionIncomplete;
028: import org.kuali.core.util.BeanPropertyComparator;
029: import org.kuali.core.web.ui.Field;
030: import org.kuali.core.web.ui.Row;
031: import org.kuali.kfs.KFSConstants;
032: import org.kuali.kfs.KFSPropertyConstants;
033: import org.kuali.kfs.service.GeneralLedgerPendingEntryService;
034: import org.kuali.module.gl.web.Constant;
035:
036: /**
037: * The abstract parent class for GL Lookupables, providing base implementations of methods
038: * to make adding new lookupable reports easier
039: */
040: public abstract class AbstractGLLookupableHelperServiceImpl extends
041: AbstractLookupableHelperServiceImpl {
042:
043: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
044: .getLogger(AbstractGLLookupableHelperServiceImpl.class);
045:
046: private GeneralLedgerPendingEntryService generalLedgerPendingEntryService;
047:
048: protected GeneralLedgerPendingEntryService getGeneralLedgerPendingEntryService() {
049: return generalLedgerPendingEntryService;
050: }
051:
052: public void setGeneralLedgerPendingEntryService(
053: GeneralLedgerPendingEntryService generalLedgerPendingEntryService) {
054: this .generalLedgerPendingEntryService = generalLedgerPendingEntryService;
055: }
056:
057: /**
058: * This method overides that in parent class so that the maintainance actions are surpressed
059: *
060: * @returns links to edit and copy maintenance action for the current maintenance record. For GL balance inquire, there are no
061: * maintenance links.
062: */
063: @Override
064: public String getActionUrls(BusinessObject bo) {
065: return KFSConstants.EMPTY_STRING;
066: }
067:
068: /**
069: * This method tests if the user selects to see the general ledager pending entries
070: *
071: * @param fieldValues the map containing the search fields and values
072: * @return the value of pending entry option
073: */
074: protected String getSelectedPendingEntryOption(Map fieldValues) {
075: // truncate the non-property filed
076: String pendingEntryOption = (String) fieldValues
077: .get(Constant.PENDING_ENTRY_OPTION);
078: fieldValues.remove(Constant.PENDING_ENTRY_OPTION);
079:
080: return pendingEntryOption;
081: }
082:
083: /**
084: * This method tests if the user selects to see the reports by monthly or accumulated
085: *
086: * @param fieldValues the map containing the search fields and values
087: * @return the value of amount view option
088: */
089: protected String getSelectedAmountViewOption(Map fieldValues) {
090:
091: String amountViewOption = Constant.EMPTY_STRING;
092: if (fieldValues.containsKey(Constant.AMOUNT_VIEW_OPTION)) {
093: amountViewOption = (String) fieldValues
094: .get(Constant.AMOUNT_VIEW_OPTION);
095:
096: // truncate the non-property filed
097: fieldValues.remove(Constant.AMOUNT_VIEW_OPTION);
098: }
099: return amountViewOption;
100: }
101:
102: /**
103: * This method tests if the user selects to see the details or consolidated results
104: *
105: * @param fieldValues the map containing the search fields and values
106: * @return true if consolidation is selected and subaccount is not specified
107: */
108: protected boolean isConsolidationSelected(Map fieldValues) {
109: // truncate the non-property filed
110: String consolidationOption = (String) fieldValues
111: .get(Constant.CONSOLIDATION_OPTION);
112: fieldValues.remove(Constant.CONSOLIDATION_OPTION);
113:
114: // detail option would be used
115: if (Constant.DETAIL.equals(consolidationOption)) {
116: return false;
117: }
118:
119: // if the subAccountNumber is specified, detail option could be used
120: String subAccountNumber = (String) fieldValues
121: .get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
122: if (!StringUtils.isBlank(subAccountNumber)) {
123: this .changeFieldValue(Constant.CONSOLIDATION_OPTION,
124: Constant.DETAIL);
125: return false;
126: }
127:
128: // if the subObjectCode is specified, detail option could be used
129: String subObjectCode = (String) fieldValues
130: .get(KFSPropertyConstants.SUB_OBJECT_CODE);
131: if (!StringUtils.isBlank(subObjectCode)) {
132: this .changeFieldValue(Constant.CONSOLIDATION_OPTION,
133: Constant.DETAIL);
134: return false;
135: }
136:
137: // if the objectTypeCode is specified, detail option could be used
138: String objectTypeCode = (String) fieldValues
139: .get(KFSPropertyConstants.OBJECT_TYPE_CODE);
140: if (!StringUtils.isBlank(objectTypeCode)) {
141: this .changeFieldValue(Constant.CONSOLIDATION_OPTION,
142: Constant.DETAIL);
143: return false;
144: }
145: return true;
146: }
147:
148: /**
149: * This method tests if the user selects to see the results with cost share subaccount
150: *
151: * @param fieldValues the map containing the search fields and values
152: * @return true if inclusive option is selected
153: */
154: protected boolean isCostShareInclusive(Map fieldValues) {
155: // TODO: is this method being called?
156: // truncate the non-property filed
157: String costShareOption = (String) fieldValues
158: .get(Constant.COST_SHARE_OPTION);
159: fieldValues.remove(Constant.COST_SHARE_OPTION);
160:
161: if (costShareOption.equals(Constant.COST_SHARE_INCLUDE)) {
162: return true;
163: }
164: return false;
165: }
166:
167: /**
168: * build the serach result list from the given collection and the number of all qualified search results
169: *
170: * @param searchResultsCollection the given search results, which may be a subset of the qualified search results
171: * @param actualSize the number of all qualified search results
172: * @return the serach result list with the given results and actual size
173: */
174: protected List buildSearchResultList(
175: Collection searchResultsCollection, Long actualSize) {
176: CollectionIncomplete results = new CollectionIncomplete(
177: searchResultsCollection, actualSize);
178:
179: // sort list if default sort column given
180: List searchResults = (List) results;
181: List defaultSortColumns = getDefaultSortColumns();
182: if (defaultSortColumns.size() > 0) {
183: Collections.sort(results, new BeanPropertyComparator(
184: defaultSortColumns, true));
185: }
186: return searchResults;
187: }
188:
189: /**
190: * This method is used to update amounts of the given entries with the corresponding pending amounts. It is a factory that
191: * executes the update methods of individual derived classes.
192: *
193: * @param entryCollection a collection of balance entries
194: * @param fieldValues the map containing the search fields and values
195: * @param pendingEntryOption flag whether the approved entries or all entries will be processed
196: * @param isCostShareInclusive flag whether the user selects to see the results with cost share subaccount
197: * @param isConsolidated flag whether the results are consolidated or not
198: */
199: protected void updateByPendingLedgerEntry(
200: Collection entryCollection, Map fieldValues,
201: String pendingEntryOption, boolean isConsolidated,
202: boolean isCostShareInclusive) {
203:
204: // determine if search results need to be updated by pending ledger entries
205: if (Constant.ALL_PENDING_ENTRY.equals(pendingEntryOption)) {
206: updateEntryCollection(entryCollection, fieldValues, false,
207: isConsolidated, isCostShareInclusive);
208: } else if (Constant.APPROVED_PENDING_ENTRY
209: .equals(pendingEntryOption)) {
210: updateEntryCollection(entryCollection, fieldValues, true,
211: isConsolidated, isCostShareInclusive);
212: }
213: }
214:
215: /**
216: * This method is an abstract method and implemented to update the given entry collection by the children classes. It is called
217: * by updateByPendingLedgerEntry method.
218: *
219: * @param entryCollection a collection of balance entries
220: * @param fieldValues the map containing the search fields and values
221: * @param isApproved flag whether the approved entries or all entries will be processed
222: * @param isCostShareInclusive flag whether the user selects to see the results with cost share subaccount
223: * @param isConsolidated flag whether the results are consolidated or not
224: */
225: protected abstract void updateEntryCollection(
226: Collection entryCollection, Map fieldValues,
227: boolean isApproved, boolean isConsolidated,
228: boolean isCostShareInclusive);
229:
230: // change the value of the field with the given field name into the given field value
231: private void changeFieldValue(String fieldName, String fieldValue) {
232: for (Iterator rowIterator = getRows().iterator(); rowIterator
233: .hasNext();) {
234: Row row = (Row) rowIterator.next();
235:
236: for (Iterator fieldIterator = row.getFields().iterator(); fieldIterator
237: .hasNext();) {
238: Field field = (Field) fieldIterator.next();
239:
240: if (field.getPropertyName().equals(fieldName)) {
241: field.setPropertyValue(fieldValue);
242: }
243: }
244: }
245: }
246: }
|