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