001    /*
002     * Copyright 2011 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     */
016    package org.kuali.kfs.module.cab.document.service.impl;
017    
018    import org.kuali.kfs.module.cab.document.service.GlAndPurApHelperService;
019    import org.kuali.kfs.sys.context.SpringContext;
020    import org.kuali.rice.kew.dto.DocumentTypeDTO;
021    import org.kuali.rice.kew.exception.WorkflowException;
022    import org.kuali.rice.kew.util.KEWConstants;
023    import org.kuali.rice.kns.util.KNSConstants;
024    import org.kuali.rice.kns.workflow.service.KualiWorkflowInfo;
025    
026    public class GlAndPurApHelperServiceImpl implements GlAndPurApHelperService {
027    
028        public String getDocHandlerUrl(String documentNumber, String docTypeName) {
029            KualiWorkflowInfo kualiWorkflowInfo = SpringContext.getBean(KualiWorkflowInfo.class);
030            try {
031                DocumentTypeDTO docType = kualiWorkflowInfo.getDocType(docTypeName);
032                String docHandlerUrl = docType.getDocTypeHandlerUrl();
033                if (docHandlerUrl.indexOf("?") == -1) {
034                    docHandlerUrl += "?";
035                }
036                else {
037                    docHandlerUrl += "&";
038                }
039    
040                docHandlerUrl += KNSConstants.PARAMETER_DOC_ID + "=" + documentNumber + "&" + KNSConstants.PARAMETER_COMMAND + "=" + KEWConstants.DOCSEARCH_COMMAND;
041                return docHandlerUrl;
042            }
043            catch (WorkflowException e) {
044                throw new RuntimeException("Caught WorkflowException trying to get document handler URL from Workflow", e);
045            }
046        }
047    }