| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.datadictionary; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.Collections; |
| 20 | |
import java.util.List; |
| 21 | |
import java.util.Map; |
| 22 | |
import java.util.Set; |
| 23 | |
|
| 24 | |
import org.apache.commons.lang.StringUtils; |
| 25 | |
import org.apache.log4j.Logger; |
| 26 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 27 | |
import org.kuali.rice.kns.service.ModuleService; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 0 | public class DataDictionaryIndexMapper implements DataDictionaryMapper { |
| 36 | 0 | private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class); |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class blockedClass) { |
| 42 | 0 | return index.getInactivationBlockersForClass().get(blockedClass); |
| 43 | |
} |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) { |
| 49 | 0 | List classNames = new ArrayList(); |
| 50 | 0 | classNames.addAll(index.getBusinessObjectEntries().keySet()); |
| 51 | |
|
| 52 | 0 | return Collections.unmodifiableList(classNames); |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) { |
| 59 | 0 | return index.getBusinessObjectEntries(); |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) { |
| 66 | 0 | if (StringUtils.isBlank(className)) { |
| 67 | 0 | throw new IllegalArgumentException("invalid (blank) className"); |
| 68 | |
} |
| 69 | 0 | if (LOG.isDebugEnabled()) { |
| 70 | 0 | LOG.debug("calling getBusinessObjectEntry '" + className + "'"); |
| 71 | |
} |
| 72 | 0 | int index = className.indexOf("$$"); |
| 73 | 0 | if (index >= 0) { |
| 74 | 0 | className = className.substring(0, index); |
| 75 | |
} |
| 76 | 0 | return ddIndex.getBusinessObjectEntries().get(className); |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) { |
| 83 | 0 | if (StringUtils.isBlank(className)) { |
| 84 | 0 | throw new IllegalArgumentException("invalid (blank) className"); |
| 85 | |
} |
| 86 | 0 | if (LOG.isDebugEnabled()) { |
| 87 | 0 | LOG.debug("calling getDictionaryObjectEntry '" + className + "'"); |
| 88 | |
} |
| 89 | 0 | int index = className.indexOf("$$"); |
| 90 | 0 | if (index >= 0) { |
| 91 | 0 | className = className.substring(0, index); |
| 92 | |
} |
| 93 | |
|
| 94 | |
|
| 95 | 0 | DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className); |
| 96 | |
|
| 97 | 0 | if (entry == null) { |
| 98 | 0 | entry = getBusinessObjectEntry(ddIndex, className); |
| 99 | |
} |
| 100 | |
|
| 101 | 0 | if (entry == null) { |
| 102 | 0 | entry = getDocumentEntry(ddIndex, className); |
| 103 | |
} |
| 104 | 0 | return entry; |
| 105 | |
} |
| 106 | |
|
| 107 | |
public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className) { |
| 108 | 0 | BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className); |
| 109 | 0 | if (entry == null) { |
| 110 | 0 | Class boClass = null; |
| 111 | |
try { |
| 112 | 0 | boClass = Class.forName(className); |
| 113 | 0 | ModuleService responsibleModuleService = KNSServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass); |
| 114 | 0 | if (responsibleModuleService != null && responsibleModuleService.isExternalizable(boClass)) { |
| 115 | 0 | return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass); |
| 116 | |
} |
| 117 | 0 | } catch (ClassNotFoundException cnfex) { |
| 118 | 0 | } |
| 119 | 0 | return null; |
| 120 | |
} else { |
| 121 | 0 | return entry; |
| 122 | |
} |
| 123 | |
} |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) { |
| 129 | 0 | return Collections.unmodifiableMap(index.getDocumentEntries()); |
| 130 | |
} |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) { |
| 136 | |
|
| 137 | 0 | if (StringUtils.isBlank(documentTypeDDKey)) { |
| 138 | 0 | throw new IllegalArgumentException("invalid (blank) documentTypeName"); |
| 139 | |
} |
| 140 | 0 | if (LOG.isDebugEnabled()) { |
| 141 | 0 | LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'"); |
| 142 | |
} |
| 143 | |
|
| 144 | 0 | DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey); |
| 145 | |
|
| 146 | 0 | if (de == null) { |
| 147 | |
try { |
| 148 | 0 | Class clazz = Class.forName(documentTypeDDKey); |
| 149 | 0 | de = index.getDocumentEntriesByBusinessObjectClass().get(clazz); |
| 150 | 0 | if (de == null) { |
| 151 | 0 | de = index.getDocumentEntriesByMaintainableClass().get(clazz); |
| 152 | |
} |
| 153 | 0 | } catch (ClassNotFoundException ex) { |
| 154 | 0 | LOG.warn("Unable to find document entry for key: " + documentTypeDDKey); |
| 155 | 0 | } |
| 156 | |
} |
| 157 | |
|
| 158 | 0 | return de; |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
public String getDocumentTypeName(DataDictionaryIndex index, |
| 165 | |
String documentTypeName) { |
| 166 | |
|
| 167 | 0 | return null; |
| 168 | |
} |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class businessObjectClass) { |
| 174 | 0 | if (businessObjectClass == null) { |
| 175 | 0 | throw new IllegalArgumentException("invalid (null) businessObjectClass"); |
| 176 | |
} |
| 177 | 0 | if (LOG.isDebugEnabled()) { |
| 178 | 0 | LOG.debug("calling getDocumentEntry by businessObjectClass '" + businessObjectClass + "'"); |
| 179 | |
} |
| 180 | |
|
| 181 | 0 | return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass); |
| 182 | |
} |
| 183 | |
} |