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.bo.BusinessObject;
019import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException;
020
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025/**
026 * The inquiryCollection defines a collection within the Business Object which contains data that should be displayed
027 * with the BO when the inquiry is performed.
028 *
029 * Each inquiryCollection defines a set of data fields, nested inquiryCollections and summaryFields.  The summaryFields
030 * will be reported in the header of this inquiryCollection.
031 *
032 * DD: See InquiryCollectionDefinition.java
033 * JSTL: The inquiryCollection element is a Map with the following keys:
034 *      * name (String)
035 *      * dataObjectClass (String)
036 *      * numberOfColumns (String)
037 *      * inquiryFields (Map)
038 *      * inquiryCollections (Map, optional)
039 *      * summaryTitle (String)
040 *      * summaryFields (Map, optional)
041 *
042 * @deprecated Use collections inside of {@link org.kuali.rice.krad.uif.view.InquiryView}.
043 */
044@Deprecated
045public class InquiryCollectionDefinition extends FieldDefinition implements CollectionDefinitionI {
046        private static final long serialVersionUID = 2257743293609536893L;
047
048        protected Class<? extends BusinessObject> businessObjectClass;
049
050        protected Integer numberOfColumns = 1;
051
052        protected Map<String,FieldDefinition> inquiryFieldMap = new HashMap<String, FieldDefinition>();
053        protected Map<String,InquiryCollectionDefinition> inquiryCollectionMap = new HashMap<String, InquiryCollectionDefinition>();
054        protected Map<String,FieldDefinitionI> summaryFieldMap = new HashMap<String, FieldDefinitionI>();
055        protected List<FieldDefinition> inquiryFields = new ArrayList<FieldDefinition>();
056        protected List<InquiryCollectionDefinition> inquiryCollections = new ArrayList<InquiryCollectionDefinition>();
057        protected List<FieldDefinition> summaryFields = new ArrayList<FieldDefinition>();
058
059        protected String summaryTitle;
060
061
062        public InquiryCollectionDefinition() {}
063
064        public Class<? extends BusinessObject> getBusinessObjectClass() {
065                return businessObjectClass;
066        }
067
068        /**
069            This attribute is used in many contexts, for example, in maintenance docs, it's used to specify the classname
070            of the BO being maintained.
071         */
072        public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
073                this.businessObjectClass = businessObjectClass;
074        }
075
076        public Integer getNumberOfColumns() {
077                return numberOfColumns;
078        }
079
080        /**
081                numberOfColumns = the number of fields to be displayed in each row of the inquiry section.
082                For example, numberOfColumns = 2 indicates that the label and values for two fields will be
083                displayed in each row as follows:
084                    field1label field1value  |   field2label field2value
085                    field3label field3value  |   field4label field4value
086                etc.
087         */
088        public void setNumberOfColumns(Integer numberOfColumns) {
089                this.numberOfColumns = numberOfColumns;
090        }
091
092        public String getName() {
093                return getAttributeName();
094        }
095        
096        public List<? extends CollectionDefinitionI> getCollections() {
097                return inquiryCollections;
098        }
099
100        public List<? extends FieldDefinitionI> getFields() {
101                return inquiryFields;
102        }
103
104        public boolean getIncludeAddLine() {
105                return false;
106        }
107
108        public boolean isAlwaysAllowCollectionDeletion() {
109                return false;
110        }
111        
112        public boolean hasSummaryField(String key) {
113                return summaryFieldMap.containsKey(key);
114        }
115
116        /**
117                The title element is used specify the title that will appear in the header
118                of an Inquiry or Lookup screen.
119         */
120        public void setSummaryTitle(String summaryTitle) {
121                this.summaryTitle = summaryTitle;
122        }
123
124        public String getSummaryTitle() {
125                return this.summaryTitle;
126        }
127
128    public List<FieldDefinition> getInquiryFields() {
129        return this.inquiryFields;
130    }
131
132    /**
133                JSTL: inquiryFields is a Map which is accessed using a
134                key of "inquiryFields".  This map contains the following types
135                of elements:
136                    * inquirySubSectionHeader
137                    * field
138                    * inquiryCollection
139                Each of these entries are keyed by "attributeName".
140                The associated value is the attributeName of the
141                mapped element.
142
143                  The inquirySubSectionHeader allows a separator containing text to
144                  separate groups of fields.  The name attribute is the displayed text.
145
146                  DD:   See InquirySubSectionHeaderDefinition.
147                  JSTL: inquirySubSectionHeader appears in the inquiryFields map as:
148                      * key = "attributeName"
149                      * value = name of inquirySubSectionHeader
150
151
152                    The field element defines the attributes of a single data field.
153
154                    DD:  See FieldDefinition.java
155                    JSTL: The field element is a Map which is accessed using
156                    a key of the attributeName.  This map contains the following keys:
157                        * attributeName (String)
158                        * forceInquiry (boolean String)
159                        * noInquiry (boolean String)
160                        * maxLength (String)
161
162                forceInquiry = true means that the displayed field value will
163                always be made inquirable (this attribute is not used within the code).
164
165                noInquiry = true means that the displayed field will never be made inquirable.
166
167                maxLength = the maximum allowable length of the field in the lookup result fields.  In other contexts,
168                like inquiries, this field has no effect.
169
170     */
171    public void setInquiryFields(List<FieldDefinition> inquiryFields) {
172        inquiryFieldMap.clear();
173        for ( FieldDefinition inquiryField : inquiryFields ) {
174            if (inquiryField == null) {
175                throw new IllegalArgumentException("invalid (null) inquiryField");
176            }
177    
178            String itemName = inquiryField.getAttributeName();
179            if (inquiryFieldMap.containsKey(itemName)) {
180                throw new DuplicateEntryException(
181                        "duplicate itemName entry for item '" + itemName + "'");
182            }
183    
184            inquiryFieldMap.put(itemName, inquiryField);
185        }
186
187        this.inquiryFields = inquiryFields;
188    }
189
190    public List<InquiryCollectionDefinition> getInquiryCollections() {
191        return inquiryCollections;
192    }
193
194    /**
195                inquirySections allows inquiry to be presented in sections.
196                Each section can have a different format.
197     */
198    public void setInquiryCollections(List<InquiryCollectionDefinition> inquiryCollections) {
199        inquiryCollectionMap.clear();
200        for ( InquiryCollectionDefinition inquiryCollection : inquiryCollections ) {
201            if (inquiryCollection == null) {
202                throw new IllegalArgumentException(
203                        "invalid (null) inquiryCollection");
204            }
205
206            String fieldName = inquiryCollection.getName();
207            if (inquiryCollectionMap.containsKey(fieldName)) {
208                throw new DuplicateEntryException(
209                        "duplicate fieldName entry for field '" + fieldName + "'");
210            }
211
212            inquiryCollectionMap.put(fieldName, inquiryCollection);
213        }
214        this.inquiryCollections = inquiryCollections;
215    }
216
217    public List<FieldDefinition> getSummaryFields() {
218        return this.summaryFields;
219    }
220
221    /**
222                    The inquirySummaryField indicates which fields are to appear in
223                    the header line of each record in a collection.  For example,
224                    the header of an address record may contain something like:
225                        "Address ( Purchase_Order - San Francisco )"
226                    where the two summary fields are:
227                        Vendor Type = "Purchase_Order"
228                        Vendor City = "San Francisco"
229
230                    DD:  See FieldDefinition.java
231     */
232    public void setSummaryFields(List<FieldDefinition> summaryFields) {
233        summaryFieldMap.clear();
234        for ( FieldDefinition inquiryField : summaryFields ) {
235            if (inquiryField == null) {
236                throw new IllegalArgumentException("invalid (null) summaryField");
237            }
238    
239            String itemName = inquiryField.getAttributeName();
240            if (summaryFieldMap.containsKey(itemName)) {
241                throw new DuplicateEntryException(
242                        "duplicate itemName entry for item '" + itemName + "'");
243            }
244    
245            summaryFieldMap.put(itemName, inquiryField);
246        }
247        this.summaryFields = summaryFields;
248    }
249        
250        
251}