| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.datadictionary; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.log4j.Logger; |
| 20 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
| 21 | |
import org.kuali.rice.krad.service.ModuleService; |
| 22 | |
import org.kuali.rice.krad.uif.container.View; |
| 23 | |
|
| 24 | |
import java.util.ArrayList; |
| 25 | |
import java.util.Collections; |
| 26 | |
import java.util.List; |
| 27 | |
import java.util.Map; |
| 28 | |
import java.util.Set; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 0 | public class DataDictionaryIndexMapper implements DataDictionaryMapper { |
| 37 | 0 | private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class); |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class<?> blockedClass) { |
| 43 | 0 | return index.getInactivationBlockersForClass().get(blockedClass); |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) { |
| 50 | 0 | List classNames = new ArrayList(); |
| 51 | 0 | classNames.addAll(index.getBusinessObjectEntries().keySet()); |
| 52 | |
|
| 53 | 0 | return Collections.unmodifiableList(classNames); |
| 54 | |
} |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) { |
| 60 | 0 | return index.getBusinessObjectEntries(); |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
@Override |
| 67 | |
public DataObjectEntry getDataObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) { |
| 68 | 0 | if (StringUtils.isBlank(className)) { |
| 69 | 0 | throw new IllegalArgumentException("invalid (blank) className"); |
| 70 | |
} |
| 71 | 0 | if ( LOG.isDebugEnabled() ) { |
| 72 | 0 | LOG.debug("calling getDataObjectEntry '" + className + "'"); |
| 73 | |
} |
| 74 | |
|
| 75 | 0 | String trimmedClassName = className; |
| 76 | 0 | int index = className.indexOf("$$"); |
| 77 | 0 | if (index >= 0) { |
| 78 | 0 | trimmedClassName = className.substring(0, index); |
| 79 | |
} |
| 80 | 0 | return ddIndex.getDataObjectEntries().get(trimmedClassName); |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) { |
| 87 | 0 | if (StringUtils.isBlank(className)) { |
| 88 | 0 | throw new IllegalArgumentException("invalid (blank) className"); |
| 89 | |
} |
| 90 | 0 | if ( LOG.isDebugEnabled() ) { |
| 91 | 0 | LOG.debug("calling getBusinessObjectEntry '" + className + "'"); |
| 92 | |
} |
| 93 | 0 | int index = className.indexOf("$$"); |
| 94 | 0 | if (index >= 0) { |
| 95 | 0 | className = className.substring(0, index); |
| 96 | |
} |
| 97 | 0 | return ddIndex.getBusinessObjectEntries().get(className); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) { |
| 104 | 0 | if (StringUtils.isBlank(className)) { |
| 105 | 0 | throw new IllegalArgumentException("invalid (blank) className"); |
| 106 | |
} |
| 107 | 0 | if ( LOG.isDebugEnabled() ) { |
| 108 | 0 | LOG.debug("calling getDictionaryObjectEntry '" + className + "'"); |
| 109 | |
} |
| 110 | 0 | int index = className.indexOf("$$"); |
| 111 | 0 | if (index >= 0) { |
| 112 | 0 | className = className.substring(0, index); |
| 113 | |
} |
| 114 | |
|
| 115 | |
|
| 116 | 0 | DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className); |
| 117 | |
|
| 118 | |
|
| 119 | 0 | if (entry == null){ |
| 120 | 0 | entry = ddIndex.getDataObjectEntries().get(className); |
| 121 | |
} |
| 122 | |
|
| 123 | 0 | if ( entry == null ) { |
| 124 | 0 | entry = getDocumentEntry(ddIndex, className); |
| 125 | |
} |
| 126 | 0 | return entry; |
| 127 | |
} |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
@Override |
| 133 | |
public DataObjectEntry getDataObjectEntry(DataDictionaryIndex index, String className) { |
| 134 | 0 | DataObjectEntry entry = getDataObjectEntryForConcreteClass(index, className); |
| 135 | |
|
| 136 | 0 | if (entry == null) { |
| 137 | 0 | Class<?> boClass = null; |
| 138 | |
try{ |
| 139 | 0 | boClass = Class.forName(className); |
| 140 | 0 | ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass); |
| 141 | 0 | if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) { |
| 142 | 0 | entry = responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass); |
| 143 | |
} |
| 144 | 0 | } catch(ClassNotFoundException cnfex){ |
| 145 | |
|
| 146 | 0 | } |
| 147 | |
} |
| 148 | |
|
| 149 | 0 | return entry; |
| 150 | |
} |
| 151 | |
|
| 152 | |
public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) { |
| 153 | 0 | BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className); |
| 154 | 0 | if (entry == null) { |
| 155 | 0 | Class boClass = null; |
| 156 | |
try{ |
| 157 | 0 | boClass = Class.forName(className); |
| 158 | 0 | ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass); |
| 159 | 0 | if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) { |
| 160 | 0 | return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass); |
| 161 | |
} |
| 162 | 0 | } catch(ClassNotFoundException cnfex){ |
| 163 | 0 | } |
| 164 | 0 | return null; |
| 165 | |
} |
| 166 | |
else { |
| 167 | 0 | return entry; |
| 168 | |
} |
| 169 | |
} |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) { |
| 175 | 0 | return Collections.unmodifiableMap(index.getDocumentEntries()); |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) { |
| 182 | |
|
| 183 | 0 | if (StringUtils.isBlank(documentTypeDDKey)) { |
| 184 | 0 | throw new IllegalArgumentException("invalid (blank) documentTypeName"); |
| 185 | |
} |
| 186 | 0 | if ( LOG.isDebugEnabled() ) { |
| 187 | 0 | LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'"); |
| 188 | |
} |
| 189 | |
|
| 190 | 0 | DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey); |
| 191 | |
|
| 192 | 0 | if ( de == null ) { |
| 193 | |
try { |
| 194 | 0 | Class<?> clazz = Class.forName( documentTypeDDKey ); |
| 195 | 0 | de = index.getDocumentEntriesByBusinessObjectClass().get(clazz); |
| 196 | 0 | if ( de == null ) { |
| 197 | 0 | de = index.getDocumentEntriesByMaintainableClass().get(clazz); |
| 198 | |
} |
| 199 | 0 | } catch ( ClassNotFoundException ex ) { |
| 200 | 0 | LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey ); |
| 201 | 0 | } |
| 202 | |
} |
| 203 | |
|
| 204 | 0 | return de; |
| 205 | |
} |
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
public String getDocumentTypeName(DataDictionaryIndex index, |
| 211 | |
String documentTypeName) { |
| 212 | |
|
| 213 | 0 | return null; |
| 214 | |
} |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class<?> businessObjectClass) { |
| 220 | 0 | if (businessObjectClass == null) { |
| 221 | 0 | throw new IllegalArgumentException("invalid (null) dataObjectClass"); |
| 222 | |
} |
| 223 | 0 | if ( LOG.isDebugEnabled() ) { |
| 224 | 0 | LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'"); |
| 225 | |
} |
| 226 | |
|
| 227 | 0 | return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass); |
| 228 | |
} |
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
public View getViewById(UifDictionaryIndex index, String viewId) { |
| 235 | 0 | if (StringUtils.isBlank(viewId)) { |
| 236 | 0 | throw new IllegalArgumentException("invalid (blank) view id"); |
| 237 | |
} |
| 238 | 0 | if (LOG.isDebugEnabled()) { |
| 239 | 0 | LOG.debug("calling getViewById by id '" + viewId + "'"); |
| 240 | |
} |
| 241 | |
|
| 242 | 0 | return index.getViewById(viewId); |
| 243 | |
} |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
public View getViewByTypeIndex(UifDictionaryIndex index, String viewTypeName, Map<String, String> indexKey) { |
| 250 | 0 | if (StringUtils.isBlank(viewTypeName)) { |
| 251 | 0 | throw new IllegalArgumentException("invalid (blank) view type name"); |
| 252 | |
} |
| 253 | 0 | if ((indexKey == null) || indexKey.isEmpty()) { |
| 254 | 0 | throw new IllegalArgumentException("index key must have at least one entry"); |
| 255 | |
} |
| 256 | |
|
| 257 | 0 | return index.getViewByTypeIndex(viewTypeName, indexKey); |
| 258 | |
} |
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
public List<View> getViewsForType(UifDictionaryIndex index, String viewTypeName) { |
| 265 | 0 | if (StringUtils.isBlank(viewTypeName)) { |
| 266 | 0 | throw new IllegalArgumentException("invalid (blank) view type name"); |
| 267 | |
} |
| 268 | |
|
| 269 | 0 | return index.getViewsForType(viewTypeName); |
| 270 | |
} |
| 271 | |
|
| 272 | |
} |