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