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