001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.service; 017 018import org.kuali.rice.kew.api.exception.WorkflowException; 019import org.kuali.rice.kim.api.identity.Person; 020import org.kuali.rice.krad.bo.AdHocRouteRecipient; 021import org.kuali.rice.krad.bo.Note; 022import org.kuali.rice.krad.document.Document; 023import org.kuali.rice.krad.exception.ValidationException; 024import org.kuali.rice.krad.rules.rule.event.DocumentEvent; 025import org.kuali.rice.krad.rules.rule.event.SaveEvent; 026 027import java.util.List; 028 029/** 030 * Defines various operations that support the Document framework. 031 * 032 * The calling code should always use any returned Document object for future operations since a new object will be 033 * created if a passed-in document is saved. 034 * 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 */ 037public interface DocumentService { 038 039 /** 040 * @param documentHeaderId 041 * @return true if a document with the given documentHeaderId exists 042 */ 043 boolean documentExists(String documentHeaderId); 044 045 /** 046 * get a new blank document instance based on the document type name 047 * 048 * @param documentTypeName 049 * @return new document instance 050 */ 051 Document getNewDocument(String documentTypeName) throws WorkflowException; 052 053 /** 054 * get a new blank document instance having the given Document class 055 * 056 * @param documentClass 057 * @return new document instance 058 */ 059 Document getNewDocument(Class<? extends Document> documentClass) throws WorkflowException; 060 061 /** 062 * get a new blank document instance based on the document type name. The principal name 063 * passed in will be used as the document initiator. 064 * 065 * @param documentTypeName 066 * @param initiatorPrincipalNm 067 * @return new document instance 068 */ 069 Document getNewDocument(String documentTypeName, String initiatorPrincipalNm) throws WorkflowException; 070 071 /** 072 * get a document based on the document header id which is the primary key for all document types 073 * 074 * @param documentHeaderId 075 * @return document, by id 076 */ 077 Document getByDocumentHeaderId(String documentHeaderId) throws WorkflowException; 078 079 /** 080 * get a document based on the document header id which is the primary key for all document types. Using this 081 * method does not require that GlobalVariables.getUserSession() be populated. Therefore, this method can be used 082 * when a HTTP request is not being processed (e.g. during workflow indexing/post-processing). 083 * 084 * @param documentHeaderId 085 * @return document, by id 086 */ 087 Document getByDocumentHeaderIdSessionless(String documentHeaderId) throws WorkflowException; 088 089 /** 090 * This method retrieves a list of fully-populated documents given a list of document header id values. 091 * 092 * @param documentClass 093 * @param documentHeaderIds 094 * @return list of fully-populated documents 095 * @throws WorkflowException 096 */ 097 List<Document> getDocumentsByListOfDocumentHeaderIds(Class<? extends Document> documentClass, 098 List<String> documentHeaderIds) throws WorkflowException; 099 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 * Send ad hoc requests for the given document to the specified node name, optionally providing an annotation which 330 * will show up in the route log of the document. Also optionally providing a list of ad hoc recipients for the 331 * document. However if no ad hoc recipients are provided, no ad hoc requests will be sent. 332 * 333 * @param document the document for which the ad hoc requests are sent 334 * @param annotation the annotation to appear in the route log of the document 335 * @param nodeName the name of the node to attach the adhoc requests to 336 * @param adHocRecipients list of ad hoc recipients to which the document will be routed 337 * @return the document 338 * @throws WorkflowException 339 */ 340 public Document sendAdHocRequests(Document document, String annotation, String nodeName, List<AdHocRouteRecipient> adHocRecipients) throws WorkflowException; 341 342 343 /** 344 * Builds an workflow notification request for the note and sends it to note recipient. 345 * 346 * @param document - document that contains the note 347 * @param note - note to notify 348 * @param sender - user who is sending the notification 349 * @return the document 350 * @throws WorkflowException 351 */ 352 public Document sendNoteRouteNotification(Document document, Note note, Person sender) throws WorkflowException; 353 354 /** 355 * Recall the document, optionally providing an annotation for the recall which will show up in the route 356 * log of the document for the action taken. 357 * 358 * @since 2.1 359 * @param document the document to recall 360 * @param annotation the annotation to appear in the route log of the document 361 * @param cancel indicates if the document should be canceled as part of the recall 362 * @return the recalled document 363 * @throws WorkflowException 364 * @since 2.1 365 */ 366 Document recallDocument(Document document, String annotation, boolean cancel) throws WorkflowException; 367 368 /** 369 * Save and then complete the document, optionally providing an annotation which will show up in the route log 370 * of the document for the action taken, and optionally providing a list of ad hoc recipients for the document 371 * 372 * @param document the document to complete 373 * @param annotation the annotation to appear in the route log of the document 374 * @param adHocRecipients list of ad hoc recipients to which the document will be routed 375 * @return the saved and completed document 376 */ 377 Document completeDocument(Document document, String annotation, 378 List adHocRecipients) throws WorkflowException; 379 380 /** 381 * Helper method used to save and validate a document 382 * 383 * @param document document to be validated and persisted 384 * @param event indicates which kualiDocumentEvent was requested 385 * @return the saved document 386 */ 387 Document validateAndPersistDocument(Document document, DocumentEvent event) throws ValidationException; 388 389 Document routeDocument(Document document, String annotation, String nodeName, List<AdHocRouteRecipient> adHocRouteRecipients) throws WorkflowException; 390 391 Document blanketApproveDocument(Document document, String annotation, String nodeName, List<AdHocRouteRecipient> adHocRouteRecipients) throws WorkflowException; 392 393 Document approveDocument(Document document, String annotation, String nodeName, List<AdHocRouteRecipient> adHocRouteRecipients) throws WorkflowException; 394 395 Document clearDocumentFyi(Document document, String nodeName, List<AdHocRouteRecipient> adHocRouteRecipients) throws WorkflowException; 396 397 Document acknowledgeDocument(Document document, String annotation, String nodeName, List<AdHocRouteRecipient> adHocRouteRecipients) throws WorkflowException; 398 399 Document completeDocument(Document document, String annotation, String nodeName, List<AdHocRouteRecipient> adHocRouteRecipients) throws WorkflowException; 400}