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