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