1 /**
2 * Copyright 2005-2014 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.krad.document;
17
18 import org.kuali.rice.kew.api.action.ActionType;
19 import org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent;
20 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
21 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
22 import org.kuali.rice.kim.api.identity.Person;
23 import org.kuali.rice.krad.bo.AdHocRoutePerson;
24 import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
25 import org.kuali.rice.krad.bo.DocumentHeader;
26 import org.kuali.rice.krad.bo.Note;
27 import org.kuali.rice.krad.bo.PersistableBusinessObject;
28 import org.kuali.rice.krad.document.authorization.PessimisticLock;
29 import org.kuali.rice.krad.exception.ValidationException;
30 import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
31 import org.kuali.rice.krad.service.DocumentSerializerService;
32 import org.kuali.rice.krad.util.NoteType;
33 import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityEvaluator;
34 import org.kuali.rice.krad.workflow.KualiDocumentXmlMaterializer;
35
36 import java.util.List;
37 import java.util.Map;
38
39
40 /**
41 * This is the Document interface. All entities that are regarded as "eDocs" in the system, including Maintenance documents and
42 * Transaction Processing documents should implement this interface as it defines methods that are necessary to interact with the
43 * underlying frameworks and components (i.e. notes, attachments, workflow, etc).
44 *
45 * @author Kuali Rice Team (rice.collab@kuali.org)
46 */
47 public interface Document extends PersistableBusinessObject {
48
49 /**
50 * This retrieves the standard <code>DocumentHeader</code> object, which contains standard meta-data about a document.
51 *
52 * @return document header since all docs will have a document header
53 */
54 public DocumentHeader getDocumentHeader();
55
56 /**
57 * Sets the associated <code>DocumentHeader</code> for this document.
58 *
59 * @param documentHeader
60 */
61 public void setDocumentHeader(DocumentHeader documentHeader);
62
63 /**
64 * All documents have a document header id. This is the quick accessor to that unique identifier and should return the same
65 * value as documentHeader.getDocumentHeaderId().
66 *
67 * @return doc header id
68 */
69 public String getDocumentNumber();
70
71 /**
72 * setter for document header id
73 *
74 * @param documentHeaderId
75 */
76 public void setDocumentNumber(String documentHeaderId);
77
78 /**
79 * This is the method to integrate with workflow, where we will actually populate the workflow defined data structure(s) so that
80 * workflow can routed based on this data. This method is responsible for passing over the proper Kuali (client system) data
81 * that will be used by workflow to determine how the document is actually routed.
82 */
83 public void populateDocumentForRouting();
84
85 /**
86 * This is a method where we can get the xml of a document that the workflow system will use to base it's routing and search
87 * attributes on.
88 *
89 * @return the document serialized to an xml string
90 */
91 public String serializeDocumentToXml();
92
93 /**
94 * This method is used to get the xml that should be used in a Route Report. In it's default implementation this will call the
95 * methods prepareForSave() and populateDocumentForRouting().
96 */
97 public String getXmlForRouteReport();
98
99 /**
100 * method to integrate with workflow, where we will actually handle the transitions of levels for documents
101 */
102 public void doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent);
103
104 /**
105 * method to integrate with workflow where we will be able to perform logic for an action taken being performed on a document
106 */
107 public void doActionTaken(ActionTakenEvent event);
108
109 /**
110 * method to integrate with workflow where we will be able to perform logic after an action taken being performed on a document
111 * @since 2.1
112 */
113 public void afterActionTaken(ActionType performed, ActionTakenEvent event);
114
115 /**
116 * This method will be called after the Workflow engine has completely finished processing a document.
117 *
118 * @param successfullyProcessed - true if the document was processed successfully, false otherwise
119 */
120 public void afterWorkflowEngineProcess(boolean successfullyProcessed);
121
122 /**
123 * This method will be called before the Workflow engine has begun processing a document.
124 */
125 public void beforeWorkflowEngineProcess();
126
127 /**
128 * This method will be called before the Workflow engine has begun processing a document.
129 */
130 public List<String> getWorkflowEngineDocumentIdsToLock();
131
132 /**
133 * Getter method to get the document title as it will appear in and be searchable in workflow.
134 */
135 public String getDocumentTitle();
136
137 /**
138 * getter method to get the list of ad hoc route persons associated with a document at a point in time, this list is only valid
139 * for a given users version of a document as this state is only persisted in workflow itself when someone takes an action on a
140 * document
141 */
142 public List<AdHocRoutePerson> getAdHocRoutePersons();
143
144 /**
145 * getter method to get the list of ad hoc route workgroups associated with a document at a point in time, this list is only
146 * valid for a given users version of a document as this state is only persisted in workflow itself when someone takes an action
147 * on a document
148 */
149 public List<AdHocRouteWorkgroup> getAdHocRouteWorkgroups();
150
151 /**
152 * setter method to set the list of ad hoc route persons associated with a document at a point in time, this list is only valid
153 * for a given users version of a document as this state is only persisted in workflow itself when someone takes an action on a
154 * document
155 *
156 * @param adHocRoutePersons
157 */
158 public void setAdHocRoutePersons(List<AdHocRoutePerson> adHocRoutePersons);
159
160 /**
161 * setter method to set the list of ad hoc route workgroups associated with a document at a point in time, this list is only
162 * valid for a given users version of a document as this state is only persisted in workflow itself when someone takes an action
163 * on a document
164 *
165 * @param adHocRouteWorkgroups
166 */
167 public void setAdHocRouteWorkgroups(List<AdHocRouteWorkgroup> adHocRouteWorkgroups);
168
169 /**
170 * This method provides a hook that will be called before the document is saved. This method is useful for applying document
171 * level data to children. For example, if someone changes data at the document level, and that data needs to be propagated to
172 * child objects or child lists of objects, you can use this method to update the child object or iterate through the list of
173 * child objects and apply the document level data to them. Any document that follows this paradigm will need to make use of
174 * this method to apply all of those changes.
175 */
176 public void prepareForSave();
177
178 /**
179 * Sends document off to the rules engine to verify business rules.
180 *
181 * @param event - indicates which document event was requested
182 * @throws ValidationException - containing the MessageMap from the validation session.
183 */
184 public void validateBusinessRules(KualiDocumentEvent event);
185
186 /**
187 * Do any work on the document that requires the KualiDocumentEvent before the save.
188 *
189 * @param event - indicates which document event was requested
190 */
191 public void prepareForSave(KualiDocumentEvent event);
192
193 /**
194 * Do any work on the document after the save.
195 *
196 * @param event - indicates which document event was requested
197 */
198 public void postProcessSave(KualiDocumentEvent event);
199
200 /**
201 * This method provides a hook that will be called after a document is retrieved, but before it is returned from the
202 * DocumentService.
203 */
204 public void processAfterRetrieve();
205
206 /**
207 * This method returns whether or not this document can be copied.
208 *
209 * @return True if it can be copied, false if not.
210 */
211 public boolean getAllowsCopy();
212
213 /**
214 * Generate any necessary events required during the save event generation
215 *
216 * @return a list of document events that were triggered by the save event
217 */
218 public List<KualiDocumentEvent> generateSaveEvents();
219
220 /**
221 * Handle the doRouteStatusChange event from the post processor
222 *
223 */
224 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent);
225
226 /**
227 * Returns the note type which should be used for notes associated with this document.
228 * This method should never return null.
229 *
230 * @return the note type supported by this document, this value should never be null
231 */
232 public NoteType getNoteType();
233
234 /**
235 * Return the target PersistableBusinessObject that notes associated with this document should be attached to.
236 * In general, this method should never return null. However, it is permissible that it will return a
237 * business object which has not been persisted yet (and therefore does not have it's unique object id
238 * established). This is only valid in cases where the note type is {@link NoteType#BUSINESS_OBJECT}.
239 *
240 * In these cases it's the responsibility for implementers of the Document interface to handle storing transient
241 * copies of the document notes (in XML or otherwise) until the underlying note target has been persisted and can be attached
242 * to the document's notes via it's object id.
243 *
244 * @return the PersistableBusinessObject with which notes on this document should be associated
245 */
246 public PersistableBusinessObject getNoteTarget();
247
248 /**
249 * Adds the given Note to the document's list of Notes.
250 *
251 * @param note the Note to add, must be non-null
252 */
253 public void addNote(Note note);
254
255 /**
256 * Returns a mutable list of all notes on the document.
257 *
258 * @return the list of notes associated with this document, if this document has no notes then an empty list will be returned
259 */
260 public List<Note> getNotes();
261
262 /**
263 * Sets the document's list of notes to the given list.
264 *
265 * @param notes the list of notes to set on the document, must be non-null
266 */
267 public void setNotes(List<Note> notes);
268
269 /**
270 * Retrieves the note at the given index.
271 *
272 * @param index the zero-based index of the note to retrieve
273 * @return the note located at the given index
274 * @throws IndexOutOfBoundsException if the index is out of range
275 */
276 public Note getNote(int index);
277
278 /**
279 * Removes the given note from the document's list of notes.
280 *
281 * @param note the note to remove from the document's list of notes, must be non-null
282 * @return true if the note was successfully removed, false if the list did not contain the given note
283 */
284 public boolean removeNote(Note note);
285
286 /**
287 * This method gets a list of the {@link PessimisticLock} objects associated with this document
288 *
289 */
290 public List<PessimisticLock> getPessimisticLocks();
291
292 /**
293 * This method updates the list of {@link PessimisticLock} objects on the document if changes could
294 * have been made
295 */
296 public void refreshPessimisticLocks();
297
298 /**
299 * This method adds a new {@link PessimisticLock} to the document
300 *
301 * NOTE: LOCKS ADDED VIA THIS METHOD WILL NOT BE SAVED WITH THE DOCUMENT
302 *
303 * @param lock - the lock to add to the document
304 */
305 public void addPessimisticLock(PessimisticLock lock);
306
307 /**
308 * This is a method that is used by Kuali Pessimistic Locking to get the names (method to call values)
309 * of the {@link KualiDocumentActionBase} methods that should release locks
310 *
311 * @return the list of method names of an action that should clear locks for the current user
312 */
313 public List<String> getLockClearningMethodNames();
314 /**
315 * Returns an evaluator object that determines whether a given property relative to the root object ({@link #wrapDocumentWithMetadataForXmlSerialization()}
316 * is serializable during the document serialization process.
317 *
318 * @return a fully initialized evaluator object, ready to be used for workflow routing
319 *
320 * @see DocumentSerializerService
321 * @see #wrapDocumentWithMetadataForXmlSerialization()
322 */
323
324 public String getBasePathToDocumentDuringSerialization();
325
326 /**
327 * Returns an evaluator object that determines whether a given property relative to the root object ({@link #wrapDocumentWithMetadataForXmlSerialization()}
328 * is serializable during the document serialization process.
329 *
330 * @return a fully initialized evaluator object, ready to be used for workflow routing
331 *
332 * @see DocumentSerializerService
333 * @see #wrapDocumentWithMetadataForXmlSerialization()
334 */
335 public PropertySerializabilityEvaluator getDocumentPropertySerizabilityEvaluator();
336
337 /**
338 * This method will return the root object to be serialized for workflow routing. If necessary, this method will wrap this document object with a wrapper (i.e. contains a reference back to this document). This
339 * wrapper may also contain references to additional objects that provide metadata useful to the workflow engine.
340 *
341 * If no wrappers are necessary, then this object may return "this"
342 *
343 * @return a wrapper object (most likely containing a reference to "this"), or "this" itself.
344 * @see KualiDocumentXmlMaterializer
345 */
346 public Object wrapDocumentWithMetadataForXmlSerialization();
347
348 /**
349 * This method returns whether or not this document supports custom lock descriptors for pessimistic locking.
350 *
351 * @return True if the document can generate custom lock descriptors, false otherwise.
352 * @see #getCustomLockDescriptor(Map, Person)
353 */
354 public boolean useCustomLockDescriptors();
355
356 /**
357 * Generates a custom lock descriptor for pessimistic locking. This method should not be called unless {@link #useCustomLockDescriptors()} returns true.
358 *
359 * @param user The user trying to establish the lock.
360 * @return A String representing the lock descriptor.
361 * @see #useCustomLockDescriptors()
362 * @see org.kuali.rice.krad.service.PessimisticLockService
363 * @see org.kuali.rice.krad.service.impl.PessimisticLockServiceImpl
364 */
365 public String getCustomLockDescriptor(Person user);
366 }