View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.rice.kns.datadictionary;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.rice.kns.inquiry.Inquirable;
24  import org.kuali.rice.kns.inquiry.InquiryAuthorizer;
25  import org.kuali.rice.kns.inquiry.InquiryPresentationController;
26  
27  /**
28      The inquiry element is used to specify the fields that will be displayed on the
29      inquiry screen for this business object and the order in which they will appear.
30  
31      JSTL: The inquiry element is a Map which is accessed using
32      a key of "inquiry".  This map contains the following keys:
33          * title (String)
34          * inquiryFields (Map)
35   */
36  public class InquiryDefinition extends DataDictionaryDefinitionBase {
37      private static final long serialVersionUID = -2506403061297774668L;
38      
39  	protected String title;
40      protected List<InquirySectionDefinition> inquirySections = new ArrayList<InquirySectionDefinition>();
41      protected Class<? extends Inquirable> inquirableClass;
42      protected Class<? extends InquiryPresentationController> presentationControllerClass;
43      protected Class<? extends InquiryAuthorizer> authorizerClass;
44      
45      protected boolean translateCodes = true;
46  
47      public InquiryDefinition() {
48      }
49  
50  
51      public String getTitle() {
52          return title;
53      }
54  
55      /**
56                 The title element is used specify the title that will appear in the header
57                  of an Inquiry or Lookup screen.
58       * @throws IllegalArgumentException if the given title is blank
59       */
60      public void setTitle(String title) {
61          if (StringUtils.isBlank(title)) {
62              throw new IllegalArgumentException("invalid (blank) title");
63          }
64  
65          this.title = title;
66      }
67  
68      /**
69       * @return Collection of all inquiryField FieldDefinitions associated with this InquiryDefinition, in the order in which they
70       *         were added
71       */
72      public List<InquirySectionDefinition> getInquirySections() {
73          return inquirySections;
74      }
75     
76      /**
77       * Returns the FieldDefinition associated with the field attribute name
78       * @param fieldName
79       * @return
80       */
81      public FieldDefinition getFieldDefinition(String fieldName) {
82          for (InquirySectionDefinition section : inquirySections ) {
83              for (FieldDefinition field : section.getInquiryFields() ) {
84                  if (field.getAttributeName().equals(fieldName)) {
85                      return field;
86                  }
87              }
88          }
89          
90          return null;
91      }
92  
93      /**
94       * Directly validate simple fields, call completeValidation on Definition fields.
95       * 
96       * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
97       */
98      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
99          for ( InquirySectionDefinition inquirySection : inquirySections ) {
100             inquirySection.completeValidation(rootBusinessObjectClass, null);
101         }
102     }
103 
104     public InquirySectionDefinition getInquirySection( String sectionTitle ) {
105         for ( InquirySectionDefinition inquirySection : inquirySections ) {
106             if ( inquirySection.getTitle().equals(sectionTitle) ) {
107                 return inquirySection;
108             }
109         }
110         return null;
111     }
112     
113     
114     /**
115      * @see java.lang.Object#toString()
116      */
117     public String toString() {
118         return "InquiryDefinition '" + getTitle() + "'";
119     }
120 
121 
122     public Class<? extends Inquirable> getInquirableClass() {
123         return inquirableClass;
124     }
125 
126     /**
127 
128             inquirableClass is required if a custom inquirable is required which will show
129             additional data other than the business object attributes.
130 
131             Example from Org.xml:
132                 <inquirableClass>org.kuali.module.chart.maintenance.OrgInquirable</inquirableClass>
133             The custom inquirable is required in this case because the organization hierarchy
134             is shown on the inquiry screen.
135      */
136     public void setInquirableClass(Class<? extends Inquirable> inquirableClass) {
137         this.inquirableClass = inquirableClass;
138     }
139 
140     /**
141      *                 inquirySections allows inquiry to be presented in sections.
142                 Each section can have a different format.
143      */
144     public void setInquirySections(List<InquirySectionDefinition> inquirySections) {
145         this.inquirySections = inquirySections;
146     }
147 
148 
149 	public Class<? extends InquiryPresentationController> getPresentationControllerClass() {
150 		return this.presentationControllerClass;
151 	}
152 
153 
154 	public void setPresentationControllerClass(
155 			Class<? extends InquiryPresentationController> presentationControllerClass) {
156 		this.presentationControllerClass = presentationControllerClass;
157 	}
158 
159 
160 	public Class<? extends InquiryAuthorizer> getAuthorizerClass() {
161 		return this.authorizerClass;
162 	}
163 
164 
165 	public void setAuthorizerClass(
166 			Class<? extends InquiryAuthorizer> authorizerClass) {
167 		this.authorizerClass = authorizerClass;
168 	}
169 
170 
171 	public boolean isTranslateCodes() {
172 		return this.translateCodes;
173 	}
174 
175 
176 	public void setTranslateCodes(boolean translateCodes) {
177 		this.translateCodes = translateCodes;
178 	}
179 	
180 }