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.kns.datadictionary;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.kns.inquiry.InquiryAuthorizer;
020import org.kuali.rice.kns.inquiry.InquiryPresentationController;
021import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
022import org.kuali.rice.krad.inquiry.Inquirable;
023
024import java.util.ArrayList;
025import java.util.List;
026
027/**
028    The inquiry element is used to specify the fields that will be displayed on the
029    inquiry screen for this business object and the order in which they will appear.
030
031    JSTL: The inquiry element is a Map which is accessed using
032    a key of "inquiry".  This map contains the following keys:
033        * title (String)
034        * inquiryFields (Map)
035 */
036@Deprecated
037public class InquiryDefinition extends DataDictionaryDefinitionBase {
038    private static final long serialVersionUID = -2506403061297774668L;
039    
040        protected String title;
041    protected List<InquirySectionDefinition> inquirySections = new ArrayList<InquirySectionDefinition>();
042    protected Class<? extends Inquirable> inquirableClass;
043    protected Class<? extends InquiryPresentationController> presentationControllerClass;
044    protected Class<? extends InquiryAuthorizer> authorizerClass;
045    
046    protected boolean translateCodes = true;
047
048    public InquiryDefinition() {
049    }
050
051
052    public String getTitle() {
053        return title;
054    }
055
056    /**
057               The title element is used specify the title that will appear in the header
058                of an Inquiry or Lookup screen.
059     * @throws IllegalArgumentException if the given title is blank
060     */
061    public void setTitle(String title) {
062        if (StringUtils.isBlank(title)) {
063            throw new IllegalArgumentException("invalid (blank) title");
064        }
065
066        this.title = title;
067    }
068
069    /**
070     * @return Collection of all inquiryField FieldDefinitions associated with this InquiryDefinition, in the order in which they
071     *         were added
072     */
073    public List<InquirySectionDefinition> getInquirySections() {
074        return inquirySections;
075    }
076   
077    /**
078     * Returns the FieldDefinition associated with the field attribute name
079     * @param fieldName
080     * @return
081     */
082    public FieldDefinition getFieldDefinition(String fieldName) {
083        for (InquirySectionDefinition section : inquirySections ) {
084            for (FieldDefinition field : section.getInquiryFields() ) {
085                if (field.getAttributeName().equals(fieldName)) {
086                    return field;
087                }
088            }
089        }
090        
091        return null;
092    }
093
094    /**
095     * Directly validate simple fields, call completeValidation on Definition fields.
096     * 
097     * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
098     */
099    public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
100        for ( InquirySectionDefinition inquirySection : inquirySections ) {
101            inquirySection.completeValidation(rootBusinessObjectClass, null);
102        }
103    }
104
105    public InquirySectionDefinition getInquirySection( String sectionTitle ) {
106        for ( InquirySectionDefinition inquirySection : inquirySections ) {
107            if ( inquirySection.getTitle().equals(sectionTitle) ) {
108                return inquirySection;
109            }
110        }
111        return null;
112    }
113    
114    
115    /**
116     * @see java.lang.Object#toString()
117     */
118    public String toString() {
119        return "InquiryDefinition '" + getTitle() + "'";
120    }
121
122
123    public Class<? extends Inquirable> getInquirableClass() {
124        return inquirableClass;
125    }
126
127    /**
128
129            inquirableClass is required if a custom inquirable is required which will show
130            additional data other than the business object attributes.
131
132            Example from Org.xml:
133                <inquirableClass>org.kuali.module.chart.maintenance.OrgInquirable</inquirableClass>
134            The custom inquirable is required in this case because the organization hierarchy
135            is shown on the inquiry screen.
136     */
137    public void setInquirableClass(Class<? extends Inquirable> inquirableClass) {
138        this.inquirableClass = inquirableClass;
139    }
140
141    /**
142     *                 inquirySections allows inquiry to be presented in sections.
143                Each section can have a different format.
144     */
145    public void setInquirySections(List<InquirySectionDefinition> inquirySections) {
146        this.inquirySections = inquirySections;
147    }
148
149
150        public Class<? extends InquiryPresentationController> getPresentationControllerClass() {
151                return this.presentationControllerClass;
152        }
153
154
155        public void setPresentationControllerClass(
156                        Class<? extends InquiryPresentationController> presentationControllerClass) {
157                this.presentationControllerClass = presentationControllerClass;
158        }
159
160
161        public Class<? extends InquiryAuthorizer> getAuthorizerClass() {
162                return this.authorizerClass;
163        }
164
165
166        public void setAuthorizerClass(
167                        Class<? extends InquiryAuthorizer> authorizerClass) {
168                this.authorizerClass = authorizerClass;
169        }
170
171
172        public boolean isTranslateCodes() {
173                return this.translateCodes;
174        }
175
176
177        public void setTranslateCodes(boolean translateCodes) {
178                this.translateCodes = translateCodes;
179        }
180        
181}