Coverage Report - org.kuali.rice.kns.service.impl.DataDictionaryServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DataDictionaryServiceImpl
0%
0/294
0%
0/136
2.081
 
 1  
 /*
 2  
  * Copyright 2005-2007 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 java.io.IOException;
 19  
 import java.math.BigDecimal;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collections;
 22  
 import java.util.HashMap;
 23  
 import java.util.Iterator;
 24  
 import java.util.List;
 25  
 import java.util.Map;
 26  
 import java.util.Set;
 27  
 import java.util.regex.Pattern;
 28  
 
 29  
 import org.apache.commons.lang.StringUtils;
 30  
 import org.apache.log4j.Logger;
 31  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 32  
 import org.kuali.rice.kew.dto.DocumentTypeDTO;
 33  
 import org.kuali.rice.kew.exception.WorkflowException;
 34  
 import org.kuali.rice.kns.bo.BusinessObject;
 35  
 import org.kuali.rice.kns.datadictionary.AttributeDefinition;
 36  
 import org.kuali.rice.kns.datadictionary.AttributeSecurity;
 37  
 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
 38  
 import org.kuali.rice.kns.datadictionary.CollectionDefinition;
 39  
 import org.kuali.rice.kns.datadictionary.DataDictionary;
 40  
 import org.kuali.rice.kns.datadictionary.DataDictionaryEntryBase;
 41  
 import org.kuali.rice.kns.datadictionary.DocumentEntry;
 42  
 import org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata;
 43  
 import org.kuali.rice.kns.datadictionary.PrimitiveAttributeDefinition;
 44  
 import org.kuali.rice.kns.datadictionary.RelationshipDefinition;
 45  
 import org.kuali.rice.kns.datadictionary.control.ControlDefinition;
 46  
 import org.kuali.rice.kns.datadictionary.exporter.DataDictionaryMap;
 47  
 import org.kuali.rice.kns.datadictionary.validation.ValidationPattern;
 48  
 import org.kuali.rice.kns.document.Document;
 49  
 import org.kuali.rice.kns.exception.UnknownBusinessClassAttributeException;
 50  
 import org.kuali.rice.kns.exception.UnknownDocumentTypeException;
 51  
 import org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder;
 52  
 import org.kuali.rice.kns.rule.PromptBeforeValidation;
 53  
 import org.kuali.rice.kns.service.DataDictionaryService;
 54  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 55  
 import org.kuali.rice.kns.service.KualiConfigurationService;
 56  
 import org.kuali.rice.kns.service.KualiModuleService;
 57  
 import org.kuali.rice.kns.web.format.Formatter;
 58  
 import org.kuali.rice.kns.workflow.service.KualiWorkflowInfo;
 59  
 
 60  
 /**
 61  
  * This class is the service implementation for a DataDictionary. It is a thin wrapper around creating, initializing, and
 62  
  * returning a DataDictionary. This is the default, Kuali delivered implementation.
 63  
  */
 64  
 public class DataDictionaryServiceImpl implements DataDictionaryService {
 65  0
     private static final Logger LOG = Logger.getLogger( DataDictionaryServiceImpl.class );
 66  
 
 67  
 
 68  
     private DataDictionary dataDictionary;
 69  0
     private DataDictionaryMap dataDictionaryMap = new DataDictionaryMap(this);
 70  
 
 71  
     private KualiConfigurationService kualiConfigurationService;
 72  
     private KualiModuleService kualiModuleService;
 73  
     private KualiWorkflowInfo workflowInfoService;
 74  
 
 75  
 
 76  
     /**
 77  
      * @see org.kuali.rice.kns.service.DataDictionaryService#setBaselinePackages(java.lang.String)
 78  
      */
 79  
     public void setBaselinePackages(List baselinePackages) throws IOException {
 80  0
         this.addDataDictionaryLocations(baselinePackages);
 81  0
     }
 82  
 
 83  
     /**
 84  
      * Default constructor.
 85  
      */
 86  0
     public DataDictionaryServiceImpl() {
 87  0
         this.dataDictionary = new DataDictionary();
 88  0
     }
 89  
 
 90  0
     public DataDictionaryServiceImpl(DataDictionary dataDictionary) {
 91  0
         this.dataDictionary = dataDictionary;
 92  0
     }
 93  
 
 94  
     /**
 95  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getDataDictionary()
 96  
      */
 97  
     public DataDictionary getDataDictionary() {
 98  0
         return dataDictionary;
 99  
     }
 100  
 
 101  
     /**
 102  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeControlDefinition(java.lang.String)
 103  
      */
 104  
     public ControlDefinition getAttributeControlDefinition(String entryName, String attributeName) {
 105  0
         ControlDefinition controlDefinition = null;
 106  
 
 107  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 108  0
         if (attributeDefinition != null) {
 109  0
             controlDefinition = attributeDefinition.getControl();
 110  
         }
 111  
 
 112  0
         return controlDefinition;
 113  
     }
 114  
 
 115  
     /**
 116  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeSize(java.lang.String)
 117  
      */
 118  
     public Integer getAttributeSize(String entryName, String attributeName) {
 119  0
         Integer size = null;
 120  
 
 121  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 122  0
         if (attributeDefinition != null) {
 123  0
             ControlDefinition controlDefinition = attributeDefinition.getControl();
 124  0
             if (controlDefinition.isText() || controlDefinition.isCurrency()) {
 125  0
                 size = controlDefinition.getSize();
 126  
             }
 127  
         }
 128  
 
 129  0
         return size;
 130  
     }
 131  
 
 132  
     /**
 133  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeMaxLength(java.lang.String)
 134  
      */
 135  
     public Integer getAttributeMaxLength(String entryName, String attributeName) {
 136  0
         Integer maxLength = null;
 137  
 
 138  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 139  0
         if (attributeDefinition != null) {
 140  0
             maxLength = attributeDefinition.getMaxLength();
 141  
         }
 142  
 
 143  0
         return maxLength;
 144  
     }
 145  
 
 146  
     /**
 147  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeExclusiveMin
 148  
      */
 149  
     public BigDecimal getAttributeExclusiveMin(String entryName, String attributeName) {
 150  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 151  0
         return attributeDefinition == null ? null : attributeDefinition.getExclusiveMin();
 152  
     }
 153  
 
 154  
     /**
 155  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeInclusiveMax
 156  
      */
 157  
     public BigDecimal getAttributeInclusiveMax(String entryName, String attributeName) {
 158  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 159  0
         return attributeDefinition == null ? null : attributeDefinition.getInclusiveMax();
 160  
     }
 161  
 
 162  
     /**
 163  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeValidatingExpression(java.lang.String)
 164  
      */
 165  
     public Pattern getAttributeValidatingExpression(String entryName, String attributeName) {
 166  0
         Pattern regex = null;
 167  
 
 168  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 169  0
         if (attributeDefinition != null) {
 170  0
             if (attributeDefinition.hasValidationPattern()) {
 171  0
                 regex = attributeDefinition.getValidationPattern().getRegexPattern();
 172  
             } else {
 173  
                 // workaround for existing calls which don't bother checking for null return values
 174  0
                 regex = Pattern.compile(".*");
 175  
             }
 176  
         }
 177  
 
 178  0
         return regex;
 179  
     }
 180  
 
 181  
     /**
 182  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeLabel(java.lang.String)
 183  
      */
 184  
     public String getAttributeLabel(String entryName, String attributeName) {
 185  0
         String label = "";
 186  
 
 187  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 188  0
         if (attributeDefinition != null) {
 189  
                 // KULRICE-4445 prevent NullPointerException by ensuring a label is set
 190  0
                       label = attributeDefinition.getLabel();
 191  0
                 if (!StringUtils.isEmpty(attributeDefinition.getDisplayLabelAttribute())) {
 192  0
                 attributeDefinition = getAttributeDefinition(entryName, attributeDefinition.getDisplayLabelAttribute());
 193  0
                 if (attributeDefinition != null) {
 194  0
                     label = attributeDefinition.getLabel();
 195  
                 }
 196  
             }
 197  
         }
 198  
 
 199  0
         return label;
 200  
     }
 201  
 
 202  
     /**
 203  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeShortLabel(java.lang.String)
 204  
      */
 205  
     public String getAttributeShortLabel(String entryName, String attributeName) {
 206  0
         String shortLabel = "";
 207  
 
 208  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 209  0
         if (attributeDefinition != null) {
 210  0
             if (!StringUtils.isEmpty(attributeDefinition.getDisplayLabelAttribute())) {
 211  0
                 attributeDefinition = getAttributeDefinition(entryName, attributeDefinition.getDisplayLabelAttribute());
 212  0
                 if (attributeDefinition != null) {
 213  0
                     shortLabel = attributeDefinition.getShortLabel();
 214  
                 }
 215  
             } else {
 216  0
                 shortLabel = attributeDefinition.getShortLabel();
 217  
             }
 218  
         }
 219  
 
 220  0
         return shortLabel;
 221  
     }
 222  
 
 223  
     /**
 224  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeErrorLabel(java.lang.String)
 225  
      */
 226  
     public String getAttributeErrorLabel(String entryName, String attributeName) {
 227  0
         String longAttributeLabel = this.getAttributeLabel(entryName, attributeName);
 228  0
         String shortAttributeLabel = this.getAttributeShortLabel(entryName, attributeName);
 229  0
         return longAttributeLabel + " (" + shortAttributeLabel + ")";
 230  
     }
 231  
 
 232  
     /**
 233  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeFormatter(java.lang.String)
 234  
      */
 235  
     public Class<? extends Formatter> getAttributeFormatter(String entryName, String attributeName) {
 236  0
         Class formatterClass = null;
 237  
 
 238  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 239  0
         if (attributeDefinition != null) {
 240  0
             if (attributeDefinition.hasFormatterClass()) {
 241  0
                 formatterClass = ClassLoaderUtils.getClass(attributeDefinition.getFormatterClass());
 242  
             }
 243  
         }
 244  
 
 245  0
         return formatterClass;
 246  
     }
 247  
 
 248  
     /**
 249  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeForceUppercase(java.lang.String)
 250  
      */
 251  
     public Boolean getAttributeForceUppercase(String entryName, String attributeName) throws UnknownBusinessClassAttributeException {
 252  0
         Boolean forceUppercase = null;
 253  
 
 254  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 255  0
         if (attributeDefinition == null) {
 256  0
             throw new UnknownBusinessClassAttributeException("Could not find a matching data dictionary business class attribute entry for " + entryName + "." + attributeName);
 257  
         }
 258  0
         forceUppercase = attributeDefinition.getForceUppercase();
 259  
 
 260  0
         return forceUppercase;
 261  
     }
 262  
 
 263  
     /**
 264  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeDisplayMask(java.lang.String, java.lang.String)
 265  
      */
 266  
     public AttributeSecurity getAttributeSecurity(String entryName, String attributeName) {
 267  0
         AttributeSecurity attributeSecurity = null;
 268  
 
 269  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 270  0
         if (attributeDefinition != null) {
 271  0
             attributeSecurity = attributeDefinition.getAttributeSecurity();
 272  
         }
 273  
 
 274  0
         return attributeSecurity;
 275  
     }
 276  
 
 277  
 
 278  
     /**
 279  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeSummary(java.lang.String)
 280  
      */
 281  
     public String getAttributeSummary(String entryName, String attributeName) {
 282  0
         String summary = null;
 283  
 
 284  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 285  0
         if (attributeDefinition != null) {
 286  0
             summary = attributeDefinition.getSummary();
 287  
         }
 288  
 
 289  0
         return summary;
 290  
     }
 291  
 
 292  
     /**
 293  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeDescription(java.lang.String)
 294  
      */
 295  
     public String getAttributeDescription(String entryName, String attributeName) {
 296  0
         String description = null;
 297  
 
 298  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 299  0
         if (attributeDefinition != null) {
 300  0
             description = attributeDefinition.getDescription();
 301  
         }
 302  
 
 303  0
         return description;
 304  
     }
 305  
 
 306  
     /**
 307  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#isAttributeRequired(java.lang.Class, java.lang.String)
 308  
      */
 309  
     public Boolean isAttributeRequired(String entryName, String attributeName) {
 310  0
         Boolean required = null;
 311  
 
 312  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 313  0
         if (attributeDefinition != null) {
 314  0
             required = attributeDefinition.isRequired();
 315  
         }
 316  
 
 317  0
         return required;
 318  
     }
 319  
 
 320  
     /**
 321  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#isAttributeDefined(java.lang.Class, java.lang.String)
 322  
      */
 323  
     public Boolean isAttributeDefined(String entryName, String attributeName) {
 324  0
         boolean isDefined = false;
 325  
 
 326  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 327  0
         if (attributeDefinition != null) {
 328  0
             isDefined = true;
 329  
         }
 330  
 
 331  0
         return isDefined;
 332  
     }
 333  
 
 334  
     /**
 335  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getAttributeValuesScopeId(java.lang.Class,
 336  
      *      java.lang.String)
 337  
      */
 338  
     public Class<? extends KeyValuesFinder> getAttributeValuesFinderClass(String entryName, String attributeName) {
 339  0
         Class valuesFinderClass = null;
 340  
 
 341  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 342  0
         if (attributeDefinition != null) {
 343  0
             String valuesFinderClassName = attributeDefinition.getControl().getValuesFinderClass();
 344  0
             valuesFinderClass = ClassLoaderUtils.getClass(valuesFinderClassName);
 345  
         }
 346  
 
 347  0
         return valuesFinderClass;
 348  
     }
 349  
 
 350  
     /**
 351  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getCollectionLabel(java.lang.Class, java.lang.String)
 352  
      */
 353  
     public String getCollectionLabel(String entryName, String collectionName) {
 354  0
         String label = "";
 355  
 
 356  0
         CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
 357  0
         if (collectionDefinition != null) {
 358  0
             label = collectionDefinition.getLabel();
 359  
         }
 360  
 
 361  0
         return label;
 362  
     }
 363  
 
 364  
     /**
 365  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getCollectionShortLabel(java.lang.Class, java.lang.String)
 366  
      */
 367  
     public String getCollectionShortLabel(String entryName, String collectionName) {
 368  0
         String shortLabel = "";
 369  
 
 370  0
         CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
 371  0
         if (collectionDefinition != null) {
 372  0
             shortLabel = collectionDefinition.getShortLabel();
 373  
         }
 374  
 
 375  0
         return shortLabel;
 376  
     }
 377  
 
 378  
     /**
 379  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getCollectionElementLabel(java.lang.Class,
 380  
      *      java.lang.String)
 381  
      */
 382  
     public String getCollectionElementLabel(String entryName, String collectionName, Class businessObjectClass) {
 383  0
         String elementLabel = "";
 384  
 
 385  0
         CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
 386  0
         if (collectionDefinition != null) {
 387  0
             elementLabel = collectionDefinition.getElementLabel();
 388  0
             if (StringUtils.isEmpty(elementLabel)) {
 389  0
                 BusinessObjectEntry boe = getDataDictionary().getBusinessObjectEntry(businessObjectClass.getName());
 390  0
                 if (boe != null) {
 391  0
                     elementLabel = boe.getObjectLabel();
 392  
                 }
 393  
             }
 394  
         }
 395  
 
 396  0
         return elementLabel;
 397  
     }
 398  
 
 399  
     /**
 400  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getCollectionSummary(java.lang.Class, java.lang.String)
 401  
      */
 402  
     public String getCollectionSummary(String entryName, String collectionName) {
 403  0
         String summary = null;
 404  
 
 405  0
         CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
 406  0
         if (collectionDefinition != null) {
 407  0
             summary = collectionDefinition.getSummary();
 408  
         }
 409  
 
 410  0
         return summary;
 411  
     }
 412  
 
 413  
     /**
 414  
      * @see org.kuali.rice.kns.service.BusinessObjectDictionaryService#getCollectionDescription(java.lang.Class,
 415  
      *      java.lang.String)
 416  
      */
 417  
     public String getCollectionDescription(String entryName, String collectionName) {
 418  0
         String description = null;
 419  
 
 420  0
         CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
 421  0
         if (collectionDefinition != null) {
 422  0
             description = collectionDefinition.getDescription();
 423  
         }
 424  
 
 425  0
         return description;
 426  
     }
 427  
 
 428  
     public Class<? extends BusinessObject> getRelationshipSourceClass(String entryName, String relationshipName) {
 429  0
         Class sourceClass = null;
 430  
 
 431  0
         RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
 432  0
         if (rd != null) {
 433  0
             sourceClass = rd.getSourceClass();
 434  
         }
 435  
 
 436  0
         return sourceClass;
 437  
     }
 438  
 
 439  
     public Class<? extends BusinessObject> getRelationshipTargetClass(String entryName, String relationshipName) {
 440  0
         Class targetClass = null;
 441  
 
 442  0
         RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
 443  0
         if (rd != null) {
 444  0
             targetClass = rd.getTargetClass();
 445  
         }
 446  
 
 447  0
         return targetClass;
 448  
     }
 449  
 
 450  
     public List<String> getRelationshipSourceAttributes(String entryName, String relationshipName) {
 451  0
         List<String> sourceAttributes = null;
 452  
 
 453  0
         RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
 454  0
         if (rd != null) {
 455  0
             sourceAttributes = new ArrayList<String>();
 456  
 
 457  0
             for (PrimitiveAttributeDefinition pad : rd.getPrimitiveAttributes()) {
 458  0
                 sourceAttributes.add(pad.getSourceName());
 459  
             }
 460  
         }
 461  
 
 462  0
         return sourceAttributes;
 463  
     }
 464  
 
 465  
     public List<String> getRelationshipTargetAttributes(String entryName, String relationshipName) {
 466  0
         List<String> targetAttributes = null;
 467  
 
 468  0
         RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
 469  0
         if (rd != null) {
 470  0
             targetAttributes = new ArrayList<String>();
 471  
 
 472  0
             for (PrimitiveAttributeDefinition pad : rd.getPrimitiveAttributes()) {
 473  0
                 targetAttributes.add(pad.getTargetName());
 474  
             }
 475  
         }
 476  
 
 477  0
         return targetAttributes;
 478  
     }
 479  
 
 480  
     public List<String> getRelationshipEntriesForSourceAttribute(String entryName, String sourceAttributeName) {
 481  0
         List<String> relationships = new ArrayList<String>();
 482  
 
 483  0
         DataDictionaryEntryBase entry = (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
 484  
 
 485  0
         for (RelationshipDefinition def : entry.getRelationships()) {
 486  0
             for (PrimitiveAttributeDefinition pddef : def.getPrimitiveAttributes()) {
 487  0
                 if (StringUtils.equals(sourceAttributeName, pddef.getSourceName())) {
 488  0
                     relationships.add(def.getObjectAttributeName());
 489  0
                     break;
 490  
                 }
 491  
             }
 492  
         }
 493  0
         return relationships;
 494  
     }
 495  
 
 496  
     public List<String> getRelationshipEntriesForTargetAttribute(String entryName, String targetAttributeName) {
 497  0
         List<String> relationships = new ArrayList<String>();
 498  
 
 499  0
         DataDictionaryEntryBase entry = (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
 500  
 
 501  0
         for (RelationshipDefinition def : entry.getRelationships()) {
 502  0
             for (PrimitiveAttributeDefinition pddef : def.getPrimitiveAttributes()) {
 503  0
                 if (StringUtils.equals(targetAttributeName, pddef.getTargetName())) {
 504  0
                     relationships.add(def.getObjectAttributeName());
 505  0
                     break;
 506  
                 }
 507  
             }
 508  
         }
 509  0
         return relationships;
 510  
     }
 511  
 
 512  
     /**
 513  
      * @param objectClass
 514  
      * @param attributeName
 515  
      * @return AttributeDefinition for the given objectClass and attribute name, or null if there is none
 516  
      * @throws IllegalArgumentException
 517  
      *             if the given Class is null or is not a BusinessObject class
 518  
      */
 519  
     private AttributeDefinition getAttributeDefinition(String entryName, String attributeName) {
 520  0
         if (StringUtils.isBlank(attributeName)) {
 521  0
             throw new IllegalArgumentException("invalid (blank) attributeName");
 522  
         }
 523  0
         AttributeDefinition attributeDefinition = null;
 524  
 
 525  0
         DataDictionaryEntryBase entry = (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
 526  0
         if (entry != null) {
 527  0
             attributeDefinition = entry.getAttributeDefinition(attributeName);
 528  
         }
 529  
 
 530  0
         return attributeDefinition;
 531  
     }
 532  
 
 533  
     /**
 534  
      * @param entryName
 535  
      * @param collectionName
 536  
      * @return CollectionDefinition for the given entryName and collectionName, or null if there is none
 537  
      */
 538  
     private CollectionDefinition getCollectionDefinition(String entryName, String collectionName) {
 539  0
         if (StringUtils.isBlank(collectionName)) {
 540  0
             throw new IllegalArgumentException("invalid (blank) collectionName");
 541  
         }
 542  0
         CollectionDefinition collectionDefinition = null;
 543  
 
 544  0
         DataDictionaryEntryBase entry = (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
 545  0
         if (entry != null) {
 546  0
             collectionDefinition = entry.getCollectionDefinition(collectionName);
 547  
         }
 548  
 
 549  0
         return collectionDefinition;
 550  
     }
 551  
 
 552  
     /**
 553  
      * @param entryName
 554  
      * @param relationshipName
 555  
      * @return RelationshipDefinition for the given entryName and relationshipName, or null if there is none
 556  
      */
 557  
     private RelationshipDefinition getRelationshipDefinition(String entryName, String relationshipName) {
 558  0
         if (StringUtils.isBlank(relationshipName)) {
 559  0
             throw new IllegalArgumentException("invalid (blank) relationshipName");
 560  
         }
 561  
 
 562  0
         RelationshipDefinition relationshipDefinition = null;
 563  
 
 564  0
         DataDictionaryEntryBase entry = (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
 565  0
         if (entry != null) {
 566  0
             relationshipDefinition = entry.getRelationshipDefinition(relationshipName);
 567  
         }
 568  
 
 569  0
         return relationshipDefinition;
 570  
     }
 571  
 
 572  
     /**
 573  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getRelationshipAttributeMap(java.lang.String, java.lang.String)
 574  
      */
 575  
     public Map<String, String> getRelationshipAttributeMap(String entryName, String relationshipName) {
 576  0
         Map<String, String> attributeMap = new HashMap<String, String>();
 577  0
         RelationshipDefinition relationshipDefinition = getRelationshipDefinition(entryName, relationshipName);
 578  0
         for (Iterator iter = relationshipDefinition.getPrimitiveAttributes().iterator(); iter.hasNext();) {
 579  0
             PrimitiveAttributeDefinition attribute = (PrimitiveAttributeDefinition) iter.next();
 580  0
             attributeMap.put(attribute.getTargetName(), attribute.getSourceName());
 581  0
         }
 582  0
         return attributeMap;
 583  
     }
 584  
 
 585  
     public boolean hasRelationship(String entryName, String relationshipName) {
 586  0
         return getRelationshipDefinition(entryName, relationshipName) != null;
 587  
     }
 588  
 
 589  
     public List<String> getRelationshipNames(String entryName) {
 590  0
         DataDictionaryEntryBase entry = (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
 591  
 
 592  0
         List<String> relationshipNames = new ArrayList<String>();
 593  0
         for (RelationshipDefinition def : entry.getRelationships()) {
 594  0
             relationshipNames.add(def.getObjectAttributeName());
 595  
         }
 596  0
         return relationshipNames;
 597  
     }
 598  
 
 599  
     /**
 600  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeControlDefinition(java.lang.String, java.lang.String)
 601  
      */
 602  
     public ControlDefinition getAttributeControlDefinition(Class businessObjectClass, String attributeName) {
 603  0
         return getAttributeControlDefinition(businessObjectClass.getName(), attributeName);
 604  
     }
 605  
 
 606  
     /**
 607  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeDescription(java.lang.String, java.lang.String)
 608  
      */
 609  
     public String getAttributeDescription(Class businessObjectClass, String attributeName) {
 610  0
         return getAttributeDescription(businessObjectClass.getName(), attributeName);
 611  
     }
 612  
 
 613  
     /**
 614  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeForceUppercase(java.lang.String, java.lang.String)
 615  
      */
 616  
     public Boolean getAttributeForceUppercase(Class businessObjectClass, String attributeName) {
 617  0
         return getAttributeForceUppercase(businessObjectClass.getName(), attributeName);
 618  
     }
 619  
 
 620  
     /**
 621  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeFormatter(java.lang.String, java.lang.String)
 622  
      */
 623  
     public Class<? extends Formatter> getAttributeFormatter(Class businessObjectClass, String attributeName) {
 624  0
         return getAttributeFormatter(businessObjectClass.getName(), attributeName);
 625  
     }
 626  
 
 627  
     /**
 628  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeLabel(java.lang.String, java.lang.String)
 629  
      */
 630  
     public String getAttributeLabel(Class businessObjectClass, String attributeName) {
 631  0
         return getAttributeLabel(businessObjectClass.getName(), attributeName);
 632  
     }
 633  
 
 634  
     /**
 635  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeMaxLength(java.lang.String, java.lang.String)
 636  
      */
 637  
     public Integer getAttributeMaxLength(Class businessObjectClass, String attributeName) {
 638  0
         return getAttributeMaxLength(businessObjectClass.getName(), attributeName);
 639  
     }
 640  
 
 641  
     /**
 642  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeShortLabel(java.lang.String, java.lang.String)
 643  
      */
 644  
     public String getAttributeShortLabel(Class businessObjectClass, String attributeName) {
 645  0
         return getAttributeShortLabel(businessObjectClass.getName(), attributeName);
 646  
     }
 647  
 
 648  
     /**
 649  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeErrorLabel(java.lang.String, java.lang.String)
 650  
      */
 651  
     public String getAttributeErrorLabel(Class businessObjectClass, String attributeName) {
 652  0
         return getAttributeErrorLabel(businessObjectClass.getName(), attributeName);
 653  
     }
 654  
 
 655  
     /**
 656  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeSize(java.lang.String, java.lang.String)
 657  
      */
 658  
     public Integer getAttributeSize(Class businessObjectClass, String attributeName) {
 659  0
         return getAttributeSize(businessObjectClass.getName(), attributeName);
 660  
     }
 661  
 
 662  
     /**
 663  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeSummary(java.lang.String, java.lang.String)
 664  
      */
 665  
     public String getAttributeSummary(Class businessObjectClass, String attributeName) {
 666  0
         return getAttributeSummary(businessObjectClass.getName(), attributeName);
 667  
     }
 668  
 
 669  
     /**
 670  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeValidatingExpression(java.lang.String, java.lang.String)
 671  
      */
 672  
     public Pattern getAttributeValidatingExpression(Class businessObjectClass, String attributeName) {
 673  0
         return getAttributeValidatingExpression(businessObjectClass.getName(), attributeName);
 674  
     }
 675  
 
 676  
     /**
 677  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeValuesFinderClass(java.lang.String, java.lang.String)
 678  
      */
 679  
     public Class getAttributeValuesFinderClass(Class businessObjectClass, String attributeName) {
 680  0
         return getAttributeValuesFinderClass(businessObjectClass.getName(), attributeName);
 681  
     }
 682  
 
 683  
     /**
 684  
          * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeValidatingErrorMessageKey(java.lang.String, java.lang.String)
 685  
          */
 686  
         public String getAttributeValidatingErrorMessageKey(String entryName, String attributeName) {
 687  0
         AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 688  0
         if (attributeDefinition != null) {
 689  0
                 if (attributeDefinition.hasValidationPattern()) {
 690  0
                         ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
 691  0
                         return validationPattern.getValidationErrorMessageKey();
 692  
                 }
 693  
         }
 694  0
         return null;
 695  
         }
 696  
 
 697  
         /**
 698  
          * @see org.kuali.rice.kns.service.DataDictionaryService#getAttributeValidatingErrorMessageParameters(java.lang.String, java.lang.String)
 699  
          */
 700  
         public String[] getAttributeValidatingErrorMessageParameters(String entryName, String attributeName) {
 701  0
                 AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
 702  0
         if (attributeDefinition != null) {
 703  0
                 if (attributeDefinition.hasValidationPattern()) {
 704  0
                         ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
 705  0
                         String attributeLabel = getAttributeErrorLabel(entryName, attributeName);
 706  0
                         return validationPattern.getValidationErrorMessageParameters(attributeLabel);
 707  
                 }
 708  
         }
 709  0
         return null;
 710  
         }
 711  
 
 712  
         /**
 713  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getCollectionDescription(java.lang.String, java.lang.String)
 714  
      */
 715  
     public String getCollectionDescription(Class businessObjectClass, String collectionName) {
 716  0
         return getCollectionDescription(businessObjectClass.getName(), collectionName);
 717  
     }
 718  
 
 719  
     /**
 720  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getCollectionLabel(java.lang.String, java.lang.String)
 721  
      */
 722  
     public String getCollectionLabel(Class businessObjectClass, String collectionName) {
 723  0
         return getCollectionLabel(businessObjectClass.getName(), collectionName);
 724  
     }
 725  
 
 726  
     /**
 727  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getCollectionShortLabel(java.lang.String, java.lang.String)
 728  
      */
 729  
     public String getCollectionShortLabel(Class businessObjectClass, String collectionName) {
 730  0
         return getCollectionShortLabel(businessObjectClass.getName(), collectionName);
 731  
     }
 732  
 
 733  
     /**
 734  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getCollectionSummary(java.lang.String, java.lang.String)
 735  
      */
 736  
     public String getCollectionSummary(Class businessObjectClass, String collectionName) {
 737  0
         return getCollectionSummary(businessObjectClass.getName(), collectionName);
 738  
     }
 739  
 
 740  
     /**
 741  
      * @see org.kuali.rice.kns.service.DataDictionaryService#isAttributeDefined(java.lang.String, java.lang.String)
 742  
      */
 743  
     public Boolean isAttributeDefined(Class businessObjectClass, String attributeName) {
 744  0
         return isAttributeDefined(businessObjectClass.getName(), attributeName);
 745  
     }
 746  
 
 747  
     /**
 748  
      * @see org.kuali.rice.kns.service.DataDictionaryService#isAttributeRequired(java.lang.String, java.lang.String)
 749  
      */
 750  
     public Boolean isAttributeRequired(Class businessObjectClass, String attributeName) {
 751  0
         return isAttributeRequired(businessObjectClass.getName(), attributeName);
 752  
 
 753  
     }
 754  
 
 755  
     /**
 756  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getDocumentLabelByClass(java.lang.Class)
 757  
      */
 758  
     public String getDocumentLabelByClass(Class documentOrBusinessObjectClass) {
 759  0
         return getDocumentLabelByTypeName(getDocumentTypeNameByClass(documentOrBusinessObjectClass));
 760  
     }
 761  
 
 762  
     /**
 763  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getDocumentLabelByTypeName(java.lang.String)
 764  
      */
 765  
     public String getDocumentLabelByTypeName(String documentTypeName) {
 766  0
         String label = null;
 767  0
         if (StringUtils.isNotBlank(documentTypeName)) {
 768  
             try {
 769  0
                 DocumentTypeDTO documentType = getWorkflowInfoService().getDocType(documentTypeName);
 770  0
                 if (documentType != null) {
 771  0
                     label = documentType.getDocTypeLabel();
 772  
                 }
 773  0
             } catch (WorkflowException e) {
 774  
                 // stop blowing up when workflow doc does not exist
 775  0
                 LOG.error("Caught Workflow Exception trying to get document type '" + documentTypeName + "'", e);
 776  0
                 return documentTypeName;
 777  0
             }
 778  
         }
 779  0
         return label;
 780  
     }
 781  
 
 782  
     /**
 783  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getDocumentTypeNameByClass(java.lang.Class)
 784  
      */
 785  
     public String getDocumentTypeNameByClass(Class documentClass) {
 786  0
         if (documentClass == null) {
 787  0
             throw new IllegalArgumentException("invalid (null) documentClass");
 788  
         }
 789  0
         if (!Document.class.isAssignableFrom(documentClass)) {
 790  0
             throw new IllegalArgumentException("invalid (non-Document) documentClass");
 791  
         }
 792  
 
 793  0
         String documentTypeName = null;
 794  
 
 795  0
         DocumentEntry documentEntry = getDataDictionary().getDocumentEntry(documentClass.getName());
 796  0
         if (documentEntry != null) {
 797  0
             documentTypeName = documentEntry.getDocumentTypeName();
 798  
         }
 799  
 
 800  0
         return documentTypeName;
 801  
     }
 802  
 
 803  
     /**
 804  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getValidDocumentTypeNameByClass(java.lang.Class)
 805  
      */
 806  
     public String getValidDocumentTypeNameByClass(Class documentClass) {
 807  0
         String documentTypeName = getDocumentTypeNameByClass(documentClass);
 808  0
         if (StringUtils.isBlank(documentTypeName)) {
 809  0
             throw new UnknownDocumentTypeException("unable to get documentTypeName for unknown documentClass '" + documentClass.getName() + "'");
 810  
         }
 811  0
         return documentTypeName;
 812  
     }
 813  
 
 814  
     /**
 815  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getDocumentClassByTypeName(java.lang.String)
 816  
      */
 817  
     public Class<? extends Document> getDocumentClassByTypeName(String documentTypeName) {
 818  0
         Class clazz = null;
 819  
 
 820  0
         DocumentEntry documentEntry = getDataDictionary().getDocumentEntry(documentTypeName);
 821  0
         if (documentEntry != null) {
 822  0
             clazz = documentEntry.getDocumentClass();
 823  
         }
 824  
 
 825  0
         return clazz;
 826  
     }
 827  
 
 828  
     /**
 829  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getValidDocumentClassByTypeName(java.lang.String)
 830  
      */
 831  
     public Class<? extends Document> getValidDocumentClassByTypeName(String documentTypeName) {
 832  0
         Class clazz = getDocumentClassByTypeName(documentTypeName);
 833  0
         if (clazz == null) {
 834  0
             throw new UnknownDocumentTypeException("unable to get class for unknown documentTypeName '" + documentTypeName + "'");
 835  
         }
 836  0
         return clazz;
 837  
     }
 838  
 
 839  
     /**
 840  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getPromptBeforeValidationClass(java.lang.String)
 841  
      */
 842  
     public Class<? extends PromptBeforeValidation> getPromptBeforeValidationClass(String docTypeName) {
 843  0
         Class preRulesCheckClass = null;
 844  
 
 845  0
         DocumentEntry documentEntry = getDataDictionary().getDocumentEntry(docTypeName);
 846  0
         if (documentEntry != null) {
 847  0
             preRulesCheckClass = documentEntry.getPromptBeforeValidationClass();
 848  
         }
 849  
 
 850  0
         return preRulesCheckClass;
 851  
     }
 852  
 
 853  
     public void addDataDictionaryLocation(String location) throws IOException {
 854  0
         dataDictionary.addConfigFileLocation(location);
 855  0
     }
 856  
 
 857  
     public void addDataDictionaryLocations(List<String> locations) throws IOException {
 858  0
         for (String location : locations) {
 859  0
             addDataDictionaryLocation(location);
 860  
         }
 861  0
     }
 862  
 
 863  
     public Map getDataDictionaryMap() {
 864  0
         return dataDictionaryMap;
 865  
     }
 866  
 
 867  
     public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
 868  0
         this.kualiConfigurationService = kualiConfigurationService;
 869  0
     }
 870  
 
 871  
     public KualiConfigurationService getKualiConfigurationService() {
 872  0
         return kualiConfigurationService;
 873  
     }
 874  
 
 875  
     public KualiModuleService getKualiModuleService() {
 876  0
         return kualiModuleService;
 877  
     }
 878  
 
 879  
     public void setKualiModuleService(KualiModuleService kualiModuleService) {
 880  0
         this.kualiModuleService = kualiModuleService;
 881  0
     }
 882  
 
 883  
     /**
 884  
      * Returns all of the inactivation blocks registered for a particular business object
 885  
      *
 886  
      * @see org.kuali.rice.kns.service.DataDictionaryService#getAllInactivationBlockingDefinitions(java.lang.Class)
 887  
      */
 888  
     public Set<InactivationBlockingMetadata> getAllInactivationBlockingDefinitions(Class inactivationBlockedBusinessObjectClass) {
 889  0
         Set<InactivationBlockingMetadata> blockingClasses = dataDictionary.getAllInactivationBlockingMetadatas(inactivationBlockedBusinessObjectClass);
 890  0
         if (blockingClasses == null) {
 891  0
             return Collections.emptySet();
 892  
         }
 893  0
         return blockingClasses;
 894  
     }
 895  
 
 896  
         public KualiWorkflowInfo getWorkflowInfoService() {
 897  0
                 if ( workflowInfoService == null ) {
 898  0
                         workflowInfoService = KNSServiceLocator.getWorkflowInfoService();
 899  
                 }
 900  0
                 return workflowInfoService;
 901  
         }
 902  
 }