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