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