Coverage Report - org.kuali.rice.kew.service.impl.KEWModuleService
 
Classes in this File Line Coverage Branch Coverage Complexity
KEWModuleService
0%
0/49
0%
0/36
2.562
KEWModuleService$1
0%
0/10
N/A
2.562
 
 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.service.impl;
 17  
 
 18  
 import org.kuali.rice.kew.docsearch.DocumentRouteHeaderEBO;
 19  
 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
 20  
 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
 21  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 22  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 23  
 import org.kuali.rice.kns.bo.ExternalizableBusinessObject;
 24  
 import org.kuali.rice.kns.service.impl.ModuleServiceBase;
 25  
 
 26  
 import java.sql.Timestamp;
 27  
 import java.util.ArrayList;
 28  
 import java.util.List;
 29  
 import java.util.Map;
 30  
 
 31  
 /**
 32  
  * The ModuleService for KEW
 33  
  *
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  0
 public class KEWModuleService extends ModuleServiceBase {
 38  
 
 39  0
         protected DocumentTypeService docTypeService = null;
 40  
 
 41  
         /**
 42  
          * These are the "primary" keys for the DocTypeService. We are considering both
 43  
          * name and documentTypeId to be unique.
 44  
          *
 45  
          * @see org.kuali.rice.kns.service.impl.ModuleServiceBase#listPrimaryKeyFieldNames(java.lang.Class)
 46  
          */
 47  
         @Override
 48  
         public List<String> listPrimaryKeyFieldNames(Class businessObjectInterfaceClass) {
 49  0
                 if ( DocumentTypeEBO.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
 50  0
                         List<String> pkFields = new ArrayList<String>( 1 );
 51  0
                         pkFields.add( "documentTypeId" );
 52  0
                         return pkFields;
 53  0
                 }else if(DocumentRouteHeaderEBO.class.isAssignableFrom( businessObjectInterfaceClass )){
 54  0
                         List<String> pkFields = new ArrayList<String>( 1 );
 55  0
                         pkFields.add( "documentId" );
 56  0
                         return pkFields;
 57  
                 }
 58  0
                 return super.listPrimaryKeyFieldNames(businessObjectInterfaceClass);
 59  
         }
 60  
 
 61  
         /**
 62  
          * This overridden method calls the DocumentTypeService instead of the underlying
 63  
          * KNS service.  Allows you to search on name and docTypeId
 64  
          *
 65  
          * @see org.kuali.rice.kns.service.impl.ModuleServiceBase#getExternalizableBusinessObject(java.lang.Class, java.util.Map)
 66  
          */
 67  
         @Override
 68  
         public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(
 69  
                         Class<T> businessObjectClass, Map<String, Object> fieldValues) {
 70  0
                 if(DocumentTypeEBO.class.isAssignableFrom(businessObjectClass)){
 71  0
                         if ( fieldValues.containsKey( "name" ) ) {
 72  0
                                 return (T)getDocumentTypeService().findByName((String)fieldValues.get( "name" ) );
 73  0
                         }else if( fieldValues.containsKey( "documentTypeId" ) ){
 74  0
                                 return (T)getDocumentTypeService().findById(Long.valueOf(fieldValues.get( "documentTypeId" ).toString()));
 75  0
                         }else if (fieldValues.containsKey( "id" ) ) {
 76  
                                 // assume it's a string and convert it to a long.
 77  0
                                 return (T)getDocumentTypeService().findById(Long.valueOf(fieldValues.get( "id" ).toString()));
 78  
                         }
 79  
 
 80  0
                 }else if(DocumentRouteHeaderEBO.class.isAssignableFrom( businessObjectClass )){
 81  0
                         if ( fieldValues.containsKey( "documentId" ) ) {
 82  0
                                 return (T)createDocSearchCriteriaEBO(KEWServiceLocator.getRouteHeaderService().getRouteHeader(fieldValues.get( "documentId" ).toString()));
 83  
                         }
 84  
 
 85  
                 }
 86  
 
 87  
                 // otherwise, use the default implementation
 88  0
                 return super.getExternalizableBusinessObject(businessObjectClass, fieldValues);
 89  
         }
 90  
 
 91  
         /**
 92  
          * @return the docTypeService
 93  
          */
 94  
         protected DocumentTypeService getDocumentTypeService() {
 95  0
                 if(this.docTypeService == null){
 96  
                         // the default
 97  0
                         this.docTypeService = KEWServiceLocator.getDocumentTypeService();
 98  
                 }
 99  0
                 return this.docTypeService;
 100  
         }
 101  
 
 102  
         /**
 103  
          * @param docTypeService the docTypeService to set
 104  
          */
 105  
         public void setDocumentTypeService(DocumentTypeService docTypeService) {
 106  0
                 this.docTypeService = docTypeService;
 107  0
         }
 108  
 
 109  
         private DocumentRouteHeaderEBO createDocSearchCriteriaEBO(final DocumentRouteHeaderValue routeHeaderValue){
 110  0
                 return new DocumentRouteHeaderEBO(){
 111  
 
 112  
                         public String getAppDocId() {
 113  0
                                 return routeHeaderValue.getAppDocId();
 114  
                         }
 115  
 
 116  
                         public Timestamp getDateCreated() {
 117  0
                                 return routeHeaderValue.getCreateDate();
 118  
                         }
 119  
 
 120  
                         public String getDocRouteStatus() {
 121  
 
 122  0
                                 return routeHeaderValue.getDocRouteStatus();
 123  
                         }
 124  
 
 125  
                         public String getAppDocStatus() {
 126  
 
 127  0
                                 return routeHeaderValue.getAppDocStatus();
 128  
                         }
 129  
 
 130  
                         public String getDocTitle() {
 131  0
                                 return routeHeaderValue.getDocTitle();
 132  
                         }
 133  
 
 134  
                         public String getDocTypeFullName() {
 135  0
                                 return routeHeaderValue.getDocumentType().getName();
 136  
                         }
 137  
 
 138  
                         public String getInitiator() {
 139  0
                                 return routeHeaderValue.getInitiatorPrincipal().getPrincipalName();
 140  
                         }
 141  
 
 142  
                         public String getDocumentId() {
 143  
 
 144  0
                                 return routeHeaderValue.getDocumentId();
 145  
                         }
 146  
 
 147  
                         public void refresh() {
 148  
                                 // do nothing
 149  
 
 150  0
                         }
 151  
 
 152  
                 };
 153  
         }
 154  
         /**
 155  
          * This overridden method rewrites the URL.
 156  
          *
 157  
          * @see org.kuali.rice.kns.service.impl.ModuleServiceBase#getExternalizableBusinessObjectInquiryUrl(java.lang.Class, java.util.Map)
 158  
          */
 159  
         @Override
 160  
         public String getExternalizableBusinessObjectInquiryUrl(
 161  
                         Class inquiryBusinessObjectClass, Map<String, String[]> parameters) {
 162  0
                 if ( DocumentTypeEBO.class.isAssignableFrom( inquiryBusinessObjectClass ) ) {
 163  0
                         int nonBlank = 0;
 164  0
                         boolean nameFound = false;
 165  
                         //"name" is the only non-blank property passed in
 166  0
                         for(String key: parameters.keySet()){
 167  0
                                 if("name".equals(key) && parameters.get(key) != null){
 168  0
                                         nameFound=true;
 169  0
                                 }else if(!"name".equals(key) && parameters.get(key) != null){
 170  0
                                         nonBlank ++;
 171  
                                 }
 172  
                         }
 173  
 
 174  0
                         if(nonBlank == 0 && nameFound == true){
 175  0
                                 parameters.clear(); // clear out other parameters, including the name pass in
 176  0
                                 DocumentTypeEBO dte = (DocumentTypeEBO)getDocumentTypeService().findByName(parameters.get( "name" )[0] );
 177  0
                                 String[] strArr = {dte.getDocumentTypeId().toString()};
 178  0
                                 parameters.put("documentTypeId", strArr);
 179  
                         }
 180  
 
 181  
                 }
 182  
 
 183  0
                 return super.getExternalizableBusinessObjectInquiryUrl(
 184  
                                 inquiryBusinessObjectClass, parameters);
 185  
         }
 186  
         /**
 187  
          * We want to be able to use name as an alternate key
 188  
          *
 189  
          * @see org.kuali.rice.kns.service.ModuleService#listAlternatePrimaryKeyFieldNames(java.lang.Class)
 190  
          */
 191  
         public List<List<String>> listAlternatePrimaryKeyFieldNames(
 192  
                         Class businessObjectInterfaceClass) {
 193  0
                 if ( DocumentTypeEBO.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
 194  0
                         ArrayList<List<String>> retList = new ArrayList<List<String>>();
 195  0
                         ArrayList<String> keyList = new ArrayList<String>();
 196  
 
 197  0
                         keyList.add("name");
 198  0
                         retList.add(keyList);
 199  0
                         return retList;
 200  
                 }else{
 201  0
                         return null;
 202  
                 }
 203  
 
 204  
         }
 205  
 }
 206