View Javadoc
1   /**
2    * Copyright 2005-2015 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.service;
17  
18  import org.kuali.rice.kew.api.exception.WorkflowException;
19  import org.kuali.rice.kim.api.identity.Person;
20  import org.kuali.rice.krad.bo.AdHocRouteRecipient;
21  import org.kuali.rice.krad.bo.Note;
22  import org.kuali.rice.krad.document.Document;
23  import org.kuali.rice.krad.exception.ValidationException;
24  import org.kuali.rice.krad.rules.rule.event.DocumentEvent;
25  import org.kuali.rice.krad.rules.rule.event.SaveEvent;
26  
27  import java.util.List;
28  
29  /**
30   * Defines various operations that support the Document framework.
31   *
32   * The calling code should always use any returned Document object for future operations since a new object will be
33   * created if a passed-in document is saved.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public interface DocumentService {
38  
39      /**
40       * @param documentHeaderId
41       * @return true if a document with the given documentHeaderId exists
42       */
43      boolean documentExists(String documentHeaderId);
44  
45      /**
46       * get a new blank document instance based on the document type name
47       *
48       * @param documentTypeName
49       * @return new document instance
50       */
51      Document getNewDocument(String documentTypeName) throws WorkflowException;
52  
53      /**
54       * get a new blank document instance having the given Document class
55       *
56       * @param documentClass
57       * @return new document instance
58       */
59      Document getNewDocument(Class<? extends Document> documentClass) throws WorkflowException;
60  
61      /**
62       * get a new blank document instance based on the document type name. The principal name
63       * passed in will be used as the document initiator.
64       *
65       * @param documentTypeName
66       * @param initiatorPrincipalNm
67       * @return new document instance
68       */
69      Document getNewDocument(String documentTypeName, String initiatorPrincipalNm) throws WorkflowException;
70  
71      /**
72       * get a document based on the document header id which is the primary key for all document types
73       *
74       * @param documentHeaderId
75       * @return document, by id
76       */
77      Document getByDocumentHeaderId(String documentHeaderId) throws WorkflowException;
78  
79      /**
80       * get a document based on the document header id which is the primary key for all document types.  Using this
81       * method does not require that GlobalVariables.getUserSession() be populated.  Therefore, this method can be used
82       * when a HTTP request is not being processed (e.g. during workflow indexing/post-processing).
83       *
84       * @param documentHeaderId
85       * @return document, by id
86       */
87      Document getByDocumentHeaderIdSessionless(String documentHeaderId) throws WorkflowException;
88  
89      /**
90       * This method retrieves a list of fully-populated documents given a list of document header id values.
91       *
92       * @param documentClass
93       * @param documentHeaderIds
94       * @return list of fully-populated documents
95       * @throws WorkflowException
96       */
97      List<Document> getDocumentsByListOfDocumentHeaderIds(Class<? extends Document> documentClass,
98              List<String> documentHeaderIds) throws WorkflowException;
99  
100     /**
101      * This method is to allow for documents to be updated.  It is currently used to update the document status as
102      * well as to allow for locked docs to be unlocked
103      *
104      * @param document the document to be updated
105      * @return the updated document
106      */
107     Document updateDocument(Document document);
108 
109     /**
110      * This is a helper method that performs the same as the {@link #saveDocument(Document, Class)} method.  The
111      * convenience of this method is that the event being used is the standard SaveDocumentEvent.
112      *
113      * @see org.kuali.rice.krad.service.DocumentService#saveDocument(Document, Class)
114      */
115     Document saveDocument(Document document) throws WorkflowException;
116 
117     /**
118      * This method saves the given document using the document event passed in.
119      *
120      * @see org.kuali.rice.krad.service.DocumentService#saveDocument(Document, Class)
121      */
122     Document saveDocument(Document document, DocumentEvent docEvent) throws WorkflowException;
123 
124     /**
125      * Saves the passed-in document. This will persist it both to the Kuali database, and also initiate it
126      * (if necessary) within workflow, so its available in the initiator's action list.  This method uses the
127      * passed in DocumentEvent class when saving the document.  The DocumentEvent class must implement
128      * the {@link SaveEvent} interface.
129      *
130      * Note that the system does not support passing in Workflow Annotations or AdHoc Route Recipients on a SaveDocument
131      * call. These are sent to workflow on a routeDocument action, or any of the others which actually causes a
132      * routing action to happen in workflow.
133      *
134      * Also note that this method will not check the document action flags to check if a save is valid
135      *
136      * The calling code should always use the object returned from this method for future operations since a new
137      * object is created when the passed-in document is saved.
138      *
139      * @param document the document to be saved
140      * @param kualiDocumentEventClass the event class to use when saving (class must implement the SaveEvent interface)
141      * @return the saved document
142      * @throws WorkflowException
143      */
144     Document saveDocument(Document document,
145             Class<? extends DocumentEvent> kualiDocumentEventClass) throws WorkflowException;
146 
147     /**
148      * Save and then route the document, optionally providing an annotation which will show up in the route log
149      * of the document for the action taken, and optionally providing a list of ad hoc recipients for the document.
150      *
151      * @param document the document to be routed
152      * @param annotation the annotation to appear in the route log of the document
153      * @param adHocRoutingRecipients list of ad hoc recipients to which the document will be routed
154      * @return the saved and routed document
155      * @throws WorkflowException
156      */
157     Document routeDocument(Document document, String annotation,
158             List<AdHocRouteRecipient> adHocRoutingRecipients) throws WorkflowException;
159 
160     /**
161      * Save and then approve the document, optionally providing an annotation which will show up in the route log
162      * of the document for the action taken, and optionally providing a list of ad hoc recipients for the document.
163      *
164      * @param document the document to be approved
165      * @param annotation the annotation to appear in the route log of the document
166      * @param adHocRoutingRecipients list of ad hoc recipients to which the document will be routed
167      * @return the saved and approved document
168      * @throws WorkflowException
169      */
170     Document approveDocument(Document document, String annotation,
171             List<AdHocRouteRecipient> adHocRoutingRecipients) throws WorkflowException;
172 
173     /**
174      * Save and then approve the document as a super user, optionally providing an annotation which will show up in the
175      * route log of the document for the action taken.
176      *
177      * @param document the document to be super user approved
178      * @param annotation the annotation to appear in the route log of the document
179      * @return the saved and super user approved document
180      * @throws WorkflowException
181      */
182     Document superUserApproveDocument(Document document, String annotation) throws WorkflowException;
183 
184      /**
185      * Save and then cancel the document as a super user, optionally providing an annotation which will show up in the
186      * route log of the document for the action taken.
187      *
188      * @param document the document to be super user canceled
189      * @param annotation the annotation to appear in the route log of the document
190      * @return the saved and super user canceled document
191      * @throws WorkflowException
192      */
193     Document superUserCancelDocument(Document document, String annotation) throws WorkflowException;
194 
195     /**
196      * Save and then disapprove the document as a super user, optionally providing an annotation which will show up
197      * in the route log of the document for the action taken.
198      *
199      * @param document the document to be super user disapproved
200      * @param annotation the annotation to appear in the route log of the document
201      * @return the saved and super user disapproved document
202      * @throws WorkflowException
203      */
204     Document superUserDisapproveDocument(Document document, String annotation) throws WorkflowException;
205 
206     /**
207      * Disapprove the document as super user, without saving, optionally providing an annotation which will show
208      * up in the route log of the document for the action taken.
209      *
210      * @param document the document to be super user disapproved
211      * @param annotation the annotation to appear in the route log of the document
212      * @return the super user disapproved document
213      * @throws WorkflowException
214      */
215     Document superUserDisapproveDocumentWithoutSaving(Document document,
216             String annotation) throws WorkflowException;
217 
218     /**
219      * Disapprove the document, without saving, optionally providing an annotation which will show up in the route log
220      * of the document for the action taken.
221      *
222      * @param document the document to be disapproved
223      * @param annotation the annotation to appear in the route log of the document
224      * @return the disapproved document
225      * @throws Exception
226      */
227     Document disapproveDocument(Document document, String annotation) throws Exception;
228 
229     /**
230      * Cancel the document, without saving, optionally providing an annotation for the disapproval which will show
231      * up in the route log of the document for the action taken.
232      *
233      * @param document the document to be canceled
234      * @param annotation the annotation to appear in the route log of the document
235      * @return the canceled document
236      * @throws WorkflowException
237      */
238     Document cancelDocument(Document document, String annotation) throws WorkflowException;
239 
240     /**
241      * Acknowledge the document, optionally providing an annotation for the acknowledgement which will show up in the
242      * route log of the document, and optionally providing a list of ad hoc recipients for the document.  The list of
243      * ad hoc recipients for this document should have an action requested of acknowledge or fyi as all other actions
244      * requested will be discarded as invalid due to the fact that this action being taken is an acknowledgement.
245      *
246      * @param document the document to be acknowledged
247      * @param annotation the annotation to appear in the route log of the document
248      * @param adHocRecipients list of ad hoc recipients to which the document will be routed
249      * @return the acknowledged document
250      * @throws WorkflowException
251      */
252     Document acknowledgeDocument(Document document, String annotation,
253             List<AdHocRouteRecipient> adHocRecipients) throws WorkflowException;
254 
255     /**
256      * Blanket approve the document which will save the document, approve the document, and stand in for an
257      * approve for all typically generated approval actions requested for this document. The user must have blanket
258      * approval authority for this document by being registered as a user in the blanket approval workgroup that is
259      * associated with this document type.  Optionally an annotation can be provided which will show up for the
260      * action taken on the document in the route log. Also optionally a list of ad hoc recipients can be provided
261      * for the document, which should be restricted to actions requested of acknowledge and fyi as all other actions
262      * requested will be discarded.
263      *
264      * @param document the document to be blanket approved
265      * @param annotation the annotation to appear in the route log of the document
266      * @param adHocRecipients list of ad hoc recipients to which the document will be routed
267      * @return the saved and blanket approved document
268      * @throws WorkflowException
269      */
270     Document blanketApproveDocument(Document document, String annotation,
271             List<AdHocRouteRecipient> adHocRecipients) throws WorkflowException;
272 
273     /**
274      * Clear the fyi requests for the document, optionally providing a list of ad hoc recipients for the document,
275      * which should be restricted to action requested of fyi as all other actions requested will be discarded.
276      *
277      * @param document the document to clear of fyi requests
278      * @param adHocRecipients list of ad hoc recipients to which the document will be routed
279      * @return the document
280      * @throws WorkflowException
281      */
282     Document clearDocumentFyi(Document document,
283             List<AdHocRouteRecipient> adHocRecipients) throws WorkflowException;
284 
285     /**
286      * Sets the title and app document id in the workflow document
287      *
288      * @param document the document to prepare
289      * @throws WorkflowException
290      */
291     void prepareWorkflowDocument(Document document) throws WorkflowException;
292 
293     /**
294      * This method creates a note from the given document and note text.  The resulting Note will
295      * have it's note type set to the value of {@link Document#getNoteType()}.  Additionally, it's
296      * remoteObjectId will be set to the object id of the document's note target.
297      *
298      * @param document the document from which to use the note type and note target when creating the note
299      * @param text the text value to include in the resulting note
300      * @return the note that was created
301      */
302     Note createNoteFromDocument(Document document, String text);
303 
304     /**
305      * Saves the notes associated with the given document if they are in a state where they can be
306      * saved.  In certain cases they may not be ready to be saved.  For example, in maintenance documents
307      * where the notes are associated with the business object instead of the document header, the notes
308      * cannot be saved until the business object itself has been persisted.
309      *
310      * @param document the document for which to save notes
311      * @return true if the notes were saved, false if they were not
312      */
313     boolean saveDocumentNotes(Document document);
314 
315     /**
316      * Send ad hoc requests for the given document, optionally providing an annotation which will show up in the route
317      * log of the document.  Also optionally providing a list of ad hoc recipients for the document. However if
318      * no ad hoc recipients are provided, no ad hoc requests will be sent.
319      *
320      * @param document the document for which the ad hoc requests are sent
321      * @param annotation the annotation to appear in the route log of the document
322      * @param adHocRecipients list of ad hoc recipients to which the document will be routed
323      * @return the document
324      * @throws WorkflowException
325      */
326     public Document sendAdHocRequests(Document document, String annotation, List<AdHocRouteRecipient> adHocRecipients) throws WorkflowException;
327 
328     /**
329      * Builds an workflow notification request for the note and sends it to note recipient.
330      *
331      * @param document - document that contains the note
332      * @param note - note to notify
333      * @param sender - user who is sending the notification
334      * @return the document
335      * @throws WorkflowException
336      */
337     public Document sendNoteRouteNotification(Document document, Note note, Person sender) throws WorkflowException;
338 
339     /**
340      * Recall the document, optionally providing an annotation for the recall which will show up in the route
341      * log of the document for the action taken.
342      *
343      * @since 2.1
344      * @param document the document to recall
345      * @param annotation the annotation to appear in the route log of the document
346      * @param cancel indicates if the document should be canceled as part of the recall
347      * @return the recalled document
348      * @throws WorkflowException
349      * @since 2.1
350      */
351     Document recallDocument(Document document, String annotation, boolean cancel) throws WorkflowException;
352 
353     /**
354      * Save and then complete the document, optionally providing an annotation which will show up in the route log
355      * of the document for the action taken, and optionally providing a list of ad hoc recipients for the document
356      *
357      * @param document the document to complete
358      * @param annotation the annotation to appear in the route log of the document
359      * @param adHocRecipients list of ad hoc recipients to which the document will be routed
360      * @return the saved and completed document
361      */
362     Document completeDocument(Document document, String annotation,
363             List adHocRecipients) throws WorkflowException;
364 
365     /**
366      * Helper method used to save and validate a document
367      *
368      * @param document document to be validated and persisted
369      * @param event indicates which kualiDocumentEvent was requested
370      * @return the saved document
371      */
372     Document validateAndPersistDocument(Document document, DocumentEvent event) throws ValidationException;
373 }