001/**
002 * Copyright 2005-2018 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.datadictionary;
017
018import java.util.List;
019
020import org.kuali.rice.krad.bo.Exporter;
021import org.kuali.rice.krad.datadictionary.parse.BeanTag;
022import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
023import org.kuali.rice.krad.datadictionary.validation.capability.MustOccurConstrainable;
024import org.kuali.rice.krad.datadictionary.validation.constraint.MustOccurConstraint;
025import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
026import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
027
028/**
029 * Generic dictionary entry for an object that does not have to implement BusinessObject. It provides support
030 * for general objects
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034@BeanTag(name = "dataObjectEntry")
035public class DataObjectEntry extends DataDictionaryEntryBase implements MustOccurConstrainable {
036    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DataObjectEntry.class);
037    private static final long serialVersionUID = 1L;
038
039    protected String name;
040    protected Class<?> dataObjectClass;
041    protected Class<?> baseDataObjectClass;
042
043    protected String titleAttribute;
044    protected String objectLabel;
045    protected String objectDescription;
046
047    protected List<String> primaryKeys;
048    protected Class<? extends Exporter> exporterClass;
049
050    protected List<MustOccurConstraint> mustOccurConstraints;
051
052    protected List<String> groupByAttributesForEffectiveDating;
053
054    protected HelpDefinition helpDefinition;
055
056    protected boolean boNotesEnabled = false;
057
058    protected List<InactivationBlockingDefinition> inactivationBlockingDefinitions;
059
060    @Override
061    public void completeValidation() {
062        completeValidation( new ValidationTrace() );
063    }
064
065    /**
066     * Directly validate simple fields
067     *
068     * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation(org.kuali.rice.krad.datadictionary.validator.ValidationTrace)
069     */
070    @Override
071    public void completeValidation(ValidationTrace tracer) {
072        super.completeValidation(tracer);
073    }
074
075    /**
076     * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#getJstlKey()
077     */
078    @Override
079    public String getJstlKey() {
080        if (dataObjectClass == null) {
081            throw new IllegalStateException("cannot generate JSTL key: dataObjectClass is null");
082        }
083
084        return dataObjectClass.getSimpleName();
085    }
086
087    /**
088     * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#getFullClassName()
089     */
090    @Override
091    public String getFullClassName() {
092        return dataObjectClass.getName();
093    }
094
095    /**
096     * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase#getEntryClass()
097     */
098    @Override
099    public Class<?> getEntryClass() {
100        return dataObjectClass;
101    }
102
103    /**
104     * @return the dataObjectClass
105     */
106    @BeanTagAttribute
107    public Class<?> getDataObjectClass() {
108        return this.dataObjectClass;
109    }
110
111    /**
112     * @param dataObjectClass the dataObjectClass to set
113     */
114    public void setDataObjectClass(Class<?> dataObjectClass) {
115        this.dataObjectClass = dataObjectClass;
116    }
117
118    /**
119     * The baseDataObjectClass is an optional parameter for specifying a base class
120     * for the dataObjectClass, allowing the data dictionary to index by the base class
121     * in addition to the current class.
122     */
123
124    public void setBaseDataObjectClass(Class<?> baseDataObjectClass) {
125        this.baseDataObjectClass = baseDataObjectClass;
126    }
127
128    @BeanTagAttribute(name = "baseDataObjectClass")
129    public Class<?> getBaseDataObjectClass() {
130        return baseDataObjectClass;
131    }
132
133    /**
134     * @return the name
135     */
136    @Override
137    @BeanTagAttribute
138    public String getName() {
139        return this.name;
140    }
141
142    /**
143     * @param name the name to set
144     */
145    public void setName(String name) {
146        this.name = name;
147    }
148
149    /**
150     * @return Returns the objectLabel.
151     */
152    @BeanTagAttribute
153    public String getObjectLabel() {
154        // If the object label was set in the DD, use that
155        if ( objectLabel != null ) {
156            return objectLabel;
157        }
158        // Otherwise, pull what we can from the metadata model
159        if ( getDataObjectMetadata() != null ) {
160            return getDataObjectMetadata().getLabel();
161        }
162        return KRADServiceLocatorWeb.getUifDefaultingService().deriveHumanFriendlyNameFromPropertyName( dataObjectClass.getSimpleName() );
163    }
164
165    /**
166     * The objectLabel provides a short name of the business
167     * object for use on help screens.
168     *
169     * @param objectLabel The objectLabel to set.
170     */
171    public void setObjectLabel(String objectLabel) {
172        this.objectLabel = objectLabel;
173    }
174
175    /**
176     * @return Returns the description.
177     */
178    @BeanTagAttribute
179    public String getObjectDescription() {
180        if ( objectDescription != null ) {
181            return objectDescription;
182        }
183        if ( getDataObjectMetadata() != null ) {
184            return getDataObjectMetadata().getDescription();
185        }
186        return "";
187    }
188
189    /**
190     * The objectDescription provides a brief description
191     * of the business object for use on help screens.
192     *
193     * @param objectDescription The description to set
194     */
195    public void setObjectDescription(String objectDescription) {
196        this.objectDescription = objectDescription;
197    }
198
199    /**
200     * Gets the helpDefinition attribute.
201     *
202     * @return Returns the helpDefinition.
203     */
204    @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
205    public HelpDefinition getHelpDefinition() {
206        return helpDefinition;
207    }
208
209    /**
210     * Sets the helpDefinition attribute value.
211     *
212     * The objectHelp element provides the keys to
213     * obtain a help description from the system parameters table.
214     *
215     * parameterNamespace the namespace of the parameter containing help information
216     * parameterName the name of the parameter containing help information
217     * parameterDetailType the detail type of the parameter containing help information
218     *
219     * @param helpDefinition The helpDefinition to set.
220     */
221    public void setHelpDefinition(HelpDefinition helpDefinition) {
222        this.helpDefinition = helpDefinition;
223    }
224
225    /**
226     * @return the mustOccurConstraints
227     */
228    @Override
229    @BeanTagAttribute
230    public List<MustOccurConstraint> getMustOccurConstraints() {
231        return this.mustOccurConstraints;
232    }
233
234    /**
235     * @param mustOccurConstraints the mustOccurConstraints to set
236     */
237    public void setMustOccurConstraints(List<MustOccurConstraint> mustOccurConstraints) {
238        this.mustOccurConstraints = mustOccurConstraints;
239    }
240
241    /**
242     * @return the titleAttribute
243     */
244    @BeanTagAttribute
245    public String getTitleAttribute() {
246        if ( titleAttribute != null ) {
247            return titleAttribute;
248        }
249        if ( getDataObjectMetadata() != null ) {
250            return getDataObjectMetadata().getPrimaryDisplayAttributeName();
251        }
252        return null;
253    }
254
255    /**
256     * The titleAttribute element is the name of the attribute that
257     * will be used as an inquiry field when the lookup search results
258     * fields are displayed.
259     *
260     * For some business objects, there is no obvious field to serve
261     * as the inquiry field. in that case a special field may be required
262     * for inquiry purposes.
263     */
264    public void setTitleAttribute(String titleAttribute) {
265        this.titleAttribute = titleAttribute;
266    }
267
268    /**
269     * @return the primaryKeys
270     */
271    @BeanTagAttribute
272    public List<String> getPrimaryKeys() {
273        if ( primaryKeys != null ) {
274            return primaryKeys;
275        }
276        if ( getDataObjectMetadata() != null ) {
277            return getDataObjectMetadata().getPrimaryKeyAttributeNames();
278        }
279        return null;
280    }
281
282    /**
283     * @param primaryKeys the primaryKeys to set
284     */
285    public void setPrimaryKeys(List<String> primaryKeys) {
286        this.primaryKeys = primaryKeys;
287    }
288
289    @BeanTagAttribute
290    public Class<? extends Exporter> getExporterClass() {
291        return this.exporterClass;
292    }
293
294    public void setExporterClass(Class<? extends Exporter> exporterClass) {
295        this.exporterClass = exporterClass;
296    }
297
298    /**
299     * Provides list of attributes that should be used for grouping
300     * when performing effective dating logic in the framework
301     *
302     * @return List<String> list of attributes to group by
303     */
304    @BeanTagAttribute
305    public List<String> getGroupByAttributesForEffectiveDating() {
306        return this.groupByAttributesForEffectiveDating;
307    }
308
309    /**
310     * Setter for the list of attributes to group by
311     *
312     * @param groupByAttributesForEffectiveDating
313     */
314    public void setGroupByAttributesForEffectiveDating(List<String> groupByAttributesForEffectiveDating) {
315        this.groupByAttributesForEffectiveDating = groupByAttributesForEffectiveDating;
316    }
317
318    /**
319     * Gets the boNotesEnabled flag for the Data object
320     *
321     * <p>
322     * true indicates that notes and attachments will be permanently
323     * associated with the business object
324     * false indicates that notes and attachments are associated
325     * with the document used to create or edit the business object.
326     * </p>
327     *
328     * @return the boNotesEnabled flag
329     */
330    @BeanTagAttribute
331    public boolean isBoNotesEnabled() {
332        return boNotesEnabled;
333    }
334
335    /**
336     * Setter for the boNotesEnabled flag
337     */
338    public void setBoNotesEnabled(boolean boNotesEnabled) {
339        this.boNotesEnabled = boNotesEnabled;
340    }
341
342    /**
343     * Gets the inactivationBlockingDefinitions for the Data object
344     *
345     * @return the list of <code>InactivationBlockingDefinition</code>
346     */
347    @BeanTagAttribute
348    public List<InactivationBlockingDefinition> getInactivationBlockingDefinitions() {
349        return this.inactivationBlockingDefinitions;
350    }
351
352    /**
353     * Setter for the inactivationBlockingDefinitions
354     */
355    public void setInactivationBlockingDefinitions(
356            List<InactivationBlockingDefinition> inactivationBlockingDefinitions) {
357        this.inactivationBlockingDefinitions = inactivationBlockingDefinitions;
358    }
359}