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