Coverage Report - org.kuali.rice.kew.doctype.DocumentTypeLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTypeLookupableHelperServiceImpl
0%
0/39
0%
0/24
7.5
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * This is a description of what this class does - chb don't forget to fill this in.
 31  
  *
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  *
 34  
  */
 35  0
 public class DocumentTypeLookupableHelperServiceImpl extends
 36  
                 KualiLookupableHelperServiceImpl
 37  
 {
 38  
 
 39  
     private static final long serialVersionUID = -5162632536083995637L;
 40  
 
 41  
     /**
 42  
          * This overridden method ...
 43  
          *
 44  
          * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean)
 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  
         // sort list if default sort column given
 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  
 }