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