Coverage Report - org.kuali.rice.krad.uif.service.impl.MaintenanceViewTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceViewTypeServiceImpl
0%
0/40
0%
0/16
2.571
 
 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.krad.uif.service.impl;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.kuali.rice.kew.api.exception.WorkflowException;
 22  
 import org.kuali.rice.krad.document.Document;
 23  
 import org.kuali.rice.krad.service.DocumentDictionaryService;
 24  
 import org.kuali.rice.krad.service.DocumentService;
 25  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 26  
 import org.kuali.rice.krad.uif.UifConstants;
 27  
 import org.kuali.rice.krad.uif.UifConstants.ViewType;
 28  
 import org.kuali.rice.krad.uif.UifParameters;
 29  
 import org.kuali.rice.krad.uif.util.ViewModelUtils;
 30  
 import org.kuali.rice.krad.uif.service.ViewTypeService;
 31  
 import org.kuali.rice.krad.util.KRADPropertyConstants;
 32  
 import org.springframework.beans.PropertyValues;
 33  
 
 34  
 /**
 35  
  * Type service implementation for maintenance views
 36  
  * 
 37  
  * <p>
 38  
  * Indexes views on object class and name. Can retrieve views by object class,
 39  
  * object class and name, or document id
 40  
  * </p>
 41  
  * 
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  */
 44  0
 public class MaintenanceViewTypeServiceImpl implements ViewTypeService {
 45  
         private DocumentService documentService;
 46  
     private DocumentDictionaryService documentDictionaryService;
 47  
 
 48  
         /**
 49  
          * @see org.kuali.rice.krad.uif.service.ViewTypeService#getViewTypeName()
 50  
          */
 51  
         public ViewType getViewTypeName() {
 52  0
                 return ViewType.MAINTENANCE;
 53  
         }
 54  
 
 55  
     /**
 56  
      * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromViewConfiguration(org.springframework.beans.PropertyValues)
 57  
      */
 58  
     public Map<String, String> getParametersFromViewConfiguration(PropertyValues propertyValues) {
 59  0
         Map<String, String> parameters = new HashMap<String, String>();
 60  
 
 61  0
         String viewName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.VIEW_NAME);
 62  0
         String dataObjectClassName = ViewModelUtils.getStringValFromPVs(propertyValues,
 63  
                 UifParameters.DATA_OBJECT_CLASS_NAME);
 64  
 
 65  0
         parameters.put(UifParameters.VIEW_NAME, viewName);
 66  0
         parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName);
 67  
 
 68  0
         return parameters;
 69  
     }
 70  
 
 71  
         /**
 72  
          * Check for document id in request parameters, if given retrieve document
 73  
          * instance to get the object class and set the name parameter
 74  
          * 
 75  
          * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromRequest(java.util.Map)
 76  
          */
 77  
         @Override
 78  
         public Map<String, String> getParametersFromRequest(Map<String, String> requestParameters) {
 79  0
                 Map<String, String> parameters = new HashMap<String, String>();
 80  
 
 81  0
                 if (requestParameters.containsKey(UifParameters.VIEW_NAME)) {
 82  0
                         parameters.put(UifParameters.VIEW_NAME, requestParameters.get(UifParameters.VIEW_NAME));
 83  
                 }
 84  
                 else {
 85  0
                         parameters.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
 86  
                 }
 87  
 
 88  0
                 if (requestParameters.containsKey(UifParameters.DATA_OBJECT_CLASS_NAME)) {
 89  0
                         parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME,
 90  
                                         requestParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME));
 91  
                 }
 92  0
                 else if (requestParameters.containsKey(KRADPropertyConstants.DOC_ID)) {
 93  0
                         String documentNumber = requestParameters.get(KRADPropertyConstants.DOC_ID);
 94  
 
 95  0
                         boolean objectClassFound = false;
 96  
                         try {
 97  
                                 // determine object class based on the document type
 98  0
                                 Document document = documentService.getByDocumentHeaderId(documentNumber);
 99  0
                                 if (document != null) {
 100  0
                                         String docTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
 101  0
                                         Class<?> objectClassName = getDocumentDictionaryService().getMaintenanceDataObjectClass(docTypeName);
 102  0
                                         if (objectClassName != null) {
 103  0
                                                 objectClassFound = true;
 104  0
                                                 parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, objectClassName.getName());
 105  
                                         }
 106  
                                 }
 107  
 
 108  0
                                 if (!objectClassFound) {
 109  0
                                         throw new RuntimeException("Could not determine object class for maintenance document with id: "
 110  
                                                         + documentNumber);
 111  
                                 }
 112  
                         }
 113  0
                         catch (WorkflowException e) {
 114  0
                                 throw new RuntimeException("Encountered workflow exception while retrieving document with id: "
 115  
                                                 + documentNumber, e);
 116  0
                         }
 117  
                 }
 118  
 
 119  0
                 return parameters;
 120  
         }
 121  
 
 122  
         protected DocumentService getDocumentService() {
 123  0
         if (documentService == null) {
 124  0
             this.documentService = KRADServiceLocatorWeb.getDocumentService();
 125  
         }
 126  0
                 return this.documentService;
 127  
         }
 128  
 
 129  
         public void setDocumentService(DocumentService documentService) {
 130  0
                 this.documentService = documentService;
 131  0
         }
 132  
 
 133  
     public DocumentDictionaryService getDocumentDictionaryService() {
 134  0
         if (documentDictionaryService == null) {
 135  0
             this.documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService();
 136  
         }
 137  0
         return documentDictionaryService;
 138  
     }
 139  
 
 140  
     public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) {
 141  0
         this.documentDictionaryService = documentDictionaryService;
 142  0
     }
 143  
 }