1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.doctype; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.Collections; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.apache.commons.lang.StringUtils; |
25 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
26 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
27 | |
import org.kuali.rice.kew.util.KEWPropertyConstants; |
28 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
29 | |
import org.kuali.rice.krad.bo.BusinessObject; |
30 | |
import org.kuali.rice.krad.util.BeanPropertyComparator; |
31 | |
import org.kuali.rice.krad.util.KRADConstants; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class DocumentTypeLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl |
40 | |
{ |
41 | |
|
42 | |
private static final long serialVersionUID = -5162632536083995637L; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@Override |
50 | |
protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) |
51 | |
{ |
52 | 0 | setBackLocation(fieldValues.get(KRADConstants.BACK_LOCATION)); |
53 | 0 | setDocFormKey(fieldValues.get(KRADConstants.DOC_FORM_KEY)); |
54 | 0 | setReferencesToRefresh(fieldValues.get(KRADConstants.REFERENCES_TO_REFRESH)); |
55 | |
|
56 | 0 | DocumentType documentType = loadDocumentTypeForSearch(fieldValues); |
57 | |
|
58 | 0 | String descendHierarchyValue = fieldValues.get("descendHierarchy"); |
59 | 0 | boolean descend = false; |
60 | |
|
61 | 0 | if( "Y".equals(descendHierarchyValue) || "Yes".equals(descendHierarchyValue)) |
62 | |
{ |
63 | 0 | descend = true; |
64 | |
} |
65 | |
|
66 | 0 | Collection docTypesFound = |
67 | |
KEWServiceLocator.getDocumentTypeService().find(documentType, fieldValues.get("parentDocType.name"), descend); |
68 | |
|
69 | 0 | List<? extends BusinessObject> searchResults = |
70 | |
new ArrayList<BusinessObject>( (Collection<? extends BusinessObject>)docTypesFound ); |
71 | |
|
72 | |
|
73 | 0 | List defaultSortColumns = getDefaultSortColumns(); |
74 | 0 | if (defaultSortColumns.size() > 0) { |
75 | 0 | Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true)); |
76 | |
} |
77 | 0 | return searchResults; |
78 | |
} |
79 | |
|
80 | |
protected DocumentType loadDocumentTypeForSearch(Map<String, String> fieldValues) { |
81 | 0 | DocumentType documentType = new DocumentType(); |
82 | |
|
83 | 0 | String activeIndicator = (String) fieldValues.get(KEWPropertyConstants.ACTIVE); |
84 | 0 | String docTypeLabel = (String) fieldValues.get(KEWPropertyConstants.DOC_TYP_LABEL); |
85 | 0 | String documentTypeId = (String) fieldValues.get(KEWPropertyConstants.DOCUMENT_TYPE_ID); |
86 | 0 | String docTypeName = (String) fieldValues.get(KEWPropertyConstants.NAME); |
87 | 0 | String applicationId = (String) fieldValues.get(KEWPropertyConstants.APPLICATION_ID); |
88 | |
|
89 | 0 | if ("Y".equals(activeIndicator)) { |
90 | 0 | documentType.setActive(Boolean.TRUE); |
91 | 0 | } else if ("N".equals(activeIndicator)) { |
92 | 0 | documentType.setActive(Boolean.FALSE); |
93 | |
} else { |
94 | 0 | documentType.setActive(null); |
95 | |
} |
96 | |
|
97 | 0 | if (docTypeLabel != null && !"".equals(docTypeLabel.trim())) { |
98 | 0 | docTypeLabel = docTypeLabel.replace('*', '%'); |
99 | 0 | documentType.setLabel("%" + docTypeLabel.trim() + "%"); |
100 | |
} |
101 | 0 | if (docTypeName != null && !"".equals(docTypeName.trim())) { |
102 | 0 | documentType.setName(docTypeName.trim()); |
103 | |
} |
104 | |
|
105 | 0 | if (documentTypeId != null && !"".equals(documentTypeId.trim())) { |
106 | 0 | documentType.setDocumentTypeId(documentTypeId.trim()); |
107 | |
} |
108 | 0 | if (!StringUtils.isBlank(applicationId)) { |
109 | 0 | documentType.setActualApplicationId(applicationId); |
110 | |
} |
111 | |
|
112 | 0 | return documentType; |
113 | |
} |
114 | |
} |