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.kns.datadictionary;
017
018import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
019import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException;
020
021import java.util.ArrayList;
022import java.util.LinkedHashMap;
023import java.util.List;
024import java.util.Map;
025
026/**
027 * inquirySection defines the format and content of one section of the inquiry.
028 * DD:  See InquirySectionDefinition.java
029 *
030 * numberOfColumns = the number of fields to be displayed in each row of the inquiry section.
031 * For example, numberOfColumns = 2 indicates that the label and values for two fields will be displayed in each row as
032 * follows:
033 *      field1label field1value  |   field2label field2value
034 *      field3label field3value  |   field4label field4value
035 *      etc.
036 *
037 * Contains section-related information for inquiry sections
038 * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
039 *
040 * @deprecated Use sections inside of {@link org.kuali.rice.krad.uif.view.InquiryView}.
041 */
042@Deprecated
043public class InquirySectionDefinition extends DataDictionaryDefinitionBase {
044    private static final long serialVersionUID = 1565114894539391362L;
045    
046        protected String title;
047    protected List<FieldDefinition> inquiryFields = new ArrayList<FieldDefinition>();
048    protected Map<String, FieldDefinition> inquiryFieldMap = new LinkedHashMap<String, FieldDefinition>();
049    protected Map inquiryCollections;
050    
051    protected Integer numberOfColumns = 1;
052    protected boolean defaultOpen = true;
053    
054    public InquirySectionDefinition() {}
055
056
057    /**
058     * @return title
059     */
060    public String getTitle() {
061        return title;
062    }
063
064    /**
065     * Sets title to the given value.
066     * 
067     * @param title
068     * @throws IllegalArgumentException if the given title is blank
069     */
070    public void setTitle(String title) {
071        this.title = title;
072    }
073
074    /**
075     * @return List of attributeNames of all FieldDefinitions associated with this InquirySection, in the order in
076     *         which they were added
077     */
078    public List<String> getInquiryFieldNames() {
079        List<String> itemNames = new ArrayList<String>();
080        itemNames.addAll(this.inquiryFieldMap.keySet());
081
082        return itemNames;
083    }
084
085    /**
086     * @return Collection of all FieldDefinitions associated with this InquirySection, in the order in which they
087     *         were added
088     */
089    public List<FieldDefinition> getInquiryFields() {
090        return inquiryFields;
091    }
092
093    /**
094     * Directly validate simple fields, call completeValidation on Definition fields.
095     * 
096     * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
097     */
098    public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
099        for (FieldDefinition inquiryField : inquiryFields ) {
100            inquiryField.completeValidation(rootBusinessObjectClass, null);
101        }
102    }
103
104    public String toString() {
105        return "InquirySectionDefinition '" + getTitle() + "'";
106    }
107
108    public Map getInquiryCollections() {
109        return inquiryCollections;
110    }
111
112    /**
113                   The inquiryCollection defines a collection within the Business Object which contains
114                   data that should be displayed with the BO when the inquiry is performed.
115
116                   Each inquiryCollection defines a set of data fields, nested inquiryCollections
117                   and summaryFields.  The summaryFields will be reported in the header of
118                   this inquiryCollection, .
119
120                   DD: See InquiryCollectionDefinition.java
121                   JSTL: The inquiryCollection element is a Map with the following keys:
122                       * name (String)
123                       * dataObjectClass (String)
124                       * numberOfColumns (String)
125                       * inquiryFields (Map)
126                       * inquiryCollections (Map, optional)
127                       * summaryTitle (String)
128                       * summaryFields (Map, optional)
129     */
130    public void setInquiryCollections(Map inquiryCollections) {
131        this.inquiryCollections = inquiryCollections;
132    }
133
134    public Integer getNumberOfColumns() {
135        return numberOfColumns;
136    }
137
138    /**
139                numberOfColumns = the number of fields to be displayed in each row of the inquiry section.
140                For example, numberOfColumns = 2 indicates that the label and values for two fields will be
141                displayed in each row as follows:
142                    field1label field1value  |   field2label field2value
143                    field3label field3value  |   field4label field4value
144                etc.
145     */
146    public void setNumberOfColumns(Integer numberOfColumns) {
147        this.numberOfColumns = numberOfColumns;
148    }
149
150
151    /**
152                JSTL: inquiryFields is a Map which is accessed using a
153                key of "inquiryFields".  This map contains the following types
154                of elements:
155                    * inquirySubSectionHeader
156                    * field
157                    * inquiryCollection
158                Each of these entries are keyed by "attributeName".
159                The associated value is the attributeName of the
160                mapped element.
161
162                  The inquirySubSectionHeader allows a separator containing text to
163                  separate groups of fields.  The name attribute is the displayed text.
164
165                  JSTL: inquirySubSectionHeader appears in the inquiryFields map as:
166                      * key = "attributeName"
167                      * value = name of inquirySubSectionHeader
168
169
170                    The field element defines the attributes of a single data field.
171
172                    DD:  See FieldDefinition.java
173                    JSTL: The field element is a Map which is accessed using
174                    a key of the attributeName.  This map contains the following keys:
175                        * attributeName (String)
176                        * forceInquiry (boolean String)
177                        * noInquiry (boolean String)
178                        * maxLength (String)
179
180                forceInquiry = true means that the displayed field value will
181                always be made inquirable (this attribute is not used within the code).
182
183                noInquiry = true means that the displayed field will never be made inquirable.
184
185                maxLength = the maximum allowable length of the field in the lookup result fields.  In other contexts,
186                like inquiries, this field has no effect.
187     */
188    public void setInquiryFields(List<FieldDefinition> inquiryFields) {
189        inquiryFieldMap.clear();
190        for (FieldDefinition inquiryField : inquiryFields ) {
191            if (inquiryField == null) {
192                throw new IllegalArgumentException("invalid (null) inquiryField");
193            }
194
195            String itemName = inquiryField.getAttributeName();
196            if (inquiryFieldMap.containsKey(itemName)) {
197                throw new DuplicateEntryException("duplicate itemName entry for item '" + itemName + "'");
198            }
199
200            inquiryFieldMap.put(itemName, inquiryField);        
201        }
202        this.inquiryFields = inquiryFields;
203    }
204
205
206        /**
207         * @return the defaultOpen
208         */
209        public boolean isDefaultOpen() {
210                return this.defaultOpen;
211        }
212
213
214        /**
215         * @param defaultOpen the defaultOpen to set
216         */
217        public void setDefaultOpen(boolean defaultOpen) {
218                this.defaultOpen = defaultOpen;
219        }
220
221}