001/** 002 * Copyright 2005-2017 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */ 016package org.kuali.rice.kew.doctype; 017 018import java.util.ArrayList; 019import java.util.Collection; 020import java.util.Collections; 021import java.util.List; 022import java.util.Map; 023 024import org.apache.commons.lang.StringUtils; 025import org.kuali.rice.kew.api.KEWPropertyConstants; 026import org.kuali.rice.kew.doctype.bo.DocumentType; 027import org.kuali.rice.kew.service.KEWServiceLocator; 028import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; 029import org.kuali.rice.krad.bo.BusinessObject; 030import org.kuali.rice.krad.util.BeanPropertyComparator; 031import org.kuali.rice.krad.util.KRADConstants; 032 033/** 034 * This is a description of what this class does - chb don't forget to fill this in. 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 * 038 */ 039public class DocumentTypeLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl 040{ 041 042 private static final long serialVersionUID = -5162632536083995637L; 043 044 /** 045 * This overridden method ... 046 * 047 * @see org.kuali.rice.krad.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean) 048 */ 049 @Override 050 protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) 051 { 052 setBackLocation(fieldValues.get(KRADConstants.BACK_LOCATION)); 053 setDocFormKey(fieldValues.get(KRADConstants.DOC_FORM_KEY)); 054 setReferencesToRefresh(fieldValues.get(KRADConstants.REFERENCES_TO_REFRESH)); 055 056 DocumentType documentType = loadDocumentTypeForSearch(fieldValues); 057 058 String descendHierarchyValue = fieldValues.get("descendHierarchy"); 059 boolean descend = false; 060 061 if( "Y".equals(descendHierarchyValue) || "Yes".equals(descendHierarchyValue)) 062 { 063 descend = true; 064 } 065 066 Collection docTypesFound = 067 KEWServiceLocator.getDocumentTypeService().find(documentType, fieldValues.get("parentDocType.name"), descend); 068 069 List<? extends BusinessObject> searchResults = 070 new ArrayList<BusinessObject>( (Collection<? extends BusinessObject>)docTypesFound ); 071 072 // sort list if default sort column given 073 List defaultSortColumns = getDefaultSortColumns(); 074 if (defaultSortColumns.size() > 0) { 075 Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true)); 076 } 077 return searchResults; 078 } 079 080 protected DocumentType loadDocumentTypeForSearch(Map<String, String> fieldValues) { 081 DocumentType documentType = new DocumentType(); 082 083 String activeIndicator = (String) fieldValues.get(KEWPropertyConstants.ACTIVE); 084 String docTypeLabel = (String) fieldValues.get(KEWPropertyConstants.DOC_TYP_LABEL); 085 String documentTypeId = (String) fieldValues.get(KEWPropertyConstants.DOCUMENT_TYPE_ID); 086 String docTypeName = (String) fieldValues.get(KEWPropertyConstants.NAME); 087 String applicationId = (String) fieldValues.get(KEWPropertyConstants.APPLICATION_ID); 088 089 if ("Y".equals(activeIndicator)) { 090 documentType.setActive(Boolean.TRUE); 091 } else if ("N".equals(activeIndicator)) { 092 documentType.setActive(Boolean.FALSE); 093 } else { 094 documentType.setActive(null); 095 } 096 097 if (docTypeLabel != null && !"".equals(docTypeLabel.trim())) { 098 docTypeLabel = docTypeLabel.replace('*', '%'); 099 documentType.setLabel("%" + docTypeLabel.trim() + "%"); 100 } 101 if (docTypeName != null && !"".equals(docTypeName.trim())) { 102 documentType.setName(docTypeName.trim()); 103 } 104 105 if (documentTypeId != null && !"".equals(documentTypeId.trim())) { 106 documentType.setDocumentTypeId(documentTypeId.trim()); 107 } 108 if (!StringUtils.isBlank(applicationId)) { 109 documentType.setActualApplicationId(applicationId); 110 } 111 112 return documentType; 113 } 114}