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.document; 017 018import org.kuali.rice.core.api.mo.common.GloballyUnique; 019import org.kuali.rice.kew.api.KewApiServiceLocator; 020import org.kuali.rice.kew.api.action.ActionRequest; 021import org.kuali.rice.kew.api.action.ActionType; 022import org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent; 023import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange; 024import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange; 025import org.kuali.rice.kim.api.identity.Person; 026import org.kuali.rice.krad.bo.AdHocRoutePerson; 027import org.kuali.rice.krad.bo.AdHocRouteWorkgroup; 028import org.kuali.rice.krad.bo.DocumentHeader; 029import org.kuali.rice.krad.bo.Note; 030import org.kuali.rice.krad.document.authorization.PessimisticLock; 031import org.kuali.rice.krad.rules.rule.event.DocumentEvent; 032import org.kuali.rice.krad.util.NoteType; 033import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityEvaluator; 034 035import java.util.List; 036 037 038 039/** 040 * This is the Document interface. All entities that are regarded as "eDocs" in the system, including Maintenance documents and 041 * Transaction Processing documents should implement this interface as it defines methods that are necessary to interact with the 042 * underlying frameworks and components (i.e. notes, attachments, workflow, etc). 043 * 044 * @author Kuali Rice Team (rice.collab@kuali.org) 045 */ 046public interface Document extends GloballyUnique { 047 048 /** 049 * This retrieves the standard {@code DocumentHeader} object, which contains standard meta-data about a document. 050 * 051 * @return document header since all docs will have a document header 052 */ 053 DocumentHeader getDocumentHeader(); 054 055 /** 056 * Sets the associated {@code DocumentHeader} for this document. 057 * 058 * @param documentHeader 059 */ 060 void setDocumentHeader(DocumentHeader documentHeader); 061 062 /** 063 * All documents have a document header id. This is the quick accessor to that unique identifier and should return the same 064 * value as documentHeader.getDocumentHeaderId(). 065 * 066 * @return doc header id 067 */ 068 String getDocumentNumber(); 069 070 /** 071 * setter for document header id 072 * 073 * @param documentHeaderId 074 */ 075 void setDocumentNumber(String documentHeaderId); 076 077 /** 078 079 * This is the method to integrate with workflow, where we will actually populate the workflow defined data structure(s) so that 080 * workflow can routed based on this data. This method is responsible for passing over the proper Kuali (client system) data 081 * that will be used by workflow to determine how the document is actually routed. 082 */ 083 void populateDocumentForRouting(); 084 085 /** 086 * 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 087 * attributes on. 088 * 089 * @return the document serialized to an xml string 090 */ 091 String serializeDocumentToXml(); 092 093 /** 094 * 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 095 * methods prepareForSave() and populateDocumentForRouting(). 096 * 097 * @return XML data for routing 098 */ 099 String getXmlForRouteReport(); 100 101 /** 102 * method to integrate with workflow, where we will actually handle the transitions of levels for documents 103 * 104 * @param levelChangeEvent route level change event 105 */ 106 void doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent); 107 108 /** 109 * method to integrate with workflow where we will be able to perform logic for an action taken being performed on a document 110 * 111 * @param event action taken event 112 */ 113 void doActionTaken(ActionTakenEvent event); 114 115 /** 116 * method to integrate with workflow where we will be able to perform logic after an action taken being performed on a document 117 * 118 * @param performed action type performed 119 * @param event action taken event 120 * @since 2.1 121 */ 122 public void afterActionTaken(ActionType performed, ActionTakenEvent event); 123 124 /** 125 * This method will be called after the Workflow engine has completely finished processing a document. 126 * 127 * @param successfullyProcessed - true if the document was processed successfully, false otherwise 128 */ 129 void afterWorkflowEngineProcess(boolean successfullyProcessed); 130 131 /** 132 * This method will be called before the Workflow engine has begun processing a document. 133 */ 134 void beforeWorkflowEngineProcess(); 135 136 /** 137 * This method will be called before the Workflow engine has begun processing a document. 138 * @return additional document IDs to lock prior to processing 139 */ 140 List<String> getWorkflowEngineDocumentIdsToLock(); 141 142 /** 143 * Getter method to get the document title as it will appear in and be searchable in workflow. 144 * 145 * @return document title 146 */ 147 String getDocumentTitle(); 148 149 /** 150 * 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 151 * for a given users version of a document as this state is only persisted in workflow itself when someone takes an action on a 152 * document 153 * 154 * @return list of ad hoc route persons 155 */ 156 List<AdHocRoutePerson> getAdHocRoutePersons(); 157 158 /** 159 * getter method to get the list of ad hoc route workgroups associated with a document at a point in time, this list is only 160 * valid for a given users version of a document as this state is only persisted in workflow itself when someone takes an action 161 * on a document 162 * 163 * @return list of ad hoc route workgroups 164 */ 165 List<AdHocRouteWorkgroup> getAdHocRouteWorkgroups(); 166 167 /** 168 * 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 169 * for a given users version of a document as this state is only persisted in workflow itself when someone takes an action on a 170 * document 171 * 172 * @param adHocRoutePersons 173 */ 174 void setAdHocRoutePersons(List<AdHocRoutePerson> adHocRoutePersons); 175 176 /** 177 * setter method to set the list of ad hoc route workgroups associated with a document at a point in time, this list is only 178 * valid for a given users version of a document as this state is only persisted in workflow itself when someone takes an action 179 * on a document 180 * 181 * @param adHocRouteWorkgroups 182 */ 183 void setAdHocRouteWorkgroups(List<AdHocRouteWorkgroup> adHocRouteWorkgroups); 184 185 /** 186 * Return the name of the node to route any adhoc requests to, or null to let the workflow engine choose. 187 * 188 * @return the name of the node to route any adhoc requests to 189 */ 190 String getAdHocRouteNodeName(); 191 192 193 /** 194 * This method provides a hook that will be called before the document is saved. This method is useful for applying document 195 * level data to children. For example, if someone changes data at the document level, and that data needs to be propagated to 196 * child objects or child lists of objects, you can use this method to update the child object or iterate through the list of 197 * child objects and apply the document level data to them. Any document that follows this paradigm will need to make use of 198 * this method to apply all of those changes. 199 */ 200 void prepareForSave(); 201 202 /** 203 * Sends document off to the rules engine to verify business rules. 204 * 205 * @param event - indicates which document event was requested 206 * @throws org.kuali.rice.krad.exception.ValidationException - containing the MessageMap from the validation session. 207 */ 208 void validateBusinessRules(DocumentEvent event); 209 210 /** 211 * Do any work on the document that requires the DocumentEvent before the save. 212 * 213 * @param event - indicates which document event was requested 214 */ 215 void prepareForSave(DocumentEvent event); 216 217 /** 218 * Do any work on the document after the save. 219 * 220 * @param event - indicates which document event was requested 221 */ 222 void postProcessSave(DocumentEvent event); 223 224 /** 225 * This method provides a hook that will be called after a document is retrieved, but before it is returned from the 226 * DocumentService. 227 */ 228 void processAfterRetrieve(); 229 230 /** 231 * This method returns whether or not this document can be copied. 232 * 233 * @return True if it can be copied, false if not. 234 */ 235 boolean getAllowsCopy(); 236 237 /** 238 * Generate any necessary events required during the save event generation 239 * 240 * @return a list of document events that were triggered by the save event 241 */ 242 List<DocumentEvent> generateSaveEvents(); 243 244 /** 245 * Handle the doRouteStatusChange event from the post processor 246 * @param statusChangeEvent status change event 247 */ 248 void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent); 249 250 /** 251 * Returns the note type which should be used for notes associated with this document. 252 * This method should never return null. 253 * 254 * @return the note type supported by this document, this value should never be null 255 */ 256 NoteType getNoteType(); 257 258 /** 259 * Return the target PersistableBusinessObject that notes associated with this document should be attached to. 260 * In general, this method should never return null. However, it is permissible that it will return a 261 * business object which has not been persisted yet (and therefore does not have it's unique object id 262 * established). This is only valid in cases where the note type is {@link NoteType#BUSINESS_OBJECT}. 263 * 264 * In these cases it's the responsibility for implementers of the Document interface to handle storing transient 265 * copies of the document notes (in XML or otherwise) until the underlying note target has been persisted and can be attached 266 * to the document's notes via it's object id. 267 * 268 * @return the PersistableBusinessObject with which notes on this document should be associated 269 */ 270 GloballyUnique getNoteTarget(); 271 272 /** 273 * Adds the given Note to the document's list of Notes. 274 * 275 * @param note the Note to add, must be non-null 276 */ 277 void addNote(Note note); 278 279 /** 280 * Returns a mutable list of all notes on the document. 281 * 282 * @return the list of notes associated with this document, if this document has no notes then an empty list will be returned 283 */ 284 List<Note> getNotes(); 285 286 /** 287 * Sets the document's list of notes to the given list. 288 * 289 * @param notes the list of notes to set on the document, must be non-null 290 */ 291 void setNotes(List<Note> notes); 292 293 /** 294 * Retrieves the note at the given index. 295 * 296 * @param index the zero-based index of the note to retrieve 297 * @return the note located at the given index 298 * @throws IndexOutOfBoundsException if the index is out of range 299 */ 300 Note getNote(int index); 301 302 /** 303 * Removes the given note from the document's list of notes. 304 * 305 * @param note the note to remove from the document's list of notes, must be non-null 306 * @return true if the note was successfully removed, false if the list did not contain the given note 307 */ 308 boolean removeNote(Note note); 309 310 /** 311 * This method gets a list of the {@link ActionRequest} objects associated with this document. 312 * 313 * @return list of action requests 314 */ 315 List<ActionRequest> getActionRequests(); 316 317 /** 318 * This method gets the annotation to be attached to a super user action. 319 * 320 * @return the super user annotation 321 */ 322 String getSuperUserAnnotation(); 323 324 /** 325 * This method sets the annotation to be attached to a super user action. 326 * 327 * @param superUserAnnotation the super user annotation 328 */ 329 void setSuperUserAnnotation(String superUserAnnotation); 330 331 /** 332 * This method gets a list of the {@link PessimisticLock} objects associated with this document 333 * 334 * @return list of pessimistic locks 335 */ 336 List<PessimisticLock> getPessimisticLocks(); 337 338 /** 339 * This method updates the list of {@link PessimisticLock} objects on the document if changes could 340 * have been made 341 */ 342 void refreshPessimisticLocks(); 343 344 /** 345 * This method adds a new {@link PessimisticLock} to the document 346 * 347 * NOTE: LOCKS ADDED VIA THIS METHOD WILL NOT BE SAVED WITH THE DOCUMENT 348 * 349 * @param lock - the lock to add to the document 350 */ 351 void addPessimisticLock(PessimisticLock lock); 352 353 /** 354 * Renamed: 355 * @see Document#getLockClearingMethodNames() 356 * @return the list of method names of an action that should clear locks for the current user 357 */ 358 @Deprecated 359 List<String> getLockClearningMethodNames(); 360 361 /** 362 * This is a method that is used by Kuali Pessimistic Locking to get the names (method to call values) 363 * of the KNS KualiDocumentActionBase methods that should release locks 364 * 365 * @return the list of method names of an action that should clear locks for the current user 366 * 367 * @deprecated Use the {@code releasePessimisticLocks method} in the transactional KRAD controller 368 */ 369 @Deprecated 370 List<String> getLockClearingMethodNames(); 371 372 /** 373 * Returns an evaluator object that determines whether a given property relative to the root object ({@link #wrapDocumentWithMetadataForXmlSerialization()} 374 * is serializable during the document serialization process. 375 * 376 * @return a fully initialized evaluator object, ready to be used for workflow routing 377 * 378 * @see org.kuali.rice.krad.service.DocumentSerializerService 379 * @see #wrapDocumentWithMetadataForXmlSerialization() 380 */ 381 382 String getBasePathToDocumentDuringSerialization(); 383 384 /** 385 * Returns an evaluator object that determines whether a given property relative to the root object ({@link #wrapDocumentWithMetadataForXmlSerialization()} 386 * is serializable during the document serialization process. 387 * 388 * @return a fully initialized evaluator object, ready to be used for workflow routing 389 * 390 * @see org.kuali.rice.krad.service.DocumentSerializerService 391 * @see #wrapDocumentWithMetadataForXmlSerialization() 392 */ 393 PropertySerializabilityEvaluator getDocumentPropertySerizabilityEvaluator(); 394 395 /** 396 * 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 397 * wrapper may also contain references to additional objects that provide metadata useful to the workflow engine. 398 * 399 * If no wrappers are necessary, then this object may return "this" 400 * 401 * @return a wrapper object (most likely containing a reference to "this"), or "this" itself. 402 * @see org.kuali.rice.krad.workflow.KualiDocumentXmlMaterializer 403 */ 404 Object wrapDocumentWithMetadataForXmlSerialization(); 405 406 /** 407 * This method returns whether or not this document supports custom lock descriptors for pessimistic locking. 408 * 409 * @return True if the document can generate custom lock descriptors, false otherwise. 410 * @see #getCustomLockDescriptor(Person) 411 */ 412 boolean useCustomLockDescriptors(); 413 414 /** 415 * Generates a custom lock descriptor for pessimistic locking. This method should not be called unless {@link #useCustomLockDescriptors()} returns true. 416 * 417 * @param user The user trying to establish the lock. 418 * @return A String representing the lock descriptor. 419 * @see #useCustomLockDescriptors() 420 * @see org.kuali.rice.krad.service.PessimisticLockService 421 */ 422 String getCustomLockDescriptor(Person user); 423}