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 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.bo.BusinessObject;
 29  
 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
 30  
 import org.kuali.rice.kns.util.BeanPropertyComparator;
 31  
 import org.kuali.rice.kns.util.KNSConstants;
 32  
 
 33  
 /**
 34  
  * This is a description of what this class does - chb don't forget to fill this in.
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  *
 38  
  */
 39  0
 public class DocumentTypeLookupableHelperServiceImpl extends
 40  
                 KualiLookupableHelperServiceImpl
 41  
 {
 42  
 
 43  
     private static final long serialVersionUID = -5162632536083995637L;
 44  
 
 45  
     /**
 46  
          * This overridden method ...
 47  
          *
 48  
          * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean)
 49  
          */
 50  
         @Override
 51  
         protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded)
 52  
         {
 53  0
         setBackLocation(fieldValues.get(KNSConstants.BACK_LOCATION));
 54  0
         setDocFormKey(fieldValues.get(KNSConstants.DOC_FORM_KEY));
 55  0
         setReferencesToRefresh(fieldValues.get(KNSConstants.REFERENCES_TO_REFRESH));
 56  
 
 57  0
         DocumentType documentType = loadDocumentTypeForSearch(fieldValues);
 58  
 
 59  0
         String descendHierarchyValue = fieldValues.get("descendHierarchy");
 60  0
         boolean descend = false;
 61  
 
 62  0
         if( "Y".equals(descendHierarchyValue) || "Yes".equals(descendHierarchyValue))
 63  
                 {
 64  0
                 descend = true;
 65  
                 }
 66  
 
 67  0
         Collection docTypesFound =
 68  
                 KEWServiceLocator.getDocumentTypeService().find(documentType, fieldValues.get("parentDocType.name"), descend);
 69  
 
 70  0
         List<? extends BusinessObject> searchResults =
 71  
                 new ArrayList<BusinessObject>( (Collection<? extends BusinessObject>)docTypesFound );
 72  
 
 73  
         // sort list if default sort column given
 74  0
         List defaultSortColumns = getDefaultSortColumns();
 75  0
         if (defaultSortColumns.size() > 0) {
 76  0
             Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true));
 77  
         }
 78  0
         return searchResults;
 79  
     }
 80  
 
 81  
         protected DocumentType loadDocumentTypeForSearch(Map<String, String> fieldValues) {
 82  0
         DocumentType documentType = new DocumentType();
 83  
 
 84  0
         String activeIndicator = (String) fieldValues.get(KEWPropertyConstants.ACTIVE);
 85  0
         String docTypeLabel = (String) fieldValues.get(KEWPropertyConstants.DOC_TYP_LABEL);
 86  0
         String documentTypeId = (String) fieldValues.get(KEWPropertyConstants.DOCUMENT_TYPE_ID);
 87  0
         String docTypeName = (String) fieldValues.get(KEWPropertyConstants.NAME);
 88  0
         String applicationId = (String) fieldValues.get(KEWPropertyConstants.APPLICATION_ID);
 89  
 
 90  0
         if ("Y".equals(activeIndicator)) {
 91  0
             documentType.setActive(Boolean.TRUE);
 92  0
         } else if ("N".equals(activeIndicator)) {
 93  0
             documentType.setActive(Boolean.FALSE);
 94  
         } else {
 95  0
             documentType.setActive(null);
 96  
         }
 97  
 
 98  0
         if (docTypeLabel != null && !"".equals(docTypeLabel.trim())) {
 99  0
             docTypeLabel = docTypeLabel.replace('*', '%');
 100  0
             documentType.setLabel("%" + docTypeLabel.trim() + "%");
 101  
         }
 102  0
         if (docTypeName != null && !"".equals(docTypeName.trim())) {
 103  0
             documentType.setName(docTypeName.trim());
 104  
         }
 105  
 
 106  0
         if (documentTypeId != null && !"".equals(documentTypeId.trim())) {
 107  
             try {
 108  0
                 documentType.setDocumentTypeId(new Long(documentTypeId.trim()));
 109  0
             } catch (NumberFormatException e) {
 110  0
                 documentType.setDocumentTypeId(new Long(-1));
 111  0
             }
 112  
         }
 113  0
         if (!StringUtils.isBlank(applicationId)) {
 114  0
             documentType.setActualApplicationId(applicationId);
 115  
         }
 116  
 
 117  0
         return documentType;
 118  
     }
 119  
 }