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