Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MaintainableSectionDefinition |
|
| 1.9285714285714286;1.929 |
1 | /* | |
2 | * Copyright 2005-2008 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.util.KNSConstants; | |
24 | ||
25 | /** | |
26 | The maintainableSection element defines one section of the | |
27 | maintenance document. | |
28 | ||
29 | JSTL: maintainableSection is a Map which is accessed by an | |
30 | integer representing the sequential occurrence of the section. | |
31 | e.g. "0", "1", etc. This map contains entries with the following | |
32 | keys: | |
33 | * index (String) - e.g. "0" for first section, etc. | |
34 | * title (String) | |
35 | * maintainableItems (Map) | |
36 | */ | |
37 | public class MaintainableSectionDefinition extends DataDictionaryDefinitionBase { | |
38 | private static final long serialVersionUID = -8615694293159113523L; | |
39 | ||
40 | protected String title; | |
41 | ||
42 | 0 | protected List<MaintainableItemDefinition> maintainableItems = new ArrayList<MaintainableItemDefinition>(); |
43 | ||
44 | 0 | protected boolean hidden = false; |
45 | ||
46 | 0 | protected boolean defaultOpen = true; |
47 | ||
48 | protected String helpUrl; | |
49 | ||
50 | 0 | public MaintainableSectionDefinition() {} |
51 | ||
52 | /** | |
53 | * @return title | |
54 | */ | |
55 | public String getTitle() { | |
56 | 0 | return title; |
57 | } | |
58 | ||
59 | /** | |
60 | * Default the ID to the title for now. | |
61 | * | |
62 | * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinitionBase#getId() | |
63 | */ | |
64 | @Override | |
65 | public String getId() { | |
66 | 0 | if (StringUtils.isBlank(id)) { |
67 | 0 | return title; |
68 | } | |
69 | 0 | return id; |
70 | } | |
71 | ||
72 | ||
73 | /** | |
74 | * Sets title of the Section. | |
75 | * | |
76 | * @throws IllegalArgumentException if the given title is blank | |
77 | */ | |
78 | public void setTitle(String title) { | |
79 | 0 | if (StringUtils.isBlank(title)) { |
80 | 0 | throw new IllegalArgumentException("invalid (blank) title"); |
81 | } | |
82 | ||
83 | 0 | this.title = title; |
84 | 0 | } |
85 | ||
86 | /** | |
87 | * @return Collection of all MaintainableFieldDefinitions associated with this MaintainableSection, in the order in which they | |
88 | * were added | |
89 | */ | |
90 | public List<MaintainableItemDefinition> getMaintainableItems() { | |
91 | 0 | return maintainableItems; |
92 | } | |
93 | ||
94 | ||
95 | /** | |
96 | * Directly validate simple fields, call completeValidation on Definition fields. | |
97 | * | |
98 | * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object) | |
99 | */ | |
100 | public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { | |
101 | 0 | if (StringUtils.contains(title, ",") && StringUtils.isBlank(id)) { |
102 | 0 | throw new DataDictionaryException("The title for maintainable section \"" + title + "\" for class " + rootBusinessObjectClass.getName() + |
103 | " contains a comma. In this case, the id property must be defined and it may not contain a comma"); | |
104 | } | |
105 | 0 | if (StringUtils.contains(id, ",")) { |
106 | 0 | throw new DataDictionaryException("The id for maintainable section \"" + id + "\" for class " + rootBusinessObjectClass.getName() + |
107 | " contains a comma, which is not allowed."); | |
108 | } | |
109 | 0 | for ( MaintainableItemDefinition maintainableItem : maintainableItems ) { |
110 | 0 | maintainableItem.completeValidation(rootBusinessObjectClass, null); |
111 | } | |
112 | 0 | } |
113 | ||
114 | public String toString() { | |
115 | 0 | return "MaintainableSectionDefinition '" + getTitle() + "'"; |
116 | } | |
117 | ||
118 | ||
119 | public boolean isHidden() { | |
120 | 0 | return this.hidden; |
121 | } | |
122 | ||
123 | ||
124 | /** Whether to hide the entire section, tab and all. */ | |
125 | public void setHidden(boolean hidden) { | |
126 | 0 | this.hidden = hidden; |
127 | 0 | } |
128 | ||
129 | ||
130 | /** | |
131 | The maintainableItems element defines the components of a | |
132 | section. These may include fields, sub-section headers, | |
133 | and fields. | |
134 | ||
135 | JSTL: maintainableItems is a Map which is accessed by a | |
136 | key of "maintainableItems". This map contains entries with | |
137 | the following keys: | |
138 | * name of first item in the section | |
139 | * name of second item in the section | |
140 | * etc. | |
141 | The corresponding value is an ExportMap which is dependent | |
142 | upon the type of the item as follows: | |
143 | ||
144 | subSectionHeader ExportMap | |
145 | In this case, the ExportMap contains the following | |
146 | keys and values: | |
147 | **Key** **Value** | |
148 | name name of subSectionHeader | |
149 | ||
150 | maintainableField ExportMap | |
151 | In this case, the ExportMap contains the following | |
152 | keys and values: | |
153 | **Key** **Value** | |
154 | field true | |
155 | name name of maintainableField | |
156 | required true or false | |
157 | ||
158 | maintainableCollection ExportMap | |
159 | In this case, the ExportMap contains the following | |
160 | keys and values: | |
161 | **Key** **Value** | |
162 | collection true | |
163 | name name of collection | |
164 | businessObjectClass name of collection class | |
165 | */ | |
166 | public void setMaintainableItems(List<MaintainableItemDefinition> maintainableItems) { | |
167 | 0 | for ( MaintainableItemDefinition maintainableItem : maintainableItems ) { |
168 | 0 | if (maintainableItem == null) { |
169 | 0 | throw new IllegalArgumentException("invalid (null) maintainableItem"); |
170 | } | |
171 | } | |
172 | ||
173 | 0 | this.maintainableItems = maintainableItems; |
174 | 0 | } |
175 | ||
176 | /** | |
177 | * @return the defaultOpen | |
178 | */ | |
179 | public boolean isDefaultOpen() { | |
180 | 0 | return this.defaultOpen; |
181 | } | |
182 | ||
183 | /** | |
184 | * @param defaultOpen the defaultOpen to set | |
185 | */ | |
186 | public void setDefaultOpen(boolean defaultOpen) { | |
187 | 0 | this.defaultOpen = defaultOpen; |
188 | 0 | } |
189 | ||
190 | public String getHelpUrl() { | |
191 | 0 | return helpUrl; |
192 | } | |
193 | ||
194 | public void setHelpUrl(String helpUrl) { | |
195 | 0 | this.helpUrl = helpUrl; |
196 | 0 | } |
197 | ||
198 | } |