Coverage Report - org.kuali.rice.krad.uif.service.impl.MaintenanceViewTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceViewTypeServiceImpl
0%
0/39
0%
0/16
2.571
 
 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.krad.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.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.container.MaintenanceView;
 30  
 import org.kuali.rice.krad.uif.container.View;
 31  
 import org.kuali.rice.krad.uif.service.ViewTypeService;
 32  
 import org.kuali.rice.krad.util.KRADPropertyConstants;
 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 String getViewTypeName() {
 52  0
                 return ViewType.MAINTENANCE;
 53  
         }
 54  
 
 55  
         /**
 56  
          * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromView(org.kuali.rice.krad.uif.container.View)
 57  
          */
 58  
         public Map<String, String> getParametersFromView(View view) {
 59  0
                 Map<String, String> parameters = new HashMap<String, String>();
 60  
 
 61  0
                 MaintenanceView maintenanceView = (MaintenanceView) view;
 62  
 
 63  0
                 parameters.put(UifParameters.VIEW_NAME, maintenanceView.getViewName());
 64  0
                 parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, maintenanceView.getDataObjectClassName()
 65  
                                 .getName());
 66  
 
 67  0
                 return parameters;
 68  
         }
 69  
 
 70  
         /**
 71  
          * Check for document id in request parameters, if given retrieve document
 72  
          * instance to get the object class and set the name parameter
 73  
          * 
 74  
          * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromRequest(java.util.Map)
 75  
          */
 76  
         @Override
 77  
         public Map<String, String> getParametersFromRequest(Map<String, String> requestParameters) {
 78  0
                 Map<String, String> parameters = new HashMap<String, String>();
 79  
 
 80  0
                 if (requestParameters.containsKey(UifParameters.VIEW_NAME)) {
 81  0
                         parameters.put(UifParameters.VIEW_NAME, requestParameters.get(UifParameters.VIEW_NAME));
 82  
                 }
 83  
                 else {
 84  0
                         parameters.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
 85  
                 }
 86  
 
 87  0
                 if (requestParameters.containsKey(UifParameters.DATA_OBJECT_CLASS_NAME)) {
 88  0
                         parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME,
 89  
                                         requestParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME));
 90  
                 }
 91  0
                 else if (requestParameters.containsKey(KRADPropertyConstants.DOC_ID)) {
 92  0
                         String documentNumber = requestParameters.get(KRADPropertyConstants.DOC_ID);
 93  
 
 94  0
                         boolean objectClassFound = false;
 95  
                         try {
 96  
                                 // determine object class based on the document type
 97  0
                                 Document document = documentService.getByDocumentHeaderId(documentNumber);
 98  0
                                 if (document != null) {
 99  0
                                         String docTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
 100  0
                                         Class<?> objectClassName = getDocumentDictionaryService().getMaintenanceDataObjectClass(docTypeName);
 101  0
                                         if (objectClassName != null) {
 102  0
                                                 objectClassFound = true;
 103  0
                                                 parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, objectClassName.getName());
 104  
                                         }
 105  
                                 }
 106  
 
 107  0
                                 if (!objectClassFound) {
 108  0
                                         throw new RuntimeException("Could not determine object class for maintenance document with id: "
 109  
                                                         + documentNumber);
 110  
                                 }
 111  
                         }
 112  0
                         catch (WorkflowException e) {
 113  0
                                 throw new RuntimeException("Encountered workflow exception while retrieving document with id: "
 114  
                                                 + documentNumber, e);
 115  0
                         }
 116  
                 }
 117  
 
 118  0
                 return parameters;
 119  
         }
 120  
 
 121  
         protected DocumentService getDocumentService() {
 122  0
         if (documentService == null) {
 123  0
             this.documentService = KRADServiceLocatorWeb.getDocumentService();
 124  
         }
 125  0
                 return this.documentService;
 126  
         }
 127  
 
 128  
         public void setDocumentService(DocumentService documentService) {
 129  0
                 this.documentService = documentService;
 130  0
         }
 131  
 
 132  
     public DocumentDictionaryService getDocumentDictionaryService() {
 133  0
         if (documentDictionaryService == null) {
 134  0
             this.documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService();
 135  
         }
 136  0
         return documentDictionaryService;
 137  
     }
 138  
 
 139  
     public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) {
 140  0
         this.documentDictionaryService = documentDictionaryService;
 141  0
     }
 142  
 }