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