| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MaintainableFieldDefinition |
|
| 1.2820512820512822;1.282 |
| 1 | /* | |
| 2 | * Copyright 2005-2008 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.kns.datadictionary; | |
| 17 | ||
| 18 | import java.util.List; | |
| 19 | ||
| 20 | import org.apache.commons.lang.StringUtils; | |
| 21 | import org.kuali.rice.kns.bo.BusinessObject; | |
| 22 | import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; | |
| 23 | import org.kuali.rice.kns.lookup.valuefinder.ValueFinder; | |
| 24 | ||
| 25 | /** | |
| 26 | The maintainableField element defines the specifications | |
| 27 | for one data field. | |
| 28 | JSTL: maintainableField is a Map accessed by the field name. | |
| 29 | It contains entries with the following keys: | |
| 30 | * field (boolean String) | |
| 31 | * name (String) | |
| 32 | * required (boolean String) | |
| 33 | ||
| 34 | * name is the name of the field | |
| 35 | * required is true if the field must contain a non-null value | |
| 36 | * readOnly is true if it cannot be updated | |
| 37 | * template documentation from MaintenanceUtils.java: | |
| 38 | Field templates are used in relation to multiple value lookups. | |
| 39 | When doing a MV lookup on a collection, the returned BOs | |
| 40 | are not necessarily of the same type as the elements of the | |
| 41 | collection. Therefore, a means of mapping between the fields | |
| 42 | for the 2 BOs are necessary. The template attribute of | |
| 43 | <maintainableField> contained within <maintainableCollection> | |
| 44 | tells us this mapping. | |
| 45 | Example: | |
| 46 | <maintainableField name="collectionAttrib" template="lookupBOAttrib"> | |
| 47 | means that when a list of BOs are returned, the lookupBOAttrib value | |
| 48 | of the looked up BO will be placed into the collectionAttrib | |
| 49 | value of the BO added to the collection | |
| 50 | * webUILeaveFieldFunction is the name of a javascript function to called when | |
| 51 | when the user tabs out of the field. | |
| 52 | * webUILeaveFieldCallbackFunction | |
| 53 | This is the call javascript function related to the webUILeaveFieldFunction. | |
| 54 | * readOnlyAfterAdd | |
| 55 | This is used to indicate that the field is read-only after the record has been | |
| 56 | initially created. | |
| 57 | */ | |
| 58 | public class MaintainableFieldDefinition extends MaintainableItemDefinition implements FieldDefinitionI{ | |
| 59 | private static final long serialVersionUID = -1176087424343479963L; | |
| 60 | ||
| 61 | 0 | protected boolean required = false; |
| 62 | 0 | protected boolean unconditionallyReadOnly = false; |
| 63 | 0 | protected boolean readOnlyAfterAdd = false; |
| 64 | 0 | protected boolean noLookup = false; |
| 65 | 0 | protected boolean lookupReadOnly = false; |
| 66 | ||
| 67 | protected String defaultValue; | |
| 68 | protected String template; | |
| 69 | protected Class<? extends ValueFinder> defaultValueFinderClass; | |
| 70 | ||
| 71 | 0 | protected String webUILeaveFieldFunction = ""; |
| 72 | 0 | protected String webUILeaveFieldCallbackFunction = ""; |
| 73 | protected List<String> webUILeaveFieldFunctionParameters; | |
| 74 | ||
| 75 | protected Class<? extends BusinessObject> overrideLookupClass; | |
| 76 | protected String overrideFieldConversions; | |
| 77 | ||
| 78 | protected String alternateDisplayAttributeName; | |
| 79 | protected String additionalDisplayAttributeName; | |
| 80 | ||
| 81 | protected boolean triggerOnChange; | |
| 82 | ||
| 83 | 0 | protected Boolean showFieldLevelHelp = null; // use default from system |
| 84 | 0 | protected String fieldLevelHelpUrl = null; |
| 85 | ||
| 86 | 0 | public MaintainableFieldDefinition() {} |
| 87 | ||
| 88 | /** | |
| 89 | * @return true if this attribute is required | |
| 90 | */ | |
| 91 | public boolean isRequired() { | |
| 92 | 0 | return required; |
| 93 | } | |
| 94 | ||
| 95 | /** | |
| 96 | required is true if the field must contain a non-null value | |
| 97 | */ | |
| 98 | public void setRequired(boolean required) { | |
| 99 | 0 | this.required = required; |
| 100 | 0 | } |
| 101 | ||
| 102 | /** | |
| 103 | * @return Returns the defaultValue. | |
| 104 | */ | |
| 105 | public String getDefaultValue() { | |
| 106 | 0 | return defaultValue; |
| 107 | } | |
| 108 | ||
| 109 | ||
| 110 | /** | |
| 111 | * | |
| 112 | The defaultValue element will pre-load the specified value | |
| 113 | into the lookup field. | |
| 114 | */ | |
| 115 | public void setDefaultValue(String defaultValue) { | |
| 116 | 0 | this.defaultValue = defaultValue; |
| 117 | 0 | } |
| 118 | ||
| 119 | ||
| 120 | /** | |
| 121 | * @return custom defaultValue class | |
| 122 | */ | |
| 123 | public Class<? extends ValueFinder> getDefaultValueFinderClass() { | |
| 124 | 0 | return defaultValueFinderClass; |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * @return the unconditionallyReadOnly | |
| 129 | */ | |
| 130 | public boolean isUnconditionallyReadOnly() { | |
| 131 | 0 | return this.unconditionallyReadOnly; |
| 132 | } | |
| 133 | ||
| 134 | /** | |
| 135 | * @param unconditionallyReadOnly the unconditionallyReadOnly to set | |
| 136 | */ | |
| 137 | public void setUnconditionallyReadOnly(boolean unconditionallyReadOnly) { | |
| 138 | 0 | this.unconditionallyReadOnly = unconditionallyReadOnly; |
| 139 | 0 | } |
| 140 | ||
| 141 | /** | |
| 142 | * Gets the overrideFieldConversions attribute. | |
| 143 | * @return Returns the overrideFieldConversions. | |
| 144 | */ | |
| 145 | public String getOverrideFieldConversions() { | |
| 146 | 0 | return overrideFieldConversions; |
| 147 | } | |
| 148 | ||
| 149 | ||
| 150 | /** | |
| 151 | * Single value lookups expect field conversions to be passed in as a HTTP parameter when the lookups is invoked from a quickfinder icon (i.e. magnifying glass on page). | |
| 152 | Field conversions are normally used to determine which fields will be returned when the "return value" link is clicked. | |
| 153 | ||
| 154 | For example, if we're performing a quickfinder lookup and the field conversion string "a:document.someObject.a1,b:document.someObject.b1" is passed into the lookup, | |
| 155 | this means that when we click on a lookup result row to be returned: | |
| 156 | ||
| 157 | * the value of property "a" from the selected result bo will be passed as the value of the HTTP parameter named "document.someObject.a1", | |
| 158 | which, in turn, populates the POJO property of the same name on the form | |
| 159 | * the value of property "b" from the selected result bo will be passed as the value of the HTTP parameter named "document.someObject.b1", | |
| 160 | which, in turn, populates the POJO property of the same name on the form | |
| 161 | ||
| 162 | Normally, the field conversion string is automatically computed by the framework to return all of the primary key values of the looked up BO into the corresponding | |
| 163 | foreign key values of the destination BO (i.e. document.someObject in the example above). However, putting in this element will allow for the overriding of the | |
| 164 | field conversions string. | |
| 165 | */ | |
| 166 | public void setOverrideFieldConversions(String overrideFieldConversions) { | |
| 167 | 0 | this.overrideFieldConversions = overrideFieldConversions; |
| 168 | 0 | } |
| 169 | ||
| 170 | ||
| 171 | /** | |
| 172 | * Gets the overrideLookupClass attribute. | |
| 173 | * @return Returns the overrideLookupClass. | |
| 174 | */ | |
| 175 | public Class<? extends BusinessObject> getOverrideLookupClass() { | |
| 176 | 0 | return overrideLookupClass; |
| 177 | } | |
| 178 | ||
| 179 | ||
| 180 | ||
| 181 | ||
| 182 | /** | |
| 183 | * Directly validate simple fields. | |
| 184 | * | |
| 185 | * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object) | |
| 186 | */ | |
| 187 | public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { | |
| 188 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getName())) { |
| 189 | 0 | throw new AttributeValidationException("unable to find attribute or collection named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
| 190 | } | |
| 191 | ||
| 192 | 0 | if (StringUtils.isNotBlank(getAlternateDisplayAttributeName())) { |
| 193 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAlternateDisplayAttributeName())) { |
| 194 | 0 | throw new AttributeValidationException("unable to find attribute or collection named '" + getAlternateDisplayAttributeName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
| 195 | } | |
| 196 | } | |
| 197 | ||
| 198 | 0 | if (StringUtils.isNotBlank(getAdditionalDisplayAttributeName())) { |
| 199 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAdditionalDisplayAttributeName())) { |
| 200 | 0 | throw new AttributeValidationException("unable to find attribute or collection named '" + getAdditionalDisplayAttributeName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
| 201 | } | |
| 202 | } | |
| 203 | ||
| 204 | 0 | if (defaultValueFinderClass != null && defaultValue != null) { |
| 205 | 0 | throw new AttributeValidationException("Both defaultValue and defaultValueFinderClass can not be specified on attribute " + getName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName()); |
| 206 | } | |
| 207 | 0 | } |
| 208 | ||
| 209 | /** | |
| 210 | * @see java.lang.Object#toString() | |
| 211 | */ | |
| 212 | public String toString() { | |
| 213 | 0 | return "MaintainableFieldDefinition for field " + getName(); |
| 214 | } | |
| 215 | ||
| 216 | ||
| 217 | public String getTemplate() { | |
| 218 | 0 | return template; |
| 219 | } | |
| 220 | ||
| 221 | ||
| 222 | /** | |
| 223 | template documentation from MaintenanceUtils.java: | |
| 224 | Field templates are used in relation to multiple value lookups. | |
| 225 | When doing a MV lookup on a collection, the returned BOs | |
| 226 | are not necessarily of the same type as the elements of the | |
| 227 | collection. Therefore, a means of mapping between the fields | |
| 228 | for the 2 BOs are necessary. The template attribute of | |
| 229 | <maintainableField> contained within <maintainableCollection> | |
| 230 | tells us this mapping. | |
| 231 | Example: | |
| 232 | <maintainableField name="collectionAttrib" template="lookupBOAttrib"> | |
| 233 | means that when a list of BOs are returned, the lookupBOAttrib value | |
| 234 | of the looked up BO will be placed into the collectionAttrib | |
| 235 | value of the BO added to the collection | |
| 236 | */ | |
| 237 | public void setTemplate(String template) { | |
| 238 | 0 | this.template = template; |
| 239 | 0 | } |
| 240 | ||
| 241 | ||
| 242 | public String getWebUILeaveFieldCallbackFunction() { | |
| 243 | 0 | return webUILeaveFieldCallbackFunction; |
| 244 | } | |
| 245 | ||
| 246 | ||
| 247 | /** | |
| 248 | * webUILeaveFieldCallbackFunction | |
| 249 | This is the call javascript function related to the webUILeaveFieldFunction. | |
| 250 | */ | |
| 251 | public void setWebUILeaveFieldCallbackFunction(String webUILeaveFieldCallbackFunction) { | |
| 252 | 0 | this.webUILeaveFieldCallbackFunction = webUILeaveFieldCallbackFunction; |
| 253 | 0 | } |
| 254 | ||
| 255 | ||
| 256 | public String getWebUILeaveFieldFunction() { | |
| 257 | 0 | return webUILeaveFieldFunction; |
| 258 | } | |
| 259 | ||
| 260 | ||
| 261 | /** | |
| 262 | * webUILeaveFieldFunction is the name of a javascript function to called when | |
| 263 | when the user tabs out of the field. | |
| 264 | */ | |
| 265 | public void setWebUILeaveFieldFunction(String webUILeaveFieldFunction) { | |
| 266 | 0 | this.webUILeaveFieldFunction = webUILeaveFieldFunction; |
| 267 | 0 | } |
| 268 | ||
| 269 | ||
| 270 | public boolean isReadOnlyAfterAdd() { | |
| 271 | 0 | return readOnlyAfterAdd; |
| 272 | } | |
| 273 | ||
| 274 | ||
| 275 | /** | |
| 276 | * This is used to indicate that the field is read-only after the record has been | |
| 277 | initially created. | |
| 278 | */ | |
| 279 | public void setReadOnlyAfterAdd(boolean readOnlyAfterAdd) { | |
| 280 | 0 | this.readOnlyAfterAdd = readOnlyAfterAdd; |
| 281 | 0 | } |
| 282 | ||
| 283 | ||
| 284 | /** | |
| 285 | The defaultValueFinderClass specifies the java class that will be | |
| 286 | used to determine the default value of a lookup field. The classname | |
| 287 | specified in this field must implement org.kuali.rice.kns.lookup.valuefinder.ValueFinder | |
| 288 | */ | |
| 289 | public void setDefaultValueFinderClass(Class<? extends ValueFinder> defaultValueFinderClass) { | |
| 290 | 0 | this.defaultValueFinderClass = defaultValueFinderClass; |
| 291 | 0 | } |
| 292 | ||
| 293 | ||
| 294 | /** | |
| 295 | * The overrideLookupClass element is used to indicate the | |
| 296 | class that should be used for the magnifying glass lookup. | |
| 297 | The specified class must be a subclass of the business object | |
| 298 | class. | |
| 299 | */ | |
| 300 | public void setOverrideLookupClass(Class<? extends BusinessObject> overrideLookupClass) { | |
| 301 | 0 | this.overrideLookupClass = overrideLookupClass; |
| 302 | 0 | } |
| 303 | ||
| 304 | /** | |
| 305 | * @return the noLookup | |
| 306 | */ | |
| 307 | public boolean isNoLookup() { | |
| 308 | 0 | return this.noLookup; |
| 309 | } | |
| 310 | ||
| 311 | /** | |
| 312 | * @param noLookup the noLookup to set | |
| 313 | */ | |
| 314 | public void setNoLookup(boolean noLookup) { | |
| 315 | 0 | this.noLookup = noLookup; |
| 316 | 0 | } |
| 317 | ||
| 318 | public boolean isLookupReadOnly() { | |
| 319 | 0 | return lookupReadOnly; |
| 320 | } | |
| 321 | ||
| 322 | public void setLookupReadOnly(boolean lookupReadOnly) { | |
| 323 | 0 | this.lookupReadOnly = lookupReadOnly; |
| 324 | 0 | } |
| 325 | ||
| 326 | public Boolean isShowFieldLevelHelp() { | |
| 327 | 0 | return showFieldLevelHelp; |
| 328 | } | |
| 329 | ||
| 330 | public void setShowFieldLevelHelp(Boolean showFieldLevelHelp) { | |
| 331 | 0 | this.showFieldLevelHelp = showFieldLevelHelp; |
| 332 | 0 | } |
| 333 | ||
| 334 | public String getFieldLevelHelpUrl() { | |
| 335 | 0 | return fieldLevelHelpUrl; |
| 336 | } | |
| 337 | ||
| 338 | public void setFieldLevelHelpUrl(String fieldLevelHelpUrl) { | |
| 339 | 0 | this.fieldLevelHelpUrl = fieldLevelHelpUrl; |
| 340 | 0 | } |
| 341 | ||
| 342 | /** | |
| 343 | * The alternateDisplayAttributeName is the name of the attribute whose value will be displayed instead | |
| 344 | * of the actual maintenance field attribute. Only applies when field is read-only. | |
| 345 | */ | |
| 346 | public String getAlternateDisplayAttributeName() { | |
| 347 | 0 | return this.alternateDisplayAttributeName; |
| 348 | } | |
| 349 | ||
| 350 | public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) { | |
| 351 | 0 | this.alternateDisplayAttributeName = alternateDisplayAttributeName; |
| 352 | 0 | } |
| 353 | ||
| 354 | /** | |
| 355 | * The additionalDisplayAttributeName is the name of the attribute whose value will be displayed in addition | |
| 356 | * to the actual maintenance field attribute. Only applies when field is read-only. | |
| 357 | */ | |
| 358 | public String getAdditionalDisplayAttributeName() { | |
| 359 | 0 | return this.additionalDisplayAttributeName; |
| 360 | } | |
| 361 | ||
| 362 | public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) { | |
| 363 | 0 | this.additionalDisplayAttributeName = additionalDisplayAttributeName; |
| 364 | 0 | } |
| 365 | ||
| 366 | public boolean isTriggerOnChange() { | |
| 367 | 0 | return this.triggerOnChange; |
| 368 | } | |
| 369 | ||
| 370 | public void setTriggerOnChange(boolean triggerOnChange) { | |
| 371 | 0 | this.triggerOnChange = triggerOnChange; |
| 372 | 0 | } |
| 373 | ||
| 374 | /** | |
| 375 | * @return the webUILeaveFieldFunctionParameters | |
| 376 | */ | |
| 377 | public List<String> getWebUILeaveFieldFunctionParameters() { | |
| 378 | 0 | return this.webUILeaveFieldFunctionParameters; |
| 379 | } | |
| 380 | ||
| 381 | /** | |
| 382 | * @param webUILeaveFieldFunctionParameters the webUILeaveFieldFunctionParameters to set | |
| 383 | */ | |
| 384 | public void setWebUILeaveFieldFunctionParameters( | |
| 385 | List<String> webUILeaveFieldFunctionParameters) { | |
| 386 | 0 | this.webUILeaveFieldFunctionParameters = webUILeaveFieldFunctionParameters; |
| 387 | 0 | } |
| 388 | ||
| 389 | } |