Coverage Report - org.kuali.rice.kns.service.impl.DocumentHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentHelperServiceImpl
0%
0/64
0%
0/34
6.167
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.kns.service.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kns.datadictionary.DataDictionary;
 20  
 import org.kuali.rice.kns.datadictionary.DocumentEntry;
 21  
 import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry;
 22  
 import org.kuali.rice.kns.datadictionary.TransactionalDocumentEntry;
 23  
 import org.kuali.rice.kns.document.Document;
 24  
 import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
 25  
 import org.kuali.rice.kns.document.authorization.DocumentAuthorizerBase;
 26  
 import org.kuali.rice.kns.document.authorization.DocumentPresentationController;
 27  
 import org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase;
 28  
 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizerBase;
 29  
 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase;
 30  
 import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizerBase;
 31  
 import org.kuali.rice.kns.document.authorization.TransactionalDocumentPresentationControllerBase;
 32  
 import org.kuali.rice.kns.service.DataDictionaryService;
 33  
 import org.kuali.rice.kns.service.DocumentHelperService;
 34  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 35  
 
 36  
 /**
 37  
  * This class is a utility service intended to help retrieve objects related to particular documents.
 38  
  * 
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  */
 42  0
 public class DocumentHelperServiceImpl implements DocumentHelperService {
 43  
     
 44  
     private DataDictionaryService dataDictionaryService;
 45  
 
 46  
     /**
 47  
      * @see org.kuali.rice.kns.service.DocumentHelperService#getDocumentAuthorizer(java.lang.String)
 48  
      */
 49  
     public DocumentAuthorizer getDocumentAuthorizer(String documentType) {
 50  0
         DataDictionary dataDictionary = getDataDictionaryService().getDataDictionary();
 51  
 
 52  0
         if (StringUtils.isBlank(documentType)) {
 53  0
             throw new IllegalArgumentException("invalid (blank) documentType");
 54  
         }
 55  
 
 56  0
         DocumentEntry documentEntry = dataDictionary.getDocumentEntry(documentType);
 57  0
         if (documentEntry == null) {
 58  0
             throw new IllegalArgumentException("unknown documentType '" + documentType + "'");
 59  
         }
 60  
 
 61  0
         Class<? extends DocumentAuthorizer> documentAuthorizerClass = documentEntry.getDocumentAuthorizerClass();
 62  
 
 63  0
         DocumentAuthorizer documentAuthorizer = null;
 64  
         try {
 65  0
             if (documentAuthorizerClass != null) {
 66  0
                 documentAuthorizer = documentAuthorizerClass.newInstance();
 67  
             }
 68  0
             else if (documentEntry instanceof MaintenanceDocumentEntry) {
 69  0
                 documentAuthorizer = new MaintenanceDocumentAuthorizerBase();
 70  
             }
 71  0
             else if (documentEntry instanceof TransactionalDocumentEntry) {
 72  0
                 documentAuthorizer = new TransactionalDocumentAuthorizerBase();
 73  
             }
 74  
             else {
 75  0
                 documentAuthorizer = new DocumentAuthorizerBase();
 76  
             }
 77  
         }
 78  0
         catch (Exception e) {
 79  0
             throw new RuntimeException("unable to instantiate documentAuthorizer '" + documentAuthorizerClass.getName() + "' for doctype '" + documentType + "'", e);
 80  0
         }
 81  
 
 82  0
         return documentAuthorizer;
 83  
     }
 84  
 
 85  
     /**
 86  
      * @see org.kuali.rice.kns.service.DocumentHelperService#getDocumentAuthorizer(org.kuali.rice.kns.document.Document)
 87  
      */
 88  
     public DocumentAuthorizer getDocumentAuthorizer(Document document) {
 89  0
         if (document == null) {
 90  0
             throw new IllegalArgumentException("invalid (null) document");
 91  0
         } else if (document.getDocumentHeader() == null) {
 92  0
             throw new IllegalArgumentException(
 93  
                     "invalid (null) document.documentHeader");
 94  0
         } else if (!document.getDocumentHeader().hasWorkflowDocument()) {
 95  0
             throw new IllegalArgumentException(
 96  
                     "invalid (null) document.documentHeader.workflowDocument");
 97  
         }
 98  
 
 99  0
         String documentType = document.getDocumentHeader().getWorkflowDocument().getDocumentType();
 100  
 
 101  0
         DocumentAuthorizer documentAuthorizer = getDocumentAuthorizer(documentType);
 102  0
         return documentAuthorizer;
 103  
     }
 104  
 
 105  
     /**
 106  
      * @see org.kuali.rice.kns.service.DocumentHelperService#getDocumentPresentationController(java.lang.String)
 107  
      */
 108  
     public DocumentPresentationController getDocumentPresentationController(String documentType) {
 109  0
         DataDictionary dataDictionary = getDataDictionaryService().getDataDictionary();
 110  0
         DocumentPresentationController documentPresentationController = null;
 111  
         
 112  0
         if (StringUtils.isBlank(documentType)) {
 113  0
             throw new IllegalArgumentException("invalid (blank) documentType");
 114  
         }
 115  
 
 116  0
         DocumentEntry documentEntry = dataDictionary.getDocumentEntry(documentType);
 117  0
         if (documentEntry == null) {
 118  0
             throw new IllegalArgumentException("unknown documentType '" + documentType + "'");
 119  
         }
 120  0
         Class<? extends DocumentPresentationController> documentPresentationControllerClass = null;
 121  
         try{
 122  0
             documentPresentationControllerClass = documentEntry.getDocumentPresentationControllerClass();
 123  0
             if(documentPresentationControllerClass != null){
 124  0
                 documentPresentationController = documentPresentationControllerClass.newInstance();
 125  
             } else {
 126  0
                 DocumentEntry doc = dataDictionary.getDocumentEntry(documentType);
 127  0
                 if ( doc instanceof TransactionalDocumentEntry ) {
 128  0
                     documentPresentationController = new TransactionalDocumentPresentationControllerBase();
 129  0
                 } else if(doc instanceof MaintenanceDocumentEntry) {
 130  0
                     documentPresentationController = new MaintenanceDocumentPresentationControllerBase();
 131  
                 } else {
 132  0
                     documentPresentationController = new DocumentPresentationControllerBase();
 133  
                 }
 134  
             }
 135  
         }
 136  0
         catch (Exception e) {
 137  0
             throw new RuntimeException("unable to instantiate documentPresentationController '" + documentPresentationControllerClass.getName() + "' for doctype '" + documentType + "'", e);
 138  0
         }
 139  
 
 140  0
         return documentPresentationController;
 141  
     }
 142  
 
 143  
     /**
 144  
      * @see org.kuali.rice.kns.service.DocumentHelperService#getDocumentPresentationController(org.kuali.rice.kns.document.Document)
 145  
      */
 146  
     public DocumentPresentationController getDocumentPresentationController(Document document) {
 147  0
         if (document == null) {
 148  0
             throw new IllegalArgumentException("invalid (null) document");
 149  
         }
 150  0
         else if (document.getDocumentHeader() == null) {
 151  0
             throw new IllegalArgumentException("invalid (null) document.documentHeader");
 152  
         }
 153  0
         else if (!document.getDocumentHeader().hasWorkflowDocument()) {
 154  0
             throw new IllegalArgumentException("invalid (null) document.documentHeader.workflowDocument");
 155  
         }
 156  
 
 157  0
         String documentType = document.getDocumentHeader().getWorkflowDocument().getDocumentType();
 158  
 
 159  0
         DocumentPresentationController documentPresentationController = getDocumentPresentationController(documentType);
 160  0
         return documentPresentationController;
 161  
     }
 162  
 
 163  
     /**
 164  
      * @return the dataDictionaryService
 165  
      */
 166  
     public DataDictionaryService getDataDictionaryService() {
 167  0
         if (dataDictionaryService == null) {
 168  0
             this.dataDictionaryService = KNSServiceLocator.getDataDictionaryService();
 169  
         }
 170  0
         return this.dataDictionaryService;
 171  
     }
 172  
 
 173  
     /**
 174  
      * @param dataDictionaryService the dataDictionaryService to set
 175  
      */
 176  
     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
 177  0
         this.dataDictionaryService = dataDictionaryService;
 178  0
     }
 179  
 
 180  
 }