View Javadoc

1   /**
2    * Copyright 2005-2012 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.kew.impl.document;
17  
18  import org.kuali.rice.kew.api.KewApiServiceLocator;
19  import org.kuali.rice.kew.api.WorkflowDocument;
20  import org.kuali.rice.kew.api.document.Document;
21  import org.kuali.rice.kew.api.document.DocumentContentUpdate;
22  import org.kuali.rice.kew.api.document.DocumentUpdate;
23  import org.kuali.rice.kew.service.KEWServiceLocator;
24  
25  /**
26   * TODO 
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   *
30   */
31  public final class DefaultWorkflowDocumentProvider implements WorkflowDocumentProvider {
32  
33      @Override
34      public WorkflowDocument createDocument(String principalId, String documentTypeName, DocumentUpdate documentUpdate, DocumentContentUpdate documentContentUpdate) {
35          Document document = KewApiServiceLocator.getWorkflowDocumentActionsService().create(documentTypeName, principalId, documentUpdate, documentContentUpdate);
36          return initializePrototype(principalId, document);
37      }
38  
39      @Override
40      public WorkflowDocument loadDocument(String principalId, String documentId) {
41          Document document = KewApiServiceLocator.getWorkflowDocumentService().getDocument(documentId);
42          if (document == null) {
43              throw new IllegalArgumentException("Failed to locate workflow document for given documentId: " + documentId);
44          }
45          return initializePrototype(principalId, document);
46      }
47      
48      private WorkflowDocumentPrototype initializePrototype(String principalId, Document document) {
49          WorkflowDocumentPrototype prototype = KEWServiceLocator.getWorkflowDocumentPrototype();
50          prototype.init(principalId, document);
51          return prototype;
52      }
53  
54  }