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