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