View Javadoc

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