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