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