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