001/**
002 * Copyright 2005-2015 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.kew.impl.document;
017
018import org.kuali.rice.kew.api.KewApiServiceLocator;
019import org.kuali.rice.kew.api.WorkflowDocument;
020import org.kuali.rice.kew.api.document.Document;
021import org.kuali.rice.kew.api.document.DocumentContentUpdate;
022import org.kuali.rice.kew.api.document.DocumentUpdate;
023import org.kuali.rice.kew.service.KEWServiceLocator;
024
025/**
026 * TODO 
027 * 
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 *
030 */
031public final class DefaultWorkflowDocumentProvider implements WorkflowDocumentProvider {
032
033    @Override
034    public WorkflowDocument createDocument(String principalId, String documentTypeName, DocumentUpdate documentUpdate, DocumentContentUpdate documentContentUpdate) {
035        Document document = KewApiServiceLocator.getWorkflowDocumentActionsService().create(documentTypeName, principalId, documentUpdate, documentContentUpdate);
036        return initializePrototype(principalId, document);
037    }
038
039    @Override
040    public WorkflowDocument loadDocument(String principalId, String documentId) {
041        Document document = KewApiServiceLocator.getWorkflowDocumentService().getDocument(documentId);
042        if (document == null) {
043            throw new IllegalArgumentException("Failed to locate workflow document for given documentId: " + documentId);
044        }
045        return initializePrototype(principalId, document);
046    }
047    
048    private WorkflowDocumentPrototype initializePrototype(String principalId, Document document) {
049        WorkflowDocumentPrototype prototype = KEWServiceLocator.getWorkflowDocumentPrototype();
050        prototype.init(principalId, document);
051        return prototype;
052    }
053
054}