1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
19 import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
20 import org.kuali.rice.krad.document.Document;
21 import org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizer;
22 import org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizerBase;
23 import org.kuali.rice.krad.maintenance.MaintenanceDocumentBase;
24 import org.kuali.rice.krad.maintenance.Maintainable;
25 import org.kuali.rice.krad.maintenance.MaintenanceDocumentPresentationControllerBase;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30
31
32
33
34
35 public class MaintenanceDocumentEntry extends DocumentEntry {
36 private static final long serialVersionUID = 4990040987835057251L;
37
38 protected Class<?> dataObjectClass;
39 protected Class<? extends Maintainable> maintainableClass;
40
41 protected List<String> lockingKeys = new ArrayList<String>();
42
43 protected boolean allowsNewOrCopy = true;
44 protected boolean preserveLockingKeysOnCopy = false;
45 protected boolean allowsRecordDeletion = false;
46
47 public MaintenanceDocumentEntry() {
48 super();
49
50 setDocumentClass(getStandardDocumentBaseClass());
51 documentAuthorizerClass = MaintenanceDocumentAuthorizerBase.class;
52 documentPresentationControllerClass = MaintenanceDocumentPresentationControllerBase.class;
53 }
54
55 public Class<? extends Document> getStandardDocumentBaseClass() {
56 return MaintenanceDocumentBase.class;
57 }
58
59
60
61
62
63 public void setDataObjectClass(Class<?> dataObjectClass) {
64 if (dataObjectClass == null) {
65 throw new IllegalArgumentException("invalid (null) dataObjectClass");
66 }
67
68 this.dataObjectClass = dataObjectClass;
69 }
70
71 public Class<?> getDataObjectClass() {
72 return dataObjectClass;
73 }
74
75
76
77
78 @SuppressWarnings("unchecked")
79 @Override
80 public Class getEntryClass() {
81 return dataObjectClass;
82 }
83
84
85
86
87
88
89
90 public void setMaintainableClass(Class<? extends Maintainable> maintainableClass) {
91 if (maintainableClass == null) {
92 throw new IllegalArgumentException("invalid (null) maintainableClass");
93 }
94 this.maintainableClass = maintainableClass;
95 }
96
97 public Class<? extends Maintainable> getMaintainableClass() {
98 return maintainableClass;
99 }
100
101
102
103
104
105 public List<String> getLockingKeyFieldNames() {
106 return lockingKeys;
107 }
108
109
110
111
112
113
114 public boolean getAllowsNewOrCopy() {
115 return allowsNewOrCopy;
116 }
117
118
119
120
121
122
123 public void setAllowsNewOrCopy(boolean allowsNewOrCopy) {
124 this.allowsNewOrCopy = allowsNewOrCopy;
125 }
126
127
128
129
130
131
132 public void completeValidation() {
133 super.completeValidation();
134
135 for (String lockingKey : lockingKeys) {
136 if (!DataDictionary.isPropertyOf(dataObjectClass, lockingKey)) {
137 throw new AttributeValidationException(
138 "unable to find attribute '" + lockingKey + "' for lockingKey in dataObjectClass '" +
139 dataObjectClass.getName());
140 }
141 }
142
143 for (ReferenceDefinition reference : defaultExistenceChecks) {
144 reference.completeValidation(dataObjectClass, null);
145 }
146
147
148 if (documentAuthorizerClass != null &&
149 !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) {
150 throw new ClassValidationException(
151 "This maintenance document for '" + getDataObjectClass().getName() + "' has an invalid " +
152 "documentAuthorizerClass ('" + documentAuthorizerClass.getName() + "'). " +
153 "Maintenance Documents must use an implementation of MaintenanceDocumentAuthorizer.");
154 }
155 }
156
157
158
159
160 public String toString() {
161 return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName();
162 }
163
164 public List<String> getLockingKeys() {
165 return lockingKeys;
166 }
167
168
169
170
171
172
173 public void setLockingKeys(List<String> lockingKeys) {
174 for (String lockingKey : lockingKeys) {
175 if (lockingKey == null) {
176 throw new IllegalArgumentException("invalid (null) lockingKey");
177 }
178 }
179 this.lockingKeys = lockingKeys;
180 }
181
182
183
184
185 public boolean getPreserveLockingKeysOnCopy() {
186 return this.preserveLockingKeysOnCopy;
187 }
188
189
190
191
192 public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) {
193 this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy;
194 }
195
196
197
198
199 public boolean getAllowsRecordDeletion() {
200 return this.allowsRecordDeletion;
201 }
202
203
204
205
206 public void setAllowsRecordDeletion(boolean allowsRecordDeletion) {
207 this.allowsRecordDeletion = allowsRecordDeletion;
208 }
209
210 }