Example usage for com.liferay.portal.kernel.workflow WorkflowDefinitionManagerUtil getWorkflowDefinition

List of usage examples for com.liferay.portal.kernel.workflow WorkflowDefinitionManagerUtil getWorkflowDefinition

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowDefinitionManagerUtil getWorkflowDefinition.

Prototype

public static WorkflowDefinition getWorkflowDefinition(long companyId, String name, int version)
            throws WorkflowException 

Source Link

Usage

From source file:com.liferay.portlet.workflowdefinitions.action.EditWorkflowDefinitionAction.java

License:Open Source License

protected void updateWorkflowDefinition(ActionRequest actionRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");

    InputStream inputStream = null;

    try {//w ww. ja va 2s  .c o  m
        inputStream = uploadPortletRequest.getFileAsStream("file");

        WorkflowDefinition workflowDefinition = null;

        if (inputStream == null) {
            String name = ParamUtil.getString(actionRequest, "name");
            int version = ParamUtil.getInteger(actionRequest, "version");

            workflowDefinition = WorkflowDefinitionManagerUtil
                    .getWorkflowDefinition(themeDisplay.getCompanyId(), name, version);

            WorkflowDefinitionManagerUtil.updateTitle(themeDisplay.getCompanyId(), themeDisplay.getUserId(),
                    name, version, getTitle(titleMap));
        } else {
            workflowDefinition = WorkflowDefinitionManagerUtil.deployWorkflowDefinition(
                    themeDisplay.getCompanyId(), themeDisplay.getUserId(), getTitle(titleMap), inputStream);
        }

        actionRequest.setAttribute(WebKeys.WORKFLOW_DEFINITION, workflowDefinition);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }

}