001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.docsearch;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.HashSet;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Set;
026:
027: import org.apache.commons.lang.StringUtils;
028:
029: import edu.iu.uis.eden.EdenConstants;
030: import edu.iu.uis.eden.KEWServiceLocator;
031: import edu.iu.uis.eden.actionlist.DisplayParameters;
032: import edu.iu.uis.eden.doctype.DocumentType;
033: import edu.iu.uis.eden.doctype.DocumentTypeService;
034: import edu.iu.uis.eden.lookupable.Column;
035: import edu.iu.uis.eden.lookupable.Field;
036: import edu.iu.uis.eden.lookupable.Row;
037: import edu.iu.uis.eden.user.WorkflowUser;
038: import edu.iu.uis.eden.util.Utilities;
039: import edu.iu.uis.eden.web.KeyValueSort;
040: import edu.iu.uis.eden.web.UrlResolver;
041:
042: /**
043: *
044: * @author delyea
045: */
046: public class StandardDocumentSearchResultProcessor implements
047: DocumentSearchResultProcessor {
048: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
049: .getLogger(StandardDocumentSearchResultProcessor.class);
050:
051: private Map<String, Boolean> sortableByKey = new HashMap<String, Boolean>();
052: private Map<String, String> labelsByKey = new HashMap<String, String>();
053: private DocSearchCriteriaVO searchCriteria;
054: private WorkflowUser searchingUser;
055:
056: /**
057: * @return the searchCriteria
058: */
059: public DocSearchCriteriaVO getSearchCriteria() {
060: return searchCriteria;
061: }
062:
063: /**
064: * @param searchCriteria the searchCriteria to set
065: */
066: public void setSearchCriteria(DocSearchCriteriaVO searchCriteria) {
067: this .searchCriteria = searchCriteria;
068: }
069:
070: /**
071: * @return the searchingUser
072: */
073: public WorkflowUser getSearchingUser() {
074: return searchingUser;
075: }
076:
077: /**
078: * @param searchingUser the searchingUser to set
079: */
080: public void setSearchingUser(WorkflowUser searchingUser) {
081: this .searchingUser = searchingUser;
082: }
083:
084: public List<Column> getCustomDisplayColumns() {
085: return new ArrayList<Column>();
086: }
087:
088: private List<Column> getAndSetUpCustomDisplayColumns(
089: DocSearchCriteriaVO criteria) {
090: List<Column> columns = getCustomDisplayColumns();
091: for (Column column : columns) {
092: for (Field field : getFields(criteria)) {
093: if ((field.getSavablePropertyName().equals(column
094: .getKey()))
095: && (column.getDisplayParameters().isEmpty())) {
096: column.setDisplayParameters(field
097: .getDisplayParameters());
098: }
099: }
100: }
101: return columns;
102: }
103:
104: public boolean getShowAllStandardFields() {
105: return true;
106: }
107:
108: public boolean getOverrideSearchableAttributes() {
109: return false;
110: }
111:
112: /**
113: * Convenience method to find a specific searchable attribute
114: *
115: * @param name - name of search attribute savable property name
116: * @return the SearchAttributeCriteriaComponent object related to the given key name or null if component is not found
117: */
118: protected SearchAttributeCriteriaComponent getSearchableAttributeByFieldName(
119: String name) {
120: if (StringUtils.isBlank(name)) {
121: throw new IllegalArgumentException(
122: "Attempted to find Searchable Attribute with blank Field name '"
123: + name + "'");
124: }
125: for (Iterator iter = getSearchCriteria()
126: .getSearchableAttributes().iterator(); iter.hasNext();) {
127: SearchAttributeCriteriaComponent critComponent = (SearchAttributeCriteriaComponent) iter
128: .next();
129: if (name.equals(critComponent.getFormKey())) {
130: return critComponent;
131: }
132: }
133: return null;
134: }
135:
136: /* (non-Javadoc)
137: * @see edu.iu.uis.eden.docsearch.DocumentSearchResultProcessor#processIntoFinalResults(java.util.List, edu.iu.uis.eden.docsearch.DocSearchCriteriaVO, edu.iu.uis.eden.user.WorkflowUser)
138: */
139: public DocumentSearchResultComponents processIntoFinalResults(
140: List<DocSearchVO> docSearchResultRows,
141: DocSearchCriteriaVO criteria, WorkflowUser user) {
142: this .setSearchCriteria(criteria);
143: this .setSearchingUser(user);
144: List columns = constructColumnList(criteria);
145:
146: List<DocumentSearchResult> documentSearchResults = new ArrayList<DocumentSearchResult>();
147: for (Iterator iter = docSearchResultRows.iterator(); iter
148: .hasNext();) {
149: DocSearchVO docSearchVO = (DocSearchVO) iter.next();
150: DocumentSearchResult docSearchResult = this
151: .generateSearchResult(docSearchVO, columns);
152: if (docSearchResult != null) {
153: documentSearchResults.add(docSearchResult);
154: }
155: }
156: return new DocumentSearchResultComponents(columns,
157: documentSearchResults);
158: }
159:
160: /**
161: * Method to construct a list of columns in order of how they should appear in the search results
162: *
163: * @return a list of columns in an ordered list that will be used to generate the final search results
164: */
165: public List<Column> constructColumnList(DocSearchCriteriaVO criteria) {
166: List<Column> tempColumns = new ArrayList<Column>();
167: List<Column> customDisplayColumnNames = getAndSetUpCustomDisplayColumns(criteria);
168: // if (!customDisplayColumnNames.isEmpty()) {
169: if ((!getShowAllStandardFields())
170: && (getOverrideSearchableAttributes())) {
171: // use only what is contained in displayColumns
172: this .addAllCustomColumns(tempColumns, criteria,
173: customDisplayColumnNames);
174: } else if (getShowAllStandardFields()
175: && (getOverrideSearchableAttributes())) {
176: // do standard fields and use displayColumns for searchable attributes
177: this .addStandardSearchColumns(tempColumns);
178: // this.addCustomSearchAttributeColumns(tempColumns, criteria, customDisplayColumnNames);
179: this .addAllCustomColumns(tempColumns, criteria,
180: customDisplayColumnNames);
181: } else if ((!getShowAllStandardFields())
182: && (!getOverrideSearchableAttributes())) {
183: // do displayColumns and then do standard searchable attributes
184: this .addCustomStandardCriteriaColumns(tempColumns,
185: criteria, customDisplayColumnNames);
186: this .addSearchableAttributeColumnsNoOverrides(tempColumns,
187: criteria);
188: }
189: // }
190: if (tempColumns.isEmpty()) {
191: // do default
192: this .addStandardSearchColumns(tempColumns);
193: this .addSearchableAttributeColumnsNoOverrides(tempColumns,
194: criteria);
195: }
196:
197: List<Column> columns = new ArrayList<Column>();
198: this .addRouteHeaderIdColumn(columns);
199: columns.addAll(tempColumns);
200: this .addRouteLogColumn(columns);
201: return columns;
202: }
203:
204: public void addStandardSearchColumns(List<Column> columns) {
205: this .addColumnUsingKey(columns,
206: DocumentSearchResult.PROPERTY_NAME_DOC_TYPE_LABEL);
207: this .addColumnUsingKey(columns,
208: DocumentSearchResult.PROPERTY_NAME_DOCUMENT_TITLE);
209: this .addColumnUsingKey(columns,
210: DocumentSearchResult.PROPERTY_NAME_ROUTE_STATUS_DESC);
211: this .addColumnUsingKey(columns,
212: DocumentSearchResult.PROPERTY_NAME_INITIATOR);
213: this .addColumnUsingKey(columns,
214: DocumentSearchResult.PROPERTY_NAME_DATE_CREATED);
215: }
216:
217: public void addRouteHeaderIdColumn(List<Column> columns) {
218: this .addColumnUsingKey(columns,
219: DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID);
220: }
221:
222: public void addRouteLogColumn(List<Column> columns) {
223: this .addColumnUsingKey(columns,
224: DocumentSearchResult.PROPERTY_NAME_ROUTE_LOG);
225: }
226:
227: public void addSearchableAttributeColumnsNoOverrides(
228: List<Column> columns, DocSearchCriteriaVO criteria) {
229: this .addSearchableAttributeColumnsBasedOnFields(columns,
230: criteria, null);
231: // Set alreadyProcessedFieldKeys = new HashSet();
232: // List<Field> fields = this.getFields(criteria, null);
233: // for (Field field : fields) {
234: // if ( (field.getSavablePropertyName() == null) || (!alreadyProcessedFieldKeys.contains(field.getSavablePropertyName())) ) {
235: // if (field.isColumnVisible()) {
236: // for (Iterator iter = Field.SEARCH_RESULT_DISPLAYABLE_FIELD_TYPES.iterator(); iter.hasNext();) {
237: // String displayableFieldType = (String) iter.next();
238: // if (field.getFieldType().equals(displayableFieldType)) {
239: // String resultFieldLabel = field.getFieldLabel();
240: // if (field.isMemberOfRange()) {
241: // resultFieldLabel = field.getMainFieldLabel();
242: // }
243: // this.addSearchableAttributeColumnUsingKey(columns, field.getSavablePropertyName(), resultFieldLabel, getSortableByKey().get(field.getSavablePropertyName()), Boolean.TRUE);
244: // if (field.getSavablePropertyName() != null) {
245: // alreadyProcessedFieldKeys.add(field.getSavablePropertyName());
246: // }
247: // break;
248: // }
249: // }
250: // }
251: // }
252: // }
253: }
254:
255: protected void addSearchableAttributeColumnsBasedOnFields(
256: List<Column> columns, DocSearchCriteriaVO criteria,
257: List<String> searchAttributeFieldNames) {
258: Set alreadyProcessedFieldKeys = new HashSet();
259: List<Field> fields = this .getFields(criteria,
260: searchAttributeFieldNames);
261: for (Field field : fields) {
262: if ((field.getSavablePropertyName() == null)
263: || (!alreadyProcessedFieldKeys.contains(field
264: .getSavablePropertyName()))) {
265: if (field.isColumnVisible()) {
266: if (Field.SEARCH_RESULT_DISPLAYABLE_FIELD_TYPES
267: .contains(field.getFieldType())) {
268: String resultFieldLabel = field.getFieldLabel();
269: if (field.isMemberOfRange()) {
270: resultFieldLabel = field
271: .getMainFieldLabel();
272: }
273: this
274: .addSearchableAttributeColumnUsingKey(
275: columns,
276: field.getDisplayParameters(),
277: field.getSavablePropertyName(),
278: resultFieldLabel,
279: getSortableByKey()
280: .get(
281: field
282: .getSavablePropertyName()),
283: Boolean.TRUE);
284: if (field.getSavablePropertyName() != null) {
285: alreadyProcessedFieldKeys.add(field
286: .getSavablePropertyName());
287: }
288: }
289: // for (Iterator iter = Field.SEARCH_RESULT_DISPLAYABLE_FIELD_TYPES.iterator(); iter.hasNext();) {
290: // String displayableFieldType = (String) iter.next();
291: // if (field.getFieldType().equals(displayableFieldType)) {
292: // String resultFieldLabel = field.getFieldLabel();
293: // if (field.isMemberOfRange()) {
294: // resultFieldLabel = field.getMainFieldLabel();
295: // }
296: // this.addSearchableAttributeColumnUsingKey(columns, field.getDisplayParameters(), field.getSavablePropertyName(), resultFieldLabel, getSortableByKey().get(field.getSavablePropertyName()), Boolean.TRUE);
297: // if (field.getSavablePropertyName() != null) {
298: // alreadyProcessedFieldKeys.add(field.getSavablePropertyName());
299: // }
300: // break;
301: // }
302: // }
303: }
304: }
305: }
306: }
307:
308: protected void addSearchableAttributeColumnUsingField() {
309:
310: }
311:
312: public void addAllCustomColumns(List<Column> columns,
313: DocSearchCriteriaVO criteria,
314: List<Column> customDisplayColumns) {
315: for (Column customColumn : customDisplayColumns) {
316: this .addCustomColumn(columns, customColumn);
317: }
318: }
319:
320: public void addCustomStandardCriteriaColumns(List<Column> columns,
321: DocSearchCriteriaVO criteria,
322: List<Column> customDisplayColumns) {
323: for (Column customColumn : customDisplayColumns) {
324: if (DocumentSearchResult.PROPERTY_NAME_SET
325: .contains(customColumn.getKey())) {
326: this .addCustomColumn(columns, customColumn);
327: }
328: }
329: }
330:
331: // public void addCustomSearchAttributeColumns(List<Column> columns,DocSearchCriteriaVO criteria,List<Column> customDisplayColumns) {
332: // for (Column customColumn : customDisplayColumns) {
333: // if (!DocumentSearchResult.PROPERTY_NAME_SET.contains(customColumn.getKey())) {
334: // this.addCustomColumn(columns,customColumn);
335: // }
336: // }
337: // }
338:
339: public void addCustomColumn(List<Column> columns,
340: Column customColumn) {
341: Boolean sortable = null;
342: if ((customColumn.getSortable() != null)
343: && (Column.COLUMN_IS_SORTABLE_VALUE.equals(customColumn
344: .getSortable()))) {
345: sortable = Boolean.TRUE;
346: } else if ((customColumn.getSortable() != null)
347: && (Column.COLUMN_NOT_SORTABLE_VALUE
348: .equals(customColumn.getSortable()))) {
349: sortable = Boolean.FALSE;
350: }
351: addColumnUsingKey(columns, customColumn.getDisplayParameters(),
352: customColumn.getKey(), customColumn.getColumnTitle(),
353: sortable);
354: }
355:
356: private List<Field> getFields(DocSearchCriteriaVO criteria) {
357: return getFields(criteria, null);
358: }
359:
360: private List<Field> getFields(DocSearchCriteriaVO criteria,
361: List<String> searchAttributeFieldNames) {
362: List<Field> returnFields = new ArrayList<Field>();
363: DocumentType documentType = null;
364: if (StringUtils.isNotBlank(criteria.getDocTypeFullName())) {
365: documentType = ((DocumentTypeService) KEWServiceLocator
366: .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE))
367: .findByName(criteria.getDocTypeFullName());
368: }
369: if (documentType != null) {
370: List<Field> allFields = new ArrayList<Field>();
371: for (SearchableAttribute searchableAttribute : documentType
372: .getSearchableAttributes()) {
373: List<Row> searchRows = searchableAttribute
374: .getSearchingRows();
375: if (searchRows == null) {
376: continue;
377: }
378: for (Row row : searchRows) {
379: allFields.addAll(row.getFields());
380: }
381: }
382: if (searchAttributeFieldNames == null) {
383: returnFields = allFields;
384: } else {
385: for (String searchAttributeName : searchAttributeFieldNames) {
386: for (Field field : allFields) {
387: if (searchAttributeName.equals(field
388: .getSavablePropertyName())) {
389: returnFields.add(field);
390: }
391: }
392: }
393: }
394: }
395: return returnFields;
396: }
397:
398: public DocumentSearchResult generateSearchResult(
399: DocSearchVO docSearchVO, List columns) {
400: Map<String, Object> alternateSortValues = getSortValuesMap(docSearchVO);
401: DocumentSearchResult docSearchResult = null;
402: for (Iterator iterator = columns.iterator(); iterator.hasNext();) {
403: Column currentColumn = (Column) iterator.next();
404: KeyValueSort kvs = generateSearchResult(docSearchVO,
405: currentColumn, alternateSortValues);
406: if (kvs != null) {
407: if (docSearchResult == null) {
408: docSearchResult = new DocumentSearchResult();
409: }
410: docSearchResult.addResultContainer(kvs);
411: }
412: }
413: return docSearchResult;
414: }
415:
416: public KeyValueSort generateSearchResult(DocSearchVO docSearchVO,
417: Column column, Map<String, Object> sortValuesByColumnKey) {
418: KeyValueSort returnValue = null;
419: String fieldValue = null;
420: Object sortFieldValue = null;
421: String columnKeyName = column.getKey();
422: SearchableAttributeValue attributeValue = null;
423:
424: if (DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID
425: .equals(columnKeyName)) {
426: fieldValue = this .getRouteHeaderIdFieldDisplayValue(
427: docSearchVO.getRouteHeaderId().toString(),
428: docSearchVO.isUsingSuperUserSearch());
429: sortFieldValue = sortValuesByColumnKey.get(columnKeyName);
430: } else if (DocumentSearchResult.PROPERTY_NAME_ROUTE_LOG
431: .equals(columnKeyName)) {
432: fieldValue = this .getRouteLogFieldDisplayValue(docSearchVO
433: .getRouteHeaderId().toString());
434: sortFieldValue = sortValuesByColumnKey.get(columnKeyName);
435: } else if (DocumentSearchResult.PROPERTY_NAME_DATE_CREATED
436: .equals(columnKeyName)) {
437: fieldValue = DocSearchUtils
438: .getDisplayValueWithDateTime(docSearchVO
439: .getDateCreated());
440: sortFieldValue = sortValuesByColumnKey.get(columnKeyName);
441: } else if (DocumentSearchResult.PROPERTY_NAME_DOC_TYPE_LABEL
442: .equals(columnKeyName)) {
443: fieldValue = docSearchVO.getDocTypeLabel();
444: sortFieldValue = sortValuesByColumnKey.get(columnKeyName);
445: } else if (DocumentSearchResult.PROPERTY_NAME_DOCUMENT_TITLE
446: .equals(columnKeyName)) {
447: fieldValue = docSearchVO.getDocumentTitle();
448: sortFieldValue = sortValuesByColumnKey.get(columnKeyName);
449: } else if (DocumentSearchResult.PROPERTY_NAME_INITIATOR
450: .equals(columnKeyName)) {
451: fieldValue = this .getInitiatorFieldDisplayValue(docSearchVO
452: .getInitiatorTransposedName(), docSearchVO
453: .getInitiatorWorkflowId());
454: sortFieldValue = sortValuesByColumnKey.get(columnKeyName);
455: } else if (DocumentSearchResult.PROPERTY_NAME_ROUTE_STATUS_DESC
456: .equals(columnKeyName)) {
457: fieldValue = docSearchVO.getDocRouteStatusCodeDesc();
458: sortFieldValue = sortValuesByColumnKey.get(columnKeyName);
459: } else {
460: // check searchable attributes
461: for (Iterator iter = docSearchVO.getSearchableAttributes()
462: .iterator(); iter.hasNext();) {
463: KeyValueSort searchAttribute = (KeyValueSort) iter
464: .next();
465: if (searchAttribute.getKey().equals(columnKeyName)) {
466: Object sortValue = sortValuesByColumnKey
467: .get(columnKeyName);
468: sortFieldValue = (sortValue != null) ? sortValue
469: : searchAttribute.getSortValue();
470: attributeValue = searchAttribute
471: .getSearchableAttributeValue();
472: if ((column.getDisplayParameters() != null)
473: && (!column.getDisplayParameters()
474: .isEmpty())) {
475: fieldValue = searchAttribute
476: .getSearchableAttributeValue()
477: .getSearchableAttributeDisplayValue(
478: column.getDisplayParameters());
479: } else {
480: fieldValue = searchAttribute.getValue();
481: }
482: break;
483: }
484: }
485: }
486: if (fieldValue != null) {
487: returnValue = new KeyValueSort(columnKeyName, fieldValue,
488: (sortFieldValue != null) ? sortFieldValue
489: : fieldValue, attributeValue);
490: }
491: return returnValue;
492: }
493:
494: /*
495: * Convenience Methods to get field values for certain Workflow Standard
496: * Search Result columns
497: */
498:
499: protected String getRouteLogFieldDisplayValue(String routeHeaderId) {
500: String linkPopup = "";
501: if (this .isRouteLogPopup()) {
502: linkPopup = " target=\"_new\"";
503: }
504: return "<a href=\"RouteLog.do?routeHeaderId="
505: + routeHeaderId
506: + "\""
507: + linkPopup
508: + "><img alt=\"Route Log for Document\" src=\"images/my_route_log.gif\"/></a>";
509: }
510:
511: protected String getRouteHeaderIdFieldDisplayValue(
512: String routeHeaderId, boolean isSuperUserSearch) {
513: return this .getValueEncodedWithDocHandlerUrl(routeHeaderId,
514: routeHeaderId, isSuperUserSearch);
515: }
516:
517: protected String getInitiatorFieldDisplayValue(
518: String fieldLinkTextValue, String initiatorWorkflowId) {
519: UrlResolver urlResolver = new UrlResolver();
520: return "<a href=\"" + urlResolver.getUserReportUrl()
521: + "?showEdit=no&methodToCall=report&workflowId="
522: + initiatorWorkflowId + "\" target=\"_blank\">"
523: + fieldLinkTextValue + "</a>";
524: }
525:
526: /**
527: * Convenience method to allow child classes to use a custom value string and wrap
528: * that string in the document handler URL
529: *
530: * @param value - the value that will show on screen as the clickable link
531: * @param routeHeaderId - the string value of the route header id the doc handler should point to
532: * @param isSuperUserSearch - boolean indicating whether this search is a super user search or not
533: * see {@link edu.iu.uis.eden.docsearch.DocSearchVO#isUsingSuperUserSearch()}
534: * @return the fully encoded html for a link using the text from the input parameter 'value'
535: */
536: protected String getValueEncodedWithDocHandlerUrl(String value,
537: String routeHeaderId, boolean isSuperUserSearch) {
538: return getDocHandlerUrlPrefix(routeHeaderId, isSuperUserSearch)
539: + value + getDocHandlerUrlSuffix(isSuperUserSearch);
540: }
541:
542: private Map<String, Object> getSortValuesMap(DocSearchVO docSearchVO) {
543: Map<String, Object> alternateSort = new HashMap<String, Object>();
544: alternateSort.put(
545: DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID,
546: docSearchVO.getRouteHeaderId());
547: alternateSort.put(DocumentSearchResult.PROPERTY_NAME_INITIATOR,
548: docSearchVO.getInitiatorTransposedName());
549: alternateSort.put(
550: DocumentSearchResult.PROPERTY_NAME_DATE_CREATED,
551: docSearchVO.getDateCreated());
552: return alternateSort;
553: }
554:
555: public Map<String, Boolean> getSortableByKey() {
556: if (sortableByKey.isEmpty()) {
557: sortableByKey = constructSortableByKey();
558: }
559: return sortableByKey;
560: }
561:
562: protected Map<String, Boolean> constructSortableColumnByKey() {
563: Map<String, Boolean> sortable = new HashMap<String, Boolean>();
564: sortable.put(
565: DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID,
566: Boolean.TRUE);
567: sortable.put(DocumentSearchResult.PROPERTY_NAME_DOC_TYPE_LABEL,
568: Boolean.TRUE);
569: sortable.put(DocumentSearchResult.PROPERTY_NAME_DOCUMENT_TITLE,
570: Boolean.TRUE);
571: sortable.put(
572: DocumentSearchResult.PROPERTY_NAME_ROUTE_STATUS_DESC,
573: Boolean.TRUE);
574: sortable.put(DocumentSearchResult.PROPERTY_NAME_INITIATOR,
575: Boolean.TRUE);
576: sortable.put(DocumentSearchResult.PROPERTY_NAME_DATE_CREATED,
577: Boolean.TRUE);
578: sortable.put(DocumentSearchResult.PROPERTY_NAME_ROUTE_LOG,
579: Boolean.FALSE);
580: return sortable;
581: }
582:
583: public Map<String, Boolean> getSortableColumnByKey() {
584: if (sortableByKey.isEmpty()) {
585: sortableByKey = constructSortableByKey();
586: }
587: return sortableByKey;
588: }
589:
590: protected Map<String, Boolean> constructSortableByKey() {
591: Map<String, Boolean> sortable = new HashMap<String, Boolean>();
592: sortable.put(
593: DocumentSearchResult.PROPERTY_NAME_ROUTE_HEADER_ID,
594: Boolean.TRUE);
595: sortable.put(DocumentSearchResult.PROPERTY_NAME_DOC_TYPE_LABEL,
596: Boolean.TRUE);
597: sortable.put(DocumentSearchResult.PROPERTY_NAME_DOCUMENT_TITLE,
598: Boolean.TRUE);
599: sortable.put(
600: DocumentSearchResult.PROPERTY_NAME_ROUTE_STATUS_DESC,
601: Boolean.TRUE);
602: sortable.put(DocumentSearchResult.PROPERTY_NAME_INITIATOR,
603: Boolean.TRUE);
604: sortable.put(DocumentSearchResult.PROPERTY_NAME_DATE_CREATED,
605: Boolean.TRUE);
606: sortable.put(DocumentSearchResult.PROPERTY_NAME_ROUTE_LOG,
607: Boolean.FALSE);
608: return sortable;
609: }
610:
611: public Map<String, String> getLabelsByKey() {
612: if (labelsByKey.isEmpty()) {
613: labelsByKey = constructLabelsByKey();
614: }
615: return labelsByKey;
616: }
617:
618: protected Map<String, String> constructLabelsByKey() {
619: return new HashMap<String, String>();
620: }
621:
622: /*
623: * Below columns are for convenience for overriding classes
624: *
625: */
626:
627: protected void addColumnUsingKey(List<Column> columns, String key) {
628: this .addColumnUsingKey(columns, new HashMap<String, String>(),
629: key, null, null);
630: }
631:
632: protected void addColumnUsingKey(List<Column> columns,
633: Map<String, String> displayParameters, String key,
634: String label) {
635: this .addColumnUsingKey(columns, displayParameters, key, label,
636: null);
637: }
638:
639: protected void addColumnUsingKey(List<Column> columns,
640: Map<String, String> displayParameters, String key,
641: Boolean sortable) {
642: this .addColumnUsingKey(columns, displayParameters, key, null,
643: sortable);
644: }
645:
646: protected void addColumnUsingKey(List<Column> columns,
647: Map<String, String> displayParameters, String key,
648: String label, Boolean sortable) {
649: columns.add(this .constructColumnUsingKey(displayParameters,
650: key, label, sortable));
651: }
652:
653: protected void addSearchableAttributeColumnUsingKey(
654: List<Column> columns, String key, String label,
655: Boolean sortableOverride, Boolean defaultSortable) {
656: addSearchableAttributeColumnUsingKey(columns,
657: new HashMap<String, String>(), key, label,
658: sortableOverride, defaultSortable);
659: }
660:
661: protected void addSearchableAttributeColumnUsingKey(
662: List<Column> columns,
663: Map<String, String> displayParameters, String key,
664: String label, Boolean sortableOverride,
665: Boolean defaultSortable) {
666: columns.add(this .constructColumnUsingKey(displayParameters,
667: key, label,
668: (sortableOverride != null) ? sortableOverride
669: : defaultSortable));
670: }
671:
672: /*
673: * Below methods should probably not be overriden by overriding classes but could be if desired
674: */
675: protected Column constructColumnUsingKey(
676: Map<String, String> displayParameters, String key,
677: String label, Boolean sortable) {
678: if (sortable == null) {
679: sortable = getSortableByKey().get(key);
680: }
681: if (label == null) {
682: label = getLabelsByKey().get(key);
683: }
684: Column c = new Column(label, ((sortable != null) && (sortable
685: .booleanValue())) ? Column.COLUMN_IS_SORTABLE_VALUE
686: : Column.COLUMN_NOT_SORTABLE_VALUE, "resultContainer("
687: + key + ").value", "resultContainer(" + key
688: + ").sortValue", key, displayParameters);
689: return c;
690: }
691:
692: private boolean isDocumentHandlerPopup() {
693: String applicationConstant = Utilities.getApplicationConstant(
694: EdenConstants.DOCUMENT_SEARCH_DOCUMENT_POPUP_KEY)
695: .trim();
696: return (EdenConstants.DOCUMENT_SEARCH_DOCUMENT_POPUP_VALUE
697: .equals(applicationConstant));
698: }
699:
700: private boolean isRouteLogPopup() {
701: String applicationConstant = Utilities.getApplicationConstant(
702: EdenConstants.DOCUMENT_SEARCH_ROUTE_LOG_POPUP_KEY)
703: .trim();
704: return (EdenConstants.DOCUMENT_SEARCH_ROUTE_LOG_POPUP_VALUE
705: .equals(applicationConstant));
706: }
707:
708: private String getDocHandlerUrlPrefix(String routeHeaderId,
709: boolean super UserSearch) {
710: String linkPopup = "";
711: if (this .isDocumentHandlerPopup()) {
712: linkPopup = " target=\"_blank\"";
713: }
714: if (super UserSearch) {
715: return "<a href=\"SuperUser.do?methodToCall=displaySuperUserDocument&routeHeaderId="
716: + routeHeaderId + "\"" + linkPopup + " >";
717: } else {
718: return "<a href=\""
719: + EdenConstants.DOC_HANDLER_REDIRECT_PAGE
720: + "?command=displayDocSearchView&docId="
721: + routeHeaderId + "\"" + linkPopup + ">";
722: }
723: }
724:
725: private String getDocHandlerUrlSuffix(boolean super UserSearch) {
726: if (super UserSearch) {
727: return "</a>";
728: } else {
729: return "</a>";
730: }
731: }
732: }
|