001: /*
002: * Copyright 2005-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.core.lookup;
017:
018: import java.util.Collection;
019: import java.util.List;
020: import java.util.Map;
021: import java.util.Properties;
022:
023: import org.kuali.RiceConstants;
024: import org.kuali.core.bo.BusinessObject;
025: import org.kuali.core.service.BusinessObjectDictionaryService;
026: import org.kuali.core.service.DataDictionaryService;
027: import org.kuali.core.util.UrlFactory;
028: import org.kuali.core.web.struts.form.LookupForm;
029: import org.kuali.core.web.ui.ResultRow;
030:
031: /**
032: * Kuali lookup implementation. Implements methods necessary to render the lookup and provides search and return methods.
033: *
034: *
035: */
036: public class KualiLookupableImpl implements Lookupable {
037: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
038: .getLogger(KualiLookupableImpl.class);
039: private static final String[] IGNORE_LIST = {
040: RiceConstants.DOC_FORM_KEY, RiceConstants.BACK_LOCATION };
041:
042: private Class businessObjectClass;
043: private LookupableHelperService lookupableHelperService;
044:
045: /**
046: * Default constructor initializes services from spring
047: */
048: public KualiLookupableImpl() {
049: }
050:
051: /**
052: * Sets the business object class for the lookup instance, then rows can be set for search render.
053: *
054: * @param boClass Class for the lookup business object
055: */
056: public void setBusinessObjectClass(Class boClass) {
057: if (boClass == null) {
058: throw new RuntimeException("Business object class is null.");
059: }
060:
061: this .businessObjectClass = boClass;
062:
063: // next line initializes the helper to return correct values for getRow();
064: getLookupableHelperService().setBusinessObjectClass(boClass);
065: }
066:
067: /**
068: * Constructs the list of columns for the search results. All properties for the column objects come from the DataDictionary.
069: */
070: public List getColumns() {
071: return getLookupableHelperService().getColumns();
072: }
073:
074: /**
075: * Checks that any required search fields have value.
076: *
077: * @see org.kuali.core.lookup.Lookupable#validateSearchParameters(java.util.Map)
078: */
079: public void validateSearchParameters(Map fieldValues) {
080: getLookupableHelperService().validateSearchParameters(
081: fieldValues);
082: }
083:
084: /**
085: * Uses Lookup Service to provide a basic unbounded search.
086: *
087: * @param fieldValues - Map containing prop name keys and search values
088: *
089: * @return List found business objects
090: */
091: public List<BusinessObject> getSearchResultsUnbounded(
092: Map<String, String> fieldValues) {
093: return getLookupableHelperService().getSearchResultsUnbounded(
094: fieldValues);
095: }
096:
097: /**
098: * Uses Lookup Service to provide a basic search.
099: *
100: * @param fieldValues - Map containing prop name keys and search values
101: *
102: * @return List found business objects
103: */
104: public List<BusinessObject> getSearchResults(
105: Map<String, String> fieldValues) {
106: return getLookupableHelperService().getSearchResults(
107: fieldValues);
108: }
109:
110: /**
111: * @return the return url for each result row.
112: */
113: public String getReturnUrl(BusinessObject bo, Map fieldConversions,
114: String lookupImpl) {
115: return getLookupableHelperService().getReturnUrl(bo,
116: fieldConversions, lookupImpl);
117: }
118:
119: /**
120: * Build a maintenanace url.
121: *
122: * @param bo - business object representing the record for maint.
123: * @param methodToCall - maintenance action
124: * @return
125: */
126: protected String getMaintenanceUrl(BusinessObject bo,
127: String methodToCall) {
128: //TODO: delete me
129: return getLookupableHelperService().getMaintenanceUrl(bo,
130: methodToCall);
131: }
132:
133: /**
134: * @see org.kuali.core.lookup.Lookupable#getCreateNewUrl()
135: */
136: public String getCreateNewUrl() {
137: String url = "";
138:
139: if (getLookupableHelperService()
140: .allowsMaintenanceNewOrCopyAction()) {
141: Properties parameters = new Properties();
142: parameters.put(RiceConstants.DISPATCH_REQUEST_PARAMETER,
143: RiceConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
144: parameters.put(
145: RiceConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE,
146: this .businessObjectClass.getName());
147:
148: url = UrlFactory.parameterizeUrl(
149: RiceConstants.MAINTENANCE_ACTION, parameters);
150: url = "<a href=\""
151: + url
152: + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>";
153: }
154:
155: return url;
156: }
157:
158: /**
159: * @see org.kuali.core.lookup.Lookupable#getHtmlMenuBar()
160: */
161: public String getHtmlMenuBar() {
162: return getBusinessObjectDictionaryService().getLookupMenuBar(
163: getBusinessObjectClass());
164: }
165:
166: /**
167: * @see org.kuali.core.lookup.Lookupable#getRows()
168: */
169: public List getRows() {
170: return getLookupableHelperService().getRows();
171: }
172:
173: /**
174: * @see org.kuali.core.lookup.Lookupable#getTitle()
175: */
176: public String getTitle() {
177: return getBusinessObjectDictionaryService().getLookupTitle(
178: getBusinessObjectClass());
179: }
180:
181: /**
182: * @see org.kuali.core.lookup.Lookupable#getReturnLocation()
183: */
184: public String getReturnLocation() {
185: return getLookupableHelperService().getReturnLocation();
186: }
187:
188: /**
189: * @return Returns the businessObjectClass.
190: */
191: public Class getBusinessObjectClass() {
192: return businessObjectClass;
193: }
194:
195: /**
196: * @return a List of the names of fields which are marked in data dictionary as return fields.
197: */
198: public List getReturnKeys() {
199: return getLookupableHelperService().getReturnKeys();
200: }
201:
202: /**
203: * @see org.kuali.core.lookup.Lookupable#getLookupInstructions()
204: */
205: public String getLookupInstructions() {
206: return getBusinessObjectDictionaryService()
207: .getLookupInstructions(getBusinessObjectClass());
208: }
209:
210: /**
211: * @see org.kuali.core.lookup.Lookupable#getExtraButtonSource()
212: */
213: public String getExtraButtonSource() {
214: return getBusinessObjectDictionaryService()
215: .getExtraButtonSource(getBusinessObjectClass());
216: }
217:
218: /**
219: * @see org.kuali.core.lookup.Lookupable#getExtraButtonParams()
220: */
221: public String getExtraButtonParams() {
222: return getBusinessObjectDictionaryService()
223: .getExtraButtonParams(getBusinessObjectClass());
224: }
225:
226: /**
227: * @return property names that will be used to sort on by default
228: */
229: public List getDefaultSortColumns() {
230: return getLookupableHelperService().getDefaultSortColumns();
231: }
232:
233: /**
234: * @see org.kuali.core.lookup.Lookupable#checkForAdditionalFields(java.util.Map)
235: */
236: public boolean checkForAdditionalFields(Map fieldValues) {
237: return getLookupableHelperService().checkForAdditionalFields(
238: fieldValues);
239: }
240:
241: /**
242: * @return Returns the backLocation.
243: */
244: public String getBackLocation() {
245: return getLookupableHelperService().getBackLocation();
246: }
247:
248: /**
249: * @param backLocation The backLocation to set.
250: */
251: public void setBackLocation(String backLocation) {
252: getLookupableHelperService().setBackLocation(backLocation);
253: }
254:
255: /**
256: * @return Returns the docFormKey.
257: */
258: public String getDocFormKey() {
259: return getLookupableHelperService().getDocFormKey();
260: }
261:
262: /**
263: * // this method is public because unit tests depend upon it
264: * @param docFormKey The docFormKey to set.
265: */
266: public void setDocFormKey(String docFormKey) {
267: getLookupableHelperService().setDocFormKey(docFormKey);
268: }
269:
270: /**
271: * @return Returns the businessObjectDictionaryService.
272: */
273: protected BusinessObjectDictionaryService getBusinessObjectDictionaryService() {
274: return getLookupableHelperService()
275: .getBusinessObjectDictionaryService();
276: }
277:
278: /**
279: * @see org.kuali.core.lookup.Lookupable#setFieldConversions(java.util.Map)
280: */
281: public void setFieldConversions(Map fieldConversions) {
282: getLookupableHelperService().setFieldConversions(
283: fieldConversions);
284: }
285:
286: /**
287: * @return Returns the dataDictionaryService.
288: */
289: protected DataDictionaryService getDataDictionaryService() {
290: return getLookupableHelperService().getDataDictionaryService();
291: }
292:
293: /**
294: * Sets the readOnlyFieldsList attribute value.
295: *
296: * @param readOnlyFieldsList The readOnlyFieldsList to set.
297: */
298: public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) {
299: getLookupableHelperService().setReadOnlyFieldsList(
300: readOnlyFieldsList);
301: }
302:
303: public LookupableHelperService getLookupableHelperService() {
304: return lookupableHelperService;
305: }
306:
307: /**
308: * Sets the lookupableHelperService attribute value.
309: * @param lookupableHelperService The lookupableHelperService to set.
310: */
311: public void setLookupableHelperService(
312: LookupableHelperService lookupableHelperService) {
313: this .lookupableHelperService = lookupableHelperService;
314: }
315:
316: /**
317: * Performs a lookup that can only return one row.
318: * @see org.kuali.core.lookup.Lookupable#performLookup(org.kuali.core.web.struts.form.LookupForm, java.util.List, boolean)
319: */
320: public Collection performLookup(LookupForm lookupForm,
321: List<ResultRow> resultTable, boolean bounded) {
322: return getLookupableHelperService().performLookup(lookupForm,
323: resultTable, bounded);
324: }
325:
326: public boolean isSearchUsingOnlyPrimaryKeyValues() {
327: return getLookupableHelperService()
328: .isSearchUsingOnlyPrimaryKeyValues();
329: }
330:
331: public String getPrimaryKeyFieldLabels() {
332: return getLookupableHelperService().getPrimaryKeyFieldLabels();
333: }
334: }
|