Coverage Report - org.kuali.rice.krad.uif.service.impl.ViewDictionaryServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewDictionaryServiceImpl
0%
0/47
0%
0/14
2.25
 
 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.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 24  
 import org.kuali.rice.krad.datadictionary.DataDictionary;
 25  
 import org.kuali.rice.krad.datadictionary.DataDictionaryException;
 26  
 import org.kuali.rice.krad.inquiry.Inquirable;
 27  
 import org.kuali.rice.krad.service.DataDictionaryService;
 28  
 import org.kuali.rice.krad.uif.UifConstants;
 29  
 import org.kuali.rice.krad.uif.UifParameters;
 30  
 import org.kuali.rice.krad.uif.util.ViewModelUtils;
 31  
 import org.kuali.rice.krad.uif.view.InquiryView;
 32  
 import org.kuali.rice.krad.uif.view.LookupView;
 33  
 import org.kuali.rice.krad.uif.view.MaintenanceView;
 34  
 import org.kuali.rice.krad.uif.view.View;
 35  
 import org.kuali.rice.krad.uif.service.ViewDictionaryService;
 36  
 import org.kuali.rice.krad.uif.UifConstants.ViewType;
 37  
 import org.kuali.rice.krad.util.ObjectUtils;
 38  
 import org.springframework.beans.PropertyValues;
 39  
 
 40  
 /**
 41  
  * Implementation of <code>ViewDictionaryService</code>
 42  
  *
 43  
  * <p>
 44  
  * Pulls view entries from the data dictionary to implement the various query
 45  
  * methods
 46  
  * </p>
 47  
  *
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  */
 50  0
 public class ViewDictionaryServiceImpl implements ViewDictionaryService {
 51  
 
 52  
     private DataDictionaryService dataDictionaryService;
 53  
 
 54  
     /**
 55  
      * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#getInquirable(java.lang.Class,
 56  
      *      java.lang.String)
 57  
      */
 58  
     public Inquirable getInquirable(Class<?> dataObjectClass, String viewName) {
 59  0
         Inquirable inquirable = null;
 60  
 
 61  0
         if (StringUtils.isBlank(viewName)) {
 62  0
             viewName = UifConstants.DEFAULT_VIEW_NAME;
 63  
         }
 64  
 
 65  0
         Map<String, String> indexKey = new HashMap<String, String>();
 66  0
         indexKey.put(UifParameters.VIEW_NAME, viewName);
 67  0
         indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
 68  
 
 69  
         // get view properties
 70  0
         PropertyValues propertyValues = getDataDictionary().getViewPropertiesByType(ViewType.INQUIRY, indexKey);
 71  
 
 72  0
         String viewHelperServiceClassName = ViewModelUtils.getStringValFromPVs(propertyValues,
 73  
                 "viewHelperServiceClassName");
 74  0
         if (StringUtils.isNotBlank(viewHelperServiceClassName)) {
 75  
             try {
 76  0
                 inquirable = (Inquirable) ObjectUtils.newInstance(Class.forName(viewHelperServiceClassName));
 77  0
             } catch (ClassNotFoundException e) {
 78  0
                 throw new RiceRuntimeException(
 79  
                         "Unable to find class for inquirable classname: " + viewHelperServiceClassName, e);
 80  0
             }
 81  
         }
 82  
 
 83  0
         return inquirable;
 84  
     }
 85  
 
 86  
     /**
 87  
      * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#isInquirable(java.lang.Class)
 88  
      */
 89  
     public boolean isInquirable(Class<?> dataObjectClass) {
 90  0
         Map<String, String> indexKey = new HashMap<String, String>();
 91  0
         indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
 92  0
         indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
 93  
 
 94  0
         boolean isInquirable = getDataDictionary().viewByTypeExist(ViewType.INQUIRY, indexKey);
 95  
 
 96  0
         return isInquirable;
 97  
     }
 98  
 
 99  
     /**
 100  
      * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#isLookupable(java.lang.Class)
 101  
      */
 102  
     public boolean isLookupable(Class<?> dataObjectClass) {
 103  0
         Map<String, String> indexKey = new HashMap<String, String>();
 104  0
         indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
 105  0
         indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
 106  
 
 107  0
         boolean isLookupable = getDataDictionary().viewByTypeExist(ViewType.LOOKUP, indexKey);
 108  
 
 109  0
         return isLookupable;
 110  
     }
 111  
 
 112  
     /**
 113  
      * @see org.kuali.rice.krad.uif.service.ViewDictionaryService#isMaintainable(java.lang.Class)
 114  
      */
 115  
     public boolean isMaintainable(Class<?> dataObjectClass) {
 116  0
         Map<String, String> indexKey = new HashMap<String, String>();
 117  0
         indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
 118  0
         indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
 119  
 
 120  0
         boolean isMaintainable = getDataDictionary().viewByTypeExist(ViewType.MAINTENANCE, indexKey);
 121  
 
 122  0
         return isMaintainable;
 123  
     }
 124  
 
 125  
     /**
 126  
      * @see org.kuali.rice.krad.uif.service.impl.ViewDictionaryService#getResultSetLimitForLookup(java.lang.Class)
 127  
      */
 128  
     @Override
 129  
     public Integer getResultSetLimitForLookup(Class<?> dataObjectClass) {
 130  0
         LookupView lookupView = null;
 131  
 
 132  0
         List<View> lookupViews = getDataDictionary().getViewsForType(UifConstants.ViewType.LOOKUP);
 133  0
         for (View view : lookupViews) {
 134  0
             LookupView lView = (LookupView) view;
 135  
 
 136  0
             if (StringUtils.equals(lView.getDataObjectClassName().getName(), dataObjectClass.getName())) {
 137  
                 // if we already found a lookup view, only override if this is the default
 138  0
                 if (lookupView != null) {
 139  0
                     if (StringUtils.equals(lView.getViewName(), UifConstants.DEFAULT_VIEW_NAME)) {
 140  0
                         lookupView = lView;
 141  
                     }
 142  
                 } else {
 143  0
                     lookupView = lView;
 144  
                 }
 145  
             }
 146  0
         }
 147  
 
 148  0
         if (lookupView != null) {
 149  0
             return lookupView.getResultSetLimit();
 150  
         }
 151  
 
 152  0
         return null;
 153  
     }
 154  
 
 155  
     protected DataDictionary getDataDictionary() {
 156  0
         return getDataDictionaryService().getDataDictionary();
 157  
     }
 158  
 
 159  
     protected DataDictionaryService getDataDictionaryService() {
 160  0
         return this.dataDictionaryService;
 161  
     }
 162  
 
 163  
     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
 164  0
         this.dataDictionaryService = dataDictionaryService;
 165  0
     }
 166  
 }