001    /**
002     * Copyright 2005-2014 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.service.impl;
017    
018    import java.io.IOException;
019    import java.util.ArrayList;
020    import java.util.Collections;
021    import java.util.HashMap;
022    import java.util.Iterator;
023    import java.util.List;
024    import java.util.Map;
025    import java.util.Set;
026    import java.util.regex.Pattern;
027    
028    import org.apache.commons.lang.StringUtils;
029    import org.kuali.rice.core.api.config.property.ConfigurationService;
030    import org.kuali.rice.core.api.util.ClassLoaderUtils;
031    import org.kuali.rice.core.web.format.Formatter;
032    import org.kuali.rice.kew.api.KewApiServiceLocator;
033    import org.kuali.rice.kew.api.doctype.DocumentType;
034    import org.kuali.rice.kew.api.doctype.DocumentTypeService;
035    import org.kuali.rice.krad.bo.BusinessObject;
036    import org.kuali.rice.krad.datadictionary.AttributeDefinition;
037    import org.kuali.rice.krad.datadictionary.AttributeSecurity;
038    import org.kuali.rice.krad.datadictionary.BusinessObjectEntry;
039    import org.kuali.rice.krad.datadictionary.CollectionDefinition;
040    import org.kuali.rice.krad.datadictionary.DataDictionary;
041    import org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase;
042    import org.kuali.rice.krad.datadictionary.DataObjectEntry;
043    import org.kuali.rice.krad.datadictionary.DocumentEntry;
044    import org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata;
045    import org.kuali.rice.krad.datadictionary.PrimitiveAttributeDefinition;
046    import org.kuali.rice.krad.datadictionary.RelationshipDefinition;
047    import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
048    import org.kuali.rice.krad.datadictionary.exception.UnknownBusinessClassAttributeException;
049    import org.kuali.rice.krad.datadictionary.exception.UnknownDocumentTypeException;
050    import org.kuali.rice.krad.datadictionary.validation.ValidationPattern;
051    import org.kuali.rice.krad.document.Document;
052    import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
053    import org.kuali.rice.krad.service.DataDictionaryService;
054    import org.kuali.rice.krad.service.KualiModuleService;
055    import org.kuali.rice.krad.uif.UifConstants.ViewType;
056    import org.kuali.rice.krad.uif.view.View;
057    
058    /**
059     * Service implementation for a DataDictionary. It is a thin wrapper around creating, initializing, and
060     * returning a DataDictionary. This is the default, Kuali delivered implementation
061     *
062     * @author Kuali Rice Team (rice.collab@kuali.org)
063     */
064    public class DataDictionaryServiceImpl implements DataDictionaryService {
065    
066        private DataDictionary dataDictionary;
067    
068        private ConfigurationService kualiConfigurationService;
069        private KualiModuleService kualiModuleService;
070        private volatile DocumentTypeService documentTypeService;
071    
072        public DataDictionaryServiceImpl() {
073            this.dataDictionary = new DataDictionary();
074        }
075    
076        public DataDictionaryServiceImpl(DataDictionary dataDictionary) {
077            this.dataDictionary = dataDictionary;
078        }
079    
080        @Override
081            public void setAdditionalDictionaryFiles(Map<String, List<String>> additionalDictionaryFiles) throws IOException {
082            for (Map.Entry<String, List<String>> entry : additionalDictionaryFiles.entrySet()) {
083                addDataDictionaryLocations(entry.getKey(), entry.getValue());
084            }
085        }
086    
087        @Override
088            public void addDataDictionaryLocations(String namespaceCode, List<String> locations) throws IOException {
089            for (String location : locations) {
090                dataDictionary.addConfigFileLocation(namespaceCode, location);
091            }
092        }
093    
094        @Override
095            public DataDictionary getDataDictionary() {
096            return dataDictionary;
097        }
098    
099        @Override
100            public ControlDefinition getAttributeControlDefinition(String entryName, String attributeName) {
101            ControlDefinition controlDefinition = null;
102    
103            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
104            if (attributeDefinition != null) {
105                controlDefinition = attributeDefinition.getControl();
106            }
107    
108            return controlDefinition;
109        }
110    
111        @Override
112            public Integer getAttributeSize(String entryName, String attributeName) {
113            Integer size = null;
114    
115            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
116            if (attributeDefinition != null) {
117                ControlDefinition controlDefinition = attributeDefinition.getControl();
118                if (controlDefinition.isText() || controlDefinition.isCurrency()) {
119                    size = controlDefinition.getSize();
120                }
121            }
122    
123            return size;
124        }
125    
126        @Override
127            public Integer getAttributeMinLength(String entryName, String attributeName) {
128            Integer minLength = null;
129    
130            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
131            if (attributeDefinition != null) {
132                minLength = attributeDefinition.getMinLength();
133            }
134    
135            return minLength;
136        }
137    
138        @Override
139            public Integer getAttributeMaxLength(String entryName, String attributeName) {
140            Integer maxLength = null;
141    
142            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
143            if (attributeDefinition != null) {
144                maxLength = attributeDefinition.getMaxLength();
145            }
146    
147            return maxLength;
148        }
149    
150        @Override
151            public String getAttributeExclusiveMin(String entryName, String attributeName) {
152            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
153            return attributeDefinition == null ? null : attributeDefinition.getExclusiveMin();
154        }
155    
156        @Override
157            public String getAttributeInclusiveMax(String entryName, String attributeName) {
158            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
159            return attributeDefinition == null ? null : attributeDefinition.getInclusiveMax();
160        }
161    
162        @Override
163            public Pattern getAttributeValidatingExpression(String entryName, String attributeName) {
164            Pattern regex = null;
165    
166            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
167            if (attributeDefinition != null && (attributeDefinition.getValidationPattern() != null)) {
168                regex = attributeDefinition.getValidationPattern().getRegexPattern();
169            } else {
170                // workaround for existing calls which don't bother checking for null return values
171                regex = Pattern.compile(".*");
172            }
173    
174            return regex;
175        }
176    
177        @Override
178            public String getAttributeLabel(String entryName, String attributeName) {
179            String label = "";
180    
181            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
182            if (attributeDefinition != null) {
183                // KULRICE-4445 prevent NullPointerException by ensuring a label is set
184                label = attributeDefinition.getLabel();
185                if (!StringUtils.isEmpty(attributeDefinition.getDisplayLabelAttribute())) {
186                    attributeDefinition = getAttributeDefinition(entryName, attributeDefinition.getDisplayLabelAttribute());
187                    if (attributeDefinition != null) {
188                        label = attributeDefinition.getLabel();
189                    }
190                }
191            }
192    
193            return label;
194        }
195    
196        @Override
197            public String getAttributeShortLabel(String entryName, String attributeName) {
198            String shortLabel = "";
199    
200            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
201            if (attributeDefinition != null) {
202                if (!StringUtils.isEmpty(attributeDefinition.getDisplayLabelAttribute())) {
203                    attributeDefinition = getAttributeDefinition(entryName, attributeDefinition.getDisplayLabelAttribute());
204                    if (attributeDefinition != null) {
205                        shortLabel = attributeDefinition.getShortLabel();
206                    }
207                } else {
208                    shortLabel = attributeDefinition.getShortLabel();
209                }
210            }
211    
212            return shortLabel;
213        }
214    
215        @Override
216            public String getAttributeErrorLabel(String entryName, String attributeName) {
217            String longAttributeLabel = this.getAttributeLabel(entryName, attributeName);
218            String shortAttributeLabel = this.getAttributeShortLabel(entryName, attributeName);
219            return longAttributeLabel + " (" + shortAttributeLabel + ")";
220        }
221    
222        @Override
223            public Class<? extends Formatter> getAttributeFormatter(String entryName, String attributeName) {
224            Class formatterClass = null;
225    
226            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
227            if (attributeDefinition != null) {
228                if (attributeDefinition.hasFormatterClass()) {
229                    formatterClass = ClassLoaderUtils.getClass(attributeDefinition.getFormatterClass());
230                }
231            }
232    
233            return formatterClass;
234        }
235    
236        @Override
237            public Boolean getAttributeForceUppercase(String entryName,
238                String attributeName) throws UnknownBusinessClassAttributeException {
239            Boolean forceUppercase = null;
240    
241            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
242            if (attributeDefinition == null) {
243                throw new UnknownBusinessClassAttributeException(
244                        "Could not find a matching data dictionary business class attribute entry for " + entryName + "." +
245                                attributeName);
246            }
247            forceUppercase = attributeDefinition.getForceUppercase();
248    
249            return forceUppercase;
250        }
251    
252        @Override
253            public AttributeSecurity getAttributeSecurity(String entryName, String attributeName) {
254            AttributeSecurity attributeSecurity = null;
255    
256            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
257            if (attributeDefinition != null) {
258                attributeSecurity = attributeDefinition.getAttributeSecurity();
259            }
260    
261            return attributeSecurity;
262        }
263    
264        @Override
265            public String getAttributeSummary(String entryName, String attributeName) {
266            String summary = null;
267    
268            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
269            if (attributeDefinition != null) {
270                summary = attributeDefinition.getSummary();
271            }
272    
273            return summary;
274        }
275    
276        /**
277         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeDescription(java.lang.String)
278         */
279        @Override
280            public String getAttributeDescription(String entryName, String attributeName) {
281            String description = null;
282    
283            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
284            if (attributeDefinition != null) {
285                description = attributeDefinition.getDescription();
286            }
287    
288            return description;
289        }
290    
291        /**
292         * @see org.kuali.rice.krad.service.DataDictionaryService#isAttributeRequired(java.lang.Class, java.lang.String)
293         */
294        @Override
295            public Boolean isAttributeRequired(String entryName, String attributeName) {
296            Boolean required = null;
297    
298            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
299            if (attributeDefinition != null) {
300                required = attributeDefinition.isRequired();
301            }
302    
303            return required;
304        }
305    
306        /**
307         * @see org.kuali.rice.krad.service.DataDictionaryService#isAttributeDefined(java.lang.Class, java.lang.String)
308         */
309        @Override
310            public Boolean isAttributeDefined(String entryName, String attributeName) {
311            boolean isDefined = false;
312    
313            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
314            if (attributeDefinition != null) {
315                isDefined = true;
316            }
317    
318            return isDefined;
319        }
320    
321        /**
322         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeValuesScopeId(java.lang.Class,
323         *      java.lang.String)
324         */
325        @Override
326            public Class<? extends KeyValuesFinder> getAttributeValuesFinderClass(String entryName, String attributeName) {
327            Class valuesFinderClass = null;
328    
329            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
330            if (attributeDefinition != null) {
331                String valuesFinderClassName = attributeDefinition.getControl().getValuesFinderClass();
332                valuesFinderClass = ClassLoaderUtils.getClass(valuesFinderClassName);
333            }
334    
335            return valuesFinderClass;
336        }
337    
338        /**
339         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionLabel(java.lang.Class, java.lang.String)
340         */
341        @Override
342            public String getCollectionLabel(String entryName, String collectionName) {
343            String label = "";
344    
345            CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
346            if (collectionDefinition != null) {
347                label = collectionDefinition.getLabel();
348            }
349    
350            return label;
351        }
352    
353        /**
354         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionShortLabel(java.lang.Class, java.lang.String)
355         */
356        @Override
357            public String getCollectionShortLabel(String entryName, String collectionName) {
358            String shortLabel = "";
359    
360            CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
361            if (collectionDefinition != null) {
362                shortLabel = collectionDefinition.getShortLabel();
363            }
364    
365            return shortLabel;
366        }
367    
368        /**
369         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionElementLabel(java.lang.Class,
370         *      java.lang.String)
371         */
372        @Override
373            public String getCollectionElementLabel(String entryName, String collectionName, Class dataObjectClass) {
374            String elementLabel = "";
375    
376            CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
377            if (collectionDefinition != null) {
378                elementLabel = collectionDefinition.getElementLabel();
379                if (StringUtils.isEmpty(elementLabel)) {
380                    BusinessObjectEntry boe = getDataDictionary().getBusinessObjectEntry(dataObjectClass.getName());
381                    if (boe != null) {
382                        elementLabel = boe.getObjectLabel();
383                    }
384                }
385            }
386    
387            return elementLabel;
388        }
389    
390        /**
391         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionSummary(java.lang.Class, java.lang.String)
392         */
393        @Override
394            public String getCollectionSummary(String entryName, String collectionName) {
395            String summary = null;
396    
397            CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
398            if (collectionDefinition != null) {
399                summary = collectionDefinition.getSummary();
400            }
401    
402            return summary;
403        }
404    
405        /**
406         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionDescription(java.lang.Class,
407         *      java.lang.String)
408         */
409        @Override
410            public String getCollectionDescription(String entryName, String collectionName) {
411            String description = null;
412    
413            CollectionDefinition collectionDefinition = getCollectionDefinition(entryName, collectionName);
414            if (collectionDefinition != null) {
415                description = collectionDefinition.getDescription();
416            }
417    
418            return description;
419        }
420    
421        @Override
422            public Class<? extends BusinessObject> getRelationshipSourceClass(String entryName, String relationshipName) {
423            Class sourceClass = null;
424    
425            RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
426            if (rd != null) {
427                sourceClass = rd.getSourceClass();
428            }
429    
430            return sourceClass;
431        }
432    
433        @Override
434            public Class<? extends BusinessObject> getRelationshipTargetClass(String entryName, String relationshipName) {
435            Class targetClass = null;
436    
437            RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
438            if (rd != null) {
439                targetClass = rd.getTargetClass();
440            }
441    
442            return targetClass;
443        }
444    
445        @Override
446            public List<String> getRelationshipSourceAttributes(String entryName, String relationshipName) {
447            List<String> sourceAttributes = null;
448    
449            RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
450            if (rd != null) {
451                sourceAttributes = new ArrayList<String>();
452    
453                for (PrimitiveAttributeDefinition pad : rd.getPrimitiveAttributes()) {
454                    sourceAttributes.add(pad.getSourceName());
455                }
456            }
457    
458            return sourceAttributes;
459        }
460    
461        @Override
462            public List<String> getRelationshipTargetAttributes(String entryName, String relationshipName) {
463            List<String> targetAttributes = null;
464    
465            RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
466            if (rd != null) {
467                targetAttributes = new ArrayList<String>();
468    
469                for (PrimitiveAttributeDefinition pad : rd.getPrimitiveAttributes()) {
470                    targetAttributes.add(pad.getTargetName());
471                }
472            }
473    
474            return targetAttributes;
475        }
476    
477        @Override
478            public List<String> getRelationshipEntriesForSourceAttribute(String entryName, String sourceAttributeName) {
479            List<String> relationships = new ArrayList<String>();
480    
481            DataDictionaryEntryBase entry =
482                    (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
483    
484            for (RelationshipDefinition def : entry.getRelationships()) {
485                for (PrimitiveAttributeDefinition pddef : def.getPrimitiveAttributes()) {
486                    if (StringUtils.equals(sourceAttributeName, pddef.getSourceName())) {
487                        relationships.add(def.getObjectAttributeName());
488                        break;
489                    }
490                }
491            }
492            return relationships;
493        }
494    
495        @Override
496            public List<String> getRelationshipEntriesForTargetAttribute(String entryName, String targetAttributeName) {
497            List<String> relationships = new ArrayList<String>();
498    
499            DataDictionaryEntryBase entry =
500                    (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
501    
502            for (RelationshipDefinition def : entry.getRelationships()) {
503                for (PrimitiveAttributeDefinition pddef : def.getPrimitiveAttributes()) {
504                    if (StringUtils.equals(targetAttributeName, pddef.getTargetName())) {
505                        relationships.add(def.getObjectAttributeName());
506                        break;
507                    }
508                }
509            }
510            return relationships;
511        }
512    
513        /**
514         * @param entryName - the qualified object name e.g. edu.sampleu.demo.kitchensink.TimeInfo
515         * @param attributeName - an attribute name e.g. startTimeAmPm
516         * @return AttributeDefinition for the given dataObjectClass and attribute name, or null if there is none
517         * @throws IllegalArgumentException if the given Class is null or is not a BusinessObject class
518         */
519        @Override
520            public AttributeDefinition getAttributeDefinition(String entryName, String attributeName) {
521            if (StringUtils.isBlank(attributeName)) {
522                throw new IllegalArgumentException("invalid (blank) attributeName");
523            }
524            AttributeDefinition attributeDefinition = null;
525    
526            DataDictionaryEntryBase entry =
527                    (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
528            if (entry != null) {
529                attributeDefinition = entry.getAttributeDefinition(attributeName);
530            }
531    
532            return attributeDefinition;
533        }
534    
535        /**
536         * @param entryName
537         * @param collectionName
538         * @return CollectionDefinition for the given entryName and collectionName, or null if there is none
539         */
540        private CollectionDefinition getCollectionDefinition(String entryName, String collectionName) {
541            if (StringUtils.isBlank(collectionName)) {
542                throw new IllegalArgumentException("invalid (blank) collectionName");
543            }
544            CollectionDefinition collectionDefinition = null;
545    
546            DataDictionaryEntryBase entry =
547                    (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
548            if (entry != null) {
549                collectionDefinition = entry.getCollectionDefinition(collectionName);
550            }
551    
552            return collectionDefinition;
553        }
554    
555        /**
556         * @param entryName
557         * @param relationshipName
558         * @return RelationshipDefinition for the given entryName and relationshipName, or null if there is none
559         */
560        private RelationshipDefinition getRelationshipDefinition(String entryName, String relationshipName) {
561            if (StringUtils.isBlank(relationshipName)) {
562                throw new IllegalArgumentException("invalid (blank) relationshipName");
563            }
564    
565            RelationshipDefinition relationshipDefinition = null;
566    
567            DataDictionaryEntryBase entry =
568                    (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
569            if (entry != null) {
570                relationshipDefinition = entry.getRelationshipDefinition(relationshipName);
571            }
572    
573            return relationshipDefinition;
574        }
575    
576        /**
577         * @see org.kuali.rice.krad.service.DataDictionaryService#getRelationshipAttributeMap(java.lang.String, java.lang.String)
578         */
579        @Override
580            public Map<String, String> getRelationshipAttributeMap(String entryName, String relationshipName) {
581            Map<String, String> attributeMap = new HashMap<String, String>();
582            RelationshipDefinition relationshipDefinition = getRelationshipDefinition(entryName, relationshipName);
583            for (Iterator iter = relationshipDefinition.getPrimitiveAttributes().iterator(); iter.hasNext(); ) {
584                PrimitiveAttributeDefinition attribute = (PrimitiveAttributeDefinition) iter.next();
585                attributeMap.put(attribute.getTargetName(), attribute.getSourceName());
586            }
587            return attributeMap;
588        }
589    
590        @Override
591            public boolean hasRelationship(String entryName, String relationshipName) {
592            return getRelationshipDefinition(entryName, relationshipName) != null;
593        }
594    
595        @Override
596            public List<String> getRelationshipNames(String entryName) {
597            DataDictionaryEntryBase entry =
598                    (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);
599    
600            List<String> relationshipNames = new ArrayList<String>();
601            for (RelationshipDefinition def : entry.getRelationships()) {
602                relationshipNames.add(def.getObjectAttributeName());
603            }
604            return relationshipNames;
605        }
606    
607        /**
608         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeControlDefinition(java.lang.String, java.lang.String)
609         */
610        @Override
611            public ControlDefinition getAttributeControlDefinition(Class dataObjectClass, String attributeName) {
612            return getAttributeControlDefinition(dataObjectClass.getName(), attributeName);
613        }
614    
615        /**
616         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeDescription(java.lang.String, java.lang.String)
617         */
618        @Override
619            public String getAttributeDescription(Class dataObjectClass, String attributeName) {
620            return getAttributeDescription(dataObjectClass.getName(), attributeName);
621        }
622    
623        /**
624         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeForceUppercase(java.lang.String, java.lang.String)
625         */
626        @Override
627            public Boolean getAttributeForceUppercase(Class dataObjectClass, String attributeName) {
628            return getAttributeForceUppercase(dataObjectClass.getName(), attributeName);
629        }
630    
631        /**
632         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeFormatter(java.lang.String, java.lang.String)
633         */
634        @Override
635            public Class<? extends Formatter> getAttributeFormatter(Class dataObjectClass, String attributeName) {
636            return getAttributeFormatter(dataObjectClass.getName(), attributeName);
637        }
638    
639        /**
640         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeLabel(java.lang.String, java.lang.String)
641         */
642        @Override
643            public String getAttributeLabel(Class dataObjectClass, String attributeName) {
644            return getAttributeLabel(dataObjectClass.getName(), attributeName);
645        }
646    
647        /**
648         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeMaxLength(java.lang.String, java.lang.String)
649         */
650        @Override
651            public Integer getAttributeMaxLength(Class dataObjectClass, String attributeName) {
652            return getAttributeMaxLength(dataObjectClass.getName(), attributeName);
653        }
654    
655        /**
656         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeShortLabel(java.lang.String, java.lang.String)
657         */
658        @Override
659            public String getAttributeShortLabel(Class dataObjectClass, String attributeName) {
660            return getAttributeShortLabel(dataObjectClass.getName(), attributeName);
661        }
662    
663        /**
664         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeErrorLabel(java.lang.String, java.lang.String)
665         */
666        @Override
667            public String getAttributeErrorLabel(Class dataObjectClass, String attributeName) {
668            return getAttributeErrorLabel(dataObjectClass.getName(), attributeName);
669        }
670    
671        /**
672         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeSize(java.lang.String, java.lang.String)
673         */
674        @Override
675            public Integer getAttributeSize(Class dataObjectClass, String attributeName) {
676            return getAttributeSize(dataObjectClass.getName(), attributeName);
677        }
678    
679        /**
680         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeSummary(java.lang.String, java.lang.String)
681         */
682        @Override
683            public String getAttributeSummary(Class dataObjectClass, String attributeName) {
684            return getAttributeSummary(dataObjectClass.getName(), attributeName);
685        }
686    
687        /**
688         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingExpression(java.lang.String, java.lang.String)
689         */
690        @Override
691            public Pattern getAttributeValidatingExpression(Class dataObjectClass, String attributeName) {
692            return getAttributeValidatingExpression(dataObjectClass.getName(), attributeName);
693        }
694    
695        /**
696         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeValuesFinderClass(java.lang.String, java.lang.String)
697         */
698        @Override
699            public Class getAttributeValuesFinderClass(Class dataObjectClass, String attributeName) {
700            return getAttributeValuesFinderClass(dataObjectClass.getName(), attributeName);
701        }
702    
703        /**
704         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingErrorMessageKey(java.lang.String, java.lang.String)
705         */
706        @Override
707            public String getAttributeValidatingErrorMessageKey(String entryName, String attributeName) {
708            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
709            if (attributeDefinition != null) {
710                if (attributeDefinition.hasValidationPattern()) {
711                    ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
712                    return validationPattern.getValidationErrorMessageKey();
713                }
714            }
715            return null;
716        }
717    
718        /**
719         * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingErrorMessageParameters(java.lang.String, java.lang.String)
720         */
721        @Override
722            public String[] getAttributeValidatingErrorMessageParameters(String entryName, String attributeName) {
723            AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
724            if (attributeDefinition != null) {
725                if (attributeDefinition.hasValidationPattern()) {
726                    ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
727                    String attributeLabel = getAttributeErrorLabel(entryName, attributeName);
728                    return validationPattern.getValidationErrorMessageParameters(attributeLabel);
729                }
730            }
731            return null;
732        }
733    
734        /**
735         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionDescription(java.lang.String, java.lang.String)
736         */
737        @Override
738            public String getCollectionDescription(Class dataObjectClass, String collectionName) {
739            return getCollectionDescription(dataObjectClass.getName(), collectionName);
740        }
741    
742        /**
743         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionLabel(java.lang.String, java.lang.String)
744         */
745        @Override
746            public String getCollectionLabel(Class dataObjectClass, String collectionName) {
747            return getCollectionLabel(dataObjectClass.getName(), collectionName);
748        }
749    
750        /**
751         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionShortLabel(java.lang.String, java.lang.String)
752         */
753        @Override
754            public String getCollectionShortLabel(Class dataObjectClass, String collectionName) {
755            return getCollectionShortLabel(dataObjectClass.getName(), collectionName);
756        }
757    
758        /**
759         * @see org.kuali.rice.krad.service.DataDictionaryService#getCollectionSummary(java.lang.String, java.lang.String)
760         */
761        @Override
762            public String getCollectionSummary(Class dataObjectClass, String collectionName) {
763            return getCollectionSummary(dataObjectClass.getName(), collectionName);
764        }
765    
766        /**
767         * @see org.kuali.rice.krad.service.DataDictionaryService#isAttributeDefined(java.lang.String, java.lang.String)
768         */
769        @Override
770            public Boolean isAttributeDefined(Class dataObjectClass, String attributeName) {
771            return isAttributeDefined(dataObjectClass.getName(), attributeName);
772        }
773    
774        /**
775         * @see org.kuali.rice.krad.service.DataDictionaryService#isAttributeRequired(java.lang.String, java.lang.String)
776         */
777        @Override
778            public Boolean isAttributeRequired(Class dataObjectClass, String attributeName) {
779            return isAttributeRequired(dataObjectClass.getName(), attributeName);
780        }
781    
782        /**
783         * @see org.kuali.rice.krad.service.DataDictionaryService#getDocumentLabelByClass(java.lang.Class)
784         */
785        @Override
786            public String getDocumentLabelByClass(Class documentOrBusinessObjectClass) {
787            return getDocumentLabelByTypeName(getDocumentTypeNameByClass(documentOrBusinessObjectClass));
788        }
789    
790        /**
791         * @see org.kuali.rice.krad.service.DataDictionaryService#getDocumentLabelByTypeName(java.lang.String)
792         */
793        @Override
794            public String getDocumentLabelByTypeName(String documentTypeName) {
795            String label = null;
796            if (StringUtils.isNotBlank(documentTypeName)) {
797                DocumentType documentType = getDocumentTypeService().getDocumentTypeByName(documentTypeName);
798                if (documentType != null) {
799                    label = documentType.getLabel();
800                }
801            }
802            return label;
803        }
804    
805        /**
806         * @see org.kuali.rice.krad.service.DataDictionaryService#getDocumentTypeNameByClass(java.lang.Class)
807         */
808        @Override
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        @Override
831            public String getValidDocumentTypeNameByClass(Class documentClass) {
832            String documentTypeName = getDocumentTypeNameByClass(documentClass);
833            if (StringUtils.isBlank(documentTypeName)) {
834                throw new UnknownDocumentTypeException(
835                        "unable to get documentTypeName for unknown documentClass '" + documentClass.getName() + "'");
836            }
837            return documentTypeName;
838        }
839    
840        /**
841         * @see org.kuali.rice.krad.service.DataDictionaryService#getDocumentClassByTypeName(java.lang.String)
842         */
843        @Override
844            public Class<? extends Document> getDocumentClassByTypeName(String documentTypeName) {
845            Class clazz = null;
846    
847            DocumentEntry documentEntry = getDataDictionary().getDocumentEntry(documentTypeName);
848            if (documentEntry != null) {
849                clazz = documentEntry.getDocumentClass();
850            }
851    
852            return clazz;
853        }
854    
855        /**
856         * @see org.kuali.rice.krad.service.DataDictionaryService#getValidDocumentClassByTypeName(java.lang.String)
857         */
858        @Override
859            public Class<? extends Document> getValidDocumentClassByTypeName(String documentTypeName) {
860            Class clazz = getDocumentClassByTypeName(documentTypeName);
861            if (clazz == null) {
862                throw new UnknownDocumentTypeException(
863                        "unable to get class for unknown documentTypeName '" + documentTypeName + "'");
864            }
865            return clazz;
866        }
867    
868        /**
869         * @see org.kuali.rice.krad.service.DataDictionaryService#getViewById(java.lang.String)
870         */
871        @Override
872            public View getViewById(String viewId) {
873            return dataDictionary.getViewById(viewId);
874        }
875    
876        /**
877         * @see org.kuali.rice.krad.service.DataDictionaryService#getDictionaryBean(java.lang.String)
878         */
879        @Override
880            public Object getDictionaryBean(String id) {
881            return dataDictionary.getDictionaryBean(id);
882        }
883    
884        /**
885         * @see org.kuali.rice.krad.service.DataDictionaryService#containsDictionaryBean(java.lang.String)
886         */
887        @Override
888            public boolean containsDictionaryBean(String id) {
889            return dataDictionary.containsDictionaryBean(id);
890        }
891    
892        /**
893         * {@inheritDoc}
894         */
895        @Override
896        public Object getDictionaryBeanProperty(String beanName, String propertyName) {
897            return dataDictionary.getDictionaryBeanProperty(beanName, propertyName);
898        }
899    
900        /**
901         * @see org.kuali.rice.krad.service.DataDictionaryService#getViewByTypeIndex(java.lang.String,
902         *      java.util.Map)
903         */
904        @Override
905            public View getViewByTypeIndex(ViewType viewTypeName, Map<String, String> indexKey) {
906            return dataDictionary.getViewByTypeIndex(viewTypeName, indexKey);
907        }
908    
909        /**
910         * @see org.kuali.rice.krad.service.DataDictionaryService#getViewIdByTypeIndex(org.kuali.rice.krad.uif.UifConstants.ViewType,
911         * java.util.Map<java.lang.String,java.lang.String>)
912         */
913        @Override
914            public String getViewIdByTypeIndex(ViewType viewTypeName, Map<String, String> indexKey) {
915            return dataDictionary.getViewIdByTypeIndex(viewTypeName, indexKey);
916        }
917    
918        /**
919         * @see org.kuali.rice.krad.service.DataDictionaryService#getGroupByAttributesForEffectiveDating(java.lang.Class)
920         */
921        @Override
922            public List<String> getGroupByAttributesForEffectiveDating(Class dataObjectClass) {
923            List<String> groupByList = null;
924    
925            DataObjectEntry objectEntry = getDataDictionary().getDataObjectEntry(dataObjectClass.getName());
926            if (objectEntry != null) {
927                groupByList = objectEntry.getGroupByAttributesForEffectiveDating();
928            }
929    
930            return groupByList;
931        }
932    
933        /**
934         * Returns all of the inactivation blocks registered for a particular business object
935         *
936         * @see org.kuali.rice.krad.service.DataDictionaryService#getAllInactivationBlockingDefinitions(java.lang.Class)
937         */
938        @Override
939            public Set<InactivationBlockingMetadata> getAllInactivationBlockingDefinitions(
940                Class inactivationBlockedBusinessObjectClass) {
941            Set<InactivationBlockingMetadata> blockingClasses =
942                    dataDictionary.getAllInactivationBlockingMetadatas(inactivationBlockedBusinessObjectClass);
943            if (blockingClasses == null) {
944                return Collections.emptySet();
945            }
946            return blockingClasses;
947        }
948    
949        public DocumentTypeService getDocumentTypeService() {
950            if (documentTypeService == null) {
951                documentTypeService = KewApiServiceLocator.getDocumentTypeService();
952            }
953            return documentTypeService;
954        }
955    
956        public void setKualiConfigurationService(ConfigurationService kualiConfigurationService) {
957            this.kualiConfigurationService = kualiConfigurationService;
958        }
959    
960        public ConfigurationService getKualiConfigurationService() {
961            return kualiConfigurationService;
962        }
963    
964        public KualiModuleService getKualiModuleService() {
965            return kualiModuleService;
966        }
967    
968        public void setKualiModuleService(KualiModuleService kualiModuleService) {
969            this.kualiModuleService = kualiModuleService;
970        }
971    }