001/**
002 * Copyright 2005-2016 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.kns.datadictionary;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.bo.BusinessObject;
020import org.kuali.rice.krad.datadictionary.DataDictionary;
021import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
022import org.kuali.rice.krad.valuefinder.ValueFinder;
023
024import java.util.List;
025
026/**
027    The maintainableField element defines the specifications
028    for one data field.
029    JSTL: maintainableField is a Map accessed by the field name.
030    It contains entries with the following keys:
031        * field (boolean String)
032        * name (String)
033        * required (boolean String)
034
035    * name is the name of the field
036    * required is true if the field must contain a non-null value
037    * readOnly is true if it cannot be updated
038    * template documentation from MaintenanceUtils.java:
039        Field templates are used in relation to multiple value lookups.
040        When doing a MV lookup on a collection, the returned BOs
041        are not necessarily of the same type as the elements of the
042        collection. Therefore, a means of mapping between the fields
043        for the 2 BOs are necessary. The template attribute of
044        <maintainableField> contained within <maintainableCollection>
045        tells us this mapping.
046        Example:
047        <maintainableField name="collectionAttrib" template="lookupBOAttrib">
048        means that when a list of BOs are returned, the lookupBOAttrib value
049        of the looked up BO will be placed into the collectionAttrib
050        value of the BO added to the collection
051    * webUILeaveFieldFunction is the name of a javascript function to called when
052        when the user tabs out of the field.
053    * webUILeaveFieldCallbackFunction
054        This is the call javascript function related to the webUILeaveFieldFunction.
055    * readOnlyAfterAdd
056        This is used to indicate that the field is read-only after the record has been
057        initially created.
058 */
059@Deprecated
060public class MaintainableFieldDefinition extends MaintainableItemDefinition implements FieldDefinitionI{
061    private static final long serialVersionUID = -1176087424343479963L;
062    
063        protected boolean required = false;
064    protected boolean unconditionallyReadOnly = false;
065    protected boolean readOnlyAfterAdd = false;
066    protected boolean noLookup = false;
067    protected boolean lookupReadOnly = false;
068    
069    protected String defaultValue;
070    protected String template;
071    protected Class<? extends ValueFinder> defaultValueFinderClass;
072
073    protected String webUILeaveFieldFunction = "";
074    protected String webUILeaveFieldCallbackFunction = "";
075    protected List<String> webUILeaveFieldFunctionParameters;
076
077    protected Class<? extends BusinessObject> overrideLookupClass;
078    protected String overrideFieldConversions;
079    
080    protected String alternateDisplayAttributeName;
081    protected String additionalDisplayAttributeName;
082    
083    protected boolean triggerOnChange;
084    
085    protected Boolean showFieldLevelHelp = null; // use default from system
086    protected String fieldLevelHelpUrl = null;
087    
088    public MaintainableFieldDefinition() {}
089
090    /**
091     * @return true if this attribute is required
092     */
093    public boolean isRequired() {
094        return required;
095    }
096
097    /**
098required is true if the field must contain a non-null value
099     */
100    public void setRequired(boolean required) {
101        this.required = required;
102    }
103
104    /**
105     * @return Returns the defaultValue.
106     */
107    public String getDefaultValue() {
108        return defaultValue;
109    }
110
111
112    /**
113     * 
114                       The defaultValue element will pre-load the specified value
115                       into the lookup field.
116     */
117    public void setDefaultValue(String defaultValue) {
118        this.defaultValue = defaultValue;
119    }
120
121
122    /**
123     * @return custom defaultValue class
124     */
125    public Class<? extends ValueFinder> getDefaultValueFinderClass() {
126        return defaultValueFinderClass;
127    }
128
129    /**
130         * @return the unconditionallyReadOnly
131         */
132        public boolean isUnconditionallyReadOnly() {
133                return this.unconditionallyReadOnly;
134        }
135
136        /**
137         * @param unconditionallyReadOnly the unconditionallyReadOnly to set
138         */
139        public void setUnconditionallyReadOnly(boolean unconditionallyReadOnly) {
140                this.unconditionallyReadOnly = unconditionallyReadOnly;
141        }
142
143    /**
144     * Gets the overrideFieldConversions attribute. 
145     * @return Returns the overrideFieldConversions.
146     */
147    public String getOverrideFieldConversions() {
148        return overrideFieldConversions;
149    }
150
151
152    /**
153     * 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).
154                        Field conversions are normally used to determine which fields will be returned when the "return value" link is clicked.
155
156                        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,
157                        this means that when we click on a lookup result row to be returned:
158
159                        * the value of property "a" from the selected result bo will be passed as the value of the HTTP parameter named "document.someObject.a1",
160                          which, in turn, populates the POJO property of the same name on the form
161                        * the value of property "b" from the selected result bo will be passed as the value of the HTTP parameter named "document.someObject.b1",
162                          which, in turn, populates the POJO property of the same name on the form
163
164                        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
165                        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
166                        field conversions string.
167     */
168    public void setOverrideFieldConversions(String overrideFieldConversions) {
169        this.overrideFieldConversions = overrideFieldConversions;
170    }
171
172
173    /**
174     * Gets the overrideLookupClass attribute. 
175     * @return Returns the overrideLookupClass.
176     */
177    public Class<? extends BusinessObject> getOverrideLookupClass() {
178        return overrideLookupClass;
179    }
180
181
182
183
184    /**
185     * Directly validate simple fields.
186     * 
187     * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
188     */
189    public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
190        if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getName())) {
191            throw new AttributeValidationException("unable to find attribute or collection named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
192        }
193
194        if (StringUtils.isNotBlank(getAlternateDisplayAttributeName())) {
195            if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAlternateDisplayAttributeName())) {
196                throw new AttributeValidationException("unable to find attribute or collection named '" + getAlternateDisplayAttributeName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
197            }
198        }
199        
200        if (StringUtils.isNotBlank(getAdditionalDisplayAttributeName())) {
201            if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAdditionalDisplayAttributeName())) {
202                throw new AttributeValidationException("unable to find attribute or collection named '" + getAdditionalDisplayAttributeName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
203            }
204        }
205
206        if (defaultValueFinderClass != null && defaultValue != null) {
207            throw new AttributeValidationException("Both defaultValue and defaultValueFinderClass can not be specified on attribute " + getName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
208        }
209   }
210
211    /**
212     * @see java.lang.Object#toString()
213     */
214    public String toString() {
215        return "MaintainableFieldDefinition for field " + getName();
216    }
217
218
219    public String getTemplate() {
220        return template;
221    }
222
223
224    /**
225template documentation from MaintenanceUtils.java:
226                            Field templates are used in relation to multiple value lookups.
227                            When doing a MV lookup on a collection, the returned BOs
228                            are not necessarily of the same type as the elements of the
229                            collection. Therefore, a means of mapping between the fields
230                            for the 2 BOs are necessary. The template attribute of
231                            <maintainableField> contained within <maintainableCollection>
232                            tells us this mapping.
233                            Example:
234                            <maintainableField name="collectionAttrib" template="lookupBOAttrib">
235                            means that when a list of BOs are returned, the lookupBOAttrib value
236                            of the looked up BO will be placed into the collectionAttrib
237                            value of the BO added to the collection
238 */
239    public void setTemplate(String template) {
240        this.template = template;
241    }
242
243
244    public String getWebUILeaveFieldCallbackFunction() {
245        return webUILeaveFieldCallbackFunction;
246    }
247
248
249    /**
250                        * webUILeaveFieldCallbackFunction
251                            This is the call javascript function related to the webUILeaveFieldFunction.
252     */
253    public void setWebUILeaveFieldCallbackFunction(String webUILeaveFieldCallbackFunction) {
254        this.webUILeaveFieldCallbackFunction = webUILeaveFieldCallbackFunction;
255    }
256
257
258    public String getWebUILeaveFieldFunction() {
259        return webUILeaveFieldFunction;
260    }
261
262
263    /**
264                        * webUILeaveFieldFunction is the name of a javascript function to called when
265                            when the user tabs out of the field.
266     */
267    public void setWebUILeaveFieldFunction(String webUILeaveFieldFunction) {
268        this.webUILeaveFieldFunction = webUILeaveFieldFunction;
269    }
270
271
272    public boolean isReadOnlyAfterAdd() {
273        return readOnlyAfterAdd;
274    }
275
276
277    /**
278     * This is used to indicate that the field is read-only after the record has been
279                            initially created.
280     */
281    public void setReadOnlyAfterAdd(boolean readOnlyAfterAdd) {
282        this.readOnlyAfterAdd = readOnlyAfterAdd;
283    }
284
285
286    /**
287The defaultValueFinderClass specifies the java class that will be
288                      used to determine the default value of a lookup field.  The classname
289                      specified in this field must implement ValueFinder
290   */
291    public void setDefaultValueFinderClass(Class<? extends ValueFinder> defaultValueFinderClass) {
292        this.defaultValueFinderClass = defaultValueFinderClass;
293    }
294
295
296    /**
297     * The overrideLookupClass element is used to indicate the
298                        class that should be used for the magnifying glass lookup.
299                        The specified class must be a subclass of the business object
300                        class.
301     */
302    public void setOverrideLookupClass(Class<? extends BusinessObject> overrideLookupClass) {
303        this.overrideLookupClass = overrideLookupClass;
304    }
305    
306        /**
307         * @return the noLookup
308         */
309        public boolean isNoLookup() {
310                return this.noLookup;
311        }
312
313        /**
314         * @param noLookup the noLookup to set
315         */
316        public void setNoLookup(boolean noLookup) {
317                this.noLookup = noLookup;
318        }
319        
320        public boolean isLookupReadOnly() {
321                return lookupReadOnly;
322        }
323    
324        public void setLookupReadOnly(boolean lookupReadOnly) {
325        this.lookupReadOnly = lookupReadOnly;
326    }
327        
328    public Boolean isShowFieldLevelHelp() {
329        return showFieldLevelHelp;
330    }
331
332    public void setShowFieldLevelHelp(Boolean showFieldLevelHelp) {
333        this.showFieldLevelHelp = showFieldLevelHelp;
334    }
335
336    public String getFieldLevelHelpUrl() {
337        return fieldLevelHelpUrl;
338    }
339
340    public void setFieldLevelHelpUrl(String fieldLevelHelpUrl) {
341        this.fieldLevelHelpUrl = fieldLevelHelpUrl;
342    }
343        
344        /**
345         * The alternateDisplayAttributeName is the name of the attribute whose value will be displayed instead
346         * of the actual maintenance field attribute. Only applies when field is read-only.
347         */
348    public String getAlternateDisplayAttributeName() {
349                return this.alternateDisplayAttributeName;
350        }
351
352        public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) {
353                this.alternateDisplayAttributeName = alternateDisplayAttributeName;
354        }
355
356        /**
357         * The additionalDisplayAttributeName is the name of the attribute whose value will be displayed in addition
358         * to the actual maintenance field attribute. Only applies when field is read-only.
359         */
360        public String getAdditionalDisplayAttributeName() {
361                return this.additionalDisplayAttributeName;
362        }
363
364        public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) {
365                this.additionalDisplayAttributeName = additionalDisplayAttributeName;
366        }
367        
368        public boolean isTriggerOnChange() {
369                return this.triggerOnChange;
370        }
371
372        public void setTriggerOnChange(boolean triggerOnChange) {
373                this.triggerOnChange = triggerOnChange;
374        }
375
376        /**
377         * @return the webUILeaveFieldFunctionParameters
378         */
379        public List<String> getWebUILeaveFieldFunctionParameters() {
380                return this.webUILeaveFieldFunctionParameters;
381        }
382
383        /**
384         * @param webUILeaveFieldFunctionParameters the webUILeaveFieldFunctionParameters to set
385         */
386        public void setWebUILeaveFieldFunctionParameters(
387                        List<String> webUILeaveFieldFunctionParameters) {
388                this.webUILeaveFieldFunctionParameters = webUILeaveFieldFunctionParameters;
389        }
390
391}