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